Skip to content

Conversation

@16-Bit-Dog
Copy link
Contributor

Issue:

Problem & Soluition:

  • Currently, generic inference fails if using lambda as argument to a function-type parameter since Slang does not handle this case during type unification. This missing logic was added.
    • inferGenericArguments->tryUnifyTypes->TryUnifyFuncTypesByStructuralMatch

jkwak-work
jkwak-work previously approved these changes Nov 13, 2025
Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

…LambdaDecl>

Add case where argument is a FuncType and parameter is a DeclRefType<LambdaDecl>

This may be needed if something like the following is somehow given as a parameter type: `decltype(*some lambda expr*)`
jkwak-work
jkwak-work previously approved these changes Nov 13, 2025
Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@jkwak-work jkwak-work added the pr: non-breaking PRs without breaking changes label Nov 13, 2025
@jkwak-work jkwak-work self-assigned this Nov 13, 2025
@jkwak-work jkwak-work enabled auto-merge November 13, 2025 22:39
@16-Bit-Dog
Copy link
Contributor Author

16-Bit-Dog commented Nov 13, 2025

I think this PR may be missing logic to handle inference for Functor's (as argument, not only lambda's).

PR will be made a draft until I figure out if this is missing or not.

Example:

//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type
//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type

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

// This test ensures that lambdas correctly unify-types with function-types so that
// generic-parameters can be infered.
func foo<let N : int>(f: functype()->vector<float, N>)->vector<float, N> { return f(); }

struct Functor : IFunc<vector<float, 1>>
{
    vector<float, 1> operator()()
    {
        return 4.0;
    }
}

[numthreads(1,1,1)]
func computeMain()->void
{
    //CHECK: 2
    // outputBuffer[0] = (int)foo(() => 2);
    //CHECK: 3
    // outputBuffer[1] = (int)foo(() => vector<float, 1>(3));

    //CHECK: 4
    Functor f;
    outputBuffer[2] = (int)foo(f);
}

@16-Bit-Dog 16-Bit-Dog marked this pull request as draft November 13, 2025 23:14
auto-merge was automatically disabled November 13, 2025 23:14

Pull request was converted to draft

@16-Bit-Dog 16-Bit-Dog marked this pull request as ready for review November 14, 2025 00:47
@16-Bit-Dog
Copy link
Contributor Author

16-Bit-Dog commented Nov 14, 2025

Update: generalized the current approach to support Functors

@16-Bit-Dog 16-Bit-Dog changed the title Add type unification logic to handle LambdaDecl with FuncType Add type unification logic to handle LambdaDecl/Functor's with FuncType Nov 15, 2025
Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@jkwak-work jkwak-work added this pull request to the merge queue Nov 19, 2025
Merged via the queue into shader-slang:master with commit ec34d69 Nov 19, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants