summaryrefslogtreecommitdiff
path: root/node.h
Commit message (Collapse)AuthorAgeFilesLines
* Disallow mixed usage of ... and */**Shugo Maeda2022-12-151-0/+1
| | | | [Feature #19134]
* Remove ruby2_keywords related to args forwardingyui-knk2022-11-291-1/+0
| | | | | | | This was introduced by b609bdeb5307e280137b4b2838af0fe4e4b46f1c to suppress warnings. However these warngins were deleted by beae6cbf0fd8b6619e5212552de98022d4c4d4d4. Therefore these codes are not needed anymore.
* Enhance keep_tokens option for RubyVM::AbstractSyntaxTree parsing methodsyui-knk2022-11-211-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implementation for Language Server Protocol (LSP) sometimes needs token information. For example both `m(1)` and `m(1, )` has same AST structure other than node locations then it's impossible to check the existence of `,` from AST. However in later case, it might be better to suggest variables list for the second argument. Token information is important for such case. This commit adds these methods. * Add `keep_tokens` option for `RubyVM::AbstractSyntaxTree.parse`, `.parse_file` and `.of` * Add `RubyVM::AbstractSyntaxTree::Node#tokens` which returns tokens for the node including tokens for descendants nodes. * Add `RubyVM::AbstractSyntaxTree::Node#all_tokens` which returns all tokens for the input script regardless the receiver node. [Feature #19070] Impacts on memory usage and performance are below: Memory usage: ``` $ cat test.rb root = RubyVM::AbstractSyntaxTree.parse_file(File.expand_path('../test/ruby/test_keyword.rb', __FILE__), keep_tokens: true) $ /usr/bin/time -f %Mkb /usr/local/bin/ruby -v ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux] 11408kb # keep_tokens :false $ /usr/bin/time -f %Mkb /usr/local/bin/ruby test.rb 17508kb # keep_tokens :true $ /usr/bin/time -f %Mkb /usr/local/bin/ruby test.rb 30960kb ``` Performance: ``` $ cat ../ast_keep_tokens.yml prelude: | src = <<~SRC module M class C def m1(a, b) 1 + a + b end end end SRC benchmark: without_keep_tokens: | RubyVM::AbstractSyntaxTree.parse(src, keep_tokens: false) with_keep_tokens: | RubyVM::AbstractSyntaxTree.parse(src, keep_tokens: true) $ make benchmark COMPARE_RUBY="./ruby" ARGS=../ast_keep_tokens.yml /home/kaneko.y/.rbenv/shims/ruby --disable=gems -rrubygems -I../benchmark/lib ../benchmark/benchmark-driver/exe/benchmark-driver \ --executables="compare-ruby::./ruby -I.ext/common --disable-gem" \ --executables="built-ruby::./miniruby -I../lib -I. -I.ext/common ../tool/runruby.rb --extout=.ext -- --disable-gems --disable-gem" \ --output=markdown --output-compare -v ../ast_keep_tokens.yml compare-ruby: ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux] built-ruby: ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux] warming up.. | |compare-ruby|built-ruby| |:--------------------|-----------:|---------:| |without_keep_tokens | 21.659k| 21.303k| | | 1.02x| -| |with_keep_tokens | 6.220k| 5.691k| | | 1.09x| -| ```
* Make anonymous rest arg (*) and block arg (&) accessible from ARGS nodeyui-knk2022-11-181-0/+1
|
* Remove unused macroyui-knk2022-10-091-1/+0
| | | | NEW_PREEXE has not been used since 52a5f76e8b1ab02ee6e259a7cff9e8c5475744e8
* Move `error` from top_stmts and top_stmt to stmtyui-knk2022-10-081-0/+2
| | | | | | | | | | | | | | | | | | | By this change, syntax error is recovered smaller units. In the case below, "DEFN :bar" is same level with "CLASS :Foo" now. ``` module Z class Foo foo. end def bar end end ``` [Feature #19013]
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-15/+15
| | | | [Misc #18891]
* Remove `NODE_DASGN_CURR` [Feature #18406]Nobuyoshi Nakada2021-12-131-2/+0
| | | | | | | This `NODE` type was used in pre-YARV implementation, to improve the performance of assignment to dynamic local variable defined at the innermost scope. It has no longer any actual difference with `NODE_DASGN`, except for the node dump.
* Turn nd_type_p into an inline functionNobuyoshi Nakada2021-12-041-1/+5
|
* Add `nd_type_p` macroS.H2021-12-041-0/+1
|
* Refactor hacky ID tables to struct rb_ast_id_table_tYusuke Endoh2021-11-211-2/+10
| | | | | | | | | The implementation of a local variable tables was represented as `ID*`, but it was very hacky: the first element is not an ID but the size of the table, and, the last element is (sometimes) a link to the next local table only when the id tables are a linked list. This change converts the hacky implementation to a normal struct.
* node/h: clean node field accessorsYusuke Endoh2021-11-171-13/+13
| | | | | This change removes nd_oid, nd_rest, and nd_opt, and adds some comments for special accessors.
* node.h: Reduce struct size to fit with Ruby object size (five VALUEs)Yusuke Endoh2021-06-181-1/+3
| | | | | | | | by merging `rb_ast_body_t#line_count` and `#script_lines`. Fortunately `line_count == RARRAY_LEN(script_lines)` was always satisfied. When script_lines is saved, it has an array of lines, and when not saved, it has a Fixnum that represents the old line_count.
* ast.rb: RubyVM::AST.parse and .of accepts `save_script_lines: true`Yusuke Endoh2021-06-181-0/+1
| | | | | | | This option makes the parser keep the original source as an array of the original code lines. This feature exploits the mechanism of `SCRIPT_LINES__` but records only the specified code that is passed to RubyVM::AST.of or .parse, instead of recording all parsed program texts.
* NODE markability should not change by nd_set_typeNobuyoshi Nakada2021-01-141-0/+12
|
* Change NODE layout for pattern matchingKazuki Tsujimoto2020-11-011-2/+2
| | | | | | | | | | | | | | | | | | | | I prefer pconst to be the first element of NODE. Before: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | imemo | imemo | pkwargs u2 | pconst | pconst | pconst u3 | apinfo | fpinfo | pkwrestarg After: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | pconst | pconst | pconst u2 | imemo | imemo | pkwargs u3 | apinfo | fpinfo | pkwrestarg
* include/ruby/backward/2/r_cast.h: deprecate卜部昌平2020-08-271-1/+1
| | | | | Remove all usages of RCAST() so that the header file can be excluded from ruby/ruby.h's dependency.
* Remove unused struct memberAaron Patterson2020-08-031-1/+0
| | | | | I accidentally added this in 35ba2783fe6b3316a6bbc6f00bf975ad7185d6e0, and it's making the size of RVALUE be too big. I'm sorry! orz
* rb_{ary,fnd}_pattern_info: Remove imemo member to reduce memory usageKazuki Tsujimoto2020-08-021-4/+2
| | | | | | | | | | | | | | | | | | | | | | This is a partial revert commit of 8f096226e1b76f95f4d853d3dea2bc75eeeb5244. NODE layout: Before: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | pconst | pconst | pconst u2 | unused | unused | pkwargs u3 | apinfo | fpinfo | pkwrestarg After: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | imemo | imemo | pkwargs u2 | pconst | pconst | pconst u3 | apinfo | fpinfo | pkwrestarg
* Use a linked list to eliminate imemo tmp bufs for managing local tablesAaron Patterson2020-07-271-0/+2
| | | | | | | This patch changes local table memory to be managed by a linked list rather than via the garbage collector. It reduces allocations from the GC and also fixes a use-after-free bug in the concurrent-with-sweep compactor I'm working on.
* Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada2020-07-031-4/+3
| | | | | | | | | | | | Use ID instead of GENTRY for gvars. Global variables are compiled into GENTRY (a pointer to struct rb_global_entry). This patch replace this GENTRY to ID and make the code simple. We need to search GENTRY from ID every time (st_lookup), so additional overhead will be introduced. However, the performance of accessing global variables is not important now a day and this simplicity helps Ractor development.
* Introduce find pattern [Feature #16828]Kazuki Tsujimoto2020-06-141-0/+11
|
* Constified code_loc_genNobuyoshi Nakada2020-05-141-1/+1
|
* Fix indentationKazuki Tsujimoto2020-05-041-1/+1
|
* add #include guard hack卜部昌平2020-04-131-3/+2
| | | | | | | | | | | | | | | | | | | | | | According to MSVC manual (*1), cl.exe can skip including a header file when that: - contains #pragma once, or - starts with #ifndef, or - starts with #if ! defined. GCC has a similar trick (*2), but it acts more stricter (e. g. there must be _no tokens_ outside of #ifndef...#endif). Sun C lacked #pragma once for a looong time. Oracle Developer Studio 12.5 finally implemented it, but we cannot assume such recent version. This changeset modifies header files so that each of them include strictly one #ifndef...#endif. I believe this is the most portable way to trigger compiler optimizations. [Bug #16770] *1: https://docs.microsoft.com/en-us/cpp/preprocessor/once *2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-1/+1
| | | | | | 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.
* delete unused functions卜部昌平2019-11-141-7/+0
| | | | | | | | | | | | Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine.
* Revert "Method reference operator"Nobuyoshi Nakada2019-11-121-2/+0
| | | | | This reverts commit 67c574736912003c377218153f9d3b9c0c96a17b. [Feature #16275]
* Define arguments forwarding as `ruby2_keywords` styleNobuyoshi Nakada2019-10-251-1/+3
| | | | | | | | | | | | Get rid of these redundant and useless warnings. ``` $ ruby -e 'def bar(a) a; end; def foo(...) bar(...) end; foo({})' -e:1: warning: The last argument is used as the keyword parameter -e:1: warning: for `foo' defined here -e:1: warning: The keyword argument is passed as the last hash parameter -e:1: warning: for `bar' defined here ```
* Add compaction support to `rb_ast_t`Aaron Patterson2019-09-261-0/+1
| | | | This commit adds compaction support to `rb_ast_t`.
* Allows calling a private method only with bare `self`Nobuyoshi Nakada2019-09-201-1/+1
|
* Moved ruby_node_name declaration to node.hNobuyoshi Nakada2019-09-131-0/+1
|
* Macros can't be expressions, so make a functionAaron Patterson2019-09-101-6/+2
| | | | | | Macros can't be expressions, that is a GNU extension (I didn't know that). This commit converts the macro to a function so that everything will compile correctly on non-GNU compatible compilers.
* WB needs to be executed after object is reachableAaron Patterson2019-09-101-1/+6
|
* Revert "Reverting node marking until I can fix GC problem."Aaron Patterson2019-09-091-1/+3
| | | | This reverts commit 092f31e7e23c0ee04df987f0c0f979d036971804.
* Rename NODE_ARRAY to NODE_LIST to reflect its actual use casesYusuke Endoh2019-09-071-5/+4
| | | | | | | | | | and NODE_ZARRAY to NODE_ZLIST. NODE_ARRAY is used not only by an Array literal, but also the contents of Hash literals, method call arguments, dynamic string literals, etc. In addition, the structure of NODE_ARRAY is a linked list, not an array. This is very confusing, so I believe `NODE_LIST` is a better name.
* Reverting node marking until I can fix GC problem.Aaron Patterson2019-09-051-3/+1
| | | | | Looks like we're getting WB misses during stressful GC on startup. I am investigating.
* Stash tmpbuffer inside internal structsAaron Patterson2019-09-051-0/+2
| | | | | | I guess those AST node were actually used for something, so we'd better not touch them. Instead this commit just puts the tmpbuffer inside a different internal struct so that we can mark them.
* Create two buckets for allocating NODE structsAaron Patterson2019-09-051-1/+1
| | | | | | | | | This commit adds two buckets for allocating NODE structs, then allocates "markable" NODE objects from one bucket. The reason to do this is so when the AST mark function scans nodes for VALUE objects to mark, we only scan NODE objects that we know to reference VALUE objects. If we *did not* divide the objects, then the mark function spends too much time scanning objects that don't contain any references.
* Make pattern matching support **nil syntaxKazuki Tsujimoto2019-09-011-0/+1
|
* Support **nil syntax for specifying a method does not accept keyword argumentsJeremy Evans2019-08-301-0/+1
| | | | | | | | | This syntax means the method should be treated as a method that uses keyword arguments, but no specific keyword arguments are supported, and therefore calling the method with keyword arguments will raise an ArgumentError. It is still allowed to double splat an empty hash when calling the method, as that does not pass any keyword arguments.
* Let memory sizes of the various IMEMO object types be reflected correctlyLourens Naudé2019-07-231-0/+1
| | | | | | [Feature #15805] Closes: https://github.com/ruby/ruby/pull/2140
* Adjust styles and indentsNobuyoshi Nakada2019-07-191-1/+2
|
* Fix grammar of macro name: ECCESSED -> ECCESSIVEMartin Dürst2019-06-051-1/+1
| | | | | Fix the name of the macro variable introduced in 0872ea5330 from NODE_SPECIAL_EXCESSED_COMMA to NODE_SPECIAL_EXCESSIVE_COMMA.
* node.h: Avoid a magic number to represent excessed commaYusuke Endoh2019-06-041-0/+1
| | | | | | `(ID)1` was assigned to NODE_ARGS#rest_arg for `{|x,| }`. This change removes the magic number by introducing an explicit macro variable for it: NODE_SPECIAL_EXCESSED_COMMA.
* parse.y: duplicated when clause warningNobuyoshi Nakada2019-05-051-0/+2
| | | | | * parse.y (case_args): moved "duplicated when clause" warning from compile phase, so that `ruby -wc` shows them.
* Introduce pattern matching [EXPERIMENTAL]ktsj2019-04-171-0/+19
| | | | | | [ruby-core:87945] [Feature #14912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.h: introduce nd_brace to determine if a hash literal is a keywordmame2019-03-151-0/+2
| | | | | | | | | NODE_HASH#nd_brace is a flag that is 1 for `foo({ k: 1 })` and 0 for `foo(k: 1)`. nd_alen had been abused for the flag (and the implementation is completely the same), but an explicit name is better to read. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Method reference operatornobu2018-12-311-0/+2
| | | | | | | | Introduce the new operator for method reference, `.:`. [Feature #12125] [Feature #13581] [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Parse the source in SCRIPT_LINES__ as arraynobu2018-11-101-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e