summaryrefslogtreecommitdiff
path: root/prism_compile.h
AgeCommit message (Collapse)Author
2025-01-14[PRISM] Handle forwarding inside evalKevin Newton
Fixes [Bug #21031] Notes: Merged: https://github.com/ruby/ruby/pull/12575
2024-11-08Fix memory leak in prism when syntax error in iseq compilationPeter Zhu
If there's a syntax error during iseq compilation then prism would leak memory because it would not free the pm_parse_result_t. This commit changes pm_iseq_new_with_opt to have a rb_protect to catch when an error is raised, and return NULL and set error_state to a value that can be raised by calling rb_jump_tag after memory has been freed. For example: 10.times do 10_000.times do eval("/[/=~s") rescue SyntaxError end puts `ps -o rss= -p #{$$}` end Before: 39280 68736 99232 128864 158896 188208 217344 246304 275376 304592 After: 12192 13200 14256 14848 16000 16000 16000 16064 17232 17952 Notes: Merged: https://github.com/ruby/ruby/pull/12036
2024-10-02Make default parser enum and define getter/setterNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11761
2024-08-29[PRISM] Handle RubyVM.keep_script_linesKevin Newton
Notes: Merged: https://github.com/ruby/ruby/pull/11501
2024-05-20[PRISM] Respect eval coverage settingKevin Newton
2024-04-25[PRISM] Raise LoadError when file cannot be readKevin Newton
2024-03-29[PRISM] Fix BEGIN{} execution orderKevin Newton
2024-03-27[PRISM] Set path on syntax errorKevin Newton
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-11[PRISM] Parse stdin on CLI with prismKevin Newton
2024-02-28[PRISM] Only look up encoding once per fileKevin Newton
2024-02-28[PRISM] Do not load -r until we check if main script can be readKevin Newton
2024-02-08[PRISM] Compile constant reads using opt_getconstant_pathKevin 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-18[PRISM] Add function to free scope nodePeter Zhu
pm_scope_node_destroy frees the scope node after we're done using it to make sure that the index_lookup_table is not leaked. For example: 10.times do 100_000.times do RubyVM::InstructionSequence.compile_prism("begin; 1; rescue; 2; end") end puts `ps -o rss= -p #{$$}` end Before: 33056 50304 67776 84544 101520 118448 135712 152352 169136 186656 After: 15264 15296 15408 17040 17152 17152 18320 18352 18400 18608
2024-01-16Remove scope_node->local_depth_offsetMatt Valentine-House
2024-01-16Bind index & depth together into pm_local_index_tMatt Valentine-House
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-11[PRISM] Restructure parameters on ScopeNodesJemma Issroff
This commit completely restructures how we handle parameters. The motivation for this commit was the fix compilation of MultiTargetNodes within parameters, including nested MultiTargetNodes. A subsequent commit will actually do the compilation for the MultiTargetNodes. This commit's main accomplishment is restructuring the locals table and how we account for it on the ScopeNode, specifically with regards to hidden variables. It has multiple steps, all commented within the code, to calculate the locals table correctly and compile the parameters: - Step 1: Caculate the table size for the locals - Step 2: Populate iv index table and local table - Step 3: Fill in parameter names of MultiTargetNodes on local table - Step 4: Fill in method body locals on local table - Step 5: Compile any locals
2023-12-01[PRISM] Restructure parametersJemma Issroff
Prior to this commit, we weren't accounting for hidden variables on the locals table, so we would have inconsistencies on the stack. This commit fixes params, and introduces a hidden_variable_count on the scope, both of which fix parameters.
2023-11-30Store depth offset inside the scope node.Matt Valentine-House
Instead of incrementing the depth using call by reference as we're recursing up the stack we could instead store an offset for each known scope where we know the depth is going to represented differently in the Prism ast.
2023-10-25[PRISM] ScopeNode doesn't need void * anymoreJemma Issroff
2023-10-25[PRISM] Move scope_node itself to CRuby, create prism_compile.hJemma Issroff