summaryrefslogtreecommitdiff
path: root/ruby.c
AgeCommit message (Collapse)Author
2024-04-06[Feature #20329] Clean up dump sub-optionsNobuyoshi Nakada
Restructure `insns_without_opt` and `parsetree_with_comment` as `insns+without_opt` and `parsetree+with_comment` respectively, like `+error-tolerant`.
2024-04-04Separate SCRIPT_LINES__ from ast.cHASUMI Hitoshi
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🙏
2024-03-27[PRISM] Pass --enable-frozen-string-literal through to evalsKevin Newton
2024-03-19Implement chilled stringsÉtienne Barrié
[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 <[email protected]>
2024-03-18[PRISM] Process encoding on CLI for -KKevin Newton
2024-03-15Refactor frozen_string_literal check during compilationJean Boussier
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`.
2024-03-14Chomp last punctuations from descriptions for `-h`Nobuyoshi Nakada
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.
2024-03-13`--dump=prism_parsetree` is no longer providedNobuyoshi Nakada
Since it did not make sense without `--parser=prism` option, just a duplication. Now it is `--parser=prism --dump=parsetree`.
2024-03-12Revisions for #10198Takashi Kokubun
This fixes some inconsistencies introduced by that PR.
2024-03-12Revisions for help text (#10198)Burdette Lamar
2024-03-11[PRISM] Parse stdin on CLI with prismKevin Newton
2024-03-06Refactor VM root modulesJean Boussier
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.
2024-02-29[PRISM] Use new command line option flagsKevin Newton
2024-02-28[PRISM] Do not load -r until we check if main script can be readKevin Newton
2024-02-28[PRISM] Factor in CLI options for prismKevin Newton
2024-02-20Update warning flags before dumpNobuyoshi Nakada
2024-02-16[PRISM] Make prism compiler warning experimentalKevin Newton
2024-02-16Abort when streaming code from stdin with PrismNobuyoshi Nakada
Do not read STDIN as a String instance.
2024-02-16Use ID without cache and fix conversion of offsetNobuyoshi Nakada
2024-02-16Extract `process_options_global_setup`Nobuyoshi Nakada
2024-02-16Extract functions depending on `--parser` optionNobuyoshi Nakada
2024-02-16Extract `show_help` functionNobuyoshi Nakada
2024-02-16Dispose AST before exit by yydebugNobuyoshi Nakada
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-02-14[PRISM] Correctly hook up line numbers for evalKevin Newton
2024-02-12Enable redefinition check for rbinc methodsNobuyoshi Nakada
2024-02-08[PRISM] Run opt init before parsingKevin Newton
2024-02-08[PRISM] Support the DATA constantKevin Newton
2024-01-31Raise errors for dumping prism parse treeKevin Newton
2024-01-31[PRISM] Mirror iseq APIsKevin Newton
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.
2024-01-22[Prism] path and script name are not the sameMatt Valentine-House
When loading Ruby from a file, or parsing using RubyVM::InstructionSequence.
2024-01-22Make prism respect dump_without_optKevin Newton
2024-01-17Fix off-by-one error of argcNobuyoshi Nakada
Fix ruby/ruby#9562
2024-01-13Fix possible out-of-bounds accessNobuyoshi Nakada
2023-12-21RJIT: Add --rjit-trace to allow TracePoint during JITTakashi Kokubun
2023-12-20Correct free_on_exit env var to free_at_exitHParker
2023-12-19We need to load builtins so that they workAaron Patterson
Before this commit no methods defined in Ruby were being loaded. For example `class` or `tap` methods would not exist. [ruby-core:115793] [Bug #20073]
2023-12-18[PRISM] Fix crash when --parser=prism called with stdinMatt Valentine-House
[Bug #20071] Currently Ruby crashes when the --parser=prism flag is used either with no input, or with input that is being redirected from stdin. So all of the following will crash ruby --parser=prism ruby --parser=prism < test_code.rb cat test_code.rb | ruby --parser=prism This commit checks whether the input is assumed to be from stdin, and then processes that as a file. This will fix the second and third case above, but will cause a slight behavioural changes for the first case - Ruby will treat stdin as an empty file in this case and exit, rather than waiting for data to be piped into stdin.
2023-12-17Adjust styles [ci skip]Nobuyoshi Nakada
2023-12-15update message to clarify compiler, not parserAdam Hess
Co-authored-by: Ufuk Kayserilioglu <[email protected]>
2023-12-15Introduce --parser runtime flagHParker
Introduce runtime flag for specifying the parser, ``` ruby --parser=prism ``` also update the description: ``` $ ruby --parser=prism --version ruby 3.3.0dev (2023-12-08T04:47:14Z add-parser-runtime.. 0616384c9f) +PRISM [x86_64-darwin23] ``` [Bug #20044]
2023-12-13Avoid warning --jit when only YJIT is enabledTakashi Kokubun
2023-12-07Free everything at shutdownAdam Hess
when the RUBY_FREE_ON_SHUTDOWN environment variable is set, manually free memory at shutdown. Co-authored-by: Nobuyoshi Nakada <[email protected]> Co-authored-by: Peter Zhu <[email protected]>
2023-12-06Revert "allow enabling Prism via flag or env var"HParker
This reverts commit 9b76c7fc89460ed8e9be40e4037c1d68395c0f6d.
2023-12-06Adjust styles [ci skip]Nobuyoshi Nakada
2023-12-05allow enabling Prism via flag or env varHParker
Enable Prism using either --prism ruby --prism test.rb or via env var RUBY_PRISM=1 ruby test.rb
2023-12-04Remove `rb_libruby_selfpath` for MJITNobuyoshi Nakada
2023-11-03[prism] Update to use new options APIsKevin Newton
2023-11-02YJIT: Always define method codegen table at boot (#8807)Takashi Kokubun
2023-10-26Use new prism prettyprint APIsKevin Newton