Skip to content

Commit

Permalink
Merge branch 'master' into dspil_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dspil committed Oct 27, 2023
2 parents 2fa5e9f + 118f5a6 commit 17005ae
Show file tree
Hide file tree
Showing 25 changed files with 994 additions and 198 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/update-submodules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2011-2022 ETH Zurich.

name: Update Submodules

on:
workflow_dispatch: # allow to manually trigger this workflow
schedule:
- cron: '0 6 * * *' # run every day at 06:00 UTC

jobs:
# Update silver and create a PR if there are any changes
update:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
submodules: true

- name: Get current commits
run: echo "PREV_SILVER_REF=$(git -C silver rev-parse HEAD)" >> $GITHUB_ENV

- name: Update Silver submodule
run: git checkout master && git pull
working-directory: silver

- name: Get new commits
run: echo "CUR_SILVER_REF=$(git -C silver rev-parse HEAD)" >> $GITHUB_ENV

- name: Create PR body
run: |
if [[ "${{ env.PREV_SILVER_REF }}" != "${{ env.CUR_SILVER_REF }}" ]]; then
echo 'PR_BODY_LINE=* Updates Silver from `${{ env.PREV_SILVER_REF }}` to `${{ env.CUR_SILVER_REF }}`.' >> $GITHUB_ENV
else
echo 'PR_BODY_LINE=' >> $GITHUB_ENV
fi
- name: Open a pull request
id: pr
uses: peter-evans/create-pull-request@v4
if: (env.PREV_SILVER_REF != env.CUR_SILVER_REF)
with:
# Use viper-admin's token to workaround a restriction of GitHub.
# See: https://github.com/peter-evans/create-pull-request/issues/48
token: ${{ secrets.UPDATE_SILVER }}
commit-message: Updates submodules
title: Update Submodules
branch: auto-update-submodules
delete-branch: true
labels: |
automated pr
body: |
${{ env.PR_BODY_LINE1 }}
- name: Enable auto-merge of PR
uses: peter-evans/create-or-update-comment@v2
if: (env.PREV_SILVER_REF != env.CUR_SILVER_REF)
with:
token: ${{ secrets.UPDATE_SILVER }}
issue-number: ${{ steps.pr.outputs.pull-request-number }}"
body: bors merge
2 changes: 1 addition & 1 deletion silver
17 changes: 15 additions & 2 deletions src/main/scala/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
noshort = true
)

val moreJoins: ScallopOption[Boolean] = opt[Boolean]("moreJoins",
descr = "Enable more joins using a more complete implementation of state merging.",
default = Some(false),
noshort = true
)

val exhaleModeOption: ScallopOption[ExhaleMode] = opt[ExhaleMode]("exhaleMode",
descr = "Exhale mode. Options are 0 (greedy, default), 1 (more complete exhale), 2 (more complete exhale on demand).",
default = None,
Expand Down Expand Up @@ -684,8 +690,10 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
)(singleArgConverter(mode => StateConsolidationMode(mode.toInt)))

val numberOfParallelVerifiers: ScallopOption[Int] = opt[Int]("numberOfParallelVerifiers",
descr = ( "Number of verifiers run in parallel. This number plus one is the number of provers "
+ s"run in parallel (default: ${Runtime.getRuntime.availableProcessors()})"),
descr = ( "Number of verifiers (and therefore also prover instances) run in parallel for method verification." +
"A value of 1 leads to sequential method verification. " +
"Functions and predicates are always verified sequentially on a separate prover instance. " +
s"Default: ${Runtime.getRuntime.availableProcessors()}"),
default = Some(Runtime.getRuntime.availableProcessors()),
noshort = true
)
Expand Down Expand Up @@ -815,6 +823,11 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
case _ => Right(())
}

validateOpt(numberOfParallelVerifiers) {
case Some(n) if n <= 0 => Left(s"Number of parallel verifiers must be positive, but $n was provided")
case _ => Right()
}

validateFileOpt(logConfig)
validateFileOpt(setAxiomatizationFile)
validateFileOpt(multisetAxiomatizationFile)
Expand Down
100 changes: 77 additions & 23 deletions src/main/scala/decider/Decider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import viper.silicon.verifier.{Verifier, VerifierComponent}
import viper.silver.reporter.{ConfigurationConfirmation, InternalWarningMessage}

