Saturday, April 27, 2024
HomeRuby On RailsRuby 3.2.0 Preview 2 Launched

Ruby 3.2.0 Preview 2 Launched


We’re happy to announce the discharge of Ruby 3.2.0-preview2. Ruby 3.2 provides many options and efficiency enhancements.

WASI based mostly WebAssembly assist

That is an preliminary port of WASI based mostly WebAssembly assist. This permits a CRuby binary to be out there on Internet browser, Serverless Edge surroundings, and different WebAssembly/WASI embedders. At present this port passes fundamental and bootstrap take a look at suites not utilizing Thread API.

Background

WebAssembly (WASM) is initially launched to run packages safely and quick in internet browsers. However its goal – operating packages efficinently with safety on varied surroundings – is lengthy wished not solely by internet but in addition by normal functions.

WASI (The WebAssembly System Interface) is designed for such use instances. Although such functions want to speak with working methods, WebAssembly runs on a digital machine which didn’t have a system interface. WASI standardizes it.

WebAssembly/WASI Help in Ruby intends to leverage these tasks. It allows Ruby builders to write down functions which runs on such promised platform.

Use case

This assist encourages builders can make the most of CRuby in WebAssembly surroundings. An instance use case of it’s TryRuby playground’s CRuby assist. Now you possibly can attempt unique CRuby in your internet browser.

Technical factors

Immediately’s WASI and WebAssembly itself has some lacking options to implement Fiber, exception, and GC as a result of it’s nonetheless evolving and likewise for safety causes. So CRuby fills the hole through the use of Asyncify, which is a binary transformation method to manage execution in userland.

As well as, we constructed a VFS on prime of WASI in order that we are able to simply pack Ruby apps right into a single .wasm file. This makes distribution of Ruby apps a bit simpler.

Associated hyperlinks

Regexp timeout

A timeout function for Regexp matching is launched.

Regexp.timeout = 1.0

/^a*b?a*$/ =~ "a" * 50000 + "x"
#=> Regexp::TimeoutError is raised in a single second

It’s recognized that Regexp matching could take unexpectedly lengthy. In case your code makes an attempt to match an probably inefficient Regexp in opposition to an untrusted enter, an attacker could exploit it for environment friendly Denial of Service (so-called Common expression DoS, or ReDoS).

The chance of DoS might be prevented or considerably mitigated by configuring Regexp.timeout in accordance with the necessities of your Ruby software. Please attempt it out in your software and welcome your suggestions.

Notice that Regexp.timeout is a worldwide configuration. If you wish to use totally different timeout settings for some particular Regexps, chances are you’ll wish to use timeout key phrase for Regexp.new.

Regexp.timeout = 1.0

# This regexp has no timeout
long_time_re = Regexp.new("^a*b?a*$", timeout: nil)

long_time_re =~ "a" * 50000 + "x" # by no means interrupted

The unique proposal is https://bugs.ruby-lang.org/points/17837

Different Notable New Options

Not bundle third occasion sources

