Skip to content

Use of wildcard in function precondition causes incompleteness (but not in an equivalent method) #512

@bobismijnnaam

Description

@bobismijnnaam

As far as I can tell, the following function & method are identical. But, for the master branch of silicon, only the method verifies. The function does not. Specifically, the last ensures clause of the function cannot be proven. Strangely enough the current version of viper used in vscode verifies both the function and method (as well as very old version of viper currently used by VerCors). My vscode plugin version is 2.2.2, though I suspect the version of viper it is using is different, but I'm not sure how to dig that up.

EDIT: The "v" field in my default vscode settings seems to be set to: "674a514867b1"

//  a field
field item: Int

function seqToSeqHelper(xs: Seq[Ref], i: Int): Seq[Int]
  requires 0 <= i && i <= |xs|
  requires (forall j: Int :: 0 <= j && j < |xs| ==> acc(xs[j].item, wildcard))

  ensures |result| == |xs| - i
  ensures (forall j: Int :: i <= j && j < |xs| ==> result[j - i] == xs[j].item)
{
  (i < |xs| ? Seq(xs[i].item) ++ seqToSeqHelper(xs, i + 1) : Seq[Int]())
}

method method_seqToSeqHelper(xs: Seq[Ref], i: Int) returns (res: Seq[Int])
  requires 0 <= i && i <= |xs|
  requires (forall j: Int :: 0 <= j && j < |xs| ==> acc(xs[j].item, wildcard))
  ensures 0 <= i && i <= |xs|
  ensures (forall j: Int :: 0 <= j && j < |xs| ==> acc(xs[j].item, wildcard))

  ensures |res| == |xs| - i
  ensures (forall j: Int :: i <= j && j < |xs| ==> res[j - i] == xs[j].item)
{
  if (i < |xs|) {
    var tail: Seq[Int]
    // tail := seqToSeqHelper(xs, i + 1) // with this instead of the line below, both methods fail
    tail := method_seqToSeqHelper(xs, i + 1)
    res := Seq(xs[i].item) ++ tail
  } else {
    res := Seq()
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions