Author: martin
Date: 2005-04-08 07:25:59 -0400 (Fri, 08 Apr 2005)
New Revision: 42688
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/decl.cs
trunk/mcs/gmcs/driver.cs
trunk/mcs/gmcs/expression.cs
trunk/mcs/gmcs/typemanager.cs
Log:
**** Merged r40402-r40410 and r42304 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-08 11:18:16 UTC (rev 42687)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-08 11:25:59 UTC (rev 42688)
@@ -1,3 +1,40 @@
+2005-02-10 Raja R Harinath <[EMAIL PROTECTED]>
+
+ Fix #52586, cs0121-4.cs.
+ * decl.cs (MemberCache.DeepCopy): Rename from SetupCache. Take
+ and return a hashtable.
+ (MemberCache.ClearDeclaredOnly): New.
+ (MemberCache.MemberCache): Update to change. Make a deep copy of
+ the method_hash of a base type too.
+ (MemberCache.AddMethods): Adapt to having a deep copy of the base
+ type methods. Overwrite entries with the same MethodHandle so
+ that the ReflectedType is correct. The process leaves in base
+ virtual functions and their overrides as distinct entries.
+ (CacheEntry): Now a class instead of a struct. It shouldn't alter
+ matters since it was boxed in a ArrayList before.
+ (CacheEntry.Member, CacheEntry.EntryType): Remove 'readonly'
+ modifier.
+ * expression.cs (Invocation.BetterFunction): Simplify. Handle the
+ case of a virtual function and its override (choose the overload
+ as better).
+ (Invocation.OverloadResolve): Avoid 'override' members during
+ 'applicable_type' calculation.
+
+2005-03-28 Raja R Harinath <[EMAIL PROTECTED]>
+
+ * typemanager.cs (TypeHandle.BaseType): Make into an IMemberContainer.
+ (TypeHandle.TypeHandle): Use LookupMemberCache rather than
+ GetTypeHandle. It is possible for a reflected type to derive from
+ a TypeBuilder (e.g., int[] derives from the TypeBuilder
+ System.Array during mscorlib compilation).
+ * decl.cs (MemberCache.MemberCache): If the base cache doesn't
+ contain a method_hash, don't create one either. Don't create a
+ deep copy of the base cache's method_hash.
+ (MemberCache.SetupCache): Rename back from DeepCopy.
+ (MemberCache.AddMethods): Rewrite, now that method_hash isn't
+ already initialized. If we see an override function, add its
+ underlying base virtual function to the member_hash too.
+
2005-02-09 Raja R Harinath <[EMAIL PROTECTED]>
Combine two near-redundant caches.
Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs 2005-04-08 11:18:16 UTC (rev 42687)
+++ trunk/mcs/gmcs/decl.cs 2005-04-08 11:25:59 UTC (rev 42688)
@@ -1770,7 +1770,10 @@
// If this is neither a dynamic type nor an interface,
create a special
// method cache with all declared and inherited methods.
Type type = container.Type;
- if (!(type is TypeBuilder) && !type.IsInterface &&
!type.IsGenericParameter) {
+ if (!(type is TypeBuilder) && !type.IsInterface &&
+ // !(type.IsGenericInstance &&
(type.GetGenericTypeDefinition () is TypeBuilder)) &&
+ !type.IsGenericInstance &&
+ (Container.BaseCache == null ||
Container.BaseCache.method_hash != null)) {
method_hash = new Hashtable ();
AddMethods (type);
}
@@ -1815,6 +1818,15 @@
return hash;
}
+ void ClearDeclaredOnly (Hashtable hash)
+ {
+ IDictionaryEnumerator it = hash.GetEnumerator ();
+ while (it.MoveNext ()) {
+ foreach (CacheEntry ce in (ArrayList) it.Value)
+ ce.EntryType &= ~EntryType.Declared;
+ }
+ }
+
/// <summary>
/// Add the contents of `cache' to the member_hash.
/// </summary>
@@ -1913,7 +1925,16 @@
void AddMethods (BindingFlags bf, Type type)
{
- MemberInfo [] members = type.GetMethods (bf);
+ //
+ // Consider the case:
+ //
+ // class X { public virtual int f() {} }
+ // class Y : X {}
+ //
+ // When processing 'Y', the method_cache will already
have a copy of 'f',
+ // with ReflectedType == X. However, we want to ensure
that its ReflectedType == Y
+ //
+ MethodBase [] members = type.GetMethods (bf);
Array.Reverse (members);
@@ -1927,6 +1948,52 @@
method_hash.Add (name, list);
}
+ if (member.IsVirtual &&
+ (member.Attributes &
MethodAttributes.NewSlot) == 0) {
+ MethodInfo base_method = ((MethodInfo)
member).GetBaseDefinition ();
+
+ if (base_method == member) {
+ //
+ // Both mcs and CSC 1.1 seem to
emit a somewhat broken
+ // ...Invoke () function for
delegates: it's missing a 'newslot'.
+ // CSC 2.0 emits a 'newslot'
for a delegate's Invoke.
+ //
+ if (member.Name != "Invoke" ||
+ !TypeManager.IsDelegateType
(type)) {
+
Report.SymbolRelatedToPreviousError (base_method);
+ Report.Warning (-28,
+ "{0} contains a
method '{1}' that is marked " +
+ " virtual, but
doesn't appear to have a slot." +
+ " The method
may be ignored during overload resolution",
+ type,
base_method);
+ }
+ goto skip;
+ }
+
+ for (;;) {
+ list.Add (new CacheEntry (null,
base_method, MemberTypes.Method, bf));
+ if ((base_method.Attributes &
MethodAttributes.NewSlot) != 0)
+ break;
+
+ //
+ // Shouldn't get here. Mono
appears to be buggy.
+ //
+ MethodInfo new_base_method =
base_method.GetBaseDefinition ();
+ if (new_base_method ==
base_method) {
+
Report.SymbolRelatedToPreviousError (base_method);
+ Report.Warning (-28,
+ "{0} contains a
method '{1}' that is marked " +
+ " virtual, but
doesn't appear to have a slot." +
+ " The method
may be ignored during overload resolution",
+ type,
base_method);
+ }
+ base_method = new_base_method;
+ }
+
+
+ }
+ skip:
+
// Unfortunately, the elements returned by
Type.GetMethods() aren't
// sorted so we need to do this check for every
member.
BindingFlags new_bf = bf;
@@ -2022,10 +2089,10 @@
MaskType =
Constructor|Event|Field|Method|Property|NestedType
}
- protected struct CacheEntry {
+ protected class CacheEntry {
public readonly IMemberContainer Container;
- public readonly EntryType EntryType;
- public readonly MemberInfo Member;
+ public EntryType EntryType;
+ public MemberInfo Member;
public CacheEntry (IMemberContainer container,
MemberInfo member,
MemberTypes mt, BindingFlags bf)
Modified: trunk/mcs/gmcs/driver.cs
===================================================================
--- trunk/mcs/gmcs/driver.cs 2005-04-08 11:18:16 UTC (rev 42687)
+++ trunk/mcs/gmcs/driver.cs 2005-04-08 11:25:59 UTC (rev 42688)
@@ -255,7 +255,7 @@
"For more information on Mono, visit the
project Web site\n" +
" http://www.go-mono.com\n\n" +
- "The compiler was written by Miguel de Icaza,
Ravi Pratap, Martin Baulig and Marek Safar");
+ "The compiler was written by Miguel de Icaza,
Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath");
Environment.Exit (0);
}
Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs 2005-04-08 11:18:16 UTC (rev 42687)
+++ trunk/mcs/gmcs/expression.cs 2005-04-08 11:25:59 UTC (rev 42688)
@@ -4454,40 +4454,8 @@
ParameterData candidate_pd =
TypeManager.GetParameterData (candidate);
ParameterData best_pd = TypeManager.GetParameterData
(best);
- int cand_count = candidate_pd.Count;
-
- //
- // If there is no best method, than this one
- // is better, however, if we already found a
- // best method, we cant tell. This happens
- // if we have:
- //
- // interface IFoo {
- // void DoIt ();
- // }
- //
- // interface IBar {
- // void DoIt ();
- // }
- //
- // interface IFooBar : IFoo, IBar {}
- //
- // We cant tell if IFoo.DoIt is better than IBar.DoIt
- //
- // However, we have to consider that
- // Trim (); is better than Trim (params char[] chars);
- //
- if (cand_count == 0 && argument_count == 0)
- return !candidate_params && best_params;
-
- if ((candidate_pd.ParameterModifier (cand_count - 1) !=
Parameter.Modifier.PARAMS) &&
- (candidate_pd.ParameterModifier (cand_count - 1) !=
Parameter.Modifier.ARGLIST))
- if (cand_count != argument_count)
- return false;
-
bool better_at_least_one = false;
- bool is_equal = true;
-
+ bool same = true;
for (int j = 0; j < argument_count; ++j) {
Argument a = (Argument) args [j];
@@ -4502,9 +4470,10 @@
if (best_params)
bt = TypeManager.GetElementType
(bt);
- if (!ct.Equals (bt))
- is_equal = false;
+ if (ct.Equals (bt))
+ continue;
+ same = false;
Type better = BetterConversion (ec, a, ct, bt,
loc);
// for each argument, the conversion to 'ct'
should be no worse than
// the conversion to 'bt'.
@@ -4517,28 +4486,48 @@
better_at_least_one = true;
}
- //
- // If a method (in the normal form) with the
- // same signature as the expanded form of the
- // current best params method already exists,
- // the expanded form is not applicable so we
- // force it to select the candidate
- //
- if (!candidate_params && best_params && cand_count ==
argument_count)
- return true;
+ if (better_at_least_one)
+ return true;
+ if (!same)
+ return false;
+
//
// If two methods have equal parameter types, but
// only one of them is generic, the non-generic one
wins.
//
- if (is_equal) {
- if (TypeManager.IsGenericMethod (best) &&
!TypeManager.IsGenericMethod (candidate))
- return true;
- else if (!TypeManager.IsGenericMethod (best) &&
TypeManager.IsGenericMethod (candidate))
- return false;
+ if (TypeManager.IsGenericMethod (best) &&
!TypeManager.IsGenericMethod (candidate))
+ return true;
+ else if (!TypeManager.IsGenericMethod (best) &&
TypeManager.IsGenericMethod (candidate))
+ return false;
+
+ //
+ // Note that this is not just an optimization. This
handles the case
+ //
+ // Add (float f1, float f2, float f3);
+ // Add (params decimal [] foo);
+ //
+ // The call Add (3, 4, 5) should be ambiguous. Without
this check, the
+ // first candidate would've chosen as better.
+ //
+ if (candidate_params == best_params) {
+ //
+ // We need to handle the case of a virtual
function and its override.
+ // The override is ignored during
'applicable_type' calculation. However,
+ // it should be chosen over the base virtual
function, especially when handling
+ // value types.
+ //
+ return IsAncestralType (best.DeclaringType,
candidate.DeclaringType);
}
- return better_at_least_one;
+ //
+ // This handles the following cases:
+ //
+ // Trim () is better than Trim (params char[] chars)
+ // Concat (string s1, string s2, string s3) is better
than
+ // Concat (string s1, params string [] srest)
+ //
+ return !candidate_params && best_params;
}
public static string FullMethodDesc (MethodBase mb)
@@ -4881,6 +4870,15 @@
candidates.Add (methods [i]);
+ //
+ // Methods marked 'override' don't take part in
'applicable_type'
+ // computation.
+ //
+ if (!me.IsBase &&
+ methods [i].IsVirtual &&
+ (methods [i].Attributes &
MethodAttributes.NewSlot) == 0)
+ continue;
+
if (applicable_type == null)
applicable_type = decl_type;
else if (applicable_type != decl_type) {
@@ -4892,7 +4890,7 @@
int candidate_top = candidates.Count;
- if (candidate_top == 0) {
+ if (applicable_type == null) {
//
// Okay so we have failed to find anything so we
// return by providing info about the closest
match
@@ -4965,11 +4963,12 @@
int j = finalized; // where to put the
next finalized candidate
int k = finalized; // where to put the
next undiscarded candidate
for (int i = finalized; i <
candidate_top; ++i) {
- Type decl_type = ((MethodBase)
candidates[i]).DeclaringType;
+ MethodBase candidate =
(MethodBase) candidates [i];
+ Type decl_type =
candidate.DeclaringType;
if (decl_type ==
applicable_type) {
- candidates[k++] =
candidates[j];
- candidates[j++] =
candidates[i];
+ candidates [k++] =
candidates [j];
+ candidates [j++] =
candidates [i];
continue;
}
@@ -4980,8 +4979,19 @@
IsAncestralType (decl_type,
next_applicable_type))
continue;
- candidates[k++] = candidates[i];
+ candidates [k++] = candidates
[i];
+#if false
+ //
+ // Methods marked 'override'
don't take part in 'applicable_type'
+ // computation.
+ //
+ if (!me.IsBase &&
+ candidate.IsVirtual &&
+ (candidate.Attributes &
MethodAttributes.NewSlot) == 0)
+ continue;
+#endif
+
if (next_applicable_type ==
null ||
IsAncestralType
(next_applicable_type, decl_type))
next_applicable_type =
decl_type;
@@ -4997,10 +5007,14 @@
// Now we actually find the best method
//
- method = (MethodBase) candidates[0];
+ method = (MethodBase) candidates [0];
method_params = candidate_to_form != null &&
candidate_to_form.Contains (method);
for (int ix = 1; ix < candidate_top; ix++){
MethodBase candidate = (MethodBase) candidates
[ix];
+
+ if (candidate == method)
+ continue;
+
bool cand_params = candidate_to_form != null &&
candidate_to_form.Contains (candidate);
if (BetterFunction (ec, Arguments, arg_count,
Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs 2005-04-08 11:18:16 UTC (rev 42687)
+++ trunk/mcs/gmcs/typemanager.cs 2005-04-08 11:25:59 UTC (rev 42688)
@@ -3027,7 +3027,7 @@
/// There is exactly one instance of this class per type.
/// </summary>
public sealed class TypeHandle : IMemberContainer {
- public readonly TypeHandle BaseType;
+ public readonly IMemberContainer BaseType;
readonly int id = ++next_id;
static int next_id = 0;
@@ -3102,8 +3102,8 @@
this.type = type;
full_name = type.FullName != null ? type.FullName : type.Name;
if (type.BaseType != null) {
- BaseType = GetTypeHandle (type.BaseType);
- base_cache = BaseType.MemberCache;
+ base_cache = TypeManager.LookupMemberCache
(type.BaseType);
+ BaseType = base_cache.Container;
} else if (type.IsInterface)
base_cache = TypeManager.LookupBaseInterfacesCache
(type);
this.is_interface = type.IsInterface || type.IsGenericParameter;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches