# mruby 3.1.0 mruby 3.1 シリーズ初の安定版mruby3.1.0をリリースです。[mruby 3.1.0](https://github.com/mruby/mruby/releases/tag/3.1.0). mruby 3.1 の新機能と変更点について説明しています。 mruby 3.1での主な変更点は、[doc/mruby3.1.md](https://github.com/mruby/mruby/blob/master/doc/mruby3.1.md).のページでも説明しています。 --- # 新機能 ## Core Language Features ### Keyword Arguments CRuby3.0互換のキーワード引数が導入されました。 キーワード引数は基本的に序数引数と分離されています。 ### その他の強化された機能 - Implement endless-def [Ruby:Feature#16746](https://bugs.ruby-lang.org/issues/16746) - Replace `R-assignment` by `single-line pattern matching` [Ruby:Feature#15921](https://bugs.ruby-lang.org/issues/15921) - Support squiggly heredocs. [#5246](https://github.com/mruby/mruby/pull/5246) - ハッシュ値省略 [Ruby:Feature#14579](https://bugs.ruby-lang.org/issues/14579) ## Configuration Options Changed いくつかの設定マクロが利用可能になりました。 - `MRB_WORDBOX_NO_FLOAT_TRUNCATE`: デフォルトでは、float 値は可能な限り word に詰め込まれますが、このマクロを定義すると float 値をヒープに割り当てることができます。 - `MRB_USE_RO_DATA_P_ETEXT`: お使いのプラットフォームで `_etext` が利用可能な場合は、このマクロを定義します。 - `MRB_NO_DEFAULT_RO_DATA_P`: 定義済みの `mrb_ro_data_p()` 関数を使用しないようにするには、このマクロを定義します。 --- # Updated Features ## New build configurations `build_config` ディレクトリにいくつかの新しいビルドコンフィギュレーションが追加されました。 - `cross-mingw-winetest.rb` - `cross-mingw.rb` - `nintendo_switch.rb` - `serenity.rb` - `minimal`: minimal configuration - `host-f32`: compiles with `mrb_float` as 32 bit `float` - `host-nofloat`: compiles with no float configuration - `android_arm64_v8a.rb`: renamed from `android_arm64-v8a.rb` ## Core Libraries ### New Methods - `Array#product` - `Array#repeated_combination` - `Array#repeated_permutation` - `Kernel#__ENCODING__` - `Random.bytes` - `Random#bytes` - `String#center` ### New Gem Enhancement - `mrbgems/mruby-pack` now supports `M` directive (Q encoding) - `mrbgems/mruby-pack` now supports `X` directive (back-up by bytes) - `mrbgems/mruby-pack` now supports `@` directive (absolute position) - `mrbgems/mruby-pack` now supports `w` directive (BER compression) ## Tools - `mruby-config` now supports `--cc` and `--ld` options. - mruby -v` のコードダンプ出力から `OP_` という接頭辞を削除しました。 - オプション `--no-ext-ops` で `mrbc` による `OP_EXT{1,2,3}` の使用を禁止することができるようになりました。 ##mruby開発者向け機能 - receiveクラス/モジュールの `mrb_get_args()` に新しい指定子 `c` を追加しました。 --- # Breaking Changes ## 互換性のない変更されたメソッド - `Kernel#printf` (`mruby-sprintf`) Format specifiers `%a` and `%A` are removed. - `Kernel#puts` (`mruby-print`) Now expand Array arguments. ## mruby VM and bytecode バイナリ形式の改善により、mrubyのバイナリには後方互換性がなくなりました。 mruby 3.1上でmrubyのバイナリを実行するには、mruby 3.1 の `mrbc` を使って再コンパイルしてください。 - Upgrade mruby VM version `RITE_VM_VER` to `0300` (means mruby 3.0 or after). - Upgrade mruby binary version `RITE_BINARY_FORMAT_VER` to `0300`. ## 再導入された Instructions mruby3.0 では、オペランド拡張のための `OP_EXT1`, `OP_EXT2`, `OP_EXT3` が削除されました。しかし、オペランドサイズの制限は実際のアプリケーションでは厳しすぎたようです。 mruby3.1` では、これらの拡張命令を再導入しました。 ## 削除されたInstructions `mruby3.1` では以下のInstructionsが削除されました。 - `OP_LOADL16` - `OP_LOADSYM16` - `OP_STRING16` - `OP_LAMBDA16` - `OP_BLOCK16` - `OP_METHOD16` - `OP_EXEC16` これらの命令は、拡張命令の再導入により不要になりました。 - `OP_SENDV` - `OP_SENDVB` 可変個数の引数を持つメソッドコールのためのこれらの命令は、もはや必要ありません。これらは `n=15` の `OP_SEND` 命令でカバーされています。 ## New Instructions `mruby3.1`では下記の新しいInstructionsが追加されました。 - `OP_GETIDX`: takes 1 operands `R[a][a+1]` - `OP_SETIDX`: takes 1 operands `R[a][a+1]=R[a+2]` - `OP_SSEND`: takes 3 operands `a=self.b(c...)`; see `OP_SEND` - `OP_SSENDB`: takes 3 operands `a=self.b(c...){...}`; see `OP_SEND` - `OP_SYMBOL`: takes 2 operands `R[a] = intern(Pool[b])` ### `OP_GETIDX` and `OP_SETIDX` Execute `obj[int]` and `obj[int] = value` respectively, where `obj` is `string|array|hash`. ### `OP_SSEND` and `OP_SSENDB` これらはそれぞれ `OP_SEND` と `OP_SENDB` に似ています。これらは `R[a]` を最初に `self` で初期化するので、それぞれの呼び出しに対して `OP_LOADSELF` 命令を1つスキップすることができます。 ### `OP_SYMBOL` poolに置かれた文字列をシンボルとして取り出します。 ## Changed Instructions ### `OP_SEND` and `OP_SENDB` メソッド呼び出し命令は統一されています。OP_SEND` と `OP_SENDB` (ブロックを使ったメソッドコール) は、splat引数とキーワード引数の両方をサポートすることができるようになりました。 命令の簡単な説明です。 |`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` | |`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` | オペランド C は引数の数を指定します。下位 4 ビット (`n`) は序数引数の数を表し、上位 4 ビット (`nk`) はキーワード引数の数を表します。 n == 15` のとき、このメソッドは配列にパックされた引数を受け取る。nk == 15` のとき、このメソッドはハッシュでパックされたキーワード引数を受け取ります。 ### `OP_ARYPUSH` 2 つのオペランドを受け取り、配列に複数のエントリをプッシュするようになりました。 ## Boxing が更新されました ### Word Boxing MRB_WORD_BOXING` は、デフォルトで `mrb_float` のサイズが `mrb_int` のサイズと同じか小さい場合に、浮動小数点数をワードにpackするようになりました。 mrb_float` と `mrb_int` のサイズが同じ場合、 `mrb_float` の最後の2ビットが切り取られ、フラグとして使用されます。完全な精度が必要な場合は、上記のように `MRB_WORDBOX_NO_FLOAT_TRUNCATE` を定義する必要があります。 ### NaN Boxing 以前の NaN ボクシングは NaN 表現で値をpackしていましたが、ポインタの取り出しは浮動小数点数の参照よりはるかに頻繁です。そこで、NaN表現に定数オフセットを追加し、ポインタ表現の上位ビットをクリアするようにしました。このような表現を”Favor Pointer”NaN Boxingと呼びます。 また、以前のNaNボックスでは、NaN値にフィットするように `mrb_int` のサイズを4バイト(32ビット)に制限していました。現在は、32ビットの範囲に収まらない場合は、Word Boxingと同じようにヒープに整数値を確保します。 ## Constant Folding コードgeneratorを更新し、命令数を削減した。 ``` a = 2 * 5 ``` will be interpreted as ``` a = 10 ``` In addition, we have improved peephole optimizations, for example: ``` GETIV R4 :@foo MOVE R1 R4 ``` to ``` GETIV R1 :@foo ``` ## `String#hash` now use `FNV1a` algorithm For better and faster hash values. --- # Major bug fixes - Fix infinite recursive call bugs in integer division [98799aa6](https://github.com/mruby/mruby/commit/98799aa6) - Fix to raise TypeError with super inside instance_eval / class_eval [#5476](https://github.com/mruby/mruby/pull/5476) - Fix to call `method_added` hooks on method definitions; [#2339](https://github.com/mruby/mruby/pull/2339) - Fix a potential buffer overflow in `time_zonename` [26340a88](https://github.com/mruby/mruby/commit/26340a88) - Fix `Module.instance_eval` bug [#5528](https://github.com/mruby/mruby/pull/5528) - Fix fix `M` packing bug [bfe2bd49](https://github.com/mruby/mruby/commit/bfe2bd49) - Fix a bug regarding attribute assignment with kargs [de2b4bd0](https://github.com/mruby/mruby/commit/de2b4bd0) - Fix SIGSEGV with mrbgems/mruby-method [#5580](https://github.com/mruby/mruby/pull/5580) - Fix print error before cleanup in `codegen_error()` [#5603](https://github.com/mruby/mruby/pull/5603) - Fix a bug in unpacking BER [#5611](https://github.com/mruby/mruby/pull/5611) - Fix a bug with numbered parameters as arguments [#5605](https://github.com/mruby/mruby/pull/5605) - Fix `mrb_ary_shift_m` initialization bug [27d1e013](https://github.com/mruby/mruby/commit/27d1e013) - Fix keyword argument with `super` [#5628](https://github.com/mruby/mruby/pull/5628) - Fix a bug with numbered parameters on toplevel [7e7f1b2f](https://github.com/mruby/mruby/commit/7e7f1b2f) - Fix keyword argument bug [#5632](https://github.com/mruby/mruby/issues/5632) - Fix multiple assignments in parameters [#5647](https://github.com/mruby/mruby/issues/5647) - Fix keyword parameters not passing through super [#5660](https://github.com/mruby/mruby/issues/5660) - Fix infinite loop from unclosed here-doc [#5676](https://github.com/mruby/mruby/issues/5676) - Fix negative integer division bug [#5678](https://github.com/mruby/mruby/issues/5678) # CVEs ## 修正済 CVEs 本リリースでは、以下のCVEを修正しました。 - [CVE-2021-](https://nvd.nist.gov/vuln/detail/CVE-2021-) - [CVE-2021-4110](https://nvd.nist.gov/vuln/detail/CVE-2021-4110) - [CVE-2021-4188](https://nvd.nist.gov/vuln/detail/CVE-2021-4188) - [CVE-2022-0080](https://nvd.nist.gov/vuln/detail/CVE-2022-0080) - [CVE-2022-0240](https://nvd.nist.gov/vuln/detail/CVE-2022-0240) - [CVE-2022-0326](https://nvd.nist.gov/vuln/detail/CVE-2022-0326) - [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481) - [CVE-2022-0631](https://nvd.nist.gov/vuln/detail/CVE-2022-0631) - [CVE-2022-0632](https://nvd.nist.gov/vuln/detail/CVE-2022-0632) - [CVE-2022-0890](https://nvd.nist.gov/vuln/detail/CVE-2022-0890) - [CVE-2022-1071](https://nvd.nist.gov/vuln/detail/CVE-2022-1071) - [CVE-2022-1106](https://nvd.nist.gov/vuln/detail/CVE-2022-1106) - [CVE-2022-1201](https://nvd.nist.gov/vuln/detail/CVE-2022-1201) - [CVE-2022-1427](https://nvd.nist.gov/vuln/detail/CVE-2022-1427) ##影響を受けないCVEsについて 以下のCVEは、本リリースでは問題を起こしません。後のリリースで修正されます。 - [CVE-2022-0481](https://nvd.nist.gov/vuln/detail/CVE-2022-0481) - [CVE-2022-0525](https://nvd.nist.gov/vuln/detail/CVE-2022-0525) - [CVE-2022-0570](https://nvd.nist.gov/vuln/detail/CVE-2022-0570) - [CVE-2022-0614](https://nvd.nist.gov/vuln/detail/CVE-2022-0614) - [CVE-2022-0623](https://nvd.nist.gov/vuln/detail/CVE-2022-0623) - [CVE-2022-0630](https://nvd.nist.gov/vuln/detail/CVE-2022-0630) - [CVE-2022-0717](https://nvd.nist.gov/vuln/detail/CVE-2022-0817) - [CVE-2022-1212](https://nvd.nist.gov/vuln/detail/CVE-2022-1212) - [CVE-2022-1276](https://nvd.nist.gov/vuln/detail/CVE-2022-1276) - [CVE-2022-1286](https://nvd.nist.gov/vuln/detail/CVE-2022-1286) --- mruby 3.0.0 以降、287 個のファイルに対して 1,076 回のコミットを行い、17,188 個の追加と 15,549 個の削除を行いました。更新の詳細については [see Commit Log](https://github.com/mruby/mruby/compare/3.0.0...3.1.0). mruby 3.1.0` のリリースにおいて、バグフィックスと改良に取り組んでくれたすべてのコントリビューターに感謝します。