import scala.collection.immutable.HashSet
import scala.collection.mutable

/*
* Interfaces
Expand All @@ -40,7 +41,8 @@ trait Decider {
def setPathConditionMark(): Mark

def assume(t: Term): Unit
def assume(ts: InsertionOrderedSet[Term], enforceAssumption: Boolean = false): Unit
def assumeDefinition(t: Term): Unit
def assume(ts: InsertionOrderedSet[Term], enforceAssumption: Boolean = false, isDefinition: Boolean = false): Unit
def assume(ts: Iterable[Term]): Unit

def check(t: Term, timeout: Int): Boolean
Expand Down Expand Up @@ -72,8 +74,10 @@ trait Decider {
// slower, so this tradeoff seems worth it.
def freshFunctions: Set[FunctionDecl]
def freshMacros: Vector[MacroDecl]
def declareAndRecordAsFreshFunctions(functions: Set[FunctionDecl]): Unit
def declareAndRecordAsFreshMacros(functions: Vector[MacroDecl]): Unit
def declareAndRecordAsFreshFunctions(functions: Set[FunctionDecl], toStack: Boolean): Unit
def declareAndRecordAsFreshMacros(functions: Seq[MacroDecl], toStack: Boolean): Unit
def pushSymbolStack(): Unit
def popSymbolStack(): (Set[FunctionDecl], Seq[MacroDecl])
def setPcs(other: PathConditionStack): Unit

def statistics(): Map[String, String]
Expand All @@ -96,8 +100,11 @@ trait DefaultDeciderProvider extends VerifierComponent { this: Verifier =>
private var _prover: Prover = _
private var pathConditions: PathConditionStack = _

private var _freshFunctions: Set[FunctionDecl] = _ /* [BRANCH-PARALLELISATION] */
private var _freshMacros: Vector[MacroDecl] = _
private var _declaredFreshFunctions: Set[FunctionDecl] = _ /* [BRANCH-PARALLELISATION] */
private var _declaredFreshMacros: Vector[MacroDecl] = _

private var _freshFunctionStack: Stack[mutable.HashSet[FunctionDecl]] = _
private var _freshMacroStack: Stack[mutable.ListBuffer[MacroDecl]] = _

def prover: Prover = _prover

Expand Down Expand Up @@ -162,16 +169,20 @@ trait DefaultDeciderProvider extends VerifierComponent { this: Verifier =>

def start(): Unit = {
pathConditions = new LayeredPathConditionStack()
_freshFunctions = if (Verifier.config.parallelizeBranches()) HashSet.empty else InsertionOrderedSet.empty /* [BRANCH-PARALLELISATION] */
_freshMacros = Vector.empty
_declaredFreshFunctions = if (Verifier.config.parallelizeBranches()) HashSet.empty else InsertionOrderedSet.empty /* [BRANCH-PARALLELISATION] */
_declaredFreshMacros = Vector.empty
_freshMacroStack = Stack.empty
_freshFunctionStack = Stack.empty
createProver()
}

def reset(): Unit = {
_prover.reset()
pathConditions = new LayeredPathConditionStack()
_freshFunctions = if (Verifier.config.parallelizeBranches()) HashSet.empty else InsertionOrderedSet.empty /* [BRANCH-PARALLELISATION] */
_freshMacros = Vector.empty
_declaredFreshFunctions = if (Verifier.config.parallelizeBranches()) HashSet.empty else InsertionOrderedSet.empty /* [BRANCH-PARALLELISATION] */
_declaredFreshMacros = Vector.empty
_freshMacroStack = Stack.empty
_freshFunctionStack = Stack.empty
}

def stop(): Unit = {
Expand Down Expand Up @@ -209,23 +220,30 @@ trait DefaultDeciderProvider extends VerifierComponent { this: Verifier =>
assume(InsertionOrderedSet(Seq(t)), false)
}

override def assumeDefinition(t: Term): Unit =
assume(InsertionOrderedSet(Seq(t)), false, true)

def assume(terms: Iterable[Term]): Unit =
assume(InsertionOrderedSet(terms), false)

def assume(terms: InsertionOrderedSet[Term], enforceAssumption: Boolean = false): Unit = {
def assume(terms: InsertionOrderedSet[Term], enforceAssumption: Boolean = false, isDefinition: Boolean = false): Unit = {
val filteredTerms =
if (enforceAssumption) terms
else terms filterNot isKnownToBeTrue

if (filteredTerms.nonEmpty) assumeWithoutSmokeChecks(filteredTerms)
if (filteredTerms.nonEmpty) assumeWithoutSmokeChecks(filteredTerms, isDefinition)
}

private def assumeWithoutSmokeChecks(terms: InsertionOrderedSet[Term]) = {
private def assumeWithoutSmokeChecks(terms: InsertionOrderedSet[Term], isDefinition: Boolean = false) = {
val assumeRecord = new DeciderAssumeRecord(terms)
val sepIdentifier = symbExLog.openScope(assumeRecord)

/* Add terms to Silicon-managed path conditions */
terms foreach pathConditions.add
if (isDefinition) {
terms foreach pathConditions.addDefinition
} else {
terms foreach pathConditions.add
}

/* Add terms to the prover's assumptions */
terms foreach prover.assume
Expand Down Expand Up @@ -320,7 +338,8 @@ trait DefaultDeciderProvider extends VerifierComponent { this: Verifier =>

prover.declare(macroDecl)

_freshMacros = _freshMacros :+ macroDecl /* [BRANCH-PARALLELISATION] */
_declaredFreshMacros = _declaredFreshMacros :+ macroDecl /* [BRANCH-PARALLELISATION] */
_freshMacroStack.foreach(l => l.append(macroDecl))

macroDecl
}
Expand Down Expand Up @@ -356,26 +375,61 @@ trait DefaultDeciderProvider extends VerifierComponent { this: Verifier =>
HeapDepFun(proverFun.id, proverFun.argSorts, proverFun.resultSort).asInstanceOf[F]
}

_freshFunctions = _freshFunctions + FunctionDecl(fun) /* [BRANCH-PARALLELISATION] */
val decl = FunctionDecl(fun)
_declaredFreshFunctions = _declaredFreshFunctions + decl /* [BRANCH-PARALLELISATION] */
_freshFunctionStack.foreach(s => s.add(decl))

fun
}


/* [BRANCH-PARALLELISATION] */
def freshFunctions: Set[FunctionDecl] = _freshFunctions
def freshMacros: Vector[MacroDecl] = _freshMacros
def freshFunctions: Set[FunctionDecl] = _declaredFreshFunctions
def freshMacros: Vector[MacroDecl] = _declaredFreshMacros

def declareAndRecordAsFreshFunctions(functions: Set[FunctionDecl], toSymbolStack: Boolean): Unit = {
if (!toSymbolStack) {
functions foreach prover.declare

_declaredFreshFunctions = _declaredFreshFunctions ++ functions
} else {
for (f <- functions) {
if (!_declaredFreshFunctions.contains(f))
prover.declare(f)

_declaredFreshFunctions = _declaredFreshFunctions + f
_freshFunctionStack.foreach(s => s.add(f))
}
}
}

def declareAndRecordAsFreshMacros(macros: Seq[MacroDecl], toStack: Boolean): Unit = {
if (!toStack) {
macros foreach prover.declare

def declareAndRecordAsFreshFunctions(functions: Set[FunctionDecl]): Unit = {
functions foreach prover.declare
_declaredFreshMacros = _declaredFreshMacros ++ macros
} else {
for (m <- macros) {
if (!_declaredFreshMacros.contains(m))
prover.declare(m)

_freshFunctions = _freshFunctions ++ functions
_declaredFreshMacros = _declaredFreshMacros.appended(m)
_freshMacroStack.foreach(l => l.append(m))
}
}
}

def declareAndRecordAsFreshMacros(macros: Vector[MacroDecl]): Unit = {
macros foreach prover.declare
def pushSymbolStack(): Unit = {
_freshFunctionStack = _freshFunctionStack.prepended(mutable.HashSet())
_freshMacroStack = _freshMacroStack.prepended(mutable.ListBuffer())
}

_freshMacros = _freshMacros ++ macros
def popSymbolStack(): (Set[FunctionDecl], Seq[MacroDecl]) = {
val funcDecls = _freshFunctionStack.head.toSet
_freshFunctionStack = _freshFunctionStack.tail
val macroDecls = _freshMacroStack.head.toSeq
_freshMacroStack = _freshMacroStack.tail
(funcDecls, macroDecls)
}

/* Misc */
Expand Down
Loading

0 comments on commit 17005ae

Please sign in to comment.