diff options
| author | Yong He <yonghe@outlook.com> | 2025-07-21 21:35:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 04:35:44 +0000 |
| commit | 9d47a352960efd71494c7dfa0918debd5b405077 (patch) | |
| tree | f0acf898cb5c4de8a1951ac8010168b119bf94ff /source | |
| parent | 9adac4069fbcc7ce5bea2c42d19c61eb1dcd7f25 (diff) | |
Fix Conditioanl<T, false> fields with a semantic. (#7855)
* Fix Conditioanl<T, false> fields with a semantic.
* Add unit test.
* Fix test.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-impl.h | 19 | ||||
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 20 | ||||
| -rw-r--r-- | source/slang/slang-check-type.cpp | 9 | ||||
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 25 |
4 files changed, 59 insertions, 14 deletions
diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 5c6be2665..81dca7312 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -1444,7 +1444,18 @@ public: Type* ExtractGenericArgType(Expr* exp); - IntVal* ExtractGenericArgInteger(Expr* exp, Type* genericParamType, DiagnosticSink* sink); + enum class ConstantFoldingKind + { + CompileTime, + LinkTime, + SpecializationConstant + }; + + IntVal* ExtractGenericArgInteger( + Expr* exp, + Type* genericParamType, + ConstantFoldingKind kind, + DiagnosticSink* sink); IntVal* ExtractGenericArgInteger(Expr* exp, Type* genericParamType); Val* ExtractGenericArgVal(Expr* exp); @@ -2184,12 +2195,6 @@ public: Expr* checkPredicateExpr(Expr* expr); - enum class ConstantFoldingKind - { - CompileTime, - LinkTime, - SpecializationConstant - }; Expr* checkExpressionAndExpectIntegerConstant( Expr* expr, IntVal** outIntVal, diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 52b0ef5bc..18fb9798b 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -270,12 +270,31 @@ bool SemanticsVisitor::TryCheckOverloadCandidateVisibility( return true; } +static bool isArrayDecl(Decl* decl) +{ + if (auto magicMod = decl->findModifier<MagicTypeModifier>()) + { + if (magicMod->magicNodeType.getTag() == ASTNodeType::ArrayExpressionType) + return true; + } + return false; +} + bool SemanticsVisitor::TryCheckGenericOverloadCandidateTypes( OverloadResolveContext& context, OverloadCandidate& candidate) { auto genericDeclRef = candidate.item.declRef.as<GenericDecl>(); + // All generic arguments, except array sizes, need to be at least a link-time constant. + // Exception: array sizes can also be a specialization constant. + // + ConstantFoldingKind argFoldingKind = ConstantFoldingKind::LinkTime; + if (isArrayDecl(genericDeclRef.getDecl())) + { + argFoldingKind = ConstantFoldingKind::SpecializationConstant; + } + // Only allow constructing a PartialGenericAppExpr when referencing a callable decl. // Other types of generic decls must be fully specified. bool allowPartialGenericApp = false; @@ -497,6 +516,7 @@ bool SemanticsVisitor::TryCheckGenericOverloadCandidateTypes( val = ExtractGenericArgInteger( arg, getType(m_astBuilder, valParamRef), + argFoldingKind, context.mode == OverloadResolveContext::Mode::JustTrying ? nullptr : getSink()); } diff --git a/source/slang/slang-check-type.cpp b/source/slang/slang-check-type.cpp index bdf9c829a..82f9596e6 100644 --- a/source/slang/slang-check-type.cpp +++ b/source/slang/slang-check-type.cpp @@ -146,6 +146,7 @@ Type* SemanticsVisitor::ExtractGenericArgType(Expr* exp) IntVal* SemanticsVisitor::ExtractGenericArgInteger( Expr* exp, Type* genericParamType, + ConstantFoldingKind kind, DiagnosticSink* sink) { IntVal* val = CheckIntegerConstantExpression( @@ -153,7 +154,7 @@ IntVal* SemanticsVisitor::ExtractGenericArgInteger( genericParamType ? IntegerConstantExpressionCoercionType::SpecificType : IntegerConstantExpressionCoercionType::AnyInteger, genericParamType, - ConstantFoldingKind::SpecializationConstant, + kind, sink); if (val) return val; @@ -168,7 +169,11 @@ IntVal* SemanticsVisitor::ExtractGenericArgInteger( IntVal* SemanticsVisitor::ExtractGenericArgInteger(Expr* exp, Type* genericParamType) { - return ExtractGenericArgInteger(exp, genericParamType, getSink()); + return ExtractGenericArgInteger( + exp, + genericParamType, + ConstantFoldingKind::LinkTime, + getSink()); } Val* SemanticsVisitor::ExtractGenericArgVal(Expr* exp) diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index 4ba9e4e03..06d2b1f34 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -2216,7 +2216,13 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameter( // A matrix is processed as if it was an array of rows else if (auto matrixType = as<MatrixExpressionType>(type)) { - auto rowCount = getIntVal(matrixType->getRowCount()); + auto foldedRowCountVal = + context->getTargetProgram()->getProgram()->tryFoldIntVal(matrixType->getRowCount()); + IntegerLiteralValue rowCount = 0; + if (!foldedRowCountVal) + { + rowCount = getIntVal(foldedRowCountVal); + } return processSimpleEntryPointParameter( context, matrixType, @@ -2228,10 +2234,15 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameter( { // Note: Bad Things will happen if we have an array input // without a semantic already being enforced. + UInt elementCount = 0; - auto elementCount = (UInt)getIntVal(arrayType->getElementCount()); - if (arrayType->isUnsized()) - elementCount = 0; + if (!arrayType->isUnsized()) + { + auto intVal = context->getTargetProgram()->getProgram()->tryFoldIntVal( + arrayType->getElementCount()); + if (intVal) + elementCount = (UInt)getIntVal(intVal); + } // We use the first element to derive the layout for the element type auto elementTypeLayout = processEntryPointVaryingParameter( @@ -2456,7 +2467,11 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameter( // for (auto fieldTypeResInfo : fieldTypeLayout->resourceInfos) { - SLANG_RELEASE_ASSERT(fieldTypeResInfo.count != 0); + // If the field is a Conditional<T, false> type, then it could have 0 size. + // We should skip this field if it has no use of layout units. + if (fieldTypeResInfo.count == 0) + continue; + auto kind = fieldTypeResInfo.kind; auto structTypeResInfo = structLayout->findOrAddResourceInfo(kind); |
