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

Exception at address when defining member function in generic class with another generic parameter #4048

Closed
Cazadorro opened this issue Apr 27, 2024 · 3 comments · Fixed by #4091
Assignees
Labels
goal:client support Feature or fix needed for a current slang user. kind:bug something doesn't work like it should

Comments

@Cazadorro
Copy link

Cazadorro commented Apr 27, 2024

When I run this:

// test_shader.slang
namespace ns{

    public interface IBinaryElementWiseFunction<T>{
       public static T call(const in T lhs, const in T rhs);
    }
    public struct AddOp<T : IArithmetic> : IBinaryElementWiseFunction<T>{
      public static  T call(const in T lhs, const in T rhs){
            return lhs + rhs; 
        }
    }
     public struct BinaryElementWiseInputData<T : IArithmetic>{
        public Ptr<T> lhs; 
        public Ptr<T> rhs; 
        public Ptr<T> out; 
        public uint64_t size; 

    
        public void test<U : IBinaryElementWiseFunction<T>>(U  x){
            out[0] = x.call(lhs[0] ,rhs[0]);
        }
    }
}

[[vk::push_constant]] ns::BinaryElementWiseInputData<uint32_t> array_info; 

[shader("compute")]
[numthreads(1024,1,1)]
void add_main(uint3 threadId: SV_DispatchThreadID) {
     ns::BinaryElementWiseInputData<uint32_t> temp = array_info; 
    if (threadId.x < array_info.size) {
        let index = threadId.x; 

        temp.test(ns::AddOp<uint32_t>());
    }    
}

My program straight up crashes in version v2024.1.10. I just see:

 slangModule = session->loadModule("test_shader", diagnosticBlob.writeRef());

and a crash in the binary:

callq  *0x1fb6b4(%rip)          
nopl   (%rax,%rax)   

and

Exception: Exception 0xe06d7363 encountered at address 0x7ffcf33753ac

If there's supposed to be debug symbols with this, I'm not seeing them in the packaged release, I'm running CMake in its debug configuration.

@Cazadorro Cazadorro changed the title Abort when defining member function in generic class with another generic parameter Exception at address when defining member function in generic class with another generic parameter Apr 27, 2024
@ArielG-NV ArielG-NV added kind:bug something doesn't work like it should goal:client support Feature or fix needed for a current slang user. labels Apr 29, 2024
@csyonghe
Copy link
Collaborator

The problem here is that there is a mismatch in the implicit generic parameter list of the interface and the implementation.

The interface IBinaryElementWiseFunction<T>::call is in the form of:

T call<T>(...)

while AddOp<T>::call is in the form of

T call<T:IArithmetic>(...)

where there is an additional type constraint on T, so the signatures doesn't match exactly.

Our semantic checking logic has a place where we are synthesizing witness requirements from compatible existing methods, but that logic is missing a case in detecting the mismatch of generic constraints.

@csyonghe
Copy link
Collaborator

@Cazadorro A workaround while we work on the fix is to add the constraint to IBinaryElementWiseFunction:

public interface IBinaryElementWiseFunction<T:IArithmetic>{
       public static T call(const in T lhs, const in T rhs);
    }

@csyonghe
Copy link
Collaborator

csyonghe commented May 2, 2024

I have a fix in review. Nested generics like this is still under tested, so please use with caution. Let us know if you run into any further issues and we will make sure to either come up with a fix, or implement checking/validation rules to restrict the use of generics that are beyond the capability of the type system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Feature or fix needed for a current slang user. kind:bug something doesn't work like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants