Commit a19956a6 authored by Kenton Varda's avatar Kenton Varda

Generics: Rename some things better. (Hardest problem in computer science.)

parent 87ea5bdb
......@@ -102,8 +102,8 @@ void enumerateDeps(schema::Node::Reader node, std::set<uint64_t>& deps) {
}
case schema::Node::INTERFACE: {
auto interfaceNode = node.getInterface();
for (auto extend: interfaceNode.getExtends()) {
deps.insert(extend.getId());
for (auto superclass: interfaceNode.getSuperclasses()) {
deps.insert(superclass.getId());
}
for (auto method: interfaceNode.getMethods()) {
deps.insert(method.getParamStructType());
......@@ -1327,7 +1327,7 @@ private:
auto proto = schema.getProto();
auto extends = KJ_MAP(extend, proto.getInterface().getExtends()) {
auto superclasses = KJ_MAP(extend, proto.getInterface().getSuperclasses()) {
Schema schema = schemaLoader.get(extend.getId());
return ExtendInfo { cppFullName(schema).flatten(), schema.getProto().getId() };
};
......@@ -1350,8 +1350,8 @@ private:
kj::strTree(
"class ", fullName, "::Client\n"
" : public virtual ::capnp::Capability::Client",
KJ_MAP(e, extends) {
return kj::strTree(",\n public virtual ", e.typeName, "::Client");
KJ_MAP(s, superclasses) {
return kj::strTree(",\n public virtual ", s.typeName, "::Client");
}, " {\n"
"public:\n"
" typedef ", fullName, " Calls;\n"
......@@ -1377,8 +1377,8 @@ private:
"\n"
"class ", fullName, "::Server\n"
" : public virtual ::capnp::Capability::Server",
KJ_MAP(e, extends) {
return kj::strTree(",\n public virtual ", e.typeName, "::Server");
KJ_MAP(s, superclasses) {
return kj::strTree(",\n public virtual ", s.typeName, "::Server");
}, " {\n"
"public:\n",
" typedef ", fullName, " Serves;\n"
......@@ -1427,10 +1427,10 @@ private:
" switch (interfaceId) {\n"
" case 0x", kj::hex(proto.getId()), "ull:\n"
" return dispatchCallInternal(methodId, context);\n",
KJ_MAP(e, extends) {
KJ_MAP(s, superclasses) {
return kj::strTree(
" case 0x", kj::hex(e.id), "ull:\n"
" return ", e.typeName, "::Server::dispatchCallInternal(methodId, context);\n");
" case 0x", kj::hex(s.id), "ull:\n"
" return ", s.typeName, "::Server::dispatchCallInternal(methodId, context);\n");
},
" default:\n"
" return internalUnimplemented(\"", proto.getDisplayName(), "\", interfaceId);\n"
......
......@@ -114,19 +114,19 @@ private:
return "(?)";
}
kj::StringTree nodeName(Schema target, Schema scope, schema::TypeEnvironment::Reader env) {
kj::StringTree nodeName(Schema target, Schema scope, schema::Brand::Reader brand) {
kj::Vector<Schema> targetPath;
kj::Vector<Schema> scopeParts;
targetPath.add(target);
std::map<uint64_t, List<schema::TypeEnvironment::Binding>::Reader> scopeBindings;
for (auto scopeEnv: env.getScopes()) {
switch (scopeEnv.which()) {
case schema::TypeEnvironment::Scope::BIND:
scopeBindings[scopeEnv.getScopeId()] = scopeEnv.getBind();
std::map<uint64_t, List<schema::Brand::Binding>::Reader> scopeBindings;
for (auto scopeBrand: brand.getScopes()) {
switch (scopeBrand.which()) {
case schema::Brand::Scope::BIND:
scopeBindings[scopeBrand.getScopeId()] = scopeBrand.getBind();
break;
case schema::TypeEnvironment::Scope::INHERIT:
case schema::Brand::Scope::INHERIT:
// TODO(someday): We need to pay attention to INHERIT and be sure to explicitly override
// any bindings that are not inherited. This requires a way to determine which of our
// parent scopes have a non-empty parameter list.
......@@ -175,9 +175,9 @@ private:
if (iter != scopeBindings.end()) {
auto bindings = KJ_MAP(binding, iter->second) {
switch (binding.which()) {
case schema::TypeEnvironment::Binding::UNBOUND:
case schema::Brand::Binding::UNBOUND:
return kj::strTree("AnyPointer");
case schema::TypeEnvironment::Binding::TYPE:
case schema::Brand::Binding::TYPE:
return genType(binding.getType(), scope);
}
return kj::strTree("<unknown binding>");
......@@ -212,13 +212,13 @@ private:
return kj::strTree("List(", genType(type.getList().getElementType(), scope), ")");
case schema::Type::ENUM:
return nodeName(schemaLoader.get(type.getEnum().getTypeId()), scope,
type.getEnum().getTypeEnvironment());
type.getEnum().getBrand());
case schema::Type::STRUCT:
return nodeName(schemaLoader.get(type.getStruct().getTypeId()), scope,
type.getStruct().getTypeEnvironment());
type.getStruct().getBrand());
case schema::Type::INTERFACE:
return nodeName(schemaLoader.get(type.getInterface().getTypeId()), scope,
type.getInterface().getTypeEnvironment());
type.getInterface().getBrand());
case schema::Type::ANY_POINTER: {
auto anyPointer = type.getAnyPointer();
switch (anyPointer.which()) {
......@@ -227,9 +227,9 @@ private:
case schema::Type::AnyPointer::PARAMETER: {
auto param = anyPointer.getParameter();
auto scopeProto = scope.getProto();
auto targetScopeId = param.getNodeId();
auto targetScopeId = param.getScopeId();
while (scopeProto.getId() != targetScopeId) {
scopeProto = schemaLoader.get(param.getNodeId()).getProto();
scopeProto = schemaLoader.get(param.getScopeId()).getProto();
}
auto params = scopeProto.getParameters();
KJ_REQUIRE(param.getParameterIndex() < params.size());
......@@ -353,7 +353,7 @@ private:
kj::StringTree genAnnotation(schema::Annotation::Reader annotation,
Schema scope,
const char* prefix = " ", const char* suffix = "") {
auto decl = schemaLoader.get(annotation.getId(), annotation.getTypeEnvironment(), scope);
auto decl = schemaLoader.get(annotation.getId(), annotation.getBrand(), scope);
auto proto = decl.getProto();
KJ_REQUIRE(proto.isAnnotation());
auto annDecl = proto.getAnnotation();
......@@ -361,10 +361,10 @@ private:
auto value = genValue(schemaLoader.getType(annDecl.getType(), decl),
annotation.getValue()).flatten();
if (value.startsWith("(")) {
return kj::strTree(prefix, "$", nodeName(decl, scope, annotation.getTypeEnvironment()),
return kj::strTree(prefix, "$", nodeName(decl, scope, annotation.getBrand()),
value, suffix);
} else {
return kj::strTree(prefix, "$", nodeName(decl, scope, annotation.getTypeEnvironment()),
return kj::strTree(prefix, "$", nodeName(decl, scope, annotation.getBrand()),
"(", value, ")", suffix);
}
}
......@@ -470,7 +470,7 @@ private:
}
kj::StringTree genParamList(InterfaceSchema interface, StructSchema schema,
schema::TypeEnvironment::Reader env) {
schema::Brand::Reader brand) {
if (schema.getProto().getScopeId() == 0) {
// A named parameter list.
return kj::strTree("(", kj::StringTree(
......@@ -485,19 +485,18 @@ private:
genAnnotations(proto.getAnnotations(), interface));
}, ", "), ")");
} else {
return nodeName(schema, interface, env);
return nodeName(schema, interface, brand);
}
}
kj::StringTree genExtends(InterfaceSchema interface) {
auto extends = interface.getProto().getInterface().getExtends();
if (extends.size() == 0) {
kj::StringTree genSuperclasses(InterfaceSchema interface) {
auto superclasses = interface.getProto().getInterface().getSuperclasses();
if (superclasses.size() == 0) {
return kj::strTree();
} else {
return kj::strTree(" extends(", kj::StringTree(
KJ_MAP(extend, extends) {
return nodeName(schemaLoader.get(extend.getId()), interface,
extend.getEnvironment());
return kj::strTree(" superclasses(", kj::StringTree(
KJ_MAP(superclass, superclasses) {
return nodeName(schemaLoader.get(superclass.getId()), interface, superclass.getBrand());
}, ", "), ")");
}
}
......@@ -546,7 +545,7 @@ private:
auto interface = schema.asInterface();
return kj::strTree(
indent, "interface ", name, " @0x", kj::hex(proto.getId()), genGenericParams(schema),
genExtends(interface),
genSuperclasses(interface),
genAnnotations(schema), " {\n",
KJ_MAP(method, sortByCodeOrder(interface.getMethods())) {
auto methodProto = method.getProto();
......@@ -554,8 +553,8 @@ private:
auto results = schemaLoader.get(methodProto.getResultStructType()).asStruct();
return kj::strTree(
indent.next(), methodProto.getName(), " @", method.getIndex(), " ",
genParamList(interface, params, methodProto.getParamEnvironment()), " -> ",
genParamList(interface, results, methodProto.getResultEnvironment()),
genParamList(interface, params, methodProto.getParamBrand()), " -> ",
genParamList(interface, results, methodProto.getResultBrand()),
genAnnotations(methodProto.getAnnotations(), interface), ";\n");
},
genNestedDecls(schema, indent.next()),
......
......@@ -64,7 +64,7 @@ public:
// Create a child node.
Node(kj::StringPtr name, Declaration::Which kind,
List<Declaration::TypeParameter>::Reader genericParams);
List<Declaration::BrandParameter>::Reader genericParams);
// Create a dummy node representing a built-in declaration, like "Int32" or "true".
uint64_t getId() { return id; }
......@@ -89,7 +89,7 @@ public:
kj::Maybe<ResolvedDecl> getParent() override;
ResolvedDecl getTopScope() override;
kj::Maybe<Schema> resolveBootstrapSchema(
uint64_t id, schema::TypeEnvironment::Reader environment) override;
uint64_t id, schema::Brand::Reader brand) override;
kj::Maybe<schema::Node::Reader> resolveFinalSchema(uint64_t id) override;
kj::Maybe<ResolvedDecl> resolveImport(kj::StringPtr name) override;
kj::Maybe<Type> resolveBootstrapType(schema::Type::Reader type, Schema scope) override;
......@@ -200,9 +200,9 @@ private:
void traverseType(const schema::Type::Reader& type, uint eagerness,
std::unordered_map<Node*, uint>& seen,
const SchemaLoader& finalLoader);
void traverseEnvironment(const schema::TypeEnvironment::Reader& type, uint eagerness,
std::unordered_map<Node*, uint>& seen,
const SchemaLoader& finalLoader);
void traverseBrand(const schema::Brand::Reader& brand, uint eagerness,
std::unordered_map<Node*, uint>& seen,
const SchemaLoader& finalLoader);
void traverseAnnotations(const List<schema::Annotation>::Reader& annotations, uint eagerness,
std::unordered_map<Node*, uint>& seen,
const SchemaLoader& finalLoader);
......@@ -372,7 +372,7 @@ Compiler::Node::Node(Node& parent, const Declaration::Reader& declaration)
}
Compiler::Node::Node(kj::StringPtr name, Declaration::Which kind,
List<Declaration::TypeParameter>::Reader genericParams)
List<Declaration::BrandParameter>::Reader genericParams)
: module(nullptr),
parent(nullptr),
// It's helpful if these have unique IDs. Real type IDs can't be under 2^31 anyway.
......@@ -677,18 +677,18 @@ void Compiler::Node::traverseNodeDependencies(
case schema::Node::INTERFACE: {
auto interface = schemaNode.getInterface();
for (auto extend: interface.getExtends()) {
uint64_t extendId = extend.getId();
if (extendId != 0) { // if zero, we reported an error earlier
traverseDependency(extendId, eagerness, seen, finalLoader);
for (auto superclass: interface.getSuperclasses()) {
uint64_t superclassId = superclass.getId();
if (superclassId != 0) { // if zero, we reported an error earlier
traverseDependency(superclassId, eagerness, seen, finalLoader);
}
traverseEnvironment(extend.getEnvironment(), eagerness, seen, finalLoader);
traverseBrand(superclass.getBrand(), eagerness, seen, finalLoader);
}
for (auto method: interface.getMethods()) {
traverseDependency(method.getParamStructType(), eagerness, seen, finalLoader, true);
traverseEnvironment(method.getParamEnvironment(), eagerness, seen, finalLoader);
traverseBrand(method.getParamBrand(), eagerness, seen, finalLoader);
traverseDependency(method.getResultStructType(), eagerness, seen, finalLoader, true);
traverseEnvironment(method.getResultEnvironment(), eagerness, seen, finalLoader);
traverseBrand(method.getResultBrand(), eagerness, seen, finalLoader);
traverseAnnotations(method.getAnnotations(), eagerness, seen, finalLoader);
}
break;
......@@ -705,19 +705,19 @@ void Compiler::Node::traverseType(const schema::Type::Reader& type, uint eagerne
std::unordered_map<Node*, uint>& seen,
const SchemaLoader& finalLoader) {
uint64_t id = 0;
schema::TypeEnvironment::Reader env;
schema::Brand::Reader brand;
switch (type.which()) {
case schema::Type::STRUCT:
id = type.getStruct().getTypeId();
env = type.getStruct().getTypeEnvironment();
brand = type.getStruct().getBrand();
break;
case schema::Type::ENUM:
id = type.getEnum().getTypeId();
env = type.getEnum().getTypeEnvironment();
brand = type.getEnum().getBrand();
break;
case schema::Type::INTERFACE:
id = type.getInterface().getTypeId();
env = type.getInterface().getTypeEnvironment();
brand = type.getInterface().getBrand();
break;
case schema::Type::LIST:
traverseType(type.getList().getElementType(), eagerness, seen, finalLoader);
......@@ -727,27 +727,27 @@ void Compiler::Node::traverseType(const schema::Type::Reader& type, uint eagerne
}
traverseDependency(id, eagerness, seen, finalLoader);
traverseEnvironment(env, eagerness, seen, finalLoader);
traverseBrand(brand, eagerness, seen, finalLoader);
}
void Compiler::Node::traverseEnvironment(
const schema::TypeEnvironment::Reader& env, uint eagerness,
void Compiler::Node::traverseBrand(
const schema::Brand::Reader& brand, uint eagerness,
std::unordered_map<Node*, uint>& seen,
const SchemaLoader& finalLoader) {
for (auto scope: env.getScopes()) {
for (auto scope: brand.getScopes()) {
switch (scope.which()) {
case schema::TypeEnvironment::Scope::BIND:
case schema::Brand::Scope::BIND:
for (auto binding: scope.getBind()) {
switch (binding.which()) {
case schema::TypeEnvironment::Binding::UNBOUND:
case schema::Brand::Binding::UNBOUND:
break;
case schema::TypeEnvironment::Binding::TYPE:
case schema::Brand::Binding::TYPE:
traverseType(binding.getType(), eagerness, seen, finalLoader);
break;
}
}
break;
case schema::TypeEnvironment::Scope::INHERIT:
case schema::Brand::Scope::INHERIT:
break;
}
}
......@@ -863,15 +863,15 @@ NodeTranslator::Resolver::ResolvedDecl Compiler::Node::getTopScope() {
}
kj::Maybe<Schema> Compiler::Node::resolveBootstrapSchema(
uint64_t id, schema::TypeEnvironment::Reader environment) {
uint64_t id, schema::Brand::Reader brand) {
KJ_IF_MAYBE(node, module->getCompiler().findNode(id)) {
// Make sure the bootstrap schema is loaded into the SchemaLoader.
if (node->getBootstrapSchema() == nullptr) {
return nullptr;
}
// Now we actually invoke get() to evaluate the environment.
return module->getCompiler().getWorkspace().bootstrapLoader.get(id, environment);
// Now we actually invoke get() to evaluate the brand.
return module->getCompiler().getWorkspace().bootstrapLoader.get(id, brand);
} else {
KJ_FAIL_REQUIRE("Tried to get schema for ID we haven't seen before.");
}
......@@ -982,8 +982,8 @@ static void findImports(Declaration::Reader decl, std::set<kj::StringPtr>& outpu
findImports(decl.getField().getType(), output);
break;
case Declaration::INTERFACE:
for (auto extend: decl.getInterface().getExtends()) {
findImports(extend, output);
for (auto superclass: decl.getInterface().getSuperclasses()) {
findImports(superclass, output);
}
break;
case Declaration::METHOD: {
......@@ -1064,10 +1064,10 @@ Compiler::Impl::Impl(AnnotationFlag annotationFlag)
if (name.startsWith("builtin")) {
kj::StringPtr symbolName = name.slice(strlen("builtin"));
List<Declaration::TypeParameter>::Reader params;
List<Declaration::BrandParameter>::Reader params;
for (auto annotation: fieldProto.getAnnotations()) {
if (annotation.getId() == 0x94099c3f9eb32d6bull) {
params = annotation.getValue().getList().getAs<List<Declaration::TypeParameter>>();
params = annotation.getValue().getList().getAs<List<Declaration::BrandParameter>>();
break;
}
}
......
......@@ -120,10 +120,10 @@ struct Declaration {
ordinal @3 :LocatedInteger; # limited to 16 bits
}
parameters @57 :List(TypeParameter);
parameters @57 :List(BrandParameter);
# If this node is parameterized (generic), the list of parameters. Empty for non-generic types.
struct TypeParameter {
struct BrandParameter {
name @0 :Text;
startByte @1 :UInt32;
endByte @2 :UInt32;
......@@ -173,7 +173,7 @@ struct Declaration {
group @20 :Void;
interface :group {
extends @21 :List(Expression);
superclasses @21 :List(Expression);
}
method :group {
params @22 :ParamList;
......@@ -228,7 +228,7 @@ struct Declaration {
builtinAnyPointer @56 :Void;
}
annotation builtinParams @0x94099c3f9eb32d6b (field) :List(TypeParameter);
annotation builtinParams @0x94099c3f9eb32d6b (field) :List(BrandParameter);
struct ParamList {
# A list of method parameters or method returns.
......
......@@ -714,8 +714,8 @@ static const ::capnp::_::AlignedData<627> b_96efe787c17e83bb = {
108, 97, 114, 97, 116, 105, 111, 110,
0, 0, 0, 0, 0, 0, 0, 0,
20, 0, 0, 0, 1, 0, 1, 0,
241, 147, 67, 145, 111, 77, 113, 169,
33, 0, 0, 0, 114, 0, 0, 0,
117, 225, 28, 175, 68, 17, 231, 213,
33, 0, 0, 0, 122, 0, 0, 0,
144, 98, 130, 115, 212, 137, 4, 208,
33, 0, 0, 0, 178, 0, 0, 0,
107, 45, 179, 158, 63, 156, 9, 148,
......@@ -724,8 +724,8 @@ static const ::capnp::_::AlignedData<627> b_96efe787c17e83bb = {
37, 0, 0, 0, 82, 0, 0, 0,
165, 210, 151, 166, 169, 8, 254, 255,
37, 0, 0, 0, 50, 0, 0, 0,
84, 121, 112, 101, 80, 97, 114, 97,
109, 101, 116, 101, 114, 0, 0, 0,
66, 114, 97, 110, 100, 80, 97, 114,
97, 109, 101, 116, 101, 114, 0, 0,
65, 110, 110, 111, 116, 97, 116, 105,
111, 110, 65, 112, 112, 108, 105, 99,
97, 116, 105, 111, 110, 0, 0, 0,
......@@ -1316,7 +1316,7 @@ static const ::capnp::_::AlignedData<627> b_96efe787c17e83bb = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
241, 147, 67, 145, 111, 77, 113, 169,
117, 225, 28, 175, 68, 17, 231, 213,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
......@@ -1330,9 +1330,9 @@ static const ::capnp::_::RawSchema* const d_96efe787c17e83bb[] = {
&s_991c7a3693d62cf2,
&s_992a90eaf30235d3,
&s_9cb9e86e3198037f,
&s_a9714d6f914393f1,
&s_b348322a8dcf0d0c,
&s_d00489d473826290,
&s_d5e71144af1ce175,
&s_e75816b56529d464,
&s_e93164a80bfe2ccf,
&s_eb971847d617c0b9,
......@@ -1343,14 +1343,14 @@ const ::capnp::_::RawSchema s_96efe787c17e83bb = {
0x96efe787c17e83bb, b_96efe787c17e83bb.words, 627, d_96efe787c17e83bb, m_96efe787c17e83bb,
12, 39, i_96efe787c17e83bb, nullptr, nullptr, { &s_96efe787c17e83bb, nullptr, nullptr, 0, 0, nullptr }
};
static const ::capnp::_::AlignedData<67> b_a9714d6f914393f1 = {
static const ::capnp::_::AlignedData<67> b_d5e71144af1ce175 = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
241, 147, 67, 145, 111, 77, 113, 169,
117, 225, 28, 175, 68, 17, 231, 213,
41, 0, 0, 0, 1, 0, 1, 0,
187, 131, 126, 193, 135, 231, 239, 150,
1, 0, 7, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
21, 0, 0, 0, 186, 1, 0, 0,
21, 0, 0, 0, 194, 1, 0, 0,
45, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
41, 0, 0, 0, 175, 0, 0, 0,
......@@ -1361,8 +1361,8 @@ static const ::capnp::_::AlignedData<67> b_a9714d6f914393f1 = {
114, 97, 109, 109, 97, 114, 46, 99,
97, 112, 110, 112, 58, 68, 101, 99,
108, 97, 114, 97, 116, 105, 111, 110,
46, 84, 121, 112, 101, 80, 97, 114,
97, 109, 101, 116, 101, 114, 0, 0,
46, 66, 114, 97, 110, 100, 80, 97,
114, 97, 109, 101, 116, 101, 114, 0,
0, 0, 0, 0, 1, 0, 1, 0,
12, 0, 0, 0, 3, 0, 4, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......@@ -1412,11 +1412,11 @@ static const ::capnp::_::AlignedData<67> b_a9714d6f914393f1 = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
static const uint16_t m_a9714d6f914393f1[] = {2, 0, 1};
static const uint16_t i_a9714d6f914393f1[] = {0, 1, 2};
const ::capnp::_::RawSchema s_a9714d6f914393f1 = {
0xa9714d6f914393f1, b_a9714d6f914393f1.words, 67, nullptr, m_a9714d6f914393f1,
0, 3, i_a9714d6f914393f1, nullptr, nullptr, { &s_a9714d6f914393f1, nullptr, nullptr, 0, 0, nullptr }
static const uint16_t m_d5e71144af1ce175[] = {2, 0, 1};
static const uint16_t i_d5e71144af1ce175[] = {0, 1, 2};
const ::capnp::_::RawSchema s_d5e71144af1ce175 = {
0xd5e71144af1ce175, b_d5e71144af1ce175.words, 67, nullptr, m_d5e71144af1ce175,
0, 3, i_d5e71144af1ce175, nullptr, nullptr, { &s_d5e71144af1ce175, nullptr, nullptr, 0, 0, nullptr }
};
static const ::capnp::_::AlignedData<45> b_d00489d473826290 = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
......@@ -1566,7 +1566,7 @@ static const ::capnp::_::AlignedData<28> b_94099c3f9eb32d6b = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
241, 147, 67, 145, 111, 77, 113, 169,
117, 225, 28, 175, 68, 17, 231, 213,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
......@@ -2163,7 +2163,7 @@ const ::capnp::_::RawSchema s_d0d1a21de617951f = {
0xd0d1a21de617951f, b_d0d1a21de617951f.words, 51, d_d0d1a21de617951f, m_d0d1a21de617951f,
2, 2, i_d0d1a21de617951f, nullptr, nullptr, { &s_d0d1a21de617951f, nullptr, nullptr, 0, 0, nullptr }
};
static const ::capnp::_::AlignedData<39> b_992a90eaf30235d3 = {
static const ::capnp::_::AlignedData<40> b_992a90eaf30235d3 = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
211, 53, 2, 243, 234, 144, 42, 153,
41, 0, 0, 0, 1, 0, 2, 0,
......@@ -2187,11 +2187,12 @@ static const ::capnp::_::AlignedData<39> b_992a90eaf30235d3 = {
0, 0, 0, 0, 5, 0, 0, 0,
0, 0, 1, 0, 21, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
13, 0, 0, 0, 66, 0, 0, 0,
13, 0, 0, 0, 106, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 3, 0, 1, 0,
36, 0, 0, 0, 2, 0, 1, 0,
101, 120, 116, 101, 110, 100, 115, 0,
12, 0, 0, 0, 3, 0, 1, 0,
40, 0, 0, 0, 2, 0, 1, 0,
115, 117, 112, 101, 114, 99, 108, 97,
115, 115, 101, 115, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......@@ -2211,7 +2212,7 @@ static const ::capnp::_::RawSchema* const d_992a90eaf30235d3[] = {
static const uint16_t m_992a90eaf30235d3[] = {0};
static const uint16_t i_992a90eaf30235d3[] = {0};
const ::capnp::_::RawSchema s_992a90eaf30235d3 = {
0x992a90eaf30235d3, b_992a90eaf30235d3.words, 39, d_992a90eaf30235d3, m_992a90eaf30235d3,
0x992a90eaf30235d3, b_992a90eaf30235d3.words, 40, d_992a90eaf30235d3, m_992a90eaf30235d3,
2, 1, i_992a90eaf30235d3, nullptr, nullptr, { &s_992a90eaf30235d3, nullptr, nullptr, 0, 0, nullptr }
};
static const ::capnp::_::AlignedData<42> b_eb971847d617c0b9 = {
......@@ -2638,7 +2639,7 @@ CAPNP_DEFINE_STRUCT(
CAPNP_DEFINE_STRUCT(
::capnp::compiler::Declaration);
CAPNP_DEFINE_STRUCT(
::capnp::compiler::Declaration::TypeParameter);
::capnp::compiler::Declaration::BrandParameter);
CAPNP_DEFINE_STRUCT(
::capnp::compiler::Declaration::AnnotationApplication);
CAPNP_DEFINE_STRUCT(
......
This diff is collapsed.
This diff is collapsed.
......@@ -62,7 +62,7 @@ public:
Resolver* scope;
// TODO(now): Returning an Expression from some other file is wrong wrong wrong. We need
// to compile the alias down to an id + type environment.
// to compile the alias down to an id + brand.
};
virtual kj::Maybe<kj::OneOf<ResolvedDecl, ResolvedParameter, ResolvedAlias>>
......@@ -79,8 +79,7 @@ public:
virtual ResolvedDecl getTopScope() = 0;
// Get the top-level scope containing this node.
virtual kj::Maybe<Schema> resolveBootstrapSchema(uint64_t id,
schema::TypeEnvironment::Reader environment) = 0;
virtual kj::Maybe<Schema> resolveBootstrapSchema(uint64_t id, schema::Brand::Reader brand) = 0;
// Get the schema for the given ID. If a schema is returned, it must be safe to traverse its
// dependencies via the Schema API. A schema that is only at the bootstrap stage is
// acceptable.
......@@ -147,14 +146,14 @@ private:
class DuplicateOrdinalDetector;
class StructLayout;
class StructTranslator;
class DeclInstance;
class TypeEnvironment;
class BrandedDecl;
class BrandScope;
Resolver& resolver;
ErrorReporter& errorReporter;
Orphanage orphanage;
bool compileAnnotations;
kj::Own<TypeEnvironment> baseEnvironment;
kj::Own<BrandScope> localBrand;
Orphan<schema::Node> wipNode;
// The work-in-progress schema node.
......@@ -194,19 +193,19 @@ private:
// The `members` arrays contain only members with ordinal numbers, in code order. Other members
// are handled elsewhere.
template <typename InitTypeEnvironmentFunc>
template <typename InitBrandFunc>
uint64_t compileParamList(kj::StringPtr methodName, uint16_t ordinal, bool isResults,
Declaration::ParamList::Reader paramList,
InitTypeEnvironmentFunc&& initTypeEnvironment);
InitBrandFunc&& initBrand);
// Compile a param (or result) list and return the type ID of the struct type.
kj::Maybe<DeclInstance> compileDeclExpression(Expression::Reader source);
kj::Maybe<DeclInstance> compileDeclExpression(
Expression::Reader source, kj::Own<TypeEnvironment> env, Resolver& resolver);
kj::Maybe<BrandedDecl> compileDeclExpression(Expression::Reader source);
kj::Maybe<BrandedDecl> compileDeclExpression(
Expression::Reader source, kj::Own<BrandScope> brand, Resolver& resolver);
// Compile an expression which is expected to resolve to a declaration or type expression.
bool compileType(Expression::Reader source, schema::Type::Builder target);
bool compileType(DeclInstance& decl, schema::Type::Builder target);
bool compileType(BrandedDecl& decl, schema::Type::Builder target);
// Returns false if there was a problem, in which case value expressions of this type should
// not be parsed.
......
......@@ -830,18 +830,18 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, ErrorReporter& errorReporterP
p::many(parsers.annotation)),
[this](Located<Text::Reader>&& name, kj::Maybe<Orphan<LocatedInteger>>&& id,
kj::Maybe<Located<kj::Array<kj::Maybe<Located<Text::Reader>>>>>&& genericParameters,
kj::Maybe<Located<kj::Array<kj::Maybe<Orphan<Expression>>>>>&& extends,
kj::Maybe<Located<kj::Array<kj::Maybe<Orphan<Expression>>>>>&& superclasses,
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>();
auto builder = initDecl(
decl.get(), kj::mv(name), kj::mv(id), kj::mv(genericParameters),
kj::mv(annotations)).initInterface();
KJ_IF_MAYBE(e, extends) {
auto extendsBuilder = builder.initExtends(e->value.size());
for (uint i: kj::indices(e->value)) {
KJ_IF_MAYBE(extend, e->value[i]) {
extendsBuilder.adoptWithCaveats(i, kj::mv(*extend));
KJ_IF_MAYBE(s, superclasses) {
auto superclassesBuilder = builder.initSuperclasses(s->value.size());
for (uint i: kj::indices(s->value)) {
KJ_IF_MAYBE(superclass, s->value[i]) {
superclassesBuilder.adoptWithCaveats(i, kj::mv(*superclass));
}
}
}
......
This diff is collapsed.
......@@ -65,23 +65,20 @@ public:
~SchemaLoader() noexcept(false);
KJ_DISALLOW_COPY(SchemaLoader);
typedef schema::TypeEnvironment::Reader GenericBindings;
Schema get(uint64_t id, GenericBindings bindings = GenericBindings(),
Schema get(uint64_t id, schema::Brand::Reader brand = schema::Brand::Reader(),
Schema scope = Schema()) const;
// Gets the schema for the given ID, throwing an exception if it isn't present.
//
// The returned schema may be invalidated if load() is called with a new schema for the same ID.
// In general, you should not call load() while a schema from this loader is in-use.
//
// `bindings` and `scope` are used to determine generic parameter bindings where relevant.
// `bindings` gives parameter bindings for the target type's generic parameters that were
// specified at the reference site. `scope` specifies the scope in which the type ID appeared --
// if the target type and the scope share some common super-scope which is parameterized,
// and bindings for those parameters weren't specified in `bindings`, they will be carried over
// from the scope.
kj::Maybe<Schema> tryGet(uint64_t id, GenericBindings bindings = GenericBindings(),
// `brand` and `scope` are used to determine brand bindings where relevant. `brand` gives
// parameter bindings for the target type's brand parameters that were specified at the reference
// site. `scope` specifies the scope in which the type ID appeared -- if the target type and the
// scope share some common super-scope which is parameterized, and bindings for those parameters
// weren't specified in `brand`, they will be carried over from the scope.
kj::Maybe<Schema> tryGet(uint64_t id, schema::Brand::Reader bindings = schema::Brand::Reader(),
Schema scope = Schema()) const;
// Like get() but doesn't throw.
......
......@@ -381,7 +381,7 @@ Type Schema::interpretType(schema::Type::Reader proto, uint location) const {
return schema::Type::ANY_POINTER;
case schema::Type::AnyPointer::PARAMETER: {
auto param = anyPointer.getParameter();
return getBrandBinding(param.getNodeId(), param.getParameterIndex());
return getBrandBinding(param.getScopeId(), param.getParameterIndex());
}
}
......@@ -529,7 +529,7 @@ kj::Maybe<InterfaceSchema::Method> InterfaceSchema::findMethodByName(
// this means that a dynamically-loaded RawSchema cannot be correctly constructed until all
// superclasses have been loaded, which imposes an ordering requirement on SchemaLoader or
// requires updating subclasses whenever a new superclass is loaded.
auto superclasses = getProto().getInterface().getExtends();
auto superclasses = getProto().getInterface().getSuperclasses();
for (auto i: kj::indices(superclasses)) {
auto superclass = superclasses[i];
uint location = _::RawBrandedSchema::makeDepLocation(
......@@ -554,7 +554,7 @@ InterfaceSchema::Method InterfaceSchema::getMethodByName(kj::StringPtr name) con
}
InterfaceSchema::SuperclassList InterfaceSchema::getSuperclasses() const {
return SuperclassList(*this, getProto().getInterface().getExtends());
return SuperclassList(*this, getProto().getInterface().getSuperclasses());
}
bool InterfaceSchema::extends(InterfaceSchema other) const {
......@@ -577,7 +577,7 @@ bool InterfaceSchema::extends(InterfaceSchema other, uint& counter) const {
}
// TODO(perf): This may be somewhat slow. See findMethodByName() for discussion.
auto superclasses = getProto().getInterface().getExtends();
auto superclasses = getProto().getInterface().getSuperclasses();
for (auto i: kj::indices(superclasses)) {
auto superclass = superclasses[i];
uint location = _::RawBrandedSchema::makeDepLocation(
......@@ -610,7 +610,7 @@ kj::Maybe<InterfaceSchema> InterfaceSchema::findSuperclass(uint64_t typeId, uint
}
// TODO(perf): This may be somewhat slow. See findMethodByName() for discussion.
auto superclasses = getProto().getInterface().getExtends();
auto superclasses = getProto().getInterface().getSuperclasses();
for (auto i: kj::indices(superclasses)) {
auto superclass = superclasses[i];
uint location = _::RawBrandedSchema::makeDepLocation(
......
......@@ -139,7 +139,7 @@ struct Node {
methods @15 :List(Method);
# Methods ordered by ordinal.
extends @31 :List(Extend);
superclasses @31 :List(Superclass);
# Superclasses of this interface.
}
......@@ -165,11 +165,6 @@ struct Node {
targetsAnnotation @30 :Bool;
}
}
struct Extend {
id @0 :Id;
environment @1 :TypeEnvironment;
}
}
struct Field {
......@@ -242,6 +237,11 @@ struct Enumerant {
annotations @2 :List(Annotation);
}
struct Superclass {
id @0 :Id;
brand @1 :Brand;
}
struct Method {
# Schema for method of an interface.
......@@ -260,14 +260,14 @@ struct Method {
# this a situation where you can't just climb the scope chain to find where a particular
# generic parameter was introduced. Making the `scopeId` zero was a mistake.)
paramEnvironment @5 :TypeEnvironment;
# Parameterization of param struct type.
paramBrand @5 :Brand;
# Brand of param struct type.
resultStructType @3 :Id;
# ID of the return struct type; similar to `paramStructType`.
resultEnvironment @6 :TypeEnvironment;
# Parameterization of result struct type.
resultBrand @6 :Brand;
# Brand of result struct type.
annotations @4 :List(Annotation);
}
......@@ -299,15 +299,15 @@ struct Type {
enum :group {
typeId @15 :Id;
typeEnvironment @21 :TypeEnvironment;
brand @21 :Brand;
}
struct :group {
typeId @16 :Id;
typeEnvironment @22 :TypeEnvironment;
brand @22 :Brand;
}
interface :group {
typeId @17 :Id;
typeEnvironment @23 :TypeEnvironment;
brand @23 :Brand;
}
anyPointer :union {
......@@ -317,9 +317,9 @@ struct Type {
parameter :group {
# This is actually a reference to a type parameter defined within this scope.
nodeId @19 :Id;
# Node ID of the generic type whose parameter we're referencing. This must be a parent
# of the current scope.
scopeId @19 :Id;
# ID of the generic type whose parameter we're referencing. This should be a parent of the
# current scope.
parameterIndex @20 :UInt16;
# Index of the parameter within the generic type's parameter list.
......@@ -328,8 +328,9 @@ struct Type {
}
}
struct TypeEnvironment {
# Specifies type parameters applying to a target type declaration, i.e. for generic types.
struct Brand {
# Specifies bindings for parameters of generics. Since these bindings turn a generic into a
# non-generic, we call it the "brand".
scopes @0 :List(Scope);
# For each of the target type and each of its parent scopes, a parameterization may be included
......@@ -403,8 +404,8 @@ struct Annotation {
id @0 :Id;
# ID of the annotation node.
typeEnvironment @2 :TypeEnvironment;
# Type environment of the annotation.
brand @2 :Brand;
# Brand of the annotation.
#
# Note that the annotation itself is not allowed to be parameterized, but its scope might be.
......
This diff is collapsed.
This diff is collapsed.
......@@ -477,9 +477,9 @@ public:
private:
InterfaceSchema parent;
List<schema::Node::Extend>::Reader list;
List<schema::Superclass>::Reader list;
inline SuperclassList(InterfaceSchema parent, List<schema::Node::Extend>::Reader list)
inline SuperclassList(InterfaceSchema parent, List<schema::Superclass>::Reader list)
: parent(parent), list(list) {}
friend class InterfaceSchema;
......
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