transpile: simplify and fix comparing SrcLocs by include paths#1548
Merged
transpile: simplify and fix comparing SrcLocs by include paths#1548
SrcLocs by include paths#1548Conversation
This simplifies `SrcLoc` comparing a lot, such that it's obviously sound (i.e., a total ordering). The include path starts with where an item is first included in the main file, continuing until the last `SrcLoc`, whose file is where the item is defined, and thus where its own `SrcLoc` is. Thus, comparing the include path first and then the main `SrcLoc` should work.
spernsteiner
approved these changes
Jan 16, 2026
Collaborator
spernsteiner
left a comment
There was a problem hiding this comment.
One potential issue, but otherwise looks good. I tried the test case that I originally saw crashing here and it works fine now.
a0fa638 to
e6b04c2
Compare
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.
SrcLocsorting is non-transitive and a false total order and equality (panics in 1.81) #1126.@spernsteiner, I'm pretty sure you were right about your suggestion in #1126 (comment).
Include paths are set up such that
include_path.first()is in the main/root file we're transpiling, the root include, whileinclude_path.last()is the final include, with that path containing the definition. Thus, comparing with the definition's location at the end of the include path produces a natural ordering for theSrcLocs should be trivially total (as long as the include paths are well-formed; they didn't use to be) as we're comparing two equivalent things (include_path.iter().copied().chain([loc]).