Skip to content

[DO NOT MERGE] ko/rbs-over-prism rebased#851

Open
KaanOzkan wants to merge 3 commits into
masterfrom
ko/rbs-over-prism-rebased
Open

[DO NOT MERGE] ko/rbs-over-prism rebased#851
KaanOzkan wants to merge 3 commits into
masterfrom
ko/rbs-over-prism-rebased

Conversation

@KaanOzkan
Copy link
Copy Markdown

@KaanOzkan KaanOzkan commented Mar 9, 2026

@KaanOzkan KaanOzkan changed the title Ko/rbs over prism rebased [DO NOT MERGE] ko/rbs-over-prism rebased Mar 9, 2026
Comment thread common/common.h Outdated
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/container/inlined_vector.h"
#include "absl/types/span.h"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be controversial, idk. It's pretty commonly used like everywhere, so it makes sense, but checkin with Stripe first

Comment thread main/pipeline/pipeline.h Outdated
Comment thread parser/prism/Translator.cc Outdated
Comment thread parser/prism/Translator.cc Outdated
// Optimization: resolve well-known constant paths eagerly instead of leaving them unresolved.
// This is important for the RBS rewriter which generates references to these constants.
{
absl::InlinedVector<core::NameRef, 4> fullPath;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would benefit from a comment:

Suggested change
absl::InlinedVector<core::NameRef, 4> fullPath;
// Max size of 4, to fit the longest path we're searching for (`Sorbet::Private::Static::Void`)
absl::InlinedVector<core::NameRef, 4> fullPath;

Comment thread parser/prism/Translator.cc Outdated
bool isRootAnchored = false;
pm_node_t *current = up_cast(const_cast<PrismLhsNode *>(node));

while (current != nullptr) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up, can we tighten this up a bit?

  1. Cap the iterations to 4. Any more than that, and we start heap-allocating elements of a path that we know for sure won't be matched below
  2. Bail early if the name at each iteration doesn't match one of the patterns we're looking for. Since the PM_CONSTANT_PATH_NODE is backwards:
    1. On the first iteration, we're looking for Static, Void, or WithoutRuntime
    2. On the second iteration we're looking for Private, Sig, or Static,
    3. etc.

Comment thread rbs/prism/CommentsAssociatorPrism.cc Outdated
Comment thread test/testdata/rbs/assertions_bind.rb
KaanOzkan added a commit that referenced this pull request Mar 11, 2026
- Remove unused `#include "absl/types/span.h"` from common.h
- Remove unused Prism includes from pipeline.h
- Fix `e.g.,` → `e.g.` style nit in Translator.cc comment
- Optimize translateConst well-known path matching: use resolveConstant
  (string_view) instead of enterNameUTF8, cap walk at 4 iterations
- Use prism.emptyNodeList() instead of {0, 0, NULL} in CommentsAssociatorPrism
Comment thread test/testdata/rbs/assertions_bind.rb Outdated
Comment thread test/testdata/rbs/assertions_bind.rb Outdated
Comment thread ast/desugar/prism/Desugar.cc Outdated
pm_node_t *current = up_cast(const_cast<PrismLhsNode *>(node));
bool isRootAnchored = false;
// Segments collected innermost-first. Fixed-size array caps at 4 (longest target path).
std::string_view segments[4];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the switch away from InlineVector?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need a fixed size array and I think it should be faster than an inline vector. I can change it back.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh you end up needing to implement your own "append" behaviour instead of push_back(). InlineVector should be equally efficient as long as you don't spill over its inline size

Comment thread rbs/prism/CommentsAssociatorPrism.cc
Comment thread rbs/prism/CommentsAssociatorPrism.h Outdated
Comment thread main/options/options.cc Outdated
Comment thread rbs/CommentsAssociator.cc
[&](parser::AndAsgn *andAsgn) {
associateAssertionCommentsToNode(andAsgn->right.get(), true);
walkNode(andAsgn->right.get());
walkNode(andAsgn->left.get());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in test/testdata/rbs/assertions_send_assign.rb

Comment thread test/testdata/rbs/assertions_block_modified.rb Outdated
Comment thread test/BUILD
Comment on lines +273 to +278
# Specific tests that are modified for Prism, contain minor differences in the exp file
"testdata/rbs/assertions_block_modified.rb",
"testdata/rbs/assertions_csend_assign_modified.rb",
"testdata/rbs/assertions_csend_modified.rb",
"testdata/rbs/assertions_heredoc_modified.rb",
"testdata/rbs/signatures_types_modified.rb",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you re-confirm these still fail, and explain which kind of differences are causing the issues?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as a comment on each file. I opted to add it to the test files because I didn't want to pollute the more general test/BUILD with details.

@KaanOzkan KaanOzkan force-pushed the ko/rbs-over-prism-rebased branch from e120ef5 to 51be6b9 Compare March 12, 2026 18:41
Comment thread main/options/options.cc
Comment thread test/pipeline_test_runner.cc
@KaanOzkan KaanOzkan force-pushed the ko/rbs-over-prism-rebased branch 3 times, most recently from 61f9415 to daa0bc5 Compare March 12, 2026 19:35
Comment thread test/pipeline_test_runner.cc Outdated
auto prismDirectDesugarAST = ast::prismDesugar::node2Tree(ctx, move(translatedTree));

if (!disableParserComparison) {
if (!disableParserComparison && !usePrismRBS) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we want to run the comparison if RBS is on?

If the two desugar trees were equal before (without RBS rewriting for the Prism one), they should still be equal now, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was always skipped. I just tried turning it on, had to trigger RBS rewriting for the legacy case. But looking at the trees they are different after an RBS rewrite:

 def foo
    #: self as Foo
    T.reveal_type(self)
  end

Legacy: InsSeq{ loc = 3:3-3:22 } starts at first real statement
Prism: InsSeq{ loc = 2:14-3:22 } starts at synthetic T.bind from RBS comment

Should I investigate prismDesugarEqual and see if we can support this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh, these locations would be pretty different all over the place.

I guess this is already tested with the RBS expectation files, so there's no need to compare the desugar trees.

I think a better way to express this is to roll it into the definition on disableParserComparison, rather than a new usePrismRBS variable (whose value is actually more past tense, like didUsePrismRBS, because by the time we check it, we've already rewritten the RBS)

Can you hoist the declaration of disableParserComparison up to where bool usePrismRBS = false; is, and set it to false where usePrismRBS is set to true?

@amomchilov amomchilov force-pushed the ko/rbs-over-prism-rebased branch from daa0bc5 to 7e6fc73 Compare March 13, 2026 01:25
@amomchilov
Copy link
Copy Markdown

This stack of pull requests is managed by Graphite. Learn more about stacking.

@KaanOzkan KaanOzkan force-pushed the ko/rbs-over-prism-rebased branch from 7e6fc73 to c084553 Compare March 13, 2026 13:48
@amomchilov amomchilov force-pushed the ko/rbs-over-prism-rebased branch 3 times, most recently from c084553 to 33c4ad5 Compare March 13, 2026 14:44
@KaanOzkan KaanOzkan force-pushed the ko/rbs-over-prism-rebased branch 3 times, most recently from 5258486 to e91aa5a Compare March 13, 2026 16:58
- Fix start > end invariant violation in desugarStatements when RBS
  rewriter inserts synthetic nodes with earlier locations. Falls back
  to the statements node's own location.
- Eagerly resolve well-known root-anchored constant paths
  (::Sorbet::Private::Static, ::T::Sig::WithoutRuntime, etc.) that
  the RBS rewriter generates, avoiding unresolved constant paths.
  Gated on rbsEnabled so it only fires for RBS-rewritten ASTs.
- Add ENFORCE check in resolveConstant() for PM_CONSTANT_ID_UNSET.
- Walk LHS of AndAsgn, OpAsgn, OrAsgn in CommentsAssociator so RBS
  comments on the left-hand side are not missed.
- Add typeAliasAllowedInContext() helper in CommentsAssociatorPrism.
- Fix type alias handling in empty class/module bodies and improve
  error messages when type aliases appear in disallowed contexts.
- Remove RBS_REWRITER stop-after-phase (subsumed by desugarer phase).
- 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 new RBS test data: csend_assign_modified, csend_modified,
  block_modified, signatures_types_modified, and others.
- Update cli-ref.md to remove 'rbs' from stop-after phases.
@KaanOzkan KaanOzkan force-pushed the ko/rbs-over-prism-rebased branch from e91aa5a to f123bbe Compare March 13, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants