# Code Review: Conversions12

**URL:** <https://www.ruby-forum.com/t/code-review-conversions12/168351>\
**Category:** IronRuby\
**Created:** [May 19, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/code-review-conversions12/168351 "2009-05-19T21:47:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 19, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/code-review-conversions12/168351/1 "2009-05-19T21:47:32Z")

</div>

tfpt review “/shelveset:Conversions12;REDMOND\tomat”

DLR:

RestrictionInfo is renamed to RestrictedArguments and passed to  
ArgBuilder.ToExpression and ArgBuilder.ToDelegate instead of  
List. This way the methods have full information on the  
meta-arguments as well as their restrictions that were used to resolve  
the overload.

OverloadResolver.ConvertExpression now takes DynamicMetaObject and its  
restricted Type. Conversions can directly cast the value to the  
restricted type (if visible) instead of testing the type again.

ConversionResult - hold on the argument value as well as its limit type.  
We need to report class name in an error message that can only be  
retrieved from the actual object not the CLR type.

Adds InstanceBuilder class, removes NullArgBuilder. NullArgBuilder is  
handled as a special case in InstanceBuilder. InstanceBuilder first  
finds a callable method if the current method info is not and then  
converts the instance argument to the declaring type of the method  
(could be an interface). It uses limit type of the instance meta  
argument to determine the callable method. The limit type could be an  
internal type that inherits an implementation of the method from its  
super type and exposes it via a public interface. In that case the  
declaring type of the method info given to the overload resolver is the  
base type yet that type might not implement the interface that exposes  
the method in the derived type. Hence we need to use the real type of  
the argument to find out the callable interface method in  
GetCallableMethod.

Fixes a bug in MetaObjectExtensions.Restrict - the method created  
meta-objects with a value given meta-objects w/o one.

Ruby:

Removes legacy implementation of conversions (copied long time ago from  
Python) and replaces it by a new one. We use 3 narrowing levels for  
conversions performed in overload resolution. Implicit static  
conversions are considered in level 1, explicit static conversions on  
level 2 and dynamic conversions on level 3.

Adds GenericConversionAction that implements dynamic non-protocol  
conversion to an arbitrary type.

ClsTypeEmitter: replaces conversions with conversion dynamic site. Adds  
dynamic site construction expressions to a list as they are emitted to  
IL and at the end, when the type is being finished, combines them all  
into a single block expression and emits that into a static method. This  
static method is then called from cctor. The approach can also be used  
for the other sites initialized in cctor (not included in this  
shelveset).

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 20, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/code-review-conversions12/168351/2 "2009-05-20T15:35:06Z")

</div>

Fixed. I renamed OverloadResolver.ConvertExpression to Convert and  
ConvertObject that returns Func\<object[], object\> to  
GetConversionDelegate.

Tomas

From: Dino Viehland  
Sent: Tuesday, May 19, 2009 1:19 PM  
To: Tomas M.; IronRuby External Code R.; Rowan Code  
Reviewers  
Cc: removed\_email\_address@domain.invalid  
Subject: RE: Code Review: Conversions12

Why does ActionBinder.ConvertExpression lose its comment?

OutArgBuilder’s /ReturnReferenceArgBuilder - new namespace is added in  
an ugly way (and again in  
ReferenceArgBuilder/ReturnBuilder/MethodCandidate/RestrictionInfo but  
it’s not as ugly - just not sorted).

OverloadResolver.ConvertExpression should be renamed to  
ConvertMetaObject.

Otherwise looks good!

From: Tomas M.  
Sent: Tuesday, May 19, 2009 12:40 PM  
To: IronRuby External Code R.; Rowan Code R.  
Cc: removed\_email\_address@domain.invalid  
Subject: Code Review: Conversions12

tfpt review “/shelveset:Conversions12;REDMOND\tomat”

DLR:

RestrictionInfo is renamed to RestrictedArguments and passed to  
ArgBuilder.ToExpression and ArgBuilder.ToDelegate instead of  
List. This way the methods have full information on the  
meta-arguments as well as their restrictions that were used to resolve  
the overload.

OverloadResolver.ConvertExpression now takes DynamicMetaObject and its  
restricted Type. Conversions can directly cast the value to the  
restricted type (if visible) instead of testing the type again.

ConversionResult - hold on the argument value as well as its limit type.  
We need to report class name in an error message that can only be  
retrieved from the actual object not the CLR type.

Adds InstanceBuilder class, removes NullArgBuilder. NullArgBuilder is  
handled as a special case in InstanceBuilder. InstanceBuilder first  
finds a callable method if the current method info is not and then  
converts the instance argument to the declaring type of the method  
(could be an interface). It uses limit type of the instance meta  
argument to determine the callable method. The limit type could be an  
internal type that inherits an implementation of the method from its  
super type and exposes it via a public interface. In that case the  
declaring type of the method info given to the overload resolver is the  
base type yet that type might not implement the interface that exposes  
the method in the derived type. Hence we need to use the real type of  
the argument to find out the callable interface method in  
GetCallableMethod.

Fixes a bug in MetaObjectExtensions.Restrict - the method created  
meta-objects with a value given meta-objects w/o one.

Ruby:

Removes legacy implementation of conversions (copied long time ago from  
Python) and replaces it by a new one. We use 3 narrowing levels for  
conversions performed in overload resolution. Implicit static  
conversions are considered in level 1, explicit static conversions on  
level 2 and dynamic conversions on level 3.

Adds GenericConversionAction that implements dynamic non-protocol  
conversion to an arbitrary type.

ClsTypeEmitter: replaces conversions with conversion dynamic site. Adds  
dynamic site construction expressions to a list as they are emitted to  
IL and at the end, when the type is being finished, combines them all  
into a single block expression and emits that into a static method. This  
static method is then called from cctor. The approach can also be used  
for the other sites initialized in cctor (not included in this  
shelveset).

Tomas
