From 43c146794aab638924d2ab838d10f8af2ebf02a7 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 5 Jun 2020 18:20:09 -0400 Subject: ASTNodes use MemoryArena (#1376) * Add a ASTBuilder to a Module Only construct on valid ASTBuilder (was being called on nullptr on occassion) * Add nodes to ASTBuilder. * Compiles with RefPtr removed from AST node types. * Initialize all AST node pointer variables in headers to nullptr; * Initialize AST node variables as nullptr. Make ASTBuilder keep a ref on node types. Make SyntaxParseCallback returns a NodeBase * Don't release canonicalType on dtor (managed by ASTBuilder). * Give ASTBuilders a name and id, to help in debugging. For now destroy the session TypeCache, to stop it holding things released when the compile request destroys ASTBuilders. * Moved the TypeCheckingCache over to Linkage from Session. * NodeBase no longer derived from RefObject. * Only add/dtor nodes that need destruction. First pass compile on linux. --- source/slang/slang-syntax.cpp | 134 +++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 67 deletions(-) (limited to 'source/slang/slang-syntax.cpp') diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index c78de91a5..06603547f 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -54,7 +54,7 @@ SourceLoc const& getDiagnosticPos(TypeExp const& typeExp) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Free functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -const RefPtr* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end) +Decl*const* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { switch (filterStyle) { @@ -99,7 +99,7 @@ const RefPtr* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, Memb return end; } -const RefPtr* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end, Index index) +Decl*const* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end, Index index) { switch (filterStyle) { @@ -156,7 +156,7 @@ const RefPtr* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, return nullptr; } -Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end) +Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { Index count = 0; switch (filterStyle) @@ -204,9 +204,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // RequirementWitness // - RequirementWitness::RequirementWitness(RefPtr val) + RequirementWitness::RequirementWitness(Val* val) : m_flavor(Flavor::val) - , m_obj(val) + , m_val(val) {} @@ -324,17 +324,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt - static RefPtr ExtractGenericArgType(RefPtr val) + static Type* ExtractGenericArgType(Val* val) { - auto type = val.as(); - SLANG_RELEASE_ASSERT(type.Ptr()); + auto type = as(val); + SLANG_RELEASE_ASSERT(type); return type; } - static RefPtr ExtractGenericArgInteger(RefPtr val) + static IntVal* ExtractGenericArgInteger(Val* val) { - auto intVal = val.as(); - SLANG_RELEASE_ASSERT(intVal.Ptr()); + auto intVal = as(val); + SLANG_RELEASE_ASSERT(intVal); return intVal; } @@ -359,30 +359,30 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // We are going to build up a list of substitutions that need // to be applied to the decl-ref to make it specialized. - RefPtr substsToApply; - RefPtr* link = &substsToApply; + Substitutions* substsToApply = nullptr; + Substitutions** link = &substsToApply; - RefPtr dd = declRef.getDecl(); + Decl* dd = declRef.getDecl(); for(;;) { - RefPtr childDecl = dd; - RefPtr parentDecl = dd->parentDecl; + Decl* childDecl = dd; + Decl* parentDecl = dd->parentDecl; if(!parentDecl) break; dd = parentDecl; - if(auto genericParentDecl = parentDecl.as()) + if(auto genericParentDecl = as(parentDecl)) { // Don't specialize any parameters of a generic. if(childDecl != genericParentDecl->inner) break; // We have a generic ancestor, but do we have an substitutions for it? - RefPtr foundSubst; + GenericSubstitution* foundSubst = nullptr; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - auto genSubst = s.as(); + auto genSubst = as(s); if(!genSubst) continue; @@ -397,7 +397,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(!foundSubst) { - RefPtr newSubst = createDefaultSubstitutionsForGeneric( + Substitutions* newSubst = createDefaultSubstitutionsForGeneric( astBuilder, genericParentDecl, nullptr); @@ -417,7 +417,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // TODO: need to figure out how to unify this with the logic // in the generic case... - RefPtr DeclRefType::create( + DeclRefType* DeclRefType::create( ASTBuilder* astBuilder, DeclRef declRef) { @@ -434,7 +434,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt GenericSubstitution* subst = nullptr; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - if(auto genericSubst = s.as()) + if(auto genericSubst = as(s)) { subst = genericSubst; break; @@ -561,7 +561,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt SLANG_UNEXPECTED("unhandled type"); } - RefPtr type = classInfo.createInstance(astBuilder); + NodeBase* type = classInfo.createInstance(astBuilder); if (!type) { SLANG_UNEXPECTED("constructor failure"); @@ -584,9 +584,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // - RefPtr findInnerMostGenericSubstitution(Substitutions* subst) + GenericSubstitution* findInnerMostGenericSubstitution(Substitutions* subst) { - for(RefPtr s = subst; s; s = s->outer) + for(Substitutions* s = subst; s; s = s->outer) { if(auto genericSubst = as(s)) return genericSubst; @@ -597,7 +597,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // DeclRefBase - RefPtr DeclRefBase::substitute(ASTBuilder* astBuilder, RefPtr type) const + Type* DeclRefBase::substitute(ASTBuilder* astBuilder, Type* type) const { // Note that type can be nullptr, and so this function can return nullptr (although only correctly when no substitutions) @@ -609,7 +609,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Otherwise we need to recurse on the type structure // and apply substitutions where it makes sense - return type->substitute(astBuilder, substitutions).as(); + return Slang::as(type->substitute(astBuilder, substitutions)); } DeclRefBase DeclRefBase::substitute(ASTBuilder* astBuilder, DeclRefBase declRef) const @@ -621,7 +621,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return declRef.substituteImpl(astBuilder, substitutions, &diff); } - RefPtr DeclRefBase::substitute(ASTBuilder* /* astBuilder*/, RefPtr expr) const + Expr* DeclRefBase::substitute(ASTBuilder* /* astBuilder*/, Expr* expr) const { // No substitutions? Easy. if (!substitutions) @@ -647,13 +647,13 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return nullptr; } - RefPtr findGlobalGenericSubst( - RefPtr substs, + GlobalGenericParamSubstitution* findGlobalGenericSubst( + Substitutions* substs, GlobalGenericParamDecl* paramDecl) { for(auto s = substs; s; s = s->outer) { - auto gSubst = s.as(); + auto gSubst = as(s); if(!gSubst) continue; @@ -666,22 +666,22 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return nullptr; } - RefPtr specializeSubstitutionsShallow( + Substitutions* specializeSubstitutionsShallow( ASTBuilder* astBuilder, - RefPtr substToSpecialize, - RefPtr substsToApply, - RefPtr restSubst, + Substitutions* substToSpecialize, + Substitutions* substsToApply, + Substitutions* restSubst, int* ioDiff) { SLANG_ASSERT(substToSpecialize); return substToSpecialize->applySubstitutionsShallow(astBuilder, substsToApply, restSubst, ioDiff); } - RefPtr specializeGlobalGenericSubstitutions( + Substitutions* specializeGlobalGenericSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr substsToSpecialize, - RefPtr substsToApply, + Substitutions* substsToSpecialize, + Substitutions* substsToApply, int* ioDiff, HashSet& ioParametersFound) { @@ -689,7 +689,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // a recursive case that skips the rest of the function. for(auto specSubst = substsToSpecialize; specSubst; specSubst = specSubst->outer) { - auto specGlobalGenericSubst = specSubst.as(); + auto specGlobalGenericSubst = as(specSubst); if(!specGlobalGenericSubst) continue; @@ -721,8 +721,8 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // We expect global generic substitutions to come at // the end of the list in all cases, so lets advance // until we see them. - RefPtr appGlobalGenericSubsts = substsToApply; - while(appGlobalGenericSubsts && !appGlobalGenericSubsts.as()) + Substitutions* appGlobalGenericSubsts = substsToApply; + while(appGlobalGenericSubsts && !as(appGlobalGenericSubsts)) appGlobalGenericSubsts = appGlobalGenericSubsts->outer; @@ -738,11 +738,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(ioParametersFound.Count() == 0) return appGlobalGenericSubsts; - RefPtr resultSubst; - RefPtr* link = &resultSubst; + Substitutions* resultSubst = nullptr; + Substitutions** link = &resultSubst; for(auto appSubst = appGlobalGenericSubsts; appSubst; appSubst = appSubst->outer) { - auto appGlobalGenericSubst = appSubst.as(); + auto appGlobalGenericSubst = as(appSubst); if(!appSubst) continue; @@ -750,7 +750,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(ioParametersFound.Contains(appGlobalGenericSubst->paramDecl)) continue; - RefPtr newSubst = astBuilder->create(); + GlobalGenericParamSubstitution* newSubst = astBuilder->create(); newSubst->paramDecl = appGlobalGenericSubst->paramDecl; newSubst->actualType = appGlobalGenericSubst->actualType; newSubst->constraintArgs = appGlobalGenericSubst->constraintArgs; @@ -762,11 +762,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return resultSubst; } - RefPtr specializeGlobalGenericSubstitutions( + Substitutions* specializeGlobalGenericSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr substsToSpecialize, - RefPtr substsToApply, + Substitutions* substsToSpecialize, + Substitutions* substsToApply, int* ioDiff) { // Keep track of any parameters already present in the @@ -778,11 +778,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Construct new substitutions to apply to a declaration, // based on a provided substitution set to be applied - RefPtr specializeSubstitutions( + Substitutions* specializeSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr substsToSpecialize, - RefPtr substsToApply, + Substitutions* substsToSpecialize, + Substitutions* substsToApply, int* ioDiff) { // No declaration? Then nothing to specialize. @@ -861,7 +861,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt substsToApply, &diff); - RefPtr firstSubst = astBuilder->create(); + GenericSubstitution* firstSubst = astBuilder->create(); firstSubst->genericDecl = ancestorGenericDecl; firstSubst->args = appGenericSubst->args; firstSubst->outer = restSubst; @@ -909,7 +909,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // for(auto s = substsToApply; s; s = s->outer) { - auto appThisTypeSubst = s.as(); + auto appThisTypeSubst = as(s); if(!appThisTypeSubst) continue; @@ -924,7 +924,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt substsToApply, &diff); - RefPtr firstSubst = astBuilder->create(); + ThisTypeSubstitution* firstSubst = astBuilder->create(); firstSubst->interfaceDecl = ancestorInterfaceDecl; firstSubst->witness = appThisTypeSubst->witness; firstSubst->outer = restSubst; @@ -1033,7 +1033,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Default is to apply the same set of substitutions/specializations // to the parent declaration as were applied to the child. - RefPtr substToApply = substitutions.substitutions; + Substitutions* substToApply = substitutions.substitutions; if(auto interfaceDecl = as(decl)) { @@ -1079,14 +1079,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // IntVal - IntegerLiteralValue getIntVal(RefPtr val) + IntegerLiteralValue getIntVal(IntVal* val) { if (auto constantVal = as(val)) { return constantVal->value; } SLANG_UNEXPECTED("needed a known integer value"); - return 0; + //return 0; } // @@ -1105,7 +1105,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Constructors for types - RefPtr getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType, IntVal* elementCount) @@ -1116,7 +1116,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return arrayType; } - RefPtr getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType) { @@ -1125,7 +1125,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return arrayType; } - RefPtr getNamedType( + NamedExpressionType* getNamedType( ASTBuilder* astBuilder, DeclRef const& declRef) { @@ -1135,11 +1135,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt } - RefPtr getFuncType( + FuncType* getFuncType( ASTBuilder* astBuilder, DeclRef const& declRef) { - RefPtr funcType = astBuilder->create(); + FuncType* funcType = astBuilder->create(); funcType->resultType = getResultType(astBuilder, declRef); for (auto paramDeclRef : getParameters(declRef)) @@ -1167,14 +1167,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return funcType; } - RefPtr getGenericDeclRefType( + GenericDeclRefType* getGenericDeclRefType( ASTBuilder* astBuilder, DeclRef const& declRef) { return astBuilder->create(declRef); } - RefPtr getNamespaceType( + NamespaceType* getNamespaceType( ASTBuilder* astBuilder, DeclRef const& declRef) { @@ -1183,17 +1183,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return type; } - RefPtr getSamplerStateType( + SamplerStateType* getSamplerStateType( ASTBuilder* astBuilder) { return astBuilder->create(); } - RefPtr findThisTypeSubstitution( + ThisTypeSubstitution* findThisTypeSubstitution( Substitutions* substs, InterfaceDecl* interfaceDecl) { - for(RefPtr s = substs; s; s = s->outer) + for(Substitutions* s = substs; s; s = s->outer) { auto thisTypeSubst = as(s); if(!thisTypeSubst) -- cgit v1.2.3