aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
Commit message (Collapse)AuthorAgeFilesLines
* Make env_clone compaction safePeter Zhu2023-12-051-1/+7
| | | | | | | | | | | | | | The original order of events is: 1. Allocate new_body. 2. Peform memcpy into new_body. 3. Create new_env using new_body. However, if GC compaction runs during step 3, then new_env would not have yet been created and objects on new_body could move but it would not be reference updated. This commit changes the order of the last two events.
* Get rid of useless dsize functionsJean Boussier2023-11-211-7/+1
| | | | | If we always return 0, we might as well not define the function at all.
* proc.c: Make Method and UnboundMethod embdedJean Boussier2023-11-201-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoid some needless malloc churn ``` compare-ruby: ruby 3.3.0dev (2023-11-20T02:02:55Z master 701b0650de) [arm64-darwin22] last_commit=[ruby/prism] feat: add encoding for IBM865 (https://github.com/ruby/prism/pull/1884) built-ruby: ruby 3.3.0dev (2023-11-20T16:23:07Z embedded-methods e35284bfaa) [arm64-darwin22] warming up.. | |compare-ruby|built-ruby| |:------------------------|-----------:|---------:| |allocate_method | 8.413M| 12.333M| | | -| 1.47x| |allocate_unbound_method | 8.083M| 11.607M| | | -| 1.44x| ``` ``` prelude: | class SomeClass def foo end end some_object = SomeClass.new benchmark: allocate_method: some_object.method(:foo) allocate_unbound_method: SomeClass.instance_method(:foo) ```
* [Feature #19362] Call `#initialize_dup` hook at `Proc#dup`Nobuyoshi Nakada2023-10-261-1/+11
|
* Make Kernel#lambda raise when given non-literal blockAlan Wu2023-09-121-27/+22
| | | | | | | | | | | | | | | | | Previously, Kernel#lambda returned a non-lambda proc when given a non-literal block and issued a warning under the `:deprecated` category. With this change, Kernel#lambda will always return a lambda proc, if it returns without raising. Due to interactions with block passing optimizations, we previously had two separate code paths for detecting whether Kernel#lambda got a literal block. This change allows us to remove one path, the hack done with rb_control_frame_t::block_code introduced in 85a337f for supporting situations where Kernel#lambda returned a non-lambda proc. [Feature #19777] Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
* Make {Nil,True,False}Class#singleton_method always raise NameErrorJeremy Evans2023-07-261-4/+3
| | | | | | | | {Nil,True,False}Class#singleton_methods always returns [] indicating that there are no singleton methods defined, so #singleton_method should be consistent with that. Fixes [Bug #11064]
* proc.c: Remove unused parameter [ci skip]Alan Wu2023-07-201-5/+5
|
* Store object age in a bitmapMatt Valentine-House2023-07-131-1/+1
| | | | | | | | | | | | | | | | | | Closes [Feature #19729] Previously 2 bits of the flags on each RVALUE are reserved to store the number of GC cycles that each object has survived. This commit introduces a new bit array on the heap page, called age_bits, to store that information instead. This patch still reserves one of the age bits in the flags (the old FL_PROMOTED0 bit, now renamed FL_PROMOTED). This is set to 0 for young objects and 1 for old objects, and is used as a performance optimisation for the write barrier. Fetching the age_bits from the heap page and doing the required math to calculate if the object was old or not would slow down the write barrier. So we keep this bit synced in the flags for fast access.
* Stop exporting symbols for MJITTakashi Kokubun2023-03-061-4/+4
|
* [DOC] Improve Kernel#binding docszverok2023-02-191-7/+35
| | | | | | * Add links to Binding class * Make examples practical * Extend possible usages description
* Encapsulate RCLASS_ATTACHED_OBJECTJean Boussier2023-02-151-5/+3
| | | | | | | | | Right now the attached object is stored as an instance variable and all the call sites that either get or set it have to know how it's stored. It's preferable to hide this implementation detail behind accessors so that it is easier to change how it's stored.
* use correct svar even if env is escapedKoichi Sasada2023-02-101-1/+2
| | | | | | | | This patch is follo-up of 0a82bfe. Without this patch, if env is escaped (Proc'ed), strange svar can be touched. This patch tracks escaped env and use it.
* Merge gc.h and internal/gc.hMatt Valentine-House2023-02-091-1/+1
| | | | [Feature #19425]
* Use rb_gc_mark_and_move for method objectsPeter Zhu2023-02-071-22/+8
|
* Use rb_gc_mark_and_move for proc and bindingPeter Zhu2023-02-071-54/+17
| | | | Also makes VM_ENV_ENVVAL movable.
* Mark "method" objects as protected by write barrierJean Boussier2023-02-031-1/+1
| | | | | All its reference are set with RB_OBJ_WRITE, so they can be marked as WB protected.
* use correct svar (#7225)Koichi Sasada2023-02-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * use correct svar Without this patch, svar location is used "nearest Ruby frame". It is almost correct but it doesn't correct when the `each` method is written in Ruby. ```ruby class C include Enumerable def each %w(bar baz).each{|e| yield e} end end C.new.grep(/(b.)/){|e| p [$1, e]} ``` This patch fix this issue by traversing ifunc's cfp. Note that if cfp doesn't specify this Thread's cfp stack, reserved svar location (`ec->root_svar`) is used. * make yjit-bindgen --------- Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
* Docs: Separate documentation for UnboundMethod#==zverok2022-12-231-2/+18
|
* UnboundMethod only refer defined_classKoichi Sasada2022-12-031-5/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | UnboundMethod records caller's class, like `D` or `E` on the following case: ```ruby class C def foo = :foo end class D < C end class E < C end d = D.instance_method(:foo) e = E.instance_method(:foo) ``` But `d` and `e` only refers `C#foo` so that UnboundMethod doesn't record `D` or `E`. This behavior changes the following methods: * `UnboundMethod#inspect` (doesn't show caller's class) * `UnboundMethod#==` (`d == e` for example) fix https://bugs.ruby-lang.org/issues/18798
* Using UNDEF_P macroS-H-GAMELINKS2022-11-161-6/+6
|
* Use RTEST to to check return valuePeter Zhu2022-11-041-1/+1
| | | | | rb_obj_is_kind_of returns a Ruby Qtrue or Qfalse. We should use RTEST rather than assuming that Qfalse is 0.
* Remove unnecessary branch in `UnboundMethod#bind`Alexander Momchilov2022-11-041-2/+1
| | | | Co-authored-by: Michael Herold <michael.herold@shopify.com>
* Mark struct METHOD->owner for the GCBenoit Daloze2022-10-031-0/+2
| | | | | * Fixes https://github.com/ruby/ruby/commit/6b7d32a5e5 * See [Bug #18729]
* Reduce diff to proc.c @ b0b9f7201acab05c2a3ad92c3043a1f01df3e17fBenoit Daloze2022-09-291-47/+29
| | | | | | * So it's easy to review https://github.com/ruby/ruby/pull/6242 + https://github.com/ruby/ruby/pull/6467 and there are less changes overall.
* Resolve zsuper method during lookup but preserve owner separatelyBenoit Daloze2022-09-291-50/+59
| | | | | * See https://bugs.ruby-lang.org/issues/18729#note-34 * See [Bug #18729]
* Fix {Method,UnboundMethod}#super_method for zsuper methodsBenoit Daloze2022-09-291-12/+13
| | | | | * We need to resolve the zsuper method first, and then look the super method of that.
* Rework vm_core to use `int first_lineno` struct member.Samuel Williams2022-09-261-3/+3
|
* Reuse rb_method_call_kw functionS-H-GAMELINKS2022-09-251-2/+1
|
* Adjust styles [ci skip]Nobuyoshi Nakada2022-09-021-1/+2
|
* Consider resolved-through-zsuper methods equal for compatibilityBenoit Daloze2022-08-201-34/+31
| | | | * Fixes https://bugs.ruby-lang.org/issues/18751
* Make Object#method and Module#instance_method not skip ZSUPER methodsJeremy Evans2022-08-201-17/+46
| | | | | | | | | | | | | | | | | | | | | | | Based on https://github.com/jeremyevans/ruby/commit/c95e7e5329140f640b6497905485761f3336d967 Among other things, this fixes calling visibility methods (public?, protected?, and private?) on them. It also fixes #owner to show the class the zsuper method entry is defined in, instead of the original class it references. For some backwards compatibility, adjust #parameters and #source_location, to show the parameters and source location of the method originally defined. Also have the parameters and source location still be shown by #inspect. Clarify documentation of {Method,UnboundMethod}#owner. Add tests based on the description of https://bugs.ruby-lang.org/issues/18435 and based on https://github.com/ruby/ruby/pull/5356#issuecomment-1005298809 Fixes [Bug #18435] [Bug #18729] Co-authored-by: Benoit Daloze <eregontp@gmail.com>
* Do not clone method entries when bind_call is usedPenelope Phippen2022-08-151-4/+14
| | | | | | | | | | | | | | | I noticed that this site unconditionally clones the method entry, which means that `bind_call` always allocates a `T_IMEMO`. While this clone is necessary for `bind`, it is not necessary for `bind_call`. I work at Stripe, and the sorbet_runtime gem uses bind call as part of it's [call validation](https://github.com/sorbet/sorbet/blob/master/gems/sorbet-runtime/lib/types/private/methods/call_validation.rb#L157) so this can save us a lot of allocations. This patch adds a `clone` parameter to `convert_umethod_to_method_components`, which then controls whether or not we do this cloning. This patch passed Stripe CI and works in our QA environment. I reviewed it with @tenderlove to talk about correctness also.
* Revert "Add {Method,UnboundMethod}#{public?,private?,protected?}"Jeremy Evans2022-08-101-59/+1
| | | | | | | | | | | | This reverts commit 27278150685e738f84105d09843d3ba371146c7a and 58dc8bf8f15df9a33d191074e8a5d4946a3d59d5. Visibility is an attribute of the method entry in a class, not an attribute of the Method object. Fixes [#18729] Fixes [#18751] Fixes [#18435]
* Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu2022-07-261-1/+1
| | | | | | rb_ary_tmp_new suggests that the array is temporary in some way, but that's not true, it just creates an array that's hidden and not on the transient heap. This commit renames it to rb_ary_hidden_new.
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-364/+364
| | | | [Misc #18891]
* Reuse `rb_proc_arity`S.H2022-04-241-7/+2
|
* [DOC] Move the documentations of moved Symbol methodsNobuyoshi Nakada2022-04-141-0/+15
|
* Fix a typo [ci skip]Kazuhiro NISHIYAMA2022-04-061-1/+1
|
* Make define_singleton_method always define a public methodJeremy Evans2022-03-291-50/+58
| | | | | | | In very unlikely cases, it could previously define a non-public method starting in Ruby 2.1. Fixes [Bug #18561]
* Add ISEQ_BODY macroPeter Zhu2022-03-241-16/+16
| | | | | | Use ISEQ_BODY macro to get the rb_iseq_constant_body of the ISeq. Using this macro will make it easier for us to change the allocation strategy of rb_iseq_constant_body when using Variable Width Allocation.
* Encourage arity argument in Proc#curry documentation for procs with variable ↵Jeremy Evans2022-03-171-0/+4
| | | | | | arguments This uses similar language to that used in Method#curry.
* Make Proc#parameters support lambda keyword for returning parameters as if ↵Jeremy Evans2022-03-171-6/+33
| | | | | | | | lambda This makes it easier to use Proc#parameters to build wrappers. Implements [Feature #15357]
* [DOC] Fix broken links to literals.rdocNobuyoshi Nakada2022-02-081-1/+1
|
* Fix {Method,UnboundMethod}#{public?,private?,protected?} for ZSUPER methodsJeremy Evans2022-01-141-4/+11
| | | | | | | | | | | | Add a visibility member to struct METHOD storing the original method visibility, and use that, instead of taking the visibility from the stored method entry (which may have different visibility for ZSUPER methods). Consider Method/UnboundMethod objects different if they have different visibilities. Fixes [Bug #18435]
* Negative RBOOL usageNobuyoshi Nakada2022-01-011-1/+1
|
* Add support for anonymous rest and keyword rest argument forwardingJeremy Evans2021-12-301-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows for the following syntax: ```ruby def foo(*) bar(*) end def baz(**) quux(**) end ``` This is a natural addition after the introduction of anonymous block forwarding. Anonymous rest and keyword rest arguments were already supported in method parameters, this just allows them to be used as arguments to other methods. The same advantages of anonymous block forwarding apply to rest and keyword rest argument forwarding. This has some minor changes to #parameters output. Now, instead of `[:rest], [:keyrest]`, you get `[:rest, :*], [:keyrest, :**]`. These were already used for `...` forwarding, so I think it makes it more consistent to include them in other cases. If we want to use `[:rest], [:keyrest]` in both cases, that is also possible. I don't think the previous behavior of `[:rest], [:keyrest]` in the non-... case and `[:rest, :*], [:keyrest, :**]` in the ... case makes sense, but if we did want that behavior, we'll have to make more substantial changes, such as using a different ID in the ... forwarding case. Implements [Feature #18351]
* Fix typosKazuhiro NISHIYAMA2021-12-211-3/+3
|
* fix Struct's setter arityKoichi Sasada2021-12-131-1/+1
| | | | https://github.com/ruby/ruby/pull/5131/files#diff-b2553d23e6b1fe76e20608d06c25f6acca06279100f1a9c24febcd79a82fac3cR2689
* Struct setter's parameters == `[:req, :_]`Koichi Sasada2021-12-131-6/+65
| | | | | | | fix [Bug #18405] Note that the parameter name `_` is not a spec, so we shouldn't rely on this behavior.
* add `method_def_aritry()`Koichi Sasada2021-12-131-7/+11
|