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-shader.cpp | 48 +++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'source/slang/slang-check-shader.cpp') diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index 80860074d..fcb9b1618 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -604,7 +604,7 @@ namespace Slang for( auto globalDecl : moduleDecl->members ) { - if(auto globalVar = globalDecl.as()) + if(auto globalVar = as(globalDecl)) { // We do not want to consider global variable declarations // that don't represents shader parameters. This includes @@ -616,7 +616,7 @@ namespace Slang // At this point we know we have a global shader parameter. ShaderParamInfo shaderParamInfo; - shaderParamInfo.paramDeclRef = makeDeclRef(globalVar.Ptr()); + shaderParamInfo.paramDeclRef = makeDeclRef(globalVar); // We need to consider what specialization parameters // are introduced by this shader parameter. This step @@ -628,7 +628,7 @@ namespace Slang getLinkage()->getASTBuilder(), shaderParamInfo, m_specializationParams, - makeDeclRef(globalVar.Ptr())); + makeDeclRef(globalVar)); m_shaderParams.add(shaderParamInfo); } @@ -968,10 +968,10 @@ namespace Slang { case SpecializationParam::Flavor::GenericType: { - auto genericTypeParamDecl = param.object.as(); + auto genericTypeParamDecl = as(param.object); SLANG_ASSERT(genericTypeParamDecl); - RefPtr argType = as(arg.val); + Type* argType = as(arg.val); if(!argType) { sink->diagnose(param.loc, Diagnostics::expectedTypeForSpecializationArg, genericTypeParamDecl); @@ -999,7 +999,7 @@ namespace Slang // global generic type parameter is a reference to *another* global generic // type parameter, since that should always be an error. // - if( auto argDeclRefType = argType.as() ) + if( auto argDeclRefType = as(argType) ) { auto argDeclRef = argDeclRefType->declRef; if(auto argGenericParamDeclRef = argDeclRef.as()) @@ -1060,10 +1060,10 @@ namespace Slang case SpecializationParam::Flavor::ExistentialType: { - auto interfaceType = param.object.as(); + auto interfaceType = as(param.object); SLANG_ASSERT(interfaceType); - RefPtr argType = as(arg.val); + Type* argType = as(arg.val); if(!argType) { sink->diagnose(param.loc, Diagnostics::expectedTypeForSpecializationArg, interfaceType); @@ -1091,13 +1091,13 @@ namespace Slang case SpecializationParam::Flavor::GenericValue: { - auto paramDecl = param.object.as(); + auto paramDecl = as(param.object); SLANG_ASSERT(paramDecl); // Now we need to check that the argument `Val` has the // appropriate type expected by the parameter. - RefPtr intVal = as(arg.val); + IntVal* intVal = as(arg.val); if(!intVal) { sink->diagnose(param.loc, Diagnostics::expectedValueOfTypeForSpecializationArg, paramDecl->getType(), paramDecl); @@ -1123,7 +1123,7 @@ namespace Slang static void _extractSpecializationArgs( ComponentType* componentType, - List> const& argExprs, + List const& argExprs, List& outArgs, DiagnosticSink* sink) { @@ -1175,7 +1175,7 @@ namespace Slang auto genericDeclRef = m_funcDeclRef.getParent().as(); SLANG_ASSERT(genericDeclRef); // otherwise we wouldn't have generic parameters - RefPtr genericSubst = getLinkage()->getASTBuilder()->create(); + GenericSubstitution* genericSubst = getLinkage()->getASTBuilder()->create(); genericSubst->outer = genericDeclRef.substitutions.substitutions; genericSubst->genericDecl = genericDeclRef.getDecl(); @@ -1235,8 +1235,8 @@ namespace Slang // TODO: We need to handle all the cases of "flavor" for the `param`s (not just types) - auto paramType = param.object.as(); - auto argType = specializationArg.val.as(); + auto paramType = as(param.object); + auto argType = as(specializationArg.val); auto witness = visitor.tryGetSubtypeWitness(argType, paramType); if (!witness) @@ -1260,7 +1260,7 @@ namespace Slang /// Create a specialization an existing entry point based on specialization argument expressions. RefPtr createSpecializedEntryPoint( EntryPoint* unspecializedEntryPoint, - List> const& argExprs, + List const& argExprs, DiagnosticSink* sink) { // We need to convert all of the `Expr` arguments @@ -1316,7 +1316,7 @@ namespace Slang void parseSpecializationArgStrings( EndToEndCompileRequest* endToEndReq, List const& genericArgStrings, - List>& outGenericArgs) + List& outGenericArgs) { auto unspecialiedProgram = endToEndReq->getUnspecializedGlobalComponentType(); @@ -1343,7 +1343,7 @@ namespace Slang // for(auto name : genericArgStrings) { - RefPtr argExpr = linkage->parseTermString(name, scope); + Expr* argExpr = linkage->parseTermString(name, scope); argExpr = semantics.CheckTerm(argExpr); if(!argExpr) @@ -1378,7 +1378,7 @@ namespace Slang ExpandedSpecializationArgs specializationArgs; for( Int aa = 0; aa < argCount; ++aa ) { - auto paramType = specializationParams[aa].object.as(); + auto paramType = as(specializationParams[aa].object); auto argType = args[aa]; ExpandedSpecializationArg arg; @@ -1387,7 +1387,7 @@ namespace Slang specializationArgs.add(arg); } - RefPtr specializedType = m_astBuilder->create(); + ExistentialSpecializedType* specializedType = m_astBuilder->create(); specializedType->baseType = unspecializedType; specializedType->args = specializationArgs; @@ -1400,7 +1400,7 @@ namespace Slang static RefPtr _createSpecializedProgramImpl( Linkage* linkage, ComponentType* unspecializedProgram, - List> const& specializationArgExprs, + List const& specializationArgExprs, DiagnosticSink* sink) { // If there are no specialization arguments, @@ -1455,12 +1455,14 @@ namespace Slang EndToEndCompileRequest::EntryPointInfo const& entryPointInfo) { auto sink = endToEndReq->getSink(); - auto entryPointFuncDecl = unspecializedEntryPoint->getFuncDecl(); + + // TODO(JS): Not used + //auto entryPointFuncDecl = unspecializedEntryPoint->getFuncDecl(); // If the user specified generic arguments for the entry point, // then we will need to parse the arguments first. // - List> specializationArgExprs; + List specializationArgExprs; parseSpecializationArgStrings( endToEndReq, entryPointInfo.specializationArgStrings, @@ -1504,7 +1506,7 @@ namespace Slang // provided via the API, so that we can match them // against what was declared in the program. // - List> globalSpecializationArgs; + List globalSpecializationArgs; parseSpecializationArgStrings( endToEndReq, endToEndReq->globalSpecializationArgStrings, -- cgit v1.2.3