Language

  • Nameless relaxation and key phrase relaxation arguments can now be handed as
    arguments, as an alternative of simply utilized in methodology parameters.
    [Feature #18351]

      def foo(*)
        bar(*)
      finish
      def baz(**)
        quux(**)
      finish
    
  • A proc that accepts a single positional argument and key phrases will
    not autosplat. [Bug #18633]

    proc a.name([1, 2])
    # Ruby 3.1 and earlier than
    # => 1
    # Ruby 3.2 and after
    # => [1, 2]
    
  • Fixed task analysis order for constants set on express
    objects has been made in line with single attribute task
    analysis order. With this code:

    foo is now referred to as earlier than baz. Equally, for a number of assignments
    to constants, left-to-right analysis order is used. With this
    code:

        foo1::BAR1, foo2::BAR2 = baz1, baz2
    

    The next analysis order is now used:

    1. foo1
    2. foo2
    3. baz1
    4. baz2

    [Bug #15928]

  • Discover sample is not experimental.
    [Feature #18585]

  • Strategies taking a relaxation parameter (like *args) and wishing to delegate key phrase
    arguments by means of foo(*args) should now be marked with ruby2_keywords
    (if not already the case). In different phrases, all strategies wishing to delegate
    key phrase arguments by means of *args should now be marked with ruby2_keywords,
    with no exception. This may make it simpler to transition to different methods of
    delegation as soon as a library can require Ruby 3+. Beforehand, the ruby2_keywords
    flag was stored if the receiving methodology took *args, however this was a bug and an
    inconsistency. A very good method to search out the potentially-missing ruby2_keywords
    is to run the take a look at suite, for the place it fails discover the final methodology which should
    obtain key phrase arguments, use places nil, caller, nil there, and examine every
    methodology/block on the decision chain which should delegate key phrases is appropriately marked
    as ruby2_keywords. [Bug #18625] [Bug #16466]

      def goal(**kw)
      finish
    
      # By chance labored with out ruby2_keywords in Ruby 2.7-3.1, ruby2_keywords
      # wanted in 3.2+. Identical to (*args, **kwargs) or (...) can be wanted on
      # each #foo and #bar when migrating away from ruby2_keywords.
      ruby2_keywords def bar(*args)
        goal(*args)
      finish
    
      ruby2_keywords def foo(*args)
        bar(*args)
      finish
    
      foo(ok: 1)
    

Efficiency enhancements

YJIT

  • Help arm64 / aarch64 on UNIX platforms.
  • Constructing YJIT requires Rust 1.58.1+. [Feature #18481]

Different notable modifications since 3.1

  • Hash
    • Hash#shift now all the time returns nil if the hash is
      empty, as an alternative of returning the default worth or
      calling the default proc. [Bug #16908]
  • MatchData
  • Module
  • Proc
  • Refinement
  • Set
    • Set is now out there as a builtin class with out the necessity for require "set". [Feature #16989]
      It’s at the moment autoloaded through the Set fixed or a name to Enumerable#to_set.
  • String
    • String#byteindex and String#byterindex have been added. [Feature #13110]
    • Replace Unicode to Model 14.0.0 and Emoji Model 14.0. [Feature #18037]
      (additionally applies to Regexp)
    • String#bytesplice has been added. [Feature #18598]
  • Struct
    • A Struct class can be initialized with key phrase arguments
      with out keyword_init: true on Struct.new [Feature #16806]

Compatibility points

Notice: Excluding function bug fixes.

Eliminated constants

The next deprecated constants are eliminated.

Eliminated strategies

The next deprecated strategies are eliminated.

Stdlib compatibility points

  • Psych not bundles libyaml sources.
    Customers want to put in the libyaml library themselves through the package deal
    system. [Feature #18571]

C API updates

Eliminated C APIs

The next deprecated APIs are eliminated.

  • rb_cData variable.
  • “taintedness” and “trustedness” capabilities. [Feature #16131]

Normal libraries updates

  • The next default gem are up to date.

  • The next bundled gems are up to date.

  • The next default gems at the moment are bundled gems. You have to add the next libraries to Gemfile beneath the bundler surroundings.

See NEWS
or commit logs
for extra particulars.

With these modifications, 2393 recordsdata modified, 168931 insertions(+), 113411 deletions(-)
since Ruby 3.1.0!

Obtain

  • https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.0-preview2.tar.gz

    SIZE: 19816780
    SHA1: 2106c77fc1600daf41ae137ecc4cf7937e27f67f
    SHA256: 8a78fd7a221b86032f96f25c1d852954c94d193b9d21388a9b434e160b7ed891
    SHA512: 5e9ddcb1a43cff449b0062cc716bfb80a9ebbb14a1b063f34005e2998c2c5033badb44e882232db9b2fceda9376f6615986e983511fda2575d60894752b605cc
    
  • https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.0-preview2.tar.xz

    SIZE: 14578112
    SHA1: 538b3ea4dc0d99f60f8bd6f71e65a56ceeb41c18
    SHA256: 01fac0929dccdabc0686c1109da6c187897a401da9ff8851242befa92f7fd430
    SHA512: 0f4cc919284fdfa1a42b6381760d1b3a4660da4b0fcdd2adf01ea04a425548b3c5ac090866915675db73964a1055090e54dd97cf4628cbb69403e541c71c28ff
    
  • https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.0-preview2.zip

    SIZE: 24150109
    SHA1: 69ffffc52cad626166f73f21f25c29c9d73fe0e8
    SHA256: 67f9ad3110be1975b3ce547c0a6e2c910dfc1945fd6e9bb1bd340568897c6554
    SHA512: 1447e099e7a8da0ff206fda6f4e466640d6e86e9da8148315ab0154684b1fd22c02c0022b5a2f4d3fc00103b4e8cef8e35a770174921fd8c6abeca9ad41c1818
    

What’s Ruby

Ruby was first developed by Matz (Yukihiro Matsumoto) in 1993,
and is now developed as Open Supply. It runs on a number of platforms
and is used all around the world particularly for internet growth.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments