Yukihiro "Matz" Matsumoto
1974aa0f72
Update Float#to_s to keep trailing zero as CRuby does; ref 68cebb6
2020-11-21 14:38:13 +09:00
KOBAYASHI Shuji
fd113da3aa
Allow bintest even if build name is not host
2020-11-19 11:37:00 +09:00
Yukihiro "Matz" Matsumoto
19450df41e
Integer operation should result in Integer.
...
Should raise `RangeError` if the operation overflows.
2020-11-14 19:38:27 +09:00
KOBAYASHI Shuji
f2d8db39be
Reduce memory usage of Hash object
...
## Implementation Summary
* Change entry list from segmented list to flat array.
* Change value of hash bucket from pointer to entry to index of entry list,
and represent it by variable length bits according to capacity of hash
buckets.
* Store management information about entry list and hash table to `struct
RHash` as much as possible.
## Benchmark Summary
Only the results of typical situations on 64-bit Word-boxing are present
here. For more detailed information, including consideration, see below
(although most of the body is written in Japanese).
* https://shuujii.github.io/mruby-hash-benchmark
### Memory Usage
Lower value is better.
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 344B | 256B | 0.74419x |
| 40 | 1,464B | 840B | 0.57377x |
| 200 | 8,056B | 3,784B | 0.46971x |
| 500 | 17,169B | 9,944B | 0.57949x |
### Performance
Higher value is better.
#### `mrb_hash_set`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 1.41847M i/s | 1.36004M i/s | 0.95881x |
| 40 | 0.39224M i/s | 0.31888M i/s | 0.81296x |
| 200 | 0.03780M i/s | 0.04290M i/s | 1.13494x |
| 500 | 0.01225M i/s | 0.01314M i/s | 1.07275x |
#### `mrb_hash_get`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 26.05920M i/s | 30.19543M i/s | 1.15872x |
| 40 | 44.26420M i/s | 32.75781M i/s | 0.74005x |
| 200 | 44.55171M i/s | 31.56926M i/s | 0.70860x |
| 500 | 39.19250M i/s | 29.73806M i/s | 0.75877x |
#### `mrb_hash_each`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 25.11964M i/s | 30.34167M i/s | 1.20789x |
| 40 | 11.74253M i/s | 13.25539M i/s | 1.12884x |
| 200 | 2.01133M i/s | 2.97214M i/s | 1.47770x |
| 500 | 0.87411M i/s | 1.21178M i/s | 1.38631x |
#### `Hash#[]=`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 0.50095M i/s | 0.56490M i/s | 1.12764x |
| 40 | 0.19132M i/s | 0.18392M i/s | 0.96129x |
| 200 | 0.03624M i/s | 0.03256M i/s | 0.89860x |
| 500 | 0.01527M i/s | 0.01236M i/s | 0.80935x |
#### `Hash#[]`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 11.53211M i/s | 12.78806M i/s | 1.10891x |
| 40 | 15.26920M i/s | 13.37529M i/s | 0.87596x |
| 200 | 15.28550M i/s | 13.36410M i/s | 0.87430x |
| 500 | 14.57695M i/s | 12.75388M i/s | 0.87494x |
#### `Hash#each`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 0.30462M i/s | 0.27080M i/s | 0.88898x |
| 40 | 0.12912M i/s | 0.11704M i/s | 0.90642x |
| 200 | 0.02638M i/s | 0.02402M i/s | 0.91071x |
| 500 | 0.01066M i/s | 0.00959M i/s | 0.89953x |
#### `Hash#delete`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 7.84167M i/s | 6.96419M i/s | 0.88810x |
| 40 | 6.91292M i/s | 7.41427M i/s | 1.07252x |
| 200 | 3.75952M i/s | 7.32080M i/s | 1.94727x |
| 500 | 2.10754M i/s | 7.05963M i/s | 3.34970x |
#### `Hash#shift`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 14.66444M i/s | 13.18876M i/s | 0.89937x |
| 40 | 11.95124M i/s | 11.10420M i/s | 0.92913x |
| 200 | 5.53681M i/s | 7.88155M i/s | 1.42348x |
| 500 | 2.96728M i/s | 5.40405M i/s | 1.82121x |
#### `Hash#dup`
| Hash Size | Baseline | New | Factor |
|----------:|--------------:|--------------:|-----------:|
| 16 | 0.15063M i/s | 5.37889M i/s | 35.71024x |
| 40 | 0.06515M i/s | 3.38196M i/s | 51.91279x |
| 200 | 0.01359M i/s | 1.46538M i/s | 107.84056x |
| 500 | 0.00559M i/s | 0.75411M i/s | 134.88057x |
### Binary Size
Lower value is better.
| File | Baseline | New | Factor |
|:-----------|--------------:|--------------:|----------:|
| mruby | 730,408B | 734,176B | 1.00519x |
| libmruby.a | 1,068,134B | 1,072,846B | 1.00441x |
## Other Fixes
The following issues have also been fixed in the parts where there was some
change this time.
* [Heap use-after-free in `Hash#value?`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-hash-value-md )
* [Heap use-after-free in `ht_hash_equal`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-ht_hash_equal-md )
* [Heap use-after-free in `ht_hash_func`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-ht_hash_func-md )
* [Heap use-after-free in `mrb_hash_merge`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-mrb_hash_merge-md )
* [Self-replacement does not work for `Hash#replace`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-self-replacement-does-not-work-for-hash-replace-md )
* [Repeated deletes and inserts increase memory usage of `Hash`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-repeated-deletes-and-inserts-increase-memory-usage-of-hash-md )
* [`Hash#rehash` does not reindex completely](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-hash-rehash-does-not-reindex-completely-md )
* `mrb_hash_delete_key` does not cause an error for frozen object
* `mrb_hash_new_capa` does not allocate required space first
* [`mrb_os_memsize_of_hash_table` result is incorrect](https://github.com/mruby/mruby/pull/5032#discussion_r457994075 )
2020-11-10 15:21:49 +09:00
Yukihiro "Matz" Matsumoto
dc886873bc
Replace R-assignment by single-line pattern matching.
...
Since `R-assignment` in CRuby is abandoned. Single-line pattern matching
in `mruby` only matches single local variable at the moment. Currently
it works as a right assignment to a local variable. It will be enhanced
in the future.
2020-11-02 15:14:36 +09:00
Yukihiro "Matz" Matsumoto
32ffd81011
Add beginless/endless ranges tests.
2020-10-29 10:43:09 +09:00
Yukihiro "Matz" Matsumoto
6b457d2c00
Merge branch 'work_for_merge' of https://github.com/zubycz/mruby into zubycz-work_for_merge
2020-10-15 18:35:13 +09:00
Yukihiro "Matz" Matsumoto
5b40bb8d15
Avoid using C struct dump for test Ruby code.
...
Files under `test/t` and `mrbgem/*/test` are for tests, not for actual
execution. So symbols in those files need not to be pre-allocated. This
change slightly reduce the memory consumption.
2020-10-14 15:52:14 +09:00
taiyoslime
bec4d05340
Introduce endless range (a part of #5085 )
...
Co-Authored-By: n4o847 <22975590+n4o847@users.noreply.github.com >
Co-Authored-By: smallkirby <ssmallkirby@gmail.com >
2020-10-13 14:09:36 +09:00
Yukihiro "Matz" Matsumoto
2b188ed8a1
Reorganize Integer system.
...
- Integrate `Fixnum` and `Integer`
- Remove `Integral`
- `int / int -> int`
- Replace `mrb_fixnum()` to `mrb_int()`
- Replace `mrb_fixnum_value()` to `mrb_int_value()`.
- Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12 18:19:54 +09:00
Yukihiro "Matz" Matsumoto
04fd7af23c
Fixed ISO section numbers in test/t/superclass.rb.
2020-10-12 16:21:48 +09:00
Yukihiro "Matz" Matsumoto
2a92fb2516
Make division by zero cause ZeroDivisionError.
...
As described in ISO 15.2.30.
2020-10-12 16:21:48 +09:00
KOBAYASHI Shuji
8bd1bc47b3
Always add trailing .0 in Float#inspect; ref #4225
...
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025b . However, I think the more human-readable format is better
for `Float#inspect`.
For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).
```ruby
assert "example" do
exp = 1.0
act = 1
assert_operator(exp, :eql?, act) #=> Expected 1 to be eql? 1.
end
```
2020-10-12 16:21:45 +09:00
dearblue
80fe9838d2
Integrate Fixnum class into Integer class
...
* The `Fixnum` constant is now an alias for the `Integer` class.
* Remove `struct mrb_state::fixnum_class` member.
If necessary, use `struct mrb_state::integer_class` instead.
2020-10-12 16:21:44 +09:00
Yukihiro "Matz" Matsumoto
ed32b6fcdc
Update tests for integer division.
2020-10-12 16:21:43 +09:00
Yukihiro "Matz" Matsumoto
8a87549315
Rename float configuration option names.
...
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`
The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto
6e86e290e4
Rightward-assign by ASSOC.
...
[ruby-bugs:15921]
2020-10-12 16:21:18 +09:00
Yukihiro "Matz" Matsumoto
52507b1083
Generate C struct from irep instead of binary dump.
2020-10-12 16:21:10 +09:00
dearblue
5dc87f77d4
Fixed shift width for MRB_ENV_SET_BIDX()
...
ref c07f24cd1 and close #5035
2020-07-16 23:11:30 +09:00
dearblue
4cd858f93d
Update test/t/kernel.rb
...
- Remove unnecessoury assert
- Fix typo
2020-06-09 20:33:56 +09:00
Mark Delk
3157efa57c
only use GEMNAME if defined in assert.rb
...
Check if the constant GEMNAME is defined before use in `assert.rb`.
This is added to prevent an undefined constant error when using
`assert.rb` in other environments - for example, testing CRuby.
2020-06-08 00:30:46 -05:00
KOBAYASHI Shuji
52ab095ccf
Print exception backtrace if possible without -v in test
...
Backtrace is useful for debugging.
2020-05-29 13:46:16 +09:00
Yusuke Endoh
6f4c585bd7
Do not destruct rest arguments for __send__
...
Formerly, `__send__(*args)` modified `args` with `Array#shift`.
This bug affects optcarrot.
This changeset avoids the array destruction by using
`args = args[1, len-1]`.
2020-05-24 01:25:03 +09:00
dearblue
81c8352179
Integrate class EnsureYieldBreak under test
2020-04-26 21:16:44 +09:00
Yukihiro "Matz" Matsumoto
c181d89c9d
Kernel#clone and Kernel#dup no longer raise TypeError; fix #4974
...
In ISO, those methods should raise `TypeError`, but the spec has been
changed. The change was discussed in [Feature#12979].
2020-04-21 13:21:12 +09:00
Yukihiro "Matz" Matsumoto
364c47610f
Fixed backtrace message for top-level blocks; fix #4936
...
In top-level, `mid` is `NULL`. We used to ignore 'mid` update for `NULL`.
2020-01-27 14:34:54 +09:00
Yukihiro "Matz" Matsumoto
06e09fc7a9
Numbered parameters should not be available in the lambda bodies.
...
`mruby` does not warn like `CRuby` for cases like #4893 .
Fix #4890 , fix #4891 , fix #4893 .
2019-12-21 22:41:32 +09:00
KOBAYASHI Shuji
74f564b0bb
_0 is not numbered parameter
...
#### Before this patch:
```console
$ bin/mruby rb -e '_0=:l; p ->{_0}.()'
-e:1:13: _0 is not available
-e:1:13: syntax error, unexpected $end, expecting '}'
```
#### After this patch (same as Ruby):
```console
$ bin/mruby rb -e '_0=:l; p ->{_0}.()'
:l
```
2019-12-21 18:54:15 +09:00
Yukihiro "Matz" Matsumoto
429f6defdd
Reimplement vformat tests; close #4868
...
Avoid creating `Data` object that refers `mruby` objects.
Also close #4622 ref #4613
2019-12-19 09:35:51 +09:00
Yukihiro "Matz" Matsumoto
7f0e1fc90b
Revert "%C value need not to be saved in TestVFormat::Native; close #4868 "
...
This reverts commit f507ff4842 .
It makes AppVeyor tests fail.
2019-12-19 00:07:08 +09:00
Yukihiro "Matz" Matsumoto
815e0c400a
Merge pull request #4875 from shuujii/remove-location-info-from-Exception-inspect
...
Remove location info from `Exception#inspect`
2019-12-18 01:55:23 +09:00
Yukihiro "Matz" Matsumoto
f507ff4842
%C value need not to be saved in TestVFormat::Native; close #4868
2019-12-18 01:40:11 +09:00
KOBAYASHI Shuji
d2f2f9db51
Remove location info from Exception#inspect
...
Because location info (file name and line number) is kept in the backtrace,
it should not be kept in the result of `inspect` (and the exception object
itself), I think.
### Example
```ruby
# example.rb
begin
raise "err"
rescue => e
p e
end
```
#### Before this patch:
```
$ bin/mruby example.rb
example.rb:2: err (RuntimeError)
```
#### After this patch:
```
$ bin/mruby example.rb
err (RuntimeError)
```
2019-12-14 22:29:37 +09:00
KOBAYASHI Shuji
7192429e83
Fix behavior of Kernel#Integer to numbers ending with _ and spaces
...
#### Before this patch:
```ruby
Integer("1_ ") #=> 1
```
#### After this patch (same as Ruby):
```ruby
Integer("1_ ") #=> ArgumentError
```
2019-12-11 16:40:39 +09:00
KOBAYASHI Shuji
bf431e77b8
Fix behavior of String#to_i/Kernel#Integer to numbers starting with _
...
#### Before this patch:
```ruby
Integer("_1") #=> 1
"_1".to_i #=> 1
```
#### After this patch (same as Ruby):
```ruby
Integer("_1") #=> ArgumentError
"_1".to_i #=> 0
```
2019-12-10 21:31:30 +09:00
Yukihiro "Matz" Matsumoto
543a9f84d1
Merge pull request #4858 from shuujii/fix-that-String-to_f-accepts-consecutive-_-as-a-numeric-expression
...
Fix that `String#to_f` accepts consecutive `_` as a numeric expression
2019-12-10 11:09:55 +09:00
KOBAYASHI Shuji
0893ee492c
Fix that String#to_f accepts consecutive _ as a numeric expression
...
Consecutive `_` is not allowed as a numeric expression:
1_2__3 #=> SyntaxError
Float("1_2__3") #=> ArgumentError
Integer("1_2__3") #=> ArgumentError
"1_2__3".to_i #=> 12
But `String#to_f` accept it, so I fixed the issue.
Before this patch:
"1_2__3".to_f #=> 123
After this patch:
"1_2__3".to_f #=> 12
2019-12-09 21:47:59 +09:00
Yukihiro "Matz" Matsumoto
0011652a28
Support new numbered parameter syntax _1 instead of @1.
2019-12-09 20:50:41 +09:00
Ukrainskiy Sergey
72d57ad094
Implement numbered parameters
2019-12-09 20:50:41 +09:00
KOBAYASHI Shuji
4b14c4633a
Squeeze redundant spaces in test/t/numeric.rb [ci skip]
2019-10-25 19:39:31 +09:00
KOBAYASHI Shuji
7ce5d33947
Integrate mrb_str_inspect and mrb_str_dump
2019-10-10 19:50:48 +09:00
KOBAYASHI Shuji
882bc80dd0
Add tests for #4746
2019-10-03 16:59:18 +09:00
KOBAYASHI Shuji
198683e914
Simplify arguments check in String#rindex
...
Also fix document about type of the first argument.
2019-09-27 17:13:57 +09:00
KOBAYASHI Shuji
549317a36b
Fix Fixnum overflow test in Integer#<< test
...
- Skip when `MRB_WITHOUT_FLOAT` is defined.
- Make `Fixnum` overflow even when `MRB_INT64` is defined.
2019-09-23 21:59:35 +09:00
KOBAYASHI Shuji
e61095426b
Simplify arguments check in String#index
...
Also fix document about type of the first argument.
2019-09-19 20:19:38 +09:00
KOBAYASHI Shuji
2f7175442f
Fix Fixnum#(to_s|inspect) argument specs
...
Before this patch:
$ bin/mruby -e 'p 3.to_s(2)'
trace (most recent call last):
[0] -e:1
-e:1: 'to_s': wrong number of arguments (1 for 0) (ArgumentError)
After this patch:
$ bin/mruby -e 'p 3.to_s(2)'
"11"
2019-09-17 09:28:51 +09:00
Yukihiro "Matz" Matsumoto
04b098d000
Move tests related to getbyte, setbyte, byteslice` to core.
2019-09-11 18:49:08 +09:00
Yukihiro "Matz" Matsumoto
9d08025b8b
Revert part of #4225
...
Since in mruby, Integer and Float interchange frequently (mostly on
overflow), so adding explicit `.0` can cause problems sometimes.
For example:
https://github.com/mattn/mruby-json/pull/40
https://github.com/pepabo/mruby-msd/pull/13
https://github.com/mattn/mruby-json/pull/42
2019-09-07 22:27:30 +09:00
takumakume
6c4278144a
add assert_not_nil method
2019-09-05 19:51:54 +09:00
dearblue
414ab682f3
Add String#rindex test for invalid UTF-8 string
2019-08-17 11:44:27 +09:00