oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.02k stars 185 forks source link

Ruby 2.7 support #2004

Closed deepj closed 3 years ago

deepj commented 4 years ago

Is there any plan to add new Ruby 2.7 goodies in near future? In my list are these:

  1. REPL improvements (the colors and syntax highlighting in IRB!!!)
  2. pattern matching (+ possible some performance optimization behind MRI implementation)
  3. Enumerator.produce
eregon commented 4 years ago

As written in https://github.com/oracle/truffleruby/blob/master/doc/contributor/workflow.md#running-specs-for-ruby-27-features

we welcome pull requests for Ruby 2.7 features as long as they don't conflict significantly with Ruby 2.6 semantics.

So adding 2.7 features as long as they don't conflict significantly with Ruby 2.6 semantics is fine.

Regarding 1, I guess it's mostly changes the irb gem. So the work there seems mostly to support the latest irb gem. Trying gem install irb; irb shows we need Ripper.lex (#1747, #1585)

Regarding 2, it seems quite some work and it's unclear if much code uses it yet. Also it's experimental in 2.7:

$ ruby -ve 'case [3]; in [e]; p e; end'
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
-e:1: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
3

So PRs for that are definitely welcome, but I guess it's not used in many gems yet, and so not so important for compatibility in general (yet).

Regarding 3, that's probably easy to implement in pure Ruby.

For each of these it would be helpful to have a separate issue so we can prioritize and triage it as needed.


Finally, regarding general plans for 2.7 at the moment I'm hesitant because of keyword arguments changes. Ruby 2.7 has broken *args-delegation and *args, **kwargs-delegation is not working in 2.7 (so the only thing that works is ruby2_keywords, details). As a result, it's hard to migrate and fix warnings in Ruby 2.7. So I'm not sure if much production apps will ever run on 2.7, it's unclear to me if they would rather wait for 2.8/3.0 which fixes *args, **kwargs-delegation and has much clearer semantics for keyword arguments in general.

Implementing the keyword arguments semantics of 2.7 seem a lot of work (at least to support the warnings), for semantics that only last for one Ruby version (semantics are significantly simpler in Ruby 2.8+). So we might want to skip the 2.7 "transition release" and go straight to Ruby 2.8 in terms of reported RUBY_VERSION. I've not made my mind yet though and I'mhappy to hear opinions on this (e.g., significant adoption of 2.7 would change things).

Individual features from 2.7 that are compatible are all welcome though. I guess it doesn't make sense to report as RUBY_VERSION 2.7 if the keyword arguments changes are not implemented though.

eregon commented 4 years ago

We're now planning to target Ruby 2.7 for the GraalVM/TruffleRuby 21.0.0 release.

eregon commented 3 years ago

I merged initial support for Ruby 2.7 in 08187f1f6e59dc72971e0f0acd94beb01306615c. That updated the stdlib, default and bundled gems, and some basic fixes needed to get the tests running. The new IRB seems to work well. Bundler is stdlib is now Bundler 2 like MRI.

Remaining:

New tagged specs:

New excluded MRI tests:

eregon commented 3 years ago

I'll also copy the checklist from https://github.com/ruby/spec/issues/745 as it might be useful to track progress, and to show individual things to fix. Some of these items might already be done.

NOTE: https://rubyreferences.github.io/rubychanges/2.7.html gives more details for many features and changes. From https://github.com/ruby/ruby/blob/v2_7_0/NEWS:

NEWS for Ruby 2.7.0

This document is a list of user visible feature changes made between releases except for bug fixes.

Changes since the 2.6.0 release

Language changes

Pattern matching

case [0, [1, 2, 3]]
in [a, [b, *c]]
  p a #=> 0
  p b #=> 1
  p c #=> [2, 3]
end

case {a: 0, b: 1}
in {a: 0, x: 1}
  :unreachable
in {a: 0, b: var}
  p var #=> 1
end

case -1
in 0 then :unreachable
in 1 then :unreachable
end #=> NoMatchingPatternError

