summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-08-14 18:41:48 -0700
committerGitHub <noreply@github.com>2024-08-14 18:41:48 -0700
commit071f1b6062b459928ebfd6f2f60a8d6ad021112b (patch)
tree2ba65eb40f39701db6fc775a9258ec8079d161a0 /source/slang/slang-check-decl.cpp
parent35a3d32c87f079749f6b100d01b289c3da02d7d6 (diff)
Variadic Generics Part 1: parsing and type checking. (#4833)
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
-rw-r--r--source/slang/slang-check-decl.cpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 2e5e13360..58fbb4689 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -1561,7 +1561,7 @@ namespace Slang
// A variable with an explicit type is simpler, for the
// most part.
SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(varDecl));
- TypeExp typeExp = subVisitor.CheckUsableType(varDecl->type);
+ TypeExp typeExp = subVisitor.CheckUsableType(varDecl->type, varDecl);
varDecl->type = typeExp;
if (varDecl->type.equals(m_astBuilder->getVoidType()))
{
@@ -7128,6 +7128,11 @@ namespace Slang
{
args.add(DeclRefType::create(astBuilder, astBuilder->getDirectDeclRef(genericTypeParamDecl)));
}
+ else if (auto genericTypePackParamDecl = as<GenericTypePackParamDecl>(mm))
+ {
+ auto packType = DeclRefType::create(astBuilder, astBuilder->getDirectDeclRef(genericTypePackParamDecl));
+ args.add(packType);
+ }
else if (auto genericValueParamDecl = as<GenericValueParamDecl>(mm))
{
if (semantics)
@@ -7574,7 +7579,7 @@ namespace Slang
if(typeExpr.exp)
{
SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(paramDecl));
- typeExpr = subVisitor.CheckUsableType(typeExpr);
+ typeExpr = subVisitor.CheckUsableType(typeExpr, paramDecl);
paramDecl->type = typeExpr;
checkMeshOutputDecl(paramDecl);
}
@@ -7622,6 +7627,27 @@ namespace Slang
}
}
}
+ else if (isTypePack(paramDecl->type.type))
+ {
+ // For now, we only allow parameter packs to be `const`.
+ bool hasConstModifier = false;
+ for (auto modifier : paramDecl->modifiers)
+ {
+ if (as<OutModifier>(modifier) || as<InOutModifier>(modifier) || as<RefModifier>(modifier) || as<ConstRefModifier>(modifier))
+ {
+ getSink()->diagnose(modifier, Diagnostics::parameterPackMustBeConst);
+ }
+ else if (as<ConstModifier>(modifier))
+ {
+ hasConstModifier = true;
+ }
+ }
+ if (!hasConstModifier)
+ {
+ auto constModifier = this->getASTBuilder()->create<ConstModifier>();
+ addModifier(paramDecl, constModifier);
+ }
+ }
// Only texture types are allowed to have memory qualifiers on parameters
if(!paramDecl->type || paramDecl->type->astNodeType != ASTNodeType::TextureType)
@@ -8413,7 +8439,7 @@ namespace Slang
void SemanticsDeclHeaderVisitor::visitSubscriptDecl(SubscriptDecl* decl)
{
- decl->returnType = CheckUsableType(decl->returnType);
+ decl->returnType = CheckUsableType(decl->returnType, decl);
visitAbstractStorageDeclCommon(decl);
@@ -8423,7 +8449,7 @@ namespace Slang
void SemanticsDeclHeaderVisitor::visitPropertyDecl(PropertyDecl* decl)
{
SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(decl));
- decl->type = subVisitor.CheckUsableType(decl->type);
+ decl->type = subVisitor.CheckUsableType(decl->type, decl);
visitAbstractStorageDeclCommon(decl);
checkVisibility(decl);
}
@@ -8639,7 +8665,7 @@ namespace Slang
return createDefaultSubstitutionsIfNeeded(m_astBuilder, this, extDeclRef).as<ExtensionDecl>();
}
- if (!TryUnifyTypes(constraints, extDecl->targetType.Ptr(), type))
+ if (!TryUnifyTypes(constraints, ValUnificationContext(), extDecl->targetType.Ptr(), type))
return DeclRef<ExtensionDecl>();
ConversionCost baseCost;
@@ -9554,12 +9580,12 @@ namespace Slang
outTypeList.add(type);
}
}
- OrderedDictionary<GenericTypeParamDecl*, List<Type*>> getCanonicalGenericConstraints(
+ OrderedDictionary<GenericTypeParamDeclBase*, List<Type*>> getCanonicalGenericConstraints(
ASTBuilder* astBuilder,
DeclRef<ContainerDecl> genericDecl)
{
- OrderedDictionary<GenericTypeParamDecl*, List<Type*>> genericConstraints;
- for (auto mm : getMembersOfType<GenericTypeParamDecl>(astBuilder, genericDecl))
+ OrderedDictionary<GenericTypeParamDeclBase*, List<Type*>> genericConstraints;
+ for (auto mm : getMembersOfType<GenericTypeParamDeclBase>(astBuilder, genericDecl))
{
genericConstraints[mm.getDecl()] = List<Type*>();
}
@@ -9574,7 +9600,7 @@ namespace Slang
constraintTypes->add(genericTypeConstraintDecl.getDecl()->getSup().type);
}
- OrderedDictionary<GenericTypeParamDecl*, List<Type*>> result;
+ OrderedDictionary<GenericTypeParamDeclBase*, List<Type*>> result;
for (auto& constraints : genericConstraints)
{
List<Type*> typeList;