Project

General

Profile

Actions

Bug #19368

open

Small issue with isolated procs and eval

Bug #19368: Small issue with isolated procs and eval

Added by luke-gru (Luke Gruber) almost 3 years ago. Updated almost 3 years ago.

Status:
Assigned
Target version:
-
[ruby-core:111971]

Description

a = Object.new # non-shareable prok = Ractor.current.instance_eval do Proc.new do eval('a') end end prok.call # this should work, we're in the main ractor and the proc is not isolated Ractor.make_shareable(prok) # this doesn't currently work, but I think it should. It gives Ractor::IsolationError. See below for reasoning on why I think it should work. # A flag seems to be set on the proc after it's run and accesses outers... 

Because this work fine:

a = Object.new # non-shareable prok = Ractor.current.instance_eval do Proc.new do eval('a') end end Ractor.make_shareable(prok) # this works, and it's okay because we get a different error when actually running the shareable proc inside a ractor that accesses outers through eval. 

Updated by luke-gru (Luke Gruber) almost 3 years ago Actions #1 [ruby-core:111972]

Hopefully this illustrates this small, weird issue a bit more:

fails = 0 a = Object.new # non-shareable value pr_maker = Ractor.current.instance_eval do # instance eval allows make_shareable to work Proc.new do Proc.new do |sym| # line 'x', let's call it. See below. if sym == :eval p 'evaling' eval('a') else p 'not evaling' end end end end PROC = pr_maker.call # so we can access in non-main ractor, we set constant Ractor.make_shareable(PROC) begin PROC.call(:eval) # this gives an error because the proc is now isolated. That's good. It shouldn't be # a SyntaxError, but so far so good. Ruby also sets a flag on the compilation node of line 'x' that it accesses outers. rescue SyntaxError => e fails +=1 if e.message.match?(/can not access variable `a' from isolated Proc/) end p fails # The flag is actually set somewhere during compilation, not on the proc object. If we # make a new proc, the issue stays the same. PROC = pr_maker.call # can't make it shareable now, even though it won't access outers if called without :eval symbol # This error should be during runtime of the proc IMO, not statically on the nodes themselves. Ractor.make_shareable(PROC) # this call fails fails += Ractor.new do fails = 0 begin PROC.call(:no_eval) # We don't reach here, but this should give the same error as above (for now, it's SyntaxError) rescue SyntaxError => e fails +=1 if e.message.match?(/can not access variable `a' from isolated Proc/) end fails end.take fails p fails 

Updated by luke-gru (Luke Gruber) almost 3 years ago Actions #2

  • Tracker changed from Bug to Misc
  • Subject changed from Ractor.make_shareable issue/inconsistency when proc has been run that acesses outers through eval to Misunderstanding on my part, please close issue
  • Backport deleted (2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN)

Updated by luke-gru (Luke Gruber) almost 3 years ago Actions #3

  • Tracker changed from Misc to Bug
  • Backport set to 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN

Updated by luke-gru (Luke Gruber) almost 3 years ago Actions #4

  • Subject changed from Misunderstanding on my part, please close issue to Small issue with isolated procs and eval

Updated by hsbt (Hiroshi SHIBATA) almost 3 years ago Actions #5 [ruby-core:111976]

  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)
Actions

Also available in: PDF Atom