yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeFix use of variadic generics with [Differentiable]. (#8736)bedc3421c

master
1.2 KiB59 linesraw
1//TEST:INTERPRET(filecheck=CHECK):
2
3// Test that we can call variadic generic [Differentiable] methods.
4
5interface IParameterExtractor
6{
7    [Differentiable]
8    void extract(no_diff uint x);
9}
10
11struct FloatParameterExtractor : IParameterExtractor
12{
13    [Differentiable]
14    void extract(no_diff uint x)
15    {
16        printf("fff\n");
17    }
18}
19
20[Differentiable]
21void extract_parameters_helper<T : IParameterExtractor>(
22    no_diff uint x,
23    T arg,
24    )
25{
26    arg.extract(x);
27}
28
29[Differentiable]
30void wrapper1<each T>(
31    uint x,
32    expand each T args, // compiler will add no_diff modifier here.
33    )
34    where T : IParameterExtractor
35{
36    expand extract_parameters_helper(x, each args);
37}
38
39[Differentiable]
40void wrapper2<each T>(
41    uint x,
42    expand each T args, // compiler will add no_diff modifier here.
43    )
44    where T : IParameterExtractor
45{
46    wrapper1(x, args);
47}
48
49
50void main()
51{
52    // There was a bug that causes the compiler failing to treat a `no_diff TypePack` as
53    // a type pack, and thus diagnose an error when resolving the following call.
54    //
55    wrapper2(1, FloatParameterExtractor(), FloatParameterExtractor());
56}
57
58// CHECK: fff
59// CHECK: fff