From a74a5494b34e2b41a294042ab8b3e7bce115dcba Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 16 Jan 2018 15:38:36 -0500 Subject: bug fixes to get falcor example shader code to compile. 1. prevent cyclic lookups when an interface inherits transitively from itself. 2. in `createGlobalGenericParamSubstitution`, create a default substitution for the base type declref before using it to lookup the witness table. --- source/slang/check.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'source/slang/check.cpp') diff --git a/source/slang/check.cpp b/source/slang/check.cpp index f7bb2ae1f..3fe4f8c5d 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1681,7 +1681,7 @@ namespace Slang { // TODO: actually implement matching here. For now we'll // just pretend that things are satisfied in order to make progress.. - requirementDict.Add(requiredMemberDeclRef, DeclRef(memberDecl, nullptr)); + requirementDict.AddIfNotExists(requiredMemberDeclRef, DeclRef(memberDecl, nullptr)); return true; } @@ -1927,10 +1927,16 @@ namespace Slang // (via the given `inheritanceDecl`) actually provides // members to satisfy all the requirements in the interface. bool checkInterfaceConformance( + HashSet> & checkedInterfaceDeclRef, DeclRef typeDeclRef, InheritanceDecl* inheritanceDecl, DeclRef interfaceDeclRef) { + if (!checkedInterfaceDeclRef.Contains(interfaceDeclRef)) + checkedInterfaceDeclRef.Add(interfaceDeclRef); + else + return true; + bool result = true; // We need to check the declaration of the interface @@ -1960,6 +1966,7 @@ namespace Slang // // TODO: we *really* need a linearization step here!!!! result = result && checkConformanceToType( + checkedInterfaceDeclRef, typeDeclRef, inheritanceDecl, getBaseType(requiredInheritanceDeclRef)); @@ -1985,6 +1992,7 @@ namespace Slang } bool checkConformanceToType( + HashSet>& checkedInterfaceDeclRefs, DeclRef typeDeclRef, InheritanceDecl* inheritanceDecl, Type* baseType) @@ -1998,6 +2006,7 @@ namespace Slang // We need to check that it provides all of the members // required by that interface. return checkInterfaceConformance( + checkedInterfaceDeclRefs, typeDeclRef, inheritanceDecl, baseInterfaceDeclRef); @@ -2019,7 +2028,8 @@ namespace Slang // Look at the type being inherited from, and validate // appropriately. auto baseType = inheritanceDecl->base.type; - return checkConformanceToType(typeDecl, inheritanceDecl, baseType.As()); + HashSet> checkdInterfaceDeclRefs; + return checkConformanceToType(checkdInterfaceDeclRefs, typeDecl, inheritanceDecl, baseType.As()); } bool checkConformance( @@ -2107,7 +2117,6 @@ namespace Slang { checkDecl(member); } - decl->SetCheckState(getCheckedState()); } @@ -4672,9 +4681,12 @@ namespace Slang // Create a witness that attests to the fact that `type` // is equal to itself. RefPtr createTypeEqualityWitness( - Type* /*type*/) + Type* type) { - SLANG_UNEXPECTED("unimplemented"); + RefPtr rs = new TypeEqualityWitness(); + rs->sub = type; + rs->sup = type; + return rs; } // If `sub` is a subtype of `sup`, then return a value that @@ -7141,4 +7153,8 @@ namespace Slang return subst; } + void checkDecl(SemanticsVisitor* visitor, Decl* decl) + { + visitor->checkDecl(decl); + } } -- cgit v1.2.3