[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
Issue #18228 has been reported by byroot (Jean Boussier).
11 messages
2021/09/27
[ruby-core:105513] [Ruby master Feature#18231] `RubyVM.keep_script_lines`
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-09-30 20:03:22 UTC
List:
ruby-core #105513
Issue #18231 has been updated by Eregon (Benoit Daloze).
ko1 (Koichi Sasada) wrote in #note-2:
> It is ISeq/AST related API so it should be internal.
I don't see how it is ISeq or AST-related.
The new `script_lines` just returns the source code as an array of strings for a given method.
So, why not simply {Method,UnboundMethod}#script_lines and e.g. Method.keep_script_lines = true?
----------------------------------------
Feature #18231: `RubyVM.keep_script_lines`
https://bugs.ruby-lang.org/issues/18231#change-93960
* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 3.1
----------------------------------------
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.
```ruby
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).
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>