aboutsummaryrefslogtreecommitdiffstats
path: root/internal.h
Commit message (Collapse)AuthorAgeFilesLines
* Consolidate empty keyword handlingJeremy Evans2019-09-131-1/+0
| | | | | | | | | | | | | | | | | | | | | | Remove rb_add_empty_keyword, and instead of calling that every place you need to add empty keyword hashes, run that code in a single static function in vm_eval.c. Add 4 defines to include/ruby/ruby.h, these are to be used as int kw_splat values when calling the various rb_*_kw functions: RB_NO_KEYWORDS :: Do not pass keywords RB_PASS_KEYWORDS :: Pass final argument (which should be hash) as keywords RB_PASS_EMPTY_KEYWORDS :: Add an empty hash to arguments and pass as keywords RB_PASS_CALLED_KEYWORDS :: Passes same keyword type as current method was called with (for method delegation) rb_empty_keyword_given_p needs to stay. It is required if argument delegation is done but delayed to a later point, which Enumerator does. Use RB_PASS_CALLED_KEYWORDS in rb_call_super to correctly delegate keyword arguments to super method.
* Fixed GCC version for diagnostic-pragmasNobuyoshi Nakada2019-09-101-2/+2
| | | | "GCC diagnostic push/pop" seems appeared at gcc 4.6.
* Convert keyword argument to required positional hash argument for Class#new, ↵Jeremy Evans2019-09-061-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Method#call, UnboundMethod#bind_call Also add keyword argument separation warnings for Class#new and Method#call. To allow for keyword argument to required positional hash converstion in cfuncs, add a vm frame flag indicating the cfunc was called with an empty keyword hash (which was removed before calling the cfunc). The cfunc can check this frame flag and add back an empty hash if it is passing its arguments to another Ruby method. Add rb_empty_keyword_given_p function for checking if called with an empty keyword hash, and rb_add_empty_keyword for adding back an empty hash to argv. All of this empty keyword argument support is only for 2.7. It will be removed in 3.0 as Ruby 3 will not convert empty keyword arguments to required positional hash arguments. Comment all of the relevent code to make it obvious this is expected to be removed. Add rb_funcallv_kw as an public C-API function, just like rb_funcallv but with a keyword flag. This is used by rb_obj_call_init (internals of Class#new). This also required expected call_type enum with CALL_FCALL_KW, similar to the recent addition of CALL_PUBLIC_KW. Add rb_vm_call_kw as a internal function, used by call_method_data (internals of Method#call and UnboundMethod#bind_call). Add tests for UnboundMethod#bind_call keyword handling.
* Make Symbol#to_proc calls handle keyword argumentsJeremy Evans2019-09-051-1/+1
| | | | | | Make rb_sym_proc_call take a flag for whether a keyword argument is used, and use the new rb_funcall_with_block_kw function to pass that information.
* hide rb_funcallv_with_cc from public卜部昌平2019-09-051-0/+52
| | | | | | Requested by ko1. Also, because now that this function is internal use only, why not just directly use struct rb_call_cache to purge the ZALLOC.
* Set symbol export for rb_hash_stlike_foreachJeremy Evans2019-08-301-0/+2
| | | | This fixes MJIT after rb_hash_stlike_foreach used vm_args.c.
* Allow ** syntax to be used for calling methods that do not accept keywordsJeremy Evans2019-08-301-1/+0
| | | | | | | | Treat the ** syntax as passing a copy of the hash as the last positional argument. If the hash being double splatted is empty, do not add a positional argument. Remove rb_no_keyword_hash, no longer needed.
* Separate keyword arguments from positional argumentsYusuke Endoh2019-08-301-0/+1
| | | | And, allow non-symbol keys as a keyword arugment
* rb_uninterruptible now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This function has only one call site so adding appropriate prototype is trivial.
* struct MEMO now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. There is only one usage of MEMO::u3::func in load.c (where void Init_Foobar(vodi) is registered) so why not just be explicit.
* rb_hash_foreach now free from ANYARGS卜部昌平2019-08-271-2/+2
| | | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit adds function prototypes for rb_hash_foreach / st_foreach_safe. Also fixes some prototype mismatches.
* rb_ensure now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
* decouple compile.c usage of imemo_ifunc卜部昌平2019-08-271-3/+3
| | | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from struct vm_ifunc, but in doing so we also have to decouple the usage of this struct in compile.c, which (I think) is an abuse of ANYARGS.
* delete rb_method_defined_by declaration.卜部昌平2019-08-271-1/+0
| | | | Ko1 missed this in d5893b91faa7dc77ca6c9728d1054dabd757aead.
* `rp(obj)` shows func, file and line. (#2394)Koichi Sasada2019-08-211-2/+4
| | | | | | rp() macro for debug also shows file location and function name such as: [OBJ_INFO:rb_call_inits@inits.c:73] 0x000056147741b248 ...
* Renamed ruby_finalize_{0,1}Nobuyoshi Nakada2019-08-131-1/+0
| | | | And pass rb_execution_context_t as an argument.
* Expanded f_quoNobuyoshi Nakada2019-08-101-0/+1
|
* add rp() and bp() in internal.h.Koichi Sasada2019-08-091-0/+16
| | | | | | | | debug utility macro rp() (rp_m()) and bp() are introduced. * rp(obj) shows obj information w/o any side-effect to STDERR. * rp_m(m, obj) is similar to rp(obj), but show m before. * bp() is alias of ruby_debug_breakpoint(), which is registered as a breakpoint in run.gdb (used by `make gdb` or make gdb-ruby`).
* introduce RCLASS_CLONED flag for inline cache.Koichi Sasada2019-08-091-0/+1
| | | | | | | | | Methods on duplicated class/module refer same constant inline cache (IC). Constant access lookup should be done for cloned class/modules but inline cache doesn't check it. To check it, this patch introduce new RCLASS_CLONED flag which are set when if class/module is cloned (both orig and dst). [Bug #15877]
* leafify opt_plus卜部昌平2019-08-061-0/+1
| | | | | | Inspired by 346aa557b31fe96760e505d30da26eb7a846bac9 Closes: https://github.com/ruby/ruby/pull/2321
* Make opt_eq and opt_neq insns leafTakashi Kokubun2019-08-041-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | # Benchmark zero? ``` require 'benchmark/ips' Numeric.class_eval do def ruby_zero? self == 0 end end Benchmark.ips do |x| x.report('0.zero?') { 0.ruby_zero? } x.report('1.zero?') { 1.ruby_zero? } x.compare! end ``` ## VM No significant impact for VM. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) [x86_64-linux] 0.zero?: 21855445.5 i/s 1.zero?: 21770817.3 i/s - same-ish: difference falls within error ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) [x86_64-linux] 1.zero?: 21958912.3 i/s 0.zero?: 21881625.9 i/s - same-ish: difference falls within error ## JIT The performance improves about 1.23x. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) +JIT [x86_64-linux] 0.zero?: 36343111.6 i/s 1.zero?: 36295153.3 i/s - same-ish: difference falls within error ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) +JIT [x86_64-linux] 0.zero?: 44740467.2 i/s 1.zero?: 44363616.1 i/s - same-ish: difference falls within error # Benchmark str == str / str != str ``` # frozen_string_literal: true require 'benchmark/ips' Benchmark.ips do |x| x.report('a == a') { 'a' == 'a' } x.report('a == b') { 'a' == 'b' } x.report('a != a') { 'a' != 'a' } x.report('a != b') { 'a' != 'b' } x.compare! end ``` ## VM No significant impact for VM. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) [x86_64-linux] a == a: 27286219.0 i/s a != a: 24892389.5 i/s - 1.10x slower a == b: 23623635.8 i/s - 1.16x slower a != b: 21800958.0 i/s - 1.25x slower ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) [x86_64-linux] a == a: 27224016.2 i/s a != a: 24490109.5 i/s - 1.11x slower a == b: 23391052.4 i/s - 1.16x slower a != b: 21811321.7 i/s - 1.25x slower ## JIT The performance improves on JIT a little. ### before ruby 2.7.0dev (2019-08-04T02:56:02Z master 2d8c037e97) +JIT [x86_64-linux] a == a: 42010674.7 i/s a != a: 38920311.2 i/s - same-ish: difference falls within error a == b: 32574262.2 i/s - 1.29x slower a != b: 32099790.3 i/s - 1.31x slower ### after ruby 2.7.0dev (2019-08-04T11:17:10Z opt-eq-leaf 6404bebd6a) +JIT [x86_64-linux] a == a: 46902738.8 i/s a != a: 43097258.6 i/s - 1.09x slower a == b: 35822018.4 i/s - 1.31x slower a != b: 33377257.8 i/s - 1.41x slower This is needed towards Bug#15589. Closes: https://github.com/ruby/ruby/pull/2318
* Expanded f_ceilNobuyoshi Nakada2019-08-021-0/+1
|
* introduce ar_hint_t.Koichi Sasada2019-08-011-2/+10
| | | | | Hash hint for ar_array is 1 byte (unsigned char). This patch introduce ar_hint_t which represents hint type.
* move macro to internal.h for documentation.Koichi Sasada2019-07-311-0/+4
| | | | | | 13e84d5c0a changes enum to macro, but the flags usage information are lost in internal.h. It should be same place with other flags information.
* Moved RHASH_LEV_MASK and turned into a macroNobuyoshi Nakada2019-07-311-2/+0
| | | | | Get rid of "ISO C restricts enumerator values to range of 'int'" error.
* Use 1 byte hint for ar_table [Feature #15602]Koichi Sasada2019-07-311-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On ar_table, Do not keep a full-length hash value (FLHV, 8 bytes) but keep a 1 byte hint from a FLHV (lowest byte of FLHV). An ar_table only contains at least 8 entries, so hints consumes 8 bytes at most. We can store hints in RHash::ar_hint. On 32bit CPU, we use 4 entries ar_table. The advantages: * We don't need to keep FLHV so ar_table only consumes 16 bytes (VALUEs of key and value) * 8 entries = 128 bytes. * We don't need to scan ar_table, but only need to check hints in many cases. Especially we don't need to access ar_table if there is no match entries (in many cases). It will increase memory cache locality. The disadvantages: * This technique can increase `#eql?` time because hints can conflicts (in theory, it conflicts once in 256 times). It can introduce incompatibility if there is a object x where x.eql? returns true even if hash values are different. I believe we don't need to care such irregular case. * We need to re-calculate FLHV if we need to switch from ar_table to st_table (e.g. exceeds 8 entries). It also can introduce incompatibility, on mutating key objects. I believe we don't need to care such irregular case too. Add new debug counters to measure the performance: * artable_hint_hit - hint is matched and eql?#=>true * artable_hint_miss - hint is not matched but eql?#=>false * artable_hint_notfound - lookup counts
* remove RHash::iter_lev.Koichi Sasada2019-07-311-8/+14
| | | | | | | | | | | | | | | iter_lev is used to detect the hash is iterating or not. Usually, iter_lev should be very small number (1 or 2) so `int` is overkill. This patch introduce iter_lev in flags (7 bits, FL13 to FL19) and if iter_lev exceeds this range, save it in hidden attribute. We can get 1 word in RHash. We can't modify frozen objects. Therefore I added new internal API `rb_ivar_set_internal()` which allows us to set an attribute even if the target object is frozen if the name is hidden ivar (the name without `@` prefix).
* Reuse match dataNobuyoshi Nakada2019-07-281-0/+1
| | | | * string.c (rb_str_split_m): reuse occupied match data. [Bug #16024]
* constify again.Koichi Sasada2019-07-221-12/+12
| | | | | | | | | | | | | | | | | | | | Same as last commit, make some fields `const`. include/ruby/ruby.h: * Rasic::klass * RArray::heap::aux::shared_root * RRegexp::src internal.h: * rb_classext_struct::origin_, redefined_class * vm_svar::cref_or_me, lastline, backref, others * vm_throw_data::throw_obj * vm_ifunc::data * MEMO::v1, v2, u3::value While modifying this patch, I found write-barrier miss on rb_classext_struct::redefined_class. Also vm_throw_data::throw_state is only `int` so change the type.
* constify RHash::ifnone.Koichi Sasada2019-07-221-1/+1
| | | | | | | RHash::ifnone should be protected by write-barriers so this field should be const. However, to introduce GC.compact, the const was removed. This commit revert this removing `const` and modify gc.c `TYPED_UPDATE_IF_MOVED` to remove `const` forcely by a type cast.
* Moved the check for `exception` to rb_execarg_addoptNobuyoshi Nakada2019-07-161-0/+1
| | | | | | Check for `exception` option in rb_execarg_addopt, as well as other options. And then raise a particular ArgumentError if it is not allowed.
* Expanded f_numeratorNobuyoshi Nakada2019-07-161-0/+1
|
* Expanded f_denominatorNobuyoshi Nakada2019-07-161-0/+1
|
* respect RUBY_DEBUG.Koichi Sasada2019-07-151-1/+1
| | | | see RUBY_DEBUG for each debug options.
* socket: use frozen string buffer when releasing GVLTanaka Akira2019-07-141-2/+2
| | | | Thanks for the patch by normalperson (Eric Wong) [Bug #14204].
* Check exception flag as a bool [Bug #15987]Nobuyoshi Nakada2019-07-111-0/+4
|
* Use rb_ident_hash_new instead of rb_hash_new_compare_by_idNobuyoshi Nakada2019-07-031-3/+0
| | | | The latter is same as the former, removed the duplicate function.
* Turned `recur` into `int` [Feature #15777]Nobuyoshi Nakada2019-06-211-1/+1
|
* Add an optional `inherit` argument to Module#autoload?Jean Boussier2019-06-211-0/+1
| | | | | | [Feature #15777] Closes: https://github.com/ruby/ruby/pull/2173
* Make opt_aref instruction support Integer#[]Yusuke Endoh2019-06-011-0/+1
| | | | | | | | | | | | only when its receiver and the argument are both Integers. Since 6bedbf4625, Integer#[] has supported a range extraction. This means that Integer#[] now accepts multiple arguments, which made the method very slow unfortunately. This change fixes the performance issue by adding a special handling for its traditional use case: `num[idx]` where both `num` and `idx` are Integers.
* Use UNALIGNED_MEMBER_PTRNobuyoshi Nakada2019-05-311-0/+17
| | | | | | | | | | | * internal.h (UNALIGNED_MEMBER_ACCESS, UNALIGNED_MEMBER_PTR): moved from eval_intern.h. * compile.c iseq.c, vm.c: use UNALIGNED_MEMBER_PTR for `entries` in `struct iseq_catch_table`. * vm_eval.c, vm_insnhelper.c: use UNALIGNED_MEMBER_PTR for `body` in `rb_method_definition_t`.
* Fix Possible Control flow issues (DEADCODE)Kazuhiro NISHIYAMA2019-05-291-0/+8
| | | | | Coverity Scan says `Execution cannot reach this statement: "poison_object(v);"`, so do nothing when `ptr` is always 0 without address_sanitizer.
* Fix typos [ci skip]Kazuhiro NISHIYAMA2019-05-241-2/+2
|
* Suppress paranoid warnings for external/3rd-party librariesNobuyoshi Nakada2019-05-231-4/+4
| | | | [Feature #15665]
* add comments [ci skip]Urabe, Shyouhei2019-05-231-0/+46
| | | | Also requested by Ko1.
* prefix ASAN related inline functions asan_Urabe, Shyouhei2019-05-231-13/+10
| | | | requested by Ko1.
* Fixing function nameAaron Patterson2019-05-141-1/+1
| | | | | This function is used for marking / pinning vm stack values, so it should have "vm" in the function name to be more clear.
* turn T_MOVED in to a linked listAaron Patterson2019-05-131-0/+1
|
* guard include with has_featureNARUSE, Yui2019-05-011-1/+3
| | | | | clang's sanitizer/msan_interface.h has fallback macros. It causes redefinition of __msan_unpoison().
* use __attribute__((__no_sanitize__("memory")))Urabe, Shyouhei2019-04-261-8/+11
|