Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#CCRewrite Test folder
Foxtrot/Tests/Sources/bin/
Foxtrot/Tests/QuickGraph/QuickGraphBinaries/
Foxtrot/Tests/RewriteExistingBinaries/


# CodeContracts installer
Microsoft.Research/ManagedContract.Setup/devlab9ts/
Expand Down
76 changes: 0 additions & 76 deletions CONTRIBUTING.md

This file was deleted.

32 changes: 17 additions & 15 deletions Foxtrot/Foxtrot/Extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,6 @@ public Block Apply(Block block) {
return result;
}
}

/// <summary>
/// Use the same assumption as the extractor for a non-iterator method: the preambles are
/// in the first block.
Expand All @@ -2351,14 +2350,14 @@ StatementList GetContractClumpFromMoveNext(Method iteratorMethod, Method moveNex
{
linkerVersion = iteratorMethod.DeclaringType.DeclaringModule.LinkerMajorVersion;
}

var initialState = moveNext.IsAsync ? -1 : 0;
var isRoslyn = linkerVersion == 48;
var initialState = moveNext.IsAsync && !isRoslyn ? -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);
int blockIndex = ContractStartInMoveNext(this.contractNodes, moveNext, out statementIndex, iteratorMethod, isRoslyn);
Contract.Assert(statementIndex >= 0, "should follow from the postcondiiton");
if (blockIndex < 0) {
// Couldn't find state 0 in MoveNext method
Expand Down Expand Up @@ -2505,12 +2504,15 @@ enum EvalKind { None = 0, IsStateValue, IsFinalCompare, IsDisposingTest }
/// - assignment to state
/// - unconditional branch
///
/// Wrinkle is async methods that are not really async and C# still emits a closure etc, but
/// 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
/// the method does not test the async state at all.
/// </summary>
[ContractVerification(true)]
[Pure]
static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, out int statementIndex, Method origMethod)
static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext, out int statementIndex, Method origMethod, bool isRoslyn)
{
Contract.Requires(contractNodes != null);
Contract.Requires(moveNext != null);
Expand Down Expand Up @@ -2563,7 +2565,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext,
lastBranchNonConditional = true;
goto OuterLoop;
}
var value = EvaluateExpression(branch.Condition, env, seenFinalCompare, isAsync);
var value = EvaluateExpression(branch.Condition, env, seenFinalCompare, isAsync, isRoslyn);
if (value.Two == EvalKind.IsDisposingTest)
{
if (value.One != 0)
Expand Down Expand Up @@ -2617,7 +2619,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext,
statementIndex = i;
return currentBlockIndex;
}
var value = EvaluateExpression(swtch.Expression, env, seenFinalCompare, isAsync);
var value = EvaluateExpression(swtch.Expression, env, seenFinalCompare, isAsync, isRoslyn);
if (value.One < 0 || swtch.Targets == null || value.One >= swtch.Targets.Count)
{
// fall through
Expand Down Expand Up @@ -2647,7 +2649,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext,
statementIndex = i;
return currentBlockIndex;
}
var value = EvaluateExpression(assign.Source, env, seenFinalCompare, isAsync);
var value = EvaluateExpression(assign.Source, env, seenFinalCompare, isAsync, isRoslyn);
if (IsThisDotState(assign.Target))
{
// end of trace
Expand Down Expand Up @@ -2700,7 +2702,7 @@ static int ContractStartInMoveNext(ContractNodes contractNodes, Method moveNext,
break;

default:
Contract.Assume(false, string.Format("Unexpected node type '{0}'", stmt.NodeType));
Contract.Assume(false);
return -1;
}
}
Expand Down Expand Up @@ -2746,15 +2748,15 @@ static bool IsDoFinallyBodies(Expression expression)
}

