diff options
| author | Yong He <yonghe@outlook.com> | 2023-01-30 19:24:09 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-30 19:24:09 -0800 |
| commit | 499b0253c224e68ceed6e5b6b1ee9cd7d65aad0f (patch) | |
| tree | 4c570a36d305c8909d633183694e0d1225f044c2 /source/slang/slang-check-decl.cpp | |
| parent | 134dd7eb26fc7988ae13559d276cbf337b4b9d27 (diff) | |
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
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<ArrayExpressionType>(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<ArrayExpressionType>(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<ArrayExpressionType>(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); |
