Skip to content

Commit

Permalink
Monomorphization of polymorphic maps and binders (#669)
Browse files Browse the repository at this point in the history
* first commit

* moved test to the correct location

* first successful verification of polymorphic lambda

* bug fix

* more bug fixes

* minor cleanup

* refactoring

* fixpoint now detects increase in instantiated declarations

* another bug fix

* added support for type instantiation based on instantiated type constructors

* enabled binder instantiation

* fixed bug

* bug fixes

* added representative Viper subset for monomorphization

* add file with parametric Viper domains

* added Dafny files for monomorphization

* remove system information from Viper monomorphization files

* fixed bugs

* refactored MonomorphicExpr() interface method

* split axiom conjuncts into separate axioms

* some typos and minor cleanup

* added dafny and viper tests (but with /noVerify)

* added some documentation

* some refactoring

* fixed bugs and added documentation

* more documentation

* List -> HashSet for instantiationHints

* added two more tests

Co-authored-by: gauravpartha <[email protected]>
  • Loading branch information
shazqadeer and gauravpartha authored Jan 11, 2023
1 parent 88cd431 commit 76b6a37
Show file tree
Hide file tree
Showing 44 changed files with 87,187 additions and 178 deletions.
1,009 changes: 844 additions & 165 deletions Source/Core/Monomorphization.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Source/Core/StandardVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ public virtual Implementation VisitImplementation(Implementation node)
node.Blocks = this.VisitBlockList(node.Blocks);
node.Proc = this.VisitProcedure(cce.NonNull(node.Proc));
node = (Implementation) this.VisitDeclWithFormals(node); // do this first or last?
VisitAttributes(node);
return node;
}

Expand Down
8 changes: 6 additions & 2 deletions Source/ExecutionEngine/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ status in `/trace` and selecting procedures to verify with
the original name of an identifier translated into Boogie from
some other source language.
---- On Axioms -------------------------------------------------------------
---- On axioms -------------------------------------------------------------
{:include_dep}
Expand Down Expand Up @@ -1898,6 +1898,8 @@ after substituting variables with their incarnations at the command.
bound variables with fresh skolem constants, whenever the quantifier is
skolemized.
These attributes are not effective for quantifiers inside the scope of axioms.
---- Civl ------------------------------------------------------------------
{:yields}
Expand Down Expand Up @@ -2002,7 +2004,9 @@ inductive sequentialization. These are exempt from the overall pool of
Multiple .bpl files supplied on the command line are concatenated into one
Boogie program.
/lib : Include library definitions
/lib:<name> : Include definitions in library <name>. The file <name>.bpl
must be an included resource in Core.dll. Currently, the
following libraries are supported---base, node.
/proc:<p> : Only check procedures matched by pattern <p>. This option
may be specified multiple times to match multiple patterns.
The pattern <p> matches the whole procedure name and may
Expand Down
7 changes: 3 additions & 4 deletions Source/VCGeneration/Prune/AxiomVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

Expand Down Expand Up @@ -80,10 +79,10 @@ public override Expr VisitExpr(Expr node) {
bvc.E1.pos = Expr.Position.Neither;
} else if (node is BinderExpr bexp) {
bexp.Body.pos = Expr.Position.Neither;
} else if (node is LetExpr l){
} else if (node is LetExpr l) {
l.Body.pos = Expr.Position.Neither;
} else {
if(node is LiteralExpr || node is IdentifierExpr) {
if (node is LiteralExpr || node is IdentifierExpr) {

} else {
Console.WriteLine(node);
Expand All @@ -93,7 +92,7 @@ public override Expr VisitExpr(Expr node) {
return base.VisitExpr(node);
}

public override Boogie.Type VisitType(Boogie.Type node)
public override Type VisitType(Type node)
{
types.Add(node);
return base.VisitType(node);
Expand Down
2 changes: 1 addition & 1 deletion Source/VCGeneration/Prune/BlocksVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override Expr VisitExpr(Expr node)
return base.VisitExpr(node);
}

public override Boogie.Type VisitType(Boogie.Type node)
public override Type VisitType(Type node)
{
types.Add(node);
return base.VisitType(node);
Expand Down
3 changes: 1 addition & 2 deletions Source/VCGeneration/Prune/DependencyEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Boogie
{
Expand All @@ -10,7 +9,7 @@ public class DependencyEvaluator : ReadOnlyVisitor
// Most incoming dependents correspond to exactly one function or constant, but some of them are tuples.
// For example, consider an axiom of the form:
// axiom forall x, y :: {P(x, y), Q(y)} {R(x)} P(x, y) ==> R(x)
// The axiom may (only) be triggerd by a declaration/implementation that either mentions
// The axiom may (only) be triggered by a declaration/implementation that either mentions
// both P and Q or mentions function R.
// Thus, it has two incoming dependents:
// 1) the tuple (P, Q) and 2) the function R. I store tuples in the variable incomingTuples.
Expand Down
2 changes: 1 addition & 1 deletion Source/VCGeneration/Prune/FunctionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override Expr VisitExpr(Expr node)
}
return base.VisitExpr(node);
}
public override Boogie.Type VisitType(Boogie.Type node)
public override Type VisitType(Boogie.Type node)
{
types.Add(node);
return base.VisitType(node);
Expand Down
1 change: 0 additions & 1 deletion Source/VCGeneration/Prune/Prune.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Boogie.GraphUtil;
Expand Down
29 changes: 29 additions & 0 deletions Test/monomorphize/Dafny_frame.bpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %parallel-boogie /monomorphize "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

type Field T;
type ref;
type HeapType = [ref]<alpha>[Field alpha]alpha;

var $Heap: HeapType;
const unique alloc: Field bool;
const null: ref;

function {:inline} read<alpha>(H: HeapType, r: ref, f: Field alpha) : alpha
{
H[r][f]
}

procedure p($r: ref)
requires $r != null;
requires $Heap[$r][alloc];
{
var $Frame: <beta>[ref,Field beta]bool;
var i: int;

$Frame := (lambda<alpha> $o: ref, $f: Field alpha ::
$o != null && read($Heap, $o, alloc) ==> false);

assert $Frame[null, alloc];
assert !$Frame[$r, alloc];
}
2 changes: 2 additions & 0 deletions Test/monomorphize/Dafny_frame.bpl.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Boogie program verifier finished with 1 verified, 0 errors
Loading

0 comments on commit 76b6a37

Please sign in to comment.