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

Ability to mark nodes as implicitly safe #4119

Open
m-vo opened this issue Jul 2, 2024 · 0 comments
Open

Ability to mark nodes as implicitly safe #4119

m-vo opened this issue Jul 2, 2024 · 0 comments

Comments

@m-vo
Copy link

m-vo commented Jul 2, 2024

What is considered safe or not in the AST, is currently hardcoded in the SafeAnalysisNodeVisitor. For instance, a node that is an instance of ConstantExpression, is considered safe in all contexts. So when I'm creating my own expressions (that are safe by definition), I need to extend from ConstantExpression for the safe analysis to still work and the escaper node visitor not affecting the output.

In c44bd1f we're suddenly making assumptions about the class from outside. This will break child classes: In the above example a PrintNode wrapping a FooConstantExpression now gets converted to a TextNode ignoring the custom implementation.

How to deal with this? IMHO the ideal way would be to mark the ConstantExpression as @final and introduce an interface/flag for nodes, that marks them as safe in a certain or all contexts. Alternatively the optimizer should probably use get_class instead of instanceof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant