Project

General

Profile

Actions

Bug #20856

closed

Incorrect and inconsistent multi-thread eval execution with Prism compiler

Added by hurricup (Alexandr Evstigneev) 19 days ago. Updated 13 days ago.

Status:
Closed
Assignee:
Target version:
-
ruby -v:
3.4.0-preview2
[ruby-core:119649]

Description

Consider example:

s = Thread.new {
  a = 5
  puts eval("a == b") 
  x = 6 
}
s.join
b = 11

As far as I see it, it should not work. Because at the moment of eval, b is unknown and not even declared (it can even be in condition).
But it may be available because file iseq already compiled and we know that there is b.

So, this works in ruby 3.3 in a script we running, wrapped into the method, or required by other file.

But in 3.4-preview2:

  • it works in file
  • it works in method
  • it fails if required from other file with:
#<Thread:0x00007725530d6a98 /home/hurricup/Projects/ruby-debugger/rdi30/test2.rb:1 run> terminated with exception (report_on_exception is true):
(eval at /home/hurricup/Projects/ruby-debugger/rdi30/test2.rb:3):1:in 'block in <top (required)>': undefined local variable or method 'b' for main (NameError)
	from /home/hurricup/Projects/ruby-debugger/rdi30/test2.rb:3:in 'Kernel#eval'
	from /home/hurricup/Projects/ruby-debugger/rdi30/test2.rb:3:in 'block in <top (required)>'
(eval at /home/hurricup/Projects/ruby-debugger/rdi30/test2.rb:3):1:in 'block in <top (required)>': undefined local variable or method 'b' for main (NameError)
	from /home/hurricup/Projects/ruby-debugger/rdi30/test2.rb:3:in 'Kernel#eval'
	from /home/hurricup/Projects/ruby-debugger/rdi30/test2.rb:3:in 'block in <top (required)>'

And this ^^ is correct behavior if you ask me :) but atm it is inconsistent between the ruby versions and even in the scope of 3.4-preview2

Updated by Eregon (Benoit Daloze) 18 days ago ยท Edited

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED

It's a bug of 3.4.0-preview2 and specifically of the Prism compiler, 3.3 and earlier and --parser=parse.y succeed for all cases.

The order is:

  • parse that file:
  • execute it
  • in that new thread eval is called
  • that parses a == b, with outer scopes [[a,x], [s,b]] (all local variables are hoisted to the start of the method/block in Ruby).

Updated by Eregon (Benoit Daloze) 18 days ago

  • Subject changed from Incorrect and inconsistent multi-thread eval execution to Incorrect and inconsistent multi-thread eval execution with Prism compiler
  • Assignee set to kddnewton (Kevin Newton)

Updated by Eregon (Benoit Daloze) 18 days ago

  • Assignee changed from kddnewton (Kevin Newton) to prism

Updated by kddnewton (Kevin Newton) 14 days ago

Thanks for the report, it should be fixed by https://github.com/ruby/ruby/pull/11993.

Actions #5

Updated by kddnewton (Kevin Newton) 13 days ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0