ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: dale.hamel@srvthe.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:94384] [Ruby master Feature#12093] Eval InstructionSequence with binding
Date: Fri, 16 Aug 2019 12:36:08 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-80799.20190816123608.ec0a69be4e559aae@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-12093.20160220120020@ruby-lang.org

Issue #12093 has been updated by dalehamel (Dale Hamel).


Yes when I test out Koichi's sample, the iseq look like:

```
disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,6)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 opt_send_without_block       <callinfo!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0004 putself
0005 opt_send_without_block       <callinfo!mid:b, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0008 newarray                     2
0010 leave
```

So there is no way for the local variables from the binding to be evaluated, as the original instruction sequence expects a method call. I hadn't realized that when compiling the iseq string, methods calls are found in this way.

This indicates that yeah, Nobu's comment above appears correct, you must have the binding available when the iseq is compiled. It appears to do so implicitly based on the current binding.



----------------------------------------
Feature #12093: Eval InstructionSequence with binding
https://bugs.ruby-lang.org/issues/12093#change-80799

* Author: pavel.evstigneev (Pavel Evstigneev)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Implementing this feature can boost template engine performance

Currently Kernel#eval can accept binding argument, so code running with eval will have access to local variables and current instance. This feature used by template languages

ERB: https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L887
Erubis: Can't find code on github, but it uses instance_eval or Kernel#eval
Haml: https://github.com/haml/haml/blob/master/lib/haml/engine.rb#L115

My proposal is to make RubyVM::InstructionSequence#eval to recieve binding argument. So it can be used for caching templates. As I see from ERB and Haml, cached template is stored as ruby code string, every time when we render template that string (ruby code) is evaluated, internally ruby will parse it into RubyVM::InstructionSequence and then evaluate.

Before I try to implement it myself in ruby, but could not. Lack of experience with C https://github.com/Paxa/ruby/commit/f5b602b6d9eada9675a4c002c9a5a79129df73a6 (not working)

---Files--------------------------------
0002-Update-iseq.eval-to-accept-optional-binding-FIXES-Bu.patch (4.83 KB)
0001-RubyVM-InstructionSequence-eval_with.patch (2.91 KB)


-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2019-08-16 12:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-12093.20160220120020@ruby-lang.org>
2016-02-20 12:00 ` [ruby-core:73901] [CommonRuby Feature#12093] Eval InstructionSequence with binding pavel.evst
2016-02-21  4:53 ` [ruby-core:73906] [Ruby trunk " nobu
2016-02-22  8:06 ` [ruby-core:73918] " nobu
2016-03-03  5:10 ` [ruby-core:74103] " shyouhei
2016-03-04 14:44 ` [ruby-core:74140] " nobu
2016-09-29  5:41 ` [ruby-core:77452] " nobu
2019-07-22 16:51 ` [ruby-core:93868] [Ruby master " dale.hamel
2019-07-23  4:35 ` [ruby-core:93877] " dale.hamel
2019-07-23 15:01 ` [ruby-core:93885] " shevegen
2019-07-23 15:14 ` [ruby-core:93889] " dale.hamel
2019-08-16  2:01 ` [ruby-core:94378] " ko1
2019-08-16 12:36 ` dale.hamel [this message]
2019-08-16 12:53 ` [ruby-core:94385] " ko1
2019-08-16 14:39 ` [ruby-core:94389] " dale.hamel
2019-08-17 23:49 ` [ruby-core:94406] " nobu
2019-08-24  5:10 ` [ruby-core:94524] " dale.hamel

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-80799.20190816123608.ec0a69be4e559aae@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).