From ef2f92fee8463fff2bf66f07eac228ff38df319f Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Sun, 21 Jan 2018 17:23:03 -0800 Subject: Trying to get generic extensions to work - Don't drop specializations on a method when adding it to requirement dictionary - Handle extension declarations under a generic when emitting to IR --- source/slang/check.cpp | 2 +- source/slang/lower-to-ir.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 52558ee15..e2d519a4c 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1708,7 +1708,7 @@ namespace Slang { // TODO: actually implement matching here. For now we'll // just pretend that things are satisfied in order to make progress.. - requirementDict.AddIfNotExists(requiredMemberDeclRef, DeclRef(memberDecl, nullptr)); + requirementDict.AddIfNotExists(requiredMemberDeclRef, memberDecl); return true; } diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 5d710725a..42d6dc303 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -3734,6 +3734,8 @@ struct DeclLoweringVisitor : DeclVisitor LoweredValInfo visitGenericDecl(GenericDecl * genDecl) { + // TODO: Should this just always visit/lower the inner decl? + if (auto innerFuncDecl = genDecl->inner->As()) return lowerFuncDecl(innerFuncDecl); else if (auto innerStructDecl = genDecl->inner->As()) @@ -3741,6 +3743,10 @@ struct DeclLoweringVisitor : DeclVisitor visitAggTypeDecl(innerStructDecl); return LoweredValInfo(); } + else if( auto extensionDecl = genDecl->inner->As() ) + { + return visitExtensionDecl(extensionDecl); + } SLANG_RELEASE_ASSERT(false); UNREACHABLE_RETURN(LoweredValInfo()); } -- cgit v1.2.3 From f114c377f2cb7458fb8555151752f21d4d824e49 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Sun, 21 Jan 2018 18:03:35 -0800 Subject: A hacky fix for specializing methods from extensions If we don't find the generic we expect in the first pass during IR specialization, then we check for the special case where we are trying to specialize something from a generic extension, using the type being extended. We assume that the generic parameter lists match (that part is the huge hack), and collect the arguments as if they were for the extension instead of the type. This will break when/if we ever have generic extensions with parameter lists that don't match the type being extended. --- source/slang/ir.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 1d3c91979..b965f908c 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -4510,6 +4510,19 @@ namespace Slang } } + if( !newGenericDecl ) + { + if(auto gd = dynamic_cast(newDecl)) + { + if( auto ed = gd->inner.As() ) + { + // TODO: we should confirm that it is an extension for the correct type... + + newGenericDecl = gd; + } + } + } + SLANG_ASSERT(newGenericDecl); RefPtr newSubst = new GenericSubstitution(); -- cgit v1.2.3