Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable marking if commands as {:allow_split} or not #960

Draft
wants to merge 74 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
576e153
IsolatePaths option seems to work, although it still duplicates errors
keyboardDrummer Sep 24, 2024
8d0bee6
Refactoring
keyboardDrummer Sep 24, 2024
0465e6e
Finish test and some more refactoring
keyboardDrummer Sep 24, 2024
b451f9f
Refactoring
keyboardDrummer Sep 24, 2024
b016f40
Refactoring
keyboardDrummer Sep 24, 2024
0fa1817
Update version number
keyboardDrummer Sep 24, 2024
4755839
Tweaks
keyboardDrummer Sep 24, 2024
23f44ed
Improve implementation and add tests
keyboardDrummer Sep 24, 2024
64b1010
More efficient assumed block generation
keyboardDrummer Sep 25, 2024
bccf0b1
Improvements to splitting, but still need check command to make the t…
keyboardDrummer Sep 25, 2024
7d5b58f
Some changes
keyboardDrummer Sep 27, 2024
a2f1f76
Remove isolatePaths code
keyboardDrummer Sep 27, 2024
9620a3f
Add path tokens
keyboardDrummer Sep 27, 2024
c5f13f0
Refactoring
keyboardDrummer Sep 27, 2024
409cdb8
Rename
keyboardDrummer Sep 27, 2024
d4d5db6
Refactoring
keyboardDrummer Sep 27, 2024
627b42c
Upgrade token
keyboardDrummer Sep 27, 2024
b6e6dab
Fixes
keyboardDrummer Sep 27, 2024
d08537e
Introduce ImplementationPartToken
keyboardDrummer Sep 27, 2024
b46af73
Rename
keyboardDrummer Sep 27, 2024
6718564
Refactoring
keyboardDrummer Sep 27, 2024
23a0942
Refactoring
keyboardDrummer Sep 27, 2024
2404e95
Fix warnings
keyboardDrummer Sep 27, 2024
d847412
Draft for isolated assertion
keyboardDrummer Sep 30, 2024
dea7493
More progress on the {:isolate} attribute
keyboardDrummer Sep 30, 2024
cf450a1
Move some code into DesugarReturns
keyboardDrummer Oct 1, 2024
6c8ccaf
Work on supporting isolate for return commands
keyboardDrummer Oct 1, 2024
5bbe971
Refactoring
keyboardDrummer Oct 1, 2024
0d0e8fc
Reorder tests
keyboardDrummer Oct 1, 2024
a73bba0
Fixes. Isolatepaths for assertions seems to work
keyboardDrummer Oct 1, 2024
9a3ee51
Added isolateJump test
keyboardDrummer Oct 1, 2024
9ebb0a2
Update tests and fixes
keyboardDrummer Oct 2, 2024
b7c9f8d
Merge commit '40f15f1e1~1' into isolatePaths
keyboardDrummer Oct 2, 2024
5372d5e
Merge commit '40f15f1e1' into isolatePaths
keyboardDrummer Oct 2, 2024
db79862
Code review
keyboardDrummer Oct 2, 2024
206acde
Add refactoring
keyboardDrummer Oct 2, 2024
617852b
Refactoring
keyboardDrummer Oct 2, 2024
2886d7e
Fix
keyboardDrummer Oct 2, 2024
feeda38
Update test
keyboardDrummer Oct 2, 2024
1ae99e3
Fix test
keyboardDrummer Oct 2, 2024
2547c87
Save
keyboardDrummer Oct 2, 2024
24e5b4d
Extract some code into file RemoveBackEdges
keyboardDrummer Oct 2, 2024
cc96494
Remove need for gotoCmdOrigins map
keyboardDrummer Oct 2, 2024
6797249
Remove occurrences of gotoCmd dictionary
keyboardDrummer Oct 2, 2024
d3a9015
Simple fail now passes
keyboardDrummer Oct 2, 2024
c1db5a2
Update test files
keyboardDrummer Oct 2, 2024
064b44a
Fixes
keyboardDrummer Oct 2, 2024
a7ce5e0
Test file fixes
keyboardDrummer Oct 2, 2024
9a27654
Fixes
keyboardDrummer Oct 3, 2024
43d6824
Update tests
keyboardDrummer Oct 3, 2024
1a5ff89
Fix path isolation error reporting
keyboardDrummer Oct 3, 2024
be86f19
Refactoring
keyboardDrummer Oct 3, 2024
d91787c
Refactoring
keyboardDrummer Oct 3, 2024
2e8c8e4
Remove TODO
keyboardDrummer Oct 3, 2024
91c304d
Refactoring
keyboardDrummer Oct 3, 2024
ff1442a
Remove TODO
keyboardDrummer Oct 3, 2024
c603cc8
Cleanup
keyboardDrummer Oct 3, 2024
506d9c1
Refactoring before adding pathable blocks, but this broke some tests
keyboardDrummer Oct 3, 2024
d2278dc
Refactoring so BlockCoalescer does not need to know about GotoFromReturn
keyboardDrummer Oct 3, 2024
09bba24
Update focus expect file
keyboardDrummer Oct 3, 2024
0eb1327
Merge commit '9a8ce8d4c4c23' into isolatePaths
keyboardDrummer Oct 4, 2024
5453541
Extract Source/Core/AST/BigBlocksResolutionContext.cs into a separate…
keyboardDrummer Oct 4, 2024
eff7523
Change FreshAnon into FreshPrefix
keyboardDrummer Oct 4, 2024
fff02b8
Automated refactoring
keyboardDrummer Oct 4, 2024
d9722c3
Automated refactoring
keyboardDrummer Oct 4, 2024
3e14a66
Extract classes into separate files
keyboardDrummer Oct 4, 2024
760c2b0
Refactoring
keyboardDrummer Oct 4, 2024
5271205
Moves classes into separate files
keyboardDrummer Oct 4, 2024
fa0019d
Refactoring
keyboardDrummer Oct 4, 2024
ccdf5c8
Add back comment
keyboardDrummer Oct 4, 2024
0a7d33e
Merge branch 'refactoring2' into isolatePathsNext
keyboardDrummer Oct 4, 2024
7c69e05
Part refactoring part prep for allow_split attribute
keyboardDrummer Oct 4, 2024
f91ccc5
Fix comp errors
keyboardDrummer Oct 4, 2024
45164d5
Updates
keyboardDrummer Oct 4, 2024
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
14 changes: 7 additions & 7 deletions Source/AbstractInterpretation/NativeLattice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void Analyze(Implementation impl, NativeLattice lattice, NativeLattice.El
int n = 0;
foreach (var block in impl.Blocks)
{
block.aiId = n;
block.AiId = n;
// Note: The forward analysis below will store lattice elements in pre[n] if pre[n] is non-null.
// Thus, the assignment "pre[n] = bottom;" below must be done under the following condition:
// n == 0 || block.widenBlock
Expand All @@ -219,7 +219,7 @@ public void Analyze(Implementation impl, NativeLattice lattice, NativeLattice.El
{
var workItem = workItems.Dequeue();
var b = workItem.Item1;
var id = b.aiId;
var id = b.AiId;
var e = workItem.Item2;
if (pre[id] == null)
{
Expand All @@ -230,7 +230,7 @@ public void Analyze(Implementation impl, NativeLattice lattice, NativeLattice.El
// no change
continue;
}
else if (b.widenBlock && options.Ai.StepsBeforeWidening <= iterations[id])
else if (b.WidenBlock && options.Ai.StepsBeforeWidening <= iterations[id])
{
e = lattice.Widen(pre[id], e);
pre[id] = e;
Expand Down Expand Up @@ -275,8 +275,8 @@ void Instrument(Implementation impl, NativeLattice.Element[] pre, NativeLattice.

foreach (var b in impl.Blocks)
{
var element = pre[b.aiId];
if (element != null && (b.widenBlock || options.InstrumentInfer ==
var element = pre[b.AiId];
if (element != null && (b.WidenBlock || options.InstrumentInfer ==
CoreOptions.InstrumentationPlaces.Everywhere))
{
List<Cmd> newCommands = new List<Cmd>();
Expand All @@ -294,9 +294,9 @@ void Instrument(Implementation impl, NativeLattice.Element[] pre, NativeLattice.

newCommands.Add(cmd);
newCommands.AddRange(b.Cmds);
if (post != null && post[b.aiId] != null)
if (post != null && post[b.AiId] != null)
{
inv = post[b.aiId].ToExpr(options);
inv = post[b.AiId].ToExpr(options);
kv = new QKeyValue(Token.NoToken, "inferred", new List<object>(), null);
if (options.InstrumentWithAsserts)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/AbstractInterpretation/Traverse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void Visit(Block b)
{
cce.BeginExpose(b);
// we got here through a back-edge
b.widenBlock = true;
b.WidenBlock = true;
cce.EndExpose();
}
else if (b.TraversingStatus == Block.VisitState.AlreadyVisited)
Expand Down Expand Up @@ -111,7 +111,7 @@ static void Visit(Block b)
/// </summary>
public static List<Block> ComputeLoopBodyFrom(Block block)
{
Contract.Requires(block.widenBlock);
Contract.Requires(block.WidenBlock);
Contract.Requires(block != null);
Contract.Ensures(cce.NonNullElements(Contract.Result<List<Block>>()));

Expand Down
10 changes: 5 additions & 5 deletions Source/Concurrency/LinearTypeChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,14 @@ void ProcessIfCmd(IfCmd ifCmd)
{
checkingContext.Error(ifCmd.tok, "access to linear store not allowed");
}
stmtLists.Push(ifCmd.thn);
if (ifCmd.elseIf != null)
stmtLists.Push(ifCmd.Thn);
if (ifCmd.ElseIf != null)
{
ProcessIfCmd(ifCmd.elseIf);
ProcessIfCmd(ifCmd.ElseIf);
}
else if (ifCmd.elseBlock != null)
else if (ifCmd.ElseBlock != null)
{
stmtLists.Push(ifCmd.elseBlock);
stmtLists.Push(ifCmd.ElseBlock);
}
}
ProcessIfCmd(ifCmd);
Expand Down
96 changes: 52 additions & 44 deletions Source/Concurrency/YieldingProcInstrumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,65 +474,73 @@ private void DesugarConcurrency(Implementation impl, List<Cmd> preconditions)

// add jumps to noninterferenceChecker, returnChecker, and refinementChecker blocks
var implRefinementCheckingBlocks = new List<Block>();
foreach (var b in impl.Blocks)
foreach (var block in impl.Blocks)
{
if (b.TransferCmd is GotoCmd gotoCmd)
if (block.TransferCmd is not GotoCmd gotoCmd)
{
block.TransferCmd = new GotoCmd(block.TransferCmd.tok,
new List<Block> { returnCheckerBlock, returnBlock, noninterferenceCheckerBlock });
}
else
{
var targetBlocks = new List<Block>();
var addEdge = false;
foreach (var nextBlock in gotoCmd.LabelTargets)
{
if (nextBlock.cmds.Count > 0)
if (nextBlock.Cmds.Count <= 0)
{
continue;
}

var cmd = nextBlock.Cmds[0];
if (cmd is not ParCallCmd parCallCmd)
{
var cmd = nextBlock.cmds[0];
if (cmd is ParCallCmd parCallCmd)
continue;
}

foreach (var callCmd in parCallCmd.CallCmds)
{
if (!refinementBlocks.TryGetValue(callCmd, out var targetBlock))
{
foreach (var callCmd in parCallCmd.CallCmds)
{
if (refinementBlocks.ContainsKey(callCmd))
{
var targetBlock = refinementBlocks[callCmd];
FixUpImplRefinementCheckingBlock(targetBlock,
CivlAttributes.IsCallMarked(callCmd)
? returnCheckerBlock
: unchangedCheckerBlock);
targetBlocks.Add(targetBlock);
implRefinementCheckingBlocks.Add(targetBlock);
}
}
addEdge = true;
continue;
}

FixUpImplRefinementCheckingBlock(targetBlock,
CivlAttributes.IsCallMarked(callCmd)
? returnCheckerBlock
: unchangedCheckerBlock);
targetBlocks.Add(targetBlock);
implRefinementCheckingBlocks.Add(targetBlock);
}

addEdge = true;
}

gotoCmd.AddTargets(targetBlocks);
if (addEdge)
if (!addEdge)
{
AddEdge(gotoCmd, noninterferenceCheckerBlock);
if (blocksInYieldingLoops.Contains(b))
{
AddEdge(gotoCmd, unchangedCheckerBlock);
}
else
{
b.Cmds.AddRange(refinementInstrumentation.CreateActionEvaluationCmds());
AddEdge(gotoCmd, refinementCheckerBlock);
}
continue;
}

AddEdge(gotoCmd, noninterferenceCheckerBlock);
if (blocksInYieldingLoops.Contains(block))
{
AddEdge(gotoCmd, unchangedCheckerBlock);
}
else
{
block.Cmds.AddRange(refinementInstrumentation.CreateActionEvaluationCmds());
AddEdge(gotoCmd, refinementCheckerBlock);
}
}
else
{
b.TransferCmd = new GotoCmd(b.TransferCmd.tok,
new List<Block> {returnCheckerBlock, returnBlock, noninterferenceCheckerBlock});
}
}

// desugar ParCallCmd
foreach (Block b in impl.Blocks)
{
if (b.cmds.Count > 0)
if (b.Cmds.Count > 0)
{
var cmd = b.cmds[0];
var cmd = b.Cmds[0];
if (cmd is ParCallCmd)
{
DesugarParCallCmdInBlock(b, blocksInYieldingLoops.Contains(b));
Expand Down Expand Up @@ -578,27 +586,27 @@ private void SplitBlocks(Implementation impl)
{
var currTransferCmd = b.TransferCmd;
int labelCount = 0;
int lastSplitIndex = b.cmds.Count;
for (int i = b.cmds.Count - 1; i >= 0; i--)
int lastSplitIndex = b.Cmds.Count;
for (int i = b.Cmds.Count - 1; i >= 0; i--)
{
var split = false;
var cmd = b.cmds[i];
var cmd = b.Cmds[i];
if (cmd is ParCallCmd)
{
split = true;
}

if (split)
{
var newBlock = new Block(b.tok, $"{b.Label}_{labelCount++}", b.cmds.GetRange(i, lastSplitIndex - i),
var newBlock = new Block(b.tok, $"{b.Label}_{labelCount++}", b.Cmds.GetRange(i, lastSplitIndex - i),
currTransferCmd);
newBlocks.Add(newBlock);
currTransferCmd = new GotoCmd(b.tok, new List<Block> {newBlock});
lastSplitIndex = i;
}
}

b.cmds = b.cmds.GetRange(0, lastSplitIndex);
b.Cmds = b.Cmds.GetRange(0, lastSplitIndex);
b.TransferCmd = currTransferCmd;
}

Expand Down Expand Up @@ -714,8 +722,8 @@ private void DesugarParCallCmdInBlock(Block block, bool isBlockInYieldingLoop)
newCmds.AddRange(CreateUpdatesToOldGlobalVars());
newCmds.AddRange(refinementInstrumentation.CreateUpdatesToOldOutputVars());
newCmds.AddRange(CreateUpdatesToPermissionCollector(parCallCmd));
newCmds.AddRange(block.cmds.GetRange(1, block.cmds.Count - 1));
block.cmds = newCmds;
newCmds.AddRange(block.Cmds.GetRange(1, block.Cmds.Count - 1));
block.Cmds = newCmds;
}

private Formal ParCallDesugarFormal(Variable v, int count, bool incoming)
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/AST/Absy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ public override void Resolve(ResolutionContext rc)

public void ResolveWhere(ResolutionContext rc)
{
if (QKeyValue.FindBoolAttribute(Attributes, "assumption") && this.TypedIdent.WhereExpr != null)
if (Attributes.FindBoolAttribute("assumption") && this.TypedIdent.WhereExpr != null)
{
rc.Error(tok, "assumption variable may not be declared with a where clause");
}
Expand All @@ -1315,7 +1315,7 @@ public override void Typecheck(TypecheckingContext tc)
{
(this as ICarriesAttributes).TypecheckAttributes(tc);
this.TypedIdent.Typecheck(tc);
if (QKeyValue.FindBoolAttribute(Attributes, "assumption") && !this.TypedIdent.Type.IsBool)
if (Attributes.FindBoolAttribute("assumption") && !this.TypedIdent.Type.IsBool)
{
tc.Error(tok, "assumption variable must be of type 'bool'");
}
Expand Down Expand Up @@ -2059,7 +2059,7 @@ public override void Emit(TokenTextWriter stream, int level)

stream.Write(this, level, (AlwaysRevealed ? "revealed " : "") + "function ");
EmitAttributes(stream);
if (Body != null && !QKeyValue.FindBoolAttribute(Attributes, "inline"))
if (Body != null && !Attributes.FindBoolAttribute("inline"))
{
Contract.Assert(DefinitionBody == null);
// Boogie inlines any function whose .Body field is non-null. The parser populates the .Body field
Expand All @@ -2069,7 +2069,7 @@ public override void Emit(TokenTextWriter stream, int level)
stream.Write("{:inline} ");
}

if (DefinitionBody != null && !QKeyValue.FindBoolAttribute(Attributes, "define"))
if (DefinitionBody != null && !Attributes.FindBoolAttribute("define"))
{
// Boogie defines any function whose .DefinitionBody field is non-null. The parser populates the .DefinitionBody field
// if the :define attribute is present, but if someone creates the Boogie file directly as an AST, then
Expand Down Expand Up @@ -2350,7 +2350,7 @@ public String ErrorMessage

public bool CanAlwaysAssume()
{
return Free && QKeyValue.FindBoolAttribute(Attributes, "always_assume");
return Free && Attributes.FindBoolAttribute("always_assume");
}


Expand Down Expand Up @@ -2490,7 +2490,7 @@ public String ErrorMessage

public bool CanAlwaysAssume ()
{
return Free && QKeyValue.FindBoolAttribute(this.Attributes, "always_assume");
return Free && Attributes.FindBoolAttribute("always_assume");
}

public Ensures(IToken token, bool free, Expr condition, string comment, QKeyValue kv)
Expand Down
10 changes: 0 additions & 10 deletions Source/Core/AST/AbsyQuant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,6 @@ public static Expr FindExprAttribute(QKeyValue kv, string name)
return null;
}

// Return 'true' if {:name true} or {:name} is an attribute in 'kv'
public static bool FindBoolAttribute(QKeyValue kv, string name)
{
Contract.Requires(name != null);
kv = FindAttribute(kv, qkv => qkv.Key == name && (qkv.Params.Count == 0 ||
(qkv.Params.Count == 1 && qkv.Params[0] is LiteralExpr &&
((LiteralExpr) qkv.Params[0]).IsTrue)));
return kv != null;
}

public static int FindIntAttribute(QKeyValue kv, string name, int defl)
{
Contract.Requires(name != null);
Expand Down
Loading
Loading