Repository navigation
Generator return(value) and throw(e); a throw after a resumed yield is caught by its try - #975
Merged
Merged
Conversation
…s caught by its try A generator typed Generator<T, ...> gets return(value) and throw(e), as JavaScript's: paused at a yield, it resumes there finishing (its finally blocks run) or throwing e (its own try/catch may catch it); one not started or finished does not run. Under -mm=own return() only for a T that owns nothing. Fixed on the way, in generators: a throw or a call after a resumed yield in a `try` went past it (only the first block of the try's body got unwind edges); its catch-type constants did not dominate a resumed turn; a `let` in a `try` read after a yield did not compile (its storage was put in front of the try, not of the generator's switch); a catch variable was a field of the generator object and its use crashed. A yield in a catch block is now an error at the yield (it crashed in LLVM's instruction selection). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d in finally still open Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al is released twice under -mm=own The generator object's `.thrown` field was `<any>undefined`. Under -mm=own a field of an object literal holding `<any>undefined` (or `<any>null`) is released twice - the store of its box is not counted as a move - which wasm's checked heap and Linux caught in every generator typed Generator<...> (00generator_next_value, 00generator_return_throw, the default library's iteration_types). The underlying own bug is recorded in TSLANG 153. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…literal field (open) 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.
Follow-up to #974 (TSLANG 153).
return(value) and throw(e) of a generator typed
Generator<T, ...>, as in JavaScript.return(value)finishes it there, so itsfinallyblocks run.throw(e)throwsethere; the generator's own try/catch may catch it, and it then goes on to its next yield.return(value)gives{ value, done: true }andthrow(e)throwse.addGeneratorResumeMethods,mlirGenGeneratorResumeChecks).return()is only added for a T that owns nothing (a number or a boolean). For any other T its result would hold the value the caller only lends.Fixed on the way: generators and
try, in every memory model.trywent past it: its catch did not catch and its finally did not run. A yield splits the try's body at its label, and only the first block of the body got unwind edges:TryOpLoweringwalked it with acontinueinside ado ... while (false).trydid not compile ("operand #0 does not dominate this use" at thetry). The catch-type constants the landing pad reads were made at the start of the body, which a resumed turn does not pass. In a generator they now go to the function's entry block.letdeclared in atryand read after a yield did not compile, with the same error. Its storage was put in front of the try instead of in front of the generator's switch (GenContext::generatorSwitchOperation).Still open: a yield in a finally block is skipped, as before. The default library's
Generatorwill declarenext(value?),return?andthrow?once a compiler release includes #974 and this PR.Tests:
00generator_return_throw.ts(compile, JIT, rc, own) and diagnostic-locationgenerator_yield_in_catch.ts. Full ctest locally: 8781 tests, 0 failed. The tsc compiler-tests sweep shows no regressions (its only difference is a test that sometimes times out).🤖 Generated with Claude Code