aboutsummaryrefslogtreecommitdiffstats
path: root/ruby.c
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Load external GC using command line argument"Peter Zhu2024-07-051-10/+0
| | | | This reverts commit 8ddb1110c283c5cb59b6582383f36fdbcc43ab19.
* Fix `--debug-frozen-string-literal` to not apply ↵Jean Boussier2024-06-241-1/+10
| | | | | | | | | `--disable-frozen-string-literal` [Feature #20205] This was an undesired side effect. Now that this value is a triplet, we can't assume it's disabled by default.
* Load external GC using command line argumentPeter Zhu2024-06-211-0/+10
| | | | | | | This commit changes the external GC to be loaded with the `--gc-library` command line argument instead of the RUBY_GC_LIBRARY_PATH environment variable because @nobu pointed out that loading binaries using environment variables can pose a security risk.
* [Bug #20562] Categorize `RUBY_FREE_AT_EXIT` warning as experimentalNobuyoshi Nakada2024-06-121-1/+1
|
* Remove prism compiler warningKevin Newton2024-06-071-24/+3
|
* Don't add `+YJIT` to `RUBY_DESCRIPTION` until it's actually enabledJean Boussier2024-06-051-1/+2
| | | | | | If you start Ruby with `--yjit-disable`, the `+YJIT` shouldn't be added until `RubyVM::YJIT.enable` is actually called. Otherwise it's confusing in crash reports etc.
* [PRISM] Respect eval coverage settingKevin Newton2024-05-201-0/+1
|
* Rename `vast` to `ast_value`yui-knk2024-05-031-15/+15
| | | | | There is an English word "vast". This commit changes the name to be more clear name to avoid confusion.
* [Universal parser] Decouple IMEMO from rb_ast_tHASUMI Hitoshi2024-04-261-16/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch removes the `VALUE flags` member from the `rb_ast_t` structure making `rb_ast_t` no longer an IMEMO object. ## Background We are trying to make the Ruby parser generated from parse.y a universal parser that can be used by other implementations such as mruby. To achieve this, it is necessary to exclude VALUE and IMEMO from parse.y, AST, and NODE. ## Summary (file by file) - `rubyparser.h` - Remove the `VALUE flags` member from `rb_ast_t` - `ruby_parser.c` and `internal/ruby_parser.h` - Use TypedData_Make_Struct VALUE which wraps `rb_ast_t` `in ast_alloc()` so that GC can manage it - You can retrieve `rb_ast_t` from the VALUE by `rb_ruby_ast_data_get()` - Change the return type of `rb_parser_compile_XXXX()` functions from `rb_ast_t *` to `VALUE` - rb_ruby_ast_new() which internally `calls ast_alloc()` is to create VALUE vast outside ruby_parser.c - `iseq.c` and `vm_core.h` - Amend the first parameter of `rb_iseq_new_XXXX()` functions from `rb_ast_body_t *` to `VALUE` - This keeps the VALUE of AST on the machine stack to prevent being removed by GC - `ast.c` - Almost all change is replacement `rb_ast_t *ast` with `VALUE vast` (sorry for the big diff) - Fix `node_memsize()` - Now it includes `rb_ast_local_table_link`, `tokens` and script_lines - `compile.c`, `load.c`, `node.c`, `parse.y`, `proc.c`, `ruby.c`, `template/prelude.c.tmpl`, `vm.c` and `vm_eval.c` - Follow-up due to the above changes - `imemo.{c|h}` - If an object with `imemo_ast` appears, considers it a bug Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
* [PRISM] Raise LoadError when file cannot be readKevin Newton2024-04-251-1/+1
|
* Eliminate usage of OBJ_FREEZE_RAWJean Boussier2024-04-161-3/+3
| | | | | | | | | | Previously it would bypass the `FL_ABLE` check, but since shapes introduction, it started having a different behavior than `OBJ_FREEZE`, as it would onyl set the `FL_FREEZE` flag, but not update the shape. I have no indication of this causing a bug yet, but it seems like a trap waiting to happen.
* [Universal parser] DeVALUE of p->debug_lines and ast->body.script_linesHASUMI Hitoshi2024-04-151-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch is part of universal parser work. ## Summary - Decouple VALUE from members below: - `(struct parser_params *)->debug_lines` - `(rb_ast_t *)->body.script_lines` - Instead, they are now `rb_parser_ary_t *` - They can also be a `(VALUE)FIXNUM` as before to hold line count - `ISEQ_BODY(iseq)->variable.script_lines` remains VALUE - In order to do this, - Add `VALUE script_lines` param to `rb_iseq_new_with_opt()` - Introduce `rb_parser_build_script_lines_from()` to convert `rb_parser_ary_t *` into `VALUE` ## Other details - Extend `rb_parser_ary_t *`. It previously could only store `rb_parser_ast_token *`, now can store script_lines, too - Change tactics of building the top-level `SCRIPT_LINES__` in `yycompile0()` - Before: While parsing, each line of the script is added to `SCRIPT_LINES__[path]` - After: After `yyparse(p)`, `SCRIPT_LINES__[path]` will be built from `p->debug_lines` - Remove the second parameter of `rb_parser_set_script_lines()` to make it simple - Introduce `script_lines_free()` to be called from `rb_ast_free()` because the GC no longer takes care of the script_lines - Introduce `rb_parser_string_deep_copy()` in parse.y to maintain script_lines when `rb_ruby_parser_free()` called - With regard to this, please see *Future tasks* below ## Future tasks - Decouple IMEMO from `rb_ast_t *` - This lifts the five-members-restriction of Ruby object, - So we will be able to move the ownership of the `lex.string_buffer` from parser to AST - Then we remove `rb_parser_string_deep_copy()` to make the whole thing simple
* Merge `push_include` and `ruby_push_include`Nobuyoshi Nakada2024-04-071-9/+2
|
* Merge `push_include_cygwin` into `push_include`Nobuyoshi Nakada2024-04-071-27/+18
|
* Remove `translit_char`Nobuyoshi Nakada2024-04-071-2/+0
| | | | It has been used only for DOSISH other than Windows.
* [Feature #20329] Separate additional flags from main dump optionsNobuyoshi Nakada2024-04-061-41/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Additional flags are comma separated list preceeded by `-` or `+`. Before: ```sh $ ruby --dump=insns+without_opt ``` After: ```sh $ ruby --dump=insns-opt,-optimize ``` At the same time, `parsetree_with_comment` is split to `parsetree` option and additional `comment` flag. Before: ```sh $ ruby --dump=parsetree_with_comment ``` After: ```sh $ ruby --dump=parsetree,+comment ``` Also flags can be separate `--dump`. ```sh $ ruby --dump=parsetree --dump=+comment --dump=+error_tolerant ``` Ineffective flags are ignored silently. ```sh $ ruby --dump=parsetree --dump=+comment --dump=+error_tolerant ```
* [Feature #20329] Clean up dump sub-optionsNobuyoshi Nakada2024-04-061-19/+29
| | | | | | Restructure `insns_without_opt` and `parsetree_with_comment` as `insns+without_opt` and `parsetree+with_comment` respectively, like `+error-tolerant`.
* Separate SCRIPT_LINES__ from ast.cHASUMI Hitoshi2024-04-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch suggests relocating the code dealing with `SCRIPT_LINES__` from ast.c to ruby_parser.c. ## Background - I guess `AbstractSyntaxTree.of` method used to use `SCRIPT_LINES__` internally for some reason before - However, now it appears `SCRIPT_LINES__` is no longer used meaningfully by the method - As evidence of this, (and as my patch shows,) removing the function call of `rb_script_lines_for()` from `ast_s_of()` does not affect the result of `test/ruby/test_ast.rb` Given the above, I think two possibilities can be considered: - (A) `AbstractSyntaxTree.of` has not needed `SCRIPT_LINES__` already (I pick this) - (B) We lack a test case of `AbstractSyntaxTree.of` that needs to use `SCRIPT_LINES__` ## Besides, The current implementation causes strange behavior: ```console ruby -e"SCRIPT_LINES__ = {__FILE__ => []}; puts RubyVM::AbstractSyntaxTree.of(->{ 1 + 2 }, keep_script_lines: true).script_lines" => `-e:1:in '<main>': undefined method 'script_lines' for nil (NoMethodError)` ``` I think this is a bug because `AbstractSyntaxTree.of` is not supposed to return `nil` even in this case. This happens due to the ast.c's dependence on `SCRIPT_LINES__`. And at the end of the `ast_s_of()`, `node_find()` can not find the target child node obviously because it doesn't make sense to look for a corresponding node made from the parameter of `AbstractSyntaxTree.of` in the AST tree made from the value of `{__FILE__ => []}` ## Solution Since I think it's good enough `SCRIPT_LINES__` to be only referred by ruby.c, I chose the possibility "(A)" and wrote this patch which moves `rb_script_lines_for()` from ast.c to ruby_parser.c. So as the result: - `ast_s_of()` function no longer look up `SCRIPT_LINES__` - Even so, this patched code passes the existing tests - The strange behavior above no longer happens (I also added a test for it) Please correct me if I miss something🙏
* [PRISM] Pass --enable-frozen-string-literal through to evalsKevin Newton2024-03-271-2/+0
|
* Implement chilled stringsÉtienne Barrié2024-03-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [Feature #20205] As a path toward enabling frozen string literals by default in the future, this commit introduce "chilled strings". From a user perspective chilled strings pretend to be frozen, but on the first attempt to mutate them, they lose their frozen status and emit a warning rather than to raise a `FrozenError`. Implementation wise, `rb_compile_option_struct.frozen_string_literal` is no longer a boolean but a tri-state of `enabled/disabled/unset`. When code is compiled with frozen string literals neither explictly enabled or disabled, string literals are compiled with a new `putchilledstring` instruction. This instruction is identical to `putstring` except it marks the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags. Chilled strings have the `FL_FREEZE` flag as to minimize the need to check for chilled strings across the codebase, and to improve compatibility with C extensions. Notes: - `String#freeze`: clears the chilled flag. - `String#-@`: acts as if the string was mutable. - `String#+@`: acts as if the string was mutable. - `String#clone`: copies the chilled flag. Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
* [PRISM] Process encoding on CLI for -KKevin Newton2024-03-181-0/+4
|
* Refactor frozen_string_literal check during compilationJean Boussier2024-03-151-0/+2
| | | | | | | In preparation for https://bugs.ruby-lang.org/issues/20205. The `frozen_string_literal` compilation option will no longer be a boolean but a tri-state: `on/off/default`.
* Chomp last punctuations from descriptions for `-h`Nobuyoshi Nakada2024-03-141-2/+3
| | | | | | | The following parts will not be shown for `-h` option. And not to reach 80 columns. Some terminal emulators (Windows command prompt at least) wrap the cursor to the next line when reaching the rightmost column, before exceeding.
* `--dump=prism_parsetree` is no longer providedNobuyoshi Nakada2024-03-131-1/+0
| | | | | Since it did not make sense without `--parser=prism` option, just a duplication. Now it is `--parser=prism --dump=parsetree`.
* Revisions for #10198Takashi Kokubun2024-03-121-4/+4
| | | | This fixes some inconsistencies introduced by that PR.
* Revisions for help text (#10198)Burdette Lamar2024-03-121-57/+60
|
* [PRISM] Parse stdin on CLI with prismKevin Newton2024-03-111-1/+5
|
* Refactor VM root modulesJean Boussier2024-03-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This `st_table` is used to both mark and pin classes defined from the C API. But `vm->mark_object_ary` already does both much more efficiently. Currently a Ruby process starts with 252 rooted classes, which uses `7224B` in an `st_table` or `2016B` in an `RArray`. So a baseline of 5kB saved, but since `mark_object_ary` is preallocated with `1024` slots but only use `405` of them, it's a net `7kB` save. `vm->mark_object_ary` is also being refactored. Prior to this changes, `mark_object_ary` was a regular `RArray`, but since this allows for references to be moved, it was marked a second time from `rb_vm_mark()` to pin these objects. This has the detrimental effect of marking these references on every minors even though it's a mostly append only list. But using a custom TypedData we can save from having to mark all the references on minor GC runs. Addtionally, immediate values are now ignored and not appended to `vm->mark_object_ary` as it's just wasted space.
* [PRISM] Use new command line option flagsKevin Newton2024-02-291-5/+12
|
* [PRISM] Do not load -r until we check if main script can be readKevin Newton2024-02-281-9/+34
|
* [PRISM] Factor in CLI options for prismKevin Newton2024-02-281-3/+7
|
* Update warning flags before dumpNobuyoshi Nakada2024-02-201-2/+2
|
* [PRISM] Make prism compiler warning experimentalKevin Newton2024-02-161-4/+10
|
* Abort when streaming code from stdin with PrismNobuyoshi Nakada2024-02-161-6/+1
| | | | Do not read STDIN as a String instance.
* Use ID without cache and fix conversion of offsetNobuyoshi Nakada2024-02-161-1/+1
|
* Extract `process_options_global_setup`Nobuyoshi Nakada2024-02-161-36/+33
|
* Extract functions depending on `--parser` optionNobuyoshi Nakada2024-02-161-146/+145
|
* Extract `show_help` functionNobuyoshi Nakada2024-02-161-52/+58
|
* Dispose AST before exit by yydebugNobuyoshi Nakada2024-02-161-1/+4
|
* Do not include a backtick in error messages and backtracesYusuke Endoh2024-02-151-8/+8
| | | | [Feature #16495]
* [PRISM] Correctly hook up line numbers for evalKevin Newton2024-02-141-0/+5
|
* Enable redefinition check for rbinc methodsNobuyoshi Nakada2024-02-121-0/+5
|
* [PRISM] Run opt init before parsingKevin Newton2024-02-081-1/+1
|
* [PRISM] Support the DATA constantKevin Newton2024-02-081-0/+15
|
* Raise errors for dumping prism parse treeKevin Newton2024-01-311-21/+19
|
* [PRISM] Mirror iseq APIsKevin Newton2024-01-311-18/+17
| | | | | | | | | | | | | Before this commit, we were mixing a lot of concerns with the prism compile between RubyVM::InstructionSequence and the general entry points to the prism parser/compiler. This commit makes all of the various prism-related APIs mirror their corresponding APIs in the existing parser/compiler. This means we now have the correct frame naming, and it's much easier to follow where the logic actually flows. Furthermore this consolidates a lot of the prism initialization, making it easier to see where we could potentially be raising errors.
* [Prism] path and script name are not the sameMatt Valentine-House2024-01-221-1/+1
| | | | | When loading Ruby from a file, or parsing using RubyVM::InstructionSequence.
* Make prism respect dump_without_optKevin Newton2024-01-221-1/+2
|
* Fix off-by-one error of argcNobuyoshi Nakada2024-01-171-2/+2
| | | | Fix ruby/ruby#9562
* Fix possible out-of-bounds accessNobuyoshi Nakada2024-01-131-1/+1
|