ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:107459] [Ruby master Bug#18569] RubyVM::InstructionSequence#disasm returns nil for composed functions
@ 2022-02-03 10:46 GabrielMalakias (Gabriel  Malaquias)
  2022-02-03 12:58 ` [ruby-core:107465] " byroot (Jean Boussier)
  2022-02-04 21:12 ` [ruby-core:107488] " jeremyevans0 (Jeremy Evans)
  0 siblings, 2 replies; 3+ messages in thread
From: GabrielMalakias (Gabriel  Malaquias) @ 2022-02-03 10:46 UTC (permalink / raw
  To: ruby-core

Issue #18569 has been reported by GabrielMalakias (Gabriel  Malaquias).

----------------------------------------
Bug #18569: RubyVM::InstructionSequence#disasm returns nil for composed functions
https://bugs.ruby-lang.org/issues/18569

* Author: GabrielMalakias (Gabriel  Malaquias)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.0
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
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.

``` ruby
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)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:107465] [Ruby master Bug#18569] RubyVM::InstructionSequence#disasm returns nil for composed functions
  2022-02-03 10:46 [ruby-core:107459] [Ruby master Bug#18569] RubyVM::InstructionSequence#disasm returns nil for composed functions GabrielMalakias (Gabriel  Malaquias)
@ 2022-02-03 12:58 ` byroot (Jean Boussier)
  2022-02-04 21:12 ` [ruby-core:107488] " jeremyevans0 (Jeremy Evans)
  1 sibling, 0 replies; 3+ messages in thread
From: byroot (Jean Boussier) @ 2022-02-03 12:58 UTC (permalink / raw
  To: ruby-core

Issue #18569 has been updated by byroot (Jean Boussier).


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

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

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

----------------------------------------
Bug #18569: RubyVM::InstructionSequence#disasm returns nil for composed functions
https://bugs.ruby-lang.org/issues/18569#change-96368

* Author: GabrielMalakias (Gabriel  Malaquias)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.0
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
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.

``` ruby
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)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:107488] [Ruby master Bug#18569] RubyVM::InstructionSequence#disasm returns nil for composed functions
  2022-02-03 10:46 [ruby-core:107459] [Ruby master Bug#18569] RubyVM::InstructionSequence#disasm returns nil for composed functions GabrielMalakias (Gabriel  Malaquias)
  2022-02-03 12:58 ` [ruby-core:107465] " byroot (Jean Boussier)
@ 2022-02-04 21:12 ` jeremyevans0 (Jeremy Evans)
  1 sibling, 0 replies; 3+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-02-04 21:12 UTC (permalink / raw
  To: ruby-core

Issue #18569 has been updated by jeremyevans0 (Jeremy Evans).

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.

----------------------------------------
Bug #18569: RubyVM::InstructionSequence#disasm returns nil for composed functions
https://bugs.ruby-lang.org/issues/18569#change-96390

* Author: GabrielMalakias (Gabriel  Malaquias)
* Status: Rejected
* Priority: Normal
* ruby -v: 3.1.0
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
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.

``` ruby
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)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-04 21:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-03 10:46 [ruby-core:107459] [Ruby master Bug#18569] RubyVM::InstructionSequence#disasm returns nil for composed functions GabrielMalakias (Gabriel  Malaquias)
2022-02-03 12:58 ` [ruby-core:107465] " byroot (Jean Boussier)
2022-02-04 21:12 ` [ruby-core:107488] " jeremyevans0 (Jeremy Evans)

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).