Commit 7197456b authored by Kenton Varda's avatar Kenton Varda

Delete Code Friday: Inline structs/lists/data are too complicated for not…

Delete Code Friday:  Inline structs/lists/data are too complicated for not enough benefit.  There goes a week of my life that I'll never get back.
parent de742607
This diff is collapsed.
......@@ -32,14 +32,6 @@
namespace capnproto {
namespace internal {
namespace {
// This zero array is used only as a default value for inlined fields, which are limited
// to no more than 64 words.
static const AlignedData<64> ZERO = {{0}};
} // namespace
// =======================================================================================
struct WireReference {
......@@ -1064,24 +1056,6 @@ StructReader StructReader::getStructField(
return WireHelpers::readStructReference(segment, ref, defaultValue, nestingLimit);
}
StructReader StructReader::getInlineStructField(
ByteCount dataOffset, ByteCount inlineDataSize,
WireReferenceCount refIndex, WireReferenceCount inlineRefCount) const {
if (dataOffset + inlineDataSize <= dataSize &&
refIndex + inlineRefCount <= referenceCount) {
return StructReader(
segment, reinterpret_cast<const byte*>(data) + dataOffset,
// WireReference is incomplete here so we have to cast around... Bah.
reinterpret_cast<const WireReference*>(
reinterpret_cast<const word*>(references) + refIndex * WORDS_PER_REFERENCE),
inlineDataSize, inlineRefCount,
nestingLimit);
} else {
// Return empty struct.
return StructReader();
}
}
ListReader StructReader::getListField(
WireReferenceCount refIndex, FieldSize expectedElementSize, const word* defaultValue) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex;
......@@ -1089,52 +1063,6 @@ ListReader StructReader::getListField(
segment, ref, defaultValue, expectedElementSize, nestingLimit);
}
ListReader StructReader::getInlineDataListField(
ByteCount offset, ElementCount elementCount, FieldSize elementSize) const {
if (offset + WireHelpers::roundUpToBytes(
elementCount * bitsPerElement(elementSize)) <= dataSize) {
return ListReader(
segment, reinterpret_cast<const byte*>(data) + offset, nullptr,
elementCount, bytesPerElement(elementSize), 0 * REFERENCES / ELEMENTS,
nestingLimit);
} else {
// Return zeros.
return ListReader(elementCount);
}
}
ListReader StructReader::getInlinePointerListField(
WireReferenceCount offset, ElementCount elementCount) const {
if (offset + elementCount * (1 * REFERENCES / ELEMENTS) <= referenceCount) {
return ListReader(
segment, nullptr,
reinterpret_cast<const WireReference*>(
reinterpret_cast<const word*>(references) + offset * WORDS_PER_REFERENCE),
elementCount, 0 * BYTES / ELEMENTS, 1 * REFERENCES / ELEMENTS,
nestingLimit);
} else {
// Return nulls.
return ListReader(elementCount);
}
}
ListReader StructReader::getInlineStructListField(
ByteCount dataOffset, WireReferenceCount ptrOffset, ElementCount elementCount,
StructSize elementSize) const {
if (dataOffset + elementSize.dataBytes <= dataSize &&
ptrOffset + elementSize.pointers <= referenceCount) {
return ListReader(
segment, reinterpret_cast<const byte*>(data) + dataOffset,
reinterpret_cast<const WireReference*>(
reinterpret_cast<const word*>(references) + ptrOffset * WORDS_PER_REFERENCE),
elementCount, elementSize.dataBytes / ELEMENTS, elementSize.pointers / ELEMENTS,
elementSize.dataBytes, elementSize.pointers, nestingLimit);
} else {
// Return empty structs.
return ListReader(elementCount);
}
}
Text::Reader StructReader::getTextField(
WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex;
......@@ -1147,17 +1075,6 @@ Data::Reader StructReader::getDataField(
return WireHelpers::readDataReference(segment, ref, defaultValue, defaultSize);
}
Data::Reader StructReader::getInlineDataField(ByteCount offset, ByteCount size) const {
// TODO(soon): Bounds check! Needs to fall back to some common zero'd region.
if (offset + size <= dataSize) {
return Data::Reader(reinterpret_cast<const char*>(reinterpret_cast<const byte*>(data) + offset),
size / BYTES);
} else {
CHECK(size < sizeof(ZERO) * BYTES);
return Data::Reader(reinterpret_cast<const char*>(ZERO.bytes), size / BYTES);
}
}
// =======================================================================================
// ListBuilder
......@@ -1230,12 +1147,6 @@ ListReader ListBuilder::asReader(StructSize elementSize) const {
// =======================================================================================
// ListReader
ListReader::ListReader(ElementCount elementCount)
: segment(nullptr), data(ZERO.bytes),
pointers(reinterpret_cast<const WireReference*>(data)), elementCount(elementCount),
stepBytes(0 * BYTES / ELEMENTS), stepPointers(0 * REFERENCES / ELEMENTS),
structDataSize(0), structReferenceCount(0), nestingLimit(0) {}
StructReader ListReader::getStructElement(ElementCount index) const {
// TODO: Inline this method?
VALIDATE_INPUT((segment == nullptr) | (nestingLimit > 0),
......
This diff is collapsed.
......@@ -51,10 +51,6 @@ struct PointerHelpers;
template <typename T, bool isPrimitive = internal::IsPrimitive<T>::value>
struct List;
template <typename T, size_t size>
struct InlineList: public List<T> {};
// Alias for List. Primarily exists so that we can specialize List<InlineList<...>>.
namespace internal {
template <size_t size> struct FieldSizeForByteSize;
......@@ -412,86 +408,6 @@ private:
friend struct internal::PointerHelpers;
};
template <typename T, size_t subSize>
struct List<InlineList<T, subSize>, false> {
// List of inline lists.
class Reader {
public:
Reader() = default;
inline explicit Reader(internal::ListReader reader): reader(reader) {}
inline uint size() { return reader.size() / ELEMENTS / subSize; }
inline typename List<T>::Reader operator[](uint index) {
return typename List<T>::Reader(reader.slice(
index * subSize * ELEMENTS, subSize * ELEMENTS));
}
typedef internal::IndexingIterator<Reader, typename List<T>::Reader> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
private:
internal::ListReader reader;
};
class Builder {
public:
Builder() = default;
inline explicit Builder(internal::ListBuilder builder): builder(builder) {}
inline uint size() { return builder.size() / ELEMENTS / subSize; }
inline typename List<T>::Builder operator[](uint index) {
return typename List<T>::Builder(builder.slice(
index * subSize * ELEMENTS, subSize * ELEMENTS));
}
typedef internal::IndexingIterator<Builder, typename List<T>::Builder> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
template <typename Other>
void copyFrom(const Other& other);
void copyFrom(std::initializer_list<typename List<T>::Reader> other);
// TODO
private:
internal::ListBuilder builder;
};
private:
inline static internal::ListBuilder initAsElementOf(
internal::ListBuilder& builder, uint index, uint size) {
return List<T>::initAsElementOf(builder, index, size * subSize);
}
inline static internal::ListBuilder getAsElementOf(
internal::ListBuilder& builder, uint index) {
return List<T>::getAsElementOf(builder, index);
}
inline static internal::ListReader getAsElementOf(
internal::ListReader& reader, uint index) {
return List<T>::getAsElementOf(reader, index);
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return List<T>::initAsFieldOf(builder, index, size * subSize);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return List<T>::getAsFieldOf(builder, index);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return List<T>::getAsFieldOf(reader, index);
}
template <typename U, bool b>
friend class List;
template <typename U>
friend struct internal::PointerHelpers;
};
template <>
struct List<Data, false> {
class Reader {
......@@ -589,103 +505,6 @@ private:
friend struct internal::PointerHelpers;
};
template <size_t subSize>
struct List<InlineData<subSize>, false> {
// List of inline data.
class Reader {
public:
Reader() = default;
inline explicit Reader(Data::Reader reader): reader(reader) {}
inline uint size() { return reader.size() / subSize; }
inline typename Data::Reader operator[](uint index) {
return typename Data::Reader(reader.slice(
index * subSize, index * subSize + subSize));
}
typedef internal::IndexingIterator<Reader, typename Data::Reader> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
private:
Data::Reader reader;
};
class Builder {
public:
Builder() = default;
inline explicit Builder(Data::Builder builder): builder(builder) {}
inline uint size() { return builder.size() / subSize; }
inline typename Data::Builder operator[](uint index) {
return typename Data::Builder(builder.slice(
index * subSize, index * subSize + subSize));
}
inline void set(uint index, Data::Reader value) {
(*this)[index].copyFrom(value);
}
typedef internal::IndexingIterator<Builder, typename Data::Builder> iterator;
inline iterator begin() { return iterator(this, 0); }
inline iterator end() { return iterator(this, size()); }
template <typename Other>
void copyFrom(const Other& other) {
auto i = other.begin();
auto end = other.end();
uint pos = 0;
for (; i != end && pos < size(); ++i) {
set(pos, *i);
}
CAPNPROTO_INLINE_DPRECOND(pos == size() && i == end,
"List::copyFrom() argument had different size.");
}
void copyFrom(std::initializer_list<Data::Reader> other) {
CAPNPROTO_INLINE_DPRECOND(other.size() == size(),
"List::copyFrom() argument had different size.");
for (uint i = 0; i < other.size(); i++) {
set(i, other.begin()[i]);
}
}
private:
Data::Builder builder;
};
private:
inline static Data::Builder initAsElementOf(
internal::ListBuilder& builder, uint index, uint size) {
return builder.initDataElement(index * ELEMENTS, size * subSize * BYTES);
}
inline static Data::Builder getAsElementOf(
internal::ListBuilder& builder, uint index) {
return builder.getDataElement(index * ELEMENTS);
}
inline static Data::Reader getAsElementOf(
internal::ListReader& reader, uint index) {
return reader.getDataElement(index * ELEMENTS);
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initDataField(index, size * subSize * BYTES);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getDataField(index, nullptr, 0 * BYTES);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getDataField(index, nullptr, 0 * BYTES);
}
template <typename U, bool b>
friend class List;
template <typename U>
friend struct internal::PointerHelpers;
};
template <>
struct List<Text, false> {
class Reader {
......
This diff is collapsed.
......@@ -59,21 +59,19 @@ using ::capnproto_test::capnproto::test::TestUnion;
using ::capnproto_test::capnproto::test::TestUnionDefaults;
using ::capnproto_test::capnproto::test::TestNestedTypes;
using ::capnproto_test::capnproto::test::TestUsing;
using ::capnproto_test::capnproto::test::TestInlineLayout;
using ::capnproto_test::capnproto::test::TestInlineUnions;
using ::capnproto_test::capnproto::test::TestInlineDefaults;
using ::capnproto_test::capnproto::test::TestListDefaults;
void initTestMessage(TestAllTypes::Builder builder);
void initTestMessage(TestDefaults::Builder builder);
void initTestMessage(TestInlineDefaults::Builder builder);
void initTestMessage(TestListDefaults::Builder builder);
void checkTestMessage(TestAllTypes::Builder builder);
void checkTestMessage(TestDefaults::Builder builder);
void checkTestMessage(TestInlineDefaults::Builder builder);
void checkTestMessage(TestListDefaults::Builder builder);
void checkTestMessage(TestAllTypes::Reader reader);
void checkTestMessage(TestDefaults::Reader reader);
void checkTestMessage(TestInlineDefaults::Reader reader);
void checkTestMessage(TestListDefaults::Reader reader);
void checkTestMessageAllZero(TestAllTypes::Builder builder);
void checkTestMessageAllZero(TestAllTypes::Reader reader);
......
This diff is collapsed.
......@@ -164,10 +164,13 @@ lookupDesc scope name = lookupDesc (descParent scope) name
builtinTypeMap :: Map.Map String Desc
builtinTypeMap = Map.fromList
([(builtinTypeName t, DescBuiltinType t) | t <- builtinTypes] ++
[("List", DescBuiltinList),
("Inline", DescBuiltinInline),
("InlineList", DescBuiltinInlineList),
("InlineData", DescBuiltinInlineData)])
[ ("List", DescBuiltinList)
{- Inlines have been disabled for now because they added too much complication.
, ("Inline", DescBuiltinInline)
, ("InlineList", DescBuiltinInlineList)
, ("InlineData", DescBuiltinInlineData)
-}
])
------------------------------------------------------------------------------------------
......
......@@ -49,7 +49,7 @@ keywords =
, (UnionKeyword, "union")
, (InterfaceKeyword, "interface")
, (AnnotationKeyword, "annotation")
, (FixedKeyword, "fixed")
-- , (FixedKeyword, "fixed") -- Inlines have been disabled because they were too complicated.
]
languageDef :: T.LanguageDef st
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment