Граф коммитов

580 Коммитов

Автор SHA1 Сообщение Дата
Tomás Coêlho 1ee8d4b0ac Fix typo on Proc docs 2020-11-16 12:38:10 -05:00
Aaron Patterson 67b2c21c32
Add `GC.auto_compact= true/false` and `GC.auto_compact`
* `GC.auto_compact=`, `GC.auto_compact` can be used to control when
  compaction runs.  Setting `auto_compact=` to true will cause
  compaction to occurr duing major collections.  At the moment,
  compaction adds significant overhead to major collections, so please
  test first!

[Feature #17176]
2020-11-02 14:42:48 -08:00
Koichi Sasada 07c03bc309 check isolated Proc more strictly
Isolated Proc prohibit to access outer local variables, but it was
violated by binding and so on, so they should be error.
2020-10-29 23:42:55 +09:00
Chris Seaton fef52122b0 Use proc_binding rather than rb_funcall
FIX
2020-10-06 15:41:47 -07:00
Nobuyoshi Nakada 68d24bc045
Moved rb_callable_receiver internal 2020-10-06 10:11:51 +09:00
Chris Seaton 8e173d8b27 Warn on a finalizer that captures the object to be finalized
Also improve specs and documentation for finalizers and more clearly
recommend a safe code pattern to use them.
2020-09-16 13:52:24 -07:00
Jeremy Evans c60aaed185
Fix Method#super_method for aliased methods
Previously, Method#super_method looked at the called_id to
determine the method id to use, but that isn't correct for
aliased methods, because the super target depends on the
original method id, not the called_id.

Additionally, aliases can reference methods defined in other
classes and modules, and super lookup needs to start in the
super of the defined class in such cases.

This adds tests for Method#super_method for both types of
aliases, one that uses VM_METHOD_TYPE_ALIAS and another that
does not.  Both check that the results for calling super
methods return the expected values.

To find the defined class for alias methods, add an rb_ prefix
to find_defined_class_by_owner in vm_insnhelper.c and make it
non-static, so that it can be called from method_super_method
in proc.c.

This bug was original discovered while researching [Bug #11189].

Fixes [Bug #17130]
2020-08-27 08:37:03 -07:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 2bfac015d3 proc_binding: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 3db159193e rb_obj_singleton_method: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 8b9b51bb3b rb_method_name_error: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 2390a8bd2e bind_local_variable_get: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada d1af2345c9
Removed space lines 2020-06-20 14:07:45 +09:00
Kazuki Tsujimoto e8b2578d31
Remove unused variables 2020-06-20 11:11:50 +09:00
Jeremy Evans 878af5147d Implement Proc#== and #eql?
Previously, these were not implemented, and Object#== and #eql?
were used.  This tries to check the proc internals to make sure
that procs created from separate blocks are treated as not equal,
but procs created from the same block are treated as equal, even
when the lazy proc allocation optimization is used.

Implements [Feature #14267]
2020-06-19 12:58:25 -07:00
卜部昌平 af6e63a9df rb_method_name_error: delete unused code
If you look at the code flow (break -> goto), this assignment never
makes any sense.  Should just remove.

I _guess_ this behaviour is unintended.  Original code at commit
4dc1a21809 did something.  It might be
the code flow that is buggy.  However rubyspec already includes this
particular edge case at ruby/core/module/undef_method_spec.rb.  I don't
think we can change the way it is any longer.
2020-06-17 10:06:01 +09:00
Jeremy Evans 2188d6d160 Warn when passing a non-literal block to Kernel#lambda
Implements [Feature #15973]
2020-06-11 07:30:48 -07:00
Jeremy Evans f3e927b0cc Make proc/Proc.new without block an error instead of warning
The warning for these was added in 2.7.
2020-06-10 17:49:54 -07:00
Jeremy Evans ad0eccf840
Work around infinite loop when overriding method visibility in prepended module (#3201)
For ZSUPER methods with no defined class for the method entry, start the next lookup at the superclass of the origin class of the method owner, instead of the superclass of the method owner.

Fixes [Bug #16942]
2020-06-09 16:30:55 -07:00
Nobuyoshi Nakada cf90df22c7
[DOC] Separated Method#[] from Method#call [Bug #16813] [ci skip] 2020-04-24 11:18:27 +09:00
Nobuyoshi Nakada ac2106acc2
[DOC] Fixed explanation for Method#>> [Bug #16813] [ci skip] 2020-04-24 11:16:19 +09:00
Nobuyoshi Nakada e474c189da
Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
Jeremy Evans adecd43197
Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188
Correctly show defined class for aliases of aliases
2020-03-22 09:30:20 -07:00
Yusuke Endoh d514ba8e17 `Proc` made by `Hash#to_proc` should be a lambda [Bug #12671]
Like `Symbol#to_proc` (f0b815dc67)
2020-03-16 23:38:26 +09:00
Yusuke Endoh 47141797be hash.c: Do not use the fast path (rb_yield_values) for lambda blocks
As a semantics, Hash#each yields a 2-element array (pairs of keys and
values).  So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception
due to lambda's arity check.
However, the optimization that avoids Array allocation by using
rb_yield_values for blocks whose arity is more than 1 (introduced at
b9d2960337 and some commits), seemed to
overlook the lambda case, and wrongly allowed the code above to work.

This change experimentally attempts to make it strict; now the code
above raises an ArgumentError.  This is an incompatible change; if the
compatibility issue is bigger than our expectation, it may be reverted
(until Ruby 3.0 release).

[Bug #12706]
2020-03-16 23:17:12 +09:00
Yusuke Endoh ad10760b05 proc.c: Remove non-sense /* fall through */ 2020-03-16 11:01:08 +09:00
Jeremy Evans e02bd0e713
Don't display singleton class in Method#inspect unless method defined there
Previously, if an object has a singleton class, and you call
Object#method on the object, the resulting string would include
the object's singleton class, even though the method was not
defined in the singleton class.

Change this so the we only show the singleton class if the method
is defined in the singleton class.

Fixes [Bug #15608]
2020-03-09 07:57:16 -07:00
Nobuyoshi Nakada 5b29ea0845
Proc from Symbol needs a receiver
So its arity should be -2 instead of -1.

[Bug #16640]
https://bugs.ruby-lang.org/issues/16640#change-84337
2020-02-22 10:49:59 +09:00
Nobuyoshi Nakada 8c5ca318cb
`Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]
With refinements, too.
2020-02-22 00:45:05 +09:00
Nobuyoshi Nakada f0b815dc67
`Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260] 2020-02-19 15:46:26 +09:00
Nobuyoshi Nakada e3e96e3faa
Check if bindable against the refined target [Bug #16617] 2020-02-09 20:13:49 +09:00
Florian Heinle 39a1959d28 Fix wrong return value in proc documentation. 2020-01-30 12:35:15 -08:00
0x005c 461db352c2 Rename RUBY_MARK_NO_PIN_UNLESS_NULL to RUBY_MARK_MOVABLE_UNLESS_NULL 2020-01-23 00:11:03 +13:00
Jeremy Evans beae6cbf0f Fully separate positional arguments and keyword arguments
This removes the warnings added in 2.7, and changes the behavior
so that a final positional hash is not treated as keywords or
vice-versa.

To handle the arg_setup_block splat case correctly with keyword
arguments, we need to check if we are taking a keyword hash.
That case didn't have a test, but it affects real-world code,
so add a test for it.

This removes rb_empty_keyword_given_p() and related code, as
that is not needed in Ruby 3.  The empty keyword case is the
same as the no keyword case in Ruby 3.

This changes rb_scan_args to implement keyword argument
separation for C functions when the : character is used.
For backwards compatibility, it returns a duped hash.
This is a bad idea for performance, but not duping the hash
breaks at least Enumerator::ArithmeticSequence#inspect.

Instead of having RB_PASS_CALLED_KEYWORDS be a number,
simplify the code by just making it be rb_keyword_given_p().
2020-01-02 18:40:45 -08:00
Alan Wu 99c7b0b7ea
Decide lambdaness of (f << g) using g (#2729)
* Deciding lambdaness of (f << g) using g

* Use version guards for spec changes
2019-12-30 17:47:58 -05:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
卜部昌平 989068cf70 internal/imemo.h rework
Arrange contents and eliminate macros, to make them readable.

Macro IFUNC_NEW was deleted because there was only one usage.
2019-12-26 20:45:12 +09:00
Alan Wu ade6543f4c
Adjust sentence in doc [ci skip] 2019-12-22 18:21:13 -05:00
zverok 5fa9c2eeb0 Actualize Method#inspect docs 2019-12-22 23:17:39 +09:00
zverok 03b983d54c Document numbered block parameters 2019-12-22 23:15:29 +09:00
Alan Wu 85a337f986 Kernel#lambda: return forwarded block as non-lambda proc
Before this commit, Kernel#lambda can't tell the difference between a
directly passed literal block and one passed with an ampersand.

A block passed with an ampersand is semantically speaking already a
non-lambda proc. When Kernel#lambda receives a non-lambda proc, it
should simply return it.

Implementation wise, when the VM calls a method with a literal block, it
places the code for the block on the calling control frame and passes a
pointer (block handler) to the callee. Before this commit, the VM
forwards block arguments by simply forwarding the block handler, which
leaves the slot for block code unused when a control frame forwards its
block argument. I use the vacant space to indicate that a frame has
forwarded its block argument and inspect that in Kernel#lambda to detect
forwarded blocks.

This is a very ad-hoc solution and relies *heavily* on the way block
passing works in the VM. However, it's the most self-contained solution
I have.

[Bug #15620]
2019-12-21 09:08:52 -05:00
Nobuyoshi Nakada c6c67254fb
Added rb_warn_deprecated 2019-12-19 09:52:17 +09:00
Jeremy Evans f45c0dc239 Add Proc#ruby2_keywords
This allows passing keywords through a normal argument splat in a
Proc.  While needing ruby2_keywords support for methods is more
common, there is code that delegates keywords through normal
argument splats in procs, including code in Rails.  For that
reason, it makes sense to expose this for procs as well.

Internally, ruby2_keywords is not tied to methods, but iseqs,
so this just allows for setting the ruby2_keywords for the iseq
related to the proc.
2019-12-09 17:10:19 +02:00
Jeremy Evans a91637c516 Make {Method,UnboundMethod}#super_method handle clone/bind/unbind
This wasn't working previously because the iclass entry wasn't
being copied, and without an iclass entry, super_method returns
nil.

Fixes [Bug #15629]
2019-12-04 01:35:34 +02:00
Paweł Przeniczny ce50af21af Fix the docs for Proc#>>.
The docs are wrong about the behaviour of `#>>` (looks like it was copied from `#<<`)
In `(prc >> g).call(n)` _prc_ is called first (with _n_), *then* _g_ is called with the result.

Code examples are OK.
2019-11-25 09:19:15 +09:00
Nobuyoshi Nakada 9b52bacc62
Refined inspection of argument forwarding 2019-11-21 02:18:13 +09:00
zverok 50cc934145 Update representation (discussed on ruby tracker) 2019-11-20 13:42:56 +09:00
zverok 4b583cff97 Method parameters inspect
Example:

    def m(a, b=nil, *c, d:, e: nil, **rest, &block)
    end
    p method(:m)
    #=> #<Method: m(a, b=<default>, *c, d:, e: <default>, **rest, &block) ...>
2019-11-20 13:42:56 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00