Skip to content

Commit

Permalink
Major simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
atomb committed Nov 15, 2023
1 parent 7529785 commit 4ad4d6a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
4 changes: 3 additions & 1 deletion Source/Provers/SMTLib/ProverInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ public virtual void SetRlimit(uint limit)
{
}

public virtual void SetOtherSMTOption(string name, string value)
// Sets a local SMT option (cleared with ClearLocalSMTOptions)
public virtual void SetLocalSMTOption(string name, string value)
{
}

// Clear options set with SetLocalSMTOption
public virtual void ClearLocalSMTOptions()
{
}
Expand Down
2 changes: 0 additions & 2 deletions Source/Provers/SMTLib/ProverUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class ProverOptions
public bool ForceLogStatus = false;
public uint TimeLimit = 0;
public uint ResourceLimit = 0;
// Other options suitable for (set-option :key value)
// TODO: put ResourceLimit in here?
public int? RandomSeed = null;
public int MemoryLimit = 0;
public int Verbosity = 0;
Expand Down
16 changes: 3 additions & 13 deletions Source/Provers/SMTLib/SMTLibProcessTheoremProver.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Diagnostics;
Expand Down Expand Up @@ -434,6 +433,7 @@ protected void SendVCOptions()
if (options.Solver == SolverKind.Z3 || options.Solver == SolverKind.NoOpWithZ3Options)
{
SendThisVC("(set-option :" + Z3.TimeoutOption + " " + options.TimeLimit + ")");
SendThisVC("(set-option :" + Z3.RlimitOption + " " + options.ResourceLimit + ")");
if (options.RandomSeed != null) {
SendThisVC("(set-option :" + Z3.SmtRandomSeed + " " + options.RandomSeed.Value + ")");
SendThisVC("(set-option :" + Z3.SatRandomSeed + " " + options.RandomSeed.Value + ")");
Expand Down Expand Up @@ -1162,27 +1162,17 @@ public override void AssertAxioms()
FlushAxioms();
}

// This doesn't use SetOtherSMTOption because it may be set using
// different mechanisms than set-option in some cases.
public override void SetTimeout(uint ms)
{
options.TimeLimit = ms;
}

// Don't use SetOtherSMTOption directly, because we want a
// connection to TimeLimit.
public override void SetRlimit(uint limit)
{
if (options.Solver == SolverKind.Z3) {
SetOtherSMTOption(Z3.RlimitOption, limit.ToString());
if (limit > 0) {
SetTimeout(0);
}
}
options.ResourceLimit = limit;
}

// Note: must be re-set for every query
public override void SetOtherSMTOption(string name, string value)
public override void SetLocalSMTOption(string name, string value)
{
options.SmtOptions.Add(new OptionValue(name, value));
}
Expand Down
18 changes: 17 additions & 1 deletion Source/VCGeneration/Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ public void Target(Program prog, ProverContext ctx, Split split)
}
}

private void SetTimeout(uint timeout)
{
TheoremProver.SetTimeout(Util.BoundedMultiply(timeout, 1000));
}

private void SetRlimit(uint rlimit)
{
TheoremProver.SetRlimit(rlimit);
}

/// <summary>
/// Set up the context.
/// </summary>
Expand Down Expand Up @@ -306,7 +316,7 @@ private async Task Check(string descriptiveName, VCExpr vc, CancellationToken ca
proverRunTime = ProverStopwatch.Elapsed;
}

public async Task BeginCheck(string descriptiveName, VCExpr vc, ProverInterface.ErrorHandler handler, CancellationToken cancellationToken)
public async Task BeginCheck(string descriptiveName, VCExpr vc, ProverInterface.ErrorHandler handler, uint timeout, uint rlimit, CancellationToken cancellationToken)
{
Contract.Requires(descriptiveName != null);
Contract.Requires(vc != null);
Expand All @@ -319,6 +329,12 @@ public async Task BeginCheck(string descriptiveName, VCExpr vc, ProverInterface.
this.handler = handler;

await thmProver.Reset(gen);
if (0 < rlimit)
{
timeout = 0;
}
SetTimeout(timeout);
SetRlimit(rlimit);

ProverStart = DateTime.UtcNow;
ProverStopwatch.Restart();
Expand Down
6 changes: 2 additions & 4 deletions Source/VCGeneration/SmokeTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,8 @@ async Task<bool> CheckUnreachable(TextWriter traceWriter, Block cur, List<Cmd> s
Emit();
}
}

checker.TheoremProver.SetTimeout(Options.SmokeTimeout);
checker.TheoremProver.SetRlimit(Options.ResourceLimit);
await checker.BeginCheck(cce.NonNull(Implementation.Name + "_smoke" + id++), vc, new ErrorHandler(Options, absyIds, callback), CancellationToken.None);
await checker.BeginCheck(cce.NonNull(Implementation.Name + "_smoke" + id++), vc, new ErrorHandler(Options, absyIds, callback),
Options.SmokeTimeout, Options.ResourceLimit, CancellationToken.None);

await checker.ProverTask;

Expand Down
6 changes: 2 additions & 4 deletions Source/VCGeneration/Split.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,12 +1353,10 @@ public async Task BeginCheck(TextWriter traceWriter, Checker checker, VerifierCa
Print();
}

checker.TheoremProver.SetTimeout(Util.BoundedMultiply(timeout, 1000));
checker.TheoremProver.SetRlimit(rlimit);
foreach (var entry in Implementation.GetExtraSMTOptions()) {
checker.TheoremProver.SetOtherSMTOption(entry.Key, entry.Value);
checker.TheoremProver.SetLocalSMTOption(entry.Key, entry.Value);
}
await checker.BeginCheck(Description, vc, reporter, cancellationToken);
await checker.BeginCheck(Description, vc, reporter, timeout, rlimit, cancellationToken);
}

public string Description
Expand Down

0 comments on commit 4ad4d6a

Please sign in to comment.