Skip to content
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

WIP: Prism work, rebase with squashed commits #404

Draft
wants to merge 117 commits into
base: master
Choose a base branch
from
Draft

Conversation

egiurleo
Copy link

This is a test for upstreaming our Prism work. In this PR, I've rebased on Prism master and squashed many of our commits (398 commits --> 117)

Motivation

Test plan

See included automated tests.

egiurleo and others added 30 commits January 14, 2025 17:00
And move all other Prism related code to the new parser/prism component
Co-Authored-By: Alex Momchilov <[email protected]>
Co-Authored-By: Emily Samp <[email protected]>
To make sure our translation layer correctly translates node locations, we create a task that, for every Prism regression test, runs the test with location comparison on.
Co-Authored-By: Alexander Momchilov <[email protected]>
Up to this point, in order to build Prism, we've needed to manually pass the path to the correct RUBY version to the build process because Bazel does not take the user's environment into account and will just use the system's default Ruby version (which is often very old).

This is a workaround for our workaround, where we use a Bazel `repository_rule` to get the `RUBY_ROOT` environment variable, write it to a file within the Bazel file system, and then pull the value from that file while building Prism.
This debug config launches the main Sorbet executable to type check
the provided file path (with Prism).
In our `downcast` helper, we check that the node argument is actually
a Prism node. However, doing this requires us to check the `type` field,
which will fail if the node is a `nullptr`. By doing a `nullptr`
check in the `ENFORCE`, we guarantee we won't crash by checking for
a field on a `nullptr`.

Co-authored-by: Alex Momchilov <[email protected]>
By not replacing `/` with `_`, the test naming structure is more consistent
with normal regression tests. But more importantly, it allows us to run
location tests that are under a folder like `error_recovery/assign`, more
easily.
The error location doesn't match what Sorbet currently generates. But the
idea is to first make parse trees match, accumulate more recovery tests,
and then come up with a strategy to generate errors that match locations.
It turns out that we only need `sourceMap`'s value to be set to the
workspace folder with any arbitrary key. So not setting `BAZEL_EXEC_ROOT`
is fine.
egiurleo and others added 30 commits January 14, 2025 17:12
1. It fixes the case where a hash pattern doesn't have a value, which will
   generate a `PM_IMPLICIT_NODE` that we currently don't handle.
2. It fixes the translation of hash patterns with a named splat node, like
   `in **o`.
The logic of `translateHash` was kind of confusing because it was handling
both vanilla hashes and also assocs/assoc splat nodes. By isolating one
part of that method, which generates key/value pairs, and then calling
that method in both cases, the two code paths become cleaner and more
obvious.
When the method call is `[]`, the message location should be just the begin
location of `[]`.
And exclude failing tests
In cases like `foo.()`, the message would be `:call`, but the message location
would have null start and end. In this case, we need to fall back to use
the call operator location.
This is not covered in parse tree location tests, but reflected in symbol
table tests: when we write `FOO = 1` (or other constant write nodes), the
location of `FOO` should just be the name, not the entire assignment.

In those cases, we should use `name_loc` instead of `base.location`.
When the symbol is used as `a: 1`, the location should not include the colon.
The main blocker for upstreaming Prism parser to Sorbet is that we currently
rely on Ruby to build Prism, as its required by Prism's `rake template` task.

But by package the files generated by `rake template` in Prim's release,
we will be able to remove the dependency on Ruby while significantly simplify
the build configurations for Prism.
When ENFORCE macros fail, they use fmt (via spdlog) to format error messages.
Add a formatter specialization for pm_node_type to properly display Prism node
types in these error messages. Instead of showing numeric values, the formatter
uses pm_node_type_to_str to display human-readable node type names.
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.

3 participants