Enhance optimizer to support constant maps#1050
Merged
schungx merged 1 commit intorhaiscript:mainfrom Nov 9, 2025
Merged
Conversation
d64c3c2 to
29ab96d
Compare
schungx
reviewed
Nov 9, 2025
Collaborator
|
Just a minor nitpick in the comments. And Great work. This will be very useful in cases where constant maps are used as a form of enum or avoiding the creation of a large number of constant variables. My own scripts have tons of those so this will be very helpful. |
schungx
reviewed
Nov 9, 2025
schungx
reviewed
Nov 9, 2025
29ab96d to
4e9d836
Compare
Signed-off-by: Pierre-Henri Symoneaux <pierre-henri.symoneaux@ovhcloud.com>
4e9d836 to
d5afecd
Compare
Contributor
Author
|
@schungx thank you for your quick feedback. I made the updates based on your comments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the optimizer to support constant propagation for map access expressions, enabling compile-time evaluation of property and index lookups when the map is a constant known at compile/optimization time. It also adds comprehensive tests to ensure these optimizations work as intended.
Optimizer enhancements for constant map access:
var.property) whenvaris a constant map, allowing direct replacement with the corresponding value at compile time.var[property]) whenvaris a constant map andpropertyis a string or a constant string variable, enabling constant folding for these expressions.#{a: 42}[property]whenpropertyis a constant string variable is also optimized at compile time, removing the need for runtime lookup.Testing improvements:
test_optimizer_const_map, which verifies that constant map optimizations work for both property and index access patterns, including dynamic key access.