summaryrefslogtreecommitdiffstats
path: root/source/slang/lookup.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-01-15 18:15:49 -0500
committerYong He <yonghe@outlook.com>2018-01-15 18:18:25 -0500
commit3d4eaf3c9b13e32c4e4d7737f17805503cddcb0b (patch)
tree7269cd553cf90a7c578afd20b56bf079fcef9656 /source/slang/lookup.cpp
parent8abae0515d734c51e7d55c44ccfdadefea8c6802 (diff)
Support transitive interfaces
This commit is a bunch of quick hacks to get transitive interfaces to work. The idea is for each concrete type we create one giant witness table that contains entries for all the transitively reachable interface requirements, and then create one copy of that witness table for each interface it implements. `DoLocalLookupImpl` now also looks up in inherited interface decles when looking up for a symbol in an interface decl. When visiting `InheritanceDecl` in `lower-to-ir`, create copies of the giant witness table for each transitively inherited interface, so that these witness tables can be found later when the IR is specialized. Re-enable the `copy all witness tables` hack in `specializeIRForEntryPoint` to ensure those transitive witness tables are copied over.
Diffstat (limited to 'source/slang/lookup.cpp')
-rw-r--r--source/slang/lookup.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/source/slang/lookup.cpp b/source/slang/lookup.cpp
index 19503d63f..0791c508b 100644
--- a/source/slang/lookup.cpp
+++ b/source/slang/lookup.cpp
@@ -297,6 +297,23 @@ void DoLocalLookupImpl(
session,
name, extDeclRef, request, result, inBreadcrumbs);
}
+
+ }
+ // for interface decls, also lookup in the base interfaces
+ if (request.semantics)
+ {
+ if (auto interfaceDeclRef = containerDeclRef.As<InterfaceDecl>())
+ {
+ auto baseInterfaces = getMembersOfType<InheritanceDecl>(interfaceDeclRef);
+ for (auto inheritanceDeclRef : baseInterfaces)
+ {
+ auto baseType = inheritanceDeclRef.getDecl()->base.type.As<DeclRefType>();
+ SLANG_ASSERT(baseType);
+ int diff = 0;
+ auto baseInterfaceDeclRef = baseType->declRef.SubstituteImpl(interfaceDeclRef.substitutions, &diff);
+ DoLocalLookupImpl(session, name, baseInterfaceDeclRef.As<ContainerDecl>(), request, result, inBreadcrumbs);
+ }
+ }
}
}