Skip to content

Fix untraced IM element traces, doubled exception header, UnionFind rank - #1474

Merged
Frotty merged 3 commits into
masterfrom
claude/fix-trace-exception-unionfind
Oct 17, 2026
Merged

Frotty merged 3 commits into
masterfrom
claude/fix-trace-exception-unionfind

Conversation

@Frotty

@Frotty Frotty commented Oct 16, 2026

Copy link
Copy Markdown
Member

Three small latent bugs, one commit each, each with a repro that fails before the fix.

ImAttributes.getTrace(Element): the search ran while (q.isEmpty()), so it never looped and every IM element without its own trace reported Ast.NoExpr(). Anything built from such an element lost its source position. Visible case: with -stacktraces on Lua, a concatenation lowered to __wurst_stringConcat printed "when calling __wurst_stringConcat" with no file or line. It now prints e.g. "... in Colors, line 217" like every other call. The fix walks the parents to the nearest traced ancestor (the behaviour before 2019). The breadth-first search it replaces also queued children, so simply flipping the condition would have revisited nodes forever. It could also pick a sibling's trace, one that does not contain the element. Detached untraced elements still get NoExpr.

Utils.printException: printExceptionWithStackTrace already starts with the exception, so the "Encountered compiler bug" diagnostic printed the first line twice.

UnionFind.union: union by rank put the rank back unchanged, so every root stayed at rank 0. Only the tree shape changes. LuaDispatchPreparation groups by root and orders groups by its own method order, so Lua output is unchanged.

Tests: ImTraceTests (new), UnionFindTests (new), UtilsTest, and LuaTranslationTests.aLoweredConcatenationKeepsItsPositionInAStackTrace (new).

Output check: I compared test-output before and after over DeterministicChecks, LuaBackendAuditTests, OptimizerTests, LuaTranslationTests and BugTests: 1574 emitted files, all byte-identical except three LuaTranslationTests Lua files. Their only change is the stack-trace position string above. Only Windows was run locally.

getTrace(Element) searched with `while (q.isEmpty())`, so the loop never
ran and every IM element without a trace of its own reported Ast.NoExpr().
Anything made from such an element lost its source position: with
-stacktraces on Lua, a concatenation lowered to __wurst_stringConcat
printed "when calling __wurst_stringConcat" without file and line.

Walk the parents instead. The search it replaces also queued children,
which would have revisited nodes forever and could pick a sibling's
trace that does not contain the element.
printExceptionWithStackTrace already starts with the exception itself,
so prepending it again printed the first line twice in the
"Encountered compiler bug" diagnostic.
Union by rank put the rank back unchanged, so every root kept rank 0 and
the second argument's tree always went below the first. Only the shape
of the trees changes: LuaDispatchPreparation groups by the root and
orders the groups by its own method order, so Lua output is unchanged.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T16:00:05.498382Z 9ebeb15 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit 1d29696 into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the claude/fix-trace-exception-unionfind branch November 25, 2026 08:53
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.

1 participant