Skip to content

Commit

Permalink
Fix inccorect dropping of declref during Unification of DeclaredSubty…
Browse files Browse the repository at this point in the history
…peWitness. (#5041)

* Fix inccorect dropping of declref during Unification of DeclaredSubtypeWitness.

* Add extension test.
  • Loading branch information
csyonghe authored Sep 10, 2024
1 parent e896827 commit f51b74d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/slang/slang-check-constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ namespace Slang
SLANG_ASSERT(constraintDecl2);
return TryUnifyTypes(constraints,
unifyCtx,
constraintDecl1.getDecl()->getSup().type,
constraintDecl2.getDecl()->getSup().type);
getSup(m_astBuilder, constraintDecl1),
getSup(m_astBuilder, constraintDecl2));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type

interface IValueGeneric<let D : int> {}
struct ValGenericImpl<let D : int> : IValueGeneric<D> {}

struct NestedValueGeneric<let D : int, S : IValueGeneric<D>>
{
int x;
}

void acceptor<let D : int, S : IValueGeneric<D>>(NestedValueGeneric<D, S> x)
{
outputBuffer[0] = D + x.x;
}

extension<let D : int, S : IValueGeneric<D>> NestedValueGeneric<D, S>
{
void foo()
{
acceptor(this);
}
}
void test2(NestedValueGeneric<2, ValGenericImpl<2>> x)
{
// 'foo' should be a member of 'NestedValueGeneric<2, ValGenericImpl<2>>' through
// the extension above.
x.foo();
}

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

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
NestedValueGeneric<2, ValGenericImpl<2>> x;
x.x = 1;
test2(x);
// CHECK: 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type

interface IValueGeneric<let D : int> {}
struct ValGenericImpl<let D : int> : IValueGeneric<D> {}

struct NestedValueGeneric<let D : int, S : IValueGeneric<D>>
{
int x;
}

void acceptor<let D : int, S : IValueGeneric<D>>(NestedValueGeneric<D, S> x)
{
outputBuffer[0] = D + x.x;
}
void test(NestedValueGeneric<2, ValGenericImpl<2>> x)
{
// Test that we can correctly infer acceptor.D and acceptor.S from `x`.
acceptor(x);
}

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

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
NestedValueGeneric<2, ValGenericImpl<2>> x;
x.x = 1;
test(x);
// CHECK: 3
}

0 comments on commit f51b74d

Please sign in to comment.