Skip to content
Merged
11 changes: 6 additions & 5 deletions src/chc/smtlib2.rs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think raw‑command definitions and user‑defined predicates should be emitted before the datatype declarations in the generated .smt2 file.

The reason is that raw commands and predicates written by users may refer to previously declared datatypes(ex. access fieleds of structs), whereas datatype definitions emmitted by Thrust will not refer to those commands or predicates.

Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@ impl<'a> std::fmt::Display for System<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "(set-logic HORN)\n")?;

writeln!(f, "{}\n", Datatypes::new(&self.ctx, self.ctx.datatypes()))?;
for datatype in self.ctx.datatypes() {
writeln!(f, "{}", DatatypeDiscrFun::new(&self.ctx, datatype))?;
writeln!(f, "{}", MatcherPredFun::new(&self.ctx, datatype))?;
}

// insert command from #![thrust::raw_command()] here
for raw_command in &self.inner.raw_commands {
writeln!(f, "{}\n", RawCommand::new(raw_command))?;
Expand All @@ -613,11 +619,6 @@ impl<'a> std::fmt::Display for System<'a> {
)?;
}

writeln!(f, "{}\n", Datatypes::new(&self.ctx, self.ctx.datatypes()))?;
for datatype in self.ctx.datatypes() {
writeln!(f, "{}", DatatypeDiscrFun::new(&self.ctx, datatype))?;
writeln!(f, "{}", MatcherPredFun::new(&self.ctx, datatype))?;
}
writeln!(f)?;
for (p, def) in self.inner.pred_vars.iter_enumerated() {
if !def.debug_info.is_empty() {
Expand Down