Skip to content

Conversation

@maditaP
Copy link

@maditaP maditaP commented Oct 30, 2025

This adds a command (get-pre-models) to check whether there are non-trivial models for the preexpectations. For coprocs, this means models where the pre evaluates to < infinity, and for procs, models where the pre evaluates to > 0.
The implementation is very similar to that of the verify command.

Copy link
Collaborator

@Philipp15b Philipp15b left a comment

Choose a reason for hiding this comment

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

I think this looks great! I have a bunch of (mostly) minor comments.

pub fn from_source_unit(
mut source_unit: SourceUnit,
depgraph: &mut DepGraph,
is_get_model_task: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This anonymous boolean flag is definitely problematic. Especially because it changes the whole interpretation and guarantees about this object. I recommend:

  • Renaming this struct to something like CoreHeyvlTask (and renaming the file and variable names accordingly)
  • Having two separate constructors for this object; one is basically the old from_source_unit (maybe called from_proc_verify), the other would be smth like from_proc_pre_model).
  • Possibly refactor a bit so that the common code is in common functions (esp. the bit about depgraphs).

Ok(result.prove_result)
}

pub fn run_smt_check_sat<'tcx>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

A short comment would be great.

.local_scope()
.add_assumptions_to_prover(&mut prover);

// Add the verification condition
Copy link
Collaborator

Choose a reason for hiding this comment

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

A short comment explaining that the verification condition is intentionally added as an assumption instead of an assertion as usually done for verification would be great.

slicing::{wrap_with_error_message, wrap_with_success_message},
};

/// Encode the preexpectations as a formula for which a model is a nontrivial bound
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dot at end of sentence, and empty line afterward :)

};
let mut block = Spanned::new(body.span, vec![]);

fn get_combination(direction: Direction) -> ast::expr::BinOpKind {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Import BinOpKind normally

}

// connect the preexpectations through the correct operator
let mut build_expr = proc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just use a reduce? That seems much simpler and less error-prone

// Unfolding (applies substitutions)
quant_task.unfold(options, &limits_ref, &tcx)?;

// TODO: How to deal with inf/sup quantifier?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess if the SMT encoder is properly used, then sup/inf will be correctly encoded. Most likely the SMT solver would fail to terminate though.


// Turn quantitative formula into a Boolean one
let builder = ExprBuilder::new(Span::dummy_span());
let top = builder.top_lit(quant_task.expr.ty.as_ref().unwrap());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move the top/bot assignments into the branches below?

}
};

// Create a Boolean verification task with the comparison
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a BoolVcProveTask was intended to be used only in the context of verification (i.e. vc == top/bot), but the operations should be sound here as well, because they're all equivalence transformations (I think).

Please make a note of this in the PR description, I'll refactor that at some point :)

Lsp(VerifyCommand),
/// Generate shell completions for the Caesar binary.
ShellCompletions(ShellCompletionsCommand),
/// Get non-trivial models for preexpectation.
Copy link
Collaborator

@Philipp15b Philipp15b Oct 31, 2025

Choose a reason for hiding this comment

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

"Compute a non-trivial model for the preconditions of each (co)proc."

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.

2 participants