39 using alias_map = std::map<QualifiedName, QualifiedName>;
42 alias_map isDirectAliasOf;
46 Program& program = translationUnit.getProgram();
51 if (!ioType->isIO(
rel) &&
clauses.size() == 1u) {
54 std::vector<Atom*> bodyAtoms = getBodyLiterals<Atom>(*cl);
56 Atom* atom = bodyAtoms[0];
66 bool onlyDistinctHeadVars =
true;
67 std::set<std::string> headVars;
70 while (onlyDistinctHeadVars && !args.empty()) {
71 const auto cur = args.back();
75 onlyDistinctHeadVars &= headVars.insert(var->getName()).second;
76 }
else if (
auto init =
dynamic_cast<const RecordInit*
>(cur)) {
78 for (
auto rec_arg : init->getArguments()) {
79 args.push_back(rec_arg);
82 onlyDistinctHeadVars =
false;
86 if (onlyDistinctHeadVars) {
100 std::set<QualifiedName> cycle_reps;
102 for (std::pair<QualifiedName, QualifiedName> cur : isDirectAliasOf) {
105 std::set<QualifiedName> visited;
106 visited.insert(cur.first);
107 visited.insert(cur.second);
109 auto pos = isDirectAliasOf.find(cur.second);
110 while (pos != isDirectAliasOf.end()) {
111 if (visited.count(pos->second) != 0u) {
112 cycle_reps.insert(cur.second);
115 cur.second = pos->second;
116 pos = isDirectAliasOf.find(cur.second);
118 isAliasOf[cur.first] = cur.second;
121 if (isAliasOf.empty()) {
127 auto pos = isAliasOf.find(atom.getQualifiedName());
128 if (pos != isAliasOf.end()) {
129 const_cast<Atom&>(atom).setQualifiedName(pos->second);
134 for (
const auto& rep : cycle_reps) {
137 assert(
clauses.size() == 1u &&
"unexpected number of clauses in relation");
138 program.removeClause(
clauses[0]);
142 for (
const auto& cur : isAliasOf) {
143 if (cycle_reps.count(cur.first) == 0u) {