Build TABLESWITCH from sorted arrays in SWITCH#518
Open
rootvector2 wants to merge 1 commit into
Open
Conversation
The TABLESWITCH branch filled the table from the caller's unsorted match/targets arrays instead of the sorted clones the LOOKUPSWITCH branch uses, so an unsorted match array produced a table with out-of-order case values and a low/high header that disagrees with the emitted offset count.
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.
SWITCHclones the caller'smatch/targetsarrays and sorts only the clones, but the TABLESWITCH branch fills the table from the original unsortedmatch/targets, while the LOOKUPSWITCH branch usesmatchClone/targetsClone. When the match array is passed unsorted (the class javadoc documents unsorted input and promises to leave the caller's arrays unaltered) and its sorted form is gap-free, the fill loop runs over unsorted keys, so the generatedTABLESWITCHgets out-of-order case values padded with default entries.TABLESWITCH.dumpthen writeslow = match[0]andhigh = match[last]that disagree with the count of offset words emitted, and re-reading the dumped instruction consumes onlyhigh - low + 1offsets, reinterpreting the surplus words as the next instructions.Fill the table from
matchClone/targetsCloneto match the LOOKUPSWITCH branch. Found while auditing the switch-generation paths.mvn; that'smvnon the command line by itself.