Skip to content

Conversation

ArielG-NV
Copy link
Collaborator

@ArielG-NV ArielG-NV commented May 20, 2025

fixes: #7143
fixes: #7146

Goal of PR:

Future PR(s) goal:

  • Support some keyword in AST. With this we will also implement all varDecl interactions between dyn and some.
  • Add IR support for some and dyn.

Breakdown of PR:

  • most of the logic is in validateDyn.*. This was done so that in the future when we implement more features we will have an easy time removing/adding restrictions to dyn interfaces.

Breaking changes:

  • As per spec (https://github.com/shader-slang/spec/pull/14/files), any type conforming to a dyn interface errors if member list contains one of the following: opaque type, non copyable type, or unsized type.
  • Due to the breaking change, the test tests\compute\dynamic-dispatch-bindless-texture.slang is incorrect. This has been fixed.

@ArielG-NV ArielG-NV requested a review from a team as a code owner May 20, 2025 00:18
@ArielG-NV ArielG-NV added the pr: non-breaking PRs without breaking changes label May 20, 2025
@ArielG-NV
Copy link
Collaborator Author

/format

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

@ArielG-NV ArielG-NV marked this pull request as draft May 20, 2025 03:48
@ArielG-NV ArielG-NV added pr: breaking change PRs with breaking changes and removed pr: non-breaking PRs without breaking changes labels May 20, 2025
@ArielG-NV
Copy link
Collaborator Author

/regenerate-cmdline-ref

@slangbot
Copy link
Contributor

🌈 Regenerated command line reference, please merge the changes from this PR

@ArielG-NV ArielG-NV changed the title Initial dyn keyword support Initial dyn keyword support & -lang 2026 May 20, 2025
@ArielG-NV ArielG-NV changed the title Initial dyn keyword support & -lang 2026 Initial dyn keyword support & -lang 2026 compiler option May 20, 2025
@ArielG-NV ArielG-NV marked this pull request as ready for review May 20, 2025 15:27
…ement-SP024-dyn-support

Regenerate command line reference for PR shader-slang#7172
include/slang.h Outdated
@@ -765,6 +765,7 @@ typedef uint32_t SlangSizeT;
SLANG_SOURCE_LANGUAGE_SPIRV,
SLANG_SOURCE_LANGUAGE_METAL,
SLANG_SOURCE_LANGUAGE_WGSL,
SLANG_SOURCE_LANGUAGE_SLANG_2026,
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we remove this? use a new option to track language version.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should be translating -lang 2026 to -lang slang -version 2026

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

-version is already a reserved keyword. We could make the option named something else like -std 2026 or something ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, -std is fine.

include/slang.h Outdated
@@ -765,6 +765,7 @@ typedef uint32_t SlangSizeT;
SLANG_SOURCE_LANGUAGE_SPIRV,
SLANG_SOURCE_LANGUAGE_METAL,
SLANG_SOURCE_LANGUAGE_WGSL,
SLANG_SOURCE_LANGUAGE_SLANG_2026,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, -std is fine.

}
else if (auto inheritanceDecl = as<InheritanceDecl>(m))
{
auto inheritedInterfaceDeclRefType = as<DeclRefType>(inheritanceDecl->base.type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

auto inheritedInterfaceDeclRef = isDeclRefTypeOf<InterfaceDecl>(inheritanceDecl->base.type);

auto interfaceDecl = as<InterfaceDecl>(decl);
if (!interfaceDecl)
return;
validateDynInterfaceUsage(visitor, sink, optionSet, interfaceDecl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't need to call this from validateDynUsage, instead validateDynInterfaceUsage should be called from visitInterfaceDecl when we check the interface decl itself.

{
visitDecl(interfaceDecl);

if (interfaceDecl->hasModifier<AnyValueSizeAttribute>())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check all the dyn interface restrictions here, also make sure to check that dyn interface itself cannot be a generic.

@@ -827,6 +827,59 @@ DIAGNOSTIC(
DIAGNOSTIC(33070, Error, expectedFunction, "expected a function, got '$0'")
DIAGNOSTIC(33071, Error, expectedAStringLiteral, "expected a string literal")

// `dyn` and `some` errors
DIAGNOSTIC(33071, Error, cannotHaveGenericDynInterface, "dyn interfaces cannot be generic: '$0'.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

33071 is duplicated.

inheritedInterfaceDecl);

// `dyn interface` cannot be a generic
auto innerInterfaceDecl = as<InterfaceDecl>(genericDecl->inner);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be moved to visitInterfaceDecl.

return;

// Ensure not inheriting from `dyn` interface
auto inheritedInterfaceDecl = findDynInheritance(visitor, innerAggTypeDecl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be moved to visitInheritanceDecl.

return;

// cannot have extension provide conformance to dyn interface
auto inheritedInterfaceDecl = findDynInheritance(visitor, extensionDecl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move to visitInheritanceDecl.

@@ -9519,6 +9736,8 @@ void SemanticsDeclBodyVisitor::visitAggTypeDecl(AggTypeDecl* aggTypeDecl)
getSink()->diagnose(aggTypeDecl->loc, Diagnostics::cannotExportIncompleteType, aggTypeDecl);
}

validateDynUsage(this, getSink(), getOptionSet(), aggTypeDecl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we calling validateDynUsage from so many different places? If we call it here, then we shouldn't need to call it from SemanticsDeclHeaderVisitor::visitGenericDecl.

Copy link
Collaborator Author

@ArielG-NV ArielG-NV May 21, 2025

Choose a reason for hiding this comment

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

I will reduce the calls to validateDynUsage to simplify things.

I just thought of this as a way to "organize" validateDynUsage.

@@ -10057,6 +10276,8 @@ void SemanticsDeclBasesVisitor::visitExtensionDecl(ExtensionDecl* decl)

_validateCrossModuleInheritance(decl, inheritanceDecl);
}

validateDynUsage(this, getSink(), getOptionSet(), decl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if you move the related checks to visitInheritanceDecl you shouldn't need to call validateDynUsage here.

ArielG-NV added 2 commits May 21, 2025 17:01
… yet.

re-organize the validation as per review, did not fix cmd-line-option yet, that is next.
@ArielG-NV
Copy link
Collaborator Author

/format

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

@ArielG-NV ArielG-NV changed the title Initial dyn keyword support & -lang 2026 compiler option Initial dyn keyword support & -std <std-revision> compiler option May 22, 2025
@ArielG-NV ArielG-NV enabled auto-merge (squash) May 22, 2025 03:19
@ArielG-NV ArielG-NV merged commit 27c6e9b into shader-slang:master May 22, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: breaking change PRs with breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SP024]Addition of -lang 2026 [SP024]Initial support for dyn keyword.
3 participants