Skip to content

WIP: Prism work, rebase only #402

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

Closed
wants to merge 398 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
398 commits
Select commit Hold shift + click to select a range
5083ce5
Refactor prism benchmarks to match memory comparison script
egiurleo Sep 18, 2024
1e71f22
Run benchmarks and commit results
egiurleo Sep 18, 2024
aae1bb2
Merge pull request #242 from Shopify/emily/benchmarks
egiurleo Sep 19, 2024
852679b
Merge pull request #243 from Shopify/emily/memory-comparison
egiurleo Sep 24, 2024
1b00096
Move cases to prevent fallthrough
amomchilov Sep 30, 2024
48e7f51
Replace duplicated code with explicit fallthrough
amomchilov Sep 30, 2024
f707ea6
Set all prism regression test files to `# typed: false`
egiurleo Sep 24, 2024
bec6d51
Merge pull request #247 from Shopify/emily/standardize-prism-tests
amomchilov Sep 30, 2024
eb7aab4
Merge pull request #246 from Shopify/Alex/fix-fallthrough-cases
amomchilov Sep 30, 2024
a672d2a
Implement translation for constant assignments
amomchilov Sep 30, 2024
afec98e
Implement translation for const path assignments
amomchilov Sep 30, 2024
5b5190b
Remove unused allocation
amomchilov Sep 30, 2024
d7aa9e9
Implement translation for assign to method result
amomchilov Sep 30, 2024
e7d6969
Handle translation of safe navigation operator
egiurleo Sep 24, 2024
c0c4dd4
Handle conditional send with block arguments
egiurleo Sep 30, 2024
1d9a97b
Merge pull request #248 from Shopify/Alex/translate-const-writes
amomchilov Oct 1, 2024
4e76c6a
Merge pull request #249 from Shopify/Alex/translate-call-writes
amomchilov Oct 1, 2024
33c9819
Check flag instead of doing string processing
amomchilov Oct 1, 2024
f5af6b1
Merge pull request #244 from Shopify/emily/fix-typecheck
egiurleo Oct 1, 2024
dcce6f9
Add brief comments to all cases
amomchilov Oct 1, 2024
8742f4b
Merge pull request #250 from Shopify/Alex/case-comments
amomchilov Oct 1, 2024
dda8eef
Remove unnecessary method def
amomchilov Sep 30, 2024
35e9f2d
Implement translation for simple pattern matches
amomchilov Oct 2, 2024
296afa9
Implement translation for simple Array patterns
amomchilov Oct 2, 2024
58befab
Implement translation for Array prefix patterns
amomchilov Oct 1, 2024
2b6450f
Implement translation for Array suffix patterns
amomchilov Oct 1, 2024
82b60fb
Implement translation for find patterns
amomchilov Oct 2, 2024
dd3cecd
Add VS Code tasks for common operations
st0012 Oct 2, 2024
0ab7a73
Merge pull request #256 from Shopify/add-tasks-definition
st0012 Oct 2, 2024
4f6cd34
Merge pull request #251 from Shopify/Alex/translate-pattern-matching
amomchilov Oct 2, 2024
0877ab9
Implement translation for simple Hash patterns
amomchilov Oct 2, 2024
83cf799
Implement translation for `**` in Hash patterns
amomchilov Oct 2, 2024
5bf8378
Implement translation for `**nil` in Hash patterns
amomchilov Oct 2, 2024
d905baf
Merge pull request #254 from Shopify/Alex/translate-Hash-pattern-matc…
amomchilov Oct 2, 2024
8255423
Implement translation for `**nil` in method def
amomchilov Oct 2, 2024
6403a5a
Merge pull request #255 from Shopify/Alex/translate-no-kwargs
amomchilov Oct 3, 2024
c539f67
Implement translation for constant targets
amomchilov Oct 3, 2024
d0b20fc
Implement translation for constant path targets
amomchilov Oct 3, 2024
3f6177a
Extract `translateConst`
amomchilov Oct 3, 2024
9720b16
`using std::is_same_v`
amomchilov Oct 3, 2024
a54dda8
`using std::move`
amomchilov Oct 3, 2024
9f59532
Drop `std::` from `std::unique_ptr`
amomchilov Oct 3, 2024
0cdcf34
Use `auto`
amomchilov Oct 3, 2024
316e50c
Add new lines for readability
amomchilov Oct 3, 2024
5cf8801
Merge pull request #257 from Shopify/Alex/translate-const-targets
amomchilov Oct 4, 2024
da5dda2
Merge pull request #258 from Shopify/Alex/misc-cleanup
amomchilov Oct 4, 2024
533723a
Support defined? node in translation layer
st0012 Oct 2, 2024
e51c5c8
Add new tasks to automate expected parse tree generation
st0012 Oct 4, 2024
1f5c625
Add more test cases for defined node
st0012 Oct 4, 2024
94cdd25
Update Prism test parse trees
st0012 Oct 7, 2024
da121e1
Update rest parameter node's translation
st0012 Oct 7, 2024
5482e63
Implement translation for method aliases
amomchilov Oct 7, 2024
ca57047
Implement translation for global variable aliases
amomchilov Oct 7, 2024
3f7c174
Group together all literal syntaxes
amomchilov Oct 7, 2024
f9622fa
Use `setup-bazel` to cache Bazel in CI
egiurleo Oct 7, 2024
6319e5e
Implement translation for `undef`
amomchilov Oct 7, 2024
c9ff127
Fix printing parse tree with Prism parser
egiurleo Sep 30, 2024
3a5c1d6
Fix all location issues in Translator
egiurleo Sep 30, 2024
d7ee620
Create a test script that will compare prism and sorbet location data
egiurleo Oct 3, 2024
f99db2f
Add location tests to CI workflow
egiurleo Oct 3, 2024
0bd3d5d
Add location tests to VSCode tasks
egiurleo Oct 3, 2024
50cc929
Implement translation for x strings
amomchilov Oct 7, 2024
9ace589
Merge location and regression testing tasks
st0012 Oct 8, 2024
bb22059
Support translating interpolated xstrings
st0012 Oct 8, 2024
a76deb8
Remove unused location `join`
amomchilov Oct 8, 2024
42aeb10
Use `translateSimpleKeyword` for `self`
amomchilov Oct 8, 2024
64c5c99
Lift repeated `loc` variable out of `switch` cases
amomchilov Oct 9, 2024
97409a8
Lift `translateLocation` calls
amomchilov Oct 9, 2024
4b4919c
Remove unnecessary null check
amomchilov Oct 8, 2024
3a421f2
Inline two `join` calls
amomchilov Oct 9, 2024
095db32
Extract `translateLoc` helper
amomchilov Oct 9, 2024
6450e06
Pass `pm_location_t` by value
amomchilov Oct 8, 2024
3eac880
Access location through untyped node pointer
amomchilov Oct 8, 2024
02d28c2
Remove template from `translateSimpleKeyword()`
amomchilov Oct 8, 2024
208cf03
Implement translation for class variable targets
amomchilov Oct 9, 2024
3901164
Implement translation for method call targets
amomchilov Oct 9, 2024
06d2074
Implement translation for global variable targets
amomchilov Oct 9, 2024
e6ce3b1
Implement translation for indexed targets
amomchilov Oct 9, 2024
b3bfcc4
Implement translation for instance var targets
amomchilov Oct 9, 2024
3dcf9b0
Add test for local variable target
amomchilov Oct 3, 2024
3bb2b80
Translate rescue modifier nodes
st0012 Oct 9, 2024
44c9312
Pass `--test-output=errors` flag to CI
egiurleo Oct 9, 2024
e65c2b9
Verify test expectations in CI
egiurleo Oct 8, 2024
39df869
Set RUBY_ROOT as an environment variable in CI
egiurleo Oct 8, 2024
ba7c3e7
Misc cleanup
amomchilov Oct 10, 2024
692c3bc
Split pattern matching into its own recursive fn
amomchilov Oct 10, 2024
7112aa2
Implement translation for alternation patterns
amomchilov Oct 9, 2024
4e19b22
`move` istead of `std::move`
amomchilov Oct 10, 2024
b9bca95
Implement translation for variable binding
amomchilov Oct 10, 2024
ddb966f
Test variable bindings inside Array patterns
amomchilov Oct 10, 2024
f2b0a4b
Handle patterns nested in Hash patterns
amomchilov Oct 10, 2024
4ca321b
Test Array patterns inside other patterns
amomchilov Oct 10, 2024
8d9ecb5
Test nested Hash patterns inside other patterns
amomchilov Oct 8, 2024
8d75b88
Implement translation for variable pinning
amomchilov Oct 10, 2024
f5c7c3d
Implement translation for expression pinning
amomchilov Oct 10, 2024
0c03610
Add empty Gemfile to use Ruby LSP
st0012 Oct 14, 2024
5a3aa28
Support translating rescue clauses
st0012 Oct 10, 2024
a19011e
Simplify rescue node translation
st0012 Oct 14, 2024
1bfe152
Add comments to rescues' test fixture
st0012 Oct 15, 2024
c049d69
Implement translation for shareable constants
amomchilov Oct 15, 2024
583eddf
Implement translation for `for` loops
amomchilov Oct 15, 2024
139ed67
Test `for` loop with `do` keyword
amomchilov Oct 15, 2024
a66537c
Implement translation for simple multi-targets
amomchilov Oct 15, 2024
749e1dd
Implement translation for splats in multi-targets
amomchilov Oct 15, 2024
301eda9
Handle trailing values in multi-targets
amomchilov Oct 15, 2024
f99fb2a
Implement translation for numbered parameters
amomchilov Oct 15, 2024
ba8064a
Implement translation for interpolated symbols
amomchilov Oct 17, 2024
3993e50
Implement translation for interpolated regexp
amomchilov Oct 17, 2024
1251f0d
Extract `translateRegexpOptions()`
amomchilov Oct 17, 2024
38495c3
Support translating block local variables
st0012 Oct 14, 2024
126b69a
Bump Prism to v1.0.0
egiurleo Oct 21, 2024
4a929b1
Bump Prism to v1.1.0
egiurleo Oct 21, 2024
e15197c
Bump Prism to v1.2.0
egiurleo Oct 21, 2024
5ee7d64
Make 'Run a single Prism test' reuse input when possible
st0012 Oct 18, 2024
6176e73
Support translating lambda literals
st0012 Oct 14, 2024
a61c735
Update parser/prism/Translator.cc
st0012 Oct 21, 2024
3276458
Implement translation of “last line matches”
amomchilov Oct 21, 2024
1a35279
Translate ensure clause
st0012 Oct 21, 2024
4381885
Make `PM_SCOPE_NODE` unreachable
amomchilov Oct 21, 2024
8546c56
Use a `repository_rule` to get the RUBY_ROOT env var
egiurleo Oct 21, 2024
8607286
Remove `--define` from our VS Code tasks
egiurleo Oct 21, 2024
13fbb38
Remove `--define RUBY_PATH` from test scripts
egiurleo Oct 21, 2024
0055a36
Implement Prism -> Sorbet translation for `PM_NUMBERED_REFERENCE_READ…
egiurleo Oct 22, 2024
8e17155
Implement Prism -> Sorbet translation for `PM_BACK_REFERENCE_READ_NODE`
egiurleo Oct 22, 2024
12e4f2f
Extract ensure/rescue clause from method body if no begin block is pr…
st0012 Oct 21, 2024
32c8a90
Update test fixtures to reduce noise
st0012 Oct 22, 2024
b48854f
Add a unreachable statement to detect edge case
st0012 Oct 23, 2024
eca902c
Translate `BEGIN` pre-execution node
st0012 Oct 23, 2024
f7f1f06
Translate `END` post-execution node
st0012 Oct 23, 2024
4e2300f
Extract `up_cast` helper
amomchilov Oct 24, 2024
ee0e042
Remove unnecessary `up_cast` calls
amomchilov Oct 24, 2024
2bd24e1
Translate embedded variable node
st0012 Oct 24, 2024
364130e
Extract `down_cast` helper
amomchilov Oct 24, 2024
30df969
Remove unnecessary `down_cast` calls
amomchilov Oct 24, 2024
dd5f52d
Fix incorrect cast in Array patterns
amomchilov Oct 24, 2024
0c34324
Fix incorrect casts in string/symbol handling
amomchilov Oct 24, 2024
1e6b310
Remove unnecessary node type-check
amomchilov Oct 24, 2024
3fdfdf5
Support translating if guards
st0012 Oct 24, 2024
864854d
Support translating unless guards
st0012 Oct 24, 2024
50bef94
Combine if and unless guard conditions
st0012 Oct 24, 2024
c5613f0
Implement translation of interpolated matches
amomchilov Oct 24, 2024
9f563be
Fix formatting
amomchilov Oct 25, 2024
2a66866
Test “match last line” in bool expressions
amomchilov Oct 25, 2024
bdd90ab
Handle implicit rest nodes in multi-writes
amomchilov Oct 25, 2024
8cb485c
Handle implicit rest nodes in multi-targets
amomchilov Oct 25, 2024
b2e02a1
Extract `translateMultiTarget()`
amomchilov Oct 25, 2024
9c80ca7
Implement translation for “flip-flop operator”
amomchilov Oct 25, 2024
a74f2ef
Implement translation for match writes
amomchilov Oct 25, 2024
098f72d
Extract variable binding tests into their own file
amomchilov Oct 25, 2024
eaf42e6
Implement translation for variable captures
amomchilov Oct 25, 2024
f3f21b2
Implement support for constant in Array patterns
amomchilov Oct 25, 2024
40e0fa8
Implement support for constant in Hash patterns
amomchilov Oct 25, 2024
e501b1d
Track translation context when entering methods
amomchilov Oct 22, 2024
cdb6c52
Handle dynamic constant assignment
amomchilov Oct 22, 2024
a0a8c15
Translate PM_MATCH_REQUIRED_NODE and PM_MATCH_PREDICATE_NODE
st0012 Oct 28, 2024
b90b1bc
Add vscode-lldb to recommended extensions list
st0012 Oct 29, 2024
6ae9be4
Add support for debugging Prism tests in VSCode
st0012 Oct 29, 2024
48e8ec5
Add launch.json config to debug Sorbet pipeline
egiurleo Oct 29, 2024
5ebfcae
Fix edge case for lambda with no params
egiurleo Oct 30, 2024
2c64b12
`nullptr` check during `ENFORCE` in `downcast`
egiurleo Oct 30, 2024
71e997c
Change location test's naming convention
st0012 Nov 1, 2024
4c6ebca
Generate error for Sorbet's `assign.rb` error recovery fixture
st0012 Oct 31, 2024
ff56ce5
Remove unnecessary task to set BAZEL_EXEC_ROOT
st0012 Oct 29, 2024
aba49be
Fix edge case where `PM_RESCUE_NODE` has empty body
egiurleo Nov 1, 2024
a354420
Only do dynamic constant assignment workaround in specific cases
egiurleo Nov 1, 2024
ab538c7
Test dynamic constant workaround for all constant assignment types
egiurleo Nov 1, 2024
58ee702
Add more test cases to rescue prism regression tests
egiurleo Nov 5, 2024
190a00c
Handle all constant path assignment node types
egiurleo Nov 4, 2024
deb8d86
Report Prism parse errors
st0012 Nov 4, 2024
69817ad
Address feedback
st0012 Nov 20, 2024
dc0db8e
Add a task to display Prism's parse errors
st0012 Nov 21, 2024
c7229e3
Keep Prism error id's type for easy comparison
st0012 Nov 22, 2024
bd80605
Stop surfacing Prism's EOF error
st0012 Nov 22, 2024
5020842
Fix output of Prism location test errors
egiurleo Nov 25, 2024
9366cb4
Change name of prism regression test suite
egiurleo Nov 26, 2024
9690ca3
Add test corpus with Prism
egiurleo Nov 26, 2024
5043b9f
Add tasks to run corpus tests with Prism
egiurleo Nov 26, 2024
24c5fb6
Update the test target on CI
egiurleo Nov 26, 2024
868ed89
Add Prism handling for packager tests too
st0012 Nov 26, 2024
b92db17
Follow up on #323
st0012 Nov 28, 2024
f177aea
Fix float translation
st0012 Nov 28, 2024
9ca4e4f
Fix integer translation
st0012 Nov 28, 2024
fe05886
Fix `launch.json` for prism regression tests
egiurleo Dec 2, 2024
2dba24a
Make test Pipeline parse with Prism in the case of `indexOne`
egiurleo Dec 2, 2024
6b3f95d
Translator should not treat `~[Integer]` as a method call
st0012 Dec 2, 2024
028a686
Seperate test input for regression and corpus tests
st0012 Dec 3, 2024
5210a43
Properly translate complex literals with prefix `-` or `+`
st0012 Dec 3, 2024
3e13db4
Correctly translate prefixed integer literals
st0012 Dec 3, 2024
ee8d301
Handle special integers with signs too
st0012 Dec 3, 2024
ba01ecd
Handle underscore in integer literals too
st0012 Dec 3, 2024
a595537
Remove error recovery tests from prism test corpus
egiurleo Dec 3, 2024
bc81111
Persist unique counter value between translator instances
egiurleo Dec 4, 2024
c030113
Add desugar tests to Prism corpus
egiurleo Dec 4, 2024
1d318af
Remove desugar/csend test from exclusions
egiurleo Dec 5, 2024
445803e
Make LHS of conditional call operator assignment `CSend`
egiurleo Dec 5, 2024
83d314b
Improve handling of `uniqueCounter` in Prism translator
egiurleo Dec 5, 2024
ee666a3
Add `desugar/defs_not_self` to Prism corpus tests
egiurleo Dec 5, 2024
94c7a42
Translate def nodes with receivers as `DefS`
egiurleo Dec 5, 2024
c78332a
Add more newly-passing tests to Prism corpus
egiurleo Dec 5, 2024
9cc8e09
Add prism regression test for singleton method defs
egiurleo Dec 6, 2024
39a7ff3
Run `desugar/blockpass` test in Prism corpus
egiurleo Dec 6, 2024
c7e8ba2
Add case to `def_singleton` Prism regression test
egiurleo Dec 6, 2024
9f489c9
Pass block arguments to super calls
egiurleo Dec 6, 2024
ec44a58
Add a `super` test case to `def_block_param` regression test
egiurleo Dec 6, 2024
c3a1861
Refactor `translateArguments` to handle block argument as well
egiurleo Dec 6, 2024
d94b1e2
Refactor `PM_SUPER_NODE` case to use refactored arguments logic
egiurleo Dec 6, 2024
de10732
Refactor `PM_INDEX_TARGET_NODE` case to use refactored arguments logic
egiurleo Dec 6, 2024
780062d
Refactor `PM_CALL_NODE` case to use refactored arguments logic
egiurleo Dec 6, 2024
9d0db9b
Refactor index operator writes to use refactored arguments logic
egiurleo Dec 6, 2024
13b605e
Refactor `translateArguments` to remove unused parameter
egiurleo Dec 6, 2024
800a327
Change argument name to `blockArgumentNode`
egiurleo Dec 9, 2024
aa31fcb
Correctly handle calls to `super` with block
egiurleo Dec 9, 2024
cf3a0ba
Handle forwarding super node with block argument
egiurleo Dec 9, 2024
058af5f
Fix splat arg translation in Prism
st0012 Dec 9, 2024
cd540f8
Handle implicit rest nodes in array patterns
st0012 Dec 16, 2024
f27ffef
Properly translate pattern matching value node with patternTranslate()
st0012 Dec 16, 2024
453a5e8
Skip error message checking when running Corpus tests with Prism
st0012 Dec 9, 2024
821af7a
Remove `desugar/range` from excluded tests
egiurleo Dec 17, 2024
1a19767
Fix test error by passing `skipDynamicConstantAssignment` flag...
egiurleo Dec 17, 2024
159ec46
Refactor `skipDynamicConstantWorkaround` logic
egiurleo Dec 17, 2024
ca62446
Remove `desugar/regex` from failing tests
egiurleo Dec 17, 2024
da64685
Run two more tests that are only failing because of error differences
egiurleo Dec 17, 2024
5c0d2c4
Improve pattern matching support with hash patterns
st0012 Dec 17, 2024
0a7188c
Handle implicit hash literal too
st0012 Dec 18, 2024
5f48178
Update test/BUILD for rewriter tests
st0012 Dec 18, 2024
94255e8
Run `rewriter/def_delegator` test as part of prism corpus
egiurleo Dec 18, 2024
e2ce4ce
Introduce `isKeywordHashElement` method to fix `def_delegator` test
egiurleo Dec 18, 2024
258a1a3
Remove `rewriter/rails/delegate` test from skipped rewriter tests
egiurleo Dec 18, 2024
36290a6
Refactor `translateHash` into `translateKeyValuePairs`
egiurleo Dec 18, 2024
7588db9
Add `local_vars` tests to prism corpus and exclude failing test
egiurleo Dec 19, 2024
533c2ac
Fix bracket method call's location translation
st0012 Dec 19, 2024
86b2a45
Generate empty Args node for method definitions with empty parentheses
st0012 Dec 19, 2024
9f6df3a
Run `local_vars/z_super_args_splats_blocks` test in Prism corpus
egiurleo Dec 19, 2024
8c253b0
Handle translation of post params
egiurleo Dec 19, 2024
f4c02d1
Add `parser/kwnil_errors` to skipped tests with a note
egiurleo Dec 20, 2024
f82d80d
Correctly translate post while loop
st0012 Dec 20, 2024
2d8be59
Correctly translate post until loop
st0012 Dec 20, 2024
0302486
Add namer tests to prism corpus
egiurleo Dec 19, 2024
d2c7040
Add `namer/arguments` test to Prism corpus
egiurleo Dec 19, 2024
21a5169
Modify locations of kw arguments and params to match legacy parser
egiurleo Dec 19, 2024
7af4f1b
Run two more namer tests that now pass
egiurleo Dec 19, 2024
f09488a
Fix call with empty message's location translation
st0012 Jan 6, 2025
0246af0
Include LSP tests in Prism Corpus tests
st0012 Jan 6, 2025
275e124
Correctly translate constant write nodes' location
st0012 Jan 6, 2025
ebe2f05
Fix symbol location for hash, keyword argument keys
st0012 Jan 7, 2025
5928811
Run Prism Corpus against all Sorbet component tests
st0012 Jan 7, 2025
8e77b08
Use improved libprism source to build Prism without dependency on Ruby
st0012 Jan 10, 2025
4738277
Use another mock source
st0012 Jan 10, 2025
9ce9635
Pull Prism source files from `ruby/prism` repo
egiurleo Jan 13, 2025
823b2a6
Add formatter for Prism node types
egiurleo Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
push:
branches: [prism]
pull_request:
branches: [prism]
jobs:
tests:
runs-on: ubuntu-latest
name: Prism Parser Regression Tests
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.0
- name: Set up Bazel
uses: bazel-contrib/[email protected]
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Store build cache per workflow.
disk-cache: ${{ github.workflow }}
# Share repository cache between workflows.
repository-cache: true
- name: Verify parse trees
run: ./tools/scripts/verify_prism_regression_tests.sh
- name: Run tests
run: ./bazel test //test:prism_regression --config=dbg --test_output=errors
- name: Run location tests
run: ./bazel test //test:prism_location_tests --config=dbg --test_output=errors
- name: Run corpus tests
run: ./bazel test //test:test_corpus_prism --config=dbg --test_output=errors
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"recommendations": [
// C++ intellisense with clangd.
"llvm-vs-code-extensions.vscode-clangd"
"llvm-vs-code-extensions.vscode-clangd",
// TODO: remove this before upstreaming
"vadimcn.vscode-lldb",
],
"unwantedRecommendations": [
// Microsoft C++ intellisense (doesn't work properly with Sorbet)
Expand Down
39 changes: 38 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,43 @@
"ignoreFailures": false
}
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Prism test in LLDB",
"program": "${workspaceFolder}/bazel-bin/test/test_PosTests/prism_regression/${input:prism_regression_test_name}_prism.runfiles/com_stripe_ruby_typer/test/pipeline_test_runner",
"args": ["--single_test=${workspaceFolder}/test/prism_regression/${input:prism_regression_test_name}.rb", "--parser=prism"],
// We need to run all tests to generate the pipeline_test_runner files, which are needed by the LLDB debugger to execute the tests.
"preLaunchTask": "Run all Prism regression tests",
"stopOnEntry": false,
"sourceMap": {
"": "${workspaceFolder}",
},
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Sorbet pipeline in LLDB",
"program": "${workspaceFolder}/bazel-bin/main/sorbet",
"args": ["--parser=prism", "${input:file_path}"],
"preLaunchTask": "Build with Prism",
"stopOnEntry": false,
"sourceMap": {
"": "${workspaceFolder}",
},
},
],
"inputs": [
{
"id": "prism_regression_test_name",
"type": "promptString",
"description": "Enter the test name, e.g. case for running test/prism_regression/case.rb",
},
{
"id": "file_path",
"type": "promptString",
"description": "Enter the path to the file to typecheck, e.g. test/prism_regression/case.rb",
}
]
}
}
136 changes: 136 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build with Prism",
"type": "shell",
"command": "./bazel build //main:sorbet --config=dbg",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always"
}
},
{
"label": "(Re)Generate Prism test",
"type": "shell",
"command": "TEST_NAME=${input:prism_regression_test_name}; $EDITOR -w test/prism_regression/$TEST_NAME.rb; ./bazel-bin/main/sorbet --stop-after=parser --print=parse-tree test/prism_regression/$TEST_NAME.rb > test/prism_regression/$TEST_NAME.parse-tree.exp; $EDITOR test/prism_regression/$TEST_NAME.parse-tree.exp test/prism_regression/$TEST_NAME.rb",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always"
}
},
{
"label": "Run a single Prism regression test",
"type": "shell",
"command": "./bazel test //test:test_PosTests/prism_regression/${input:prism_regression_test_name}_prism //test:prism_regression/${input:prism_regression_test_name}_location_test --config=dbg --test_output=all",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always"
},
// With this option, when running this task with the `Tasks: Rerun Last Test` command, it'll
// reuse the previous run's input, rather than prompting for it again
"runOptions": {
"reevaluateOnRerun": false
}
},
{
"label": "Run all Prism regression tests",
"type": "shell",
"command": "./bazel test //test:prism_regression //test:prism_location_tests --config=dbg --test_output=all",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always"
}
},
{
"label": "Run all Prism corpus tests",
"type": "shell",
"command": "./bazel test //test:test_corpus_prism --config=dbg --test_output=all",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always"
}
},
{
"label": "Run a single Prism corpus test",
"type": "shell",
"command": "./bazel test //test:test_PosTests/testdata/${input:prism_corpus_test_name}_prism --config=dbg --test_output=all",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always"
},
// With this option, when running this task with the `Tasks: Rerun Last Test` command, it'll
// reuse the previous run's input, rather than prompting for it again
"runOptions": {
"reevaluateOnRerun": false
}
},
{
"label": "Typecheck with Prism",
"type": "shell",
"command": "bazel-bin/main/sorbet --parser=prism ${input:file_path}",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": ["Build with Prism"],
"presentation": {
"reveal": "always"
}
},
{
"label": "Display Prism parse tree & errors for Ruby file",
"type": "shell",
"command": "tools/scripts/inspect_parsing_errors.rb ${file}",
"presentation": {
"reveal": "always"
},
"options": {
// Makes sure the shell can find the correct Ruby version
"shell": {
"executable": "${env:SHELL}",
"args": ["-c"]
}
},
"problemMatcher": []
}
],
"inputs": [
{
"id": "prism_corpus_test_name",
"type": "promptString",
"description": "Enter the test name, e.g. parser/and_and_bug for running test/testdata/parser/and_and_bug.rb",
},
{
"id": "prism_regression_test_name",
"type": "promptString",
"description": "Enter the test name, e.g. case for running test/prism_regression/case.rb",
},
{
"id": "file_path",
"type": "promptString",
"default": "test.rb",
"description": "Enter the file path to typecheck, e.g. test.rb",
}
]
}
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source "https://rubygems.org"
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
GEM
remote: https://rubygems.org/
specs:

PLATFORMS
arm64-darwin-23
ruby

DEPENDENCIES

BUNDLED WITH
2.5.17
Empty file added break.rb
Empty file.
21 changes: 21 additions & 0 deletions main/options/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ buildOptions(const vector<pipeline::semantic_extension::SemanticExtensionProvide
cxxopts::value<vector<string>>()->implicit_value("all"), "SECTION");
// }}}

options.add_options("dev")("parser", "Which parser to use", cxxopts::value<string>()->default_value("sorbet"),
"{sorbet, prism}");

for (auto &provider : semanticExtensionProviders) {
provider->injectOptions(options);
}
Expand Down Expand Up @@ -791,6 +794,22 @@ Phase extractStopAfter(cxxopts::ParseResult &raw, shared_ptr<spdlog::logger> log
return Phase::INIT;
}

Parser extractParser(cxxopts::ParseResult &raw, shared_ptr<spdlog::logger> logger) {
string opt = raw["parser"].as<string>();
for (auto &known : parser_options) {
if (known.option == opt) {
return known.flag;
}
}
vector<string_view> allOptions;
for (auto &known : parser_options) {
allOptions.emplace_back(known.option);
}

logger->error("Unknown --parser option: {}\nValid values: {}", opt, fmt::join(allOptions, ", "));
return Parser::SORBET;
}

// Given a path, strips any trailing forward slashes (/) at the end of the path.
string_view stripTrailingSlashes(string_view path) {
while (path.back() == '/') {
Expand Down Expand Up @@ -954,6 +973,7 @@ void readOptions(Options &opts,
throw EarlyReturnWithCode(1);
}
opts.stopAfterPhase = extractStopAfter(raw, logger);
opts.parser = extractParser(raw, logger);

opts.silenceErrors = raw["quiet"].as<bool>();
opts.autocorrect = raw["autocorrect"].as<bool>();
Expand Down Expand Up @@ -1346,6 +1366,7 @@ void readOptions(Options &opts,
fmt::print("Sorbet typechecker {}\n", sorbet_full_version_string);
throw EarlyReturnWithCode(0);
}

} catch (cxxopts::OptionParseException &e) {
logger->info("{}. To see all available options pass `--help`.", e.what());
throw EarlyReturnWithCode(1);
Expand Down
23 changes: 23 additions & 0 deletions main/options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,28 @@ enum class Phase {
INFERENCER,
};

enum class Parser {
PRISM,
SORBET,
};

struct ParserOptions {
std::string option;
Parser flag;
};

const std::vector<ParserOptions> parser_options({
{"sorbet", Parser::SORBET},
{"prism", Parser::PRISM},
});

struct AutogenConstCacheConfig {
// A file which contains a cache that can be used to potentially skip autogen
std::string cacheFile;
// A list of files which have changed since the last autogen run.
std::vector<std::string> changedFiles;
};

namespace {

#if !defined(EMSCRIPTEN)
Expand All @@ -120,6 +142,7 @@ constexpr size_t MAX_CACHE_SIZE_BYTES = 1L * 1024 * 1024 * 1024; // 1 GiB
struct Options {
Printers print;
Phase stopAfterPhase = Phase::INFERENCER;
Parser parser = Parser::SORBET;
bool noStdlib = false;

// Should we monitor STDOUT for HUP and exit if it hangs up. This is a
Expand Down
2 changes: 2 additions & 0 deletions main/pipeline/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cc_library(
"//namer",
"//packager",
"//parser",
"//parser/prism",
"//payload/binary",
"//payload/text",
"//resolver",
Expand Down Expand Up @@ -70,6 +71,7 @@ cc_library(
"//main/options",
"//namer",
"//parser",
"//parser/prism",
"//payload/binary",
"//payload/text",
"//resolver",
Expand Down
Loading