Skip to content

Commit

Permalink
fix: Add missing triggers to Map#Card axioms in Boogie prelude (dafny…
Browse files Browse the repository at this point in the history
…-lang#2417)

Closes dafny-lang#2380.

@atomb , can you show me how to run a performance regression run on
this? I'm not sure how it will impact our customers.

Co-authored-by: Mikaël Mayer <[email protected]>
  • Loading branch information
cpitclaudel and MikaelMayer authored Jul 31, 2023
1 parent f7b9143 commit 72410e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Source/DafnyCore/DafnyPrelude.bpl
Original file line number Diff line number Diff line change
Expand Up @@ -1207,13 +1207,13 @@ axiom (forall<U, V> m: Map U V ::
m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));

axiom (forall<U, V> m: Map U V ::
{ Set#Card(Map#Domain(m)) }
{ Set#Card(Map#Domain(m)) } { Map#Card(m) }
Set#Card(Map#Domain(m)) == Map#Card(m));
axiom (forall<U, V> m: Map U V ::
{ Set#Card(Map#Values(m)) }
{ Set#Card(Map#Values(m)) } { Map#Card(m) }
Set#Card(Map#Values(m)) <= Map#Card(m));
axiom (forall<U, V> m: Map U V ::
{ Set#Card(Map#Items(m)) }
{ Set#Card(Map#Items(m)) } { Map#Card(m) }
Set#Card(Map#Items(m)) == Map#Card(m));

// The set of Values of a Map can be obtained by the function Map#Values, which is
Expand Down
32 changes: 32 additions & 0 deletions Test/git-issues/git-issue-2380.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %dafny /compile:0 "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

method M0(t: map<int, int>, k: int)
requires k in t
{
if * {
assert |t| == |t - {k}| + 1;
} else if * {
assume t.Items == {(1, 2), (3, 4)};
assert |t| == 2;
} else {
assume t.Values == {2, 3, 4};
assert |t| >= 2;
}
}

method M0'(t: map<int, int>, k: int)
requires k in t
{
if * {
var _ := |(t - {k}).Keys|;
assert |t| == |t - {k}| + 1;
} else if * {
assume t.Items == {(1, 2), (3, 4)};
var _ := |t.Items|;
assert |t| == 2;
} else {
assume t.Values == {2, 3, 4};
assert |t.Values| >= 2;
}
}
2 changes: 2 additions & 0 deletions Test/git-issues/git-issue-2380.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Dafny program verifier finished with 2 verified, 0 errors

0 comments on commit 72410e1

Please sign in to comment.