Skip to content

EH fixes: interface-field accessors in try, a call in a catch to a typed catch, uncaught descriptions; ++/-- on accessors - #732

Merged
ASDAlexander77 merged 3 commits into
mainfrom
interface-accessor-try
Oct 29, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
interface-accessor-try

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Two exception-handling fixes, plus ++/-- on accessors, and uncaught exceptions that say what was thrown.

An interface-field accessor that throws inside try is caught

This was the gap left open by #731.

A class can fill an interface's field with a getter and setter, through a tagged cell (#719). A load or store through that field calls the accessor only when it is lowered to LLVM, which happens after try has been lowered. So a throw from the accessor escaped the catch.

The ownership passes (the verifier, inference and stack promotion) run between try lowering and LLVM lowering, and they analyze these loads and stores. So the loads and stores stay as they are:

  • Marking. try lowering records each load or store through such a field (mayCallInterfaceAccessor, sharing the predicate with InterfaceAccessorCell::of).
  • Edges. Once the function is a single CFG, each recorded access ends its block with a new terminator, ts.AccessorUnwindEdge [^cont, ^landing]. This keeps the landing block alive, since it may have no other predecessor, and shows the analyses that the access may leave for the handler.
  • LLVM lowering. The edge becomes a plain branch, and the getter or setter call in the cell branch becomes an invoke that unwinds to the landing block.

A call in a catch can throw to a typed catch in the same function

This was a crash, an abort in the built executable, or a stack overflow:

try {
    try { throw 1; } catch (e: number) { thrower(); }
} catch (e: number) { r = e; }   // reading `e` crashed
  • Cause. On Windows, print with several values builds its line in a variable-size alloca. In a function with exception funclets, that moves the stack, and the CRT then writes the outer catch's object to the wrong address. Building the IR with clang's own backend reproduced it, and removing the alloca alone fixed it.
  • Fix. In such functions the line is now built on the heap and freed once printed. The same now happens in presplit coroutines, where the heap copy used to leak.

++ and -- on a get/set property

o.prop++ was an error: "'++'/'--' on a get/set accessor property is not supported". It now calls the setter with the getter's value plus or minus one, the same as += 1 does. A prefix operator gives the new value, and a postfix operator gives the old one. It works for instance, static, virtual, this., interface and object-literal accessors. The new test is 00class_accessor_increment.ts.

An uncaught exception says what was thrown

In the JIT, an uncaught exception used to print only "uncaught exception". Since #731 made the range checks throw a RangeError, that meant losing the message their asserts used to print. The JIT's exception filter now reads the thrown value from the throw's exception record while the value is still alive:

  • a string, number, boolean or bigint is printed by its value;
  • a class is printed by its name;
  • an Error is printed by its name and message, for example tslang: error: uncaught exception: RangeError: Division by zero.

Every read is guarded, and a record of any other shape is left undescribed. The uncaught/* tests now check this text, and throw_number.ts is new. This applies to Windows only, where the JIT catches the exception; executables built ahead of time still end without a message.

Still open

A call that throws inside a finally while another exception is unwinding still ends the program. The C++ runtime treats that as terminate, and Windows cleanup funclets can't throw.

Tests

  • 00try_catch_accessor.ts now also covers interface-field get and set, finally, and a plain-field implementer.
  • New test 00try_catch_call_in_catch.ts covers catch values of number, class and string types, and a finally on the way out.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 29, 2026 11:13
…atch can throw to a typed catch

- A load or a store through an interface's field whose slot names a cell of
  accessors calls the getter or setter only once it is lowered to LLVM, after
  the `try`. Such an access inside a `try` now ends its block with a
  ts.AccessorUnwindEdge to the handler (added once the function is one CFG),
  which keeps the landing block and lowers to a branch. The getter or setter
  is called by an invoke unwinding there.
- On Windows a print of several values was a variable-size alloca. In a
  function with exception funclets it moved the stack, and an exception thrown
  by a call in a catch, taken by a typed catch of the same function, had its
  catch object written at the wrong address: a crash, or a stack overflow.
  There the line is now built on the heap and freed once written; so is it in
  a presplit coroutine, where the heap copy leaked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`o.prop++` was an error ("'++'/'--' on a get/set accessor property is not
supported"): there is no reference to store the new value to. MLIRGen now
calls the setter with the getter's value plus or minus one, as `+= 1` does,
and gives the new value for a prefix operator and the old one for a postfix.
This covers instance, static, virtual, `this.`, interface and object-literal
accessors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77 ASDAlexander77 changed the title Interface-field accessors that throw in try are caught; a call in a catch can throw to a typed catch Interface-field accessors throwing in try are caught; a call in a catch can throw to a typed catch; ++/-- on accessors Oct 29, 2026
A JIT run that ended in an uncaught exception printed only "uncaught
exception". Since the range checks throw a RangeError (#731), that lost the
message their asserts printed. The JIT's exception filter now reads the thrown
value while it is still alive, from the record of the throw: a string, a
number, a boolean or a bigint by its value, a class by its name, and an Error
(core.ts) by its name and message:

    tslang: error: uncaught exception: RangeError: Division by zero

Every read is guarded; a record of another shape is left undescribed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77 ASDAlexander77 changed the title Interface-field accessors throwing in try are caught; a call in a catch can throw to a typed catch; ++/-- on accessors EH fixes: interface-field accessors in try, a call in a catch to a typed catch, uncaught descriptions; ++/-- on accessors Oct 29, 2026
@ASDAlexander77
ASDAlexander77 merged commit 47fd18f into main Oct 29, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the interface-accessor-try branch October 29, 2026 12:06
ASDAlexander77 added a commit that referenced this pull request Oct 29, 2026
…parameter functions as wider function types (#733)

* A finally that throws while an exception unwinds replaces it (Windows)

On Windows the finally run on the way out of an exception was a cleanup
funclet, which may not throw: a call or a throw there was a second exception
during unwinding, and the process terminated. A finally that may throw is now
entered through the catch-all pad a `return` in it already used, which
rethrows at its end; thrown from it, an exception is a nested one, which
replaces the first, as JavaScript's does.

The copy of the finally on that path also lost its calls' unwind entries
(cloneRegionBefore carried over jumps and parentTryOp only): a call there was
a plain call, which in the funclet has no way out, and -O3 crashed on it. Its
unwind entries, and the interface-field accesses of #732, are carried over now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* A function with fewer parameters can be given as a wider function type

`apply(one)` where `apply` takes `(a: number, b: number) => number` and `one`
takes `a` only was an error ("it takes 1 argument(s), 2 expected"), though
TypeScript lets a function ignore the parameters it does not declare. A named
function or an arrow that captures nothing is now given as a private function
of its own (`<name>.args<N>`) that takes them all and calls it with the first
ones. No result and a `void` one count as the same. A closure is still an
error: its wrapper would have to carry the captures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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