From 499b0253c224e68ceed6e5b6b1ee9cd7d65aad0f Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 30 Jan 2023 19:24:09 -0800 Subject: Make ArrayExpressionType a DeclRefType and define its autodiff extension in stdlib. (#2615) * Allow array parameters in forward diff. * Use type canonicalization instead of coersion. * Reimplement array type. * Fix. * Update test case. --------- Co-authored-by: Yong He --- source/slang/slang-check-decl.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 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 5add89312..9bda6c3e7 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -955,17 +955,14 @@ namespace Slang } } - static bool isUnsizedArrayType(Type* type) + bool isUnsizedArrayType(Type* type) { // Not an array? auto arrayType = as(type); if (!arrayType) return false; // Explicit element count given? - auto elementCount = arrayType->arrayLength; - if (elementCount) return true; - - return true; + return arrayType->isUnsized(); } bool SemanticsVisitor::shouldSkipChecking(Decl* decl, DeclCheckState state) @@ -3304,7 +3301,7 @@ namespace Slang { arg = synth.emitIndexExpr(arg, synth.emitVarExpr(indexVar)); } - auto assignStmt = _synthesizeMemberAssignMemberHelper(synth, funcName, arrayType->baseType, innerLeft, _Move(args), nestingLevel + 1); + auto assignStmt = _synthesizeMemberAssignMemberHelper(synth, funcName, arrayType->getElementType(), innerLeft, _Move(args), nestingLevel + 1); synth.popScope(); if (!assignStmt) return nullptr; @@ -5986,17 +5983,19 @@ namespace Slang if (!arrayType) return; // Explicit element count given? - auto elementCount = arrayType->arrayLength; - if (elementCount) return; + if (!isUnsizedArrayType(arrayType)) + return; // No initializer? auto initExpr = varDecl->initExpr; if(!initExpr) return; + IntVal* elementCount = nullptr; + // Is the type of the initializer an array type? if(auto arrayInitType = as(initExpr->type)) { - elementCount = arrayInitType->arrayLength; + elementCount = arrayInitType->getElementCount(); } else { @@ -6008,7 +6007,7 @@ namespace Slang // and install it into our type. varDecl->type.type = getArrayType( m_astBuilder, - arrayType->baseType, + arrayType->getElementType(), elementCount); } @@ -6017,8 +6016,7 @@ namespace Slang auto arrayType = as(varDecl->type); if (!arrayType) return; - auto elementCount = arrayType->arrayLength; - if (!elementCount) + if (arrayType->isUnsized()) { // Note(tfoley): For now we allow arrays of unspecified size // everywhere, because some source languages (e.g., GLSL) @@ -6030,6 +6028,7 @@ namespace Slang } // TODO(tfoley): How to handle the case where bound isn't known? + auto elementCount = arrayType->getElementCount(); if (GetMinBound(elementCount) <= 0) { getSink()->diagnose(varDecl, Diagnostics::invalidArraySize); -- cgit v1.2.3