Project

General

Profile

Actions

Bug #20044

closed

Add runtime flag and environment variable for prism

Added by HParker (Adam Hess) 12 months ago. Updated 11 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:115598]

Description

To enable prism to be used as the parser when running Ruby code, I would like to add a runtime flag and environment variable that allow it to be enabled.

The flags could be,

ruby --prism test.rb

and the environment variable could be,

RUBY_PRISM=1 ruby test.rb

Previously implemented here: https://github.com/ruby/ruby/pull/9115, but merged before discussion could happen.

Things to be sure to discuss mentioned by @mame (Yusuke Endoh),

  • What to do with the command-line option when prism becomes the default parser in the future.
    ** Just remove it, or leave it as a "do nothing" option?
  • What are the appropriate names.
    ** In Ruby, not absolutely but the names of features for professional use tend to be long and verbose, while those used by ordinary users tend to be short.
  • Whether to print a warning when this mode is used.

Updated by HParker (Adam Hess) 12 months ago

I am happy to adopt any direction the core team likes for this proposal, but to attempt answers to @mame's questions, I would suggest,

What to do with the command-line option when prism becomes the default parser in the future.

I believe we can safely begin ignoring the environment variable when prism becomes the default parser without any work (just deleting code). I think deprecating the runtime flag version with a message is reasonable one release after it becomes the default, but I don't have a strong opinion here and I defer to whatever Ruby has typically done in the past.

What are the appropriate names.

I was unaware of this naming convention and I believe in the first release including prism as an option, this should be targeted towards people who are sure this is what they want. My intention with this change is to allow those interested in testing prism to begin doing that. I would like to integrate it into CI and begin testing Ruby HEAD with it enabled when that becomes possible.

Whether to print a warning when this mode is used.

I am conflicted on this. RubyVM::InstructionSequence.compile_prism does not outputs a warning. I suspect using Prism as your default parser is more experimental than using prism via this API, but I am not sure how much more experimental. I suspect if we plan to remove the flag, at least using the flag should warn, but I don't have strong feelings about this either.

Updated by Eregon (Benoit Daloze) 12 months ago

I think a warning would cause some incompatibility and is not necessary, instead the flag & env var can be documented as experimental.

Updated by eightbitraptor (Matt V-H) 12 months ago

What are the appropriate names.

Given the precedent set by mjit and yjit of having short names that mirror the actual project names my preferred approach is having --prism but labelling it as (experimental)

cf.

  --jit           enable JIT for the platform, same as --yjit
  --mjit          enable C compiler-based JIT compiler (experimental)
  --yjit          enable in-process JIT compiler

Updated by kddnewton (Kevin Newton) 12 months ago

I agree with marking it as experimental. This would only be for testing purposes (or maybe for an IDE for getting more enhanced error messages). That way (hopefully) there would not be an issue with removing it.

Updated by mame (Yusuke Endoh) 12 months ago

Discussed at today's dev meeting. @matz (Yukihiro Matsumoto) said:

  • Introduce a command-line option --parser=prism and --parser=parse.y
    • If parse.y is removed in the future, --parser=parse.y should report an error
  • Do NOT introduce environment variable
    • Use RUBYOPT=--parser=prism instead
  • No warning should be printed
  • Add +prism (or +PRISM or something) to RUBY_DESCRIPTION, like YJIT
    • This should be removed in the future if prism is the default parser
$ ruby --jit --parser=prism -v
ruby 3.3.0dev (2023-12-07T02:37:08Z master 214f6d6598) +YJIT +prism [x86_64-linux]
Actions #6

Updated by HParker (Adam Hess) 11 months ago

  • Status changed from Open to Closed

Applied in changeset git|55326a915f25608be1d40ab32baa9fc57762615d.


Introduce --parser runtime flag

Introduce runtime flag for specifying the parser,

ruby --parser=prism

also update the description:

$ ruby --parser=prism --version
ruby 3.3.0dev (2023-12-08T04:47:14Z add-parser-runtime.. 0616384c9f) +PRISM [x86_64-darwin23]

[Bug #20044]

Updated by mame (Yusuke Endoh) 11 months ago

I noticed that the patch outputs a warning.

$ ./local/bin/ruby --parser=prism -e ''
./local/bin/ruby: warning: The compiler based on the Prism parser is currently experimental and compatibility with the compiler based on parse.y is not yet complete. Please report any issues you find on the `ruby/prism` issue tracker.

@matz (Yukihiro Matsumoto) said that it would be better not to output the warning. However, he also said that if you (the Prism developers) wanted to print it out, he would not stop the warning. FYI.

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0