Skip to content

Commit

Permalink
zonking now only happens locally till next mut
Browse files Browse the repository at this point in the history
  • Loading branch information
leissa committed Feb 12, 2025
1 parent 11c9ce8 commit b40c59b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
3 changes: 0 additions & 3 deletions include/mim/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Infer : public Def, public Setters<Infer> {
Infer* unset() { return Def::unset()->as<Infer>(); }
///@}

/// Eliminate Infer%s that may have been resolved in the meantime by rebuilding.
static bool has_infer(Ref def) { return def->isa_imm() && def->has_dep(Dep::Infer); }

/// [Union-Find](https://en.wikipedia.org/wiki/Disjoint-set_data_structure) to unify Infer nodes.
/// Def::flags is used to keep track of rank for
/// [Union by rank](https://en.wikipedia.org/wiki/Disjoint-set_data_structure#Union_by_rank).
Expand Down
33 changes: 16 additions & 17 deletions src/mim/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ class Zonker : public Rewriter {
: Rewriter(world) {}

Ref rewrite(Ref old_def) override {
if (Infer::has_infer(old_def)) return Rewriter::rewrite(old_def);
if (old_def->has_dep(Dep::Infer)) return Rewriter::rewrite(old_def);
return old_def;
}
};

} // namespace

// TODO this vastly overaproximates the nodes to visit.
const Def* Def::zonk() const {
if (Infer::has_infer(this)) return Zonker(world()).rewrite(this);
if (has_dep(Dep::Infer)) return Zonker(world()).rewrite(this);
return this;
}

Expand Down Expand Up @@ -152,20 +151,6 @@ template<Checker::Mode mode> bool Checker::alpha_(Ref r1, Ref r2) {
}
}

auto mut1 = d1->isa_mut();
auto mut2 = d2->isa_mut();
if (mut1 && mut2 && mut1 == mut2) return true;
// Globals are HACKs and require additionaly HACKs:
// Unless they are pointer equal (above) always consider them unequal.
if (d1->isa<Global>() || d2->isa<Global>()) return false;

if (mut1) {
if (auto [i, ins] = done_.emplace(mut1, d2); !ins) return i->second == d2;
}
if (mut2) {
if (auto [i, ins] = done_.emplace(mut2, d1); !ins) return i->second == d1;
}

auto i1 = d1->isa_mut<Infer>();
auto i2 = d2->isa_mut<Infer>();

Expand All @@ -187,6 +172,20 @@ template<Checker::Mode mode> bool Checker::alpha_(Ref r1, Ref r2) {
}
}

auto mut1 = d1->isa_mut();
auto mut2 = d2->isa_mut();
if (mut1 && mut2 && mut1 == mut2) return true;
// Globals are HACKs and require additionaly HACKs:
// Unless they are pointer equal (above) always consider them unequal.
if (d1->isa<Global>() || d2->isa<Global>()) return false;

if (mut1) {
if (auto [i, ins] = done_.emplace(mut1, d2); !ins) return i->second == d2;
}
if (mut2) {
if (auto [i, ins] = done_.emplace(mut2, d1); !ins) return i->second == d1;
}

// normalize:
if ((d1->isa<Lit>() && !d2->isa<Lit>()) // Lit to right
|| (!d1->isa<UMax>() && d2->isa<UMax>()) // UMax to left
Expand Down
1 change: 0 additions & 1 deletion src/mim/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ Ref World::implicit_app(Ref callee, Ref arg) {
}

Ref World::app(Ref callee, Ref arg) {
// Infer::zonk(Vector<Ref*>{&callee, &arg});
callee = callee->zonk();
auto pi = callee->type()->isa<Pi>();

Expand Down

0 comments on commit b40c59b

Please sign in to comment.