Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make Kernel#lambda raise when given non-literal block #8405

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

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

XrXr
Copy link
Member

@XrXr XrXr commented Sep 8, 2023

Previously, Kernel#lambda returned a non-lambda proc when given a non-literal block and issued a warning under the :deprecated category. With this change, Kernel#lambda will always return a lambda proc, if it returns without raising.

Due to interactions with block passing optimizations, we previously had two separate code paths for detecting whether Kernel#lambda got a literal block. This change allows us to remove one path, the hack done with rb_control_frame_t::block_code introduced in 85a337f for supporting situations where Kernel#lambda returned a non-lambda proc.

[Feature #19777]

@matzbot matzbot requested a review from a team September 8, 2023 22:34
Previously, Kernel#lambda returned a non-lambda proc when given a
non-literal block and issued a warning under the `:deprecated` category.
With this change, Kernel#lambda will always return a lambda proc, if it
returns without raising.

Due to interactions with block passing optimizations, we previously had
two separate code paths for detecting whether Kernel#lambda got a
literal block. This change allows us to remove one path, the hack done
with rb_control_frame_t::block_code introduced in 85a337f for supporting
situations where Kernel#lambda returned a non-lambda proc.

[Feature #19777]

Co-authored-by: Takashi Kokubun <[email protected]>
@XrXr
Copy link
Member Author

XrXr commented Sep 11, 2023

The part of the patch that leaves block_code uninitialized for C frames seems to be causing issues on MinGW without YJIT. It should probably not be lumped up with this PR anyways so I'll investigate that separately.

  1) Failure:
  TestLazyEnumerator#test_map_zip [D:/a/ruby/ruby/src/test/ruby/test_lazy_enumerator.rb:602]:
  [ruby-core:50545]
  pid 3608 exit 3
  | -e:2: [BUG] Segmentation fault
  | ruby 3.3.0dev (2023-09-08T23:22:45Z pull/8405/merge d413f37104) [x64-mingw-ucrt]
  | 
  | -- Control frame information -----------------------------------------------
  | c:0007 p:---- s:0022 e:000021 IFUNC 
  | c:0006 p:---- s:0019 E:001280 CFUNC  :each
  | c:0005 p:---- s:0016 e:000015 CFUNC  :each
  | c:0004 p:---- s:0013 E:001940 CFUNC  :zip
  | c:0003 p:---- s:0010 e:000009 CFUNC  :zip
  | c:0002 p:0017 s:0006 E:001820 EVAL   -e:2 [FINISH]
  | c:0001 p:0000 s:0003 E:001270 DUMMY  [FINISH]
  | 
  | -- Ruby level backtrace information ----------------------------------------
  | -e:2:in `<main>'
  | -e:2:in `zip'
  | -e:2:in `zip'
  | -e:2:in `each'
  | -e:2:in `each'
  | 
  | -- Threading information ---------------------------------------------------
  | Total ractor count: 1
  | Ruby thread count for this ractor: 1
  | 
  | -- C level backtrace information -------------------------------------------
  | C:\Windows\SYSTEM32\ntdll.dll(ZwWaitForSingleObject+0x14) [0x00007ffb64dc0114]
  | C:\Windows\System32\KERNELBASE.dll(WaitForSingleObjectEx+0x8e) [0x00007ffb6230d77e]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_bugreport+0x316) [0x00007ffb45d3fc56]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_bug_for_fatal_signal+0x80) [0x00007ffb45b373c0]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_shape_memsize+0x892) [0x00007ffb45c8bd92]
  |  [0x00007ff6e00a1e32]
  | C:\Windows\System32\ucrtbase.dll(_C_specific_handler+0xa0) [0x00007ffb62a255f0]
  | C:\Windows\SYSTEM32\ntdll.dll(_chkstk+0x12f) [0x00007ffb64dc4fff]
  | C:\Windows\SYSTEM32\ntdll.dll(RtlVirtualUnwind2+0x35e) [0x00007ffb64d518fe]
  | C:\Windows\SYSTEM32\ntdll.dll(KiUserExceptionDispatcher+0x2e) [0x00007ffb64dc3fee]
  |  [0x000002c336d1e7b8]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_bh_to_procval+0x29b6) [0x00007ffb45d209f6]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_yield+0x3a3) [0x00007ffb45d27293]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_invoke_proc+0x85) [0x00007ffb45d27595]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_proc_call_kw+0x7b) [0x00007ffb45c2579b]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_invoke_proc+0x1ed) [0x00007ffb45d276fd]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_invoke_proc+0xe06) [0x00007ffb45d28316]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_funcallv_public_kw+0xc7) [0x00007ffb45d2af47]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_catch+0x274) [0x00007ffb45d1ceb4]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_block_call_kw+0x87) [0x00007ffb45d1d437]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_nmin_run+0x4b7c) [0x00007ffb45b2edfc]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_invoke_proc+0x1ed) [0x00007ffb45d276fd]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_invoke_proc+0xe06) [0x00007ffb45d28316]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_funcallv_public_kw+0xc7) [0x00007ffb45d2af47]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_catch+0x274) [0x00007ffb45d1ceb4]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_block_call+0x84) [0x00007ffb45d1d394]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_enc_foreach_name+0x2573) [0x00007ffb45b22ae3]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_invoke_proc+0x1ed) [0x00007ffb45d276fd]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_invoke_proc+0xe06) [0x00007ffb45d28316]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_call_super_kw+0x114) [0x00007ffb45d29b54]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_error_arity+0xe05) [0x00007ffb45d13f85]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_search_method_slowpath+0x74e) [0x00007ffb45d1a25e]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_check_funcall+0x254c) [0x00007ffb45d3265c]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_vm_exec+0xf5) [0x00007ffb45d22b45]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(rb_refinement_module_get_refined_class+0x2c89) [0x00007ffb45b3f7f9]
  | D:\a\ruby\ruby\build\x64-ucrt-ruby330.dll(ruby_run_node+0x90) [0x00007ffb45b41ed0]
  |  [0x00007ff6e00a2a50]
  |  [0x00007ff6e00a12ee]
  |  [0x00007ff6e00a1406]
  | C:\Windows\System32\KERNEL32.DLL(BaseThreadInitThunk+0x10) [0x00007ffb637f4de0]
  | 
  | -- Other runtime information -----------------------------------------------
  | 
  | * Loaded script: -e
  | 
  | * Loaded features:
  | 
  |     0 enumerator.so
  |     1 thread.rb
  |     2 fiber.so
  |     3 rational.so
  |     4 complex.so
  |     5 ruby2_keywords.rb
  |     6 D:/a/ruby/ruby/build/.ext/x64-mingw-ucrt/enc/encdb.so
  |     7 D:/a/ruby/ruby/build/.ext/x64-mingw-ucrt/enc/trans/transdb.so
  |     8 D:/a/ruby/ruby/build/rbconfig.rb
  |     9 D:/a/ruby/ruby/src/lib/rubygems/compatibility.rb
  |    10 D:/a/ruby/ruby/src/lib/rubygems/defaults.rb
  |    11 D:/a/ruby/ruby/src/lib/rubygems/deprecate.rb
  |    12 D:/a/ruby/ruby/src/lib/rubygems/errors.rb
  |    13 D:/a/ruby/ruby/src/lib/rubygems/unknown_command_spell_checker.rb
  |    14 D:/a/ruby/ruby/src/lib/rubygems/exceptions.rb
  |    15 D:/a/ruby/ruby/src/lib/rubygems/basic_specification.rb
  |    16 D:/a/ruby/ruby/src/lib/rubygems/stub_specification.rb
  |    17 D:/a/ruby/ruby/src/lib/rubygems/platform.rb
  |    18 D:/a/ruby/ruby/src/lib/rubygems/util/list.rb
  |    19 D:/a/ruby/ruby/src/lib/rubygems/version.rb
  |    20 D:/a/ruby/ruby/src/lib/rubygems/requirement.rb
  |    21 D:/a/ruby/ruby/src/lib/rubygems/specification.rb
  |    22 D:/a/ruby/ruby/src/lib/rubygems/util.rb
  |    23 D:/a/ruby/ruby/src/lib/rubygems/core_ext/kernel_gem.rb
  |    24 D:/a/ruby/ruby/build/.ext/x64-mingw-ucrt/monitor.so
  |    25 D:/a/ruby/ruby/build/.ext/common/monitor.rb
  |    26 D:/a/ruby/ruby/src/lib/rubygems.rb
  |    27 D:/a/ruby/ruby/src/lib/bundled_gems.rb
  |    28 D:/a/ruby/ruby/src/lib/error_highlight/version.rb
  |    29 D:/a/ruby/ruby/src/lib/error_highlight/base.rb
  |    30 D:/a/ruby/ruby/src/lib/error_highlight/formatter.rb
  |    31 D:/a/ruby/ruby/src/lib/error_highlight/core_ext.rb
  |    32 D:/a/ruby/ruby/src/lib/error_highlight.rb
  |    33 D:/a/ruby/ruby/src/lib/did_you_mean/version.rb
  |    34 D:/a/ruby/ruby/src/lib/did_you_mean/core_ext/name_error.rb
  |    35 D:/a/ruby/ruby/src/lib/did_you_mean/levenshtein.rb
  |    36 D:/a/ruby/ruby/src/lib/did_you_mean/jaro_winkler.rb
  |    37 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checker.rb
  |    38 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
  |    39 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
  |    40 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/name_error_checkers.rb
  |    41 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/method_name_checker.rb
  |    42 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/key_error_checker.rb
  |    43 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/null_checker.rb
  |    44 D:/a/ruby/ruby/src/lib/did_you_mean/tree_spell_checker.rb
  |    45 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/require_path_checker.rb
  |    46 D:/a/ruby/ruby/src/lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb
  |    47 D:/a/ruby/ruby/src/lib/did_you_mean/formatter.rb
  |    48 D:/a/ruby/ruby/src/lib/did_you_mean.rb
  |    49 D:/a/ruby/ruby/src/lib/syntax_suggest/core_ext.rb
  | 
  
  
  Finished tests in 2168.788430s, 11.6743 tests/s, 2813.3118 assertions/s.
  25319 tests, 6101478 assertions, 1 failures, 0 errors, 219 skips
  
  ruby -v: ruby 3.3.0dev (2023-09-08T23:22:45Z pull/8405/merge d413f37104) [x64-mingw-ucrt]

@XrXr XrXr merged commit 39ee3e2 into ruby:master Sep 12, 2023
@XrXr XrXr deleted the only-lit-lambdas branch September 13, 2023 21:57
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.

3 participants