Project

General

Profile

Actions

Bug #18569

closed

RubyVM::InstructionSequence#disasm returns nil for composed functions

Added by GabrielMalakias (Gabriel Malaquias) about 2 years ago. Updated about 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:107459]

Description

I was testing function composition Proc#>> (https://ruby-doc.org/core-2.6/Proc.html#method-i-3E-3E) and noticed that when disassembling composed functions it always returns nil.

first_proc = proc { |x| x + 2 }
puts RubyVM::InstructionSequence.disasm(first_proc)

# returns 
# == disasm: #<ISeq:block in <main>@disasm.rb:3 (3,18)-(3,31)> (catch: FALSE)
# local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
# [ 1] x@0<Arg>
# 0000 getlocal_WC_0                          x@0                       (   3)[LiBc]
# 0002 putobject                              2
# 0004 opt_plus                               <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
# 0006 leave                                  [Br]
# -------------------------------------

puts RubyVM::InstructionSequence.disasm(first_proc >> first_proc)
# return nil

Is this expected or there is something weird happening here? I'm happy to help fixing it with some help in case it's a bug


Files

disasm.rb (631 Bytes) disasm.rb Script to reproduce the problem GabrielMalakias (Gabriel Malaquias), 02/03/2022 10:39 AM

Updated by byroot (Jean Boussier) about 2 years ago

Don't take my word as definitive, but I'd say it's expected. Proc#<< return has no "source code":

>> proc{}.source_location
=> ["(irb)", 4]
>> (proc{} << proc{}).source_location
=> nil

Think of it as a "delegator", it has no InstructionSequence of its own.

Updated by jeremyevans0 (Jeremy Evans) about 2 years ago

  • Status changed from Open to Rejected

I agree, this is expected behavior, since there is no instruction sequence for a composed proc. If you would like an instruction sequence, you need to manually compose the proc in Ruby.

Actions

Also available in: Atom PDF

Like0
Like0Like0