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

Add test and fix bug in RevealedAnalysis #907

Merged
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
2 changes: 2 additions & 0 deletions Source/Core/AST/ChangeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public override void Typecheck(TypecheckingContext tc) {
}

public override void Emit(TokenTextWriter stream, int level) {
stream.Write(this, level, Mode == Modes.Push ? "push" : "pop");
stream.WriteLine(";");
}

public override void AddAssignedVariables(List<Variable> vars) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- Target framework and package configuration -->
<PropertyGroup>
<Version>3.2.0</Version>
<Version>3.2.1</Version>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>Boogie</Authors>
Expand Down
21 changes: 14 additions & 7 deletions Source/VCGeneration/Prune/RevealedAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.Boogie;

namespace VCGeneration.Prune;
Expand All @@ -27,10 +28,14 @@ public RevealedAnalysis(IReadOnlyList<Cmd> roots,
RevealedState.AllRevealed);

protected override ImmutableStack<RevealedState> Merge(ImmutableStack<RevealedState> first, ImmutableStack<RevealedState> second) {
var firstTop = first.Peek();
var secondTop = second.Peek();
var mergedTop = MergeStates(firstTop, secondTop);
return ImmutableStack.Create(mergedTop);
if (first.IsEmpty && second.IsEmpty) {
return ImmutableStack<RevealedState>.Empty;
}
var firstElement = first.Peek();
var secondElement = second.Peek();
var mergedTop = MergeStates(firstElement, secondElement);
var mergedTail = Merge(first.Pop(), second.Pop());
return mergedTail.Push(mergedTop);
}

protected override bool StateEquals(ImmutableStack<RevealedState> first, ImmutableStack<RevealedState> second) {
Expand Down Expand Up @@ -77,10 +82,12 @@ static RevealedState GetUpdatedState(HideRevealCmd hideRevealCmd, RevealedState
}

protected override ImmutableStack<RevealedState> Update(Cmd node, ImmutableStack<RevealedState> state) {
if (state.IsEmpty) {
throw new Exception("Unbalanced use of push and pop commands");
}

if (node is ChangeScope changeScope) {
return changeScope.Mode == ChangeScope.Modes.Push
? state.Push(state.Peek())
: state.Pop();
return changeScope.Mode == ChangeScope.Modes.Push ? state.Push(state.Peek()) : state.Pop();
}

if (node is HideRevealCmd hideRevealCmd) {
Expand Down
11 changes: 11 additions & 0 deletions Test/pruning/Reveal.bpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ procedure Scoping() {
assert outer(2) == inner(2) + 1;
pop;
assert outer(3) == inner(3) + 1; // error
}

procedure Nesting() {
hide *;
push;
push;
if (*) {
reveal outer;
}
pop;
pop;
}
2 changes: 1 addition & 1 deletion Test/pruning/Reveal.bpl.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Reveal.bpl(29,7): Error: this assertion could not be proved
Reveal.bpl(31,7): Error: this assertion could not be proved
Reveal.bpl(42,3): Error: this assertion could not be proved

Boogie program verifier finished with 0 verified, 4 errors
Boogie program verifier finished with 1 verified, 4 errors
Loading