From 131c31a9209c61f84d318aa18b61f468f48b8219 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 26 Oct 2022 19:43:14 +0900 Subject: [PATCH] [Bug #19081] Show the caller location in warning for Ractor The internal location in ractor.rb is not usefull at all. ``` $ ruby -e 'Ractor.new {}' :267: warning: Ractor is experimental, ... ``` --- bootstraptest/test_ractor.rb | 6 ++++++ ractor.c | 6 ------ ractor.rb | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 6373349e42..0fad04ebbc 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -1618,4 +1618,10 @@ assert_equal "ok", %q{ "ok" } +assert_match /\Atest_ractor\.rb:1:\s+warning:\s+Ractor is experimental/, %q{ + Warning[:experimental] = $VERBOSE = true + STDERR.reopen(STDOUT) + eval("Ractor.new{}.take", nil, "test_ractor.rb", 1) +} + end # if !ENV['GITHUB_WORKFLOW'] diff --git a/ractor.c b/ractor.c index 7fea312ab0..3569202e58 100644 --- a/ractor.c +++ b/ractor.c @@ -1438,12 +1438,6 @@ cancel_single_ractor_mode(void) } ruby_single_main_ractor = NULL; - - if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL)) { - rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL, - "Ractor is experimental, and the behavior may change in future versions of Ruby! " - "Also there are many implementation issues."); - } } static void diff --git a/ractor.rb b/ractor.rb index 8e229d4700..1031fe499b 100644 --- a/ractor.rb +++ b/ractor.rb @@ -262,6 +262,10 @@ class Ractor def self.new(*args, name: nil, &block) b = block # TODO: builtin bug raise ArgumentError, "must be called with a block" unless block + if __builtin_cexpr!("RBOOL(ruby_single_main_ractor)") + warn("Ractor is experimental, and the behavior may change in future versions of Ruby! " \ + "Also there are many implementation issues.", uplevel: 0, category: :experimental) + end loc = caller_locations(1, 1).first loc = "#{loc.path}:#{loc.lineno}" __builtin_ractor_create(loc, name, args, b)