Project

General

Profile

Actions

Feature #18231

closed

`RubyVM.keep_script_lines`

Added by ko1 (Koichi Sasada) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Target version:
[ruby-core:105500]

Description

This ticket proposes the method RubyVM.keep_script_lines to manage the flag to keep the source code.

Now, SCRIPT_LINES__ = {} constant is defined, the hash will stores the compiled script with a path name ({path => src}). However, eval source code doesn't stores in it (maybe because it can be bigger and bigger).

Proposal

This proposal to add script lines to the ISeq and AST.

RubyVM::keep_script_lines = true

eval("def foo = nil\ndef bar = nil")
pp RubyVM::InstructionSequence.of(method(:foo)).script_lines
#=> ["def foo = nil\n", "def bar = nil"]

In this case, methods foo and bar are defined by eval() and ISeq of foo can returns script lines (all script for eval).
ISeq#script_lines returns compiled script lines.

When ISeq is GCed, then the source code will be also free'ed.

Discussion

  • This feature will be used by debugger (to show the source code) or REPL support (irb and so on) with error_highlight.
  • Of course memory usage will be increased.
  • We can introduce new status only_eval in future which will help REPL systems.
  • We can implement ISeq#source method like AST#source method (similar to toSource in JavaScript), but this ticket doesn't contain it.

Implementation

https://github.com/ruby/ruby/pull/4913

For the Ractor support script lines object should be immutable (not implemented yet).


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #17930: Add column information into error backtraceClosedmame (Yusuke Endoh)Actions
Related to Ruby master - Feature #18159: Integrate functionality of syntax_suggest gem into RubyClosedhsbt (Hiroshi SHIBATA)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0