[#50466] [ruby-trunk - Bug #7492][Open] Segmentation fault at DL::TestDL#test_call_double on x64 Windows 8 — "phasis68 (Heesob Park)" <phasis@...>
23 messages
2012/12/02
[#59083] [ruby-trunk - Bug #7492] Segmentation fault at DL::TestDL#test_call_double on x64 Windows 8
— "phasis68 (Heesob Park)" <phasis@...>
2013/12/13
[#50483] [IMPORTANT] 2.0.0 release plan — Yusuke Endoh <mame@...>
ALL COMMITTERS SHOULD READ THIS MAIL! コミッタはこのメール読んで!
5 messages
2012/12/02
[#50561] [ruby-trunk - Bug #7513][Open] TracePoint#enable/disable should not cause error — "ko1 (Koichi Sasada)" <redmine@...>
7 messages
2012/12/05
[#50575] [ruby-trunk - Feature #7517][Open] Fixnum::MIN,MAX — "matz (Yukihiro Matsumoto)" <matz@...>
20 messages
2012/12/05
[#50593] [ruby-trunk - Feature #7517] Fixnum::MIN,MAX
— "shyouhei (Shyouhei Urabe)" <shyouhei@...>
2012/12/05
[#50594] Re: [ruby-trunk - Feature #7517] Fixnum::MIN,MAX
— Charles Oliver Nutter <headius@...>
2012/12/05
On Wed, Dec 5, 2012 at 12:24 PM, shyouhei (Shyouhei Urabe)
[#50636] [ruby-trunk - Bug #7528][Open] CSV.== fails to check object type — "SteveW (Stephen Wattam)" <stephenwattam@...>
6 messages
2012/12/06
[#50645] [ruby-trunk - Bug #7530][Open] Concurrent loads fail with mutex errors — "headius (Charles Nutter)" <headius@...>
7 messages
2012/12/06
[#50660] [ruby-trunk - Feature #4085] Refinements and nested methods — "trans (Thomas Sawyer)" <transfire@...>
3 messages
2012/12/07
[#50699] Commit access for Yehuda Katz — Aaron Patterson <tenderlove@...>
Hi,
4 messages
2012/12/08
[#50923] Re: Commit access for Yehuda Katz
— Charles Oliver Nutter <headius@...>
2012/12/16
I will +1 this, unsure if it has happened already (it's "catch up on
[#50733] [ruby-trunk - Bug #7539][Open] Misleading error message "can't convert nil into string" — "connec (Chris Connelly)" <chris@...>
8 messages
2012/12/10
[#50755] Becoming a committer — Charlie Somerville <charlie@...>
Hi ruby-core,
21 messages
2012/12/11
[#50759] Re: Becoming a committer
— Yukihiro Matsumoto <matz@...>
2012/12/11
Hi,
[#50784] Re: Becoming a committer
— Charles Oliver Nutter <headius@...>
2012/12/11
It's really this easy? If so, I'll send over my public key today :)
[#50795] Re: Becoming a committer
— Yukihiro Matsumoto <matz@...>
2012/12/11
Hi,
[#50797] Re: Becoming a committer
— Charles Oliver Nutter <headius@...>
2012/12/11
I guess there's a few things I'd be interested in:
[#50809] Re: Becoming a committer
— SASADA Koichi <ko1@...>
2012/12/12
(2012/12/12 8:55), Charles Oliver Nutter wrote:
[#50815] Re: Becoming a committer
— Charles Oliver Nutter <headius@...>
2012/12/12
On Wed, Dec 12, 2012 at 12:04 AM, SASADA Koichi <[email protected]> wrote:
[#50816] Re: Becoming a committer
— "NARUSE, Yui" <naruse@...>
2012/12/12
2012/12/12 Charles Oliver Nutter <[email protected]>:
[#50817] Re: Becoming a committer
— Charles Oliver Nutter <headius@...>
2012/12/12
On Wed, Dec 12, 2012 at 2:59 AM, NARUSE, Yui <[email protected]> wrote:
[#50765] [ruby-trunk - Bug #7544][Open] Accented characters in IRB — cfabianski (Cédric FABIANSKI) <cfabianski@...>
6 messages
2012/12/11
[#50793] [ruby-trunk - Bug #7547][Open] Dir.mktmpdir('~something') tries to expand a profile directory — "jstanley0 (Jeremy Stanley)" <jeremy@...>
4 messages
2012/12/11
[#50810] [ruby-trunk - Feature #7549][Open] A Ruby Design Process — "brixen (Brian Ford)" <brixen@...>
34 messages
2012/12/12
[#50829] [ruby-trunk - Feature #7549] A Ruby Design Process
— "subwindow (Erik Peterson)" <erik@...>
2012/12/12
[#50837] [ruby-trunk - Feature #7549] A Ruby Design Process
— "subwindow (Erik Peterson)" <erik@...>
2012/12/12
[#50867] [ruby-trunk - Bug #7556][Assigned] test error on refinement — "usa (Usaku NAKAMURA)" <usa@...>
14 messages
2012/12/13
[#50900] [ruby-trunk - Bug #7564][Open] r38175 introduces incompatibility — "tenderlovemaking (Aaron Patterson)" <aaron@...>
14 messages
2012/12/14
[#50913] [ruby-trunk - Bug #7568][Open] Yaml fails to encode zero date string. — "anshul (Anshul Khandelwal)" <anshul@...>
5 messages
2012/12/15
[#50920] [ruby-trunk - Bug #7568][Assigned] Yaml fails to encode zero date string.
— "charliesome (Charlie Somerville)" <charlie@...>
2012/12/16
[#50988] Re: [ruby-trunk - Bug #7568][Assigned] Yaml fails to encode zero date string.
— Aaron Patterson <tenderlove@...>
2012/12/19
On Sun, Dec 16, 2012 at 12:53:14PM +0900, charliesome (Charlie Somerville) wrote:
[#51015] 1.9.3 patch level release — Zachary Scott <zachary@...>
I know unak-san was asking about a 1.9.3 patch level release, so I
8 messages
2012/12/20
[#51099] [ruby-trunk - Feature #7612][Open] Enumerators take a proc — "pedz (Perry Smith)" <pedz@...>
4 messages
2012/12/23
[ruby-core:50440] Re: [ruby-trunk - Feature #4085] Refinements and nested methods
From:
The 8472 <the8472@...>
Date:
2012-12-01 12:21:20 UTC
List:
ruby-core #50440
On 30.11.2012 20:41, headius (Charles Nutter) wrote:
> respond_to? brings up a really good point: there's lots of methods that might need special refinement care...but I think it makes things more confusing rather than less.
>
> Let's take the respond_to? example. You want respond_to? to reflect refinements. That seems reasonable on the surface, even though respond_to? is not refined itself. The first peculiarity there is that you could no longer wrap respond_to?, respond_to_missing?, method, instance_method, and so on, because wrapping them would break their visibility to refinements (due to the intervening unrefined Ruby frame). We'd be reducing the metaprogrammability of many, many core methods.
>
> And then there's methods that *call* respond_to? (or coercion methods like to_s). Example:
>
> class X; end
>
> module M1
> refine X
> def to_path; '/tmp'; end
> end
> end
>
> using M1
>
> File.open(X.new) # ????
>
> File.open checks respond_to?(:to_path) and if that succeeds it calls to_path. But the above code will never work unless File.open is also made refinement-aware.
>
> I think this is a pretty significant problem, and it shows how much more limited refinements will actually be. The bottom line is that making any core methods reflect refinements may be *more* confusing, because only direct invocations will work...not wrapped invocations, called-method invocations, or double-dispatched invocations.
The common problem of all these methods is that they happen down-stack.
The obvious solution that problem would be the option to make
refinements optionally apply on a thread-scope too, but the performance
implications obviously are horrible as they would could impact any
callsite anywhere in the whole application.
So I think the proper solution is to provide a much much more low-level
metaprogramming alternative: The modification of individual, selected
callsites and methods. I.e. Allow metaprogramming on the AST itself.
Once we can do that we can also inspect the stack - or as potentially
more performant alternative as it wouldn't need to reify the whole stack
- examine thread-local variables.
Modifying the AST obviates the problem of inheritance as the programmer
has precise control of which method or callsite gets modified where.
To express some commonly thrown-around refinement examples as
AST-transforms:
(Concepts shamelessly stolen from Java's MethodHandle/invokedynamic and
AspectJ)
case a) Traditional monkeypatching
class A
def foo
puts "in A"
raise "woops"
end
end
class B < A
def foo
super
puts "after exception!"
end
end
Ruby::AST.methods(A, :foo).enter do |method_name, *args|
puts "inserted in #{self.name}" # we're inside the method here
end
A.new.foo
# inserted in A
# in A
# Exception: woops
# match super call
sites = Ruby::Ast.methods(B, :foo).callsites(A, :foo)
# match existing AST callsites and those defined in the future
transform = sites.transforms(:existing, :future)
# add a new transform
sites.wrap do |source_self,target_self,target_as_proc, *args, &block|
nil # don't execute target method
end
B.new.foo
# after exception!
case b) Simple, scoped Intercept
class C
def m1
"Foo".downcase
end
end
# match methods in C, then select callsites inside those methods
sites = Ruby::AST.methods(C, [:m1,:m2]).callsites(String, :downcase)
# don't modify existing code
sites.transforms(:future).after do |target, result, *args|
result + "x"
end
class C
def m2
"Foo".downcase
end
def m3
"Foo".downcase
end
end
C.new.m1 # => foo
C.new.m2 # => foox
C.new.m3 # => foo
case c) advanced example, down-stack "refinement"
f = future_transforms = []
# not scoped to specific methods here!
sites = Ruby::AST.callsites(String, :dasherize)
transform = sites.transforms(:future, :existing)
transform = transform.guard{Thread.token?(:refine_dasherize)}
# modifies callsites in the whole application
# megamorphic ones will suffer a performance loss from a typecheck.
# optimized, monomorphic callsites will only
# suffer from the thread-local variable check
# since it's not volatile it can be hoisted in loops
f << transform.wrap do |target,target_method_as_proc, *args, &block|
if target_method_as_proc != nil
# ok, target already exists, let's call that
target_method_as_proc.call(*args, &block)
else
# roll our own implementation
target.gsub(%r_/, '-')
end
end
sites = Ruby::AST.callsites(String, :send)
transform = sites.transforms(:future, :existing)
transform = transform.thread_guard(:refine_dasherize)
# same performance impact as above
f << transform.wrap do |target, target_method_as_proc, *args, &block|
if args[0] == :dasherize
# invoke directly -> this is a normal callsite
# -> gets wrapped by previous transform
target.dasherize
else
target_method_as_proc.call(*args,&block)
end
end
# above deals with .send()
# similar could be achieved with Module.prepend
# but callsite modification is invisible to the stack
# and to the module hierarchy
# it's a matter of picking the right tools for the right job
transforms = Ruby::AST.methods(D).transforms(:future)
# enable refinement for all methods in ClassB and downstack
transforms.enter do |method_name, *args, &block|
# thread tokens should be a MultiSet to allow reentrancy
Thread.add_token(:refine_dasherize)
end
transforms.exit do |method_name, return_value, *args, &block|
Thread.remove_token(:refine_dasherize)
return_value
end
class D
def m1
"a_b".dasherize
end
def m2
"a_b".send(:dasherize)
end
end
# transforms(:future) -> code gets patched
require "some_gem"
future_transforms.each{|t| t.suspend}
# code doesn't get patched anymore
require "other_gem"
Is this complex? Yes
Is this verbose? Yes
Can you shoot yourself in the foot with it? Yes
This is intentional. It's a low-level API meant to provide as much
freedom to the programmer as possible. Higher-level abstractions (such
as refinements) can be built ontop of it. These abstractions could cover
many of the conflicting use-cases we have discussed in this thread.
Inheritance? A matter of module/method selectors
File scope? A matter of existing/future transform selectiveness
Super calls? You have full control over them, they're just callsites
OOP integration? Only when you want to go the extra mile
Actually, if we combine AST modification and Module.prepend we can
actually get down-stack refinements with complete OOP-integration if
needed. Assuming an .unprepend is also possible.
In fact, let me write this down:
case c) now with metaclass coercion:
module StringRefinement
def downcase
super + "x"
end
end
Class E
def m1
"Foo".send(:downcase)
end
end
sites = Ruby::Ast.methods(E).callsites(String)
transforms = sites.transform(:existing)
# an alternative to .wrap
# similar to method .enter/.exist. Except it's for callsites
transforms.before do |target,method_name, *args, &block|
target.metaclass.send(:prepend, StringRefinement)
end
transforms.after do |target,method_name, return_value, *args, &block|
target.metaclass.send(:unprepend, StringRefinement)
return_value
end
E.new.m1 # => foox
I think such a fine-grained API is what we will need. No single
high-level API can cover all the use-cases provided for Refinements and
retain performance at the same time. Simply because it is too coarse.