MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
union.cpp
Go to the documentation of this file.
1
#include "
mim/union.h
"
2
3
#include <algorithm>
4
5
#include "
mim/check.h
"
6
#include "
mim/lam.h
"
7
8
namespace
mim
{
9
10
DefVec
Match::cases
(
const
Def*
scrutinee
) {
11
auto
type
=
scrutinee
->
unfold_type
();
12
if
(!
type
)
return
{};
13
if
(
auto
join =
type
->isa<
Join
>())
return
DefVec
(join->ops().begin(), join->ops().end());
14
if
(
auto
variant =
type
->isa<
Variant
>())
return
DefVec
(variant->ops().begin(), variant->ops().end());
15
return
DefVec
{
type
};
16
}
17
18
bool
Match::accepts
(
const
Def*
arm
,
const
Def* c,
bool
infer) {
19
auto
alpha = [infer](
const
Def* a,
const
Def* b) {
return
infer ?
Check::alpha
(a, b) :
Check::test_alpha
(a, b); };
20
21
auto
pi =
arm
->
isa_type
<
Pi
>();
22
if
(!pi)
return
false
;
23
if
(alpha(pi->dom(), c))
return
true
;
24
if
(
auto
join = pi->dom()->isa_imm<
Join
>())
25
return
std::ranges::any_of(join->ops(), [&](
const
Def*
op
) { return alpha(op, c); });
26
return
false
;
27
}
28
29
}
// namespace mim
check.h
mim::Check::test_alpha
static bool test_alpha(const Def *d1, const Def *d2)
Definition
check.h:101
mim::Check::alpha
static bool alpha(const Def *d1, const Def *d2)
Definition
check.h:93
mim::Def::op
const Def * op(size_t i) const noexcept
Definition
def.h:377
mim::Def::unfold_type
const Def * unfold_type() const
Yields the type of this Def and builds a new Type (LSucc n) if necessary.
Definition
def.cpp:469
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1119
mim::Def::isa_type
const T * isa_type() const
Is Def::unfold_type a T? Yields nullptr for Level, which has no type at all.
Definition
def.h:363
mim::Join
A union type whose ops are sorted and deduplicated: T ∪ T is T.
Definition
union.h:44
mim::Match::accepts
static bool accepts(const Def *arm, const Def *c, bool infer=false)
Does arm handle c?
Definition
union.cpp:18
mim::Match::cases
static DefVec cases(const Def *scrutinee)
Definition
union.cpp:10
mim::Match::scrutinee
const Def * scrutinee() const
Definition
union.h:135
mim::Match::arm
const Def * arm(size_t i) const
Definition
union.h:140
mim::Pi
A dependent function type.
Definition
lam.h:14
mim::Variant
A sum type whose cases are positional: unlike a Join, they are neither sorted nor deduplicated.
Definition
union.h:86
lam.h
mim
Definition
ast.h:16
mim::DefVec
fe::Vector< const Def * > DefVec
Definition
def.h:98
union.h
src
mim
union.cpp
Generated by
1.18.0