[mono/mono] d92b0d6d: [mcs] Dynamically calculate size of flow-analysis bitset. Fixes #4210

"Marek Safar ([email protected])" <[email protected]> Sun, 24 Nov 2013 13:16:04 +0000
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <000001428a40b05e-fb3b3968-db58-4e74-b097-a431553bf695-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/2c7864ae9854...d92b0d6d9f5b

   Commit: d92b0d6d9f5b35f6871f73bb84921645d24d30f3
   Author: Marek Safar <[email protected]> (marek-safar)
     Date: 2013-11-24 13:14:54 GMT
      URL: https://github.com/mono/mono/commit/d92b0d6d9f5b35f6871f73bb84921645d24d30f3

[mcs] Dynamically calculate size of flow-analysis bitset. Fixes #4210

Changed paths:
  M mcs/mcs/anonymous.cs
  M mcs/mcs/assign.cs
  M mcs/mcs/class.cs
  M mcs/mcs/context.cs
  M mcs/mcs/flowanalysis.cs
  M mcs/mcs/iterators.cs
  M mcs/mcs/statement.cs

Modified: mcs/mcs/anonymous.cs
===================================================================
@@ -1537,6 +1537,9 @@ public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae
 				if (!CheckReachableExit (ec.Report)) {
 					return null;
 				}
+
+				if (bc != null)
+					bc.AssignmentInfoOffset = aec.AssignmentInfoOffset;
 			}
 
 			if (am != null && am.ReturnTypeInference != null) {

Modified: mcs/mcs/assign.cs
===================================================================
@@ -555,20 +555,21 @@ public class FieldInitializer : Assign
 		// share same constructor (block) for expression trees resolve but
 		// they have they own resolve scope
 		//
-		sealed class FieldInitializerContext : ResolveContext
+		sealed class FieldInitializerContext : BlockContext
 		{
-			ExplicitBlock ctor_block;
+			readonly ExplicitBlock ctor_block;
 
-			public FieldInitializerContext (IMemberContext mc, ResolveContext constructorContext)
-				: base (mc, Options.FieldInitializerScope | Options.ConstructorScope)
+			public FieldInitializerContext (IMemberContext mc, BlockContext constructorContext)
+				: base (mc, null, constructorContext.ReturnType)
 			{
+				flags |= Options.FieldInitializerScope | Options.ConstructorScope;
 				this.ctor_block = constructorContext.CurrentBlock.Explicit;
 			}
 
 			public override ExplicitBlock ConstructorBlock {
-				get {
-					return ctor_block;
-				}
+			    get {
+			        return ctor_block;
+			    }
 			}
 		}
 
@@ -586,21 +587,25 @@ public FieldInitializer (FieldBase mc, Expression expression, Location loc)
 				((FieldExpr)target).InstanceExpression = new CompilerGeneratedThis (mc.CurrentType, expression.Location);
 		}
 
+		public int AssignmentOffset { get; private set; }
+
 		public override Location StartLocation {
 			get {
 				return loc;
 			}
 		}
 
-		protected override Expression DoResolve (ResolveContext ec)
+		protected override Expression DoResolve (ResolveContext rc)
 		{
 			// Field initializer can be resolved (fail) many times
 			if (source == null)
 				return null;
 
+			var bc = (BlockContext) rc;
 			if (resolved == null) {
-				var ctx = new FieldInitializerContext (mc, ec);
+				var ctx = new FieldInitializerContext (mc, bc);
 				resolved = base.DoResolve (ctx) as ExpressionStatement;
+				AssignmentOffset = ctx.AssignmentInfoOffset - bc.AssignmentInfoOffset;
 			}
 
 			return resolved;

Modified: mcs/mcs/class.cs
===================================================================
@@ -991,6 +991,7 @@ public void ResolveFieldInitializers (BlockContext ec)
 					if (!has_complex_initializer && fi.IsDefaultInitializer)
 						continue;
 
+					ec.AssignmentInfoOffset += fi.AssignmentOffset;
 					ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
 				}
 
