Skip to content

Gensym / remove the RGF name instead of using f and __args - #147

Merged
ChrisRackauckas merged 4 commits into
SciML:masterfrom
penelopeysm:master
Aug 23, 2026
Merged

ChrisRackauckas merged 4 commits into
SciML:masterfrom
penelopeysm:master

Conversation

@penelopeysm

@penelopeysm penelopeysm commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #146. f was not needed so that could just be removed.

For __args the chance of collision is quite small but it's obviously an improvement to gensym it. It was quite annoying to pass a gensym'd args into the generated_callfunc_body, so I just inlined that function.

The newly added tests fail on current master and pass with this PR!

@penelopeysm penelopeysm changed the title Gensym the RGF name instead of using f Gensym / remove the RGF name instead of using f and __args Aug 21, 2026

@ChrisRackauckas ChrisRackauckas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

gensym args would do two things. First, it would make every RGF a unique AST which would break precompilation because then compiling the same function would give you two different hashes. Secondly, it makes it so there is non-freeable memory, so making 1 million RGFs in a session would start to crash the system. Something that does not effect those two properties would be needed.

Comment on lines -402 to +393
f::$RuntimeGeneratedFunctions.RuntimeGeneratedFunction{
::$RuntimeGeneratedFunctions.RuntimeGeneratedFunction{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think just keep the change to f? The args thing is orthogonal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Happy with restricting to f! I'll revert the args bit. I didn't run into issues with the gensym'd args, I know it's pretty hard but is there anyway to test that property?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I'm not mistaken, it's still two separate unicode underscores back to back (i.e. it's not _ , IIRC htmlsymbols.xyz/unicode/U+FF3F and one other). If a real human writes code that has the same variable name as that then they probably deserve more problems than that 🤷

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Of course, security by obscurity isn't fully secure, but it's hard to come up with another solution that hits the properties I mentioned above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmmmmm, they look like ordinary underscores to me:

julia> codeunits("__args")
6-element Base.CodeUnits{UInt8, String}:
 0x5f
 0x5f
 0x61
 0x72
 0x67
 0x73

I don't really mind the security by obscurity (I mean after all a gensym is still not fully "secure"), but I suppose if we can reduce the chance of failures from 0.1% to 0.0001% then it would be worth it. Would you be up for changing that identifier to be a more obnoxious Unicode one?

@ChrisRackauckas

Copy link
Copy Markdown
Member

I'll do the follow up

@ChrisRackauckas
ChrisRackauckas merged commit 28fa8b0 into SciML:master Aug 23, 2026
16 checks passed
@penelopeysm

Copy link
Copy Markdown
Contributor Author

Thanks Chris!

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.

Stack overflow when calling a function named f outside the RGF

2 participants