From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [IPv6:2a01:4f8:1c0c:6b10::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 274E01F44D for ; Thu, 14 Mar 2024 14:52:23 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=H1bkuM83; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=fnOiS/T7; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 95B22832B4; Thu, 14 Mar 2024 14:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1710427933; bh=OpNfHuhkeWWKVY+xFevVPDR8ygegFbT5igTb7lP0cv0=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=H1bkuM83i5vUzYB2xmJ6V/+4rCSyj34TPJNwm9ev/7ix7rZMcQ84iPtQSzGFLrX7/ 4IPHmR8ebI1zbtgLJMxSdjLLF62ekfOlyd+uQkHwVJi/cWjZyHu6U+Y+P3CNmiT2p4 7bNDxKL0WoCqW6NgoFjUk1+BPiayCMO0FsRJEigg= Received: from s.wfbtzhsv.outbound-mail.sendgrid.net (s.wfbtzhsv.outbound-mail.sendgrid.net [159.183.224.104]) by nue.mailmanlists.eu (Postfix) with ESMTPS id C060F83105 for ; Thu, 14 Mar 2024 14:52:09 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=fnOiS/T7; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=wVMBOr0CUjUJZfONNPyduyRj/B8xQSfc85Gxnt41FnQ=; b=fnOiS/T7PU7zfLemHqsE6ah7p800jiUm8GDOGEijdamcRuOmjn44Gn7kY5o7ef/wAyut 64VTWLMozamntlgTFfY69r42KxMrmC20b+AqVLhvDYGy3op4skEsU95LhrP2Y+K6TN0xfP iU+ppkqbXzyFrokHc73HZiCfXC83kUjDgNI2+NDQLaMyUkRtKxuJ1tyGPR75KAqzvhYLFL eEsyQj8Hs84GPWUWMotmCfEDOgMChFgXtB9QOKGiBcrJynUvh0j4WxaD75LeHBCWRgMUCx bpZCxwjhHPyIxowEr2XrYpwWHscQyJmuWBFHK72nKeJ4MfqOc0jABZZ+v1CBwMyA== Received: by recvd-c464bfb6d-pk4r4 with SMTP id recvd-c464bfb6d-pk4r4-1-65F30F18-1 2024-03-14 14:52:08.209142464 +0000 UTC m=+1270911.195254591 Received: from herokuapp.com (unknown) by geopod-ismtpd-19 (SG) with ESMTP id ZzH4kWeqSzunm_OH3TITgQ for ; Thu, 14 Mar 2024 14:52:08.128 +0000 (UTC) Date: Thu, 14 Mar 2024 14:52:08 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 20335 X-Redmine-Issue-Author: byroot X-Redmine-Issue-Priority: Normal X-Redmine-Sender: Eregon X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 93740 X-SG-EID: =?us-ascii?Q?u001=2EByjZWvxTCjdoV8K03xEuhE7KqN4thWULFLM7+oH78KY30oYB3qFthsDpL?= =?us-ascii?Q?4w4cbYa3ttBh8bAHPOnE=2FkzPba67JNu7Lnrked2?= =?us-ascii?Q?O7K9VQ=2FJax05WDZebErQTTboC9SbZRmuy3VW9mp?= =?us-ascii?Q?OBtOGSI9hFtNVRS6kDFPiEQmT4sWxSVb5wTJG93?= =?us-ascii?Q?TN=2Fsj9lpQCBtKnZ3YO31KlFi6HJ+NHx=2FHavEJGa?= =?us-ascii?Q?=2F3owK6HHRr9c9alH9tDYl10=2FTnALwRbML49y6Cc?= =?us-ascii?Q?j6vZfK324IeOwAu=2F=2Ftv6Xh3a5g=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: RZHYNPUN276OLGNO25LRHVYJJ7VYHM6P X-Message-ID-Hash: RZHYNPUN276OLGNO25LRHVYJJ7VYHM6P X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:117174] [Ruby master Feature#20335] `Thread.each_caller_location` should accept the same arguments as `caller` and `caller_locations` List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "Eregon (Benoit Daloze) via ruby-core" Cc: "Eregon (Benoit Daloze)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20335 has been updated by Eregon (Benoit Daloze). I think omitting the first N frames is useful. However I see little reason to have a `length` or `Range`, one can just `break/return` out of the `Thread.each_caller_location`, and it seems pretty rare to need that. So I think it's best to only add `start = 1` for now. In fact the `length` argument is already an issue for `caller_locations`: if it's too high it causes `caller_locations` to return an empty Array instead of whatever is available: ``` irb(main):001:0> caller_locations(10) => ["/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb/ruby-lex.rb:248:in `catch'", "/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb/ruby-lex.rb:248:in `each_top_level_statement'", "/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb.rb:566:in `eval_input'", "/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb.rb:500:in `block in run'", "/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb.rb:499:in `catch'", "/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb.rb:499:in `run'", "/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb.rb:421:in `start'", "/home/eregon/.rubies/ruby-3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `'", "/home/eregon/.rubies/ruby-3.2.2/bin/irb:25:in `load'", "/home/eregon/.rubies/ruby-3.2.2/bin/irb:25:in `
'"] irb(main):002:0> caller_locations(20) => [] ``` That implies it needs to count how many frames are available, which is inefficient. So we certainly wouldn't want that behavior for `each_caller_location` as it would ruin a significant part of its performance advantage. (we should probably also fix this for `caller_locations`, but that should be a separate ticket) Similarly the Range form is also problematic as it also requires iterating all the stack to find how many frames there are to know which frames `0..-2` should use. ---------------------------------------- Feature #20335: `Thread.each_caller_location` should accept the same arguments as `caller` and `caller_locations` https://bugs.ruby-lang.org/issues/20335#change-107264 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- `Thread.each_caller_location` was added to Ruby 3.2 as part of [Feature #16663] and is a very useful API for emitting warnings with a proper source location and similar use cases. However in many of the cases where I used it, or seen it used, it was needed to skip the first, or a couple frames: Examples: Sorbet: https://github.com/Shopify/sorbet/blob/b27a14c247ace7cabdf0f348bfb11fdf0b7e9ab4/gems/sorbet-runtime/lib/types/private/caller_utils.rb#L6-L18 ```ruby def self.find_caller skiped_first = false Thread.each_caller_location do |loc| unless skiped_first skiped_first = true next end next if loc.path&.start_with?("= 1 frames_to_skip -= 1 next end # snipp... ``` ### Proposal I think it would be very useful if `Thread.each_caller_location` accepted the same arguments as `caller` and `caller_locations`: ```ruby #each_caller_location(start = 1, length = nil) #each_caller_location(range) ``` @jeremyevans0 what do you think? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/