Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
6839ebf
Fix lambda `Send` locations
amomchilov Nov 10, 2025
b88f9ae
Add fallback to legacy pipeline
amomchilov Dec 3, 2025
b94c06f
Desugar `PM_SUPER_NODE`
thomasmarshall Dec 8, 2025
dc2bf13
Skip loop if there's no splats at all
amomchilov Dec 9, 2025
97cf2b3
TODO
amomchilov Dec 9, 2025
cacac5e
Move `messageLoc` declaration
amomchilov Dec 9, 2025
6cfb547
Narrow scope of `blockPassLoc`
amomchilov Dec 9, 2025
caa572a
Move `blockExpr` declaration up
amomchilov Dec 9, 2025
dde5631
Move symbol proc desugaring up
amomchilov Dec 9, 2025
96a6b95
Simplify checks for `blockPassArg`
amomchilov Dec 9, 2025
cf332b2
Simplify checks for `blockExpr`
amomchilov Dec 9, 2025
12f0d09
Inline `blockPassArgIsSymbol`
amomchilov Dec 9, 2025
de5638e
Narrow scope of `blockStatsStore` check
amomchilov Dec 9, 2025
4eaf867
Invert `if`
amomchilov Dec 9, 2025
e7335a7
Narrow scope of block-related variables
amomchilov Dec 9, 2025
1b996ae
Inline `methodName`
amomchilov Dec 9, 2025
1b336a2
FIXME: move this comment
amomchilov Dec 9, 2025
d6b4e93
Rename `name` → `methodName`
amomchilov Dec 9, 2025
d61d326
Narrow scope of `prismBlock`
amomchilov Dec 9, 2025
b504ca7
Desugar conditional sends
amomchilov Dec 9, 2025
be4ec3c
fixup add comment
amomchilov Dec 9, 2025
9eb3085
extract desugarLiteralBlock
jesse-shopify Dec 9, 2025
81141c6
extract desugarBlockPassArgument
jesse-shopify Dec 9, 2025
2b538c4
Match Whitequark based desugar of call node when both forwarding and …
jesse-shopify Dec 10, 2025
7e40138
Match legacy desugar of call with block pass a block literal
jesse-shopify Dec 10, 2025
a286934
Update error handling file enumeration of issues
jesse-shopify Dec 10, 2025
f045e74
Compare NameRefs instead of strings
amomchilov Dec 10, 2025
d7dc1a8
Move receiver handling up
amomchilov Dec 10, 2025
7e606c6
Rename `messageLoc` → `methodNameLoc`
amomchilov Dec 10, 2025
9c1c0f5
Lift `isPrivateOk` local
amomchilov Dec 10, 2025
e0ae143
Extract `desugarMethodCall()`
thomasmarshall Dec 8, 2025
73a4c6f
Additional testing for call node forwarding error cases
jesse-shopify Dec 10, 2025
1930f47
Extract `desugarBlock()`
amomchilov Dec 10, 2025
33f13c0
Lift `block` desugaring up
amomchilov Dec 10, 2025
7718b0d
Align location of flattenKwargs to whitequark ouput
jesse-shopify Dec 10, 2025
67ad1fa
Add tests for call forwarding variations in error recovery
jesse-shopify Dec 10, 2025
17d1a1d
Lift out `argumentsNode` local
amomchilov Dec 10, 2025
d0e9139
Reuse `receiverNode` local
amomchilov Dec 10, 2025
7467f2c
Migrate `computeMethodCallLoc()` block param
amomchilov Dec 10, 2025
ba7049b
Lift `block_given?` check up
amomchilov Dec 10, 2025
a4c0635
Align PM_LAMBDA_NODE location with legacy desugar
jesse-shopify Dec 10, 2025
e65b483
align PM_SUPER_NODE with legacy desugar locations
jesse-shopify Dec 10, 2025
9cb22bd
Exclude prism regression tests related to error recovery from prism_r…
jesse-shopify Dec 10, 2025
a33dccb
Align parens handling with legacy desugar for PM_MULTI_TARGET_NODE
jesse-shopify Dec 10, 2025
d9b2d37
document excludes in prism_regression tests
jesse-shopify Dec 10, 2025
8273f9b
More loaction updates for PM_FOR_LOOP and call forwarding
jesse-shopify Dec 10, 2025
3029a4f
Additional location update to match existing behavior
jesse-shopify Dec 10, 2025
2194f23
Better document prism exclusions
jesse-shopify Dec 10, 2025
7b2f145
Restore disable-parser-comparison flags
jesse-shopify Dec 10, 2025
6ecd308
Update PM_CASE_NODE locations to match legacy when "when body" is empty
jesse-shopify Dec 10, 2025
b982d45
more sophisticated PM_CASE_NODE location fix
jesse-shopify Dec 11, 2025
c2092dc
Fix heredoc locations
jesse-shopify Dec 11, 2025
e04bcb8
Fix issues following rebase
jesse-shopify Dec 11, 2025
cef3ac8
refactor desugarMlhs to fix tests and improve code
jesse-shopify Dec 11, 2025
28cdc1a
Align string / HEREDOC locations
jesse-shopify Dec 11, 2025
b2cfeaf
Align with whitequark on locations of PM_CASE_NODE and PM_IT_PARAMETE…
jesse-shopify Dec 11, 2025
7f35d5d
disable-parser-comparison on additional prism_regression tests
jesse-shopify Dec 12, 2025
19c52a7
Fix tests related to PM_LAMBDA_NODE
amomchilov Dec 16, 2025
ccbc0a0
exclude more files from test_corpus_prism
jesse-shopify Dec 12, 2025
7682363
Directly desugar lambdas
amomchilov Dec 16, 2025
ee867de
Directly desugar `block_given?`
amomchilov Dec 8, 2025
e883f9c
End-to-end Desugar tests
amomchilov Dec 16, 2025
f15595d
Fix Regexp desugared content location
amomchilov Nov 12, 2025
26cd5ff
Throw `PrismFallback` in unimplemented code paths
amomchilov Dec 11, 2025
8759879
Narrow type of `make_node_with_expr()`
amomchilov Dec 3, 2025
a304c35
Delete most of `PrismDesugar.cc`
amomchilov Dec 3, 2025
8db20bd
Delete `directDesugar` dead code
amomchilov Nov 17, 2025
a323ede
Narrow type of `make_unsupported_node()`
amomchilov Dec 3, 2025
2a46c43
Make `make_node_with_expr()` static
amomchilov Dec 3, 2025
0ccd7ea
Delete `directlyDesugar` checks
amomchilov Dec 3, 2025
7133f80
Delete remaining `directlyDesugar` uses
amomchilov Nov 17, 2025
091fa5f
Rework `hasExpr()` into `enforceHasExpr`
amomchilov Dec 3, 2025
9a20928
Delete `hasExpr()`
amomchilov Nov 17, 2025
bfe1ce1
Migrate `desugarScopeBodyToRHSStore` to non-optional
amomchilov Nov 17, 2025
f41b7e7
Delete always-true check
amomchilov Nov 17, 2025
7e92626
Add new `ExprOnly` wrapper node
amomchilov Dec 8, 2025
1672492
Add `desugar()` methods
amomchilov Dec 8, 2025
29fdfc3
Merge translate+desugar for Hash nodes
amomchilov Dec 3, 2025
01b60e2
Update translateRegexp to return expr_only
amomchilov Dec 10, 2025
a1cd08c
Update translateRegexpOptions to return expr_only
jesse-shopify Nov 21, 2025
bd2eb52
PM_ALIAS_GLOBAL_VARIABLE_NODE return expr_only
jesse-shopify Nov 24, 2025
dc7b210
Migrate to `expr_only`
jesse-shopify Nov 24, 2025
f0f8dd4
PM_INTERPOLATED_SYMBOL_NODE, PM_INTERPOLATED_X_STRING_NODE, PM_INTERP…
jesse-shopify Nov 24, 2025
bc2d6e7
PM_IMAGINARY_NODE return expr_only
jesse-shopify Nov 25, 2025
f1201be
PM_RANGE_NODE return expr_only
jesse-shopify Nov 25, 2025
d2bd161
PM_WHILE_NODE, PM_UNTIL_NODE return expr_only
jesse-shopify Nov 25, 2025
f7c4746
add desugarBreakNextReturn to handle those cases add desugarArguments…
amomchilov Dec 4, 2025
8ea5e31
PM_YIELD_NODE returns expr_only
jesse-shopify Nov 25, 2025
b68047d
PM_X_STRING_NODE returns expr_only
jesse-shopify Nov 25, 2025
26e94ec
PM_INDEX_TARGET_NODE returns expr_only
jesse-shopify Nov 25, 2025
773481d
PM_ARRAY_NODE returns expr_only
jesse-shopify Nov 25, 2025
1f322e0
Replace `desugarArguments()` with `nodeListToStore()`
jesse-shopify Nov 25, 2025
186e317
PM_UNDEF_NODE returns expr_only
jesse-shopify Nov 25, 2025
84c12ff
PM_EMBEDDED_STATEMENTS_NODE returns expr_only
jesse-shopify Nov 25, 2025
b4d9841
PM_PARENTHESES_NODE returns expr_only
jesse-shopify Nov 25, 2025
5eccf3b
PM_STATEMENTS_NODE returns expr_only
jesse-shopify Nov 25, 2025
b5e0472
Use takeDesugaredExprOrEmptyTree where possible
jesse-shopify Nov 26, 2025
b4c1cd3
Allow specifying location for empty tree ExprOnly
thomasmarshall Nov 26, 2025
a5936d3
Fix location for empty regexps
thomasmarshall Nov 26, 2025
788c3eb
Translate begin node inside method context
thomasmarshall Nov 26, 2025
3563d0d
Reorder rescue case temp name to match original parser
thomasmarshall Nov 26, 2025
cdcc323
Add missing parse-tree exp
thomasmarshall Nov 26, 2025
96e2641
PM_BEGIN_NODE returns expr_only
jesse-shopify Nov 26, 2025
ed14850
PM_FORWARDING_SUPER_BLOCK returns expr_only partly
jesse-shopify Nov 27, 2025
1037498
PM_MULTI_WRITE_NODE returns expr_only partly
jesse-shopify Nov 27, 2025
70aa8c5
PM_RESCUE_MODIFIER_NODE returns expr_only
jesse-shopify Nov 27, 2025
a3f9521
PM_SPLAT_NODE returns expr_only
jesse-shopify Nov 27, 2025
6eaa4dd
PM_IF_NODE and PM_UNLESS_NODE return expr_only and refactored
jesse-shopify Nov 27, 2025
ce458e3
Migrate `it` parameters to `expr_only`
amomchilov Dec 8, 2025
08bce71
desugar Assignment helpers
jesse-shopify Dec 1, 2025
b3f1ecc
translateConst use expr_only and narrow return
jesse-shopify Dec 2, 2025
eda3c20
change interface of translateConst
jesse-shopify Dec 2, 2025
c8a72ec
Remove legacy parser code from PM_CASE_NODE
jesse-shopify Dec 2, 2025
c1bc0b6
more removal of legacy parser from PM_CASE_NODE
jesse-shopify Dec 2, 2025
bc7e1a9
migrate make_unsupported_node to use expr_only
jesse-shopify Dec 2, 2025
72e8e75
mark PM_WHEN_NODE as unreachable
jesse-shopify Dec 2, 2025
8be6dc7
Add collectPatternMatchingVarsPrism and update PM_CASE_MATCH_NODE
jesse-shopify Dec 3, 2025
5e694e3
Additional work on pattern matching to fix tests and handle more cases
jesse-shopify Dec 3, 2025
21266b0
Remove legacy parser code from PM_FOR_NODE - part 1
jesse-shopify Dec 3, 2025
de2693a
PM_FOR_NODE part 2
jesse-shopify Dec 3, 2025
19dd06a
PM_FOR_NODE part 3
jesse-shopify Dec 3, 2025
f753648
remove translateStatements
jesse-shopify Dec 3, 2025
ffcf882
Delete `desugarHash()`
amomchilov Dec 3, 2025
457c244
Migrate `desugarScopeBodyToRHSStore()`
amomchilov Dec 3, 2025
f58c479
Clean up `this->enterModuleContext()` param
amomchilov Dec 3, 2025
557a434
Rename to `desugarClassOrModule()`
amomchilov Dec 3, 2025
bb760a1
Migrate bodies of class/sclass/module
amomchilov Dec 3, 2025
a4a1717
Delete `parser::Send` construction
amomchilov Dec 10, 2025
f59555f
Remove `kwargsHashHasExpr`
amomchilov Dec 3, 2025
76b6899
Remove `supportedArgs`
amomchilov Dec 2, 2025
ac05a70
Rework check for `block_given?`
amomchilov Dec 2, 2025
ec14f79
Remove `attemptToDesugarBlockParams`
amomchilov Dec 2, 2025
92fbe75
Narrow `didDesugarBlockParams`
amomchilov Dec 2, 2025
4bb04e5
Move `supportedCallType` down
amomchilov Dec 2, 2025
d252549
Remove dead branch
amomchilov Dec 2, 2025
2b0a2ed
Remove `supportedBlock`
amomchilov Dec 2, 2025
346ba68
Prune dead branches
amomchilov Dec 2, 2025
d2fed70
Remove `supportedCall`
amomchilov Dec 2, 2025
2ac2079
Remove `attemptToDesugarParams`
amomchilov Dec 2, 2025
16973e1
Remove `parser::DefMethod` construction
amomchilov Dec 2, 2025
11a1a68
Narrow `didDesugarParams`
amomchilov Dec 2, 2025
c743d9f
Bury `didDesugarParams` check into helper
amomchilov Dec 2, 2025
da4dd9e
Remove always-true bool return
amomchilov Dec 2, 2025
a83e5e3
Remove always-true bool param
amomchilov Dec 2, 2025
674e1b3
Replace `c_all_of()` with loop and eager throw
amomchilov Dec 2, 2025
e9bf433
Invert if-else
amomchilov Dec 2, 2025
bda1765
Remove `parser::DefMethod`/`DefS` construction
amomchilov Dec 2, 2025
5f28037
Add new `desugarParametersNode()` overload
amomchilov Dec 2, 2025
3925d89
Reuse `desugarParametersNode()` for block params
amomchilov Dec 3, 2025
6a4d61c
Migrate `it` desugar logic
amomchilov Dec 8, 2025
c8964d1
Delete unused `blockParameters` local
amomchilov Dec 8, 2025
b310526
Delete old parameter translation functions
amomchilov Dec 2, 2025
b0ebf11
Remove `NodeVec` return
amomchilov Dec 2, 2025
00ed97b
Return `PARAM_store` from helper
amomchilov Dec 2, 2025
38ff187
Use ExprOnly for `translateOpAssignment()` and co.
amomchilov Dec 2, 2025
bef16b6
Migrate params to `ast::ExpressionPtr`
amomchilov Dec 2, 2025
d763f2c
Migrate `translateAnyOpAssignment()` param
amomchilov Dec 2, 2025
a38d176
Rename `lhsExpr` → `lhs`
amomchilov Dec 2, 2025
b5afdb4
Rename `rhsExpr` → `rhs`
amomchilov Dec 4, 2025
6d2f812
Clean up `translateIndexAssignment()` body
amomchilov Dec 2, 2025
13eacf8
Don't pass block when desugaring index assignement
amomchilov Dec 4, 2025
f4f61fb
Delete `translateArguments()`
amomchilov Dec 2, 2025
f35a2b7
Narrow `translateIndexAssignment()` return type
amomchilov Dec 2, 2025
35a86a4
Migrate op assigns to return `ExpressionPtr`
amomchilov Dec 4, 2025
734ff5c
Migrate translateRegexp and translateRegexpOptions to return Expressi…
jesse-shopify Dec 4, 2025
53d3535
Remove translateMulti and translateMultiInto
jesse-shopify Dec 4, 2025
b16b6f0
Disable prism/legacy pipeline comparison for certain tests
thomasmarshall Nov 27, 2025
01bd93d
Extract lambda in desugarMlhs
thomasmarshall Dec 3, 2025
070ae63
Pass prism node to desugarMlhs
thomasmarshall Dec 3, 2025
51b9549
Use desugar in PM_MULTI_WRITE_NODE
thomasmarshall Dec 3, 2025
94c2e59
Use desugar in PM_MULTI_TARGET_NODE
thomasmarshall Dec 3, 2025
cfc272e
Add destructureMlhsParam
thomasmarshall Dec 4, 2025
96989bb
Remove intermediate `NodeVec`
amomchilov Dec 2, 2025
bfa79bc
Remove translateMultiTargetLhs
thomasmarshall Dec 4, 2025
a74de47
Add tests for parameter destructuring
amomchilov Dec 4, 2025
f39d8a6
remove legacy parser from patternTranslate
jesse-shopify Dec 4, 2025
06e465c
Remove unreachable guard clause
thomasmarshall Dec 5, 2025
1df69b4
Fix formatting
thomasmarshall Dec 5, 2025
599ce67
fixup! remove legacy parser from patternTranslate
thomasmarshall Dec 5, 2025
8e0419d
Remove unused helpers
thomasmarshall Dec 5, 2025
a7955da
patternTranslate returns ast::ExpressionPtr
jesse-shopify Dec 5, 2025
a7c3a28
remove nodeVecToStore
jesse-shopify Dec 5, 2025
64c95f2
Delete now-unused overloads of `enforceHasExpr()`
amomchilov Dec 5, 2025
5015cca
Remove translate followed by enforceHasExpr with desugar / desugarNul…
jesse-shopify Dec 6, 2025
e8b1d80
Delete dead complemented integer edgecase
amomchilov Dec 10, 2025
7c4932f
remove enforceHasExpr from PM_CALL_NODE
jesse-shopify Dec 6, 2025
6b647e3
remove args NodeVec from PM_CALL_NODE and remaining enforceHasExpr uses
jesse-shopify Dec 8, 2025
64e4a5f
remove legacy parser dependencies in PM_CALL_NODE kwarg handling and …
jesse-shopify Dec 8, 2025
dfd9910
additional PM_CALL_NODE legacy parser code removal
jesse-shopify Dec 8, 2025
642ce7b
Desugar PM_KEYWORD_HASH_NODE
thomasmarshall Dec 8, 2025
d5ae5d0
Delete `takeDesugaredExprOrEmptyTree()`
amomchilov Dec 8, 2025
6aa8a0a
Inline last `enforceHasExpr()` helper
amomchilov Dec 8, 2025
0eb295e
Document unreachable cases
amomchilov Dec 8, 2025
b604fb4
Migrate `PM_CASE_MATCH_NODE`'s predicate
amomchilov Dec 8, 2025
a8dc744
Remove dead branch
amomchilov Dec 8, 2025
194920a
Move local vars closer to point of use
amomchilov Dec 8, 2025
b82e499
Remove all but 2 remaining `->takeDesugaredExpr()`
amomchilov Dec 8, 2025
d73f757
Remove unnecessary `translate()` call
amomchilov Dec 8, 2025
5d77a8b
Rename `valueNode` → `argument`
amomchilov Dec 8, 2025
04ebb18
squash! delete stale comment
amomchilov Dec 8, 2025
a9f9ff4
squash! delete stale comment
amomchilov Dec 8, 2025
a2e127b
Delete `parser::NodeWithExpr`
amomchilov Dec 8, 2025
7375525
Remove `expr_only()` calls
amomchilov Dec 8, 2025
66487e6
Delete `empty_expr()`
amomchilov Dec 8, 2025
bedcc39
Delete `expr_only()`
amomchilov Dec 8, 2025
9e79c39
Migrate `translate()` to `ast::ExpressionPtr`
amomchilov Dec 8, 2025
a917b4f
fixup! document unreachable
amomchilov Dec 8, 2025
9276123
silence unused var
amomchilov Dec 8, 2025
33b22e0
fake location
amomchilov Dec 8, 2025
74b3397
Fix empty else
thomasmarshall Dec 8, 2025
f88c3be
Direct dispatch to `desugarStatements()`
amomchilov Dec 8, 2025
ed5638d
Rename `translate()` → `desugar()`
amomchilov Dec 8, 2025
b0a443c
Rename `patternTranslate()` → `desugarPattern()`
amomchilov Dec 8, 2025
fa7c119
exclude additional test failures
jesse-shopify Dec 19, 2025
aaea70d
Set ast/desugar test to manual until SimplePrismDesugar test is fixed
jesse-shopify Dec 19, 2025
80f8589
fixup stale comment
amomchilov Dec 8, 2025
e4f28a9
Remove verify_prism_regression_tests.sh
thomasmarshall Dec 17, 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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
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 corpus tests
Expand Down
3 changes: 3 additions & 0 deletions ast/desugar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ cc_test(
"//tools/config:linkshared": 0,
"//conditions:default": 1,
}),
# TODO: SimplePrismDesugar test case uses legacy parser with Prism desugarer,
# which is incompatible. Excluded until the test is fixed to use Prism parser.
tags = ["manual"],
visibility = ["//tools:__pkg__"],
deps = [
"//ast/desugar",
Expand Down
2,232 changes: 19 additions & 2,213 deletions ast/desugar/PrismDesugar.cc

Large diffs are not rendered by default.

35 changes: 24 additions & 11 deletions main/pipeline/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ parser::ParseResult runPrismParser(core::GlobalState &gs, core::FileRef file, co
node = runPrismRBSRewrite(gs, file, node, prismResult.getCommentLocations(), print, ctx, parser);
}

bool directlyDesugar = !gs.cacheSensitiveOptions.rbsEnabled;
auto translatedTree = parser::Prism::Translator(parser, ctx, prismResult.getParseErrors(), directlyDesugar,
preserveConcreteSyntax)
.translate(node);
auto translatedTree =
parser::Prism::Translator(parser, ctx, prismResult.getParseErrors(), preserveConcreteSyntax)
.translate_TODO(node);

parseResult = parser::ParseResult{move(translatedTree), prismResult.getCommentLocations()};
}
Expand Down Expand Up @@ -338,16 +337,16 @@ unique_ptr<parser::Node> runRBSRewrite(core::GlobalState &gs, core::FileRef file
}

