MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
nom_erasure.cpp
Go to the documentation of this file.
2
3#include <fe/worklist.h>
4
5namespace mim {
6
7static bool has_nom(const Def* def) {
8 for (auto queue = fe::BFSWorklist<DefSet>{def}; !queue.empty();) {
9 auto d = queue.pop();
10 if (d->isa<Nom>()) return true;
11 for (auto dep : d->deps())
12 queue.push(dep);
13 }
14 return false;
15}
16
17const Def* NomErasure::lookup(const Def* old_def) {
18 // An opaque Axm whose type mentions a Nom is rebuilt under the same flags with an erased type.
19 if (auto axm = old_def->isa<Axm>()) {
20 if (auto new_def = Rewriter::lookup(axm)) return new_def;
21 if (has_nom(axm->type())) return nullptr;
22 }
23 return RWPhase::lookup(old_def);
24}
25
27 auto type = rewrite(nom->op());
28 log().d("nom-erasure `{}` → `{}`", nom, type);
29 profile_count("nominals eliminated");
30 return type;
31}
32
34 profile_count("nominals eliminated");
35 return rewrite(name->op());
36}
37
39 profile_count("nominals eliminated");
40 return rewrite(struc->op());
41}
42
43} // namespace mim
Definition axm.h:9
Base class for all Defs.
Definition def.h:289
Nominal newtype term introduction.
Definition nom.h:34
const Def * op() const
Definition nom.h:44
const Def * rewrite_imm_Nom(const Nom *) final
const Def * lookup(const Def *) final
Lookup old_def by searching in reverse through the stack of maps.
const Def * rewrite_imm_Name(const Name *) final
const Def * rewrite_imm_Struc(const Struc *) final
Nominal newtype formation.
Definition nom.h:11
const Def * op() const
The wrapped type.
Definition nom.h:21
const fe::Log & log() const
Definition phase.h:60
void profile_count(std::string_view key, uint64_t n=1)
Adds n to the custom fe::Profiler counter key of the current run; no-op unless profiling is enabled.
Definition phase.cpp:60
std::string_view name() const
Definition phase.h:61
const Def * lookup(const Def *) override
Lookup old_def by searching in reverse through the stack of maps.
Definition phase.cpp:212
virtual const Def * rewrite(const Def *)
Definition rewrite.cpp:62
virtual const Def * lookup(const Def *old_def)
Lookup old_def by searching in reverse through the stack of maps.
Definition rewrite.h:66
Nominal newtype term elimination.
Definition nom.h:56
Definition ast.h:16
static bool has_nom(const Def *def)