Skip to content

[Bug #22412] Copy ep when duplicating ifunc procs - #19251

Merged
peterzhu2118 merged 1 commit into
ruby:masterfrom
peterzhu2118:ifunc-proc-dup
Oct 8, 2026
Merged

peterzhu2118 merged 1 commit into
ruby:masterfrom
peterzhu2118:ifunc-proc-dup

Conversation

@peterzhu2118

Copy link
Copy Markdown
Member

When duplicating ifunc procs that have heap allocated env, we should share it instead of making a copy.

In debug mode, the following script triggers an assertion failure:

pr = proc {|a, b| [a, b] }.curry.dup
pr.call(1)

It crashes with:

vm.c:281: Assertion Failed: vm_ep_in_heap_p_:env->ep == ep
ruby 4.1.0dev (2026-10-07T07:57:31Z master 9ce0df6719) +PRISM [arm64-darwin27]

-- Crash Report log information --------------------------------------------
  See Crash Report log file in one of the following locations:
    * ~/Library/Logs/DiagnosticReports
    * /Library/Logs/DiagnosticReports for more details. Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information ----------------------------------------------- c:0004 p:---- s:0014 e:000013 l:y b:0001 r:0x0 CFUNC  :proc c:0003 p:---- s:0011 e:000010 l:n b:---- r:0x0 IFUNC
c:0002 p:0015 s:0008 E:001e90 l:n b:---- r:0x0 EVAL   test.rb:2 [FINISH]
c:0001 p:0000 s:0003 E:001ff8 l:y b:---- r:0x0 DUMMY  [FINISH]

-- Ruby level backtrace information ---------------------------------------- test.rb:2:in '<main>' test.rb:2:in 'proc'

-- Threading information --------------------------------------------------- Total ractor count: 1 Ruby thread count for this ractor: 1

-- C level backtrace information ------------------------------------------- miniruby(rb_assert_failure_detail+0xf0) [0x105456fe4] error.c:1268 miniruby(rb_assert_failure_detail) (null):0 miniruby(rb_assert_failure_detail+0x0) [0x105456ef4] error.c:1244 miniruby(rb_assert_failure) (null):0 miniruby(vm_ep_in_heap_p_.cold.1+0x28) [0x105463d24] vm.c:281 miniruby(vm_ep_in_heap_p_.cold.2) (null):0 miniruby(rb_vm_cref_dup+0x0) [0x10519a4e4] vm.c:281 miniruby(vm_ep_in_heap_p_) (null):0 miniruby(VM_ENV_ESCAPED_P+0x68) [0x1051ba188] vm.c:295 miniruby(vm_make_env_each+0xa4) [0x1051d56c8] vm.c:1120 miniruby(vm_make_env_object+0x8) [0x1051b9f18] vm.c:1217 miniruby(rb_vm_make_proc_lambda) vm.c:1720 miniruby(vm_call0_body+0x778) [0x1051d39dc] vm_eval.c:164 miniruby(rb_call0+0x2ac) [0x1051d47e0] vm_eval.c:101 miniruby(rb_iterate0+0x1d0) [0x1051b5e04] vm_eval.c:1506 miniruby(rb_block_call_kw+0x28) [0x1051b59a4] vm_eval.c:1580 miniruby(rb_block_call) vm_eval.c:1566 miniruby(RB_SPECIAL_CONST_P+0x0) [0x105096de0] proc.c:4236 miniruby(rbimpl_RB_TYPE_P_fastpath) include/ruby/internal/value_type.h:349 miniruby(rbimpl_obj_typeddata_p) include/ruby/internal/core/rtypeddata.h:661 miniruby(rb_proc_new) include/ruby/internal/core/rtypeddata.h:735 miniruby(make_curry_proc) proc.c:4524 miniruby(vm_yield_with_cfunc+0xc0) [0x10519de40] vm_insnhelper.c:5275 miniruby(vm_invoke_ifunc_block+0xe0) [0x1051cd8bc] vm_insnhelper.c:5539 miniruby(vm_exec_core+0x42ec) [0x1051a5d48] vm_insnhelper.c:6285 miniruby(vm_exec_loop+0x0) [0x10519f240] vm.c:2909 miniruby(rb_vm_exec) vm.c:2912 miniruby(rb_ec_exec_node+0xa0) [0x104fac450] eval.c:300 miniruby(ruby_run_node+0x64) [0x104fac354] eval.c:338 miniruby(rb_main+0x1c) [0x104ee09b0] main.c:42 miniruby(main) main.c:62

[Bug #22412]

When duplicating ifunc procs that have heap allocated env, we should share
it instead of making a copy.

In debug mode, the following script triggers an assertion failure:

    pr = proc {|a, b| [a, b] }.curry.dup
    pr.call(1)

It crashes with:

    vm.c:281: Assertion Failed: vm_ep_in_heap_p_:env->ep == ep
    ruby 4.1.0dev (2026-10-07T07:57:31Z master 9ce0df6) +PRISM [arm64-darwin27]

    -- Crash Report log information --------------------------------------------
      See Crash Report log file in one of the following locations:
        * ~/Library/Logs/DiagnosticReports
        * /Library/Logs/DiagnosticReports
      for more details.
    Don't forget to include the above Crash Report log file in bug reports.

    -- Control frame information -----------------------------------------------
    c:0004 p:---- s:0014 e:000013 l:y b:0001 r:0x0 CFUNC  :proc
    c:0003 p:---- s:0011 e:000010 l:n b:---- r:0x0 IFUNC
    c:0002 p:0015 s:0008 E:001e90 l:n b:---- r:0x0 EVAL   test.rb:2 [FINISH]
    c:0001 p:0000 s:0003 E:001ff8 l:y b:---- r:0x0 DUMMY  [FINISH]

    -- Ruby level backtrace information ----------------------------------------
    test.rb:2:in '<main>'
    test.rb:2:in 'proc'

    -- Threading information ---------------------------------------------------
    Total ractor count: 1
    Ruby thread count for this ractor: 1

    -- C level backtrace information -------------------------------------------
    miniruby(rb_assert_failure_detail+0xf0) [0x105456fe4] error.c:1268
    miniruby(rb_assert_failure_detail) (null):0
    miniruby(rb_assert_failure_detail+0x0) [0x105456ef4] error.c:1244
    miniruby(rb_assert_failure) (null):0
    miniruby(vm_ep_in_heap_p_.cold.1+0x28) [0x105463d24] vm.c:281
    miniruby(vm_ep_in_heap_p_.cold.2) (null):0
    miniruby(rb_vm_cref_dup+0x0) [0x10519a4e4] vm.c:281
    miniruby(vm_ep_in_heap_p_) (null):0
    miniruby(VM_ENV_ESCAPED_P+0x68) [0x1051ba188] vm.c:295
    miniruby(vm_make_env_each+0xa4) [0x1051d56c8] vm.c:1120
    miniruby(vm_make_env_object+0x8) [0x1051b9f18] vm.c:1217
    miniruby(rb_vm_make_proc_lambda) vm.c:1720
    miniruby(vm_call0_body+0x778) [0x1051d39dc] vm_eval.c:164
    miniruby(rb_call0+0x2ac) [0x1051d47e0] vm_eval.c:101
    miniruby(rb_iterate0+0x1d0) [0x1051b5e04] vm_eval.c:1506
    miniruby(rb_block_call_kw+0x28) [0x1051b59a4] vm_eval.c:1580
    miniruby(rb_block_call) vm_eval.c:1566
    miniruby(RB_SPECIAL_CONST_P+0x0) [0x105096de0] proc.c:4236
    miniruby(rbimpl_RB_TYPE_P_fastpath) include/ruby/internal/value_type.h:349
    miniruby(rbimpl_obj_typeddata_p) include/ruby/internal/core/rtypeddata.h:661
    miniruby(rb_proc_new) include/ruby/internal/core/rtypeddata.h:735
    miniruby(make_curry_proc) proc.c:4524
    miniruby(vm_yield_with_cfunc+0xc0) [0x10519de40] vm_insnhelper.c:5275
    miniruby(vm_invoke_ifunc_block+0xe0) [0x1051cd8bc] vm_insnhelper.c:5539
    miniruby(vm_exec_core+0x42ec) [0x1051a5d48] vm_insnhelper.c:6285
    miniruby(vm_exec_loop+0x0) [0x10519f240] vm.c:2909
    miniruby(rb_vm_exec) vm.c:2912
    miniruby(rb_ec_exec_node+0xa0) [0x104fac450] eval.c:300
    miniruby(ruby_run_node+0x64) [0x104fac354] eval.c:338
    miniruby(rb_main+0x1c) [0x104ee09b0] main.c:42
    miniruby(main) main.c:62
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

This pull request references the following Redmine tickets:

@peterzhu2118
peterzhu2118 merged commit bd24fa6 into ruby:master Oct 8, 2026
139 of 141 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant