Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
beta_red.cpp
Go to the documentation of this file.
2
3#include "thorin/rewrite.h"
4
5namespace thorin {
6
8 if (auto [app, lam] = isa_apped_mut_lam(def); isa_workable(lam) && !keep_.contains(lam)) {
9 if (auto [_, ins] = data().emplace(lam); ins) {
10 world().DLOG("beta-reduction {}", lam);
11 return lam->reduce(app->arg()).back();
12 } else {
13 return proxy(app->type(), {lam, app->arg()}, 0);
14 }
15 }
16
17 return def;
18}
19
21 auto lam = proxy->op(0)->as_mut<Lam>();
22 if (keep_.emplace(lam).second) {
23 world().DLOG("found proxy app of '{}' within '{}'", lam, curr_mut());
24 return undo_visit(lam);
25 }
26
27 return No_Undo;
28}
29
31 auto undo = No_Undo;
32 for (auto op : def->ops()) {
33 if (auto lam = isa_workable(op->isa_mut<Lam>()); lam && keep_.emplace(lam).second) {
34 auto [_, ins] = data().emplace(lam);
35 if (!ins) {
36 world().DLOG("non-callee-position of '{}'; undo inlining of {} within {}", lam, lam, curr_mut());
37 undo = std::min(undo, undo_visit(lam));
38 }
39 }
40 }
41
42 return undo;
43}
44
45} // namespace thorin
Ref rewrite(Ref) override
Definition beta_red.cpp:7
undo_t analyze(const Proxy *) override
Definition beta_red.cpp:20
auto ops() const
Definition def.h:268
const Def * op(size_t i) const
Definition def.h:269
T * isa_mut() const
If this is *mut*able, it will cast constness away and perform a dynamic_cast to T.
Definition def.h:449
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
Definition def.h:457
undo_t undo_visit(Def *mut) const
Retrieves the point to backtrack to just before mut was seen the very first time.
Definition pass.h:273
A function.
Definition lam.h:97
World & world()
Definition pass.h:296
const Proxy * proxy(Ref type, Defs ops, u32 tag=0)
Definition pass.h:75
M * curr_mut() const
Definition pass.h:232
Helper class to retrieve Infer::arg if present.
Definition def.h:87
Definition cfg.h:11
static constexpr undo_t No_Undo
Definition pass.h:15
size_t undo_t
Definition pass.h:14
std::pair< const App *, Lam * > isa_apped_mut_lam(const Def *def)
Definition lam.h:239
Lam * isa_workable(Lam *lam)
These are Lams that are neither nullptr, nor Lam::is_external, nor Lam::is_unset.
Definition lam.h:234