Skip to content

Commit

Permalink
refactor(ast)!: add top level expression type Expr::Root
Browse files Browse the repository at this point in the history
Add `Expr::Root`, and use this to store top-level constraints in `Model`
(instead of the current `Vec<Expr>`).

Among other things, this allows partial evaluation of the top level of
the model again. For more details, see the RFC:
#596.

Closes: #596
  • Loading branch information
niklasdewally committed Feb 4, 2025
1 parent aa369f1 commit 59aa5fb
Show file tree
Hide file tree
Showing 204 changed files with 26,886 additions and 14,987 deletions.
4 changes: 2 additions & 2 deletions conjure_oxide/examples/solver-hello-minion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn main() {
let model = get_example_model("div-05").unwrap();
println!(
"Input model: \n {} \n",
pretty_expressions_as_top_level(&model.constraints)
pretty_expressions_as_top_level(&model.get_constraints_vec())
);

// TODO: We will have a nicer way to do this in the future
Expand All @@ -36,7 +36,7 @@ pub fn main() {
let model = rewrite_model(&model, &rule_sets).unwrap();
println!(
"Rewritten model: \n {} \n",
pretty_expressions_as_top_level(&model.constraints)
pretty_expressions_as_top_level(&model.get_constraints_vec())
);

// To tell the `Solver` type what solver to use, you pass it a `SolverAdaptor`.
Expand Down
2 changes: 1 addition & 1 deletion conjure_oxide/src/utils/essence_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn parse_essence_file_native(
constraint_vec.push(parse_constraint(constraint, &source_code));
}
}
model.constraints.extend(constraint_vec);
model.add_constraints(constraint_vec);
}
"e_prime_label" => {}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion conjure_oxide/tests/generated_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fn check_solutions_stage(
}

fn assert_vector_operators_have_partially_evaluated(model: &conjure_core::Model) {
for node in model.constraints.universe_bi() {
for node in model.universe_bi() {
use conjure_core::ast::Expression::*;
match node {
Sum(_, ref vec) => assert_constants_leq_one(&node, vec),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
{
"constraints": [
{
"Eq": [
{
"clean": false,
"etype": null
},
"constraints": {
"Root": [
{
"clean": false,
"etype": null
},
[
{
"Abs": [
"Eq": [
{
"clean": false,
"etype": null
},
{
"Atomic": [
"Abs": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "x"
}
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "x"
}
}
]
}
]
}
]
},
{
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 1
}
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 1
}
}
]
}
]
}
]
}
],
]
},
"symbols": {
"next_machine_name": 0,
"table": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{
"constraints": [
{
"FlatAbsEq": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 1
}
},
"constraints": {
"Root": [
{
"clean": false,
"etype": null
},
[
{
"Reference": {
"UserName": "x"
}
"FlatAbsEq": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 1
}
},
{
"Reference": {
"UserName": "x"
}
}
]
}
]
}
],
]
},
"symbols": {
"next_machine_name": 0,
"table": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,87 @@
{
"constraints": [
{
"Eq": [
{
"clean": false,
"etype": null
},
"constraints": {
"Root": [
{
"clean": false,
"etype": null
},
[
{
"Sum": [
"Eq": [
{
"clean": false,
"etype": null
},
[
{
"Abs": [
{
"clean": false,
"etype": null
},
{
"Sum": [
{
"clean": false,
"etype": null
},
[
{
"Atomic": [
"Abs": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "x"
}
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "x"
}
}
]
}
]
}
]
},
{
"Abs": [
{
"clean": false,
"etype": null
},
{
"Atomic": [
"Abs": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "y"
}
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Reference": {
"UserName": "y"
}
}
]
}
]
}
]
}
]
]
},
{
"Atomic": [
{
"clean": false,
"etype": null
]
},
{
"Literal": {
"Int": 10
}
"Atomic": [
{
"clean": false,
"etype": null
},
{
"Literal": {
"Int": 10
}
}
]
}
]
}
]
}
],
]
},
"symbols": {
"next_machine_name": 0,
"table": [
Expand Down
Loading

0 comments on commit 59aa5fb

Please sign in to comment.