Debian Codegraph @

vendor/mruby-source/doc/mruby3.1.md

raw
1 # User visible changes in `mruby3.1` from `mruby3.0`
2
3 # New Features
4
5 ## Core Language Features
6
7 ### Keyword Arguments
8
9 CRuby3.0 compatible keyword arguments are introduced.
10 Keyword arguments are basically separated from ordinal arguments.
11
12 ### Other Language Enhancement
13
14 - Implement endless-def [Ruby:Feature#16746](https://bugs.ruby-lang.org/issues/16746)
15 - Replace `R-assignment` by `single-line pattern matching` [Ruby:Feature#15921](https://bugs.ruby-lang.org/issues/15921)
16 - Support squiggly heredocs. [#5246](https://github.com/mruby/mruby/pull/5246)
17 - Hash value omission [Ruby:Feature#14579](https://bugs.ruby-lang.org/issues/14579)
18
19 ## Configuration Options Changed
20
21 Some configuration macros are available:
22
23 - `MRB_WORDBOX_NO_FLOAT_TRUNCATE`: by default, float values are packed in the word if possible, but define this macro to allocate float values in the heap.
24 - `MRB_USE_RO_DATA_P_ETEXT`: define this macro if `_etext` is available on your platform.
25 - `MRB_NO_DEFAULT_RO_DATA_P`: define this macro to avoid using predefined `mrb_ro_data_p()` function
26
27 ---
28
29 # Updated Features
30
31 ## New build configurations
32
33 We have added several new build configurations in the `build_config` directory.
34
35 - `cross-mingw-winetest.rb`
36 - `cross-mingw.rb`
37 - `nintendo_switch.rb`
38 - `serenity.rb`
39 - `minimal`: minimal configuration
40 - `host-f32`: compiles with `mrb_float` as 32 bit `float`
41 - `host-nofloat`: compiles with no float configuration
42 - `android_arm64_v8a.rb`: renamed from `android_arm64-v8a.rb`
43
44 ## Core Libraries
45
46 ### New Methods
47
48 - `Array#product`
49 - `Array#repeated_combination`
50 - `Array#repeated_permutation`
51 - `Kernel#__ENCODING__`
52 - `Random.bytes`
53 - `Random#bytes`
54 - `String#center`
55
56 ### New Gem Enhancement
57
58 - `mrbgems/mruby-pack` now supports `M` directive (Q encoding)
59 - `mrbgems/mruby-pack` now supports `X` directive (back-up by bytes)
60 - `mrbgems/mruby-pack` now supports `@` directive (absolute position)
61 - `mrbgems/mruby-pack` now supports `w` directive (BER compression)
62
63 ## Tools
64
65 - `mruby-config` now supports `--cc` and `--ld` options.
66 - Remove `OP_` prefix from `mruby -v` code dump output.
67 - Prohibit use of `OP_EXT{1,2,3}` by `mrbc` with `--no-ext-ops` option.
68
69 ## Features for mruby Developer
70
71 - Add new specifier `c` to `mrb_get_args()` for receive Class/Module.
72
73 ---
74
75 # Breaking Changes
76
77 ## Incompatibly Changed Methods
78
79 - `Kernel#printf` (`mruby-sprintf`) Format specifiers `%a` and `%A` are removed.
80 - `Kernel#puts` (`mruby-print`) Now expand Array arguments.
81
82 ## mruby VM and bytecode
83
84 Due to improvements in the binary format, mruby binaries are no longer backward compatible.
85 To run the mruby binaries on mruby 3.1, recompile with the mruby 3.1 `mrbc`.
86
87 - Upgrade mruby VM version `RITE_VM_VER` to `0300` (means mruby 3.0 or after).
88 - Upgrade mruby binary version `RITE_BINARY_FORMAT_VER` to `0300`.
89
90 ## Reintroduced Instructions
91
92 `mruby3.0` removed `OP_EXT1`, `OP_EXT2`, `OP_EXT3` for operand extension. But the operand size limitations was too tight for real-world application.
93 `mruby3.1` reintroduces those extension instructions.
94
95 ## Removed Instructions
96
97 `mruby3.1` removed following instructions.
98
99 - `OP_LOADL16`
100 - `OP_LOADSYM16`
101 - `OP_STRING16`
102 - `OP_LAMBDA16`
103 - `OP_BLOCK16`
104 - `OP_METHOD16`
105 - `OP_EXEC16`
106
107 Those instructions are no longer needed by reintroduction of extension instructions.
108
109 - `OP_SENDV`
110 - `OP_SENDVB`
111
112 Those instructions for method calls with variable number of arguments are no longer needed. They are covered by `OP_SEND` instruction with `n=15`.
113
114 ## New Instructions
115
116 `mruby3.1` introduces following new instructions.
117
118 - `OP_GETIDX`: takes 1 operands `R[a][a+1]`
119 - `OP_SETIDX`: takes 1 operands `R[a][a+1]=R[a+2]`
120 - `OP_SSEND`: takes 3 operands `a=self.b(c...)`; see `OP_SEND`
121 - `OP_SSENDB`: takes 3 operands `a=self.b(c...){...}`; see `OP_SEND`
122 - `OP_SYMBOL`: takes 2 operands `R[a] = intern(Pool[b])`
123
124 ### `OP_GETIDX` and `OP_SETIDX`
125
126 Execute `obj[int]` and `obj[int] = value` respectively, where `obj` is `string|array|hash`.
127
128 ### `OP_SSEND` and `OP_SSENDB`
129
130 They are similar to `OP_SEND` and `OP_SENDB` respectively. They initialize the `R[a]` by `self` first so that we can skip one `OP_LOADSELF` instruction for each call.
131
132 ### `OP_SYMBOL`
133
134 Extracts the character string placed in the pool as a symbol.
135
136 ## Changed Instructions
137
138 ### `OP_SEND` and `OP_SENDB`
139
140 Method calling instructions are unified. Now `OP_SEND` and `OP_SENDB` (method call with a block) can support both splat arguments and keyword arguments as well.
141
142 The brief description of the instructions:
143
144 |`OP_SEND` | BBB | `R[a] = R[a].call(Syms[b],R[a+1..n],R[a+n+1],R[a+n+2]..nk) c=n|nk<<4` |
145 |`OP_SENDB` | BBB | `R[a] = R[a].call(Syms[b],R[a+1..n],R[a+n+1..nk],R[a+n+2..nk],&R[a+n+2*nk+2]) c=n|nk<<4` |
146
147 Operand C specifies the number of arguments. Lower 4 bits (`n`) represents the number of ordinal arguments, and higher 4 bits (`nk`) represents the number of keyword arguments.
148 When `n == 15`, the method takes arguments packed in an array. When `nk == 15`, the method takes keyword arguments are packed in a hash.
149
150 ### `OP_ARYPUSH`
151
152 Now takes 2 operands and pushes multiple entries to an array.
153
154 ## Boxing Updated
155
156 ### Word Boxing
157
158 `MRB_WORD_BOXING` now packs floating-point numbers in the word, if the size of `mrb_float` is equal or smaller than the size of `mrb_int` by default.
159 If the size of `mrb_float` and `mrb_int` are same, the last 2 bits in the `mrb_float` are trimmed and used as flags. If you need full precision, you need to define `MRB_WORDBOX_NO_FLOAT_TRUNCATE` as described above.
160
161 ### NaN Boxing
162
163 Previous NaN boxing packs values in NaN representation, but pointer retrievals are far more frequent than floating-point number references. So we add constant offset to NaN representation to clear higher bits of pointer representation. This representation is called "Favor Pointer" NaN Boxing.
164
165 Also, previous NaN boxing limit the size of `mrb_int` to 4 bytes (32 bits) to fit in NaN values. Now we allocate integer values in the heap, if the value does not fit in the 32 bit range, just like we did in Word Boxing.
166
167 ## Constant Folding
168
169 The code generator was updated to reduce the number of instructions, e.g.
170
171 ```
172 a = 2 * 5
173 ```
174
175 will be interpreted as
176
177 ```
178 a = 10
179 ```
180
181 In addition, we have improved peephole optimizations, for example:
182
183 ```
184 GETIV R4 :@foo
185 MOVE R1 R4
186 ```
187
188 to
189
190 ```
191 GETIV R1 :@foo
192 ```
193
194 ## `String#hash` now use `FNV1a` algorithm
195
196 For better and faster hash values.
197
198 ---
199
200 # Major bug fixes
201
202 - Fix infinite recursive call bugs in integer division [98799aa6](https://github.com/mruby/mruby/commit/98799aa6)
203 - Fix to raise TypeError with super inside instance_eval / class_eval [#5476](https://github.com/mruby/mruby/pull/5476)
204 - Fix to call `method_added` hooks on method definitions; [#2339](https://github.com/mruby/mruby/pull/2339)
205 - Fix a potential buffer overflow in `time_zonename` [26340a88](https://github.com/mruby/mruby/commit/26340a88)
206 - Fix `Module.instance_eval` bug [#5528](https://github.com/mruby/mruby/pull/5528)
207 - Fix fix `M` packing bug [bfe2bd49](https://github.com/mruby/mruby/commit/bfe2bd49)
208 - Fix a bug regarding attribute assignment with kargs [de2b4bd0](https://github.com/mruby/mruby/commit/de2b4bd0)
209 - Fix SIGSEGV with mrbgems/mruby-method [#5580](https://github.com/mruby/mruby/pull/5580)
210 - Fix print error before cleanup in `codegen_error()` [#5603](https://github.com/mruby/mruby/pull/5603)
211 - Fix a bug in unpacking BER [#5611](https://github.com/mruby/mruby/pull/5611)
212 - Fix a bug with numbered parameters as arguments [#5605](https://github.com/mruby/mruby/pull/5605)
213 - Fix `mrb_ary_shift_m` initialization bug [27d1e013](https://github.com/mruby/mruby/commit/27d1e013)
214 - Fix keyword argument with `super` [#5628](https://github.com/mruby/mruby/pull/5628)
215 - Fix a bug with numbered parameters on toplevel [7e7f1b2f](https://github.com/mruby/mruby/commit/7e7f1b2f)
216 - Fix keyword argument bug [#5632](https://github.com/mruby/mruby/issues/5632)
217 - Fix multiple assignments in parameters [#5647](https://github.com/mruby/mruby/issues/5647)
218 - Fix keyword parameters not passing through super [#5660](https://github.com/mruby/mruby/issues/5660)
219 - Fix infinite loop from unclosed here-doc [#5676](https://github.com/mruby/mruby/issues/5676)
220 - Fix negative integer division bug [#5678](https://github.com/mruby/mruby/issues/5678)
221
222 # CVEs
223
224 ## Fixed CVEs
225
226 Following CVEs are fixed in this release.
227
228 - [CVE-2021-4110](https://nvd.nist.gov/vuln/detail/CVE-2021-4110)
229 - [CVE-2021-4188](https://nvd.nist.gov/vuln/detail/CVE-2021-4188)
230 - [CVE-2022-0080](https://nvd.nist.gov/vuln/detail/CVE-2022-0080)
231 - [CVE-2022-0240](https://nvd.nist.gov/vuln/detail/CVE-2022-0240)
232 - [CVE-2022-0326](https://nvd.nist.gov/vuln/detail/CVE-2022-0326)
233 - [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481)
234 - [CVE-2022-0631](https://nvd.nist.gov/vuln/detail/CVE-2022-0631)
235 - [CVE-2022-0632](https://nvd.nist.gov/vuln/detail/CVE-2022-0632)
236 - [CVE-2022-0890](https://nvd.nist.gov/vuln/detail/CVE-2022-0890)
237 - [CVE-2022-1071](https://nvd.nist.gov/vuln/detail/CVE-2022-1071)
238 - [CVE-2022-1106](https://nvd.nist.gov/vuln/detail/CVE-2022-1106)
239 - [CVE-2022-1201](https://nvd.nist.gov/vuln/detail/CVE-2022-1201)
240 - [CVE-2022-1427](https://nvd.nist.gov/vuln/detail/CVE-2022-1427)
241
242 ## Unaffected CVEs
243
244 Following CVEs do not cause problems in this release. They are fixed in the later release.
245
246 - [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481)
247 - [CVE-2022-0525](https://nvd.nist.gov/vuln/detail/CVE-2022-0525)
248 - [CVE-2022-0570](https://nvd.nist.gov/vuln/detail/CVE-2022-0570)
249 - [CVE-2022-0614](https://nvd.nist.gov/vuln/detail/CVE-2022-0614)
250 - [CVE-2022-0623](https://nvd.nist.gov/vuln/detail/CVE-2022-0623)
251 - [CVE-2022-0630](https://nvd.nist.gov/vuln/detail/CVE-2022-0630)
252 - [CVE-2022-0717](https://nvd.nist.gov/vuln/detail/CVE-2022-0817)
253 - [CVE-2022-1212](https://nvd.nist.gov/vuln/detail/CVE-2022-1212)
254 - [CVE-2022-1276](https://nvd.nist.gov/vuln/detail/CVE-2022-1276)
255 - [CVE-2022-1286](https://nvd.nist.gov/vuln/detail/CVE-2022-1286)