diff --git a/.gitignore b/.gitignore index 32762c15..6894d318 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ - +#CCRewrite Test folder +Foxtrot/Tests/Sources/bin/ +Foxtrot/Tests/QuickGraph/QuickGraphBinaries/ +Foxtrot/Tests/RewriteExistingBinaries/ # CodeContracts installer Microsoft.Research/ManagedContract.Setup/devlab9ts/ diff --git a/Foxtrot/Foxtrot/Extractor.cs b/Foxtrot/Foxtrot/Extractor.cs index 9f3dab2d..10b6081c 100644 --- a/Foxtrot/Foxtrot/Extractor.cs +++ b/Foxtrot/Foxtrot/Extractor.cs @@ -2326,6 +2326,7 @@ public Block Apply(Block block) { return result; } } + /// /// Use the same assumption as the extractor for a non-iterator method: the preambles are /// in the first block. @@ -2350,14 +2351,14 @@ StatementList GetContractClumpFromMoveNext(Method iteratorMethod, Method moveNex { linkerVersion = iteratorMethod.DeclaringType.DeclaringModule.LinkerMajorVersion; } - var isRoslyn = linkerVersion == 48; - var initialState = moveNext.IsAsync && !isRoslyn ? -1 : 0; + + var initialState = moveNext.IsAsync ? -1 : 0; moveNext.MoveNextStartState = initialState; originalContractPosition = null; int statementIndex; Contract.Assume(moveNext.Body != null); Contract.Assume(moveNext.Body.Statements != null); - int blockIndex = ContractStartInMoveNext(this.contractNodes, moveNext, out statementIndex, iteratorMethod, isRoslyn); + int blockIndex = ContractStartInMoveNext(this.contractNodes, moveNext, out statementIndex, iteratorMethod); Contract.Assert(statementIndex >= 0, "should follow from the postcondiiton"); if (blockIndex < 0) { // Couldn't find state 0 in MoveNext method @@ -2504,15 +2505,12 @@ enum EvalKind { None = 0, IsStateValue, IsFinalCompare, IsDisposingTest } /// - assignment to state /// - unconditional branch /// - /// Wrinkle: in Rosly, the initial async state is also 0, not -1. - /// The context uses the linker version to determine if this assembly was Roslyn generated. - /// - /// Another wrinkle is async methods that are not really async and C# still emits a closure etc, but + /// Wrinkle is async methods that are not really async and C# still emits a closure etc, but /// the method does not test the async state at all. /// [ContractVerification(true)] [Pure] - static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, out int statementIndex, Method origMethod, bool isRoslyn) + static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, out int statementIndex, Method origMethod) { Contract.Requires(contractNodes != null); Contract.Requires(moveNext != null); @@ -2565,7 +2563,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, lastBranchNonConditional = true; goto OuterLoop; } - var value = EvaluateExpression(branch.Condition, env, seenFinalCompare, isAsync, isRoslyn); + var value = EvaluateExpression(branch.Condition, env, seenFinalCompare, isAsync); if (value.Two == EvalKind.IsDisposingTest) { if (value.One != 0) @@ -2619,7 +2617,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, statementIndex = i; return currentBlockIndex; } - var value = EvaluateExpression(swtch.Expression, env, seenFinalCompare, isAsync, isRoslyn); + var value = EvaluateExpression(swtch.Expression, env, seenFinalCompare, isAsync); if (value.One < 0 || swtch.Targets == null || value.One >= swtch.Targets.Count) { // fall through @@ -2649,7 +2647,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, statementIndex = i; return currentBlockIndex; } - var value = EvaluateExpression(assign.Source, env, seenFinalCompare, isAsync, isRoslyn); + var value = EvaluateExpression(assign.Source, env, seenFinalCompare, isAsync); if (IsThisDotState(assign.Target)) { // end of trace @@ -2702,7 +2700,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, break; default: - Contract.Assume(false); + Contract.Assume(false, string.Format("Unexpected node type '{0}'", stmt.NodeType)); return -1; } } @@ -2748,15 +2746,15 @@ static bool IsDoFinallyBodies(Expression expression) } [ContractVerification(true)] - static private Pair EvaluateExpression(Expression expression, Dictionary> env, bool ignoreUnknown, bool isAsync, bool isRoslyn) + static private Pair EvaluateExpression(Expression expression, Dictionary> env, bool ignoreUnknown, bool isAsync) { Contract.Requires(env != null); var binary = expression as BinaryExpression; if (binary != null) { - var op1 = EvaluateExpression(binary.Operand1, env, ignoreUnknown, isAsync, isRoslyn); - var op2 = EvaluateExpression(binary.Operand2, env, ignoreUnknown, isAsync, isRoslyn); + var op1 = EvaluateExpression(binary.Operand1, env, ignoreUnknown, isAsync); + var op2 = EvaluateExpression(binary.Operand2, env, ignoreUnknown, isAsync); var resultKind = CombineEvalKind(ref op1, ref op2); switch (binary.NodeType) { @@ -2791,7 +2789,7 @@ static private Pair EvaluateExpression(Expression expression, Dic var unary = expression as UnaryExpression; if (unary != null) { - var op = EvaluateExpression(unary.Operand, env, ignoreUnknown, isAsync, isRoslyn); + var op = EvaluateExpression(unary.Operand, env, ignoreUnknown, isAsync); var resultKind = EvalKind.None; if (op.Two == EvalKind.IsDisposingTest) { @@ -2830,7 +2828,7 @@ static private Pair EvaluateExpression(Expression expression, Dic return Pair.For(0, EvalKind.IsDisposingTest); } if (name.Contains("<>") && name.Contains("__state")) { - var initialState = isAsync && !isRoslyn ? -1 : 0; + var initialState = isAsync ? -1 : 0; return Pair.For(initialState, EvalKind.IsStateValue); } } diff --git a/Foxtrot/Foxtrot/Utility.cs b/Foxtrot/Foxtrot/Utility.cs index 6f6e2bdb..fe4047fb 100644 --- a/Foxtrot/Foxtrot/Utility.cs +++ b/Foxtrot/Foxtrot/Utility.cs @@ -2317,7 +2317,14 @@ public override void VisitConstruct(Construct cons) } else { //Console.WriteLine("Not atomic closure part: {0}", m.FullName); - Debug.Assert(m.DeclaringType.Name.Name.Contains("DisplayClass") || !m.Name.Name.Contains("__")); + var declaringTypeName = m.DeclaringType.Name.Name; + var name = m.Name.Name; + string message = + string.Format( + "DeclaringName should contain 'DisplayClass' or Name should not have '__'. \r\nDeclaringTypeName: {0}, Name: {1}", + declaringTypeName, name); + + Debug.Assert(declaringTypeName.Contains("DisplayClass") || !name.Contains("__"), message); } } } diff --git a/Foxtrot/Tests/RewriterTests.cs b/Foxtrot/Tests/RewriterTests.cs index ff9f4549..8b12bdcb 100644 --- a/Foxtrot/Tests/RewriterTests.cs +++ b/Foxtrot/Tests/RewriterTests.cs @@ -199,10 +199,11 @@ public void BuildRewriteRunFromSourcesV45() [DeploymentItem("Foxtrot\\Tests\\TestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\TestInputs.xml", "TestFile", DataAccessMethod.Sequential)] [TestMethod] [TestCategory("Runtime"), TestCategory("CoreTest"), TestCategory("Roslyn"), TestCategory("V4.5")] + [Ignore()] // Old Roslyn bits are not compatible with CCRewrite. Test (and old binaries) should be removed in the next iteration. public void BuildRewriteRunFromSourcesRoslynV45() { var options = new Options(this.TestContext); - options.IsRoslyn = true; + options.IsLegacyRoslyn = true; options.FoxtrotOptions = options.FoxtrotOptions + String.Format(" /throwonfailure /rw:{0}.exe,TestInfrastructure.RewriterMethods", Path.GetFileNameWithoutExtension(options.TestName)); options.BuildFramework = @"Roslyn\v4.5"; options.ReferencesFramework = @".NetFramework\v4.5"; @@ -210,6 +211,23 @@ public void BuildRewriteRunFromSourcesRoslynV45() options.UseTestHarness = true; TestDriver.BuildRewriteRun(options); } + + [DeploymentItem("Foxtrot\\Tests\\TestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\TestInputs.xml", "TestFile", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("Runtime"), TestCategory("CoreTest"), TestCategory("Roslyn"), TestCategory("VS14")] + public void BuildRewriteRunFromSourcesRoslynVS14RC() + { + var options = new Options(this.TestContext); + // For VS14RC+ version compiler name is the same Csc.exe, and behavior from async/iterator perspective is similar + // to old compiler as well. That's why IsLegacyRoslyn should be false in this test case. + options.IsLegacyRoslyn = false; + options.FoxtrotOptions = options.FoxtrotOptions + String.Format(" /throwonfailure /rw:{0}.exe,TestInfrastructure.RewriterMethods", Path.GetFileNameWithoutExtension(options.TestName)); + options.BuildFramework = @"Roslyn\VS14RC"; + options.ReferencesFramework = @".NetFramework\v4.5"; + options.ContractFramework = @".NETFramework\v4.0"; + options.UseTestHarness = true; + TestDriver.BuildRewriteRun(options); + } [DeploymentItem("Foxtrot\\Tests\\TestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\TestInputs.xml", "TestFile", DataAccessMethod.Sequential)] diff --git a/Foxtrot/Tests/Sources/async6.cs b/Foxtrot/Tests/Sources/async6.cs index 47a709f1..7cc0954b 100644 --- a/Foxtrot/Tests/Sources/async6.cs +++ b/Foxtrot/Tests/Sources/async6.cs @@ -34,6 +34,7 @@ public static async Task CountThem(T[] values, T other) var x = values.Length; if (x == 4) throw new ArgumentException(); + await Task.Delay(42); return x; } } diff --git a/Foxtrot/Tests/TestDriver.cs b/Foxtrot/Tests/TestDriver.cs index 70baec58..69da7111 100644 --- a/Foxtrot/Tests/TestDriver.cs +++ b/Foxtrot/Tests/TestDriver.cs @@ -62,6 +62,10 @@ internal static object Rewrite(string absoluteSourceDir, string absoluteBinary, { if (options.MustSucceed) { + if (capture.ExitCode != 0) + { + Console.WriteLine(""); + } Assert.AreEqual(0, capture.ExitCode, "{0} returned an errorcode of {1}.", FoxtrotExe, capture.ExitCode); } return capture; @@ -447,7 +451,10 @@ public string TestName } } - public bool IsRoslyn { get; set; } + /// + /// Should be true, if old (pre-RC) Roslyn compiler needs to be used. + /// + public bool IsLegacyRoslyn { get; set; } public string Compiler { @@ -456,7 +463,7 @@ public string Compiler switch (compilerCode) { case "VB": - if (IsRoslyn) + if (IsLegacyRoslyn) { return "rvbc.exe"; } @@ -465,7 +472,7 @@ public string Compiler return "vbc.exe"; } default: - if (IsRoslyn) + if (IsLegacyRoslyn) { return "rcsc.exe"; } @@ -478,14 +485,14 @@ public string Compiler } bool IsV40 { get { return this.BuildFramework.Contains("v4.0"); } } - bool IsV45 { get { return this.BuildFramework.Contains("v4.5"); } } + bool IsV45 { get { return this.BuildFramework.Contains("v4.5") || BuildFramework.Contains("VS14"); } } bool IsSilverlight { get { return this.BuildFramework.Contains("Silverlight"); } } string Moniker { get { - if (!IsRoslyn) { return FrameworkMoniker; } + if (!IsLegacyRoslyn) { return FrameworkMoniker; } if (compilerCode == "VB") { return FrameworkMoniker + ",ROSLYN"; diff --git a/Foxtrot/Tests/UnitTests/RewrittenContractTest.cs b/Foxtrot/Tests/UnitTests/RewrittenContractTest.cs index 340a399a..f03fd6c1 100644 --- a/Foxtrot/Tests/UnitTests/RewrittenContractTest.cs +++ b/Foxtrot/Tests/UnitTests/RewrittenContractTest.cs @@ -70,7 +70,6 @@ private static int RunProcess(string cwd, string tool, string arguments) [AssemblyInitialize] public static void AssembyInitialize(TestContext context) { - // // VERY IMPORTANT!! Do NOT do anything that caused any type from CodeUnderTest.dll to be loaded // before the assembly is rewritten!!! @@ -86,8 +85,9 @@ public static void AssembyInitialize(TestContext context) var deploymentDir = Directory.GetCurrentDirectory(); var testResultPosition = deploymentDir.IndexOf(@"TestResults"); - - Assert.IsTrue(testResultPosition != -1, "Can't find the TestResults directory!!!"); + + Assert.IsTrue(testResultPosition != -1, + string.Format("Can't find the TestResults directory!!! Current deployment directory is '{0}'", deploymentDir)); var testDirRoot = deploymentDir.Substring(0, testResultPosition); diff --git a/Microsoft.Research/Imported/Tools/.NETFramework/v4.5/msvcp110_clr0400.dll b/Microsoft.Research/Imported/Tools/.NETFramework/v4.5/msvcp110_clr0400.dll new file mode 100644 index 00000000..24d7a351 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/.NETFramework/v4.5/msvcp110_clr0400.dll differ diff --git a/Microsoft.Research/Imported/Tools/.NETFramework/v4.5/msvcr110_clr0400.dll b/Microsoft.Research/Imported/Tools/.NETFramework/v4.5/msvcr110_clr0400.dll new file mode 100644 index 00000000..a2d6a95d Binary files /dev/null and b/Microsoft.Research/Imported/Tools/.NETFramework/v4.5/msvcr110_clr0400.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/CvtResUI.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/CvtResUI.dll new file mode 100644 index 00000000..f6ebc984 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/CvtResUI.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/FileTrackerUI.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/FileTrackerUI.dll new file mode 100644 index 00000000..345e9365 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/FileTrackerUI.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/IlDasmrc.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/IlDasmrc.dll new file mode 100644 index 00000000..2314ff1d Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/IlDasmrc.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/Microsoft.VisualBasic.Activities.CompilerUI.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/Microsoft.VisualBasic.Activities.CompilerUI.dll new file mode 100644 index 00000000..2e1ef0b1 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/Microsoft.VisualBasic.Activities.CompilerUI.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/TrackerUI.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/TrackerUI.dll new file mode 100644 index 00000000..26a4302a Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/TrackerUI.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/alinkui.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/alinkui.dll new file mode 100644 index 00000000..aeba03b8 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/alinkui.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/cscui.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/cscui.dll new file mode 100644 index 00000000..709c0247 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/cscui.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/flogvwrc.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/flogvwrc.dll new file mode 100644 index 00000000..08e77ae7 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/flogvwrc.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/gacutlrc.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/gacutlrc.dll new file mode 100644 index 00000000..5b944902 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/gacutlrc.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/pevrfyrc.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/pevrfyrc.dll new file mode 100644 index 00000000..e32d4dbf Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/pevrfyrc.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/snrc.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/snrc.dll new file mode 100644 index 00000000..10847d6d Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/snrc.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/vbc7ui.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/vbc7ui.dll new file mode 100644 index 00000000..53992c56 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/1033/vbc7ui.dll differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/PEVerify.exe b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/PEVerify.exe new file mode 100644 index 00000000..66698fc2 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/PEVerify.exe differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/PEVerify.exe.config b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/PEVerify.exe.config new file mode 100644 index 00000000..0094e8d3 --- /dev/null +++ b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/PEVerify.exe.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/_readme.txt b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/_readme.txt new file mode 100644 index 00000000..df3a477e --- /dev/null +++ b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/_readme.txt @@ -0,0 +1 @@ +Roslyn bits was taken from installed VS14RC. \ No newline at end of file diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.exe b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.exe new file mode 100644 index 00000000..c87e0695 Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.exe differ diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.exe.config b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.exe.config new file mode 100644 index 00000000..39b6572c --- /dev/null +++ b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.exe.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.rsp b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.rsp new file mode 100644 index 00000000..aee022cb --- /dev/null +++ b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/csc.rsp @@ -0,0 +1,44 @@ +# This file contains command-line options that the C# +# command line compiler (CSC) will process as part +# of every compilation, unless the "/noconfig" option +# is specified. + +# Reference the common Framework libraries +/r:Accessibility.dll +/r:Microsoft.CSharp.dll +/r:System.Configuration.dll +/r:System.Configuration.Install.dll +/r:System.Core.dll +/r:System.Data.dll +/r:System.Data.DataSetExtensions.dll +/r:System.Data.Linq.dll +/r:System.Data.OracleClient.dll +/r:System.Deployment.dll +/r:System.Design.dll +/r:System.DirectoryServices.dll +/r:System.dll +/r:System.Drawing.Design.dll +/r:System.Drawing.dll +/r:System.EnterpriseServices.dll +/r:System.Management.dll +/r:System.Messaging.dll +/r:System.Runtime.Remoting.dll +/r:System.Runtime.Serialization.dll +/r:System.Runtime.Serialization.Formatters.Soap.dll +/r:System.Security.dll +/r:System.ServiceModel.dll +/r:System.ServiceModel.Web.dll +/r:System.ServiceProcess.dll +/r:System.Transactions.dll +/r:System.Web.dll +/r:System.Web.Extensions.Design.dll +/r:System.Web.Extensions.dll +/r:System.Web.Mobile.dll +/r:System.Web.RegularExpressions.dll +/r:System.Web.Services.dll +/r:System.Windows.Forms.Dll +/r:System.Workflow.Activities.dll +/r:System.Workflow.ComponentModel.dll +/r:System.Workflow.Runtime.dll +/r:System.Xml.dll +/r:System.Xml.Linq.dll diff --git a/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/peverify.dll b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/peverify.dll new file mode 100644 index 00000000..ad840b5e Binary files /dev/null and b/Microsoft.Research/Imported/Tools/Roslyn/VS14RC/peverify.dll differ diff --git a/buildCC.bat b/buildCC.bat index 7d86f71a..e5d8f300 100644 --- a/buildCC.bat +++ b/buildCC.bat @@ -1,9 +1,9 @@ -@echo off -cd Microsoft.Research\ManagedContract.Setup -call buildmsi %1 devlab9ts -call buildnuget %1 devlab9ts -cd ..\.. -echo . -echo **************************************************** -echo Done building CodeContracts version %1 -echo **************************************************** +@echo off +cd Microsoft.Research\ManagedContract.Setup +call buildmsi %1 devlab9ts +call buildnuget %1 devlab9ts +cd ..\.. +echo . +echo **************************************************** +echo Done building CodeContracts version %1 +echo ****************************************************