MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
single_erasure.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mim/phase.h
"
4
5
namespace
mim
{
6
7
/// Eliminates all types that have exactly one inhabitant, so that no Single/Wrap ever reaches a backend.
8
/// Such a type carries no information, so its erasure is the unit: `«e»` becomes `[]` and `‹e›` becomes `()`.
9
/// Within an aggregate the component is dropped altogether, which shifts the indices of its successors.
10
/// Besides Single this also catches the unit `[]` and `Idx 1` - and any aggregate built from those.
11
/// A Variant with a single case `| A` is isomorphic to `A` and erased to it.
12
/// A singleton above `*` has no unit to erase to and degrades to the type of its inhabitant instead.
13
/// Where an erased value meets a shape that still demands its components (e.g. an Axm's signature), it is coerce()d:
14
/// dropped components are re-inserted as their sole inhabitants, and Cn%s are η-wrapped.
15
class
SingleErasure
:
public
RWPhase
{
16
public
:
17
SingleErasure
(
World
&
world
, std::string
name
)
18
:
RWPhase
(
world
, std::move(
name
)) {}
19
SingleErasure
(
World
&
world
,
flags_t
annex
)
20
:
RWPhase
(
world
,
annex
) {}
21
22
private
:
23
/// @name Erasure
24
/// All arguments live in old_world(), all results in new_world().
25
///@{
26
bool
is_unit
(
const
Single
* single) {
return
single->
type
() ==
old_world
().
type
<0>(); }
27
const
Def* erase(
const
Single*);
///< The erasure of the singleton *type* itself.
28
const
Def* inhabitant(
const
Def* type);
///< The sole inhabitant of the information-free @p type.
29
Sieve sieve(
const
Sigma*);
///< The components of @p sigma that survive.
30
/// The literal @p index into a Sigma, adjusted for the components @p keep dropped.
31
size_t
remap(
const
Sieve& keep,
const
Def* index);
32
///@}
33
34
const
Def*
rewrite_imm_Single
(
const
Single*)
final
;
35
const
Def*
rewrite_imm_Wrap
(
const
Wrap*)
final
;
36
const
Def*
rewrite_imm_Variant
(
const
Variant*)
final
;
37
const
Def*
rewrite_imm_Inj
(
const
Inj*)
final
;
38
const
Def*
rewrite_imm_Match
(
const
Match*)
final
;
39
const
Def*
rewrite_imm_Sigma
(
const
Sigma*)
final
;
40
const
Def*
rewrite_mut_Sigma
(Sigma*)
final
;
41
const
Def*
rewrite_imm_Tuple
(
const
Tuple*)
final
;
42
const
Def*
rewrite_imm_Extract
(
const
Extract*)
final
;
43
const
Def*
rewrite_imm_Insert
(
const
Insert*)
final
;
44
const
Def*
rewrite_imm_Seq
(
const
Seq*)
final
;
45
const
Def*
rewrite_mut_Seq
(Seq*)
final
;
46
};
47
48
}
// namespace mim
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1119
mim::Phase::annex
flags_t annex() const
Definition
phase.h:62
mim::Phase::name
std::string_view name() const
Definition
phase.h:61
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:334
mim::RWPhase::world
World & world()=delete
Hides both and forbids direct access.
mim::RWPhase::old_world
World & old_world()
Get old Defs from here.
Definition
phase.h:378
mim::SingleErasure::rewrite_imm_Tuple
const Def * rewrite_imm_Tuple(const Tuple *) final
Definition
single_erasure.cpp:79
mim::SingleErasure::SingleErasure
SingleErasure(World &world, flags_t annex)
Definition
single_erasure.h:19
mim::SingleErasure::rewrite_imm_Variant
const Def * rewrite_imm_Variant(const Variant *) final
Definition
single_erasure.cpp:49
mim::SingleErasure::rewrite_mut_Seq
const Def * rewrite_mut_Seq(Seq *) final
Definition
single_erasure.cpp:114
mim::SingleErasure::rewrite_mut_Sigma
const Def * rewrite_mut_Sigma(Sigma *) final
Definition
single_erasure.cpp:71
mim::SingleErasure::rewrite_imm_Wrap
const Def * rewrite_imm_Wrap(const Wrap *) final
Definition
single_erasure.cpp:44
mim::SingleErasure::rewrite_imm_Match
const Def * rewrite_imm_Match(const Match *) final
Definition
single_erasure.cpp:59
mim::SingleErasure::rewrite_imm_Insert
const Def * rewrite_imm_Insert(const Insert *) final
Definition
single_erasure.cpp:96
mim::SingleErasure::rewrite_imm_Sigma
const Def * rewrite_imm_Sigma(const Sigma *) final
Definition
single_erasure.cpp:65
mim::SingleErasure::SingleErasure
SingleErasure(World &world, std::string name)
Definition
single_erasure.h:17
mim::SingleErasure::rewrite_imm_Extract
const Def * rewrite_imm_Extract(const Extract *) final
Definition
single_erasure.cpp:84
mim::SingleErasure::rewrite_imm_Inj
const Def * rewrite_imm_Inj(const Inj *) final
Definition
single_erasure.cpp:54
mim::SingleErasure::rewrite_imm_Single
const Def * rewrite_imm_Single(const Single *) final
Definition
single_erasure.cpp:37
mim::SingleErasure::rewrite_imm_Seq
const Def * rewrite_imm_Seq(const Seq *) final
Definition
single_erasure.cpp:109
mim::Single
Singleton type formation.
Definition
single.h:10
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
mim::World::type
const Type * type(const Def *level)
Definition
world.cpp:235
mim
Definition
ast.h:16
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::is_unit
bool is_unit(const Def *)
Definition
tuple.cpp:113
phase.h
include
mim
phase
single_erasure.h
Generated by
1.18.0