json = <<END
{
  "name": "Alice",
  "age": 30,
  "children": [{ "name": "Bob", "age": 2 }]
}
END

JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: name, age: age}]}

p name #=> "Bob"
p age  #=> 2

JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: "Charlie", age: age}]}
#=> NoMatchingPatternError

See the following slides for more details:

The spec of keyword arguments is changed towards 3.0

def foo(**kw); p kw; end; foo("str" => 1) #=> {"str"=>1}
def foo(h, **nil); end; foo(key: 1)       # ArgumentError
def foo(h, **nil); end; foo(**{key: 1})   # ArgumentError
def foo(h, **nil); end; foo("str" => 1)   # ArgumentError
def foo(h, **nil); end; foo({key: 1})     # OK
def foo(h, **nil); end; foo({"str" => 1}) # OK
h = {}; def foo(*a) a end; foo(**h) # []
h = {}; def foo(a) a end; foo(**h)  # {} and warning
h = {}; def foo(*a) a end; foo(h)   # [{}]
h = {}; def foo(a) a end; foo(h)    # {}

Numbered parameters

proc/lambda without block is deprecated

Other miscellaneous changes

Command line options

Warning option

The -W option has been extended with a following :, to manage categorized warnings. Feature #16345 Feature #16420

See also Warning in {Core classes updates}[#label-Core+classes+updates+-28outstanding+ones+only-29].

Core classes updates (outstanding ones only)

Array

Comparable

Complex

Dir

Encoding

Enumerable

Enumerator

Fiber

File

FrozenError

GC

IO

Integer

Method

Module

NilClass / TrueClass / FalseClass

ObjectSpace::WeakMap

Proc

Range

String

Symbol

Time

UnboundMethod

Warning

$LOAD_PATH

Stdlib updates (outstanding ones only)

Compatibility issues (excluding feature bug fixes)

Proc

Range

Stdlib compatibility issues (excluding feature bug fixes)

pathname

C API updates

ssnickolay commented 3 years ago

I'll start with Added Complex#<=>., if you do not mind //cc @eregon

norswap commented 3 years ago

I'll take a stab at the rescue parser bug.

norswap commented 3 years ago

I'm marking "The flip-flop syntax deprecation is reverted." as done, since it doesn't seem we emitted the deprecation warning in the first place.

LillianZ commented 3 years ago

Could you also mark enumerator#produce as done per https://github.com/oracle/truffleruby/pull/2160 ? Thanks!

gogainda commented 3 years ago

taking Integer#[] now supports range operations

LillianZ commented 3 years ago

Pathname.glob now delegates 3 arguments to Dir.glob to accept base keyword. Feature #14405 already occurs in TruffleRuby, and thus can be removed/ticked off. The examples in the Redmine post al function.

chrisseaton commented 3 years ago

Are there specs for it? If so do they need to be untagged, if not we should add at least a couple.

eregon commented 3 years ago

Very few things left from the list above:

gogainda commented 3 years ago

I looked into C-API *_kw functions but didn't figure out how to approach this works. @eregon Can we do 1 function so I can work on the rest by the example?

eregon commented 3 years ago

@gogainda https://github.com/oracle/truffleruby/blob/169bce9afead36cde38ae32a19d27b0b95cf9f6d/src/main/c/cext/class.c#L79-L82 is an example. The *_kw functions can be found by git grep -E 'rb_.+_kw\b' lib/cext/include/ruby.

gogainda commented 3 years ago

I thought that // Ignoring kw_splat for now should be replaced by actual code, no?

eregon commented 3 years ago

@gogainda At this point it seems unnecessary, because of how we handle keyword arguments in TruffleRuby. I think we'll only need to deal with this when migrating to Ruby 3.0. So it's OK to just ignore it and add this comment as a reminder when we move to Ruby 3.

eregon commented 3 years ago

I think it's time to mark this issue as solved, we already support most of 2.7 since 21.0.0/21.1.0.

Remaining from the list is:

Those don't seem used much so I think we'll just pragmatically add them when we see an app/gem needing them.