[Ironruby-core] Code Review: IO7

Tomas Matousek Tomas.Matousek at microsoft.com
Thu Feb 5 19:44:42 EST 2009


tfpt review "/shelveset:IO7;REDMOND\tomat"

Reviewed F2F by Curt.

1) Includes inherited overloads in CLR method groups (RubyMethodGroupInfo). Method groups can now comprise of methods that are declared in multiple derived types. This might be a bit strange concept for Ruby programmer since "overloads" can only be defined in a C library in Ruby and all of them in a single class. Some examples how basic Ruby operations work with CLR inherited overloads:

CLR hierarchy:
class A { void f(int); }
class B : A { void f(int, int); }
class C : B { void f(int, int, int); }

Ruby view:
class A: "f" => MethodGroup { A::f(int) }
class B: "f" => MethodGroup { A::f(int), B::f(int, int) }
class C: "f" => MethodGroup { A::f(int), B::f(int, int), C::f(int, int, int) }

Following calls work:
C.new.f(1)
C.new.f(1,2)
C.new.f(1,2,3)

In each case, C#f is found and overload resolution based on passed argument types is performed on overloads contained in C#f group.

If B is monkey-patched

class B
  def f; end
end

the new Ruby method hides all overloads in B and above. The Ruby view is now:

class A: "f" => MethodGroup { A::f(int) }
class B: "f" => RubyMethod
class C: "f" => MethodGroup { C::f(int, int, int) }

It is no longer possible to call A::f, B::f overloads from an instance of C:
C.new.f(1)  # error
C.new.f(1,2)  # calls Ruby method
C.new.f(1,2,3)   # calls C::f(int,int,int) overload

If we remove B#f, we get to the previous state:

class B
   remove_method :f
end

C.new.f(1)      # works
C.new.f(1,2)  # works
C.new.f(1,2,3)    # works

Strangely enough, we can remove "f" again from B - now it would be the CLR method group "f" (see #2).

2) Enables removing CLR methods.

If CLR method group "f" is removed from a class (say X) then all CLR methods "f" that are declared below the first member "f" (in the inheritance hierarchy) that is not a CLR method group are not accessible from an instance of X or any of its subclasses. This also means that it is not possible to remove a method override and call the overridden method, since the overridden method is removed as well along with the override. This behavior is consistent with CLR restrictions on virtual method calls - it is not verifiable to call an overridden virtual method directly. Although the restriction is unnecessary for non-virtual new-slot methods, which could be called directly, it makes the semantics and implementation simpler. Removing a CLR method group just hides all CLR methods of the same name below the first non-CLR or non-method member.

3) Removes some exceptions thrown from Ruby meta-object binders. Eventually Ruby binders will use "fallback" mechanism instead of throwing exceptions, this is the first step. Implements a new caching mechanism for calls to methods that are handled by method_missing.

5) Moves version tracking from RubyModule to RubyClasses. We don't need to track versions of mixins.

6) Replaces strong references to dependent modules with weak ones. The number of weak references allocated for tracking class hierarchy dependencies is exactly equal to the number of classes in the hierarchy. Each class defines a weak reference pointing to itself and this weak reference is reused in all lists that track dependency on this class.

7) Reimplements dynamic site cache invalidation for mixin inclusions. Previously we invalidated far too many sites that don't need to be invalidated. Reduces site cache invalidation rate during RoR startup phase to 33% of the current value (from 9161 invalidated rules to 3017).

In the table below, the two numbers for each module update operation are the number of modules whose version is incremented due to the update and the number of rules that are bound to the old version. Such rules' tests are going to be evaluated to false next time they are invoked.

Before:

module

operation

modules

rules

Object

IncludeModules

201

5644

Kernel

SetMethod: require

34

1138

Object

IncludeModules

58

495

Object

IncludeModules

70

382

Object

SetMethod: require

81

317

Kernel

IncludeModules

50

308

Module

SetMethod: append_features

18

254

Enumerable

IncludeModules

9

242

Array

CreateInstanceSingleton

1

59

Module

IncludeModules

46

47

Module

IncludeModules

47

44

Array

IncludeModules

1

32

Object

IncludeModules

81

27


SetMethod: method_added

12

24

Class

SetMethod: inherited

15

19

Set

CreateInstanceSingleton

1

13

Hash

IncludeModules

1

11

Class

IncludeModules

23

11

Array

CreateInstanceSingleton

1

10

String

IncludeModules

1

8


IncludeModules

1

8


IncludeModules

1

7


IncludeModules

1

7

Hash

IncludeModules

1

6

Symbol

IncludeModules

1

6

String

IncludeModules

1

5


IncludeModules

1

5

Integer

IncludeModules

2

4

Inflector

SetMethod: inflections

2

4


IncludeModules

1

4


IncludeModules

1

4

REXML::XMLDecl

CreateInstanceSingleton

1

3

Integer

IncludeModules

2

2


IncludeModules

1

2


IncludeModules

1

2


RemoveMethodNoEvent

1

1

String

IncludeModules

1

1


IncludeModules

1

1


IncludeModules

1

1


SetMethod: included

1

1


IncludeModules

1

1


SetMethod: new

1

1



After:

UPDATED:

Object

SetMethod: require

425

1592

UPDATED:

Object

SetMethod: require

200

966

UPDATED:

Module

SetMethod: append_features

135

259

UPDATED:

Array

CreateInstanceSingleton

4

82

UPDATED:

Class

SetMethod: inherited

126

58

UPDATED:

SetMethod: method_added

110

24

UPDATED:

Set

CreateInstanceSingleton

2

13

UPDATED:

Array

CreateInstanceSingleton

5

10

UPDATED:

SetMethod: inherited

1

4

UPDATED:

REXML::XMLDecl

CreateInstanceSingleton

1

3

UPDATED:

SetMethod: inherited

1

2

UPDATED:

RemoveMethodNoEvent

1

1

UPDATED:

SetMethod: inherited

1

1

UPDATED:

SetMethod: included

1

1

UPDATED:

SetMethod: new

1

1


Further optimizations might include special caching policy for require, append_features, inherited, method_added and other Ruby "notifications".


8)      Fixes various bugs related to the features implemented/improved and adds bunch of unit tests.

Tomas


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090205/cd3e6e7e/attachment-0001.html>


More information about the Ironruby-core mailing list