ast::ExpressionPtr runDesugar(core::GlobalState &gs, core::FileRef file, unique_ptr<parser::Node> parseTree,
const options::Printers &print, bool preserveConcreteSyntax = false) {
const options::Printers &print, bool preserveConcreteSyntax = false,
bool usePrismDesugar = false) {
ENFORCE(parseTree);

Timer timeit(gs.tracer(), "runDesugar", {{"file", string(file.data(gs).path())}});
ast::ExpressionPtr ast;
core::MutableContext ctx(gs, core::Symbols::root(), file);
{
core::UnfreezeNameTable nameTableAccess(gs); // creates temporaries during desugaring
// The RBS rewriter produces plain Whitequark nodes and not `NodeWithExpr` which causes errors in
// `PrismDesugar.cc`. For now, disable all direct translation, and fallback to `Desugar.cc`.
auto directlyDesugar = gs.parseWithPrism && !gs.cacheSensitiveOptions.rbsEnabled;
ast = directlyDesugar ? ast::prismDesugar::node2Tree(ctx, move(parseTree), preserveConcreteSyntax)
ast = usePrismDesugar ? ast::prismDesugar::node2Tree(ctx, move(parseTree), preserveConcreteSyntax)
: ast::desugar::node2Tree(ctx, move(parseTree), preserveConcreteSyntax);
}
if (print.DesugarTree.enabled) {
Expand Down Expand Up @@ -442,6 +441,8 @@ ast::ParsedFile indexOne(const options::Options &opts, core::GlobalState &lgs, c
return emptyParsedFile(file);
}

bool usePrismDesugar = false;

unique_ptr<parser::Node> parseTree;
switch (parser) {
case options::Parser::ORIGINAL: {
Expand All @@ -455,7 +456,18 @@ ast::ParsedFile indexOne(const options::Options &opts, core::GlobalState &lgs, c
break;
}
case options::Parser::PRISM: {
auto parseResult = runPrismParser(lgs, file, print, opts);
parser::ParseResult parseResult;
try {
parseResult = runPrismParser(lgs, file, print, opts);

// The RBS rewriter produces plain Whitequark nodes and not `NodeWithExpr` which causes errors
// in `PrismDesugar.cc`. For now, disable all direct translation, and fallback to `Desugar.cc`.
usePrismDesugar = !lgs.cacheSensitiveOptions.rbsEnabled;
categoryCounterInc("Prism parse kind", "direct");
} catch (parser::Prism::PrismFallback &) {
parseResult = runParser(lgs, file, print, opts.traceLexer, opts.traceParser);
categoryCounterInc("Prism parse kind", "fallback");
}

// parseResult is null if runPrismParser stopped after an intermediate phase
if (parseResult.tree == nullptr) {
Expand All @@ -470,7 +482,8 @@ ast::ParsedFile indexOne(const options::Options &opts, core::GlobalState &lgs, c
}
}

tree = runDesugar(lgs, file, move(parseTree), print);
tree = runDesugar(lgs, file, move(parseTree), print, false, usePrismDesugar);

if (opts.stopAfterPhase == options::Phase::DESUGARER) {
return emptyParsedFile(file);
}
Expand Down
79 changes: 0 additions & 79 deletions parser/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,85 +62,6 @@ template <class To> bool isa_node(Node *what) {
return cast_node<To>(what) != nullptr;
}

class NodeWithExpr final : public Node {
ast::ExpressionPtr desugaredExpr;

public:
const std::unique_ptr<Node> wrappedNode;

NodeWithExpr(std::unique_ptr<Node> wrappedNode, ast::ExpressionPtr desugaredExpr)
: Node(wrappedNode->loc), desugaredExpr(std::move(desugaredExpr)), wrappedNode(std::move(wrappedNode)) {
ENFORCE(this->wrappedNode != nullptr, "Can't create NodeWithExpr with a null wrappedNode");
ENFORCE(this->desugaredExpr != nullptr, "Can't create NodeWithExpr with a null desugaredExpr for node: {}",
wrappedNode->nodeName());
}
virtual ~NodeWithExpr() = default;

virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const final {
return wrappedNode->toStringWithTabs(gs, tabs);
}

virtual std::string toJSON(const core::GlobalState &gs, int tabs = 0) final {
return wrappedNode->toJSON(gs, tabs);
}

virtual std::string toJSONWithLocs(const core::GlobalState &gs, core::FileRef file, int tabs = 0) final {
return wrappedNode->toJSONWithLocs(gs, file, tabs);
}

virtual std::string toWhitequark(const core::GlobalState &gs, int tabs = 0) final {
return wrappedNode->toWhitequark(gs, tabs);
}

virtual std::string nodeName() const final {
return wrappedNode->nodeName();
}

virtual ast::ExpressionPtr takeDesugaredExpr() final {
ENFORCE(this->desugaredExpr != nullptr,
"Tried to call make a second call to `takeDesugaredExpr()` on a NodeWithExpr");

// We know each `NodeAndExpr` object's `takeDesugaredExpr()` will be called at most once, either:
// 1. When its parent node is being translated in `prism/Translator.cc`,
// and this value is used to create that parent's expr.
// 2. When this node is visted by `node2TreeImpl` in `PrismDesugar.cc`,
// and this value is called from the `NodeWithExpr` case
//
// Because of this, we don't need to make any copies here. Just move this value out,
// and hand exclusive ownership to the caller.
return std::move(this->desugaredExpr);
}

virtual bool hasDesugaredExpr() final {
return this->desugaredExpr != nullptr;
}

virtual const ast::ExpressionPtr &peekDesugaredExpr() const final {
return this->desugaredExpr;
}

// Like `parser::cast_node`, but can cast a `NodeWithExpr` *as if* it was its wrapped node.
template <class To> static To *cast_node(parser::Node *what) {
if (auto casted = parser::cast_node<To>(what)) {
categoryCounterInc("prism_cast_node", "correct");
return casted;
}

if (auto wrapper = parser::cast_node<parser::NodeWithExpr>(what)) {
categoryCounterInc("prism_cast_node", "delegated");
return parser::cast_node<To>(wrapper->wrappedNode.get());
} else {
categoryCounterInc("prism_cast_node", "miss");
return nullptr;
}
}

// Like `parser::isa_node`, but can check a `NodeWithExpr` *as if* it was its wrapped node.
template <class To> static bool isa_node(parser::Node *what) {
return NodeWithExpr::cast_node<To>(what) != nullptr;
}
};

using NodeVec = InlinedVector<std::unique_ptr<Node>, 4>;

inline NodeVec NodeVec1(std::unique_ptr<Node> node) {
Expand Down
7 changes: 3 additions & 4 deletions parser/prism/Parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ namespace sorbet::parser::Prism {

using namespace std::literals::string_view_literals;

parser::ParseResult Parser::run(core::MutableContext ctx, bool directlyDesugar, bool preserveConcreteSyntax) {
parser::ParseResult Parser::run(core::MutableContext ctx, bool preserveConcreteSyntax) {
auto file = ctx.file;
auto source = file.data(ctx).source();
Prism::Parser parser{source};
bool collectComments = ctx.state.cacheSensitiveOptions.rbsEnabled;
Prism::ParseResult parseResult = parser.parseWithoutTranslation(collectComments);

auto translatedTree =
Prism::Translator(parser, ctx, parseResult.parseErrors, directlyDesugar, preserveConcreteSyntax)
.translate(parseResult.getRawNodePointer());
auto translatedTree = Prism::Translator(parser, ctx, parseResult.parseErrors, preserveConcreteSyntax)
.translate_TODO(parseResult.getRawNodePointer());
return parser::ParseResult{move(translatedTree), move(parseResult.commentLocations)};
}

Expand Down
5 changes: 3 additions & 2 deletions parser/prism/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class Parser final {
Parser(Parser &&) = delete;
Parser &operator=(Parser &&) = delete;

static parser::ParseResult run(core::MutableContext ctx, bool directlyDesugar = true,
bool preserveConcreteSyntax = false);
static parser::ParseResult run(core::MutableContext ctx, bool preserveConcreteSyntax = false);

ParseResult parseWithoutTranslation(bool collectComments = false);
core::LocOffsets translateLocation(pm_location_t location) const;
Expand Down Expand Up @@ -136,5 +135,7 @@ class ParseResult final {
}
};

struct PrismFallback {};

} // namespace sorbet::parser::Prism
#endif // SORBET_PARSER_PRISM_PARSER_H
Loading
Loading