Skip to content

Commit

Permalink
Backported: Bug fix. The static compiler cannot use a different way t…
Browse files Browse the repository at this point in the history
…o encode erased array types than the runtime compiler (because otherwise the runtime can't override statically compiled methods).
  • Loading branch information
jfrijters committed Dec 6, 2012
1 parent f7408ca commit e02eb45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
7 changes: 1 addition & 6 deletions runtime/DynamicTypeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5999,18 +5999,13 @@ internal static Type[] GetModOpt(TypeWrapperFactory context, TypeWrapper tw, boo
TypeWrapper tw1 = tw.IsArray ? tw.GetUltimateElementTypeWrapper() : tw;
if (tw1.IsErasedOrBoxedPrimitiveOrRemapped || tw.IsGhostArray || (mustBePublic && !tw1.IsPublic))
{
#if STATIC_COMPILER
modopt = new Type[] { GetModOptHelper(tw) };
#else
// FXBUG Ref.Emit refuses arrays in custom modifiers, so we add an array type for each dimension
// (note that in this case we only add the custom modifiers to make the signature unique, we never read back this information)
modopt = new Type[tw.ArrayRank + 1];
modopt[0] = GetModOptHelper(tw1);
for (int i = 1; i < modopt.Length; i++)
{
modopt[i] = typeof(Array);
modopt[i] = Types.Array;
}
#endif
}
}
return modopt;
Expand Down
58 changes: 29 additions & 29 deletions runtime/TypeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4413,55 +4413,55 @@ internal string GetGenericSignature()
}
}

private static TypeWrapper TypeWrapperFromModOpt(Type modopt)
private static TypeWrapper TypeWrapperFromModOpt(Type[] modopt)
{
int rank = 0;
while (ReflectUtil.IsVector(modopt))
TypeWrapper tw = null;
foreach (Type type in modopt)
{
rank++;
modopt = modopt.GetElementType();
if (type == JVM.LoadType(typeof(IKVM.Attributes.AccessStub)))
{
// ignore
}
else if (type == Types.Array)
{
rank++;
}
else if (type == Types.Void || type.IsPrimitive || ClassLoaderWrapper.IsRemappedType(type))
{
tw = DotNetTypeWrapper.GetWrapperFromDotNetType(type);
}
else
{
tw = ClassLoaderWrapper.GetWrapperFromType(type)
?? new UnloadableTypeWrapper(TypeNameUtil.UnmangleNestedTypeName(type.Name), type);
}
}
if (rank != 0)
{
return TypeWrapperFromModOpt(modopt).MakeArrayType(rank);
}
else if (modopt == Types.Void || modopt.IsPrimitive || ClassLoaderWrapper.IsRemappedType(modopt))
{
return DotNetTypeWrapper.GetWrapperFromDotNetType(modopt);
}
else
{
return ClassLoaderWrapper.GetWrapperFromType(modopt)
?? new UnloadableTypeWrapper(TypeNameUtil.UnmangleNestedTypeName(modopt.Name), modopt);
tw = tw.MakeArrayType(rank);
}
return tw;
}

private static TypeWrapper GetPropertyTypeWrapper(PropertyInfo property)
{
Type[] modopt = property.GetOptionalCustomModifiers();
return modopt.Length == 0
? ClassLoaderWrapper.GetWrapperFromType(property.PropertyType)
: TypeWrapperFromModOpt(modopt[0]);
return TypeWrapperFromModOpt(property.GetOptionalCustomModifiers())
?? ClassLoaderWrapper.GetWrapperFromType(property.PropertyType);
}

private static TypeWrapper GetFieldTypeWrapper(FieldInfo field)
{
Type[] modopt = field.GetOptionalCustomModifiers();
return modopt.Length == 0
? ClassLoaderWrapper.GetWrapperFromType(field.FieldType)
: TypeWrapperFromModOpt(modopt[0]);
return TypeWrapperFromModOpt(field.GetOptionalCustomModifiers())
?? ClassLoaderWrapper.GetWrapperFromType(field.FieldType);
}

private static TypeWrapper GetParameterTypeWrapper(ParameterInfo param)
{
// we don't want to rely on the ordering of the custom modifiers,
// because reflection (currently) reports them in reverse order
foreach (Type modopt in param.GetOptionalCustomModifiers())
TypeWrapper tw = TypeWrapperFromModOpt(param.GetOptionalCustomModifiers());
if (tw != null)
{
if (modopt != JVM.LoadType(typeof(IKVM.Attributes.AccessStub)))
{
return TypeWrapperFromModOpt(modopt);
}
return tw;
}
Type parameterType = param.ParameterType;
if (parameterType.IsByRef)
Expand Down

0 comments on commit e02eb45

Please sign in to comment.