refactor(compile): single-source the guest-error raise idiom (159 sites, −407 lines)#1271
Merged
Conversation
…tErrorEmitter
The 4-opcode tail (Ldstr msg; Newobj TS{Type,Range,Reference,Syntax}
ErrorCtor; Call CreateException; Throw) was open-coded ~170x across the
emitter files. GuestErrorEmitter now provides ThrowTypeError/
ThrowRangeError/ThrowReferenceError/ThrowSyntaxError (constant message)
and ThrowErrorFromStack (computed message on the stack); 159 sites
across 40 files were converted mechanically (same-identifier-anchored
multiline rewrite), including the two file-local helpers in
Objects.StrictShared whose bodies now delegate.
Deliberately NOT converted: sites with code setters, non-throwing
CreateException uses, the ILCompiler.Classes ctor lookup table, and
TSArray's label-dispatch variants — those are genuinely different
shapes. Emitted opcode stream is identical; helper calls emit the same
IL.
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.
The largest remaining item from the hygiene backlog: the 4-opcode guest-error raise tail (
Ldstr msg; Newobj TS{Type,Range,Reference,Syntax}ErrorCtor; Call CreateException; Throw) was open-coded ~170× across the emitter files — any change to the raise idiom had to be edited everywhere, and two files had already grown local re-inventions.Change
New
GuestErrorEmitterstatic class withThrowTypeError/ThrowRangeError/ThrowReferenceError/ThrowSyntaxError(constant message) andThrowErrorFromStack(computed message already on the stack). 159 sites across 40 files converted via a same-identifier-anchored multiline rewrite — the pattern required the same ILGenerator identifier and the same runtime expression on all four lines, so only exact matches were touched. The two file-local helpers inObjects.StrictSharednow delegate through it.Deliberately not converted (genuinely different shapes): sites with error-code setters, non-throwing
CreateExceptionuses, theILCompiler.Classeserror-ctor lookup table, andTSArray's label-dispatch throw variants.The helper emits the identical opcode stream, so compiled output is byte-for-byte unchanged.
Verification