3#include <absl/container/fixed_array.h>
15 if (
auto new_def =
lookup(old_def))
return new_def;
18 return new_def->set(old_def->
dbg());
22#define CODE_MUT(N) case Node::N: new_def = rewrite_mut_##N(old_mut->as<N>()); break;
23#define CODE_IMM(N) case Node::N: new_def = rewrite_imm_##N(old_def->as<N>()); break;
28 switch (old_def->
node()) {
30 default: fe::unreachable();
32 return map(old_def, new_def);
37 switch (old_mut->
node()) {
39 default: fe::unreachable();
48 auto new_ops =
DefVec(ops.size());
49 for (
size_t i = 0, e = ops.size(); i != e; ++i)
57const Def* Rewriter::rewrite_imm_Nat (
const Nat* ) {
return world().
type_nat(); }
58const Def* Rewriter::rewrite_imm_Univ (
const Univ* ) {
return world().
univ(); }
94const Def* Rewriter::rewrite_imm_Axm(
const Axm* a) {
95 if (&
a->world() != &
world()) {
97 return world().
axm(
a->normalizer(),
a->curry(),
a->trip(), type,
a->plugin(),
a->tag(),
a->sub());
102const Def* Rewriter::rewrite_imm_Extract(
const Extract* ex) {
103 auto new_index =
rewrite(ex->index());
104 if (
auto index =
Lit::isa(new_index)) {
105 if (
auto tuple = ex->tuple()->isa<
Tuple>())
return map(ex,
rewrite(tuple->op(*index)));
106 if (
auto pack = ex->tuple()->isa_imm<
Pack>(); pack && pack->arity()->is_closed())
110 auto new_tuple =
rewrite(ex->tuple());
114const Def* Rewriter::rewrite_mut_Hole(
Hole* hole) {
115 auto [
last,
op] = hole->find();
130 return map(seq, new_seq);
137 if (
auto var = seq->
has_var(); var && l && *l <=
world().flags().scalarize_threshold) {
138 auto new_ops = absl::FixedArray<const Def*>(*l);
139 for (
size_t i = 0, e = *l; i != e; ++i) {
153 map(old_mut, new_mut);
156 for (
size_t i = 0, e = old_mut->
num_ops(); i != e; ++i)
158 if (
auto new_imm = new_mut->
immutabilize())
return map(old_mut, new_imm);
A (possibly paramterized) Array.
bool is_set() const
Yields true if empty or the last op is set.
constexpr Node node() const noexcept
Def * set(size_t i, const Def *)
Successively set from left to right.
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
bool is_intro() const noexcept
T * isa_mut() const
If this is mutable, it will cast constness away and perform a dynamic_cast to T.
const Def * op(size_t i) const noexcept
virtual const Def * immutabilize()
Tries to make an immutable from a mutable.
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
virtual const Def * arity() const
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
constexpr size_t num_ops() const noexcept
This node is a hole in the IR that is inferred by its context later on.
A built-in constant of type Nat -> *.
Creates a new Tuple / Pack by inserting Insert::value at position Insert::index into Insert::tuple.
static std::optional< T > isa(const Def *def)
Scrutinize Match::scrutinee() and dispatch to Match::arms.
A (possibly paramterized) Tuple.
A dependent function type.
const Def * lookup(const Def *old_def)
Lookup old_def by searching in reverse through the stack of maps.
virtual const Def * rewrite_imm_Seq(const Seq *seq)
virtual const Def * rewrite_mut_Seq(Seq *seq)
virtual const Def * rewrite_mut(Def *)
virtual const Def * rewrite_stub(Def *, Def *)
const Def * map(const Def *old_def, const Def *new_def)
Map old_def to new_def and returns new_def.
virtual const Def * rewrite_imm(const Def *)
virtual const Def * rewrite(const Def *)
Base class for Arr and Pack.
Picks the aspect of a Meet [value](Pick::value) by its [type](Def::type).
Data constructor for a Sigma.
A singleton wraps a type into a higher order type.
const Def * insert(const Def *d, const Def *i, const Def *val)
const Def * meet(Defs ops)
const Def * uinc(const Def *op, level_t offset=1)
const Lit * lit(const Def *type, u64 val)
const Type * type(const Def *level)
const Def * sigma(Defs ops)
const Def * app(const Def *callee, const Def *arg)
const Pi * pi(const Def *dom, const Def *codom, bool implicit=false)
const Def * seq(bool term, const Def *arity, const Def *body)
const Def * bot(const Def *type)
const Lam * lam(const Pi *pi, Lam::Filter f, const Def *body)
const Def * tuple(Defs ops)
const Def * inj(const Def *type, const Def *value)
const Axm * axm(NormalizeFn n, u8 curry, u8 trip, const Def *type, plugin_t p, tag_t t, sub_t s)
const Def * var(const Def *type, Def *mut)
const Def * extract(const Def *d, const Def *i)
const Def * join(Defs ops)
const Proxy * proxy(const Def *type, Defs ops, u32 index, u32 tag)
const Def * uniq(const Def *inhabitant)
const Def * prod(bool term, Defs ops)
const Def * merge(const Def *type, Defs ops)
const Def * top(const Def *type)
const Def * split(const Def *type, const Def *value)
const Rule * rule(const Reform *type, const Def *lhs, const Def *rhs, const Def *guard)
const Def * op(trait o, const Def *type)
Vector< const Def * > DefVec
TBound< true > Join
AKA union.
TBound< false > Meet
AKA intersection.