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

generic interface cannot be used as a generic argument #3804

Closed
jkwak-work opened this issue Mar 20, 2024 · 3 comments · Fixed by #4870
Closed

generic interface cannot be used as a generic argument #3804

jkwak-work opened this issue Mar 20, 2024 · 3 comments · Fixed by #4870
Assignees
Labels
goal:client exploration Speculative work for a potential use case. inactive:wontfix out of scope, or not desired

Comments

@jkwak-work
Copy link
Collaborator

When an interface uses "__generic", the interface cannot be used as a part of the __generic argument.

It is easier to explain the problem with an example.
The following code gives us a compile error,

__generic<T:__BuiltinFloatingPointType> // <== This is the problem
interface IOperation
{
  static bool Equals(T lhs, T rhs);
};
 
__generic<T:__BuiltinFloatingPointType, OpType:IOperation<T>> // <= Not sure if this is a right way
bool Equals(T lhs, T rhs)
{
  return OpType::Equals(lhs, rhs);
}

The error message is following,

a.slang(8): note 99999: an internal error threw an exception while working on code near this location
bool Equals(T lhs, T rhs)
    ^~~~~~
(0): error 99999: Slang compilation aborted due to an exception of class Slang::InternalError: unexpected: Generic type/value shouldn't be handled here!

The following alternative approach didn't work either,

__generic<T:__BuiltinFloatingPointType>
interface IOperation
{
   bool Equals(T lhs, T rhs);
};

__generic<T:__BuiltinFloatingPointType>
struct JKWAK_test
{
    __generic<OpType:IOperation<T>>
    bool Equals(OpType op, T lhs, T rhs)
    {
       return op.Equals(lhs, rhs);
    }
}

The error message is identical to the first example.

@csyonghe
Copy link
Collaborator

This is due to some fundamental limitation we have in our IR. Supporting this is likely something we cannot afford in the short term. Let's try:

__generic<T:__BuiltinFloatingPointType>
struct JKWAK_test
{
    bool Equals(IOperation<T>op, T lhs, T rhs)
    {
       return op.Equals(lhs, rhs);
    }
}

If this doesn't work, we may be able to fix it.

@csyonghe csyonghe closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2024
@jkwak-work
Copy link
Collaborator Author

Oh. I got it wrong.
The suggested workaround seems to be working.
Let me try it on UE.

@swoods-nv swoods-nv added goal:client support Feature or fix needed for a current slang user. goal:client exploration Speculative work for a potential use case. and removed goal:client support Feature or fix needed for a current slang user. labels Mar 21, 2024
@jkwak-work jkwak-work added the inactive:wontfix out of scope, or not desired label Jun 4, 2024
@jkwak-work
Copy link
Collaborator Author

This issue was closed as WNF due to the low bang for the buck.
But we should track it as an unfinished feature like #4236

@jkwak-work jkwak-work reopened this Jun 4, 2024
csyonghe added a commit to csyonghe/slang that referenced this issue Aug 20, 2024
@csyonghe csyonghe assigned csyonghe and unassigned swoods-nv Aug 20, 2024
@csyonghe csyonghe added this to the Q3 2024 (Summer) milestone Aug 20, 2024
csyonghe added a commit that referenced this issue Aug 21, 2024
* Support dependent generic constraints.

* Fix warning.

* Update comment.

* Fix.

* Add a test case to verify fix of #3804.

* Address review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client exploration Speculative work for a potential use case. inactive:wontfix out of scope, or not desired
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants