From 4b284daeb0cc3f6df0835befad4326c81abeb374 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 9 Jan 2018 13:26:42 -0800 Subject: Support nested generics fixes #362 --- source/slang/syntax.cpp | 61 +++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'source/slang/syntax.cpp') diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index c63dfc781..cdcb623ff 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1194,6 +1194,7 @@ void Type::accept(IValVisitor* visitor, void* extra) auto substSubst = new GenericSubstitution(); substSubst->genericDecl = genericDecl; substSubst->args = substArgs; + substSubst->outer = outerSubst.As(); return substSubst; } @@ -1897,27 +1898,9 @@ void Type::accept(IValVisitor* visitor, void* extra) SubstitutionSet substituteSubstitutions(SubstitutionSet oldSubst, SubstitutionSet subst, int * ioDiff) { - if (oldSubst) - oldSubst = oldSubst.substituteImpl(subst, ioDiff); - - // if oldSubst does not have ThisTypeSubst (which means `this_type` is free variable) - // and subst has a ThisTypeSubst (which means `this_type` is bound to a type), - // then copy that ThisTypeSubst over (to bind the this_type to the specified type) - SubstitutionSet newSubst = oldSubst; - insertGlobalGenericSubstitutions(newSubst, subst, ioDiff); - /*if (!hasThisTypeSubstitutions(oldSubst)) - { - auto thisTypeSubst = findThisTypeSubst(subst); - if (thisTypeSubst) - { - auto cpyThisTypeSubst = new ThisTypeSubstitution(); - cpyThisTypeSubst->sourceType = thisTypeSubst->sourceType; - insertSubstAtBottom(newSubst, cpyThisTypeSubst); - *ioDiff = 1; - } - }*/ - return newSubst; + return oldSubst.substituteImpl(subst, ioDiff); } + bool SubstitutionSet::Equals(SubstitutionSet substSet) const { if (genericSubstitutions) @@ -1951,8 +1934,8 @@ void Type::accept(IValVisitor* visitor, void* extra) rs.globalGenParamSubstitutions = globalGenParamSubstitutions->SubstituteImpl(subst, ioDiff).As(); if (thisTypeSubstitution) rs.thisTypeSubstitution = thisTypeSubstitution->SubstituteImpl(subst, ioDiff).As(); - else - rs.thisTypeSubstitution = subst.thisTypeSubstitution; + + insertGlobalGenericSubstitutions(rs, subst, ioDiff); return rs; } int SubstitutionSet::GetHashCode() const @@ -1966,5 +1949,39 @@ void Type::accept(IValVisitor* visitor, void* extra) rs = combineHash(rs, globalGenParamSubstitutions->GetHashCode()); return rs; } + + RefPtr cloneSubstitutionNonRecursive(RefPtr subst) + { + if (!subst) + return nullptr; + if (auto genSubst = dynamic_cast(subst.Ptr())) + { + RefPtr newSubst = new GenericSubstitution(); + newSubst->genericDecl = genSubst->genericDecl; + + for (auto arg : genSubst->args) + { + newSubst->args.Add(arg); + } + return newSubst; + } + else if (auto thisSubst = dynamic_cast(subst.Ptr())) + { + RefPtr newSubst = new ThisTypeSubstitution(); + newSubst->sourceType = thisSubst->sourceType; + return newSubst; + } + else if (auto genTypeSubst = dynamic_cast(subst.Ptr())) + { + RefPtr newSubst = new GlobalGenericParamSubstitution(); + newSubst->actualType = genTypeSubst->actualType; + newSubst->paramDecl = genTypeSubst->paramDecl; + newSubst->witnessTables = genTypeSubst->witnessTables; + return newSubst; + } + else + SLANG_UNREACHABLE("unimplemented cloneSubstitution"); + UNREACHABLE_RETURN(nullptr); + } } -- cgit v1.2.3 From 99f49e42fd3d55b0404261379d68dcca2b350209 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 13 Jan 2018 14:30:37 -0500 Subject: remove out-of-date changes --- source/slang/ir.cpp | 6 ++---- source/slang/syntax.cpp | 34 ---------------------------------- 2 files changed, 2 insertions(+), 38 deletions(-) (limited to 'source/slang/syntax.cpp') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 3abc2e2e3..46eff33e9 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3690,12 +3690,12 @@ namespace Slang cloneFunctionCommon(context, clonedFunc, originalFunc); // for now, clone all unreferenced witness tables - for (auto gv = context->getOriginalModule()->getFirstGlobalValue(); + /*for (auto gv = context->getOriginalModule()->getFirstGlobalValue(); gv; gv = gv->getNextValue()) { if (gv->op == kIROp_witness_table) cloneGlobalValue(context, (IRWitnessTable*)gv); - } + }*/ // We need to attach the layout information for // the entry point to this declaration, so that @@ -4746,9 +4746,7 @@ namespace Slang // // We will first find or construct a specialized version // of the callee funciton/ - auto originalFunc = dumpIRFunc(genericFunc); auto specFunc = getSpecializedFunc(sharedContext, genericFunc, specDeclRef); - auto specFuncStr = dumpIRFunc(specFunc); // // Then we will replace the use sites for the `specialize` // instruction with uses of the specialized function. diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index cdcb623ff..2ed10e138 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1949,39 +1949,5 @@ void Type::accept(IValVisitor* visitor, void* extra) rs = combineHash(rs, globalGenParamSubstitutions->GetHashCode()); return rs; } - - RefPtr cloneSubstitutionNonRecursive(RefPtr subst) - { - if (!subst) - return nullptr; - if (auto genSubst = dynamic_cast(subst.Ptr())) - { - RefPtr newSubst = new GenericSubstitution(); - newSubst->genericDecl = genSubst->genericDecl; - - for (auto arg : genSubst->args) - { - newSubst->args.Add(arg); - } - return newSubst; - } - else if (auto thisSubst = dynamic_cast(subst.Ptr())) - { - RefPtr newSubst = new ThisTypeSubstitution(); - newSubst->sourceType = thisSubst->sourceType; - return newSubst; - } - else if (auto genTypeSubst = dynamic_cast(subst.Ptr())) - { - RefPtr newSubst = new GlobalGenericParamSubstitution(); - newSubst->actualType = genTypeSubst->actualType; - newSubst->paramDecl = genTypeSubst->paramDecl; - newSubst->witnessTables = genTypeSubst->witnessTables; - return newSubst; - } - else - SLANG_UNREACHABLE("unimplemented cloneSubstitution"); - UNREACHABLE_RETURN(nullptr); - } } -- cgit v1.2.3