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