Three weeks later. Looks good. (I can't see any other reviews of this, let me 
know if I'm wrong so I can figure out what happened to that email ;))

JD

...there is no try

From: Shri Borde
Sent: Wednesday, April 22, 2009 4:52 PM
To: IronRuby External Code Reviewers
Cc: ironruby-core@rubyforge.org
Subject: Review: Equality and misc fixes

http://github.com/shri/ironruby/commit/19a5ea114cf91ed9bd4ba1871da28293240fe344

Here is the description I put at 
http://www.ironruby.net/Documentation/CLR_Interop/Specification:
Equality and hashing [Edit section] 
<http://www.ironruby.net/Documentation/CLR_Interop/Specification>
Object equality and hashing are fundamental properties of objects. The Ruby API 
for comparing and hashing objects is Object#== (or Object#eql?) and Object#hash 
respectively. The CLR APIs are System.Object.Equals and 
System.Object.GetHashCode respectively. IronRuby does an automatic mapping 
between the two concepts so that Ruby objects can be compared and hashsed from 
static MSIL code and vice versa.
When Ruby code calls #== and #hash [Edit section] 
<http://www.ironruby.net/Documentation/CLR_Interop/Specification>

  *   If the object is a Ruby object, the default implementations of #== and 
#hash get called. The default implementations call 
System.Object.ReferenceEquals and 
System.Runtime.CompileServices.RuntimeHelpers.GetHashCode respectively.
  *   If the object is a CLR object, System.Object.Equals and 
System.Object.GetHashCode respectively get called on the CLR object.
  *   If the object is a Ruby subclass object inheriting from a CLR class, the 
CLR's class's implementation of System.Object.Equals and 
System.Object.GetHashCode will get called if the Ruby subclass does not define 
#== and #hash. If the Ruby subclass defines #== and #hash, those will be called 
instead.
When static MSIL code calls System.Object.Equals and System.Object.GetHashCode 
[Edit section] <http://www.ironruby.net/Documentation/CLR_Interop/Specification>

  *   If the object is a Ruby objects, the Ruby object will direct the call to 
#== and #hash. If the Ruby object has implementations for these methods, they 
will be called. Otherwise, the default implementation mentioned above gets 
called.
  *   If the object is a Ruby subclass object inheriting from a CLR class,  the 
CLR's class's implementation of System.Object.Equals and 
System.Object.GetHashCode will get called if the Ruby subclass does not define 
#== and #hash. If the Ruby subclass defines #== and #hash, those will be called 
instead.
Hashing of mutable objects
The CLR expects that System.Object.GetHashCode always returns the same value 
for a given object. If this invariant is not maintained, using the object as a 
key in a System.Collections.Generic.Dictionary<K,V> will misbehave. Ruby allows 
#hash to return different results, and relies on the user to deal with the 
scenario of using the object as a key in a Hash. The mapping above between the 
Ruby and CLR concepts of equality and hashing means that CLR code that deals 
with Ruby objects has to be aware of the issue. If static MSIL code uses a Ruby 
object as a the key in a Dictionary<K,V>, unexpected behavior might happen.
To reduce the chances of this happenning when using common Ruby types, IronRuby 
does not map #hash to GetHashCode for Array and Hash. For other Ruby classes, 
the user can provide separate implementations for #== and Equals, and #hash and 
GetHashCode if the Ruby class is mutable but also needs to be usable as a key 
in a Dictionary<K,V>.



http://github.com/shri/ironruby/commit/3239e977f7b7697129f43259b23f829411a96e51


"ir.exe -Ifoo" should work. We were requiring "-I foo".
Removed critical tags in io\close that I noticed were working.
Miscellaneous new tests in File.basename
Our copy of unit\testcase.rb uses SubclassTracker which is defined in "hacks" 
and so should require "hacks"

<<inline: image001.gif>>

_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to