Repository navigation
Bind an untyped/any catch's value as a real any; catch (e: number) takes an int - #347
Merged
Merged
Conversation
…ber) takes an int
`catch (e) { print(e) }` crashed unless the throw was `throw <any>x`: the catch
binds an `any`, but received the raw thrown value. Same for `catch (e: any)`.
Windows: the `.PEAX` CatchableType an int/double/string/class throw carries is
no longer a plain copy. It names a copy function (a thunk MLIRGen synthesizes)
that boxes the value, and the CRT calls it to build the catch variable
(`__thiscall` on x86 - CxxThrowCallingConvPass sets it). An int throw also
lists `.N` with a widening thunk, so `catch (e: number)` catches `throw 1`.
The changed records, arrays and ThrowInfos get new names so objects built
before them cannot be merged with them.
Linux: an untyped/any catch used a `_ZTIPv` clause, which only matches pointer
exceptions (a thrown number was never caught). It is a real catch-all now, and
binding it compares __cxa_current_exception_type() with each type tslang
throws - including the classes this module throws, recorded by MLIRGen - and
boxes accordingly. A `number` catch also lists the int type_info and widens.
00throw_number_untyped_catch.ts now runs on Linux too; new test
00catch_untyped_value.ts reads the caught values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
catch (e) { print(e) }crashed the first timeewas read, unless the code had thrownthrow <any>x. That includesthrow "message".catch (e: any)had the same problem. The catch variable is anany, but it received the raw thrown value. On Linux such a catch did not even catch a thrown number.Windows
.PEAXCatchableType, which is what an untyped catch filters on. That entry is no longer a plain byte copy. It now names a copy function: a small thunk that MLIRGen synthesizes (MLIRGenImpl::mlirGenCatchCopyThunk). The thunk boxes the value into anany, and the CRT calls it to build the catch variable..Nwith a widening thunk, socatch (e: number)now catchesthrow 1. An integer literal is anintin tslang.__thiscall, soCxxThrowCallingConvPasssets that convention on every.eh.copy.*function.linkonce_odr. With the old names, an object built by an older compiler (for example a prebuilt default lib) could be merged with them and the linker would keep either copy.Linux
anycatch used a_ZTIPvclause. In the Itanium ABI that clause matches only pointer exceptions, so a thrown number was never caught. It is now a real catch-all.__cxa_current_exception_type()against the int, double, string andanytypeinfos, and against the typeinfo of each class this module throws. MLIRGen records those classes in the module attributets.thrown_classes. The value is then boxed with its real type descriptor, which unboxing to a class needs.numbercatch also lists the int typeinfo as a clause and widens the value.Tests
00catch_untyped_value.ts: untyped/anycatches read a number, int, string, class and derived class. It also checkscatch (e: number)againstthrow 1and that typed catches are unchanged.00throw_number_untyped_catch.tswas Windows-only and now runs on Linux too.check-x86-eh.sh: the int ThrowInfo's array is now_CTA3H.Verified locally
check-x86-eh.sh: 53/53 ok.check-x86-run.sh: 21 ok, none failed.🤖 Generated with Claude Code