summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-overload.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-07-19 16:20:52 -0700
committerGitHub <noreply@github.com>2023-07-19 16:20:52 -0700
commit3509059cd8357455155260d8587b8a438c34e49f (patch)
tree59933528a4e93bb02b93d80c8f4ebfe38509b24d /source/slang/slang-check-overload.cpp
parenta5987aad211d2e0b9391bdda4b67873ec9873074 (diff)
Add `sampleCount` parameter for MS textures. (#3001)
* Add `sampleCount` parameter for MS textures. * Fix test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-overload.cpp')
-rw-r--r--source/slang/slang-check-overload.cpp66
1 files changed, 52 insertions, 14 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index 1d2f82ac7..2fa13f3fa 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -196,6 +196,14 @@ namespace Slang
{
auto genericDeclRef = candidate.item.declRef.as<GenericDecl>();
+ // Only allow constructing a PartialGenericAppExpr when referencing a callable decl.
+ // Other types of generic decls must be fully specified.
+ bool allowPartialGenericApp = false;
+ if (as<CallableDecl>(genericDeclRef.getDecl()->inner))
+ {
+ allowPartialGenericApp = true;
+ }
+
// The basic idea here is that we need to check that the
// arguments to a generic application (e.g., `F<A1, A2, ...>`)
// have the right "type," which in this context means
@@ -235,13 +243,27 @@ namespace Slang
{
if (aa >= context.argCount)
{
- // If we have run out of arguments, then we don't
- // apply any more checks at this step. We will instead
- // attempt to *infer* an argument at this position
- // at a later stage.
- //
- candidate.flags |= OverloadCandidate::Flag::IsPartiallyAppliedGeneric;
- break;
+ if (allowPartialGenericApp)
+ {
+ // If we have run out of arguments, and the referenced decl
+ // allows partially applied specialization (i.e. a callable
+ // decl) then we don't apply any more checks at this step.
+ // We will instead attempt to *infer* an argument at this
+ // position at a later stage.
+ //
+ candidate.flags |= OverloadCandidate::Flag::IsPartiallyAppliedGeneric;
+ break;
+ }
+ else
+ {
+ // Otherwise, the generic decl had better provide a default value
+ // or this reference is ill-formed.
+ auto substType = typeParamRef.substitute(m_astBuilder, typeParamRef.getDecl()->initType.type);
+ if (!substType)
+ return false;
+ checkedArgs.add(substType);
+ continue;
+ }
}
// We have a type parameter, and we expect to find
@@ -287,13 +309,29 @@ namespace Slang
{
if (aa >= context.argCount)
{
- // If we have run out of arguments, then we don't
- // apply any more checks at this step. We will instead
- // attempt to *infer* an argument at this position
- // at a later stage.
- //
- candidate.flags |= OverloadCandidate::Flag::IsPartiallyAppliedGeneric;
- break;
+ if (allowPartialGenericApp)
+ {
+ // If we have run out of arguments and the decl allows
+ // partial specialization, then we don't apply any more
+ // checks at this step. We will instead attempt to
+ // *infer* an argument at this position at a later
+ // stage.
+ //
+ candidate.flags |= OverloadCandidate::Flag::IsPartiallyAppliedGeneric;
+ break;
+ }
+ else
+ {
+ // Otherwise, the generic decl had better provide a default value
+ // or this reference is ill-formed.
+ ensureDecl(valParamRef, DeclCheckState::Checked);
+ ConstantFoldingCircularityInfo newCircularityInfo(valParamRef.getDecl(), nullptr);
+ auto defaultVal = tryConstantFoldExpr(valParamRef.substitute(m_astBuilder, valParamRef.getDecl()->initExpr), &newCircularityInfo);
+ if (!defaultVal)
+ return false;
+ checkedArgs.add(defaultVal);
+ continue;
+ }
}
// The case for a generic value parameter is similar to that