MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
nom_erasure.cpp
Go to the documentation of this file.
1
#include "
mim/phase/nom_erasure.h
"
2
3
#include <fe/worklist.h>
4
5
namespace
mim
{
6
7
static
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
17
const
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
26
const
Def
*
NomErasure::rewrite_imm_Nom
(
const
Nom
* nom) {
27
auto
type =
rewrite
(nom->
op
());
28
log
().d(
"nom-erasure `{}` → `{}`"
, nom, type);
29
profile_count
(
"nominals eliminated"
);
30
return
type;
31
}
32
33
const
Def
*
NomErasure::rewrite_imm_Name
(
const
Name
*
name
) {
34
profile_count
(
"nominals eliminated"
);
35
return
rewrite
(
name
->
op
());
36
}
37
38
const
Def
*
NomErasure::rewrite_imm_Struc
(
const
Struc
* struc) {
39
profile_count
(
"nominals eliminated"
);
40
return
rewrite
(struc->op());
41
}
42
43
}
// namespace mim
mim::Axm
Definition
axm.h:9
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Name
Nominal newtype term introduction.
Definition
nom.h:34
mim::Name::op
const Def * op() const
Definition
nom.h:44
mim::NomErasure::rewrite_imm_Nom
const Def * rewrite_imm_Nom(const Nom *) final
Definition
nom_erasure.cpp:26
mim::NomErasure::lookup
const Def * lookup(const Def *) final
Lookup old_def by searching in reverse through the stack of maps.
Definition
nom_erasure.cpp:17
mim::NomErasure::rewrite_imm_Name
const Def * rewrite_imm_Name(const Name *) final
Definition
nom_erasure.cpp:33
mim::NomErasure::rewrite_imm_Struc
const Def * rewrite_imm_Struc(const Struc *) final
Definition
nom_erasure.cpp:38
mim::Nom
Nominal newtype formation.
Definition
nom.h:11
mim::Nom::op
const Def * op() const
The wrapped type.
Definition
nom.h:21
mim::Phase::log
const fe::Log & log() const
Definition
phase.h:60
mim::Phase::profile_count
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
mim::Phase::name
std::string_view name() const
Definition
phase.h:61
mim::RWPhase::lookup
const Def * lookup(const Def *) override
Lookup old_def by searching in reverse through the stack of maps.
Definition
phase.cpp:212
mim::Rewriter::rewrite
virtual const Def * rewrite(const Def *)
Definition
rewrite.cpp:62
mim::Rewriter::lookup
virtual const Def * lookup(const Def *old_def)
Lookup old_def by searching in reverse through the stack of maps.
Definition
rewrite.h:66
mim::Struc
Nominal newtype term elimination.
Definition
nom.h:56
mim
Definition
ast.h:16
mim::has_nom
static bool has_nom(const Def *def)
Definition
nom_erasure.cpp:7
nom_erasure.h
src
mim
phase
nom_erasure.cpp
Generated by
1.18.0