Skip to content

Carbon implementation of new backend-independent counterexample format#574

Open
marcoeilers wants to merge 11 commits into
masterfrom
meilers_raoul_counterexamples
Open

Carbon implementation of new backend-independent counterexample format#574
marcoeilers wants to merge 11 commits into
masterfrom
meilers_raoul_counterexamples

Conversation

@marcoeilers

Copy link
Copy Markdown
Contributor

Carbon implementation of the new backend-independent counterexample format (see viperproject/silver#883), written by @rvandoren in his practical work project.

@marcoeilers
marcoeilers marked this pull request as ready for review July 15, 2026 22:32
// The "weak" hash map is necessary to avoid leaking memory.
// See issue https://github.com/viperproject/carbon/issues/444
val mapping = mutable.WeakHashMap[VerificationError, Member]()
val mapping = mutable.HashMap[String, Member]()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust comment or revert change

@@ -0,0 +1,1207 @@
package viper.carbon.boogie

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add header


/**
* Transforms a counterexample returned by Boogie back to a Viper counterexample. The programmer can choose between an
* "intermediate" CE or an "extended" CE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust old names in comments throughout

/**
* Chooses the latest instance of a variable in the counterexample model received from the SMT solver.
*/
def transformModelEntries(originalEntries: Map[String, ModelEntry], namesInMember: Map[String, String]): mutable.Map[String, ModelEntry] = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should no longer be needed

newEntries
}

def isLaterVersion(firstName: String, originalName: String, secondName: String): Boolean = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should no longer be needed

*/
def decodeBoxedValue(v: String, model: Model): String = {
if (!v.startsWith("T@U!")) return v
for (fn <- Seq("U_2_int", "U_2_bool")) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this specific to int and bool?

* Match heap resources to their ast node and translate all identifiers (for fields and references)
*/
def detHeap(opMapping: Map[Seq[String], String], basicHeap: RawHeap, program: Program, collections: Seq[CECollection], translNames: Map[String, String], model: Model): HeapCounterexample = {
// choosing all the needed values from the Boogie Model

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment

type WandShape = Func
//This needs to be resettable, which is why "lazy val" is not used. See also: wandToShapes method
private var lazyWandToShapes: Option[Map[MagicWandStructure.MagicWandStructure, WandShape]] = None
/* private */ var lazyWandToShapes: Option[Map[MagicWandStructure.MagicWandStructure, WandShape]] = None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary?

capturedStates = collection.mutable.LinkedHashMap.empty
case "*** END_MODEL" if parsingModel.isDefined =>
if (capturedStates != null && capturedStates.nonEmpty) {
// The captured states are sparse (each lists only the variables whose current

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me that we want to do that, check.

// 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-2025 ETH Zurich.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant