Skip to content

Commit

Permalink
Fix prebound parameter pack - argument list matching logic. (#6111)
Browse files Browse the repository at this point in the history
* Fix prebound parameter pack - argument list matching logic.

* Move tests.

* Fix.
  • Loading branch information
csyonghe authored Jan 17, 2025
1 parent dfb369e commit 3666c66
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/slang/slang-ast-decl-ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void DeclRefBase::toText(StringBuilder& out)
return;
}

if (as<GenericTypeParamDecl>(this->getDecl()))
if (as<GenericTypeParamDeclBase>(this->getDecl()))
{
SLANG_ASSERT(as<DirectDeclRef>(this));
out << this->getDecl()->getName()->text;
Expand Down
18 changes: 17 additions & 1 deletion source/slang/slang-check-overload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

namespace Slang
{

bool isFreeFormTypePackParam(SemanticsVisitor* visitor, Type* type, ParamDecl* paramDecl)
{
if (auto declRef = isDeclRefTypeOf<GenericTypePackParamDecl>(type))
{
return visitor->GetOuterGeneric(declRef.getDecl()) ==
visitor->GetOuterGeneric(paramDecl->parentDecl);
}
return false;
}

SemanticsVisitor::ParamCounts SemanticsVisitor::CountParameters(
FilteredMemberRefList<ParamDecl> params)
{
Expand All @@ -25,10 +36,15 @@ SemanticsVisitor::ParamCounts SemanticsVisitor::CountParameters(
counts.required += typePack->getTypeCount();
allowedArgCountToAdd = typePack->getTypeCount();
}
else
else if (isFreeFormTypePackParam(this, paramType, param.getDecl()))
{
counts.allowed = -1;
}
else
{
counts.required++;
counts.allowed++;
}
}
else if (!param.getDecl()->initExpr)
{
Expand Down
28 changes: 28 additions & 0 deletions tests/language-feature/generics/prebound-variadic-pack.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//TEST:SIMPLE(filecheck=CHECK): -target spirv

struct Set<each T>
{
Tuple<expand each T> data;
void f(expand each T v){}
void h<each U>(U x){}
void g(expand each T d)
{
//CHECK-NOT: ([[# @LINE+1]]): error
f(expand each d); // OK

//CHECK-NOT: ([[# @LINE+1]]): error
h(54); // OK, specializing free-form parameter U.

//CHECK: ([[# @LINE+1]]): error
f(); // error, cannot call f without arguments.

//CHECK: ([[# @LINE+1]]): error
f(5); // error, cannot call f with different type pack.
}
}

[numthreads(1,1,1)]
void computeMain()
{
Set<float> v;
}
22 changes: 22 additions & 0 deletions tests/language-feature/generics/variadic-tuple-field.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -output-using-type

struct Set<each T>
{
Tuple<expand each T> data;
void f(expand each T v){}
__init(expand each T d) {
f(d);
data = makeTuple(d);
}
}

//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4)
RWStructuredBuffer<float> outputBuffer;

[numthreads(1,1,1)]
void computeMain()
{
let set = Set<float>(1.0);
outputBuffer[0] = set.data._0;
// CHECK: 1.0
}

0 comments on commit 3666c66

Please sign in to comment.