3#include <absl/container/fixed_array.h>
14 if (
auto new_def =
lookup(old_def))
return new_def;
28 auto new_type = old_def->isa<
Type>() ?
nullptr :
rewrite(old_def->
type());
30 auto new_ops = absl::FixedArray<const Def*>(size);
31 for (
size_t i = 0; i != size; ++i) new_ops[i] =
rewrite(old_def->
op(i));
37 auto new_mut = old_mut->
stub(
world(), new_type);
38 map(old_mut, new_mut);
41 for (
size_t i = 0, e = old_mut->
num_ops(); i != e; ++i) new_mut->set(i,
rewrite(old_mut->
op(i)));
42 if (
auto new_imm = new_mut->immutabilize())
return map(old_mut, new_imm);
51 return map(seq, new_seq);
57 auto new_ops = absl::FixedArray<const Def*>(*l);
58 for (
size_t i = 0, e = *l; i != e; ++i) {
59 if (
auto var = seq->
has_var()) {
77 if (
auto index =
Lit::isa(new_index)) {
84 return map(ex,
world().extract(new_tuple, new_index)->set(ex->
dbg()));
88 auto [last, op] = hole->
find();
A (possibly paramterized) Array.
bool is_set() const
Yields true if empty or the last op is set.
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
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
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
const Def * rebuild(World &w, const Def *type, Defs ops) const
Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.
const T * isa_imm() const
bool is_closed() const
Has no free_vars()?
Def * stub(World &w, const Def *type)
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.
std::pair< Hole *, const Def * > find()
Transitively walks up Holes until the last one while path-compressing everything.
static std::optional< T > isa(const Def *def)
A (possibly paramterized) Tuple.
const Def * shape() const final
virtual const Def * rewrite_hole(Hole *)
const Def * lookup(const Def *old_def)
Lookup old_def by searching in reverse through the stack of maps.
virtual const Def * rewrite_mut(Def *)
virtual const Def * rewrite_pack(const Pack *pack)
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_seq(const Seq *)
virtual const Def * rewrite(const Def *)
virtual const Def * rewrite_extract(const Extract *)
virtual const Def * rewrite_arr(const Arr *arr)
Base class for Arr and Pack.
virtual const Def * prod(World &w, Defs) const =0
Creates either a Tuple or Sigma.
virtual const Def * shape() const =0
virtual const Def * rebuild(World &, const Def *shape, const Def *body) const =0
Data constructor for a Sigma.
Flags & flags()
Retrieve compile Flags.
uint64_t scalarize_threshold