Skip to content

Improve Syntax::makeValidName function#2598

Merged
jstone-lucasfilm merged 1 commit intoAcademySoftwareFoundation:mainfrom
ld-kerley:shadergen/simplify-making-valid-names
Oct 2, 2025
Merged

Improve Syntax::makeValidName function#2598
jstone-lucasfilm merged 1 commit intoAcademySoftwareFoundation:mainfrom
ld-kerley:shadergen/simplify-making-valid-names

Conversation

@ld-kerley
Copy link
Copy Markdown
Contributor

@ld-kerley ld-kerley commented Oct 1, 2025

This PR improves the logic around how valid names are generated with consideration for reserved words defined in specific Syntax objects.

Currently the shader generator calls Syntax::makeIdentifier() to ensure that variable names are legal. This compares the current name against a map of already used identifiers. The reserved words for a syntax are prepopulated in this map.

There are some places, namely here and here, where we generate names that need to be legal, but do not call makeIdentifier() but instead just call makeValidName(). Which got me to thinking that make makeValidName() should be doing the reserved word check.

Moving the check to makeValidName() means we do not have to copy all of the reserved words in to the identifier map for each ShaderGraph object we create, as well as plugging the potential bug of being able to generate illegal function names.

I didn't add a warning - but I wonder if we should emit a warning if a reserved word is used as a variable name?

…ords. This has a couple of benefits, we don't need to populate each ShaderGraphs identifier list with every reserved word in the syntax for each graph we create. Also there are a couple of places where makeValidName() is called - namely in SourceCodeNode and CompoundNode, to generate the names of functions, which currently do not ensure that reserved words are not generated.
@niklasharrysson
Copy link
Copy Markdown
Contributor

This looks like a great change. Feels much better and safer to keep the reserved words check fully contained within the Syntax class.

//

ShaderGraph::ShaderGraph(const ShaderGraph* parent, const string& name, ConstDocumentPtr document, const StringSet& reservedWords) :
ShaderGraph::ShaderGraph(const ShaderGraph* parent, const string& name, ConstDocumentPtr document, const StringSet& /*reservedWords*/) :
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps remove the reservedWords parameter completely since it's not used now?

This constructor is only ever called from within ShaderGraph.cpp, in the ShaderGraph::create methods, and I doubt anyone has ever used it explicitly from an integration. It's not exposed in python. So I think it should be safe to change the signature.

@ld-kerley
Copy link
Copy Markdown
Contributor Author

Thanks @niklasharrysson - yeah I was debating removing it from the interface too - but wasn't sure how worried I needed to be about backwards compatibility.

I think I'll maybe it's better to merge this PR (just need someone to hit the approve button), and then I can put up a cleanup PR afterwards, that way if the clean up causes someone an issue - we can easily revert it.

Copy link
Copy Markdown
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

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

This looks fine to me as well, thanks @ld-kerley!

@jstone-lucasfilm jstone-lucasfilm changed the title Improve Syntax::makeValidName() function Improve Syntax::makeValidName function Oct 2, 2025
@jstone-lucasfilm jstone-lucasfilm merged commit b323afd into AcademySoftwareFoundation:main Oct 2, 2025
32 checks passed
@ld-kerley ld-kerley deleted the shadergen/simplify-making-valid-names branch November 21, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants