Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ mod tests {
annotations: vec![],
});

let ast = ast_builder.build().expect("valid ast");
let mut ast = ast_builder.build().expect("valid ast");
let mut solver = Solver::default();
let mut context = CompilationContext::new(&mut solver);
let options = FlatZincOptions::default();

super::super::reserve_constraint_tags::run(&ast, &mut context)
super::super::reserve_constraint_tags::run(&mut ast, &mut context)
.expect("step should not fail");
super::super::prepare_variables::run(&ast, &mut context).expect("step should not fail");
run(&ast, &mut context, &options).expect("step should not fail");
Expand Down Expand Up @@ -320,15 +320,15 @@ mod tests {
annotations: vec![],
});

let ast = ast_builder.build().expect("valid ast");
let mut ast = ast_builder.build().expect("valid ast");
let mut solver = Solver::default();
let mut context = CompilationContext::new(&mut solver);
let options = FlatZincOptions {
proof_type: Some(ProofType::Full),
..Default::default()
};

super::super::reserve_constraint_tags::run(&ast, &mut context)
super::super::reserve_constraint_tags::run(&mut ast, &mut context)
.expect("step should not fail");
super::super::prepare_variables::run(&ast, &mut context).expect("step should not fail");
run(&ast, &mut context, &options).expect("step should not fail");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) fn compile(
let mut context = CompilationContext::new(solver);

define_constants::run(&ast, &mut context)?;
reserve_constraint_tags::run(&ast, &mut context)?;
reserve_constraint_tags::run(&mut ast, &mut context)?;
remove_unused_variables::run(&mut ast, &mut context)?;
prepare_variables::run(&ast, &mut context)?;
merge_equivalences::run(&ast, &mut context, &options)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn run(
) -> Result<(), FlatZincError> {
let mut marked_identifiers = BTreeSet::new();

mark_identifiers_in_constraints(ast, context, &mut marked_identifiers);
mark_identifiers_in_constraints(context, &mut marked_identifiers);
mark_identifiers_in_arrays(ast, context, &mut marked_identifiers);

// Make sure the objective, which can be unconstrained, is always marked.
Expand Down Expand Up @@ -110,16 +110,16 @@ fn mark_identifiers_in_arrays(
}
}

/// Go over all constraints and add any identifier in the arguments to the `marked_identifiers` set.
/// Go over all constraints in `context` and add any identifier in their arguments to the
/// `marked_identifiers` set.
fn mark_identifiers_in_constraints(
ast: &FlatZincAst,
context: &mut CompilationContext,
marked_identifiers: &mut BTreeSet<Rc<str>>,
) {
for expr in ast
.constraint_decls
for expr in context
.constraints
.iter()
.flat_map(|constraint| &constraint.exprs)
.flat_map(|(_, constraint)| &constraint.exprs)
{
match expr {
flatzinc::Expr::VarParIdentifier(id) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
//! necessary because adding a constraint can cause inferences to be introduced in the proof.
//! However, we assume that the first n constraint tags are the flatzinc constraints. Therefore,
//! the root-level inferences would throw off that mapping.
//!
//! The constraints are moved from the AST into the [`CompilationContext`], together with their
//! tags, so that only one copy of them is kept during the compilation.

use super::context::CompilationContext;
use crate::flatzinc::ast::FlatZincAst;
use crate::flatzinc::error::FlatZincError;

pub(crate) fn run(
ast: &FlatZincAst,
ast: &mut FlatZincAst,
context: &mut CompilationContext,
) -> Result<(), FlatZincError> {
for decl in &ast.constraint_decls {
for decl in std::mem::take(&mut ast.constraint_decls) {
let tag = context.solver.new_constraint_tag();
context.constraints.push((tag, decl.clone()));
context.constraints.push((tag, decl));
}

Ok(())
Expand Down
Loading