Skip to content

Commit 24fce3b

Browse files
committed
Wire up RBS-over-Prism in pipeline and test runner
- Update pipeline_test_runner to run Prism+RBS desugaring path: parse with Prism, run RBS rewrite on the Prism AST, then desugar. Skip legacy parser comparison when using Prism RBS path. - Unexclude RBS tests from PrismPosTests (most now pass with Prism). - Add Prism-specific _modified test variants for csend_assign, csend, and signatures_types.
1 parent 0a04427 commit 24fce3b

8 files changed

+1373
-52
lines changed

test/BUILD

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ pipeline_tests(
271271
"testdata/**/*.exp",
272272
],
273273
exclude = [
274-
# Specific test that is modified for Prism, contains minor differences in the exp file
274+
# Specific tests that are modified for Prism, contain minor differences in the exp file
275+
"testdata/rbs/assertions_csend_assign_modified.rb",
276+
"testdata/rbs/assertions_csend_modified.rb",
275277
"testdata/rbs/assertions_heredoc_modified.rb",
278+
"testdata/rbs/signatures_types_modified.rb",
276279
],
277280
),
278281
"PosTests",
@@ -517,56 +520,12 @@ pipeline_tests(
517520
"testdata/parser/error_recovery/csend_masgn.rb",
518521
"testdata/parser/misc.rb",
519522

520-
# Fixing a bug in pipeline_test_runner.cc revealed that these tests
521-
# were not actually running because they have RBS support enabled
522-
"testdata/lsp/hover_rbs.rb",
523-
"testdata/lsp/hover_rbs_assertions_let.rb",
524-
"testdata/rbs/annotations_helpers.rb",
525-
"testdata/rbs/assertions_absurd.rb",
526-
"testdata/rbs/assertions_and_assign.rb",
527-
"testdata/rbs/assertions_and_or.rb",
528-
"testdata/rbs/assertions_array.rb",
529-
"testdata/rbs/assertions_assign.rb",
530-
"testdata/rbs/assertions_bind.rb",
531-
"testdata/rbs/assertions_block.rb",
532-
"testdata/rbs/assertions_break.rb",
533-
"testdata/rbs/assertions_case.rb",
534-
"testdata/rbs/assertions_case_pattern.rb",
535-
"testdata/rbs/assertions_class.rb",
523+
# RBS tests whose rewrite-tree.exp files have legacy-parser-specific
524+
# output (temp variable ordering, constant resolution, heredoc handling).
525+
# Prism-specific _modified variants exist for each of these.
536526
"testdata/rbs/assertions_csend.rb",
537527
"testdata/rbs/assertions_csend_assign.rb",
538-
"testdata/rbs/assertions_def.rb",
539-
"testdata/rbs/assertions_defs.rb",
540-
"testdata/rbs/assertions_ensure.rb",
541-
"testdata/rbs/assertions_errors.rb",
542-
"testdata/rbs/assertions_for.rb",
543-
"testdata/rbs/assertions_hash.rb",
544528
"testdata/rbs/assertions_heredoc.rb",
545-
"testdata/rbs/assertions_heredoc_modified.rb",
546-
"testdata/rbs/assertions_if.rb",
547-
"testdata/rbs/assertions_kwbegin.rb",
548-
"testdata/rbs/assertions_massign.rb",
549-
"testdata/rbs/assertions_module.rb",
550-
"testdata/rbs/assertions_next.rb",
551-
"testdata/rbs/assertions_op_assign.rb",
552-
"testdata/rbs/assertions_or_assign.rb",
553-
"testdata/rbs/assertions_rescue.rb",
554-
"testdata/rbs/assertions_sclass.rb",
555-
"testdata/rbs/assertions_send.rb",
556-
"testdata/rbs/assertions_send_assign.rb",
557-
"testdata/rbs/assertions_super.rb",
558-
"testdata/rbs/assertions_type_params.rb",
559-
"testdata/rbs/assertions_unless.rb",
560-
"testdata/rbs/assertions_until.rb",
561-
"testdata/rbs/assertions_while.rb",
562-
"testdata/rbs/empty_if_else_module.rb",
563-
"testdata/rbs/signatures_attrs.rb",
564-
"testdata/rbs/signatures_attrs_multiline.rb",
565-
"testdata/rbs/signatures_blocks.rb",
566-
"testdata/rbs/signatures_defs.rb",
567-
"testdata/rbs/signatures_defs_multiline.rb",
568-
"testdata/rbs/signatures_generics.rb",
569-
"testdata/rbs/signatures_type_aliases.rb",
570529
"testdata/rbs/signatures_types.rb",
571530
],
572531
),

