Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange error in implicit return of match variable #3104

Closed
gavin-scott opened this Issue Jul 4, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@gavin-scott
Copy link

gavin-scott commented Jul 4, 2015

In some cases implicitly returned match variables ($1) are being incorrectly returned as nil. Using an explicit return fixes the issue. This was seen on jruby 9.0.0.0.rc1.

Here is a simple script that reproduces the issue:

[gscott@dev tmp]$ jruby --version
jruby 9.0.0.0.rc1 (2.2.2) 2015-06-10 a0bf3b3 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-amd64]
[gscott@dev tmp]$ cat test.rb
def parse_char_with_return(string)
  if string =~ /Prefix (\w)/
    puts "++> parse_char_with_return(#{string}) = #{$1}"
    return $1
  end
end

def parse_char_wo_return(string)
  if string =~ /Prefix (\w)/
    puts "++> parse_char_wo_return(#{string}) = #{$1}"
    $1
  end
end

ret = parse_char_with_return("Prefix A")
puts "==> parse_char_with_return(Prefix A) = #{ret.inspect}"
raise(Exception, 'Failed to return correct value') if ret.nil?

puts ''
ret = parse_char_wo_return("Prefix A")
puts "==> parse_char_wo_return(Prefix A) = #{ret.inspect}"
[gscott@dev tmp]$ jruby test.rb
++> parse_char_with_return(Prefix A) = A
==> parse_char_with_return(Prefix A) = "A"

++> parse_char_wo_return(Prefix A) = A
==> parse_char_wo_return(Prefix A) = nil

Both parse_char_with_return and parse_char_wo_return should return "A" but the latter returns nil as shown above.

@enebo enebo added this to the JRuby 9.0.0.0.rc2 milestone Jul 4, 2015

@donv

This comment has been minimized.

Copy link
Member

donv commented Jul 6, 2015

Duplicate of #3031 I think.

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Jul 6, 2015

@donv you think so? Yours implies a concurrency issue but this one I do not see that happening. Same result but perhaps different problem.

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Jul 6, 2015

Ok startup interpreter does not have this issue:

jruby -X-C ../snippets/cat1.rb 
++> parse_char_with_return(Prefix A) = A
==> parse_char_with_return(Prefix A) = "A"

++> parse_char_wo_return(Prefix A) = A
==> parse_char_wo_return(Prefix A) = "A"

Full build interpreter does have this issue:

jruby -X-C -Xjit.threshold=0 -Xjit.background=false ../snippets/cat1.rb 
++> parse_char_with_return(Prefix A) = A
==> parse_char_with_return(Prefix A) = "A"

++> parse_char_wo_return(Prefix A) = A
==> parse_char_wo_return(Prefix A) = nil

This is good because it means yet again we can fix this without dipping into the bytecode layer (yay IR). I just tested this on master so it is still broken.

I also verified this does not affect 1.7 so @donv issue has same behavior but it is something broken in concurrent access (in #3031)

@subbuss subbuss closed this in be5e7f1 Jul 7, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.