Project

General

Profile

Actions

Feature #20564

open

Switch default parser to Prism

Added by kddnewton (Kevin Newton) 6 months ago. Updated 2 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:118243]

Description

This issue is to propose switching the default parser for Ruby to Prism on the master branch. The main goal is to get this default into both master and the next preview so that the community has plenty of time to test before the eventual 3.4 release.

Matz has indicated that the final decision about the default parser for Ruby 3.4 will be made later in the year. Decisions about the default parser for Ruby 3.5+ and the relationship between Prism, lrama, parse.y, etc. will also be made at a later time.

Background

For some background on the Prism project itself, here are a couple of links in chronological order that you can read:

Status

Prism now passes all Ruby tests and specs. Internally at Shopify, it also passes our Core monolith's CI, which is a large and complex Rails application. We are confident that it is ready for production use. External to CRuby, Prism has already been adopted extensively around the ecosystem, including but not limited to:

Fortunately with the community adoption, we have been able to find many edge cases and bugs that have been fixed. Thank you so much to everyone who has tried, used, reported problems with, and improved Prism in the last couple of years. We would not have hit this milestone without this community involvement.

Caveats

While Prism correctly accepts and parses all valid Ruby syntax, there are still a number of cases where it does not reject invalid syntax as it should. We are currently working on these cases, and we are confident that we can eliminate them before the next preview release. You can find them listed here: https://github.com/ruby/prism/issues?q=is%3Aopen+is%3Aissue+label%3Ainvalid-syntax. This is our top priority right now, and I anticipate these being resolved quickly.

The other caveat is unknown unknowns: bugs or syntax issues that we have yet to discover. At Shopify we are currently taking numerous steps to mitigate this risk, including:

  • Prism currently passes all Ruby tests and specs, and will continue to going forward. The tests and specs are extensive, and we are confident this gets us almost all of the way there.
  • Grammar-based fuzzing to ensure we handle all possible syntax variations (both valid and invalid). As an example, that recently led to the discovery that the current compiler was segfaulting on safe navigation in for loops (https://bugs.ruby-lang.org/issues/20468). It has also found several memory leaks that have been fixed.
  • Mutation testing of existing source files (by adding and deleting random bytes) to find additional edge cases.

Our goal is 100% compatibility, and we believe this is achievable through the above techniques and others. The goal of this proposal is to allow more companies to test their codebase against Prism, and to make this easier. We believe that we can sort out the remaining problems much more quickly in that manner.

Implementation

The implementation will be relatively straightforward, as there is already the --parser flag that can be used to switch between the current parser and Prism. We will change the default to be "prism" instead of "parse.y". There is no plan to remove or change any code related to parse.y, lrama, or compile.c at this time, as we want to create the minimal amount of change possible to ensure stability.

Actions

Also available in: Atom PDF

Like3
Like0Like0Like1Like2Like0Like0Like0