Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circularity issue when checking multiple generic interface constraints. #6121

Merged
15 changes: 12 additions & 3 deletions source/slang/slang-check-inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,14 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
if (constraintDeclRef.getDecl()->checkState.isBeingChecked())
continue;

ensureDecl(&visitor, constraintDeclRef.getDecl(), DeclCheckState::CanSpecializeGeneric);
ensureDecl(&visitor, constraintDeclRef.getDecl(), DeclCheckState::ScopesWired);

auto subType = getSub(astBuilder, constraintDeclRef);
auto superType = getSup(astBuilder, constraintDeclRef);
// Check only the sub-type.
visitor.CheckConstraintSubType(constraintDeclRef.getDecl()->sub);
auto sub = constraintDeclRef.getDecl()->sub;
if (!sub.type)
sub = visitor.TranslateTypeNodeForced(sub);
auto subType = constraintDeclRef.substitute(astBuilder, sub.type);

// We only consider constraints where the type represented
// by `declRef` is the subtype, since those
Expand All @@ -489,6 +493,11 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
if (subDeclRefType->getDeclRef() != declRef)
continue;

// Further check the constraint, since we now need the sup-type.
ensureDecl(&visitor, constraintDeclRef.getDecl(), DeclCheckState::CanSpecializeGeneric);

auto superType = getSup(astBuilder, constraintDeclRef);

// Because the constraint is a declared inheritance relationship,
// adding the base to our list of direct bases is as straightforward
// as in all the preceding cases.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type

interface IFoo<T : __BuiltinFloatingPointType>
{
bool requirement(T v1);
}

struct Bar<T : __BuiltinFloatingPointType, A : IFoo<T>, B : IFoo<T>>
{
[Differentiable]
T doThing(T a)
{
return a * T(2.0);
}
}

struct Foo : IFoo<float>
{
bool requirement(float v)
{
return v > 0.5;
}
}

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

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
int tid = dispatchThreadID.x;
Bar<float, Foo, Foo> obj;
outputBuffer[tid] = obj.doThing(2.0f);
// CHECK: 4
}
Loading