MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
clos_conv_prep.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/pass.h>
4
6
7namespace mim {
8
9class EtaExp;
10
11namespace plug::clos {
12
13class ClosConvPrep : public RWPass<ClosConvPrep, Lam> {
14public:
17
18 void init(PassMan*) final;
19
20 void enter() override;
21 const Def* rewrite(const Def*) override;
22 const App* rewrite_arg(const App* app);
23 const App* rewrite_callee(const App* app);
24
25 Lam* scope(Lam* lam);
26
27 bool from_outer_scope(Lam* lam) {
28 // return curr_mut()->free_vars().intersects(lam->free_vars()); }
29 // return scope_.free_defs().contains(lam);
30 return scope(lam) && scope(lam) != scope(curr_mut());
31 }
32
33 bool from_outer_scope(const Def* lam) { return curr_mut()->free_vars().has_intersection(lam->free_vars()); }
34
35 const Def* eta_wrap(const Def* def, attr a) {
36 auto& w = world();
37 auto [entry, inserted] = old2wrapper_.emplace(def, nullptr);
38 auto& wrapper = entry->second;
39 if (inserted) {
40 wrapper = w.mut_lam(def->type()->as<Pi>());
41 wrapper->app(false, def, wrapper->var());
42 lam2fscope_[wrapper] = scope(curr_mut());
43 wrapper_.emplace(wrapper);
44 }
45 return world().call(a, wrapper);
46 }
47
48private:
49 EtaExp* eta_exp_;
50 DefMap<Lam*> old2wrapper_;
51 DefSet wrapper_;
52 Lam2Lam lam2fscope_;
53 bool ignore_ = false;
54};
55
56} // namespace plug::clos
57} // namespace mim
Base class for all Defs.
Definition def.h:251
const Def * var(nat_t a, nat_t i) noexcept
Definition def.h:429
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.cpp:447
Vars free_vars() const
Compute a global solution by transitively following mutables as well.
Definition def.cpp:337
Performs η-expansion: f -> λx.f x, if f is a Lam with more than one user and does not appear in calle...
Definition eta_exp.h:13
A function.
Definition lam.h:111
An optimizer that combines several optimizations in an optimal way.
Definition pass.h:172
A dependent function type.
Definition lam.h:15
RWPass(World &world, std::string name)
Definition pass.h:295
bool has_intersection(Set other) const noexcept
Is ?.
Definition sets.h:267
World & world()
Definition pass.h:64
flags_t annex() const
Definition pass.h:68
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:32
const Def * call(Id id, Args &&... args)
Complete curried call of annexes obeying implicits.
Definition world.h:543
const Def * rewrite(const Def *) override
const App * rewrite_callee(const App *app)
void enter() override
Invoked just before Pass::rewriteing PassMan::curr_mut's body.
const App * rewrite_arg(const App *app)
bool from_outer_scope(const Def *lam)
ClosConvPrep(World &world, flags_t annex)
const Def * eta_wrap(const Def *def, attr a)
The clos Plugin
Definition clos.h:7
Definition ast.h:14
u64 flags_t
Definition types.h:45
GIDMap< const Def *, To > DefMap
Definition def.h:73
LamMap< Lam * > Lam2Lam
Definition lam.h:222
GIDSet< const Def * > DefSet
Definition def.h:74