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-conversion.cpp | 98 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'source/slang/slang-check-conversion.cpp') diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index c4e809025..ba4a9b8d9 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -24,7 +24,7 @@ namespace Slang } bool SemanticsVisitor::isEffectivelyScalarForInitializerLists( - RefPtr type) + Type* type) { if(as(type)) return false; if(as(type)) return false; @@ -58,8 +58,8 @@ namespace Slang } bool SemanticsVisitor::shouldUseInitializerDirectly( - RefPtr toType, - RefPtr fromExpr) + Type* toType, + Expr* fromExpr) { // A nested initializer list should always be used directly. // @@ -89,9 +89,9 @@ namespace Slang } bool SemanticsVisitor::_readValueFromInitializerList( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr, + Type* toType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr, UInt &ioInitArgIndex) { // First, we will check if we have run out of arguments @@ -152,9 +152,9 @@ namespace Slang } bool SemanticsVisitor::_readAggregateValueFromInitializerList( - RefPtr inToType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr, + Type* inToType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr, UInt &ioArgIndex) { auto toType = inToType; @@ -162,7 +162,7 @@ namespace Slang // In the case where we need to build a result expression, // we will collect the new arguments here - List> coercedArgs; + List coercedArgs; if(isEffectivelyScalarForInitializerLists(toType)) { @@ -215,7 +215,7 @@ namespace Slang for(UInt ee = 0; ee < elementCount; ++ee) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toElementType, outToExpr ? &coercedArg : nullptr, @@ -263,7 +263,7 @@ namespace Slang for(UInt ee = 0; ee < elementCount; ++ee) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toElementType, outToExpr ? &coercedArg : nullptr, @@ -289,7 +289,7 @@ namespace Slang UInt elementCount = 0; while(ioArgIndex < argCount) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toElementType, outToExpr ? &coercedArg : nullptr, @@ -352,7 +352,7 @@ namespace Slang for(UInt rr = 0; rr < rowCount; ++rr) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toRowType, outToExpr ? &coercedArg : nullptr, @@ -380,7 +380,7 @@ namespace Slang // for(auto fieldDeclRef : getMembersOfType(toStructDeclRef, MemberFilterStyle::Instance)) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( getType(m_astBuilder, fieldDeclRef), outToExpr ? &coercedArg : nullptr, @@ -429,9 +429,9 @@ namespace Slang } bool SemanticsVisitor::_coerceInitializerList( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr) + Type* toType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr) { UInt argCount = fromInitializerListExpr->args.getCount(); UInt argIndex = 0; @@ -454,9 +454,9 @@ namespace Slang } bool SemanticsVisitor::_failedCoercion( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromExpr) + Type* toType, + Expr** outToExpr, + Expr* fromExpr) { if(outToExpr) { @@ -478,10 +478,10 @@ namespace Slang } bool SemanticsVisitor::_coerce( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromType, - RefPtr fromExpr, + Type* toType, + Expr** outToExpr, + Type* fromType, + Expr* fromExpr, ConversionCost* outCost) { // An important and easy case is when the "to" and "from" types are equal. @@ -571,7 +571,7 @@ namespace Slang // ConversionCost subCost = kConversionCost_None; - RefPtr derefExpr; + DerefExpr* derefExpr = nullptr; if(outToExpr) { derefExpr = m_astBuilder->create(); @@ -754,8 +754,8 @@ namespace Slang } bool SemanticsVisitor::canCoerce( - RefPtr toType, - RefPtr fromType, + Type* toType, + Type* fromType, ConversionCost* outCost) { // As an optimization, we will maintain a cache of conversion results @@ -764,11 +764,11 @@ namespace Slang bool shouldAddToCache = false; ConversionCost cost; - TypeCheckingCache* typeCheckingCache = getSession()->getTypeCheckingCache(); + TypeCheckingCache* typeCheckingCache = getLinkage()->getTypeCheckingCache(); BasicTypeKeyPair cacheKey; - cacheKey.type1 = makeBasicTypeKey(toType.Ptr()); - cacheKey.type2 = makeBasicTypeKey(fromType.Ptr()); + cacheKey.type1 = makeBasicTypeKey(toType); + cacheKey.type2 = makeBasicTypeKey(fromType); if( cacheKey.isValid()) { @@ -811,16 +811,16 @@ namespace Slang return rs; } - RefPtr SemanticsVisitor::createImplicitCastExpr() + TypeCastExpr* SemanticsVisitor::createImplicitCastExpr() { return m_astBuilder->create(); } - RefPtr SemanticsVisitor::CreateImplicitCastExpr( - RefPtr toType, - RefPtr fromExpr) + Expr* SemanticsVisitor::CreateImplicitCastExpr( + Type* toType, + Expr* fromExpr) { - RefPtr castExpr = createImplicitCastExpr(); + TypeCastExpr* castExpr = createImplicitCastExpr(); auto typeType = m_astBuilder->getTypeType(toType); @@ -835,12 +835,12 @@ namespace Slang return castExpr; } - RefPtr SemanticsVisitor::createCastToSuperTypeExpr( - RefPtr toType, - RefPtr fromExpr, - RefPtr witness) + Expr* SemanticsVisitor::createCastToSuperTypeExpr( + Type* toType, + Expr* fromExpr, + Val* witness) { - RefPtr expr = m_astBuilder->create(); + CastToSuperTypeExpr* expr = m_astBuilder->create(); expr->loc = fromExpr->loc; expr->type = QualType(toType); expr->valueArg = fromExpr; @@ -848,16 +848,16 @@ namespace Slang return expr; } - RefPtr SemanticsVisitor::coerce( - RefPtr toType, - RefPtr fromExpr) + Expr* SemanticsVisitor::coerce( + Type* toType, + Expr* fromExpr) { - RefPtr expr; + Expr* expr = nullptr; if (!_coerce( toType, &expr, - fromExpr->type.Ptr(), - fromExpr.Ptr(), + fromExpr->type, + fromExpr, nullptr)) { // Note(tfoley): We don't call `CreateErrorExpr` here, because that would @@ -872,8 +872,8 @@ namespace Slang } bool SemanticsVisitor::canConvertImplicitly( - RefPtr toType, - RefPtr fromType) + Type* toType, + Type* fromType) { // Can we convert at all? ConversionCost conversionCost; -- cgit v1.2.3