-
Notifications
You must be signed in to change notification settings - Fork 13
feat(resolver): extract generator functions as definitions (JS/TS) #1333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
445b98d
feat(resolver): extract generator functions as definitions (JS/TS)
carlos-alm 037d326
test(parsers): strengthen generator call attribution assertion with l…
carlos-alm 2b85908
Merge remote-tracking branch 'origin/main' into feat/generator-yield-…
carlos-alm b9c9d97
Merge branch 'main' into feat/generator-yield-resolution
carlos-alm 4f39a7c
Merge branch 'main' into feat/generator-yield-resolution
carlos-alm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
70 changes: 70 additions & 0 deletions
70
tests/benchmarks/resolution/fixtures/jelly-micro/generators/expected-edges.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| { | ||
| "$schema": "../../../expected-edges.schema.json", | ||
| "language": "javascript", | ||
| "description": "Hand-annotated call edges for generator function resolution benchmark", | ||
| "edges": [ | ||
| { | ||
| "source": { "name": "gen2", "file": "generators.js" }, | ||
| "target": { "name": "gen1", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "yield* delegation inside generator — inner call_expression" | ||
| }, | ||
| { | ||
| "source": { "name": "gen3", "file": "generators.js" }, | ||
| "target": { "name": "gen9", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "direct call to another generator from within a generator" | ||
| }, | ||
| { | ||
| "source": { "name": "gen4", "file": "generators.js" }, | ||
| "target": { "name": "gen4helper", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "call to regular function from inside a generator" | ||
| }, | ||
| { | ||
| "source": { "name": "gen5", "file": "generators.js" }, | ||
| "target": { "name": "gen2", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "yield* delegation to another named generator" | ||
| }, | ||
| { | ||
| "source": { "name": "gen5", "file": "generators.js" }, | ||
| "target": { "name": "gen4", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "second yield* delegation from gen5" | ||
| }, | ||
| { | ||
| "source": { "name": "gen6", "file": "generators.js" }, | ||
| "target": { "name": "gen7", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "direct call to sibling generator" | ||
| }, | ||
| { | ||
| "source": { "name": "gen7", "file": "generators.js" }, | ||
| "target": { "name": "gen6", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "direct call to sibling generator (mutual recursion)" | ||
| }, | ||
| { | ||
| "source": { "name": "gen9", "file": "generators.js" }, | ||
| "target": { "name": "gen8", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "yield* delegation — inner call_expression resolves to gen8" | ||
| }, | ||
| { | ||
| "source": { "name": "gen10", "file": "generators.js" }, | ||
| "target": { "name": "gen8", "file": "generators.js" }, | ||
| "kind": "calls", | ||
| "mode": "static", | ||
| "notes": "call from variable-declared generator (const gen10 = function*(){})" | ||
| } | ||
| ] | ||
| } |
56 changes: 56 additions & 0 deletions
56
tests/benchmarks/resolution/fixtures/jelly-micro/generators/generators.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Jelly micro-test: generators | ||
| // Tests call resolution in/between generator functions. | ||
|
|
||
| function* gen1() { | ||
| yield 42; | ||
| } | ||
|
|
||
| function* gen2() { | ||
| yield* gen1(); // yield* delegation → edge gen2 → gen1 | ||
| } | ||
|
|
||
| function* gen3() { | ||
| const it = gen9(); // direct call → edge gen3 → gen9 | ||
| it.next(); | ||
| yield it; | ||
| } | ||
|
|
||
| function gen4helper() { | ||
| return 1; | ||
| } | ||
|
|
||
| function* gen4() { | ||
| yield gen4helper(); // call to regular function → edge gen4 → gen4helper | ||
| } | ||
|
|
||
| function* gen5() { | ||
| yield* gen2(); // yield* delegation → edge gen5 → gen2 | ||
| yield* gen4(); // yield* delegation → edge gen5 → gen4 | ||
| } | ||
|
|
||
| function* gen6() { | ||
| yield gen7(); // call to sibling generator → edge gen6 → gen7 | ||
| } | ||
|
|
||
| function* gen7() { | ||
| yield gen6(); // call to sibling generator → edge gen7 → gen6 | ||
| } | ||
|
|
||
| function* gen8() { | ||
| yield 1; | ||
| yield 2; | ||
| } | ||
|
|
||
| function* gen9() { | ||
| yield* gen8(); // yield* delegation → edge gen9 → gen8 | ||
| } | ||
|
|
||
| // Variable-declared generator | ||
| const gen10 = function* () { | ||
| yield gen8(); // call from var-declared generator → edge gen10 → gen8 | ||
| }; | ||
|
|
||
| // Entry: call some generators | ||
| gen3(); | ||
| gen5(); | ||
| gen10(); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test
attributes calls inside generator body to the generatoronly confirms thatgen8appears somewhere insymbols.calls— it does not assert that the call is scoped togen9. The original bug was that calls fell through to file-level attribution, and this test would pass even with the old (broken) behavior since the call would still appear in the flatcallslist. A stronger assertion would check that no definition with a matching line range contains the call, or use the graph resolution path to confirm thegen9 → gen8edge actually appears.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — rewrote the test to use multi-line generator bodies so line ranges are distinct, then added line-range containment assertions: the call to
gen8must fall withingen9's[line, endLine]range (proving it is attributed to gen9's body), and must NOT fall withingen8's own range. This would have caught the original bug — with the old behavior, generators had no definitions and all calls had file-level attribution outside any definition's range.