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

Fix modifier parsing. #6347

Merged
merged 6 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/slang-core-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ add_custom_command(
slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source
${core_module_generated_header} -save-glsl-module-bin-source
${glsl_module_generated_header}
DEPENDS slang-bootstrap
DEPENDS slang-bootstrap slang-without-embedded-core-module
VERBATIM
)
# Add a target so that we can depend on the above step when we create the glsl
Expand Down
3 changes: 2 additions & 1 deletion source/slang/slang-ast-support-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,8 @@ enum class LookupMask : uint8_t
Function = 0x2,
Value = 0x4,
Attribute = 0x8,
Default = type | Function | Value,
SyntaxDecl = 0x10,
Default = type | Function | Value | SyntaxDecl,
};

/// Flags for options to be used when looking up declarations
Expand Down
6 changes: 5 additions & 1 deletion source/slang/slang-lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ bool DeclPassesLookupMask(Decl* decl, LookupMask mask)
{
return (int(mask) & int(LookupMask::Attribute)) != 0;
}

// syntax declaration
else if (const auto syntaxDecl = as<SyntaxDecl>(decl))
{
return (int(mask) & int(LookupMask::SyntaxDecl)) != 0;
}
// default behavior is to assume a value declaration
// (no overloading allowed)

Expand Down
24 changes: 15 additions & 9 deletions source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,10 @@ static Token peekToken(Parser* parser)
return parser->tokenReader.peekToken();
}

static SyntaxDecl* tryLookUpSyntaxDecl(Parser* parser, Name* name)
static SyntaxDecl* tryLookUpSyntaxDecl(
Parser* parser,
Name* name,
LookupMask syntaxLookupMask = LookupMask::Default)
{
// Let's look up the name and see what we find.

Expand All @@ -1100,7 +1103,7 @@ static SyntaxDecl* tryLookUpSyntaxDecl(Parser* parser, Name* name)
nullptr, // no semantics visitor available yet
name,
parser->currentScope,
LookupMask::Default,
syntaxLookupMask,
true);

// If we didn't find anything, or the result was overloaded,
Expand Down Expand Up @@ -1175,23 +1178,26 @@ bool tryParseUsingSyntaxDeclImpl(Parser* parser, SyntaxDecl* syntaxDecl, T** out
}

template<typename T>
bool tryParseUsingSyntaxDecl(Parser* parser, T** outSyntax)
bool tryParseUsingSyntaxDecl(
Parser* parser,
T** outSyntax,
LookupMask syntaxLookupMask = LookupMask::Default)
{
if (peekTokenType(parser) != TokenType::Identifier)
return false;

auto nameToken = peekToken(parser);
auto name = nameToken.getName();

auto syntaxDecl = tryLookUpSyntaxDecl(parser, name);
auto syntaxDecl = tryLookUpSyntaxDecl(parser, name, syntaxLookupMask);

if (!syntaxDecl)
return false;

return tryParseUsingSyntaxDeclImpl<T>(parser, syntaxDecl, outSyntax);
}

static Modifiers ParseModifiers(Parser* parser)
static Modifiers ParseModifiers(Parser* parser, LookupMask modifierLookupMask = LookupMask::Default)
{
Modifiers modifiers;
Modifier** modifierLink = &modifiers.first;
Expand All @@ -1212,7 +1218,7 @@ static Modifiers ParseModifiers(Parser* parser)
Token nameToken = peekToken(parser);

Modifier* parsedModifier = nullptr;
if (tryParseUsingSyntaxDecl<Modifier>(parser, &parsedModifier))
if (tryParseUsingSyntaxDecl<Modifier>(parser, &parsedModifier, modifierLookupMask))
{
parsedModifier->keywordName = nameToken.getName();
if (!parsedModifier->loc.isValid())
Expand Down Expand Up @@ -4253,7 +4259,7 @@ static ParamDecl* parseModernParamDecl(Parser* parser)
// like `in`, `out`, and `in out`/`inout` be applied to the
// type (after the colon).
//
auto modifiers = ParseModifiers(parser);
auto modifiers = ParseModifiers(parser, LookupMask::SyntaxDecl);

// We want to allow both "modern"-style and traditional-style
// parameters to appear in any modern-style parameter list,
Expand Down Expand Up @@ -4918,7 +4924,7 @@ static DeclBase* ParseDeclWithModifiers(
// as a declaration keyword and parse a declaration using
// its associated callback:
Decl* parsedDecl = nullptr;
if (tryParseUsingSyntaxDecl<Decl>(parser, &parsedDecl))
if (tryParseUsingSyntaxDecl<Decl>(parser, &parsedDecl, LookupMask::Default))
{
decl = parsedDecl;
break;
Expand Down Expand Up @@ -6293,7 +6299,7 @@ ExpressionStmt* Parser::ParseExpressionStatement()
ParamDecl* Parser::ParseParameter()
{
ParamDecl* parameter = astBuilder->create<ParamDecl>();
parameter->modifiers = ParseModifiers(this);
parameter->modifiers = ParseModifiers(this, LookupMask::SyntaxDecl);
currentLookupScope = currentScope->parent;
_parseTraditionalParamDeclCommonBase(this, parameter, kDeclaratorParseOption_AllowEmpty);
resetLookupScope();
Expand Down
11 changes: 11 additions & 0 deletions tests/front-end/in-redeclare.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//TEST:SIMPLE(filecheck=CHECK):-target spirv

// CHECK: OpEntryPoint

struct Foo{ float4 v; }

[shader("vertex")]
float4 vert(in Foo in, in Foo o) : SV_Position
{
return in.v;
}
Loading