Skip to content

Commit 8fba03f

Browse files
committed
Copy 3.2.0 preview/rc from en
1 parent abf2ed4 commit 8fba03f

3 files changed

+1233
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
---
2+
layout: news_post
3+
title: "Ruby 3.2.0 Preview 2 Released"
4+
author: "naruse"
5+
translator:
6+
date: 2022-09-09 00:00:00 +0000
7+
lang: en
8+
---
9+
10+
{% assign release = site.data.releases | where: "version", "3.2.0-preview2" | first %}
11+
12+
We are pleased to announce the release of Ruby {{ release.version }}. Ruby 3.2 adds many features and performance improvements.
13+
14+
15+
## WASI based WebAssembly support
16+
17+
This is an initial port of WASI based WebAssembly support. This enables a CRuby binary to be available on Web browser, Serverless Edge environment, and other WebAssembly/WASI embedders. Currently this port passes basic and bootstrap test suites not using Thread API.
18+
19+
![](https://i.imgur.com/opCgKy2.png)
20+
21+
### Background
22+
23+
[WebAssembly (Wasm)](https://webassembly.org/) is originally introduced to run programs safely and fast in web browsers. But its objective - running programs efficinently with security on various environment - is long wanted not only by web but also by general applications.
24+
25+
[WASI (The WebAssembly System Interface)](https://wasi.dev/) is designed for such use cases. Though such applications need to communicate with operating systems, WebAssembly runs on a virtual machine which didn't have a system interface. WASI standardizes it.
26+
27+
WebAssembly/WASI Support in Ruby intends to leverage those projects. It enables Ruby developers to write applications which runs on such promised platform.
28+
29+
### Use case
30+
31+
This support encourages developers can utilize CRuby in WebAssembly environment. An example use case of it is [TryRuby playground](https://try.ruby-lang.org/playground/)'s CRuby support. Now you can try original CRuby in your web browser.
32+
33+
### Technical points
34+
35+
Today’s WASI and WebAssembly itself has some missing features to implement Fiber, exception, and GC because it’s still evolving and also for security reasons. So CRuby fills the gap by using Asyncify, which is a binary transformation technique to control execution in userland.
36+
37+
In addition, we built [a VFS on top of WASI](https://github.com/kateinoigakukun/wasi-vfs/wiki/Getting-Started-with-CRuby) so that we can easily pack Ruby apps into a single .wasm file. This makes distribution of Ruby apps a bit easier.
38+
39+
40+
### Related links
41+
42+
* [Add WASI based WebAssembly support #5407](https://github.com/ruby/ruby/pull/5407)
43+
* [An Update on WebAssembly/WASI Support in Ruby](https://itnext.io/final-report-webassembly-wasi-support-in-ruby-4aface7d90c9)
44+
45+
## Regexp timeout
46+
47+
A timeout feature for Regexp matching is introduced.
48+
49+
```ruby
50+
Regexp.timeout = 1.0
51+
52+
/^a*b?a*$/ =~ "a" * 50000 + "x"
53+
#=> Regexp::TimeoutError is raised in one second
54+
```
55+
56+
It is known that Regexp matching may take unexpectedly long. If your code attempts to match an possibly inefficient Regexp against an untrusted input, an attacker may exploit it for efficient Denial of Service (so-called Regular expression DoS, or ReDoS).
57+
58+
The risk of DoS can be prevented or significantly mitigated by configuring `Regexp.timeout` according to the requirements of your Ruby application. Please try it out in your application and welcome your feedback.
59+
60+
Note that `Regexp.timeout` is a global configuration. If you want to use different timeout settings for some special Regexps, you may want to use `timeout` keyword for `Regexp.new`.
61+
62+
```ruby
63+
Regexp.timeout = 1.0
64+
65+
# This regexp has no timeout
66+
long_time_re = Regexp.new("^a*b?a*$", timeout: nil)
67+
68+
long_time_re =~ "a" * 50000 + "x" # never interrupted
69+
```
70+
71+
The original proposal is https://bugs.ruby-lang.org/issues/17837
72+
73+
74+
## Other Notable New Features
75+
76+
### No longer bundle 3rd party sources
77+
78+
* We no longer bundle 3rd party sources like `libyaml`, `libffi`.
79+
80+
* libyaml source has been removed from psych. You may need to install `libyaml-dev` with Ubuntu/Debian platfrom. The package name is different each platforms.
81+
82+
* libffi will be removed from `fiddle` at preview2
83+
84+
### Language
85+
86+
* Anonymous rest and keyword rest arguments can now be passed as
87+
arguments, instead of just used in method parameters.
88+
[[Feature #18351]]
89+
90+
```ruby
91+
def foo(*)
92+
bar(*)
93+
end
94+
def baz(**)
95+
quux(**)
96+
end
97+
```
98+
99+
* A proc that accepts a single positional argument and keywords will
100+
no longer autosplat. [[Bug #18633]]
101+
102+
```ruby
103+
proc{|a, **k| a}.call([1, 2])
104+
# Ruby 3.1 and before
105+
# => 1
106+
# Ruby 3.2 and after
107+
# => [1, 2]
108+
```
109+
110+
* Constant assignment evaluation order for constants set on explicit
111+
objects has been made consistent with single attribute assignment
112+
evaluation order. With this code:
113+
114+
```ruby
115+
foo::BAR = baz
116+
```
117+
118+
`foo` is now called before `baz`. Similarly, for multiple assignments
119+
to constants, left-to-right evaluation order is used. With this
120+
code:
121+
122+
```ruby
123+
foo1::BAR1, foo2::BAR2 = baz1, baz2
124+
```
125+
126+
The following evaluation order is now used:
127+
128+
1. `foo1`
129+
2. `foo2`
130+
3. `baz1`
131+
4. `baz2`
132+
133+
[[Bug #15928]]
134+
135+
* Find pattern is no longer experimental.
136+
[[Feature #18585]]
137+
138+
* Methods taking a rest parameter (like `*args`) and wishing to delegate keyword
139+
arguments through `foo(*args)` must now be marked with `ruby2_keywords`
140+
(if not already the case). In other words, all methods wishing to delegate
141+
keyword arguments through `*args` must now be marked with `ruby2_keywords`,
142+
with no exception. This will make it easier to transition to other ways of
143+
delegation once a library can require Ruby 3+. Previously, the `ruby2_keywords`
144+
flag was kept if the receiving method took `*args`, but this was a bug and an
145+
inconsistency. A good technique to find the potentially-missing `ruby2_keywords`
146+
is to run the test suite, for where it fails find the last method which must
147+
receive keyword arguments, use `puts nil, caller, nil` there, and check each
148+
method/block on the call chain which must delegate keywords is correctly marked
149+
as `ruby2_keywords`. [[Bug #18625]] [[Bug #16466]]
150+
151+
```ruby
152+
def target(**kw)
153+
end
154+
155+
# Accidentally worked without ruby2_keywords in Ruby 2.7-3.1, ruby2_keywords
156+
# needed in 3.2+. Just like (*args, **kwargs) or (...) would be needed on
157+
# both #foo and #bar when migrating away from ruby2_keywords.
158+
ruby2_keywords def bar(*args)
159+
target(*args)
160+
end
161+
162+
ruby2_keywords def foo(*args)
163+
bar(*args)
164+
end
165+
166+
foo(k: 1)
167+
```
168+
169+
## Performance improvements
170+
171+
### YJIT
172+
173+
* Support arm64 / aarch64 on UNIX platforms.
174+
* Building YJIT requires Rust 1.58.1+. [[Feature #18481]]
175+
176+
## Other notable changes since 3.1
177+
178+
* Hash
179+
* Hash#shift now always returns nil if the hash is
180+
empty, instead of returning the default value or
181+
calling the default proc. [[Bug #16908]]
182+
183+
* MatchData
184+
* MatchData#byteoffset has been added. [[Feature #13110]]
185+
186+
* Module
187+
* Module.used_refinements has been added. [[Feature #14332]]
188+
* Module#refinements has been added. [[Feature #12737]]
189+
* Module#const_added has been added. [[Feature #17881]]
190+
191+
* Proc
192+
* Proc#dup returns an instance of subclass. [[Bug #17545]]
193+
* Proc#parameters now accepts lambda keyword. [[Feature #15357]]
194+
195+
* Refinement
196+
* Refinement#refined_class has been added. [[Feature #12737]]
197+
198+
* Set
199+
* Set is now available as a builtin class without the need for `require "set"`. [[Feature #16989]]
200+
It is currently autoloaded via the `Set` constant or a call to `Enumerable#to_set`.
201+
202+
* String
203+
* String#byteindex and String#byterindex have been added. [[Feature #13110]]
204+
* Update Unicode to Version 14.0.0 and Emoji Version 14.0. [[Feature #18037]]
205+
(also applies to Regexp)
206+
* String#bytesplice has been added. [[Feature #18598]]
207+
208+
* Struct
209+
* A Struct class can also be initialized with keyword arguments
210+
without `keyword_init: true` on `Struct.new` [[Feature #16806]]
211+
212+
## Compatibility issues
213+
214+
Note: Excluding feature bug fixes.
215+
216+
### Removed constants
217+
218+
The following deprecated constants are removed.
219+
220+
* `Fixnum` and `Bignum` [[Feature #12005]]
221+
* `Random::DEFAULT` [[Feature #17351]]
222+
* `Struct::Group`
223+
* `Struct::Passwd`
224+
225+
### Removed methods
226+
227+
The following deprecated methods are removed.
228+
229+
* `Dir.exists?` [[Feature #17391]]
230+
* `File.exists?` [[Feature #17391]]
231+
* `Kernel#=~` [[Feature #15231]]
232+
* `Kernel#taint`, `Kernel#untaint`, `Kernel#tainted?`
233+
[[Feature #16131]]
234+
* `Kernel#trust`, `Kernel#untrust`, `Kernel#untrusted?`
235+
[[Feature #16131]]
236+
237+
## Stdlib compatibility issues
238+
239+
* `Psych` no longer bundles libyaml sources.
240+
Users need to install the libyaml library themselves via the package
241+
system. [[Feature #18571]]
242+
243+
## C API updates
244+
245+
### Removed C APIs
246+
247+
The following deprecated APIs are removed.
248+
249+
* `rb_cData` variable.
250+
* "taintedness" and "trustedness" functions. [[Feature #16131]]
251+
252+
### Standard libraries updates
253+
254+
* The following default gem are updated.
255+
256+
* TBD
257+
258+
* The following bundled gems are updated.
259+
260+
* TBD
261+
262+
* The following default gems are now bundled gems. You need to add the following libraries to `Gemfile` under the bundler environment.
263+
264+
* TBD
265+
266+
See [NEWS](https://github.com/ruby/ruby/blob/{{ release.tag }}/NEWS.md)
267+
or [commit logs](https://github.com/ruby/ruby/compare/v3_1_0...{{ release.tag }})
268+
for more details.
269+
270+
With those changes, [{{ release.stats.files_changed }} files changed, {{ release.stats.insertions }} insertions(+), {{ release.stats.deletions }} deletions(-)](https://github.com/ruby/ruby/compare/v3_1_0...{{ release.tag }}#file_bucket)
271+
since Ruby 3.1.0!
272+
273+
## Download
274+
275+
* <{{ release.url.gz }}>
276+
277+
SIZE: {{ release.size.gz }}
278+
SHA1: {{ release.sha1.gz }}
279+
SHA256: {{ release.sha256.gz }}
280+
SHA512: {{ release.sha512.gz }}
281+
282+
* <{{ release.url.xz }}>
283+
284+
SIZE: {{ release.size.xz }}
285+
SHA1: {{ release.sha1.xz }}
286+
SHA256: {{ release.sha256.xz }}
287+
SHA512: {{ release.sha512.xz }}
288+
289+
* <{{ release.url.zip }}>
290+
291+
SIZE: {{ release.size.zip }}
292+
SHA1: {{ release.sha1.zip }}
293+
SHA256: {{ release.sha256.zip }}
294+
SHA512: {{ release.sha512.zip }}
295+
296+
## What is Ruby
297+
298+
Ruby was first developed by Matz (Yukihiro Matsumoto) in 1993,
299+
and is now developed as Open Source. It runs on multiple platforms
300+
and is used all over the world especially for web development.
301+
302+
303+
304+
[Feature #12005]: https://bugs.ruby-lang.org/issues/12005
305+
[Feature #12655]: https://bugs.ruby-lang.org/issues/12655
306+
[Feature #12737]: https://bugs.ruby-lang.org/issues/12737
307+
[Feature #13110]: https://bugs.ruby-lang.org/issues/13110
308+
[Feature #14332]: https://bugs.ruby-lang.org/issues/14332
309+
[Feature #15231]: https://bugs.ruby-lang.org/issues/15231
310+
[Feature #15357]: https://bugs.ruby-lang.org/issues/15357
311+
[Bug #15928]: https://bugs.ruby-lang.org/issues/15928
312+
[Feature #16131]: https://bugs.ruby-lang.org/issues/16131
313+
[Bug #16466]: https://bugs.ruby-lang.org/issues/16466
314+
[Feature #16806]: https://bugs.ruby-lang.org/issues/16806
315+
[Bug #16889]: https://bugs.ruby-lang.org/issues/16889
316+
[Bug #16908]: https://bugs.ruby-lang.org/issues/16908
317+
[Feature #16989]: https://bugs.ruby-lang.org/issues/16989
318+
[Feature #17351]: https://bugs.ruby-lang.org/issues/17351
319+
[Feature #17391]: https://bugs.ruby-lang.org/issues/17391
320+
[Bug #17545]: https://bugs.ruby-lang.org/issues/17545
321+
[Feature #17881]: https://bugs.ruby-lang.org/issues/17881
322+
[Feature #18037]: https://bugs.ruby-lang.org/issues/18037
323+
[Feature #18159]: https://bugs.ruby-lang.org/issues/18159
324+
[Feature #18351]: https://bugs.ruby-lang.org/issues/18351
325+
[Bug #18487]: https://bugs.ruby-lang.org/issues/18487
326+
[Feature #18571]: https://bugs.ruby-lang.org/issues/18571
327+
[Feature #18585]: https://bugs.ruby-lang.org/issues/18585
328+
[Feature #18598]: https://bugs.ruby-lang.org/issues/18598
329+
[Bug #18625]: https://bugs.ruby-lang.org/issues/18625
330+
[Bug #18633]: https://bugs.ruby-lang.org/issues/18633
331+
[Feature #18685]: https://bugs.ruby-lang.org/issues/18685
332+
[Bug #18782]: https://bugs.ruby-lang.org/issues/18782
333+
[Feature #18788]: https://bugs.ruby-lang.org/issues/18788
334+
[Feature #18809]: https://bugs.ruby-lang.org/issues/18809
335+
[Feature #18481]: https://bugs.ruby-lang.org/issues/18481

0 commit comments

Comments
 (0)