Skip to content

Generate internal compiler errors instead of panicking - #7450

Merged
laurmaedje merged 3 commits into
mainfrom
internal-compiler-errors
Nov 27, 2025
Merged

laurmaedje merged 3 commits into
mainfrom
internal-compiler-errors

Conversation

@saecki

@saecki saecki commented Nov 24, 2025

Copy link
Copy Markdown
Member

Avoid crashes: #7301 #7257

But proper fixes are still outstanding.

This adds some utilities to generate internal compiler errors instead of panicking. These errors can capture a stack trace which is nice for debugging. Generating a backtrace is only attempted when debug_assertions are enabled and when RUST_BACKTRACE is set. In release mode debug symbols are stripped anyway, so the backtrace only displays addresses.
The backtrace isn't captured using Backtrace::force_capture, because the paths in the backtrace are absolute and thus machine dependent, I experimented with sanitizing the paths, but that was somewhat hacky since there is no proper API to access the individual frames.

@laurmaedje laurmaedje left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice if the error had a precise line/column number regardless of the backtrace like panics do. if the backtrace API can't do that in release, I suppose a macro still could with file!() and line!(). though that would only nicely work for the assert variant, not for the expect variant.

@saecki
saecki force-pushed the internal-compiler-errors branch from ee90f65 to 4f517b6 Compare November 24, 2025 20:02
@saecki

saecki commented Nov 24, 2025

Copy link
Copy Markdown
Member Author

Using #[track_caller] and std::panic::Location::caller() works!

Comment thread crates/typst-library/src/diag.rs Resolved
@saecki
saecki force-pushed the internal-compiler-errors branch 3 times, most recently from 7a415f1 to d6d1bf4 Compare November 24, 2025 20:45
@laurmaedje

Copy link
Copy Markdown
Member

The Windows tests strike again, c.f. #6433 (comment)

@laurmaedje laurmaedje added the fix A bug fix. label Nov 25, 2025
@saecki
saecki force-pushed the internal-compiler-errors branch from d6d1bf4 to f8a6e08 Compare November 25, 2025 13:18
@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Nov 25, 2025
@saecki
saecki force-pushed the internal-compiler-errors branch from f8a6e08 to 86ed797 Compare November 25, 2025 20:21
@laurmaedje
laurmaedje force-pushed the internal-compiler-errors branch 2 times, most recently from 01a1c60 to 0e18cc1 Compare November 26, 2025 16:56
@laurmaedje
laurmaedje enabled auto-merge November 26, 2025 16:57
@laurmaedje
laurmaedje disabled auto-merge November 26, 2025 16:59
Comment thread crates/typst-pdf/src/tags/tree/build.rs Resolved
@laurmaedje laurmaedje added waiting-on-author Pull request waits on author and removed waiting-on-review This PR is waiting to be reviewed. labels Nov 26, 2025
These barely add value, but I just don't like the look of bare items!
@saecki
saecki force-pushed the internal-compiler-errors branch from 0e18cc1 to 4da3fd0 Compare November 26, 2025 17:59
@saecki
saecki force-pushed the internal-compiler-errors branch from 4da3fd0 to 575e208 Compare November 26, 2025 18:01
@laurmaedje laurmaedje removed the waiting-on-author Pull request waits on author label Nov 27, 2025
@laurmaedje
laurmaedje added this pull request to the merge queue Nov 27, 2025
Merged via the queue into main with commit 1f2d469 Nov 27, 2025
@laurmaedje
laurmaedje deleted the internal-compiler-errors branch November 27, 2025 13:59
laurmaedje added a commit that referenced this pull request Dec 2, 2025
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants