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

Check arguments direction in interface implementation #5962

Closed
cezneluk opened this issue Dec 30, 2024 · 0 comments · Fixed by #5964
Closed

Check arguments direction in interface implementation #5962

cezneluk opened this issue Dec 30, 2024 · 0 comments · Fixed by #5964
Assignees
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang

Comments

@cezneluk
Copy link

Currently, the direction of function arguments in a structure that implements an interface is not checked if it is the same as in the interface declaration. Therefore a function can modify a variable that is expected to be only an input and do not modify a variable that is expected to be an output.

Current result:

public interface ITest {
    public void testIn(int a);
    public void testOut(out int b);
};

public struct TestImpl : ITest {
    public void testIn(out int a) {
        a = 5;
 }
    public void testOut(int b) {
        b = 6;
 }
}

RWStructuredBuffer<int> output;

void doSomething<T>(T data) where T : ITest {
    int a = 516;
    data.testIn(a);
    int b = 687;
    data.testOut(b);

    output[0] = a;
    output[1] = b;
}

[shader("compute")]
[numthreads(1,1,1)]
void computeMain()
{
    TestImpl data;
    doSomething(data);
}

This shader is successfully compiled and after the invocation of this code, output buffer contains [5, 687], which is not expected if we look at the interface declaration.

Tested on binaries from the latest release (v2024.17) and a build from the current master (89dd2b1).

Expected result:

Slang will write an error about the difference in an argument direction. This can be quite useful in the link-time specialization where the entire shader works with an unknown type based on a known interface.

@csyonghe csyonghe self-assigned this Dec 30, 2024
@csyonghe csyonghe added the goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang label Dec 30, 2024
@csyonghe csyonghe added this to the Q4 2024 (Fall) milestone Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants