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

816 Коммитов

Автор SHA1 Сообщение Дата
S.H 05a3dc1a65
Improve performance Kernel#Float with using Primitive.mandatory_only? method [Feature #18344] (#5133) 2021-11-17 20:26:40 -08:00
Jeremy Evans 717ab0bb2e
Add Class#descendants
Doesn't include receiver or singleton classes.

Implements [Feature #14394]

Co-authored-by: fatkodima <fatkodima123@gmail.com>
Co-authored-by: Benoit Daloze <eregontp@gmail.com>
2021-10-26 12:35:21 -07:00
Shugo Maeda 6606597109
Deprecate include/prepend in refinements and add Refinement#import_methods instead
Refinement#import_methods imports methods from modules.
Unlike Module#include, it copies methods and adds them into the refinement,
so the refinement is activated in the imported methods.

[Bug #17429] [ruby-core:101639]
2021-10-21 16:31:54 +09:00
Alan Wu 5906a5a732 Add comments about special runtime routines YJIT calls
When YJIT make calls to routines without reconstructing interpreter
state through jit_prepare_routine_call(), it relies on the routine to
never allocate, raise, and push/pop control frames. Comment about this
on the routines that YJTI calls.

This is probably something we should dynamically verify on debug builds.
It's hard to statically verify this as it requires verifying all
functions in the call tree. Maybe something to look at in the future.
2021-10-20 18:19:43 -04:00
Nobuyoshi Nakada c0a892a7f0
Fix a typo [Bug #17048] 2021-09-19 22:39:18 +09:00
Nobuyoshi Nakada fd918d1afa
Removed Module.allocate [Bug #17048] 2021-09-17 11:14:08 +09:00
Nobuyoshi Nakada 178ee1e801
Already initialized modules cannot be replaced [Bug #17048] 2021-09-17 11:14:04 +09:00
S-H-GAMELINKS 83a5e2bb5c Using RB_FLOAT_TYPE_P macro 2021-09-12 11:16:31 +09:00
S-H-GAMELINKS 032534dbdf Using RB_BIGNUM_TYPE_P macro 2021-09-11 09:13:24 +09:00
卜部昌平 e18bc14a05 include/ruby/ruby.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平 6e62cf46ed include/ruby/internal/arithmetic/double.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平 d43accae15 include/ruby/internal/intern/object.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平 a2b8f61cba include/ruby/internal/core/rbasic.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平 7c28330ca0 include/ruby/internal/core/rclass.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平 4881a3ed38 include/ruby/internal/fl_type.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平 3be4adcf2b include/ruby/internal/globals.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平 1f66d8a77b include/ruby/internal/newobj.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
Nobuyoshi Nakada 6329da588b Use predefined IDs 2021-07-27 15:40:27 +09:00
Nobuyoshi Nakada bc1323ce5c
Use RB_INTEGER_TYPE_P 2021-07-20 21:45:11 +09:00
Nobuyoshi Nakada 8a6ef5ef8f
Make boolean expected messages more consitent 2021-07-18 20:51:30 +09:00
Nobuyoshi Nakada 56d983697f
Constified a local table 2021-07-18 19:56:36 +09:00
Nobuyoshi Nakada 301d194ee3 Add Integer.try_convert [Feature #15211] 2021-07-16 17:49:53 +09:00
S-H-GAMELINKS b32ae9898f Move rb_str_escape function declaration 2021-07-11 18:26:20 +09:00
Nobuyoshi Nakada 94bd3bde81 Specify version to remove as bare numbers 2021-06-30 10:47:01 +09:00
Nobuyoshi Nakada 8118d435d0 rb_warn_deprecated_to_remove_at [Feature #17432]
At compilation time with RUBY_DEBUG enabled, check if the removal
version has been reached.
2021-06-30 10:47:01 +09:00
Nobuyoshi Nakada 47a9b58b2a
Share freeze option handling 2021-06-28 10:53:37 +09:00
Nobuyoshi Nakada e4f891ce8d
Adjust styles [ci skip]
* --braces-after-func-def-line
* --dont-cuddle-else
* --procnames-start-lines
* --space-after-for
* --space-after-if
* --space-after-while
2021-06-17 10:13:40 +09:00
S.H 28b481938b
Implemented some NilClass method in Ruby code is faster [Feature #17054] (#3366) 2021-06-02 20:04:56 -07:00
Burdette Lamar 6b32f1f338
Object whats here (#4503)
What's Here section for class Object.
2021-05-18 08:16:29 -05:00
Burdette Lamar 434cd3c399
What's Here for BasicObject (#4499)
* What's Here for BasicObject
2021-05-13 17:19:07 -05:00
Burdette Lamar 879cc64d06
What's Here for Kernel (#4488) 2021-05-13 12:09:07 -05:00
Aaron Patterson 9a6226c61e Eagerly allocate instance variable tables along with object
This allows us to allocate the right size for the object in advance,
meaning that we don't have to pay the cost of ivar table extension
later.  The idea is that if an object type ever became "extended" at
some point, then it is very likely it will become extended again.  So we
may as well allocate the ivar table up front.
2021-05-03 14:11:48 -07:00
Kenichi Kamiya c080bb2284 [Doc] Update to FrozenError from RuntimeError in Object#freeze 2021-04-01 10:10:02 -07:00
Nobuyoshi Nakada 1499f626a5
[DOC] Modified prefixes to get rid of conflicts 2021-02-07 23:35:06 +09:00
Nobuyoshi Nakada 03e3cc2b72
[DOC] make individual names so that rdoc can find each documents 2021-02-07 23:12:06 +09:00
Nobuyoshi Nakada 0261519f6e
[DOC] Module#method_undefined 2021-02-07 23:11:59 +09:00
Marcus Stollsteimer c3f91f9d88 [DOC] Fix typos 2020-12-24 23:09:51 +01:00
卜部昌平 7fbad92241 rb_cData: no longer exists
Commit 8918a9cf6c introduced macro
`#define rb_cData rb_cData()`.  This deleting `VALUE rb_cData;`
declaration was then macro-expanded into `VALUE rb_cData();`.  This
worked by accident because the expanded expression happen to be a K&R
style function declaration.

This is rather complicated and I guess unintended.  Just delete the line
to keep things simple straight forward.
2020-12-22 16:18:17 +09:00
Nobuyoshi Nakada 8918a9cf6c Removed rb_cData entity
* Use the wrapper of rb_cObject instead of data access
* Replaced rest of extentions
* Updated the version guard for Data
* Added the version guard of rb_cData
2020-12-22 02:51:49 +09:00
卜部昌平 c30f03d328 Data: delete
Has been deprecated since 684bdf6171.

Matz says in [ruby-core:83954] that Data should be an alias of Object.
Because rb_cData has not been deprecated, let us deprecate the constant
to make it a C-level synonym of rb_cObject.
2020-12-22 02:51:49 +09:00
Nobuyoshi Nakada 34f6b22df0
Use rb_id_attrset without intermediate strings 2020-12-19 11:44:05 +09:00
Radosław Bułat d40d95296d Feature 17314: update docs and NEWS about attr* methods returning array of symbols 2020-12-19 09:22:26 +09:00
Yusuke Endoh aa7a020710 Revert "Revert "Use rb_id_attrset without intermediate strings""
This reverts commit 41c208d4a4.

Reintroduce 66090b9d10.
2020-12-19 03:20:09 +09:00
Radosław Bułat 5944c4b3cf
attr_reader, attr_writer, attr_accessor and attr methods returns array of symbols (#3935)
Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2020-12-19 03:11:35 +09:00
Jeremy Evans 05313c914b Use category: :deprecated in warnings that are related to deprecation
Also document that both :deprecated and :experimental are supported
:category option values.

The locations where warnings were marked as deprecation warnings
was previously reviewed by shyouhei.

Comment a couple locations where deprecation warnings should probably
be used but are not currently used because deprecation warning
enablement has not occurred at the time they are called
(RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K).

Add assert_deprecated_warn to test assertions.  Use this to simplify
some tests, and fix failing tests after marking some warnings with
deprecated category.
2020-12-18 09:54:11 -08:00
Yusuke Endoh 982443e6e3 Revert "Better cooperation between public/protected/private with attr* and alias_method"
This reverts commit 81739ad4fd.
2020-12-18 16:08:55 +09:00
Yusuke Endoh 41c208d4a4 Revert "Use rb_id_attrset without intermediate strings"
This reverts commit 66090b9d10.
2020-12-18 16:08:25 +09:00
Nobuyoshi Nakada 66090b9d10
Use rb_id_attrset without intermediate strings 2020-12-18 12:10:20 +09:00
Radosław Bułat 81739ad4fd Better cooperation between public/protected/private with attr* and alias_method 2020-12-17 12:46:02 -05:00
Nobuyoshi Nakada a039dc018c
[DOC] Described "numeric representation" more precisely [ci skip]
[Bug #17395]
2020-12-16 00:07:37 +09:00
Nobuyoshi Nakada d2b7e1e4b2
Protoized old pre-ANSI K&R style definitions 2020-12-05 14:57:31 +09:00
Aaron Patterson 0bbbb5a657 `dest` is always embedded so we can remove this check 2020-10-28 08:41:39 -07:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Koichi Sasada 91ec5f9e39 remove rb_obj_iv_index_tbl
(1) nobody uses it (gem-codesearch)
(2) the data strucuture will be changed.
2020-10-17 08:18:04 +09:00
S.H 5e120a2389
Improve doc in rb_class_real doc (#3637) 2020-10-10 04:52:21 -04:00
John Hawthorn 0b81a484f3 Initialize new T_OBJECT as ROBJECT_EMBED
Previously, when an object is first initialized, ROBJECT_EMBED isn't
set. This means that for brand new objects, ROBJECT_NUMIV(obj) is 0 and
ROBJECT_IV_INDEX_TBL(obj) is NULL.

Previously, this combination meant that the inline cache would never be
initialized when setting an ivar on an object for the first time since
iv_index_tbl was NULL, and if it were it would never be used because
ROBJECT_NUMIV was 0. Both cases always fell through to the generic
rb_ivar_set which would then set the ROBJECT_EMBED flag and initialize
the ivar array.

This commit changes rb_class_allocate_instance to set the ROBJECT_EMBED
flag on the object initially and to initialize all members of the
embedded array to Qundef. This allows the inline cache to be set
correctly on first use and to be used on future uses.

This moves rb_class_allocate_instance to gc.c, so that it has access to
newobj_of. This seems appropriate given that there are other allocating
methods in this file (ex. rb_data_object_wrap, rb_imemo_new).
2020-09-02 14:54:29 -07:00
卜部昌平 6649677eb9 ROBJECT_IV_INDEX_TBL: convert into an inline function
Former ROBJECT_IV_INDEX_TBL macro included RCLASS_IV_INDEX_TBL, which is
not disclosed to extension libraies.  The macro was kind of broken.  Why
not just deprecate it, and convert the internal use into an inline
function.
2020-08-19 14:30:57 +09:00
Espartaco Palma cfbae7dae0 [skip-ci] Clarification for dup vs clone docs
Both clone & dup returns a new object when executed
on the documentation looks like they are returning the
same object cloned or dup'ed which is true for method
as extend, but not for the above mentioned.
2020-07-30 18:34:17 +09:00
卜部昌平 9721f477c7 inline Primitive.cexpr!
We can obtain the verbatim source code of Primitive.cexpr!.  Why not
paste that content into the JITed program.
2020-07-13 08:56:18 +09:00
Takashi Kokubun 24fa37d87a
Make Kernel#then, #yield_self, #frozen? builtin (#3283)
* Make Kernel#then, #yield_self, #frozen? builtin

* Fix test_jit
2020-07-03 18:02:43 -07:00
Takashi Kokubun f3a0d7a203
Rewrite Kernel#tap with Ruby (#3281)
* Rewrite Kernel#tap with Ruby

This was good for VM too, but of course my intention is to unblock JIT's inlining of a block over yield
(inlining invokeyield has not been committed though).

* Fix test_settracefunc

About the :tap deletions, the :tap events are actually traced (we already have a TracePoint test for builtin methods),
but it's filtered out by tp.path == "xyzzy" (it became "<internal:kernel>"). We could trace tp.path == "<internal:kernel>"
cases too, but the lineno is impacted by kernel.rb changes and I didn't want to make it fragile for kernel.rb lineno changes.
2020-07-03 09:52:35 -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
卜部昌平 82ed66a75a rb_cstr_to_dbl_raise: 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
卜部昌平 06ed9a7a04 rb_convert_to_integer: 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
卜部昌平 268962077a rb_mod_const_location: 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
卜部昌平 60212cd8ee rb_mod_const_defined: 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
卜部昌平 3b8d9badab rb_mod_const_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
卜部昌平 1f6e74106f class_or_module_required: 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
Takashi Kokubun 946e5cc668
Annotate Kernel#class as inline (#3250)
```
$ benchmark-driver -v --rbenv 'before;after;before --jit;after --jit' benchmark/mjit_class.yml --repeat-count=4
before: ruby 2.8.0dev (2020-06-23T07:09:54Z master 37a2e48d76) [x86_64-linux]
after: ruby 2.8.0dev (2020-06-23T17:29:56Z inline-class 0ff147c007) [x86_64-linux]
before --jit: ruby 2.8.0dev (2020-06-23T07:09:54Z master 37a2e48d76) +JIT [x86_64-linux]
after --jit: ruby 2.8.0dev (2020-06-23T17:29:56Z inline-class 0ff147c007) +JIT [x86_64-linux]
Calculating -------------------------------------
                         before       after  before --jit  after --jit
    mjit_class(self)    39.219M     40.060M       53.502M      69.202M i/s -     40.000M times in 1.019915s 0.998495s 0.747631s 0.578021s
       mjit_class(1)    39.567M     41.242M       52.100M      68.895M i/s -     40.000M times in 1.010935s 0.969885s 0.767749s 0.580591s

Comparison:
                 mjit_class(self)
         after --jit:  69201690.7 i/s
        before --jit:  53502336.4 i/s - 1.29x  slower
               after:  40060289.1 i/s - 1.73x  slower
              before:  39218939.2 i/s - 1.76x  slower

                    mjit_class(1)
         after --jit:  68895358.6 i/s
        before --jit:  52100353.0 i/s - 1.32x  slower
               after:  41241993.6 i/s - 1.67x  slower
              before:  39567314.0 i/s - 1.74x  slower
```
2020-06-23 23:49:03 -07:00
Jean byroot Boussier f48fce4981 Fix a typo in instance_variable_set documentation 2020-06-10 17:49:11 -07:00
Jeremy Evans 573e8d7736 Change language used in instance_variable_set documentation [ci skip]
This uses less harsh language recommended by duerst.

Fixes [Misc #15265]
Fixes [Misc #15748]
2020-06-10 10:49:28 -07:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Marc-Andre Lafortune adf709a785 Classes made from Struct should have default `new` singleton method.
[Bug #16465] [Bug #16801]
[Fix GH-2795] [Fix GH-2944] [Fix GH-3045] [Fix GH-3093]

Note: Backporting shouldn't modify object.h and instead can use
struct_new_kw which is basically a duplicate implementation of
rb_class_new_instance_pass_kw

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: Adam Hess <HParker@github.com>
Co-authored-by: Jose Cortinas <jacortinas@gmail.com>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2020-05-08 04:18:45 -04:00
Nobuyoshi Nakada eb0125957b
Share logically equivalent functions 2020-05-07 02:50:10 +09:00
Nobuyoshi Nakada 3a6dad9d8b
[DOC] Removed no longer meaningful part [ci skip]
As now `Object#===` document is separated from `rb_equal`, this note
no longer makes sense.
2020-05-06 09:51:01 +09:00
Nobuyoshi Nakada b0498caa7e
Removed unnecessary duplicate code
`rb_equal` may be inlined in `case_equal` and actually same code
is generated twice.
2020-05-06 09:47:41 +09:00
Benoit Daloze e79e5e0b40 Generalize the explanation of the side effect of the rb_equal() optimization 2020-05-06 00:27:23 +02:00
Benoit Daloze 48d509cefc Document rb_equal() and clarify the relation with Kernel#===
* Multiple times people have been confused and believed rb_equal()
  called #=== but it does not, it calls #==.
* This optimization has a subtle side effect for Float::NAN,
  which is now documented.
2020-05-06 00:20:11 +02:00
Benoit Daloze 00a9d697a8 Remove redundant check in rb_obj_cmp()
* rb_equal() already checks using `obj1 == obj2`.
2020-05-06 00:09:56 +02:00
S.H 17083011ee
support builtin for Kernel#Float
# Iteration per second (i/s)

|             |compare-ruby|built-ruby|
|:------------|-----------:|---------:|
|float        |     30.395M|   38.314M|
|             |           -|     1.26x|
|float_true   |      3.833M|   27.322M|
|             |           -|     7.13x|
|float_false  |      4.182M|   24.938M|
|             |           -|     5.96x|
2020-04-22 09:49:13 +09:00
Nobuyoshi Nakada 62554ca978
Removed NIL/TRUE/FALSE
Deprerecated constants which had been warned since 2.4.
2020-04-17 17:35:17 +09:00
Nobuyoshi Nakada e474c189da
Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Jeremy Evans 4f7b435c95 Support obj.clone(freeze: true) for freezing clone
This freezes the clone even if the receiver is not frozen.  It
is only for consistency with freeze: false not freezing the clone
even if the receiver is frozen.

Because Object#clone is now partially implemented in Ruby and
not fully implemented in C, freeze: nil must be supported to
provide the default behavior of only freezing the clone if the
receiver is frozen.

This requires modifying delegate and set, to set freeze: nil
instead of freeze: true as the keyword parameter for
initialize_clone.  Those are the two libraries in stdlib that
override initialize_clone.

Implements [Feature #16175]
2020-03-22 09:30:07 -07:00
Nobuyoshi Nakada 165e457236
Check if `freeze` option is given 2020-03-17 19:46:03 +09:00
S.H 290d608637
support builtin for Kernel#clone 2020-03-17 19:37:07 +09:00
Nobuyoshi Nakada 83e9d6b3f4
Pass keyword argument by RB_PASS_KEYWORDS
To pass `false` as `freeze:` keyword argument, `kw_splat` argument
should be true.  Also `rb_keyword_given_p()` should return true
here as `false` has been given as a keyword argument.
2020-03-12 17:26:52 +09:00
Nobuyoshi Nakada 6b86549df8
[DOC] fixed line numbers [ci skip]
Fix up the example of const_source_location at
2bde7919a0.
2020-01-24 09:46:34 +09:00
zverok 2bde7919a0 Clarify const_source_location docs 2020-01-23 09:22:38 -08:00
Nobuyoshi Nakada aefb13eb63
Added rb_warn_deprecated_to_remove
Warn the deprecation and future removal, with obeying the warning
flag.
2020-01-23 21:42:15 +09:00
Jeremy Evans e18b817b1f Make taint warnings non-verbose instead of verbose 2020-01-22 11:19:13 -08:00
Jeremy Evans 04eb7c7e46 Call initialize_clone with freeze: false if clone called with freeze: false
This makes it possible to initialize_clone to correctly not freeze
internal state if the freeze: false keyword is passed to clone.

If clone is called with freeze: true or no keyword, do not pass
a second argument to initialize_clone to keep backwards
compatibility.

This makes it so that external libraries that override
initialize_clone but do not support the freeze keyword will fail
with ArgumentError if passing freeze: false to clone.  I think that
is better than the current behavior, which succeeds but results in
an unfrozen object with frozen internals.

Fix related issues in set and delegate in stdlib.

Fixes [Bug #14266]
2020-01-03 20:13:09 -08: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
Joao Fernandes 918fe2ed7c Fix Object#inspect documentation
Starting from ruby 2.7.0, there's no longer a connection between the hexadecimal
number that #inspect shows and the object's ID.
2019-12-31 18:31:59 +09:00
Nobuyoshi Nakada bf77fc23e7
Use the more popular word [ci skip]
[Bug #16437]
2019-12-27 17:51:24 +09: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
Nobuyoshi Nakada 4ba9347554
`Object#=~` warning also obeys `Warning[:deprecated]` 2019-12-24 18:53:14 +09:00
zverok c1bd1bf272 Document Module#const_source_location 2019-12-23 08:30:21 +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
Nobuyoshi Nakada f72dc407f2
Prohibit calling undefined allocator [Bug #16297] 2019-11-06 11:17:09 +09:00
Jean Boussier eff15a269f [EXPERIMENTAL] Make NilClass#to_s, TrueClass#to_s and FalseClass#to_s return a frozen String
* Always the same frozen String for each of these values.
    * Avoids extra allocations whenever calling these 3 methods.
    * See [Feature #16150]
2019-09-27 13:52:33 +09:00
Jeremy Evans 27b6746872 Make passing empty keywords to dig pass empty keywords to next dig method
If defined in Ruby, dig would be defined as def dig(arg, *rest) end,
it would not use keywords.  If the last dig argument was an empty
hash, it could be treated as keyword arguments by the next dig
method.  Allow dig to pass along the empty keyword flag if called
with an empty keyword, to suppress the previous behavior and force
treating the hash as a positional argument and not keywords.

Also handle the case where dig calls method_missing, passing the
empty keyword flag to that as well.

This requires adding rb_check_funcall_with_hook_kw functions, so
that dig can specify how arguments are treated.  It also adds
kw_splat arguments to a couple static functions.
2019-09-20 07:45:11 -07:00
Jeremy Evans b78a345bd6 Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from Ruby
It is not safe to set this in C functions that can be called from
other C functions, as in the non argument-delegation case, you
can end up calling a Ruby method with a flag indicating keywords
are set without passing keywords.

Introduce some new *_kw functions that take a kw_splat flag and
use these functions to set RB_PASS_CALLED_KEYWORDS in places where
we know we are delegating methods (e.g. Class#new, Method#call)
2019-09-14 01:49:33 -07:00
卜部昌平 bfe5d22f89 drop-in type check for rb_define_private_method
We can check the function pointer passed to rb_define_private_method
like how we do so in rb_define_method.  Doing so revealed some
problematic usages of rb_obj_dummy.  They had to be split according
to their arity.
2019-08-29 18:34:09 +09:00
卜部昌平 0766f67168 move docs around [ci skip]
To properly generate documents.
2019-08-29 18:34:09 +09:00
卜部昌平 7bcfd9189a drop-in type check for rb_define_global_function
We can check the function pointer passed to rb_define_global_function
like we do so in rb_define_method.  It turns out that almost anybody
is misunderstanding the API.
2019-08-29 18:34:09 +09:00
Jeremy Evans 04735c48ab Minor documentation fixes [ci skip]
From zverok (Victor Shepelev)

Fixes [Misc #16126]
2019-08-24 14:05:19 -07:00
Jeremy Evans e1c991f8d7 Move Object#hash rdoc to hash.c [ci skip]
This gets RDoc to pick up the documentation correctly.

Problem pointed out by zverok (Victor Shepelev).
2019-08-24 09:09:53 -07:00
songhuangcn d2070f2e45 Fix doc in Object#respond_to_missing? (#2239) 2019-08-16 00:20:52 +09:00
Yusuke Endoh 086ffe72c7 Revert "Revert "Add a specialized instruction for `.nil?` calls""
This reverts commit a0980f2446.

Retry for macOS Mojave.
2019-08-02 23:25:38 +09:00
Yusuke Endoh a0980f2446 Revert "Add a specialized instruction for `.nil?` calls"
This reverts commit 9faef3113f.

It seemed to cause a failure on macOS Mojave, though I'm unsure how.
https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1014/ruby-master/log/20190802T034503Z.fail.html.gz

This tentative revert is to check if the issue is actually caused by the
change or not.
2019-08-02 15:03:34 +09:00
Aaron Patterson 31ec475ad8
Update object.c
Co-Authored-By: Takashi Kokubun <takashikkbn@gmail.com>
2019-07-31 16:36:25 -07:00
Aaron Patterson 9faef3113f
Add a specialized instruction for `.nil?` calls
This commit adds a specialized instruction for called to `.nil?`.  It is
about 27% faster than master in the case where the object is nil or not
nil.  In the case where an object implements `nil?`, I think it may be
slightly slower.  Here is a benchmark:

```ruby
require "benchmark/ips"

class Niller
  def nil?; true; end
end

not_nil = Object.new
xnil = nil
niller = Niller.new

Benchmark.ips do |x|
  x.report("nil?")    { xnil.nil? }
  x.report("not nil") { not_nil.nil? }
  x.report("niller")   { niller.nil? }
end
```

On Ruby master:

```
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   429.195k i/100ms
             not nil   437.889k i/100ms
              niller   437.935k i/100ms
Calculating -------------------------------------
                nil?     20.166M (± 8.1%) i/s -    100.002M in   5.002794s
             not nil     20.046M (± 7.6%) i/s -     99.839M in   5.020086s
              niller     22.467M (± 6.1%) i/s -    112.111M in   5.013817s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   449.660k i/100ms
             not nil   433.836k i/100ms
              niller   443.073k i/100ms
Calculating -------------------------------------
                nil?     19.997M (± 8.8%) i/s -     99.375M in   5.020458s
             not nil     20.529M (± 7.0%) i/s -    102.385M in   5.020689s
              niller     21.796M (± 8.0%) i/s -    108.110M in   5.002300s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   402.119k i/100ms
             not nil   438.968k i/100ms
              niller   398.226k i/100ms
Calculating -------------------------------------
                nil?     20.050M (±12.2%) i/s -     98.519M in   5.008817s
             not nil     20.614M (± 8.0%) i/s -    102.280M in   5.004531s
              niller     22.223M (± 8.8%) i/s -    110.309M in   5.013106s

```

On this branch:

```
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   468.371k i/100ms
             not nil   456.517k i/100ms
              niller   454.981k i/100ms
Calculating -------------------------------------
                nil?     27.849M (± 7.8%) i/s -    138.169M in   5.001730s
             not nil     26.417M (± 8.7%) i/s -    131.020M in   5.011674s
              niller     21.561M (± 7.5%) i/s -    107.376M in   5.018113s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   477.259k i/100ms
             not nil   428.712k i/100ms
              niller   446.109k i/100ms
Calculating -------------------------------------
                nil?     28.071M (± 7.3%) i/s -    139.837M in   5.016590s
             not nil     25.789M (±12.9%) i/s -    126.470M in   5.011144s
              niller     20.002M (±12.2%) i/s -     98.144M in   5.001737s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   467.676k i/100ms
             not nil   445.791k i/100ms
              niller   415.024k i/100ms
Calculating -------------------------------------
                nil?     26.907M (± 8.0%) i/s -    133.755M in   5.013915s
             not nil     25.319M (± 7.9%) i/s -    125.713M in   5.007758s
              niller     19.569M (±11.8%) i/s -     96.286M in   5.008533s
```

Co-Authored-By: Ashe Connor <kivikakk@github.com>
2019-07-31 16:21:25 -07:00
Jeremy Evans 8bccbf3cfe Add more documentation on #eql?/#hash relationship [ci skip]
Fixes [Bug #14263]
2019-07-26 17:05:46 -07:00
Jeremy Evans 6279cf8b2b Restore documentation for Object#hash [ci skip]
Object#hash documentation was removed (probably by accident) in
7b19e6f3fd.
2019-07-26 16:57:42 -07:00
Nobuyoshi Nakada 3e7d002118
Check exception flag as a bool [Bug #15987] 2019-07-11 20:04:29 +09:00
Nobuyoshi Nakada 4cda2e5013
Moved error messages 2019-07-09 10:58:12 +09:00
git c5c3486340 * expand tabs. 2019-06-23 01:47:40 +09:00
Nobuyoshi Nakada 9384383019
Module#constant_source_location [Feature #10771] 2019-06-23 01:46:38 +09:00
Luke Gruber 02b1a85385
remove 2 redundant calls to rb_str_dup
Because `rb_class_path` calls `rb_str_dup` already.

Closes: https://github.com/ruby/ruby/pull/2232
2019-06-13 18:05:04 +09:00
Jean Boussier 7d805e67f3
Avoid triggering autoload in Module#const_defined?(String)
[Bug #15780]
2019-05-07 21:20:01 +09:00
nobu d10451f3fd object.c: fix searching nested const paths
* object.c (rb_mod_const_get, rb_mod_const_defined): nested const
  paths should not search from toplevel constants.
  [ruby-core:92202] [Bug #15758]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-08 13:47:37 +00:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
nobu 7fa16fd962 Fix `Module#const_defined?` on inherited constants
[Fix GH-2061]

From: manga_osyo <manga.osyo@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-28 13:32:32 +00:00
nobu 4e28fdf417 No FloatDomainError at non-finitive number if exception: false
[ruby-core:91021] [Bug #15525]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-12 09:36:52 +00:00
kazu bace0d4cdc [DOC] Add `or nil` to call-seq [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03 05:51:18 +00:00
mame e030e9f0b8 object.c (rb_obj_match): use rb_warn for deprecation warning
Now the warning is printed even without -w option.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-26 09:04:12 +00:00
stomar 9166fdac50 complex.c, object.c: [DOC] improve "exception: false" docs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-24 20:41:15 +00:00
normal 9b9fe826fd {complex,object,rational}.c: document exception: false
From: Victor Shepelev <zverok.offline@gmail.com>

[ruby-core:90673] [Bug #15452]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22 22:39:31 +00:00
nobu 8ef2aae2d0 Use idException
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22 10:23:06 +00:00
kazu 968fcd8346 [DOC] Update Object#=~ [ci skip]
see r65989

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-16 14:54:05 +00:00
nobu 973f84ef55 Show the class of the receiver [Feature #15231]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 23:03:54 +00:00
nobu 09ef29a78f Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05 01:09:44 +00:00
mame ebff9dc10e object.c: Deprecate Object#=~ and add NilClass#=~`
Object#=~ always returns nil.  This behavior is not only unuseful but
also troublesome because it may hide a type error.

This change deprecates Object#=~.  For compatibility, NilClass#=~ is
newly introduced.  [Feature #15231]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 07:55:07 +00:00
k0kubun 38caab29bc Always inline rb_to_integer to prevent a method call penalty
for integer types

Close https://github.com/ruby/ruby/pull/2001

Co-Authored-By: methodmissing <lourens@methodmissing.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-03 12:24:49 +00:00
stomar 905be736f7 object.c: [DOC] fix typos in doc for yield_self
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-26 12:19:04 +00:00
aycabta d67b903519 Improve doc of yield_self
* object.c: Add code samples for yield_self.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21 07:15:44 +00:00
nobu e1966b31e9 Get rid of calling to_f in rat2dbl_without_to_f
[Bug #15189]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-02 18:03:43 +00:00
nobu 603f95a0ed Fix Rational of Float
[ruby-core:89239] [Bug #15189]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-02 16:42:21 +00:00
nobu 02cae85e34 object.c: prefer base optarg
* object.c (rb_f_integer): prefer `base` optional argument over
  keyword arguments.  this issue should be resolved more generally
  by separating keyword arguments from hashes in the future.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-22 16:03:58 +00:00
ko1 38e05ff3e1 Don't copy FL_USER* on Kernel#clone. [Bug #14847]
* object.c (mutable_obj_clone): `Kernel#clone` should not copy
  FL_USER* flags because they are copied unexpectedly.
  Unexpected copy will break internal data consistency.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-09 08:07:26 +00:00
matz d53ee00891 object.c: Add a new alias `then` to `Kernel#yield_self`; [Feature #14594]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-30 08:24:52 +00:00
nobu 955849c126 object.c: raise on long invalid float string
* object.c (rb_cstr_to_dbl_raise): check long invalid float
  string more precisely when truncating insignificant part.
  [ruby-core:86800] [Bug #14729]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-04 06:12:12 +00:00
nobu 853707123e object.c: fix exponent with underscore
* object.c (rb_cstr_to_dbl_raise): do not ignore exponent part
  when the input string longer than internal buffer contains
  underscore(s).  [ruby-core:86836] [Bug #14731]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-02 13:37:18 +00:00
nobu f852af0e59 symbol.c: non-ASCII constant names
* symbol.c (rb_sym_constant_char_p): support for non-ASCII
  constant names.  [Feature #13770]

* object.c (rb_mod_const_get, rb_mod_const_defined): support for
  non-ASCII constant names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-10 00:41:47 +00:00
mrkn 2993b4423d Add `exception:` keyword in Kernel#Float()
Support `exception:` keyword argument in `Kernel#Float()`.
If `exception:` is `false`, `Kernel#Float()` returns `nil` if the given
value cannot be interpreted as a float value.
The default value of `exception:` is `true`.
This is part of [Feature #12732].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 07:19:45 +00:00
mrkn 2cfc5b03da Add `exception:` keyword in Kernel#Integer()
Support `exception:` keyword argument in Kernel#Integer().
If `exception:` is `false`, `Kernel#Integer()` returns `nil` if the given
value cannot be interpreted as an integer value.
The default value of `exception:` is `true`.
This is part of [Feature #12732].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 07:19:43 +00:00
nobu a13b044109 object.c: conversions with ID
* object.c (rb_to_integer, rb_check_to_int): convert to Integer
  with method ID.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07 07:43:07 +00:00