A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
ISLE: veri: error on `opt` RHS building ill-typed clif terms (#14608)
Alexa VanHattum774338bb9637
diff --git a/cranelift/codegen/src/prelude.isle b/cranelift/codegen/src/prelude.isleindex ee69d00921..9cd9509312 100644--- a/cranelift/codegen/src/prelude.isle+++ b/cranelift/codegen/src/prelude.isle@@ -16,7 +16,7 @@(model Type (type (struct (bits Int))))(type Type (primitive Type))-(model Value (type (bv)))+(model Value (type (bv (8 16 32 64))))(type Value (primitive Value))(type ValueList (primitive ValueList))diff --git a/cranelift/codegen/src/prelude_opt.isle b/cranelift/codegen/src/prelude_opt.isleindex 744bbfb7af..e76d27f368 100644--- a/cranelift/codegen/src/prelude_opt.isle+++ b/cranelift/codegen/src/prelude_opt.isle@@ -243,13 +243,15 @@(decl uextend_maybe (Type Value) Value)(extractor (uextend_maybe ty val) (uextend_maybe_etor ty val))(rule 0 (uextend_maybe ty val) (uextend ty val))-(rule 1 (uextend_maybe ty val@(value_type ty)) val)+(attr rule uextend_maybe_same_type (veri priority))+(rule uextend_maybe_same_type 1 (uextend_maybe ty val@(value_type ty)) val);; Same as `uextend_maybe` above, just for `sextend`.(decl sextend_maybe (Type Value) Value)(extractor (sextend_maybe ty val) (sextend_maybe_etor ty val))(rule 0 (sextend_maybe ty val) (sextend ty val))-(rule 1 (sextend_maybe ty val@(value_type ty)) val)+(attr rule sextend_maybe_same_type (veri priority))+(rule sextend_maybe_same_type 1 (sextend_maybe ty val@(value_type ty)) val);;;;;; Helper CLIF Extractors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;diff --git a/cranelift/codegen/src/spec/inst_specs.isle b/cranelift/codegen/src/spec/inst_specs.isleindex 7eb9469a8e..66d1ffac2c 100644--- a/cranelift/codegen/src/spec/inst_specs.isle+++ b/cranelift/codegen/src/spec/inst_specs.isle@@ -461,6 +461,7 @@((args (named Type) (bv 64)) (ret (bv 64))))(spec (ireduce ty x)+ (require (< (:bits ty) (widthof x)))(provide (= result (conv_to (widthof result) x))(= (:bits ty) (widthof result))))(instantiate ireduce@@ -482,11 +483,13 @@;; (8->8, 16->16, 32->32, 64->64) are not accepted in clif.(spec (uextend ty x)+ (require (< (widthof x) (:bits ty)))(provide (= result (zero_ext (widthof result) x))(= (:bits ty) (widthof result))))(instantiate uextend extend)(spec (sextend ty x)+ (require (< (widthof x) (:bits ty)))(provide (= result (sign_ext (widthof result) x))(= (:bits ty) (widthof result))))(instantiate sextend extend)diff --git a/cranelift/codegen/src/spec/opt.isle b/cranelift/codegen/src/spec/opt.isleindex a525505f12..2c544b16b6 100644--- a/cranelift/codegen/src/spec/opt.isle+++ b/cranelift/codegen/src/spec/opt.isle@@ -174,6 +174,22 @@((args (named Type) (bv 32)) (ret (bv 64)))((args (named Type) (bv 64)) (ret (bv 64))))+;; Same as `uextend_maybe` but with sign extension.+(spec (sextend_maybe ty val)+ (provide (= result (sign_ext (widthof result) val))+ (= (:bits ty) (widthof result))))+(instantiate sextend_maybe+ ((args (named Type) (bv 8)) (ret (bv 8)))+ ((args (named Type) (bv 8)) (ret (bv 16)))+ ((args (named Type) (bv 8)) (ret (bv 32)))+ ((args (named Type) (bv 8)) (ret (bv 64)))+ ((args (named Type) (bv 16)) (ret (bv 16)))+ ((args (named Type) (bv 16)) (ret (bv 32)))+ ((args (named Type) (bv 16)) (ret (bv 64)))+ ((args (named Type) (bv 32)) (ret (bv 32)))+ ((args (named Type) (bv 32)) (ret (bv 64)))+ ((args (named Type) (bv 64)) (ret (bv 64))))+(attr splat (tag vector));;;; Concrete `f32`/`f64` sign bit-ops ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;@@ -475,7 +491,8 @@;; Partial: bit width (8/16/32) -> that integer type.(spec (shift_amt_to_type v)(match (or (= v (int2bv 64 8)) (= v (int2bv 64 16)) (= v (int2bv 64 32))))- (provide (= (int2bv 64 (:bits result)) v)))+ (provide (= (:bits result)+ (if (= v (int2bv 64 8)) 8 (if (= v (int2bv 64 16)) 16 32)))));;;; `imm64_*` min/max/shift folding ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 64-bit `Imm64`, masked to the low `ty` bits. Signed ops sign-extend those bitsdiff --git a/cranelift/isle/isle/src/ast.rs b/cranelift/isle/isle/src/ast.rsindex b08edfbb1a..1642c7ef86 100644--- a/cranelift/isle/isle/src/ast.rs+++ b/cranelift/isle/isle/src/ast.rs@@ -492,6 +492,8 @@ pub enum ModelType {Unit,/// SMT-LIB bitvector, but with a potentially-polymorphic widthBitVec(Option<usize>),+ /// SMT-LIB bitvector whose width is one of the given widths.+ BitVecOneOf(Vec<usize>),/// Structured type.Struct(Vec<ModelField>),/// Same model as the named type.diff --git a/cranelift/isle/isle/src/parser.rs b/cranelift/isle/isle/src/parser.rsindex bc161317cd..89e85c1496 100644--- a/cranelift/isle/isle/src/parser.rs+++ b/cranelift/isle/isle/src/parser.rs@@ -857,6 +857,22 @@ impl<'a> Parser<'a> {} else if self.is_lparen() {self.expect_lparen()?;if self.eat_sym_str("bv")? {+ // (bv (w1 w2 ...))+ if self.is_lparen() {+ self.expect_lparen()?;+ let mut widths = Vec::new();+ while !self.is_rparen() {+ widths.push(usize::try_from(self.expect_int()?).map_err(|err| {+ self.error(pos, format!("Invalid BitVector width: {err}"))+ })?);+ }+ self.expect_rparen()?;+ self.expect_rparen()?;+ if widths.is_empty() {+ return Err(self.error(pos, "Empty BitVector width set".to_string()));+ }+ return Ok(ModelType::BitVecOneOf(widths));+ }let width = if self.is_rparen() {None} else if self.is_int() {diff --git a/cranelift/isle/isle/src/printer.rs b/cranelift/isle/isle/src/printer.rsindex dc9650577d..d4b1c1ee35 100644--- a/cranelift/isle/isle/src/printer.rs+++ b/cranelift/isle/isle/src/printer.rs@@ -509,6 +509,10 @@ impl ToSExpr for ModelType {SExpr::List(vec![SExpr::atom("bv"), SExpr::atom(size)])}ModelType::BitVec(None) => SExpr::List(vec![SExpr::atom("bv")]),+ ModelType::BitVecOneOf(widths) => SExpr::List(vec![+ SExpr::atom("bv"),+ SExpr::List(widths.iter().map(SExpr::atom).collect()),+ ]),ModelType::Struct(fields) => {let mut parts = vec![SExpr::atom("struct")];parts.extend(fields.iter().map(ToSExpr::to_sexpr));diff --git a/cranelift/isle/veri/veri/src/debug.rs b/cranelift/isle/veri/veri/src/debug.rsindex 8e3c7eb501..c4b2e99024 100644--- a/cranelift/isle/veri/veri/src/debug.rs+++ b/cranelift/isle/veri/veri/src/debug.rs@@ -296,6 +296,7 @@ pub fn constrain_string(constrain: &Constrain, tyenv: &TypeEnv) -> String {binding_id.index(),constraint_string(constraint, tyenv)),+ Constrain::Equal(a, b) => format!("{} == {}", a.index(), b.index()),Constrain::NotAll(constraints) => {format!("not_all({constraints})",diff --git a/cranelift/isle/veri/veri/src/expand.rs b/cranelift/isle/veri/veri/src/expand.rsindex 3dbc0ff567..6dfb820b62 100644--- a/cranelift/isle/veri/veri/src/expand.rs+++ b/cranelift/isle/veri/veri/src/expand.rs@@ -10,6 +10,7 @@ use std::collections::{HashMap, HashSet};#[derive(Debug, Clone)]pub enum Constrain {Match(BindingId, Constraint),+ Equal(BindingId, BindingId),NotAll(Vec<Constrain>),}@@ -17,6 +18,7 @@ impl Constrain {fn bindings(&self) -> Vec<BindingId> {match self {Constrain::Match(binding_id, _) => vec![*binding_id],+ Constrain::Equal(a, b) => vec![*a, *b],Constrain::NotAll(constrains) => constrains.iter().flat_map(|c| c.bindings()).collect(),}}@@ -26,6 +28,7 @@ impl Constrain {Constrain::Match(binding_id, constraint) => {Constrain::Match(reindex.id(*binding_id), *constraint)}+ Constrain::Equal(a, b) => Constrain::Equal(reindex.id(*a), reindex.id(*b)),Constrain::NotAll(constrains) => {Constrain::NotAll(constrains.iter().map(|c| c.substitute(reindex)).collect())}@@ -66,8 +69,8 @@ impl Expansion {return false;}}- Constrain::NotAll(_) => {- // Conservatively assume negated constraints can be met.+ Constrain::Equal(..) | Constrain::NotAll(_) => {+ // Conservatively assume these can be met.continue;}}@@ -782,10 +785,20 @@ impl Application {}}+ // Collect the equalities required.+ for i in 0..rule_set.bindings.len() {+ let binding_id = i.try_into().unwrap();+ if let Some(equal_binding_id) = rule.equals.find(binding_id)+ && equal_binding_id != binding_id+ {+ let a = self.add_binding(rule_set, binding_id);+ let b = self.add_binding(rule_set, equal_binding_id);+ constraints.push(Constrain::Equal(a, b));+ }+ }+// Require their negation.self.expansion.constrain(Constrain::NotAll(constraints));-- // TODO(mbm): negation of equality constraints}fn add_binding(&mut self, rule_set: &RuleSet, binding_id: BindingId) -> BindingId {diff --git a/cranelift/isle/veri/veri/src/runner.rs b/cranelift/isle/veri/veri/src/runner.rsindex fb17e5ce4c..0b0caf93d6 100644--- a/cranelift/isle/veri/veri/src/runner.rs+++ b/cranelift/isle/veri/veri/src/runner.rs@@ -453,6 +453,7 @@ pub struct RunSummary {/// instantiation, so no query reached the solver. Only populated under/// `--debug`, and only reported when populated.pub no_instantiations: Option<usize>,+ pub expansion_errors: usize,pub spec_conflicts: usize,pub applicable: usize,pub success: usize,@@ -468,6 +469,7 @@ impl RunSummary {if let Some(no_instantiations) = self.no_instantiations {println!("No instantiations: {no_instantiations}");}+ println!("Expansion errors: {}", self.expansion_errors);println!("Type instantiations: {}", self.total_instantiations);println!("Applicable: {}", self.applicable);println!("Verification passed: {}", self.success);@@ -851,7 +853,6 @@ impl Runner {description = failure.description,inst = failure.instantiation_index,);- eprintln!("model:");eprint!("{counterexample}");printed += 1;}@@ -981,6 +982,7 @@ impl Runner {total_expansions,in_scope,no_instantiations,+ expansion_errors: errors.len(),spec_conflicts,..Default::default()};@@ -1233,6 +1235,9 @@ impl Runner {Choice::TermInstantiation(term_id, sig) => {format!("{term}{sig}", term = self.prog.term_name(*term_id))}+ Choice::BitVectorWidth(x, width) => {+ format!("width(e{x}) = {width}", x = x.index())+ }};writeln!(output, "\t{choice}")?;choices.push(choice);@@ -1430,8 +1435,16 @@ impl Runner {};// Verify.+ let ill_typed = solver.ill_typed().to_vec();+ for (x, reason) in &ill_typed {+ writeln!(output, "\t\till-typed: e{x}: {reason}", x = x.index())?;+ }let start = time::Instant::now();- let verification = solver.check_verification_condition()?;+ let verification = if ill_typed.is_empty() {+ solver.check_verification_condition()?+ } else {+ solver.check_assumptions_unreachable()?+ };let verify_time = Some(start.elapsed());writeln!(output, "\t\tverification = {verification}")?;@@ -1441,6 +1454,19 @@ impl Runner {conditions.write_model(&mut rendered, &model, &self.prog)?;let rendered = String::from_utf8(rendered)?;+ let mut notes = String::new();+ for (x, reason) in &ill_typed {+ let position = conditions+ .pos+ .get(x)+ .map(|pos| pos.pretty_print_line(&self.prog.files))+ .unwrap_or_else(|| "?".to_string());+ notes.push_str(&format!(+ "ill-typed term reachable: {position}: e{x}: {reason}\n",+ x = x.index()+ ));+ }+let failure_path = log_dir.join("failure.out");let mut failure_file = Self::open_log_file(log_dir.clone(), "failure.out")?;writeln!(@@ -1449,8 +1475,8 @@ impl Runner {)?;writeln!(failure_file, "expansion:")?;write_expansion(&mut failure_file, &self.prog, expansion)?;- writeln!(failure_file, "model:")?;- write!(failure_file, "{rendered}")?;+ let counterexample = format!("{notes}model:\n{rendered}");+ write!(failure_file, "{counterexample}")?;writeln!(output, "\t\tfailure written to {}", failure_path.display())?;log::warn!(@@ -1464,7 +1490,7 @@ impl Runner {description: description.to_string(),instantiation_index,failure_path,- counterexample: self.print_counterexample.then_some(rendered),+ counterexample: self.print_counterexample.then_some(counterexample),});VerifyReport {diff --git a/cranelift/isle/veri/veri/src/solver.rs b/cranelift/isle/veri/veri/src/solver.rsindex c29bb4eeff..759b5b292d 100644--- a/cranelift/isle/veri/veri/src/solver.rs+++ b/cranelift/isle/veri/veri/src/solver.rs@@ -1,6 +1,6 @@use std::{cmp::Ordering, collections::HashSet, iter::zip};-use anyhow::{Context as _, Error, Result, bail, format_err};+use anyhow::{Context as _, Error, Result, bail};use cranelift_isle_veri_caching::{Context, Response, SExpr, SExprData};use num_bigint::BigUint;use num_traits::Num as _;@@ -75,6 +75,18 @@ pub enum Dialect {Z3,}+/// Expression not valid at its inferred widths.+#[derive(Debug)]+struct IllTypedWidth(&'static str);++impl std::fmt::Display for IllTypedWidth {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.write_str(self.0)+ }+}++impl std::error::Error for IllTypedWidth {}+pub struct Solver<'a> {smt: Context,dialect: Dialect,@@ -86,6 +98,9 @@ pub struct Solver<'a> {/// Widths for which the deterministic `fp.sqrt` uninterpreted function has/// already been declared (see [`Solver::fp_sqrt`]).sqrt_uf_widths: HashSet<usize>,++ /// Ill-typed expressions, left unconstrained.+ ill_typed: Vec<(ExprId, String)>,}impl Drop for Solver<'_> {@@ -110,6 +125,7 @@ impl<'a> Solver<'a> {assignment,tmp_idx: 0,sqrt_uf_widths: HashSet::new(),+ ill_typed: Vec::new(),};solver.prelude()?;Ok(solver)@@ -164,6 +180,29 @@ impl<'a> Solver<'a> {Ok(verdict)}+ /// Expressions ill-typed under this type instantiation.+ pub fn ill_typed(&self) -> &[(ExprId, String)] {+ &self.ill_typed+ }++ /// Check the assumptions are unsatisfiable, with a model if not.+ pub fn check_assumptions_unreachable(&mut self) -> Result<Verification> {+ self.smt.push()?;++ let assumptions = self.all(&self.conditions.assumptions);+ self.smt.assert(assumptions)?;++ let verdict = match self.check()? {+ Response::Sat => Verification::Failure(self.model()?),+ Response::Unsat => Verification::Success,+ Response::Unknown => Verification::Unknown,+ };++ self.smt.pop()?;++ Ok(verdict)+ }+pub fn check_verification_condition(&mut self) -> Result<Verification> {// Enter solver context frame.self.smt.push()?;@@ -262,9 +301,16 @@ impl<'a> Solver<'a> {fn assign_expr(&mut self, x: ExprId, expr: &Expr) -> Result<()> {let lhs = self.smt.atom(self.expr_name(x));- let rhs = self- .expr_to_smt(expr)- .map_err(|err| self.error(x, err.to_string()))?;+ let rhs = match self.expr_to_smt(expr) {+ Ok(rhs) => rhs,+ Err(err) => {+ if let Some(ill_typed) = err.downcast_ref::<IllTypedWidth>() {+ self.ill_typed.push((x, ill_typed.to_string()));+ return Ok(());+ }+ return Err(self.error(x, err.to_string()));+ }+ };Ok(self.smt.assert(self.smt.named(format!("expr{}", x.index()), self.smt.eq(lhs, rhs)),@@ -488,7 +534,7 @@ impl<'a> Solver<'a> {// Build zero_extend expression.let padding = dst.checked_sub(src)- .ok_or(format_err!("cannot zero extend to smaller width"))?;+ .ok_or(IllTypedWidth("cannot zero extend to smaller width"))?;Ok(self.zero_extend(padding, self.expr_atom(x)))}@@ -512,7 +558,7 @@ impl<'a> Solver<'a> {// Build sign_extend expression.let padding = dst.checked_sub(src)- .ok_or(format_err!("cannot sign extend to smaller width"))?;+ .ok_or(IllTypedWidth("cannot sign extend to smaller width"))?;Ok(self.sign_extend(padding, self.expr_atom(x)))}diff --git a/cranelift/isle/veri/veri/src/spec.rs b/cranelift/isle/veri/veri/src/spec.rsindex 195756884d..6b29146118 100644--- a/cranelift/isle/veri/veri/src/spec.rs+++ b/cranelift/isle/veri/veri/src/spec.rs@@ -625,6 +625,8 @@ pub struct SpecEnv {/// Model for the given type.pub type_model: HashMap<TypeId, Compound>,+ /// Widths from `(bv (w1 w2 ...))` models.+ pub type_model_widths: HashMap<TypeId, Vec<usize>>,/// Value for the given constant.pub const_value: HashMap<Sym, Expr>,@@ -645,6 +647,7 @@ impl SpecEnv {priority: HashSet::new(),rule_tags: HashMap::new(),type_model: HashMap::new(),+ type_model_widths: HashMap::new(),const_value: HashMap::new(),macros: HashMap::new(),};@@ -755,6 +758,9 @@ impl SpecEnv {);self.type_model.insert(type_id, Compound::from_ast(model_type));+ if let ModelType::BitVecOneOf(widths) = model_type {+ self.type_model_widths.insert(type_id, widths.clone());+ }}fn collect_state(&mut self, defs: &[Def]) -> Result<()> {@@ -919,7 +925,8 @@ impl SpecEnv {) -> Result<()> {for (term_id, spec) in &self.term_spec {let term = &termenv.terms[term_id.index()];- if !Self::term_returns_option(term, tyenv) {+ // An extractor's requires are assumed, so only constructors apply.+ if !term.has_constructor() || !Self::term_returns_option(term, tyenv) {continue;}if !spec.requires.is_empty() {diff --git a/cranelift/isle/veri/veri/src/type_inference.rs b/cranelift/isle/veri/veri/src/type_inference.rsindex e22c72e256..0b38467029 100644--- a/cranelift/isle/veri/veri/src/type_inference.rs+++ b/cranelift/isle/veri/veri/src/type_inference.rs@@ -135,6 +135,8 @@ impl std::fmt::Display for Constraint {#[derive(Clone)]pub enum Choice {TermInstantiation(TermId, Signature),+ /// Width chosen from a declared width set.+ BitVectorWidth(ExprId, usize),}impl std::fmt::Display for Choice {@@ -143,6 +145,9 @@ impl std::fmt::Display for Choice {Choice::TermInstantiation(term_id, sig) => {write!(f, "term_instantiation({}, {sig})", term_id.index())}+ Choice::BitVectorWidth(x, width) => {+ write!(f, "bit_vector_width({}, {width})", x.index())+ }}}}@@ -163,6 +168,7 @@ pub struct System {choices: Vec<Choice>,constraints: Vec<Constraint>,branches: Vec<Branch>,+ width_domains: Vec<(ExprId, Vec<usize>)>,}impl System {@@ -185,6 +191,7 @@ impl System {constraints,choices,branches: branches.clone(),+ width_domains: self.width_domains.clone(),})}@@ -272,6 +279,8 @@ impl<'a> SystemBuilder<'a> {self.qualifier(qualifier);}+ self.system.width_domains = self.conditions.width_domains.clone();+self.system}@@ -929,6 +938,33 @@ impl Solver {// Done?if system.branches.is_empty() {+ // Branch over the declared widths of an undetermined bit-vector.+ let undetermined = system+ .width_domains+ .iter()+ .find(|(x, _)| self.assignment.bit_vector_width(*x).is_none());+ if let Some((x, widths)) = undetermined {+ let x = *x;+ let mut solutions = Vec::new();+ for &width in widths {+ let mut choices = system.choices.clone();+ choices.push(Choice::BitVectorWidth(x, width));+ let mut constraints = system.constraints.clone();+ constraints.push(Constraint::Type {+ x,+ ty: Type::BitVector(Width::Bits(width)),+ });+ let child = System {+ choices,+ constraints,+ branches: Vec::new(),+ width_domains: system.width_domains.clone(),+ };+ solutions.extend(self.clone().solve(&child));+ }+ return solutions;+ }+let status = if self.assignment.is_concrete() {Status::Solved} else {diff --git a/cranelift/isle/veri/veri/src/types.rs b/cranelift/isle/veri/veri/src/types.rsindex 3cb34a3df4..059e790785 100644--- a/cranelift/isle/veri/veri/src/types.rs+++ b/cranelift/isle/veri/veri/src/types.rs@@ -292,7 +292,9 @@ impl Compound {ModelType::Int => Self::Primitive(Type::Int),ModelType::Bool => Self::Primitive(Type::Bool),ModelType::Unit => Self::Primitive(Type::Unit),- ModelType::BitVec(None) => Self::Primitive(Type::BitVector(Width::Unknown)),+ ModelType::BitVec(None) | ModelType::BitVecOneOf(_) => {+ Self::Primitive(Type::BitVector(Width::Unknown))+ }ModelType::BitVec(Some(bits)) => Self::Primitive(Type::BitVector(Width::Bits(*bits))),ModelType::Struct(fields) => Self::Struct(fieldsdiff --git a/cranelift/isle/veri/veri/src/veri.rs b/cranelift/isle/veri/veri/src/veri.rsindex ecd6e55979..548289ab9d 100644--- a/cranelift/isle/veri/veri/src/veri.rs+++ b/cranelift/isle/veri/veri/src/veri.rs@@ -774,6 +774,7 @@ pub struct Conditions {pub calls: Vec<Call>,pub qualifiers: Vec<Qualifier>,pub pos: HashMap<ExprId, Pos>,+ pub width_domains: Vec<(ExprId, Vec<usize>)>,}impl Conditions {@@ -1440,11 +1441,13 @@ impl<'a> ConditionsBuilder<'a> {vars.set(name.0.clone(), (*input).clone())?;}- // Requires.+ // Requires. An extractor's are assumed with the provides below.let mut requires: Vec<ExprId> = Vec::new();- for require in &term_spec.requires {- let require = self.spec_expr(require, &vars)?;- requires.push(self.as_scalar(require)?);+ if kind == TermKind::Constructor {+ for require in &term_spec.requires {+ let require = self.spec_expr(require, &vars)?;+ requires.push(self.as_scalar(require)?);+ }}// Matches.@@ -1466,6 +1469,14 @@ impl<'a> ConditionsBuilder<'a> {provides.push(self.as_scalar(provide)?);}+ // An extractor's requires hold of the matched term.+ if kind == TermKind::Extractor {+ for require in &term_spec.requires {+ let require = self.spec_expr(require, &vars)?;+ provides.push(self.as_scalar(require)?);+ }+ }+// Partial function.// REVIEW(mbm): pin down semantics for partial function specifications.if let Domain::Partial(p) = domain {@@ -1494,8 +1505,9 @@ impl<'a> ConditionsBuilder<'a> {}}- // Record callsite.- self.record_term_instantiation(term, args.to_vec(), ret)?;+ // Record callsite. Instantiations do not constrain constructor/RHS terms.+ let rhs = kind == TermKind::Constructor && matches!(invocation, Invocation::Caller);+ self.record_term_instantiation(term, args.to_vec(), ret, !rhs)?;Ok(())}@@ -1505,12 +1517,17 @@ impl<'a> ConditionsBuilder<'a> {term: TermId,args: Vec<Symbolic>,ret: Symbolic,+ use_instantiations: bool,) -> Result<()> {- let signatures = self.prog.specenv.resolve_term_instantiations(- &term,- &self.prog.tyenv,- self.excluded_tags,- )?;+ let signatures = if use_instantiations {+ self.prog.specenv.resolve_term_instantiations(+ &term,+ &self.prog.tyenv,+ self.excluded_tags,+ )?+ } else {+ Vec::new()+ };self.conditions.calls.push(Call {term,args,@@ -1741,6 +1758,7 @@ impl<'a> ConditionsBuilder<'a> {fn constrain(&mut self, constrain: &Constrain) -> Result<ExprId> {match constrain {Constrain::Match(binding_id, constraint) => self.constraint(*binding_id, constraint),+ Constrain::Equal(a, b) => self.bindings_equal(*a, *b),Constrain::NotAll(constrains) => {let cs = constrains.iter()@@ -2536,7 +2554,7 @@ impl<'a> ConditionsBuilder<'a> {for variant in &e.variants {let term = self.prog.get_variant_term(e.ty, variant.id);let args = variant.field_values()?;- self.record_term_instantiation(term, args, ret.clone())?;+ self.record_term_instantiation(term, args, ret.clone(), true)?;}Ok(ret)@@ -2570,7 +2588,14 @@ impl<'a> ConditionsBuilder<'a> {some width, or an enum listing its variants) so the verifier can allocate a \symbolic value for it.")))?;- self.alloc_value(ty, name)+ let value = self.alloc_value(ty, name)?;++ if let Some(widths) = self.prog.specenv.type_model_widths.get(&type_id) {+ let x = self.as_scalar(value.clone())?;+ self.conditions.width_domains.push((x, widths.clone()));+ }++ Ok(value)}fn undef_variable(&mut self) -> ExprId {