forked from dafny-lang/dafny
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into projectAwareIDE
- Loading branch information
Showing
189 changed files
with
3,323 additions
and
2,385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Source/DafnyBenchmarkingPlugin/BenchmarkInstrumentation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using DafnyBenchmarkingPlugin; | ||
using Microsoft.Dafny; | ||
using Microsoft.Dafny.Compilers; | ||
using Microsoft.Dafny.Plugins; | ||
|
||
public class BenchmarkingCompilerInstrumenter : CompilerInstrumenter { | ||
public BenchmarkingCompilerInstrumenter(ErrorReporter reporter) : base(reporter) { } | ||
|
||
public override void Instrument(IExecutableBackend backend, SinglePassCompiler compiler, Program program) { | ||
if (compiler is JavaCompiler javaCompiler) { | ||
javaCompiler.AddInstrumenter(new JavaBenchmarkCompilationInstrumenter(Reporter)); | ||
} else { | ||
Reporter.Error(MessageSource.Compiler, ResolutionErrors.ErrorId.none, program.GetFirstTopLevelToken(), | ||
$"The benchmarking plugin does not support this compilation target: {compiler} (--target:{backend.TargetId})"); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Source/DafnyBenchmarkingPlugin/DafnyBenchmarkingPlugin.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<OutputPath>..\..\Binaries\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DafnyCore\DafnyCore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
40 changes: 40 additions & 0 deletions
40
Source/DafnyBenchmarkingPlugin/JavaBenchmarkCompilationInstrumenter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.Dafny; | ||
using Microsoft.Dafny.Plugins; | ||
|
||
namespace DafnyBenchmarkingPlugin; | ||
|
||
public class JavaBenchmarkCompilationInstrumenter : GenericCompilationInstrumenter { | ||
|
||
private readonly ErrorReporter Reporter; | ||
|
||
public JavaBenchmarkCompilationInstrumenter(ErrorReporter reporter) { | ||
Reporter = reporter; | ||
} | ||
|
||
public override void BeforeClass(TopLevelDecl cls, ConcreteSyntaxTree wr) { | ||
if (Attributes.Contains(cls.Attributes, "benchmarks")) { | ||
wr.WriteLine("@org.openjdk.jmh.annotations.State(org.openjdk.jmh.annotations.Scope.Benchmark)"); | ||
} | ||
} | ||
|
||
public override void BeforeMethod(Method m, ConcreteSyntaxTree wr) { | ||
if (Attributes.Contains(m.EnclosingClass.Attributes, "benchmarks")) { | ||
if (m is Constructor) { | ||
if (m.Ins.Any()) { | ||
Reporter.Error(MessageSource.Compiler, ResolutionErrors.ErrorId.none, m.tok, | ||
$"Classes with {{:benchmarks}} can not accept parameters in their constructors"); | ||
} | ||
|
||
// _ctor() needs to be explicitly invoked as usual, | ||
// and it's convenient (but a bit of a hack) to do this by marking it as Setup. | ||
// It's not safe in general to run a Dafny compiled constructor | ||
// multiple times on the same object, | ||
// so the better solution in the future is probably to maintain the benchmark object | ||
// as a separate object that Setup instantiates every time. | ||
wr.WriteLine("@org.openjdk.jmh.annotations.Setup(org.openjdk.jmh.annotations.Level.Iteration)"); | ||
} else { | ||
wr.WriteLine("@org.openjdk.jmh.annotations.Benchmark"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# DafnyBenchmarkingPlugin | ||
|
||
This compiler plugin adds support for a class-level `{:benchmarks}` attribute, | ||
for defining harnesses to measure the performance of Dafny code. | ||
It can also be used to check for concurrent execution bugs | ||
just by verifying the benchmarking process doesn't crash. | ||
|
||
For now this plugin only supports the Java backend, | ||
but support for the other languages will be added in the future. | ||
|
||
## Example | ||
|
||
See [this regression test](../../Test/benchmarks/sequence-race/SequenceRace.dfy) | ||
for a race condition in the Dafny runtime. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.Dafny; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Tomlyn; | ||
|
||
namespace DafnyCore.Test; | ||
|
||
public class ClonerTest { | ||
class DummyDecl : Declaration { | ||
public DummyDecl(Cloner cloner, Declaration original) : base(cloner, original) { | ||
} | ||
|
||
public DummyDecl(RangeToken rangeToken, Name name, Attributes attributes, bool isRefining) : base(rangeToken, name, | ||
attributes, isRefining) { | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ClonerKeepsBodyStartTok() { | ||
var tokenBodyStart = new Token() { line = 2 }; | ||
var rangeToken = new RangeToken(Token.NoToken, Token.NoToken); | ||
var specificationFrame = new LiteralExpr(Microsoft.Dafny.Token.NoToken, 1); | ||
var formal1 = new Formal(Token.NoToken, "a", Microsoft.Dafny.Type.Bool, true, false, null) { | ||
RangeToken = new RangeToken(tokenBodyStart, tokenBodyStart), | ||
IsTypeExplicit = true | ||
}; | ||
var formal2 = new Formal(Token.NoToken, "b", Microsoft.Dafny.Type.Bool, true, false, null) { | ||
RangeToken = new RangeToken(tokenBodyStart, tokenBodyStart), | ||
IsTypeExplicit = false | ||
}; | ||
var dummyDecl = new Method(rangeToken, new Name(rangeToken, "hello"), | ||
false, false, new List<TypeParameter>(), new List<Formal> { formal1, formal2 }, | ||
new List<Formal>(), new List<AttributedExpression>(), | ||
new Specification<FrameExpression>(new List<FrameExpression>(), null), | ||
new List<AttributedExpression>(), new Specification<Expression>(new List<Expression>(), null), | ||
new BlockStmt(rangeToken, new List<Statement>()), null, Token.NoToken, false); | ||
|
||
dummyDecl.BodyStartTok = tokenBodyStart; | ||
var cloner = new Cloner(); | ||
var dummyDecl2 = cloner.CloneMethod(dummyDecl); | ||
Assert.Equal(2, dummyDecl2.BodyStartTok.line); | ||
Assert.Equal(2, dummyDecl2.Ins[0].RangeToken.StartToken.line); | ||
Assert.True(dummyDecl2.Ins[0].IsTypeExplicit); | ||
Assert.Equal(2, dummyDecl2.Ins[1].RangeToken.StartToken.line); | ||
Assert.False(dummyDecl2.Ins[1].IsTypeExplicit); | ||
} | ||
} |
Oops, something went wrong.