ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "ko1 (Koichi Sasada)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105543] [Ruby master Feature#18231] `RubyVM.keep_script_lines`
Date: Mon, 04 Oct 2021 17:20:47 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-94000.20211004172046.17@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18231.20210930081612.17@ruby-lang.org

Issue #18231 has been updated by ko1 (Koichi Sasada).


Some comments:

* For debugger, `Thread::Backtrace::Location#script_lines` is enough.
* If we introduce this feature outside of `RubyVM`, people can use it casually and I'm not sure we can support it well because this feature (keeping all loaded sources). For example, if I install rails with `gem install rails` and `[master]$ du -sh .../lib/ruby/gems/3.1.0/gems/` returns 72MB.

----------------------------------------
Feature #18231: `RubyVM.keep_script_lines`
https://bugs.ruby-lang.org/issues/18231#change-94000

* 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/

  parent reply	other threads:[~2021-10-04 17:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30  8:16 [ruby-core:105500] [Ruby master Feature#18231] `RubyVM.keep_script_lines` ko1 (Koichi Sasada)
2021-09-30  9:13 ` [ruby-core:105501] " Eregon (Benoit Daloze)
2021-09-30 12:00 ` [ruby-core:105505] " ko1 (Koichi Sasada)
2021-09-30 20:03 ` [ruby-core:105513] " Eregon (Benoit Daloze)
2021-10-01  1:07 ` [ruby-core:105516] " ko1 (Koichi Sasada)
2021-10-02 10:36 ` [ruby-core:105522] " Eregon (Benoit Daloze)
2021-10-02 14:46 ` [ruby-core:105524] " ko1 (Koichi Sasada)
2021-10-02 14:51 ` [ruby-core:105525] " ko1 (Koichi Sasada)
2021-10-03  8:31 ` [ruby-core:105528] " duerst
2021-10-03  9:53 ` [ruby-core:105529] " Eregon (Benoit Daloze)
2021-10-03  9:59 ` [ruby-core:105530] " Eregon (Benoit Daloze)
2021-10-04  3:05 ` [ruby-core:105535] " matz (Yukihiro Matsumoto)
2021-10-04  9:38 ` [ruby-core:105538] " Eregon (Benoit Daloze)
2021-10-04 12:29 ` [ruby-core:105539] " ko1 (Koichi Sasada)
2021-10-04 12:38 ` [ruby-core:105540] " Eregon (Benoit Daloze)
2021-10-04 15:02 ` [ruby-core:105541] " ko1 (Koichi Sasada)
2021-10-04 16:51 ` [ruby-core:105542] " Eregon (Benoit Daloze)
2021-10-04 17:20 ` ko1 (Koichi Sasada) [this message]
2021-12-14 16:58 ` [ruby-core:106672] " ko1 (Koichi Sasada)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-94000.20211004172046.17@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).