test/pipeline_test_runner.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ vector<ast::ParsedFile> index(core::GlobalState &gs, absl::Span<core::FileRef> f
246246
// Parser
247247
parser::ParseResult legacyParseResult;
248248
std::optional<parser::Prism::ParseResult> prismParseResult;
249+
bool disableParserComparison = false;
249250
{
250251
core::UnfreezeNameTable nameTableAccess(gs); // enters original strings
251252
core::MutableContext ctx(gs, core::Symbols::root(), file);
@@ -280,11 +281,17 @@ vector<ast::ParsedFile> index(core::GlobalState &gs, absl::Span<core::FileRef> f
280281
break;
281282
}
282283
case realmain::options::Parser::PRISM: {
284+
prismParseResult.emplace(parser::Prism::Parser::run(ctx));
285+
283286
if (gs.cacheSensitiveOptions.rbsEnabled) {
284-
continue;
285-
}
287+
auto &prismParser = prismParseResult->getParser();
288+
auto node = rbs::runPrismRBSRewrite(gs, file, prismParseResult->getRawNodePointer(),
289+
prismParseResult->getCommentLocations(), ctx, prismParser);
290+
prismParseResult->replaceRootNode(node);
291+
disableParserComparison = true;
286292

287-
prismParseResult.emplace(parser::Prism::Parser::run(ctx));
293+
handler.addObserved(gs, "rbs-rewrite-tree", [&]() { return prismParseResult->prettyPrint(); });
294+
}
288295

289296
break;
290297
}
@@ -297,7 +304,7 @@ vector<ast::ParsedFile> index(core::GlobalState &gs, absl::Span<core::FileRef> f
297304
core::MutableContext ctx(gs, core::Symbols::root(), file);
298305
core::UnfreezeNameTable nameTableAccess(ctx); // enters original strings
299306

300-
auto disableParserComparison =
307+
disableParserComparison = disableParserComparison ||
301308
BooleanPropertyAssertion::getValue("disable-parser-comparison", assertions).value_or(false);
302309

303310
if (prismParseResult.has_value()) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# typed: strict
2+
# enable-experimental-rbs-comments: true
3+
# Modified for Prism: csend desugaring assigns inner/outer temp variables in
4+
# opposite order ($3/$4, $5/$6 swapped), producing semantically equivalent but
5+
# textually different rewrite-tree output.
6+
7+
# let
8+
9+
class Let
10+
#: (*untyped) -> void
11+
def foo=(*args); end
12+
13+
#: -> untyped
14+
def foo; end
15+
end
16+
17+
let1 = Let.new #: Let?
18+
let1&.foo = "foo" #: String
19+
20+
let2 = Let.new #: Let?
21+
let2&.foo&.foo = "foo" #: String
22+
23+
let3 = Let.new #: Let?
24+
let3&.foo&.foo = "foo", "bar" #: Array[String]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
class <emptyTree><<C <root>>> < (::<todo sym>)
2+
class <emptyTree>::<C Let><<C <todo sym>>> < (::<todo sym>)
3+
::T::Sig::WithoutRuntime.sig() do ||
4+
<self>.params(:args, ::<root>::<C T>.untyped()).void()
5+
end
6+
7+
def foo=<<todo method>>(*args, &<blk>)
8+
<emptyTree>
9+
end
10+
11+
::T::Sig::WithoutRuntime.sig() do ||
12+
<self>.returns(::<root>::<C T>.untyped())
13+
end
14+
15+
def foo<<todo method>>(&<blk>)
16+
<emptyTree>
17+
end
18+
19+
<runtime method definition of foo=>
20+
21+
<runtime method definition of foo>
22+
end
23+
24+
let1 = <cast:let>(<emptyTree>::<C Let>.new(), <todo sym>, ::<root>::<C T>.nilable(<emptyTree>::<C Let>))
25+
26+
begin
27+
<assignTemp>$2 = let1
28+
if ::NilClass.===(<assignTemp>$2)
29+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$2)
30+
else
31+
<assignTemp>$2.foo=(<cast:let>("foo", <todo sym>, <emptyTree>::<C String>))
32+
end
33+
end
34+
35+
let2 = <cast:let>(<emptyTree>::<C Let>.new(), <todo sym>, ::<root>::<C T>.nilable(<emptyTree>::<C Let>))
36+
37+
begin
38+
<assignTemp>$4 = begin
39+
<assignTemp>$3 = let2
40+
if ::NilClass.===(<assignTemp>$3)
41+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$3)
42+
else
43+
<assignTemp>$3.foo()
44+
end
45+
end
46+
if ::NilClass.===(<assignTemp>$4)
47+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$4)
48+
else
49+
<assignTemp>$4.foo=(<cast:let>("foo", <todo sym>, <emptyTree>::<C String>))
50+
end
51+
end
52+
53+
let3 = <cast:let>(<emptyTree>::<C Let>.new(), <todo sym>, ::<root>::<C T>.nilable(<emptyTree>::<C Let>))
54+
55+
begin
56+
<assignTemp>$6 = begin
57+
<assignTemp>$5 = let3
58+
if ::NilClass.===(<assignTemp>$5)
59+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$5)
60+
else
61+
<assignTemp>$5.foo()
62+
end
63+
end
64+
if ::NilClass.===(<assignTemp>$6)
65+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$6)
66+
else
67+
<assignTemp>$6.foo=(<cast:let>(["foo", "bar"], <todo sym>, ::<root>::<C T>::<C Array>.<syntheticSquareBrackets>(<emptyTree>::<C String>)))
68+
end
69+
end
70+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# typed: strict
2+
# enable-experimental-rbs-comments: true
3+
# Modified for Prism: csend desugaring assigns inner/outer temp variables in
4+
# opposite order ($10/$11 swapped), producing semantically equivalent but
5+
# textually different rewrite-tree output.
6+
7+
this = self #: as untyped
8+
9+
this&.puts #: as String
10+
11+
this&.ARGV.first #: as String
12+
13+
begin
14+
ARGV #: as Integer?
15+
end&.first # error: Method `first` does not exist on `Integer`
16+
17+
this&.puts begin
18+
ARGV.first #: as String
19+
end #: as String
20+
21+
this&.puts(
22+
42 #: as String
23+
)
24+
25+
this&.puts(
26+
42, #: as String
27+
42 #: as String
28+
)
29+
30+
this&.
31+
puts #: as Integer
32+
33+
this&. #: as Integer?
34+
first #: as Integer
35+
# ^^^^^ error: Method `first` does not exist on `Integer`
36+
37+
ARGV #: as Integer?
38+
&.first #: as String? # error: Method `first` does not exist on `Integer`
39+
&.last # error: Method `last` does not exist on `String`
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
class <emptyTree><<C <root>>> < (::<todo sym>)
2+
this = ::<root>::<C T>.unsafe(<self>)
3+
4+
<cast:cast>(begin
5+
<assignTemp>$2 = this
6+
if ::NilClass.===(<assignTemp>$2)
7+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$2)
8+
else
9+
<assignTemp>$2.puts()
10+
end
11+
end, <todo sym>, <emptyTree>::<C String>)
12+
13+
<cast:cast>(begin
14+
<assignTemp>$3 = this
15+
if ::NilClass.===(<assignTemp>$3)
16+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$3)
17+
else
18+
<assignTemp>$3.ARGV()
19+
end
20+
end.first(), <todo sym>, <emptyTree>::<C String>)
21+
22+
begin
23+
<assignTemp>$4 = <cast:cast>(<emptyTree>::<C ARGV>, <todo sym>, ::<root>::<C T>.nilable(<emptyTree>::<C Integer>))
24+
if ::NilClass.===(<assignTemp>$4)
25+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$4)
26+
else
27+
<assignTemp>$4.first()
28+
end
29+
end
30+
31+
<cast:cast>(begin
32+
<assignTemp>$5 = this
33+
if ::NilClass.===(<assignTemp>$5)
34+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$5)
35+
else
36+
<assignTemp>$5.puts(<cast:cast>(<emptyTree>::<C ARGV>.first(), <todo sym>, <emptyTree>::<C String>))
37+
end
38+
end, <todo sym>, <emptyTree>::<C String>)
39+
40+
begin
41+
<assignTemp>$6 = this
42+
if ::NilClass.===(<assignTemp>$6)
43+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$6)
44+
else
45+
<assignTemp>$6.puts(<cast:cast>(42, <todo sym>, <emptyTree>::<C String>))
46+
end
47+
end
48+
49+
begin
50+
<assignTemp>$7 = this
51+
if ::NilClass.===(<assignTemp>$7)
52+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$7)
53+
else
54+
<assignTemp>$7.puts(<cast:cast>(42, <todo sym>, <emptyTree>::<C String>), <cast:cast>(42, <todo sym>, <emptyTree>::<C String>))
55+
end
56+
end
57+
58+
<cast:cast>(begin
59+
<assignTemp>$8 = this
60+
if ::NilClass.===(<assignTemp>$8)
61+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$8)
62+
else
63+
<assignTemp>$8.puts()
64+
end
65+
end, <todo sym>, <emptyTree>::<C Integer>)
66+
67+
<cast:cast>(begin
68+
<assignTemp>$9 = <cast:cast>(this, <todo sym>, ::<root>::<C T>.nilable(<emptyTree>::<C Integer>))
69+
if ::NilClass.===(<assignTemp>$9)
70+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$9)
71+
else
72+
<assignTemp>$9.first()
73+
end
74+
end, <todo sym>, <emptyTree>::<C Integer>)
75+
76+
begin
77+
<assignTemp>$11 = <cast:cast>(begin
78+
<assignTemp>$10 = <cast:cast>(<emptyTree>::<C ARGV>, <todo sym>, ::<root>::<C T>.nilable(<emptyTree>::<C Integer>))
79+
if ::NilClass.===(<assignTemp>$10)
80+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$10)
81+
else
82+
<assignTemp>$10.first()
83+
end
84+
end, <todo sym>, ::<root>::<C T>.nilable(<emptyTree>::<C String>))
85+
if ::NilClass.===(<assignTemp>$11)
86+
::<Magic>.<nil-for-safe-navigation>(<assignTemp>$11)
87+
else
88+
<assignTemp>$11.last()
89+
end
90+
end
91+
end

0 commit comments

Comments
 (0)