Commit graph

282 commits

Author SHA1 Message Date
Yuri Smirnov
13e87e5049
fix Data docs (#6497) 2022-10-06 10:13:17 -07:00
Nobuyoshi Nakada
cbd82f5250
Cannot define from defined Data class again 2022-10-03 23:28:01 +09:00
Nobuyoshi Nakada
56f2fd3bc9
Use the dedicated function to check arity 2022-10-01 16:24:36 +09:00
Nobuyoshi Nakada
15d3b7fe6d
Fix an out of bound access 2022-10-01 16:20:22 +09:00
Nobuyoshi Nakada
c767618d4c
Do not define the method only for RDoc
`Data.members` fails an assertion.
2022-10-01 15:36:01 +09:00
Victor Shepelev
ad651925e3
Add Data class implementation: Simple immutable value object 2022-09-30 18:23:19 +09:00
Nobuyoshi Nakada
cfe10e482e
[DOC] Update Struct#new behavior with keyword_init: true 2022-09-09 18:58:07 +09:00
Peter Zhu
efb91ff19b Rename rb_ary_tmp_new to rb_ary_hidden_new
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.
2022-07-26 09:12:09 -04:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
John Hawthorn
adc709adb8
Don't attempt to read ivars on T_ICLASS in struct (#5664) 2022-05-26 11:54:15 -07:00
Peter Zhu
54b53e2c8f [ci skip] Fix docs 2022-04-13 10:43:23 -04:00
Burdette Lamar
ffcdbedbfb
Repaired What's Here sections for Range, String, Symbol, Struct (#5735)
Repaired What's Here sections for Range, String, Symbol, Struct.
2022-03-30 13:46:24 -05:00
Nobuyoshi Nakada
e660b934b9
A positional Hash is not keyword arguments [Bug #18632] 2022-03-17 20:53:41 +09:00
Nobuyoshi Nakada
50c972a1ae
[DOC] Simplify operator method references 2022-02-12 12:38:36 +09:00
Peter Zhu
a32e5e1b97 [DOC] Use RDoc link style for links in the same class/module
I used this regex:

(?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+)

And performed a global find & replace for this:

rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Peter Zhu
f9a2802bc5 [DOC] Use RDoc link style for links to other classes/modules
I used this regex:

([A-Za-z]+)\.html#(?:class|module)-[A-Za-z]+-label-([A-Za-z0-9\-\+]+)

And performed a global find & replace for this:

rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Burdette Lamar
a07fa198a6
Improve links to labels in string.c and struct.c (#5531) 2022-02-06 09:44:40 -06:00
Nobuyoshi Nakada
c956f979e5
Initialize Struct by calling with keyword arguments 2021-12-26 23:28:54 +09:00
Kazuhiro NISHIYAMA
04f07713d1
Fix typos [ci skip] 2021-12-25 10:33:49 +09:00
zverok
fed1629ada Fix StructClass:: class method docs 2021-12-24 10:29:31 +09:00
Nobuyoshi Nakada
c5ec05d047
struct_pos_num is no longer used 2021-11-20 21:32:57 +09:00
Koichi Sasada
82ea287018 optimize Struct getter/setter
Introduce new optimized method type
`OPTIMIZED_METHOD_TYPE_STRUCT_AREF/ASET` with index information.
2021-11-19 08:32:39 +09:00
Nobuyoshi Nakada
4fb71575e2
[DOC] Fix code markup [ci skip]
Code markup in RDoc must not be concatenated with anothr word.
2021-10-25 01:04:51 +09:00
S.H
dc9112cf10
Using NIL_P macro instead of == Qnil 2021-10-03 22:34:45 +09:00
Burdette Lamar
2cf1014362
Enhanced RDoc for Struct (#4895)
Revises introductory material.
    Adds section "What's Here".
    Adds previously missing documentation for method #deconstruct_keys.
2021-09-27 18:17:47 -05:00
Burdette Lamar
39a6bf5513
Enhanced RDoc for Struct (#4891)
Treats:

    #values_at
    #select
    #==
    #hash
    #eql?
    #size
    #dig
2021-09-24 18:41:02 -05:00
Burdette Lamar
bbdfce96a2
Enhanced RDoc for Struct (#4890)
Treated:

    #each
    #each_pair
    #inspect
    #to_a
    #to_h
    #[]
    #[]=
2021-09-24 10:35:19 -05:00
Burdette Lamar
b38d2bf118
Enhance RDoc for Struct (#4885)
Treats #members and ::new.
2021-09-23 17:21:40 -05:00
Nobuyoshi Nakada
a27c274f04
[DOC] Fix broken links [ci skip]
* As the "doc/" prefix is specified by the `--page-dir` option,
  remove from the rdoc references.
* Refer to the original .rdoc instead of the converted .html.
2021-09-15 14:16:14 +09:00
S-H-GAMELINKS
56065f0686 Using SYMBOL_P macro 2021-09-11 08:48:56 +09:00
Nobuyoshi Nakada
3e7a7fb28a
Make Struct#keyword_init? return nil by default [Feature #18008] 2021-07-15 22:24:02 +09:00
Nobuyoshi Nakada
33bea3bdff
Regularize keyword_init values not to hold the argument object 2021-07-15 21:32:04 +09:00
hkdnet
1a63754416
struct.c: Add keyword_init? singleton method for StructClass (#4609)
Fixes [Feature #18008]
2021-07-15 18:14:27 +09:00
Takashi Kokubun
8d099aa040
Warn Struct#initialize with only keyword args (#4070)
* Warn Struct#initialize with only keyword args

A part of [Feature #16806]

* Do not warn if `keyword_init: false`

is explicitly specified

* Add a NEWS entry

* s/in/from/

* Make sure all fields are initialized
2021-01-17 01:35:54 -08:00
卜部昌平
99093e1600 RHASH_TBL: is now ext-only
It seems almost no internal codes use RHASH_TBL any longer.  Why not
just eliminate it entirely, so that the macro can be purely ext-only.
2020-08-19 15:10:53 +09:00
Burdette Lamar
c84ccf1a07
Fix links to Dig Methods document (#3421)
* Fix links to Dig Methods document

* Fix links to Dig Methods document
2020-08-14 18:55:04 -05:00
Burdette Lamar
22fd617aa5
Adding doc/dig_methods.rdoc and links to it (#3416)
Adds a full discussion of #dig, along with links from Array, Hash, Struct, and OpenStruct.

CSV::Table and CSV::Row are over in ruby/csv. I'll get to them soon.

The art to the thing is to figure out how much (or how little) to say at each #dig.
2020-08-13 13:16:27 -05:00
卜部昌平
f66e0212ef precalc invokebuiltin destinations
Noticed that struct rb_builtin_function is a purely compile-time
constant.  MJIT can eliminate some runtime calculations by statically
generate dedicated C code generator for each builtin functions.
2020-07-13 08:56:18 +09:00
Takashi Kokubun
167d139487
Inline builtin struct aref
We don't do this for aset because it might raise a FrozenError.

```
$ benchmark-driver -v --rbenv 'before;after;before --jit;after --jit' benchmark/mjit_struct_aref.yml --repeat-count=4
before: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6) [x86_64-linux]
after: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) [x86_64-linux]
last_commit=Inline builtin struct aref
before --jit: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6) +JIT [x86_64-linux]
after --jit: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) +JIT [x86_64-linux]
last_commit=Inline builtin struct aref
Calculating -------------------------------------
                             before       after  before --jit  after --jit
mjit_struct_aref(struct)    34.783M     34.810M       48.321M      58.378M i/s -     40.000M times in 1.149996s 1.149097s 0.827794s 0.685192s

Comparison:
             mjit_struct_aref(struct)
             after --jit:  58377836.7 i/s
            before --jit:  48321205.7 i/s - 1.21x  slower
                   after:  34809935.5 i/s - 1.68x  slower
                  before:  34782736.5 i/s - 1.68x  slower
```
2020-07-06 00:14:00 -07:00
Nobuyoshi Nakada
ccb7a4b9f2
Replaced accessors of Struct with invokebuiltin 2020-06-17 08:18:46 +09:00
Nobuyoshi Nakada
318d52e820
Revert "Replaced accessors of Struct with invokebuiltin"
This reverts commit 19cabe8b09,
which didn't support tool/lib/iseq_loader_checker.rb.
2020-06-16 18:44:58 +09:00
Nobuyoshi Nakada
19cabe8b09
Replaced accessors of Struct with invokebuiltin 2020-06-16 18:24:02 +09:00
Nobuyoshi Nakada
8a504b224f
Added GC guard for splatted array 2020-05-08 21:23:21 +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
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
卜部昌平
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
Kazuki Tsujimoto
2439948bcc
Avoid needless object allocation 2019-11-19 08:53:01 -06: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
Kazuki Tsujimoto
d4da74ea78
Define Struct#deconstruct_keys 2019-11-08 11:37:46 +09:00
Alan Wu
4c7f789e94 Allow only one argument for keyword_init struct
```
irb(main):001:0> RUBY_VERSION
=> "2.6.5"
irb(main):002:0> S = Struct.new(:foo, keyword_init: true)
=> S(keyword_init: true)
irb(main):003:0> S.new({foo: 23424}, 234) # I don't think this is intentional
=> #<struct S foo=23424>
irb(main):004:0>
```

Tightening this up should inform users when they are confused about
whether a struct is `keyword_init`.
2019-10-31 00:37:53 +09:00