MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
def.cpp
Go to the documentation of this file.
1#include "mim/def.h"
2
3#include <algorithm>
4
5#include "mim/rewrite.h"
6#include "mim/world.h"
7
8using namespace std::literals;
9
10namespace mim {
11
12/*
13 * constructors
14 */
15
16Def::Def(World* w, node_t node, const Def* type, Defs ops, flags_t flags)
17 : world_(w)
18 , flags_(flags)
19 , node_(unsigned(node))
20 , mut_(false)
21 , external_(false)
22 , dep_(unsigned(node == Node::Axiom ? Dep::Axiom
23 : node == Node::Infer ? Dep::Infer
24 : node == Node::Proxy ? Dep::Proxy
25 : node == Node::Var ? Dep::Var
26 : Dep::None))
27 , valid_(false)
28 , num_ops_(ops.size())
29 , type_(type) {
30 std::ranges::copy(ops, ops_ptr());
31 gid_ = world().next_gid();
32
33 if (auto var = isa<Var>()) {
34 vars_.local = world().vars(var);
35 muts_.local = Muts();
36 } else {
37 vars_.local = Vars();
38 muts_.local = Muts();
39
40 for (auto op : extended_ops()) {
41 vars_.local = world().merge(vars_.local, op->local_vars());
42 muts_.local = world().merge(muts_.local, op->local_muts());
43 }
44 }
45
46 if (node == Node::Univ) {
47 hash_ = murmur3(gid());
48 } else {
49 hash_ = type ? type->gid() : 0;
50 for (auto op : ops) hash_ = murmur3(hash_, u32(op->gid()));
51 hash_ = murmur3(hash_, flags_);
52 hash_ = murmur3_rest(hash_, u8(node));
53 hash_ = murmur3_finalize(hash_, num_ops());
54 }
55}
56
57Def::Def(node_t n, const Def* type, Defs ops, flags_t flags)
58 : Def(nullptr, n, type, ops, flags) {}
59
60Def::Def(node_t node, const Def* type, size_t num_ops, flags_t flags)
61 : flags_(flags)
62 , node_(node)
63 , mut_(true)
64 , external_(false)
65 , dep_(Dep::Mut | (node == Node::Infer ? Dep::Infer : Dep::None))
66 , num_ops_(num_ops)
67 , type_(type) {
68 gid_ = world().next_gid();
69 hash_ = murmur3(gid());
70 var_ = nullptr;
71 vars_.free = Vars();
72 muts_.fv_consumers = Muts();
73 std::fill_n(ops_ptr(), num_ops, nullptr);
74 if (!type->dep_const()) type->uses_.emplace(this, Use::Type);
75}
76
77Nat::Nat(World& world)
78 : Def(Node, world.type(), Defs{}, 0) {}
79
80UMax::UMax(World& world, Defs ops)
81 : Def(Node, world.univ(), ops, 0) {}
82
83// clang-format off
84
85/*
86 * rebuild
87 */
88
89#ifndef DOXYGEN // TODO Doxygen doesn't expand MIM_DEF_MIXIN
90Ref Infer ::rebuild_(World&, Ref, Defs ) const { fe::unreachable(); }
91Ref Global ::rebuild_(World&, Ref, Defs ) const { fe::unreachable(); }
92Ref Idx ::rebuild_(World& w, Ref , Defs ) const { return w.type_idx(); }
93Ref Nat ::rebuild_(World& w, Ref , Defs ) const { return w.type_nat(); }
94Ref Univ ::rebuild_(World& w, Ref , Defs ) const { return w.univ(); }
95Ref Ac ::rebuild_(World& w, Ref t, Defs o) const { return w.ac(t, o); }
96Ref App ::rebuild_(World& w, Ref , Defs o) const { return w.app(o[0], o[1]); }
97Ref Arr ::rebuild_(World& w, Ref , Defs o) const { return w.arr(o[0], o[1]); }
98Ref Extract ::rebuild_(World& w, Ref , Defs o) const { return w.extract(o[0], o[1]); }
99Ref Insert ::rebuild_(World& w, Ref , Defs o) const { return w.insert(o[0], o[1], o[2]); }
100Ref Lam ::rebuild_(World& w, Ref t, Defs o) const { return w.lam(t->as<Pi>(), o[0], o[1]); }
101Ref Lit ::rebuild_(World& w, Ref t, Defs ) const { return w.lit(t, get()); }
102Ref Pack ::rebuild_(World& w, Ref t, Defs o) const { return w.pack(t->arity(), o[0]); }
103Ref Pi ::rebuild_(World& w, Ref , Defs o) const { return w.pi(o[0], o[1], is_implicit()); }
104Ref Pick ::rebuild_(World& w, Ref t, Defs o) const { return w.pick(t, o[0]); }
105Ref Proxy ::rebuild_(World& w, Ref t, Defs o) const { return w.proxy(t, o, pass(), tag()); }
106Ref Sigma ::rebuild_(World& w, Ref , Defs o) const { return w.sigma(o); }
107Ref Singleton::rebuild_(World& w, Ref , Defs o) const { return w.singleton(o[0]); }
108Ref Type ::rebuild_(World& w, Ref , Defs o) const { return w.type(o[0]); }
109Ref Test ::rebuild_(World& w, Ref , Defs o) const { return w.test(o[0], o[1], o[2], o[3]); }
110Ref Tuple ::rebuild_(World& w, Ref t, Defs o) const { return w.tuple(t, o); }
111Ref UInc ::rebuild_(World& w, Ref , Defs o) const { return w.uinc(o[0], offset()); }
112Ref UMax ::rebuild_(World& w, Ref , Defs o) const { return w.umax(o); }
113Ref Var ::rebuild_(World& w, Ref t, Defs o) const { return w.var(t, o[0]->as_mut()); }
114Ref Vel ::rebuild_(World& w, Ref t, Defs o) const { return w.vel(t, o[0])->set(dbg()); }
115
116Ref Axiom ::rebuild_(World& w, Ref t, Defs ) const {
117 if (&w != &world()) return w.axiom(normalizer(), curry(), trip(), t, plugin(), tag(), sub())->set(dbg());
118 assert(Check::alpha(t, type()));
119 return this;
120}
121
122template<bool up> Ref TExt <up>::rebuild_(World& w, Ref t, Defs ) const { return w.ext <up>(t)->set(dbg()); }
123template<bool up> Ref TBound<up>::rebuild_(World& w, Ref , Defs o) const { return w.bound<up>(o)->set(dbg()); }
124#endif
125
126/*
127 * stub
128 */
129
130Arr* Arr ::stub_(World& w, Ref t) { return w.mut_arr (t); }
131Global* Global::stub_(World& w, Ref t) { return w.global (t, is_mutable()); }
132Infer* Infer ::stub_(World& w, Ref t) { return w.mut_infer(t); }
133Lam* Lam ::stub_(World& w, Ref t) { return w.mut_lam (t->as<Pi>()); }
134Pack* Pack ::stub_(World& w, Ref t) { return w.mut_pack (t); }
135Pi* Pi ::stub_(World& w, Ref t) { return w.mut_pi (t, is_implicit()); }
136Sigma* Sigma ::stub_(World& w, Ref t) { return w.mut_sigma(t, num_ops()); }
137
138template<bool up> TBound<up>* TBound<up>::stub_(World& w, Ref t) { return w.mut_bound<up>(t, num_ops()); }
139template<bool up> TExt <up>* TExt <up>::stub_(World& , Ref ) { fe::unreachable(); }
140
141/*
142 * instantiate templates
143 */
144
145#ifndef DOXYGEN
146template Ref TExt<false> ::rebuild_(World&, Ref, Defs) const;
147template Ref TExt<true > ::rebuild_(World&, Ref, Defs) const;
148template Ref TBound<false>::rebuild_(World&, Ref, Defs) const;
149template Ref TBound<true >::rebuild_(World&, Ref, Defs) const;
154#endif
155
156// clang-format on
157
158/*
159 * immutabilize
160 */
161
162// TODO check for recursion
164 if (auto var = has_var(); var && codom()->free_vars().contains(var)) return nullptr;
165 return world().pi(dom(), codom());
166}
167
169 if (auto v = has_var(); v && std::ranges::any_of(ops(), [v](auto op) { return op->free_vars().contains(v); }))
170 return nullptr;
171 return static_cast<const Sigma*>(*world().sigma(ops()));
172}
173
175 auto& w = world();
176 if (auto var = has_var(); !var || !body()->free_vars().contains(var)) return w.arr(shape(), body());
177
178 if (auto n = Lit::isa(shape()); n && *n < w.flags().scalarize_threshold)
179 return w.sigma(DefVec(*n, [&](size_t i) { return reduce(w.lit_idx(*n, i)); }));
180
181 return nullptr;
182}
183
185 auto& w = world();
186 if (auto var = has_var(); !var || !body()->free_vars().contains(var)) return w.pack(shape(), body());
187
188 if (auto n = Lit::isa(shape()); n && *n < w.flags().scalarize_threshold)
189 return w.tuple(DefVec(*n, [&](size_t i) { return reduce(w.lit_idx(*n, i)); }));
190
191 return nullptr;
192}
193
194/*
195 * reduce
196 */
197
198const Def* Arr::reduce(const Def* arg) const {
199 if (auto mut = isa_mut<Arr>()) return rewrite(1, mut, arg);
200 return body();
201}
202
203const Def* Pack::reduce(const Def* arg) const {
204 if (auto mut = isa_mut<Pack>()) return rewrite(0, mut, arg);
205 return body();
206}
207
208DefVec Def::reduce(const Def* arg) const {
209 if (auto mut = isa_mut()) return mut->reduce(arg);
210 return DefVec(ops().begin(), ops().end());
211}
212
213DefVec Def::reduce(const Def* arg) {
214 auto& cache = world().move_.cache;
215 if (auto i = cache.find({this, arg}); i != cache.end()) return i->second;
216
217 return cache[{this, arg}] = rewrite(this, arg);
218}
219
220const Def* Def::refine(size_t i, const Def* new_op) const {
221 DefVec new_ops(ops().begin(), ops().end());
222 new_ops[i] = new_op;
223 return rebuild(type(), new_ops);
224}
225
226/*
227 * Def - set
228 */
229
230void Def::finalize() {
231 for (size_t i = Use::Type; auto op : partial_ops()) {
232 if (op) {
233 dep_ |= op->dep();
234 if (!op->dep_const()) {
235 const auto& p = op->uses_.emplace(this, i);
236 assert_unused(p.second);
237 }
238 }
239 ++i;
240 }
241}
242
243// clang-format off
244Def* Def:: set(Defs ops) { assert(ops.size() == num_ops()); for (size_t i = 0, e = num_ops(); i != e; ++i) set(i, ops[i]); return this; }
245Def* Def::reset(Defs ops) { assert(ops.size() == num_ops()); for (size_t i = 0, e = num_ops(); i != e; ++i) reset(i, ops[i]); return this; }
246// clang-format on
247
248Def* Def::set(size_t i, const Def* def) {
249 invalidate();
250 assert(def && !op(i) && curr_op_ == i);
251#ifndef NDEBUG
252 curr_op_ = (curr_op_ + 1) % num_ops();
253#endif
254 ops_ptr()[i] = def;
255 const auto& p = def->uses_.emplace(this, i);
256 assert_unused(p.second);
257
258 if (i == num_ops() - 1) {
259 check();
260 update();
261 }
262
263 return this;
264}
265
267 invalidate();
268#ifndef NDEBUG
269 curr_op_ = 0;
270#endif
271 for (size_t i = 0, e = num_ops(); i != e; ++i) {
272 if (op(i))
273 unset(i);
274 else {
275 assert(std::all_of(ops_ptr() + i + 1, ops_ptr() + num_ops(), [](auto op) { return !op; }));
276 break;
277 }
278 }
279 return this;
280}
281
282Def* Def::unset(size_t i) {
283 invalidate();
284 assert(op(i) && op(i)->uses_.contains(Use(this, i)));
285 op(i)->uses_.erase(Use(this, i));
286 ops_ptr()[i] = nullptr;
287 return this;
288}
289
290Def* Def::set_type(const Def* type) {
291 if (type_ != type) {
292 invalidate();
293 if (type_ != nullptr) unset_type();
294 type_ = type;
295 type->uses_.emplace(this, Use::Type);
296 }
297 return this;
298}
299
301 if (type_) {
302 invalidate();
303 if (!type_->dep_const()) {
304 assert(type_->uses_.contains(Use(this, Use::Type)));
305 type_->uses_.erase(Use(this, Use::Type));
306 }
307 type_ = nullptr;
308 }
309}
310
311bool Def::is_set() const {
312 if (num_ops() == 0) return true;
313 bool result = ops().back();
314 assert((!result || std::ranges::all_of(ops().rsubspan(1), [](auto op) { return op; }))
315 && "the last operand is set but others in front of it aren't");
316 return result;
317}
318
319/*
320 * free_vars
321 */
322
324 if (auto mut = isa_mut()) return world().muts(mut);
325 return muts_.local;
326}
327
329 if (auto mut = isa_mut()) return mut->free_vars();
330
331 auto vars = local_vars();
332 for (auto mut : local_muts()) vars = world().merge(vars, mut->free_vars());
333 return vars;
334}
335
337 if (!isa_mut()) return const_cast<const Def*>(this)->free_vars();
338 if (!is_set()) return {};
339
340 if (!valid_) {
341 // fixed-point interation to recompute vars_.free
342 uint32_t run = 1;
343 for (bool todo = true; todo;) {
344 todo = false;
345 free_vars(todo, ++run);
346 }
347 validate();
348 }
349
350 return vars_.free;
351}
352
353Vars Def::free_vars(bool& todo, uint32_t run) {
354 // Recursively recompute vars_.free. If
355 // * valid_ == true: no recomputation is necessary
356 // * mark_ == run: We are running in cycles within the *current* iteration of our fixed-point loop
357 if (valid_ || mark_ == run) return vars_.free;
358 mark_ = run;
359
360 auto fvs0 = vars_.free;
361 auto fvs = fvs0;
362
363 for (auto op : extended_ops()) fvs = world().merge(fvs, op->local_vars());
364
365 for (auto op : extended_ops()) {
366 for (auto local_mut : op->local_muts()) {
367 local_mut->muts_.fv_consumers = world().insert(local_mut->muts_.fv_consumers, this);
368 fvs = world().merge(fvs, local_mut->free_vars(todo, run));
369 }
370 }
371
372 if (auto var = has_var()) fvs = world().erase(fvs, var); // FV(λx.e) = FV(e) \ {x}
373
374 todo |= fvs0 != fvs;
375 return vars_.free = fvs;
376}
377
378void Def::validate() {
379 valid_ = true;
380 mark_ = 0;
381
382 for (auto op : extended_ops()) {
383 for (auto local_mut : op->local_muts())
384 if (!local_mut->valid_) local_mut->validate();
385 }
386}
387
388void Def::invalidate() {
389 if (valid_) {
390 valid_ = false;
391 for (auto mut : fv_consumers()) mut->invalidate();
392 vars_.free.clear();
393 muts_.fv_consumers.clear();
394 }
395}
396
397bool Def::is_closed() const {
398 if (local_vars().empty() && local_muts().empty()) return true;
399#ifdef MIM_ENABLE_CHECKS
400 assert(!is_external() || free_vars().empty());
401#endif
402 return free_vars().empty();
403}
404
405bool Def::is_open() const {
406 if (!local_vars().empty() || !local_muts().empty()) return true;
407 return !free_vars().empty();
408}
409/*
410 * Def - misc
411 */
412
413Sym Def::sym(const char* s) const { return world().sym(s); }
414Sym Def::sym(std::string_view s) const { return world().sym(s); }
415Sym Def::sym(std::string s) const { return world().sym(std::move(s)); }
416
418 if (isa<Univ>()) return *world_;
419 if (auto type = isa<Type>()) return type->level()->world();
420 return type()->world(); // TODO unroll
421}
422
423const Def* Def::unfold_type() const {
424 if (!type_) {
425 if (auto t = isa<Type>()) return world().type(world().uinc(t->level()));
426 assert(isa<Univ>());
427 return nullptr;
428 }
429
430 return type_;
431}
432
433std::string_view Def::node_name() const {
434 switch (node()) {
435#define CODE(op, abbr) \
436 case Node::op: return #abbr;
438#undef CODE
439 default: fe::unreachable();
440 }
441}
442
444 if (isa<Type>() || isa<Univ>()) return Defs();
445 assert(type());
446 return Defs(ops_ptr() - 1, (is_set() ? num_ops_ : 0) + 1);
447}
448
449#ifndef NDEBUG
450const Def* Def::debug_prefix(std::string prefix) const { return dbg_.set(world().sym(prefix + sym().str())), this; }
451const Def* Def::debug_suffix(std::string suffix) const { return dbg_.set(world().sym(sym().str() + suffix)), this; }
452#endif
453
454// clang-format off
455
457 if (var_) return var_;
458 auto& w = world();
459
460 if (w.is_frozen()) return nullptr;
461 if (auto lam = isa<Lam >()) return w.var(lam ->dom(), lam);
462 if (auto pi = isa<Pi >()) return w.var(pi ->dom(), pi);
463 if (auto sig = isa<Sigma>()) return w.var(sig, sig);
464 if (auto arr = isa<Arr >()) return w.var(w.type_idx(arr ->shape()), arr ); // TODO shapes like (2, 3)
465 if (auto pack = isa<Pack >()) return w.var(w.type_idx(pack->shape()), pack); // TODO shapes like (2, 3)
466 if (isa<Bound >()) return w.var(this, this);
467 if (isa<Infer >()) return nullptr;
468 if (isa<Global>()) return nullptr;
469 fe::unreachable();
470}
471
472bool Def::is_term() const {
473 if (auto t = type()) {
474 if (auto u = t->type()) {
475 if (auto type = u->isa<Type>()) {
476 if (auto level = Lit::isa(type->level())) return *level == 0;
477 }
478 }
479 }
480 return false;
481}
482
484 if (auto sigma = isa<Sigma>()) return world().lit_nat(sigma->num_ops());
485 if (auto arr = isa<Arr >()) return arr->shape();
486 if (auto t = type()) return t->arity();
487 return world().lit_nat_1();
488}
489
490std::optional<nat_t> Def::isa_lit_arity() const {
491 if (auto sigma = isa<Sigma>()) return sigma->num_ops();
492 if (auto arr = isa<Arr >()) return Lit::isa(arr->shape());
493 if (auto t = type()) return t->isa_lit_arity();
494 return 1;
495}
496
497// clang-format on
498
499bool Def::equal(const Def* other) const {
500 if (isa<Univ>() || this->isa_mut() || other->isa_mut()) return this == other;
501
502 bool result = this->node() == other->node() && this->flags() == other->flags()
503 && this->num_ops() == other->num_ops() && this->type() == other->type();
504
505 for (size_t i = 0, e = num_ops(); result && i != e; ++i) result &= this->op(i) == other->op(i);
506
507 return result;
508}
509
510void Def::make_external() { return world().make_external(this); }
511void Def::make_internal() { return world().make_internal(this); }
512
513std::string Def::unique_name() const { return sym().str() + "_"s + std::to_string(gid()); }
514
516 if (auto a = isa_lit_arity(); a && *a < world().flags().scalarize_threshold) return *a;
517 return 1;
518}
519
520const Def* Def::proj(nat_t a, nat_t i) const {
521 static constexpr int Search_In_Uses_Threshold = 8;
522
523 if (a == 1) {
524 if (!type()) return this;
525 if (!isa_mut<Sigma>() && !type()->isa_mut<Sigma>()) return this;
526 }
527
528 World& w = world();
529
530 if (isa<Tuple>() || isa<Sigma>()) {
531 return op(i);
532 } else if (auto arr = isa<Arr>()) {
533 if (arr->arity()->isa<Top>()) return arr->body();
534 return arr->reduce(w.lit_idx(a, i));
535 } else if (auto pack = isa<Pack>()) {
536 if (pack->arity()->isa<Top>()) return pack->body();
537 assert(!w.is_frozen() && "TODO");
538 return pack->reduce(w.lit_idx(a, i));
539 }
540
541 if (w.is_frozen() || uses().size() < Search_In_Uses_Threshold) {
542 for (auto u : uses()) {
543 if (auto ex = u->isa<Extract>(); ex && ex->tuple() == this) {
544 if (auto index = Lit::isa(ex->index()); index && *index == i) return ex;
545 }
546 }
547
548 if (w.is_frozen()) return nullptr;
549 }
550
551 return w.extract(this, a, i);
552}
553
554/*
555 * Idx
556 */
557
559 if (auto app = def->isa<App>()) {
560 if (app->callee()->isa<Idx>()) return app->arg();
561 }
562
563 return nullptr;
564}
565
566std::optional<nat_t> Idx::size2bitwidth(const Def* size) {
567 if (size->isa<Top>()) return 64;
568 if (auto s = Lit::isa(size)) return size2bitwidth(*s);
569 return {};
570}
571
572/*
573 * Global
574 */
575
576const App* Global::type() const { return Def::type()->as<App>(); }
577const Def* Global::alloced_type() const { return type()->arg(0); }
578
579} // namespace mim
const Def * arg() const
Definition lam.h:214
A (possibly paramterized) Array.
Definition tuple.h:51
const Def * immutabilize() override
Tries to make an immutable from a mutable.
Definition def.cpp:174
const Def * body() const
Definition tuple.h:62
const Def * shape() const
Definition tuple.h:61
const Def * reduce(const Def *arg) const
Definition def.cpp:198
static bool alpha(Ref d1, Ref d2)
Are d1 and d2 α-equivalent?
Definition check.h:59
Base class for all Defs.
Definition def.h:220
bool is_set() const
Yields true if empty or the last op is set.
Definition def.cpp:311
Def * set(size_t i, const Def *def)
Successively set from left to right.
Definition def.cpp:248
const Def * proj(nat_t a, nat_t i) const
Similar to World::extract while assuming an arity of a, but also works on Sigmas and Arrays.
Definition def.cpp:520
const Uses & uses() const
Definition def.h:325
auto vars()
Definition def.h:398
void make_internal()
Definition def.cpp:511
size_t num_ops() const
Definition def.h:267
Ref var()
Not necessarily a Var: E.g., if the return type is [], this will yield ().
Definition def.cpp:456
const Def * op(size_t i) const
Definition def.h:266
nat_t num_tprojs() const
As above but yields 1, if Flags::scalarize_threshold is exceeded.
Definition def.cpp:515
const Def * refine(size_t i, const Def *new_op) const
Definition def.cpp:220
Def * set_type(const Def *)
Definition def.cpp:290
std::string_view node_name() const
Definition def.cpp:433
Defs extended_ops() const
Definition def.cpp:443
Vars local_vars() const
Definition def.h:418
void make_external()
Definition def.cpp:510
Muts fv_consumers()
Definition def.h:423
World & world() const
Definition def.cpp:417
Dbg dbg_
Definition def.h:565
virtual void check()
Definition def.h:512
T * isa_mut() const
If this is *mut*able, it will cast constness away and perform a dynamic_cast to T.
Definition def.h:444
unsigned dep() const
Definition def.h:332
bool is_term() const
Yields true if this:T and T:(.Type 0).
Definition def.cpp:472
const Def * debug_prefix(std::string) const
Definition def.cpp:450
bool dep_const() const
Definition def.h:335
DefVec reduce(const Def *arg) const
Rewrites Def::ops by substituting this mutable's Var with arg.
Definition def.cpp:208
bool is_external() const
Definition def.h:428
const Def * unfold_type() const
Yields the type of this Def and builds a new .Type (UInc n) if necessary.
Definition def.cpp:423
bool is_open() const
Has free_vars()?
Definition def.cpp:405
void unset_type()
Definition def.cpp:300
auto ops() const
Definition def.h:265
Muts local_muts() const
Definition def.cpp:323
void update()
Resolves Infers of this Def's type.
Definition def.h:296
const Def * debug_suffix(std::string) const
Definition def.cpp:451
const Def * type() const
Definition def.h:245
node_t node() const
Definition def.h:238
virtual Ref rebuild_(World &w, Ref type, Defs ops) const =0
u32 gid() const
Definition def.h:236
Ref arity() const
Definition def.cpp:483
Sym sym() const
Definition def.h:465
flags_t flags() const
Definition def.h:235
std::optional< nat_t > isa_lit_arity() const
Definition def.cpp:490
flags_t flags_
Definition def.h:572
Defs partial_ops() const
Definition def.h:318
Ref rebuild(World &w, Ref type, Defs ops) const
Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.
Definition def.h:493
Def * unset()
Unsets all Def::ops; works even, if not set at all or partially.
Definition def.cpp:266
std::string unique_name() const
name + "_" + Def::gid
Definition def.cpp:513
bool is_closed() const
Has no free_vars()?
Definition def.cpp:397
Def * reset(size_t i, const Def *def)
Successively reset from left to right.
Definition def.h:288
Vars free_vars() const
Definition def.cpp:328
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
Definition def.h:402
Extracts from a Sigma or Array-typed Extract::tuple the element at position Extract::index.
Definition tuple.h:119
const Def * tuple() const
Definition tuple.h:127
const Def * alloced_type() const
Definition def.cpp:577
bool is_mutable() const
Definition def.h:790
const App * type() const
Definition def.cpp:576
Global * stub_(World &, Ref) override
Definition def.cpp:131
A built-in constant of type .Nat -> *.
Definition def.h:731
static Ref size(Ref def)
Checks if def is a .Idx s and returns s or nullptr otherwise.
Definition def.cpp:558
static constexpr nat_t size2bitwidth(nat_t n)
Definition def.h:744
This node is a hole in the IR that is inferred by its context later on.
Definition check.h:12
A function.
Definition lam.h:96
static std::optional< T > isa(Ref def)
Definition def.h:712
A (possibly paramterized) Tuple.
Definition tuple.h:88
const Def * body() const
Definition tuple.h:98
const Def * shape() const
Definition tuple.cpp:40
const Def * reduce(const Def *arg) const
Definition def.cpp:203
const Def * immutabilize() override
Tries to make an immutable from a mutable.
Definition def.cpp:184
A dependent function type.
Definition lam.h:11
Ref codom() const
Definition lam.h:40
const Pi * immutabilize() override
Tries to make an immutable from a mutable.
Definition def.cpp:163
Ref dom() const
Definition lam.h:32
constexpr bool contains(const T &elem) const
Definition pool.h:66
constexpr bool empty() const noexcept
Definition pool.h:61
constexpr void clear() noexcept
Definition pool.h:55
Helper class to retrieve Infer::arg if present.
Definition def.h:85
A dependent tuple type.
Definition tuple.h:9
const Def * immutabilize() override
Tries to make an immutable from a mutable.
Definition def.cpp:168
This is a thin wrapper for std::span<T, N> with the following additional features:
Definition span.h:28
Specific Bound depending on Up.
Definition lattice.h:31
Ref rebuild_(World &, Ref, Defs) const override
TBound * stub_(World &, Ref) override
Definition def.cpp:138
Extremum. Either Top (Up) or Bottom.
Definition lattice.h:130
Ref rebuild_(World &, Ref, Defs) const override
TExt * stub_(World &, Ref) override
Definition def.cpp:139
References a user.
Definition def.h:107
static constexpr size_t Type
Definition def.h:109
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:33
Vars vars(const Var *var)
Definition world.h:505
void make_internal(Def *def)
Definition world.h:175
Ref insert(Ref d, Ref i, Ref val)
Definition world.cpp:353
Flags & flags()
Retrive compile Flags.
Definition world.cpp:74
u32 next_gid()
Definition world.h:90
Vars merge(Vars a, Vars b)
Definition world.h:507
Sym sym(std::string_view)
Definition world.cpp:77
const Pi * pi(Ref dom, Ref codom, bool implicit=false)
Definition world.h:255
void make_external(Def *def)
Definition world.h:169
Muts muts(Def *mut)
Definition world.h:506
const Lit * lit_nat(nat_t a)
Definition world.h:388
Ref sigma(Defs ops)
Definition world.cpp:231
const Type * type(Ref level)
Definition world.cpp:94
Vars erase(Vars vars, const Var *var)
Definition world.h:511
const Lit * lit_nat_1()
Definition world.h:390
#define MIM_NODE(m)
Definition def.h:17
@ Univ
Definition def.h:39
void * get(void *handle, const char *symbol_name)
Definition dl.cpp:36
Definition cfg.h:11
View< const Def * > Defs
Definition def.h:60
u64 nat_t
Definition types.h:43
Vector< const Def * > DefVec
Definition def.h:61
Dep
Definition def.h:144
u64 flags_t
Definition types.h:45
uint64_t scalarize_threshold
Definition flags.h:13
u8 node_t
Definition types.h:44
PooledSet< Def * > Muts
Definition def.h:70
hash_t murmur3(hash_t h, uint32_t key)
Definition hash.h:22
PooledSet< const Var * > Vars
Definition def.h:79
uint32_t u32
Definition types.h:34
DefVec rewrite(Def *mut, Ref arg)
Definition rewrite.cpp:45
uint8_t u8
Definition types.h:34
hash_t murmur3_finalize(hash_t h, hash_t len)
Definition hash.h:51
hash_t murmur3_rest(hash_t h, uint8_t key)
Definition hash.h:41
Dbg & set(Sym sym)
Definition dbg.h:153
#define CODE(t, str)
Definition tok.h:53