[mono/mono] 66403410: [mcs] Excluded methods should not take a part in flow analysis

"Marek Safar ([email protected])" <[email protected]> Mon, 25 Nov 2013 16:53:52 +0000
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000142902e731f-1a7f9eb5-add6-424c-b9e7-53348f2adae1-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/1d5cefe7ad5e...66403410b0b8

   Commit: 66403410b0b887d3ecb65add8bee3ed7e685bc9d
   Author: Marek Safar <[email protected]> (marek-safar)
     Date: 2013-11-25 16:51:34 GMT
      URL: https://github.com/mono/mono/commit/66403410b0b887d3ecb65add8bee3ed7e685bc9d

[mcs] Excluded methods should not take a part in flow analysis

Changed paths:
  M mcs/mcs/codegen.cs
  M mcs/mcs/delegate.cs
  M mcs/mcs/ecore.cs
  M mcs/mcs/expression.cs
  M mcs/mcs/method.cs
Added paths:
  A mcs/errors/cs0165-33.cs

Added: mcs/errors/cs0165-33.cs
===================================================================
@@ -0,0 +1,20 @@
+// CS0165: Use of unassigned local variable `a'
+// Line: 13
+
+using System;
+using System.Diagnostics;
+
+class C
+{
+	static int Main ()
+	{
+		int a;
+		Foo (a = 9);
+		return a;
+	}
+
+	[Conditional ("MISSING")]
+	static void Foo (int value)
+	{
+	}
+}
\ No newline at end of file

Modified: mcs/mcs/codegen.cs
===================================================================
@@ -968,10 +968,6 @@ struct CallEmitter
 
 		public void Emit (EmitContext ec, MethodSpec method, Arguments Arguments, Location loc)
 		{
-			// Speed up the check by not doing it on not allowed targets
-			if (method.ReturnType.Kind == MemberKind.Void && method.IsConditionallyExcluded (ec.MemberContext))
-				return;
-
 			EmitPredefined (ec, method, Arguments, loc);
 		}
 

Modified: mcs/mcs/delegate.cs
===================================================================
@@ -532,7 +532,7 @@ protected override Expression DoResolve (ResolveContext ec)
 				}
 			}
 
-			TypeSpec rt = delegate_method.ReturnType;
+			TypeSpec rt = method_group.BestCandidateReturnType;
 			if (rt.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
 				rt = ec.BuiltinTypes.Object;
 
@@ -541,7 +541,7 @@ protected override Expression DoResolve (ResolveContext ec)
 				Error_ConversionFailed (ec, delegate_method, ret_expr);
 			}
 
-			if (delegate_method.IsConditionallyExcluded (ec)) {
+			if (method_group.IsConditionallyExcluded) {
 				ec.Report.SymbolRelatedToPreviousError (delegate_method);
 				MethodOrOperator m = delegate_method.MemberDefinition as MethodOrOperator;
 				if (m != null && m.IsPartialDefinition) {

Modified: mcs/mcs/ecore.cs
===================================================================
@@ -3550,6 +3550,8 @@ bool OverloadResolver.IErrorHandler.TypeInferenceFailed (ResolveContext rc, Memb
 	/// </summary>
 	public class MethodGroupExpr : MemberExpr, OverloadResolver.IBaseMembersProvider
 	{
+		static readonly MemberSpec[] Excluded = new MemberSpec[0];
+
 		protected IList<MemberSpec> Methods;
 		MethodSpec best_candidate;
 		TypeSpec best_candidate_return;
@@ -3599,6 +3601,12 @@ public MethodGroupExpr (MethodSpec m, TypeSpec type, Location loc)
 			}
 		}
 
+		public bool IsConditionallyExcluded {
+			get {
+				return Methods == Excluded;
+			}
+		}
+
 		public override bool IsInstance {
 			get {
 				if (best_candidate != null)
@@ -3668,7 +3676,7 @@ public override Expression CreateExpressionTree (ResolveContext ec)
 				return null;
 			}
 
-			if (best_candidate.IsConditionallyExcluded (ec))
+			if (IsConditionallyExcluded)
 				ec.Report.Error (765, loc,
 					"Partial methods with only a defining declaration or removed conditional methods cannot be used in an expression tree");
 			
@@ -3793,6 +3801,10 @@ public virtual MethodGroupExpr OverloadResolve (ResolveContext ec, ref Arguments
 				ErrorIsInaccesible (ec, best_candidate.GetSignatureForError (), loc);
 			}
 
+			// Speed up the check by not doing it on disallowed targets
+			if (best_candidate_return.Kind == MemberKind.Void && best_candidate.IsConditionallyExcluded (ec))
+				Methods = Excluded;
+
 			return this;
 		}
 

Modified: mcs/mcs/expression.cs
===================================================================
@@ -6223,6 +6223,9 @@ protected virtual MethodGroupExpr DoResolveOverload (ResolveContext ec)
 
 		public override void FlowAnalysis (FlowAnalysisContext fc)
 		{
+			if (mg.IsConditionallyExcluded)
+				return;
+
 			mg.FlowAnalysis (fc);
 
 			if (arguments != null)
@@ -6269,6 +6272,9 @@ public static bool IsSpecialMethodInvocation (ResolveContext ec, MethodSpec meth
 
 		public override void Emit (EmitContext ec)
 		{
+			if (mg.IsConditionallyExcluded)
+				return;
+
 			mg.EmitCall (ec, arguments);
 		}
 		

Modified: mcs/mcs/method.cs
===================================================================
@@ -205,6 +205,8 @@ public sealed class MethodSpec : MemberSpec, IParametersMember
 		TypeSpec[] targs;
 		TypeParameterSpec[] constraints;
 
+		public static readonly MethodSpec Excluded = new MethodSpec (MemberKind.Method, InternalType.FakeInternalType, null, null, ParametersCompiled.EmptyReadOnlyParameters, 0);
+
 		public MethodSpec (MemberKind kind, TypeSpec declaringType, IMethodDefinition details, TypeSpec returnType,
 			AParametersCollection parameters, Modifiers modifiers)
 			: base (kind, declaringType, details, modifiers)


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches