Commit 3d8c403e authored by Kenton Varda's avatar Kenton Varda

WIP: Implement AnyStruct/AnyList/Capability types. Need to pull Jason's fixes; oops.

parent c3b6b203
......@@ -206,6 +206,13 @@ TEST(Any, AnyList) {
#endif
}
TEST(Any, AnyStructListCapInSchema) {
MallocMessageBuilder builder;
auto root = builder.getRoot<test::TestAnyOthers>();
initTestMessage(root.initAnyStructFieldAs<TestAllTypes>());
}
} // namespace
} // namespace _ (private)
} // namespace capnp
......@@ -265,6 +265,7 @@ struct AnyPointer {
friend class LocalClient;
friend class PipelineHook;
friend class AnyStruct::Pipeline;
};
#endif // !CAPNP_LITE
};
......@@ -474,20 +475,21 @@ private:
#if !CAPNP_LITE
class AnyStruct::Pipeline {
public:
Pipeline getPointerField(uint16_t pointerIndex);
// Return a new Promise representing a sub-object of the result. `pointerIndex` is the index
// of the sub-object within the pointer section of the result (the result must be a struct).
//
// TODO(perf): On GCC 4.8 / Clang 3.3, use rvalue qualifiers to avoid the need for copies.
// Also make `ops` into a Vector to optimize this.
inline Pipeline(decltype(nullptr)): typeless(nullptr) {}
inline explicit Pipeline(AnyPointer::Pipeline&& typeless)
: typeless(kj::mv(typeless)) {}
inline AnyPointer::Pipeline getPointerField(uint16_t pointerIndex) {
// Return a new Promise representing a sub-object of the result. `pointerIndex` is the index
// of the sub-object within the pointer section of the result (the result must be a struct).
//
// TODO(perf): On GCC 4.8 / Clang 3.3, use rvalue qualifiers to avoid the need for copies.
// Also make `ops` into a Vector to optimize this.
return typeless.getPointerField(pointerIndex);
}
private:
kj::Own<PipelineHook> hook;
kj::Array<PipelineOp> ops;
inline Pipeline(kj::Own<PipelineHook>&& hook, kj::Array<PipelineOp>&& ops)
: hook(kj::mv(hook)), ops(kj::mv(ops)) {}
AnyPointer::Pipeline typeless;
};
#endif // !CAPNP_LITE
......@@ -519,7 +521,6 @@ private:
friend struct ToDynamic_;
};
class List<AnyStruct, Kind::OTHER>::Builder {
public:
typedef List<AnyStruct> Builds;
......@@ -844,6 +845,10 @@ struct PointerHelpers<AnyStruct, Kind::OTHER> {
return AnyStruct::Builder(builder.initStruct(
StructSize(dataWordCount * WORDS, pointerCount * POINTERS)));
}
// TODO(soon): implement these
static void adopt(PointerBuilder builder, Orphan<AnyStruct>&& value);
static Orphan<AnyStruct> disown(PointerBuilder builder);
};
template <>
......@@ -868,6 +873,10 @@ struct PointerHelpers<AnyList, Kind::OTHER> {
return AnyList::Builder(builder.initStructList(
elementCount * ELEMENTS, StructSize(dataWordCount * WORDS, pointerCount * POINTERS)));
}
// TODO(soon): implement these
static void adopt(PointerBuilder builder, Orphan<AnyList>&& value);
static Orphan<AnyList> disown(PointerBuilder builder);
};
} // namespace _ (private)
......
......@@ -5,7 +5,7 @@
namespace capnp {
namespace schemas {
static const ::capnp::_::AlignedData<21> b_b9c6f99ebf805f2c = {
static const ::capnp::_::AlignedData<20> b_b9c6f99ebf805f2c = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
44, 95, 128, 191, 158, 249, 198, 185,
16, 0, 0, 0, 5, 0, 1, 0,
......@@ -15,7 +15,7 @@ static const ::capnp::_::AlignedData<21> b_b9c6f99ebf805f2c = {
21, 0, 0, 0, 210, 0, 0, 0,
33, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 3, 0, 1, 0,
28, 0, 0, 0, 2, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
99, 97, 112, 110, 112, 47, 99, 43,
......@@ -24,18 +24,17 @@ static const ::capnp::_::AlignedData<21> b_b9c6f99ebf805f2c = {
101, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
::capnp::word const* const bp_b9c6f99ebf805f2c = b_b9c6f99ebf805f2c.words;
#if !CAPNP_LITE
const ::capnp::_::RawSchema s_b9c6f99ebf805f2c = {
0xb9c6f99ebf805f2c, b_b9c6f99ebf805f2c.words, 21, nullptr, nullptr,
0xb9c6f99ebf805f2c, b_b9c6f99ebf805f2c.words, 20, nullptr, nullptr,
0, 0, nullptr, nullptr, nullptr, { &s_b9c6f99ebf805f2c, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
static const ::capnp::_::AlignedData<20> b_f264a779fef191ce = {
static const ::capnp::_::AlignedData<19> b_f264a779fef191ce = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
206, 145, 241, 254, 121, 167, 100, 242,
16, 0, 0, 0, 5, 0, 252, 7,
......@@ -45,7 +44,7 @@ static const ::capnp::_::AlignedData<20> b_f264a779fef191ce = {
21, 0, 0, 0, 170, 0, 0, 0,
29, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
24, 0, 0, 0, 3, 0, 1, 0,
24, 0, 0, 0, 2, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
99, 97, 112, 110, 112, 47, 99, 43,
......@@ -53,14 +52,13 @@ static const ::capnp::_::AlignedData<20> b_f264a779fef191ce = {
110, 97, 109, 101, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
::capnp::word const* const bp_f264a779fef191ce = b_f264a779fef191ce.words;
#if !CAPNP_LITE
const ::capnp::_::RawSchema s_f264a779fef191ce = {
0xf264a779fef191ce, b_f264a779fef191ce.words, 20, nullptr, nullptr,
0xf264a779fef191ce, b_f264a779fef191ce.words, 19, nullptr, nullptr,
0, 0, nullptr, nullptr, nullptr, { &s_f264a779fef191ce, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
......
......@@ -478,7 +478,18 @@ private:
return CppTypeName::makePrimitive(" ::capnp::AnyPointer");
}
} else {
return CppTypeName::makePrimitive(" ::capnp::AnyPointer");
switch (type.whichAnyPointerKind()) {
case schema::Type::AnyPointer::Unconstrained::ANY_KIND:
return CppTypeName::makePrimitive(" ::capnp::AnyPointer");
case schema::Type::AnyPointer::Unconstrained::STRUCT:
return CppTypeName::makePrimitive(" ::capnp::AnyStruct");
case schema::Type::AnyPointer::Unconstrained::LIST:
return CppTypeName::makePrimitive(" ::capnp::AnyList");
case schema::Type::AnyPointer::Unconstrained::CAPABILITY:
hasInterfaces = true; // Probably need to #inculde <capnp/capability.h>.
return CppTypeName::makePrimitive(" ::capnp::Capability");
}
KJ_UNREACHABLE;
}
}
KJ_UNREACHABLE;
......@@ -1249,12 +1260,27 @@ private:
kind = FieldKind::INTERFACE;
break;
case schema::Type::ANY_POINTER:
kind = FieldKind::ANY_POINTER;
if (defaultBody.hasAnyPointer()) {
defaultOffset = field.getDefaultValueSchemaOffset();
}
if (typeSchema.getBrandParameter() != nullptr) {
kind = FieldKind::BRAND_PARAMETER;
} else {
kind = FieldKind::ANY_POINTER;
switch (typeSchema.whichAnyPointerKind()) {
case schema::Type::AnyPointer::Unconstrained::ANY_KIND:
kind = FieldKind::ANY_POINTER;
break;
case schema::Type::AnyPointer::Unconstrained::STRUCT:
kind = FieldKind::STRUCT;
break;
case schema::Type::AnyPointer::Unconstrained::LIST:
kind = FieldKind::LIST;
break;
case schema::Type::AnyPointer::Unconstrained::CAPABILITY:
kind = FieldKind::INTERFACE;
break;
}
}
break;
}
......@@ -1461,6 +1487,8 @@ private:
(kind == FieldKind::STRUCT || kind == FieldKind::BRAND_PARAMETER);
bool shouldIncludeArrayInitializer = false;
bool shouldExcludeInLiteMode = type.hasInterfaces();
bool shouldTemplatizeInit = typeSchema.which() == schema::Type::ANY_POINTER &&
kind != FieldKind::BRAND_PARAMETER;
CppTypeName elementReaderType;
if (typeSchema.isList()) {
......@@ -1555,9 +1583,17 @@ private:
COND(shouldIncludeArrayInitializer,
" inline void set", titleCase, "(::kj::ArrayPtr<const ", elementReaderType, "> value);\n"),
COND(shouldIncludeStructInit,
" inline ", builderType, " init", titleCase, "();\n"),
COND(shouldTemplatizeInit,
" template <typename T_>\n"
" inline ::capnp::BuilderFor<T_> init", titleCase, "As();\n"),
COND(!shouldTemplatizeInit,
" inline ", builderType, " init", titleCase, "();\n")),
COND(shouldIncludeSizedInit,
" inline ", builderType, " init", titleCase, "(unsigned int size);\n"),
COND(shouldTemplatizeInit,
" template <typename T_>\n"
" inline ::capnp::BuilderFor<T_> init", titleCase, "As(unsigned int size);\n"),
COND(!shouldTemplatizeInit,
" inline ", builderType, " init", titleCase, "(unsigned int size);\n")),
" inline void adopt", titleCase, "(::capnp::Orphan<", type, ">&& value);\n"
" inline ::capnp::Orphan<", type, "> disown", titleCase, "();\n",
COND(shouldExcludeInLiteMode, "#endif // !CAPNP_LITE\n"),
......@@ -1613,19 +1649,41 @@ private:
" _builder.getPointerField(", offset, " * ::capnp::POINTERS), value);\n"
"}\n"),
COND(shouldIncludeStructInit,
templateContext.allDecls(),
"inline ", builderType, " ", scope, "Builder::init", titleCase, "() {\n",
unionDiscrim.set,
" return ::capnp::_::PointerHelpers<", type, ">::init(\n"
" _builder.getPointerField(", offset, " * ::capnp::POINTERS));\n"
"}\n"),
COND(shouldTemplatizeInit,
templateContext.allDecls(),
"template <typename T_>\n"
"inline ::capnp::BuilderFor<T_> ", scope, "Builder::init", titleCase, "As() {\n",
" static_assert(::capnp::kind<T_>() == ::capnp::Kind::STRUCT,\n"
" \"", proto.getName(), " must be a struct\");\n",
unionDiscrim.set,
" return ::capnp::_::PointerHelpers<T_>::init(\n"
" _builder.getPointerField(", offset, " * ::capnp::POINTERS));\n"
"}\n"),
COND(!shouldTemplatizeInit,
templateContext.allDecls(),
"inline ", builderType, " ", scope, "Builder::init", titleCase, "() {\n",
unionDiscrim.set,
" return ::capnp::_::PointerHelpers<", type, ">::init(\n"
" _builder.getPointerField(", offset, " * ::capnp::POINTERS));\n"
"}\n")),
COND(shouldIncludeSizedInit,
templateContext.allDecls(),
"inline ", builderType, " ", scope, "Builder::init", titleCase, "(unsigned int size) {\n",
unionDiscrim.set,
" return ::capnp::_::PointerHelpers<", type, ">::init(\n"
" _builder.getPointerField(", offset, " * ::capnp::POINTERS), size);\n"
"}\n"),
COND(shouldTemplatizeInit,
templateContext.allDecls(),
"template <typename T_>\n"
"inline ::capnp::BuilderFor<T_> ", scope, "Builder::init", titleCase, "As(unsigned int size) {\n",
" static_assert(::capnp::kind<T_>() == ::capnp::Kind::LIST,\n"
" \"", proto.getName(), " must be a list\");\n",
unionDiscrim.set,
" return ::capnp::_::PointerHelpers<T_>::init(\n"
" _builder.getPointerField(", offset, " * ::capnp::POINTERS), size);\n"
"}\n"),
COND(!shouldTemplatizeInit,
templateContext.allDecls(),
"inline ", builderType, " ", scope, "Builder::init", titleCase, "(unsigned int size) {\n",
unionDiscrim.set,
" return ::capnp::_::PointerHelpers<", type, ">::init(\n"
" _builder.getPointerField(", offset, " * ::capnp::POINTERS), size);\n"
"}\n")),
templateContext.allDecls(),
"inline void ", scope, "Builder::adopt", titleCase, "(\n"
" ::capnp::Orphan<", type, ">&& value) {\n",
......
......@@ -225,7 +225,17 @@ private:
auto anyPointer = type.getAnyPointer();
switch (anyPointer.which()) {
case schema::Type::AnyPointer::UNCONSTRAINED:
return kj::strTree("AnyPointer");
switch (anyPointer.getUnconstrained().which()) {
case schema::Type::AnyPointer::Unconstrained::ANY_KIND:
return kj::strTree("AnyPointer");
case schema::Type::AnyPointer::Unconstrained::STRUCT:
return kj::strTree("AnyStruct");
case schema::Type::AnyPointer::Unconstrained::LIST:
return kj::strTree("AnyList");
case schema::Type::AnyPointer::Unconstrained::CAPABILITY:
return kj::strTree("Capability");
}
KJ_UNREACHABLE;
case schema::Type::AnyPointer::PARAMETER: {
auto param = anyPointer.getParameter();
auto scopeProto = scope.getProto();
......
......@@ -226,6 +226,9 @@ struct Declaration {
builtinList @54 :Void $builtinParams([(name = "Element")]);
builtinObject @55 :Void; # only for "renamed to AnyPointer" error message
builtinAnyPointer @56 :Void;
builtinAnyStruct @58 :Void;
builtinAnyList @59 :Void;
builtinCapability @60 :Void;
}
annotation builtinParams @0x94099c3f9eb32d6b (field) :List(BrandParameter);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -211,6 +211,9 @@ struct Declaration {
BUILTIN_LIST,
BUILTIN_OBJECT,
BUILTIN_ANY_POINTER,
BUILTIN_ANY_STRUCT,
BUILTIN_ANY_LIST,
BUILTIN_CAPABILITY,
};
struct BrandParameter;
struct AnnotationApplication;
......@@ -1397,6 +1400,15 @@ public:
inline bool hasParameters() const;
inline ::capnp::List< ::capnp::compiler::Declaration::BrandParameter>::Reader getParameters() const;
inline bool isBuiltinAnyStruct() const;
inline ::capnp::Void getBuiltinAnyStruct() const;
inline bool isBuiltinAnyList() const;
inline ::capnp::Void getBuiltinAnyList() const;
inline bool isBuiltinCapability() const;
inline ::capnp::Void getBuiltinCapability() const;
private:
::capnp::_::StructReader _reader;
template <typename, ::capnp::Kind>
......@@ -1602,6 +1614,18 @@ public:
inline void adoptParameters(::capnp::Orphan< ::capnp::List< ::capnp::compiler::Declaration::BrandParameter>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Declaration::BrandParameter>> disownParameters();
inline bool isBuiltinAnyStruct();
inline ::capnp::Void getBuiltinAnyStruct();
inline void setBuiltinAnyStruct( ::capnp::Void value = ::capnp::VOID);
inline bool isBuiltinAnyList();
inline ::capnp::Void getBuiltinAnyList();
inline void setBuiltinAnyList( ::capnp::Void value = ::capnp::VOID);
inline bool isBuiltinCapability();
inline ::capnp::Void getBuiltinCapability();
inline void setBuiltinCapability( ::capnp::Void value = ::capnp::VOID);
private:
::capnp::_::StructBuilder _builder;
template <typename, ::capnp::Kind>
......@@ -5190,6 +5214,84 @@ inline ::capnp::Orphan< ::capnp::List< ::capnp::compiler::Declaration::BrandPara
_builder.getPointerField(7 * ::capnp::POINTERS));
}
inline bool Declaration::Reader::isBuiltinAnyStruct() const {
return which() == Declaration::BUILTIN_ANY_STRUCT;
}
inline bool Declaration::Builder::isBuiltinAnyStruct() {
return which() == Declaration::BUILTIN_ANY_STRUCT;
}
inline ::capnp::Void Declaration::Reader::getBuiltinAnyStruct() const {
KJ_IREQUIRE(which() == Declaration::BUILTIN_ANY_STRUCT,
"Must check which() before get()ing a union member.");
return _reader.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void Declaration::Builder::getBuiltinAnyStruct() {
KJ_IREQUIRE(which() == Declaration::BUILTIN_ANY_STRUCT,
"Must check which() before get()ing a union member.");
return _builder.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline void Declaration::Builder::setBuiltinAnyStruct( ::capnp::Void value) {
_builder.setDataField<Declaration::Which>(
1 * ::capnp::ELEMENTS, Declaration::BUILTIN_ANY_STRUCT);
_builder.setDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS, value);
}
inline bool Declaration::Reader::isBuiltinAnyList() const {
return which() == Declaration::BUILTIN_ANY_LIST;
}
inline bool Declaration::Builder::isBuiltinAnyList() {
return which() == Declaration::BUILTIN_ANY_LIST;
}
inline ::capnp::Void Declaration::Reader::getBuiltinAnyList() const {
KJ_IREQUIRE(which() == Declaration::BUILTIN_ANY_LIST,
"Must check which() before get()ing a union member.");
return _reader.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void Declaration::Builder::getBuiltinAnyList() {
KJ_IREQUIRE(which() == Declaration::BUILTIN_ANY_LIST,
"Must check which() before get()ing a union member.");
return _builder.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline void Declaration::Builder::setBuiltinAnyList( ::capnp::Void value) {
_builder.setDataField<Declaration::Which>(
1 * ::capnp::ELEMENTS, Declaration::BUILTIN_ANY_LIST);
_builder.setDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS, value);
}
inline bool Declaration::Reader::isBuiltinCapability() const {
return which() == Declaration::BUILTIN_CAPABILITY;
}
inline bool Declaration::Builder::isBuiltinCapability() {
return which() == Declaration::BUILTIN_CAPABILITY;
}
inline ::capnp::Void Declaration::Reader::getBuiltinCapability() const {
KJ_IREQUIRE(which() == Declaration::BUILTIN_CAPABILITY,
"Must check which() before get()ing a union member.");
return _reader.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void Declaration::Builder::getBuiltinCapability() {
KJ_IREQUIRE(which() == Declaration::BUILTIN_CAPABILITY,
"Must check which() before get()ing a union member.");
return _builder.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline void Declaration::Builder::setBuiltinCapability( ::capnp::Void value) {
_builder.setDataField<Declaration::Which>(
1 * ::capnp::ELEMENTS, Declaration::BUILTIN_CAPABILITY);
_builder.setDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS, value);
}
inline bool Declaration::BrandParameter::Reader::hasName() const {
return !_reader.getPointerField(0 * ::capnp::POINTERS).isNull();
}
......
This diff is collapsed.
......@@ -948,7 +948,16 @@ bool NodeTranslator::BrandedDecl::compileAsType(
"inconvenience, and thanks for being an early adopter. :)");
// no break
case Declaration::BUILTIN_ANY_POINTER:
target.initAnyPointer().setUnconstrained();
target.initAnyPointer().initUnconstrained().setAnyKind();
return true;
case Declaration::BUILTIN_ANY_STRUCT:
target.initAnyPointer().initUnconstrained().setStruct();
return true;
case Declaration::BUILTIN_ANY_LIST:
target.initAnyPointer().initUnconstrained().setList();
return true;
case Declaration::BUILTIN_CAPABILITY:
target.initAnyPointer().initUnconstrained().setCapability();
return true;
case Declaration::FILE:
......
......@@ -45,6 +45,8 @@ struct ToDynamic_; // Defined in dynamic.h, needs to be declared as everyone's
struct DynamicStruct; // So that it can be declared a friend.
struct Capability; // To declare brandBindingFor<Capability>()
namespace _ { // private
#if !CAPNP_LITE
......@@ -69,7 +71,10 @@ struct RawBrandedSchema {
uint16_t listDepth; // Number of times to wrap the base type in List().
uint16_t paramIndex; // for AnyPointer, if it's a type parameter.
uint16_t paramIndex;
// For AnyPointer. If it's a type parameter (scopeId is non-zero) or it's an implicit parameter
// (isImplicitParameter is true), then this is the parameter index. Otherwise this is a numeric
// value of one of schema::Type::AnyPointer::Unconstrained::Which.
union {
const RawBrandedSchema* schema; // for struct, enum, interface
......@@ -345,6 +350,27 @@ struct BrandBindingFor_<AnyPointer, Kind::OTHER> {
}
};
template <>
struct BrandBindingFor_<AnyStruct, Kind::OTHER> {
static constexpr RawBrandedSchema::Binding get(uint16_t listDepth) {
return { 18, listDepth, 0, 1 };
}
};
template <>
struct BrandBindingFor_<AnyList, Kind::OTHER> {
static constexpr RawBrandedSchema::Binding get(uint16_t listDepth) {
return { 18, listDepth, 0, 2 };
}
};
template <>
struct BrandBindingFor_<Capability, Kind::OTHER> {
static constexpr RawBrandedSchema::Binding get(uint16_t listDepth) {
return { 18, listDepth, 0, 3 };
}
};
template <typename T>
constexpr RawBrandedSchema::Binding brandBindingFor() {
return BrandBindingFor_<T>::get(0);
......
This diff is collapsed.
......@@ -42,7 +42,7 @@ const ::capnp::_::RawSchema s_9fd69ebc87b9719c = {
};
#endif // !CAPNP_LITE
CAPNP_DEFINE_ENUM(Side_9fd69ebc87b9719c, 9fd69ebc87b9719c);
static const ::capnp::_::AlignedData<33> b_d20b909fee733a8e = {
static const ::capnp::_::AlignedData<32> b_d20b909fee733a8e = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
142, 58, 115, 238, 159, 144, 11, 210,
25, 0, 0, 0, 1, 0, 1, 0,
......@@ -66,13 +66,12 @@ static const ::capnp::_::AlignedData<33> b_d20b909fee733a8e = {
0, 0, 0, 0, 0, 0, 0, 0,
13, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 3, 0, 1, 0,
20, 0, 0, 0, 2, 0, 1, 0,
8, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 2, 0, 1, 0,
115, 105, 100, 101, 0, 0, 0, 0,
15, 0, 0, 0, 0, 0, 0, 0,
156, 113, 185, 135, 188, 158, 214, 159,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
......@@ -85,11 +84,11 @@ static const ::capnp::_::RawSchema* const d_d20b909fee733a8e[] = {
static const uint16_t m_d20b909fee733a8e[] = {0};
static const uint16_t i_d20b909fee733a8e[] = {0};
const ::capnp::_::RawSchema s_d20b909fee733a8e = {
0xd20b909fee733a8e, b_d20b909fee733a8e.words, 33, d_d20b909fee733a8e, m_d20b909fee733a8e,
0xd20b909fee733a8e, b_d20b909fee733a8e.words, 32, d_d20b909fee733a8e, m_d20b909fee733a8e,
1, 1, i_d20b909fee733a8e, nullptr, nullptr, { &s_d20b909fee733a8e, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
static const ::capnp::_::AlignedData<34> b_b88d09a9c5f39817 = {
static const ::capnp::_::AlignedData<33> b_b88d09a9c5f39817 = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
23, 152, 243, 197, 169, 9, 141, 184,
25, 0, 0, 0, 1, 0, 1, 0,
......@@ -114,13 +113,12 @@ static const ::capnp::_::AlignedData<34> b_b88d09a9c5f39817 = {
0, 0, 0, 0, 0, 0, 0, 0,
13, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 3, 0, 1, 0,
20, 0, 0, 0, 2, 0, 1, 0,
8, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 2, 0, 1, 0,
106, 111, 105, 110, 73, 100, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
......@@ -130,7 +128,7 @@ static const ::capnp::_::AlignedData<34> b_b88d09a9c5f39817 = {
static const uint16_t m_b88d09a9c5f39817[] = {0};
static const uint16_t i_b88d09a9c5f39817[] = {0};
const ::capnp::_::RawSchema s_b88d09a9c5f39817 = {
0xb88d09a9c5f39817, b_b88d09a9c5f39817.words, 34, nullptr, m_b88d09a9c5f39817,
0xb88d09a9c5f39817, b_b88d09a9c5f39817.words, 33, nullptr, m_b88d09a9c5f39817,
0, 1, i_b88d09a9c5f39817, nullptr, nullptr, { &s_b88d09a9c5f39817, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
......@@ -189,7 +187,7 @@ const ::capnp::_::RawSchema s_b47f4979672cb59d = {
0, 0, nullptr, nullptr, nullptr, { &s_b47f4979672cb59d, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
static const ::capnp::_::AlignedData<65> b_95b29059097fca83 = {
static const ::capnp::_::AlignedData<62> b_95b29059097fca83 = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
131, 202, 127, 9, 89, 144, 178, 149,
25, 0, 0, 0, 1, 0, 1, 0,
......@@ -214,27 +212,26 @@ static const ::capnp::_::AlignedData<65> b_95b29059097fca83 = {
0, 0, 0, 0, 0, 0, 0, 0,
69, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 3, 0, 1, 0,
76, 0, 0, 0, 2, 0, 1, 0,
64, 0, 0, 0, 2, 0, 1, 0,
72, 0, 0, 0, 2, 0, 1, 0,
1, 0, 0, 0, 2, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
73, 0, 0, 0, 82, 0, 0, 0,
69, 0, 0, 0, 82, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
72, 0, 0, 0, 3, 0, 1, 0,
84, 0, 0, 0, 2, 0, 1, 0,
68, 0, 0, 0, 2, 0, 1, 0,
76, 0, 0, 0, 2, 0, 1, 0,
2, 0, 0, 0, 3, 0, 0, 0,
0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
81, 0, 0, 0, 66, 0, 0, 0,
73, 0, 0, 0, 66, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
76, 0, 0, 0, 3, 0, 1, 0,
88, 0, 0, 0, 2, 0, 1, 0,
68, 0, 0, 0, 2, 0, 1, 0,
76, 0, 0, 0, 2, 0, 1, 0,
106, 111, 105, 110, 73, 100, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......@@ -243,7 +240,6 @@ static const ::capnp::_::AlignedData<65> b_95b29059097fca83 = {
7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......@@ -251,7 +247,6 @@ static const ::capnp::_::AlignedData<65> b_95b29059097fca83 = {
7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
......@@ -261,11 +256,11 @@ static const ::capnp::_::AlignedData<65> b_95b29059097fca83 = {
static const uint16_t m_95b29059097fca83[] = {0, 1, 2};
static const uint16_t i_95b29059097fca83[] = {0, 1, 2};
const ::capnp::_::RawSchema s_95b29059097fca83 = {
0x95b29059097fca83, b_95b29059097fca83.words, 65, nullptr, m_95b29059097fca83,
0x95b29059097fca83, b_95b29059097fca83.words, 62, nullptr, m_95b29059097fca83,
0, 3, i_95b29059097fca83, nullptr, nullptr, { &s_95b29059097fca83, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
static const ::capnp::_::AlignedData<65> b_9d263a3630b7ebee = {
static const ::capnp::_::AlignedData<62> b_9d263a3630b7ebee = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
238, 235, 183, 48, 54, 58, 38, 157,
25, 0, 0, 0, 1, 0, 1, 0,
......@@ -290,27 +285,26 @@ static const ::capnp::_::AlignedData<65> b_9d263a3630b7ebee = {
0, 0, 0, 0, 0, 0, 0, 0,
69, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 3, 0, 1, 0,
76, 0, 0, 0, 2, 0, 1, 0,
64, 0, 0, 0, 2, 0, 1, 0,
72, 0, 0, 0, 2, 0, 1, 0,
1, 0, 0, 0, 32, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
73, 0, 0, 0, 82, 0, 0, 0,
69, 0, 0, 0, 82, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
72, 0, 0, 0, 3, 0, 1, 0,
84, 0, 0, 0, 2, 0, 1, 0,
68, 0, 0, 0, 2, 0, 1, 0,
76, 0, 0, 0, 2, 0, 1, 0,
2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
81, 0, 0, 0, 34, 0, 0, 0,
73, 0, 0, 0, 34, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
76, 0, 0, 0, 3, 0, 1, 0,
88, 0, 0, 0, 2, 0, 1, 0,
68, 0, 0, 0, 2, 0, 1, 0,
76, 0, 0, 0, 2, 0, 1, 0,
106, 111, 105, 110, 73, 100, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......@@ -319,7 +313,6 @@ static const ::capnp::_::AlignedData<65> b_9d263a3630b7ebee = {
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......@@ -327,7 +320,6 @@ static const ::capnp::_::AlignedData<65> b_9d263a3630b7ebee = {
18, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
18, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
......@@ -337,7 +329,7 @@ static const ::capnp::_::AlignedData<65> b_9d263a3630b7ebee = {
static const uint16_t m_9d263a3630b7ebee[] = {2, 0, 1};
static const uint16_t i_9d263a3630b7ebee[] = {0, 1, 2};
const ::capnp::_::RawSchema s_9d263a3630b7ebee = {
0x9d263a3630b7ebee, b_9d263a3630b7ebee.words, 65, nullptr, m_9d263a3630b7ebee,
0x9d263a3630b7ebee, b_9d263a3630b7ebee.words, 62, nullptr, m_9d263a3630b7ebee,
0, 3, i_9d263a3630b7ebee, nullptr, nullptr, { &s_9d263a3630b7ebee, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
......
This diff is collapsed.
......@@ -372,7 +372,7 @@ Type Schema::interpretType(schema::Type::Reader proto, uint location) const {
auto anyPointer = proto.getAnyPointer();
switch (anyPointer.which()) {
case schema::Type::AnyPointer::UNCONSTRAINED:
return schema::Type::ANY_POINTER;
return anyPointer.getUnconstrained().which();
case schema::Type::AnyPointer::PARAMETER: {
auto param = anyPointer.getParameter();
return getBrandBinding(param.getScopeId(), param.getParameterIndex());
......@@ -409,7 +409,7 @@ Type Schema::BrandArgumentList::operator[](uint index) const {
} else if (binding.isImplicitParameter) {
result = Type::ImplicitParameter { binding.paramIndex };
} else {
result = schema::Type::ANY_POINTER;
result = static_cast<schema::Type::AnyPointer::Unconstrained::Which>(binding.paramIndex);
}
} else if (binding.schema == nullptr) {
// Builtin / primitive type.
......@@ -858,7 +858,11 @@ bool Type::operator==(const Type& other) const {
KJ_UNREACHABLE;
case schema::Type::ANY_POINTER:
return scopeId == other.scopeId && (scopeId == 0 || paramIndex == other.paramIndex);
return scopeId == other.scopeId &&
// Trying to comply with strict aliasing rules. Hopefully the compiler realizes that
// both branches compile to the same instructions and can optimize it away.
(scopeId != 0 || isImplicitParam ? paramIndex == other.paramIndex
: anyPointerKind == other.anyPointerKind);
}
KJ_UNREACHABLE;
......
......@@ -319,8 +319,18 @@ struct Type {
}
anyPointer :union {
unconstrained @18 :Void;
# A regular AnyPointer.
unconstrained :union {
# A regular AnyPointer.
#
# The name "unconstained" means as opposed to constraining it to match a type parameter.
# In retrospect this name is probably a poor choice given that it may still be constrained
# to be a struct, list, or capability.
anyKind @18 :Void; # truly AnyPointer
struct @25 :Void; # AnyStruct
list @26 :Void; # AnyList
capability @27 :Void; # Capability
}
parameter :group {
# This is actually a reference to a type parameter defined within this scope.
......
This diff is collapsed.
This diff is collapsed.
......@@ -593,6 +593,7 @@ public:
inline Type(EnumSchema schema);
inline Type(InterfaceSchema schema);
inline Type(ListSchema schema);
inline Type(schema::Type::AnyPointer::Unconstrained::Which anyPointerKind);
inline Type(BrandParameter param);
inline Type(ImplicitParameter param);
......@@ -615,6 +616,9 @@ public:
// Only callable if which() returns ANY_POINTER. Returns null if the type is just a regular
// AnyPointer and not a parameter. "Implicit parameters" refer to type parameters on methods.
inline schema::Type::AnyPointer::Unconstrained::Which whichAnyPointerKind() const;
// Only callable if which() returns ANY_POINTER.
inline bool isVoid() const;
inline bool isBool() const;
inline bool isInt8() const;
......@@ -652,10 +656,15 @@ private:
// If true, this refers to an implicit method parameter. baseType must be ANY_POINTER, scopeId
// must be zero, and paramIndex indicates the parameter index.
uint16_t paramIndex;
// If baseType is ANY_POINTER but this Type actually refers to a type parameter, this is the
// index of the parameter among the parameters at its scope, and `scopeId` below is the type ID
// of the scope where the parameter was defined.
union {
uint16_t paramIndex;
// If baseType is ANY_POINTER but this Type actually refers to a type parameter, this is the
// index of the parameter among the parameters at its scope, and `scopeId` below is the type ID
// of the scope where the parameter was defined.
schema::Type::AnyPointer::Unconstrained::Which anyPointerKind;
// If scopeId is zero and isImplicitParam is false.
};
union {
const _::RawBrandedSchema* schema; // if type is struct, enum, interface...
......@@ -669,7 +678,7 @@ private:
void requireUsableAs(Type expected) const;
friend class ListSchema;
friend class ListSchema; // only for requireUsableAs()
};
// -------------------------------------------------------------------
......@@ -845,6 +854,7 @@ inline Type::Type(schema::Type::Which primitive)
primitive != schema::Type::LIST);
if (primitive == schema::Type::ANY_POINTER) {
scopeId = 0;
anyPointerKind = schema::Type::AnyPointer::Unconstrained::ANY_KIND;
} else {
schema = nullptr;
}
......@@ -864,6 +874,9 @@ inline Type::Type(InterfaceSchema schema)
: baseType(schema::Type::INTERFACE), listDepth(0), schema(schema.raw) {}
inline Type::Type(ListSchema schema)
: Type(schema.getElementType()) { ++listDepth; }
inline Type::Type(schema::Type::AnyPointer::Unconstrained::Which anyPointerKind)
: baseType(schema::Type::ANY_POINTER), listDepth(0), isImplicitParam(false),
anyPointerKind(anyPointerKind), scopeId(0) {}
inline Type::Type(BrandParameter param)
: baseType(schema::Type::ANY_POINTER), listDepth(0), isImplicitParam(false),
paramIndex(param.index), scopeId(param.scopeId) {}
......@@ -875,6 +888,12 @@ inline schema::Type::Which Type::which() const {
return listDepth > 0 ? schema::Type::LIST : baseType;
}
inline schema::Type::AnyPointer::Unconstrained::Which Type::whichAnyPointerKind() const {
KJ_IREQUIRE(baseType == schema::Type::ANY_POINTER);
return !isImplicitParam && scopeId == 0 ? anyPointerKind
: schema::Type::AnyPointer::Unconstrained::ANY_KIND;
}
template <typename T>
inline Type Type::from() { return Type(Schema::from<T>()); }
......
......@@ -165,6 +165,12 @@ struct TestAnyPointer {
# in the struct.
}
struct TestAnyOthers {
anyStructField @0 :AnyStruct;
anyListField @1 :AnyList;
capabilityField @2 :Capability;
}
struct TestOutOfOrder {
foo @3 :Text;
bar @2 :Text;
......
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