Skip to content

Commit

Permalink
Add extra cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboardDrummer committed Aug 9, 2024
1 parent b57c1ed commit 045b5b9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
14 changes: 7 additions & 7 deletions Source/BoogieDriver/BoogieDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class OnlyBoogie
public static int Main(string[] args)
{
Contract.Requires(cce.NonNullElements(args));

var options = new CommandLineOptions(Console.Out, new ConsolePrinter())
{
RunningBoogieFromCommandLine = true
Expand All @@ -21,6 +21,12 @@ public static int Main(string[] args)
{
return 1;
}
var source = new CancellationTokenSource();
if (options.ProcessTimeLimit != 0)
{
source.CancelAfter(TimeSpan.FromSeconds(options.ProcessTimeLimit));
}

using var executionEngine = ExecutionEngine.CreateWithoutSharedCache(options);

if (options.ProcessInfoFlags())
Expand Down Expand Up @@ -64,12 +70,6 @@ public static int Main(string[] args)

Helpers.ExtraTraceInformation(options, "Becoming sentient");

var source = new CancellationTokenSource();
if (options.ProcessTimeLimit != 0)
{
source.CancelAfter(TimeSpan.FromSeconds(options.ProcessTimeLimit));
}

var success = executionEngine.ProcessFiles(Console.Out, fileList, cancellationToken: source.Token).Result;
if (options.XmlSink != null)
{
Expand Down
56 changes: 34 additions & 22 deletions Source/ExecutionEngine/ExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,50 +74,62 @@ public static ExecutionEngine CreateWithoutSharedCache(ExecutionEngineOptions op

static DateTime FirstRequestStart;

static readonly ConcurrentDictionary<string, TimeSpan>
TimePerRequest = new ConcurrentDictionary<string, TimeSpan>();
static readonly ConcurrentDictionary<string, TimeSpan> TimePerRequest = new();

static readonly ConcurrentDictionary<string, PipelineStatistics> StatisticsPerRequest =
new ConcurrentDictionary<string, PipelineStatistics>();
static readonly ConcurrentDictionary<string, PipelineStatistics> StatisticsPerRequest = new();

static readonly ConcurrentDictionary<string, CancellationTokenSource> ImplIdToCancellationTokenSource =
new ConcurrentDictionary<string, CancellationTokenSource>();
static readonly ConcurrentDictionary<string, CancellationTokenSource> ImplIdToCancellationTokenSource = new();

private readonly TaskScheduler largeThreadScheduler;
private readonly bool disposeScheduler;

public async Task<bool> ProcessFiles(TextWriter output, IList<string> fileNames, bool lookForSnapshots = true,
public async Task<bool> ProcessFiles(TextWriter output, IList<string> fileNames,
string programId = null, CancellationToken cancellationToken = default) {
Contract.Requires(cce.NonNullElements(fileNames));

if (Options.VerifySeparately && 1 < fileNames.Count) {
var success = true;
foreach (var fileName in fileNames) {
success &= await ProcessFiles(output, new List<string> { fileName }, lookForSnapshots, fileName, cancellationToken: cancellationToken);
}
return success;
}

if (0 <= Options.VerifySnapshots && lookForSnapshots) {
if (0 <= Options.VerifySnapshots) {
var snapshotsByVersion = LookForSnapshots(fileNames);
var success = true;
foreach (var snapshots in snapshotsByVersion) {
cancellationToken.ThrowIfCancellationRequested();
// BUG: Reusing checkers during snapshots doesn't work, even though it should. We create a new engine (and thus checker pool) to workaround this.
using var engine = new ExecutionEngine(Options, Cache,
CustomStackSizePoolTaskScheduler.Create(StackSize, Options.VcsCores), true);
success &= await engine.ProcessFiles(output, new List<string>(snapshots), false, programId, cancellationToken: cancellationToken);
success &= await engine.ProcessBoogieFiles(output, snapshots, programId, cancellationToken: cancellationToken);
}
return success;
}

return await ProcessBoogieFiles(output, fileNames, programId, cancellationToken);
}

private async Task<bool> ProcessBoogieFiles(TextWriter output, IList<string> fileNames, string programId,
CancellationToken cancellationToken)
{
if (Options.VerifySeparately) {
var success = true;
foreach (var fileName in fileNames) {
cancellationToken.ThrowIfCancellationRequested();
success &= await ProcessBoogieFilesTogether(output, new List<string> { fileName }, fileName, cancellationToken: cancellationToken);
}
return success;
}

return await ProcessBoogieFilesTogether(output, fileNames, programId, cancellationToken);
}

private Task<bool> ProcessBoogieFilesTogether(TextWriter output, IList<string> fileNames, string programId,
CancellationToken cancellationToken)
{
using XmlFileScope xf = new XmlFileScope(Options.XmlSink, fileNames[^1]);
Program program = ParseBoogieProgram(fileNames, false);
var bplFileName = fileNames[^1];
if (program == null) {
return true;
var program = ParseBoogieProgram(fileNames, false);
if (program == null)
{
return Task.FromResult(true);
}

return await ProcessProgram(output, program, bplFileName, programId, cancellationToken: cancellationToken);
var bplFileName = fileNames[^1];
return ProcessProgram(output, program, bplFileName, programId, cancellationToken: cancellationToken);
}

[Obsolete("Please inline this method call")]
Expand Down

0 comments on commit 045b5b9

Please sign in to comment.