[ContractVerification(true)]
static private Pair<int, EvalKind> EvaluateExpression(Expression expression, Dictionary<Variable, Pair<int, EvalKind>> env, bool ignoreUnknown, bool isAsync)
static private Pair<int, EvalKind> EvaluateExpression(Expression expression, Dictionary<Variable, Pair<int, EvalKind>> env, bool ignoreUnknown, bool isAsync, bool isRoslyn)
{
Contract.Requires(env != null);

var binary = expression as BinaryExpression;
if (binary != null)
{
var op1 = EvaluateExpression(binary.Operand1, env, ignoreUnknown, isAsync);
var op2 = EvaluateExpression(binary.Operand2, env, ignoreUnknown, isAsync);
var op1 = EvaluateExpression(binary.Operand1, env, ignoreUnknown, isAsync, isRoslyn);
var op2 = EvaluateExpression(binary.Operand2, env, ignoreUnknown, isAsync, isRoslyn);
var resultKind = CombineEvalKind(ref op1, ref op2);
switch (binary.NodeType)
{
Expand Down Expand Up @@ -2789,7 +2791,7 @@ static private Pair<int, EvalKind> EvaluateExpression(Expression expression, Dic
var unary = expression as UnaryExpression;
if (unary != null)
{
var op = EvaluateExpression(unary.Operand, env, ignoreUnknown, isAsync);
var op = EvaluateExpression(unary.Operand, env, ignoreUnknown, isAsync, isRoslyn);
var resultKind = EvalKind.None;
if (op.Two == EvalKind.IsDisposingTest)
{
Expand Down Expand Up @@ -2828,7 +2830,7 @@ static private Pair<int, EvalKind> EvaluateExpression(Expression expression, Dic
return Pair.For(0, EvalKind.IsDisposingTest);
}
if (name.Contains("<>") && name.Contains("__state")) {
var initialState = isAsync ? -1 : 0;
var initialState = isAsync && !isRoslyn ? -1 : 0;
return Pair.For(initialState, EvalKind.IsStateValue);
}
}
Expand Down
9 changes: 1 addition & 8 deletions Foxtrot/Foxtrot/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2317,14 +2317,7 @@ public override void VisitConstruct(Construct cons)
} else
{
//Console.WriteLine("Not atomic closure part: {0}", m.FullName);
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);
Debug.Assert(m.DeclaringType.Name.Name.Contains("DisplayClass") || !m.Name.Name.Contains("__"));
}
}
}
Expand Down
20 changes: 1 addition & 19 deletions Foxtrot/Tests/RewriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,35 +199,17 @@ 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.IsLegacyRoslyn = true;
options.IsRoslyn = 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";
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)]
[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)]
Expand Down
1 change: 0 additions & 1 deletion Foxtrot/Tests/Sources/async6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static async Task<int> CountThem<T>(T[] values, T other)

var x = values.Length;
if (x == 4) throw new ArgumentException();
await Task.Delay(42);
return x;
}
}
Expand Down
17 changes: 5 additions & 12 deletions Foxtrot/Tests/TestDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ 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;
Expand Down Expand Up @@ -451,10 +447,7 @@ public string TestName
}
}

/// <summary>
/// Should be true, if old (pre-RC) Roslyn compiler needs to be used.
/// </summary>
public bool IsLegacyRoslyn { get; set; }
public bool IsRoslyn { get; set; }

public string Compiler
{
Expand All @@ -463,7 +456,7 @@ public string Compiler
switch (compilerCode)
{
case "VB":
if (IsLegacyRoslyn)
if (IsRoslyn)
{
return "rvbc.exe";
}
Expand All @@ -472,7 +465,7 @@ public string Compiler
return "vbc.exe";
}
default:
if (IsLegacyRoslyn)
if (IsRoslyn)
{
return "rcsc.exe";
}
Expand All @@ -485,14 +478,14 @@ public string Compiler
}

bool IsV40 { get { return this.BuildFramework.Contains("v4.0"); } }
bool IsV45 { get { return this.BuildFramework.Contains("v4.5") || BuildFramework.Contains("VS14"); } }
bool IsV45 { get { return this.BuildFramework.Contains("v4.5"); } }
bool IsSilverlight { get { return this.BuildFramework.Contains("Silverlight"); } }

string Moniker
{
get
{
if (!IsLegacyRoslyn) { return FrameworkMoniker; }
if (!IsRoslyn) { return FrameworkMoniker; }
if (compilerCode == "VB")
{
return FrameworkMoniker + ",ROSLYN";
Expand Down
6 changes: 3 additions & 3 deletions Foxtrot/Tests/UnitTests/RewrittenContractTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ 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!!!
Expand All @@ -85,9 +86,8 @@ public static void AssembyInitialize(TestContext context)
var deploymentDir = Directory.GetCurrentDirectory();

var testResultPosition = deploymentDir.IndexOf(@"TestResults");

Assert.IsTrue(testResultPosition != -1,
string.Format("Can't find the TestResults directory!!! Current deployment directory is '{0}'", deploymentDir));

Assert.IsTrue(testResultPosition != -1, "Can't find the TestResults directory!!!");

var testDirRoot = deploymentDir.Substring(0, testResultPosition);

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

Loading