Skip to content

Commit

Permalink
Do not lit-wrap if we can not profit from it
Browse files Browse the repository at this point in the history
  • Loading branch information
ole-thoeb committed Jan 3, 2025
1 parent 631b728 commit f944bea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/ast/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,15 @@ pub struct DomainDecl {
pub span: Span,
}

impl DomainDecl {
pub fn function_decls(&self) -> impl Iterator<Item = &DeclRef<FuncDecl>> {
self.body.iter().filter_map(|spec| match spec {
DomainSpec::Function(func_ref) => Some(func_ref),
_ => None,
})
}
}

impl SimplePretty for DomainDecl {
fn pretty(&self) -> Doc {
Doc::text("domain")
Expand Down
6 changes: 6 additions & 0 deletions src/smt/limited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ pub fn return_value_invariant<'smt, 'ctx>(
axiom
}

/// Returns true if the [FuncDecl] can be transformed into a limited function.
/// Use [SmtCtx::is_limited_function_decl] to check if the transformation should actually be applied.
pub fn is_eligible_for_limited_function(func: &FuncDecl) -> bool {
func.body.borrow().is_some()
}

type HashExpr = PointerHashShared<ExprData>;

#[derive(Default, Clone)]
Expand Down
16 changes: 12 additions & 4 deletions src/smt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use self::{translate_exprs::TranslateExprs, uninterpreted::Uninterpreteds};
use crate::ast::{DeclKind, FuncDecl};
use crate::smt::limited::{
build_func_domain, computation_axiom, defining_axiom, fuel_synonym_axiom,
return_value_invariant,
is_eligible_for_limited_function, return_value_invariant,
};
use crate::{
ast::{DeclRef, DomainDecl, DomainSpec, Ident, TyKind},
Expand Down Expand Up @@ -48,6 +48,15 @@ pub struct SmtCtx<'ctx> {

impl<'ctx> SmtCtx<'ctx> {
pub fn new(ctx: &'ctx Context, tcx: &'ctx TyCtx, options: SmtCtxOptions) -> Self {
let domains: Vec<_> = tcx.domains_owned();
// disable lit-wrapping if there are no limited functions that can profit from it
let lit_wrap = options.lit_wrap
&& options.use_limited_functions
&& domains.iter().any(|d| {
d.borrow()
.function_decls()
.any(|func| is_eligible_for_limited_function(&func.borrow()))
});
let mut res = SmtCtx {
ctx,
tcx,
Expand All @@ -57,9 +66,8 @@ impl<'ctx> SmtCtx<'ctx> {
lits: RefCell::new(Vec::new()),
uninterpreteds: Uninterpreteds::new(ctx),
use_limited_functions: options.use_limited_functions,
lit_wrap: options.lit_wrap,
lit_wrap,
};
let domains: Vec<_> = tcx.domains_owned();
res.declare_domains(domains.as_slice());
res
}
Expand Down Expand Up @@ -204,7 +212,7 @@ impl<'ctx> SmtCtx<'ctx> {
}

pub fn is_limited_function_decl(&self, func: &FuncDecl) -> bool {
self.use_limited_functions && func.body.borrow().is_some()
self.use_limited_functions && is_eligible_for_limited_function(func)
}

pub fn functions_with_def(&self) -> Vec<Ident> {
Expand Down

0 comments on commit f944bea

Please sign in to comment.