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

Deprecate and remove interface keyword #291

Open
llvm-beanz opened this issue Jul 31, 2024 · 0 comments
Open

Deprecate and remove interface keyword #291

llvm-beanz opened this issue Jul 31, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@llvm-beanz
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
HLSL interface declarations are very limited and a bit broken in DXC. Some examples are:

Given these declarations (which compile fine in isolation):

interface Animal {
    void Walk();
};

class Dog : Animal {
  int4 Legs;

  void Walk() {}
};

class Worm : Animal {
  void crawl() {}
};

Compiler Explorer

The following errors can occur with subsequent expressions.

Function parameters cannot be declared of interface type. This is true for all parameter modifier specifications (in/inout/out).
Code:

void move(Animal A) {}

Diagnostics:

error: parameter type 'Animal' is an abstract class
void move(Animal A) {}
                 ^
<source>:3:10: note: unimplemented pure virtual method 'Walk' in 'Animal'
    void Walk();
         ^

Code:

Animal A;

Diagnostics:

<source>:20:10: error: variable type 'Animal' is an abstract class
  Animal A;
         ^

This is the one case that seems to do somewhat what you would expect, except it only occurs on a declaration not at any other point.

Code:

Worm B;

Diagnostics

<source>:21:8: error: variable type 'Worm' is an abstract class
  Worm B;
       ^
<source>:3:10: note: unimplemented pure virtual method 'Walk' in 'Worm'
    void Walk();
         ^

Describe the solution you'd like
Interfaces are a bit of legacy that don't really work in HLSL. The functionality of interfaces can be provided with C++ templates using SFINAE or C++20 concepts. As we align the language in that direction we should remove the interface keyword in HLSL 202x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Triaged
Development

No branches or pull requests

2 participants