@@ -1012,6 +1013,7 @@ public void ResolveFieldInitializers (BlockContext ec)
 				if (fi.IsDefaultInitializer && ec.Module.Compiler.Settings.Optimize)
 					continue;
 
+				ec.AssignmentInfoOffset += fi.AssignmentOffset;
 				ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
 			}
 		}

Modified: mcs/mcs/context.cs
===================================================================
@@ -440,12 +440,12 @@ public class FlowAnalysisContext
 	{
 		readonly CompilerContext ctx;
 
-		public FlowAnalysisContext (CompilerContext ctx, ParametersBlock parametersBlock)
+		public FlowAnalysisContext (CompilerContext ctx, ParametersBlock parametersBlock, int definiteAssignmentLength)
 		{
 			this.ctx = ctx;
 			this.ParametersBlock = parametersBlock;
 
-			DefiniteAssignment = new DefiniteAssignmentBitSet ();
+			DefiniteAssignment = new DefiniteAssignmentBitSet (definiteAssignmentLength);
 		}
 
 		public DefiniteAssignmentBitSet DefiniteAssignment { get; set; }

Modified: mcs/mcs/flowanalysis.cs
===================================================================
@@ -512,9 +512,9 @@ public class DefiniteAssignmentBitSet
 		System.Collections.BitArray bits;
 		bool copy_on_write;
 
-		public DefiniteAssignmentBitSet ()
+		public DefiniteAssignmentBitSet (int length)
 		{
-			bits = new System.Collections.BitArray (4096); // TODO:
+			bits = new System.Collections.BitArray (length);
 		}
 
 		public DefiniteAssignmentBitSet (DefiniteAssignmentBitSet source)
@@ -548,7 +548,7 @@ private DefiniteAssignmentBitSet (System.Collections.BitArray bits)
 		public static DefiniteAssignmentBitSet And (List<DefiniteAssignmentBitSet> das)
 		{
 			if (das.Count == 0)
-				return new DefiniteAssignmentBitSet ();
+				throw new ArgumentException ("Empty das");
 
 			DefiniteAssignmentBitSet res = das [0];
 			for (int i = 1; i < das.Count; ++i) {
@@ -587,5 +587,16 @@ void Clone ()
 			bits = new System.Collections.BitArray (bits);
 			copy_on_write = false;
 		}
+
+		public override string ToString ()
+		{
+			var length = bits.Length;
+			StringBuilder sb = new StringBuilder (length);
+			for (int i = 0; i < length; ++i) {
+				sb.Append (bits[i] ? '1' : '0');
+			}
+
+			return sb.ToString ();
+		}
 	}
 }

Modified: mcs/mcs/iterators.cs
===================================================================
@@ -791,7 +791,8 @@ protected virtual BlockContext CreateBlockContext (BlockContext bc)
 
 		protected override Expression DoResolve (ResolveContext rc)
 		{
-			var ctx = CreateBlockContext ((BlockContext) rc);
+			var bc = (BlockContext) rc;
+			var ctx = CreateBlockContext (bc);
 
 			Block.Resolve (ctx);
 
@@ -801,6 +802,7 @@ protected override Expression DoResolve (ResolveContext rc)
 				storey.AddEntryMethod (move_next);
 			}
 
+			bc.AssignmentInfoOffset = ctx.AssignmentInfoOffset;
 			eclass = ExprClass.Value;
 			return this;
 		}

Modified: mcs/mcs/statement.cs
===================================================================
@@ -4197,7 +4197,7 @@ public bool Resolve (BlockContext bc, IMethodData md)
 			if ((flags & Flags.NoFlowAnalysis) != 0)
 				return true;
 
-			var fc = new FlowAnalysisContext (bc.Module.Compiler, this);
+			var fc = new FlowAnalysisContext (bc.Module.Compiler, this, bc.AssignmentInfoOffset);
 			try {
 				FlowAnalysis (fc);
 			} catch (Exception e) {


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