Skip to content

transpile: simplify and fix comparing SrcLocs by include paths#1548

Merged
kkysen merged 3 commits intomasterfrom
kkysen/simplify-src-loc-cmp
Jan 16, 2026
Merged

transpile: simplify and fix comparing SrcLocs by include paths#1548
kkysen merged 3 commits intomasterfrom
kkysen/simplify-src-loc-cmp

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented Jan 15, 2026

@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, while include_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 the SrcLocs 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]).

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.
Copy link
Collaborator

@spernsteiner spernsteiner left a comment

Choose a reason for hiding this comment

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

One potential issue, but otherwise looks good. I tried the test case that I originally saw crashing here and it works fine now.

@kkysen kkysen force-pushed the kkysen/simplify-src-loc-cmp branch from a0fa638 to e6b04c2 Compare January 16, 2026 18:51
@kkysen kkysen merged commit df492e0 into master Jan 16, 2026
11 checks passed
@kkysen kkysen deleted the kkysen/simplify-src-loc-cmp branch January 16, 2026 19:19
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.

SrcLoc sorting is non-transitive and a false total order and equality (panics in 1.81)

2 participants