Skip to content

SMT2 frontend: renaming let bindings is no longer necessary #6179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2021
Merged
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
26 changes: 17 additions & 9 deletions src/solvers/smt2/smt2_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,22 @@ exprt smt2_parsert::let_expression()
if(next_token() != smt2_tokenizert::CLOSE)
throw error("expected ')' at end of bindings");

// save the renaming map
renaming_mapt old_renaming_map=renaming_map;
// we may hide identifiers in outer scopes
std::vector<std::pair<irep_idt, idt>> saved_ids;

// go forwards, add to id_map, renaming if need be
// add the bindings to the id_map
for(auto &b : bindings)
{
// get a fresh id for it
b.first = add_fresh_id(b.first, idt::BINDING, b.second);
auto insert_result = id_map.insert({b.first, idt{idt::BINDING, b.second}});
if(!insert_result.second) // already there
{
auto &id_entry = *insert_result.first;
saved_ids.emplace_back(id_entry.first, std::move(id_entry.second));
id_entry.second = idt{idt::BINDING, b.second};
}
}

// now parse, with bindings in place
exprt where = expression();

if(next_token() != smt2_tokenizert::CLOSE)
Expand All @@ -232,11 +238,13 @@ exprt smt2_parsert::let_expression()
values.push_back(b.second);
}

// we keep these in the id_map in order to retain globally
// unique identifiers
// delete the bindings from the id_map
for(const auto &binding : bindings)
id_map.erase(binding.first);

// restore renamings
renaming_map=old_renaming_map;
// restore any previous ids
for(auto &saved_id : saved_ids)
id_map.insert(std::move(saved_id));

return let_exprt(variables, values, where);
}
Expand Down