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-check-decl.cpp | 89 ++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'source/slang/slang-check-decl.cpp') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 8486bf107..b69c8cf0d 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -42,7 +42,7 @@ namespace Slang void visitDecl(Decl*) {} void visitDeclGroup(DeclGroup*) {} - void checkVarDeclCommon(RefPtr varDecl); + void checkVarDeclCommon(VarDeclBase* varDecl); void visitVarDecl(VarDecl* varDecl) { @@ -149,7 +149,7 @@ namespace Slang void visitDecl(Decl*) {} void visitDeclGroup(DeclGroup*) {} - void checkVarDeclCommon(RefPtr varDecl); + void checkVarDeclCommon(VarDeclBase* varDecl); void visitVarDecl(VarDecl* varDecl) { @@ -290,7 +290,7 @@ namespace Slang SemanticsVisitor* sema, DiagnosticSink* sink, DeclRef declRef, - RefPtr* outTypeResult, + Type** outTypeResult, SourceLoc loc) { if( sema ) @@ -452,14 +452,14 @@ namespace Slang DeclRef declRef, SourceLoc loc) { - RefPtr typeResult; + Type* typeResult = nullptr; return getTypeForDeclRef(astBuilder, nullptr, nullptr, declRef, &typeResult, loc); } DeclRef ApplyExtensionToType( SemanticsVisitor* semantics, ExtensionDecl* extDecl, - RefPtr type) + Type* type) { if(!semantics) return DeclRef(); @@ -467,12 +467,12 @@ namespace Slang return semantics->ApplyExtensionToType(extDecl, type); } - RefPtr createDefaultSubstitutionsForGeneric( + GenericSubstitution* createDefaultSubstitutionsForGeneric( ASTBuilder* astBuilder, GenericDecl* genericDecl, - RefPtr outerSubst) + Substitutions* outerSubst) { - RefPtr genericSubst = astBuilder->create(); + GenericSubstitution* genericSubst = astBuilder->create(); genericSubst->genericDecl = genericDecl; genericSubst->outer = outerSubst; @@ -493,7 +493,7 @@ namespace Slang { if (auto genericTypeConstraintDecl = as(mm)) { - RefPtr witness = astBuilder->create(); + DeclaredSubtypeWitness* witness = astBuilder->create(); witness->declRef = DeclRef(genericTypeConstraintDecl, outerSubst); witness->sub = genericTypeConstraintDecl->sub.type; witness->sup = genericTypeConstraintDecl->sup.type; @@ -521,7 +521,7 @@ namespace Slang if(decl != genericDecl->inner) return outerSubstSet; - RefPtr genericSubst = createDefaultSubstitutionsForGeneric( + GenericSubstitution* genericSubst = createDefaultSubstitutionsForGeneric( astBuilder, genericDecl, outerSubstSet.substitutions); @@ -775,7 +775,7 @@ namespace Slang return true; } - void SemanticsDeclHeaderVisitor::checkVarDeclCommon(RefPtr varDecl) + void SemanticsDeclHeaderVisitor::checkVarDeclCommon(VarDeclBase* varDecl) { // A variable that didn't have an explicit type written must // have its type inferred from the initial-value expression. @@ -851,7 +851,7 @@ namespace Slang } } - void SemanticsDeclBodyVisitor::checkVarDeclCommon(RefPtr varDecl) + void SemanticsDeclBodyVisitor::checkVarDeclCommon(VarDeclBase* varDecl) { if (auto initExpr = varDecl->initExpr) { @@ -1093,7 +1093,7 @@ namespace Slang // TODO: This could be factored into another visitor pass // that fits more with the standard checking below. // - for(auto& importDecl : moduleDecl->getMembersOfType()) + for(auto importDecl : moduleDecl->getMembersOfType()) { ensureDecl(importDecl, DeclCheckState::Checked); } @@ -1263,13 +1263,13 @@ namespace Slang // be compared). return doesMemberSatisfyRequirement( - DeclRef(genDecl.getDecl()->inner.Ptr(), genDecl.substitutions), - DeclRef(requirementGenDecl.getDecl()->inner.Ptr(), requirementGenDecl.substitutions), + DeclRef(genDecl.getDecl()->inner, genDecl.substitutions), + DeclRef(requirementGenDecl.getDecl()->inner, requirementGenDecl.substitutions), witnessTable); } bool SemanticsVisitor::doesTypeSatisfyAssociatedTypeRequirement( - RefPtr satisfyingType, + Type* satisfyingType, DeclRef requiredAssociatedTypeDeclRef, RefPtr witnessTable) { @@ -1426,6 +1426,8 @@ namespace Slang DeclRef requiredMemberDeclRef, RefPtr witnessTable) { + SLANG_UNUSED(interfaceDeclRef) + // The goal of this function is to find a suitable // value to satisfy the requirement. // @@ -1608,7 +1610,7 @@ namespace Slang // // TODO: need to decide if a this-type substitution is needed here. // It probably it. - RefPtr targetType = DeclRefType::create(m_astBuilder, interfaceDeclRef); + Type* targetType = DeclRefType::create(m_astBuilder, interfaceDeclRef); auto extDeclRef = ApplyExtensionToType(candidateExt, targetType); if(!extDeclRef) continue; @@ -1992,8 +1994,9 @@ namespace Slang // * come first in the list of base types // Index inheritanceClauseCounter = 0; - RefPtr tagType; - InheritanceDecl* tagTypeInheritanceDecl = nullptr; + + Type* tagType = nullptr; + InheritanceDecl* tagTypeInheritanceDecl = nullptr; for(auto inheritanceDecl : decl->getMembersOfType()) { Index inheritanceClauseIndex = inheritanceClauseCounter++; @@ -2088,9 +2091,9 @@ namespace Slang // seems like the best place to do it. { // First, look up the type of the `__EnumType` interface. - RefPtr enumTypeType = getASTBuilder()->getEnumTypeType(); + Type* enumTypeType = getASTBuilder()->getEnumTypeType(); - RefPtr enumConformanceDecl = m_astBuilder->create(); + InheritanceDecl* enumConformanceDecl = m_astBuilder->create(); enumConformanceDecl->parentDecl = decl; enumConformanceDecl->loc = decl->loc; enumConformanceDecl->base.type = getASTBuilder()->getEnumTypeType(); @@ -2106,7 +2109,7 @@ namespace Slang Name* tagAssociatedTypeName = getSession()->getNameObj("__Tag"); Decl* tagAssociatedTypeDecl = nullptr; - if(auto enumTypeTypeDeclRefType = enumTypeType.dynamicCast()) + if(auto enumTypeTypeDeclRefType = dynamicCast(enumTypeType)) { if(auto enumTypeTypeInterfaceDecl = as(enumTypeTypeDeclRefType->declRef.getDecl())) { @@ -2174,7 +2177,7 @@ namespace Slang // the tag value for a successor case that doesn't // provide an explicit tag. - RefPtr explicitTagVal = TryConstantFoldExpr(explicitTagValExpr); + IntVal* explicitTagVal = TryConstantFoldExpr(explicitTagValExpr); if(explicitTagVal) { if(auto constIntVal = as(explicitTagVal)) @@ -2198,7 +2201,7 @@ namespace Slang { // This tag has no initializer, so it should use // the default tag value we are tracking. - RefPtr tagValExpr = m_astBuilder->create(); + IntegerLiteralExpr* tagValExpr = m_astBuilder->create(); tagValExpr->loc = caseDecl->loc; tagValExpr->type = QualType(tagType); tagValExpr->value = defaultTag; @@ -2315,7 +2318,7 @@ namespace Slang bool SemanticsVisitor::doGenericSignaturesMatch( GenericDecl* left, GenericDecl* right, - RefPtr* outSubstRightToLeft) + GenericSubstitution** outSubstRightToLeft) { // Our first goal here is to determine if `left` and // `right` have equivalent lists of explicit @@ -2577,10 +2580,10 @@ namespace Slang return true; } - RefPtr SemanticsVisitor::createDummySubstitutions( + GenericSubstitution* SemanticsVisitor::createDummySubstitutions( GenericDecl* genericDecl) { - RefPtr subst = m_astBuilder->create(); + GenericSubstitution* subst = m_astBuilder->create(); subst->genericDecl = genericDecl; for (auto dd : genericDecl->members) { @@ -2703,7 +2706,7 @@ namespace Slang // Then we will compare the parameter types of `foo2` // against the specialization `foo1`. // - RefPtr subst; + GenericSubstitution* subst = nullptr; if(!doGenericSignaturesMatch(newGenericDecl, oldGenericDecl, &subst)) return SLANG_OK; @@ -2982,7 +2985,7 @@ namespace Slang void SemanticsDeclHeaderVisitor::checkCallableDeclCommon(CallableDecl* decl) { - for(auto& paramDecl : decl->getParameters()) + for(auto paramDecl : decl->getParameters()) { ensureDecl(paramDecl, DeclCheckState::ReadyForReference); } @@ -3004,7 +3007,7 @@ namespace Slang checkCallableDeclCommon(funcDecl); } - IntegerLiteralValue SemanticsVisitor::GetMinBound(RefPtr val) + IntegerLiteralValue SemanticsVisitor::GetMinBound(IntVal* val) { if (auto constantVal = as(val)) return constantVal->value; @@ -3145,7 +3148,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::calcThisType(DeclRef declRef) + Type* SemanticsVisitor::calcThisType(DeclRef declRef) { if( auto interfaceDeclRef = declRef.as() ) { @@ -3154,7 +3157,7 @@ namespace Slang // conform to the interface and fill in its // requirements. // - RefPtr thisType = m_astBuilder->create(); + ThisType* thisType = m_astBuilder->create(); thisType->interfaceDeclRef = interfaceDeclRef; return thisType; } @@ -3203,7 +3206,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::calcThisType(Type* type) + Type* SemanticsVisitor::calcThisType(Type* type) { if( auto declRefType = as(type) ) { @@ -3215,7 +3218,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::findResultTypeForConstructorDecl(ConstructorDecl* decl) + Type* SemanticsVisitor::findResultTypeForConstructorDecl(ConstructorDecl* decl) { // We want to look at the parent of the declaration, // but if the declaration is generic, the parent will be @@ -3269,7 +3272,7 @@ namespace Slang if(!anyAccessors) { - RefPtr getterDecl = m_astBuilder->create(); + GetterDecl* getterDecl = m_astBuilder->create(); getterDecl->loc = decl->loc; getterDecl->parentDecl = decl; @@ -3310,7 +3313,7 @@ namespace Slang DeclRef SemanticsVisitor::ApplyExtensionToType( ExtensionDecl* extDecl, - RefPtr type) + Type* type) { DeclRef extDeclRef = makeDeclRef(extDecl); @@ -3339,7 +3342,7 @@ namespace Slang } // Now extract the target type from our (possibly specialized) extension decl-ref. - RefPtr targetType = getTargetType(m_astBuilder, extDeclRef); + Type* targetType = getTargetType(m_astBuilder, extDeclRef); // As a bit of a kludge here, if the target type of the extension is // an interface, and the `type` we are trying to match up has a this-type @@ -3360,17 +3363,17 @@ namespace Slang { // Looks like we have a match in the types, // now let's see if we have a this-type substitution. - if(auto appThisTypeSubst = appInterfaceDeclRef.substitutions.substitutions.as()) + if(auto appThisTypeSubst = as(appInterfaceDeclRef.substitutions.substitutions)) { if(appThisTypeSubst->interfaceDecl == appInterfaceDeclRef.getDecl()) { // The type we want to apply to has a this-type substitution, // and (by construction) the target type currently does not. // - SLANG_ASSERT(!targetInterfaceDeclRef.substitutions.substitutions.as()); + SLANG_ASSERT(!as(targetInterfaceDeclRef.substitutions.substitutions)); // We will create a new substitution to apply to the target type. - RefPtr newTargetSubst = m_astBuilder->create(); + ThisTypeSubstitution* newTargetSubst = m_astBuilder->create(); newTargetSubst->interfaceDecl = appThisTypeSubst->interfaceDecl; newTargetSubst->witness = appThisTypeSubst->witness; newTargetSubst->outer = targetInterfaceDeclRef.substitutions.substitutions; @@ -3385,7 +3388,7 @@ namespace Slang // references to the target type of the extension // declaration have a chance to resolve the way we want them to. - RefPtr newExtSubst = m_astBuilder->create(); + ThisTypeSubstitution* newExtSubst = m_astBuilder->create(); newExtSubst->interfaceDecl = appThisTypeSubst->interfaceDecl; newExtSubst->witness = appThisTypeSubst->witness; newExtSubst->outer = extDeclRef.substitutions.substitutions; @@ -3425,7 +3428,7 @@ namespace Slang QualType SemanticsVisitor::GetTypeForDeclRef(DeclRef declRef, SourceLoc loc) { - RefPtr typeResult; + Type* typeResult = nullptr; return getTypeForDeclRef( m_astBuilder, this, @@ -3462,7 +3465,7 @@ namespace Slang if (!importDecl->hasModifier()) continue; - importModuleIntoScope(scope, importDecl->importedModuleDecl.Ptr()); + importModuleIntoScope(scope, importDecl->importedModuleDecl); } } -- cgit v1.2.3