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