From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id DFE8B1AE0071 for ; Fri, 9 Sep 2016 08:08:32 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 5FC22B5D89E for ; Fri, 9 Sep 2016 08:41:04 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 8C84218CC80D for ; Fri, 9 Sep 2016 08:41:04 +0900 (JST) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A02A6120482; Fri, 9 Sep 2016 08:41:03 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id A6FA9120459 for ; Fri, 9 Sep 2016 08:41:00 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=N9XnBPChSpvZsUBtBT44yDMogTs=; b=JIh33Gc9g0C8+7Yty7 2YnSLp4NGEMaIHf226pz37zUCyWEQqnznAE03nppJmwlK9hLT+n9qgWkMsBPqePH qbeE61S99ZUysFKHFdbk+DNUvOlCllhFcGkyEHoc9Lru2JMj0KnETeWYrFgCSx9o t9MgPRns8gsNNjlLZcrONEo7Y= Received: by filter0578p1mdw1.sendgrid.net with SMTP id filter0578p1mdw1.6191.57D1F70845 2016-09-08 23:40:56.970808704 +0000 UTC Received: from herokuapp.com (ec2-54-163-214-37.compute-1.amazonaws.com [54.163.214.37]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id y2z2vMYXSnqi1PDh-I4ibA Thu, 08 Sep 2016 23:40:56.922 +0000 (UTC) Date: Thu, 08 Sep 2016 23:40:56 +0000 From: shugo@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 52023 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 12086 X-Redmine-Issue-Author: shugo X-Redmine-Sender: shugo 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-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4Ka+lM/g+L8aOvQGOGxW58auLzJRTtvKB8x7 sLIpPjDEM7YrPRiR6lPgripEPBUC5526bpbJVZmYZ+4p8Fy7JijrJoTTC3MfPQD3HLX3A76tPaFzNL 36QF+7MU7N1jauwBI7EEdZkcGRoPSYFOWjenWFRUhmDAQ31oY02c8KD7dw== X-ML-Name: ruby-core X-Mail-Count: 77225 Subject: [ruby-core:77225] [Ruby trunk Feature#12086] using: option for instance_eval etc. X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #12086 has been updated by Shugo Maeda. Charles Nutter wrote: > Yes, it appears that every call to instance_eval(using: Foo ...) blows away the global method cache by calling rb_using_module. So one library using instance_eval+using *will* hurt performance for every method call, in the same way that Object#extend does. This is more an MRI concern, since JRuby and JRuby+Truffle invalidate on a much smaller scale. It's true that cache is invalidated by instance_eval(using:), but global method caching has been improved in MRI, and I don't know how different compared to JRuby. > New Ruby features should not hurt code that never uses those features, right? I don't know it should be applied to code used with the new features. ---------------------------------------- Feature #12086: using: option for instance_eval etc. https://bugs.ruby-lang.org/issues/12086#change-60452 * Author: Shugo Maeda * Status: Open * Priority: Normal * Assignee: ---------------------------------------- Currently refinements can be activated only in toplevel or class/module definitions. If they can be activated in block-level, it's useful to implement internal DSLs. How about to add a new option using: for Kernel#instance_eval and Moule#{class,module}_eval? ```ruby module FixnumDivExt refine Fixnum do def /(other) quo(other) end end end p 1 / 2 #=> 0 instance_eval(using: FixnumDivExt) do p 1 / 2 #=> (1/2) end p 1 / 2 #=> 0 ``` Proof-of-concept implementation is available at . In my previous proposal before Ruby 2.0, refinements used in a class or module are implicitly activated by instance_eval and class_eval, but now I think it's better to explicitly specify refinements to be activated. Considerations: * In the PoC implementation, refined methods are not cached inline, and thus it decreases the performance of refined method call. If there is a way to guarantee that blocks never be evaluated in different environments, refined methods can be cached inline. * {instance,class,module}_exec cannot be extended in the same way, because they take arbitrary arguments and there's no way to distinguish an option hash from the last argument hash. -- https://bugs.ruby-lang.org/