Skip to content

Commit 852cb9b

Browse files
committed
solved valgrind memory issues (pass by reference vs pass by value pointer)
1 parent d7734e9 commit 852cb9b

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

dialects/compile/compile.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ extern "C" THORIN_EXPORT thorin::DialectInfo thorin_get_dialect_info() {
7070
int level = (int)(app->as<App>()->arg(0)->as<Lit>()->get<u64>());
7171
world.DLOG(" Level: {}", level);
7272
// TODO: add a debug pass to the pipeline
73-
builder.append_pass_after_end([&](PassMan& man) {
73+
builder.append_pass_after_end([=](PassMan& man) {
7474
man.add<thorin::compile::DebugPrint>(level);
75-
// man.add<thorin::compile::DebugPrint>(1);
75+
// man.add<thorin::compile::DebugPrint>(level);
76+
// man.add<thorin::compile::DebugPrint>(42);
7677
});
7778
};
7879

dialects/compile/compile.thorin

-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@
7878
///
7979
// TODO: allow functions by inlining them first
8080
.let optimization_phase = {
81-
// TODO: it needs to be possible to add a pass twice and keep the instances separate (bind in pipeline/manager?)
8281
.let eta_red = %compile.eta_red_pass;
8382
.let eta_exp = %compile.eta_exp_pass eta_red;
84-
// TODO: use pass_phase
8583
%compile.pass_phase (%compile.pass_list
8684
%compile.partial_eval_pass
8785
%compile.beta_red_pass

lit/compile/id.thorin

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
.lam .extern _compile [] -> Pipeline = {
1616
%compile.pipe
17-
(%compile.debug_phase 1)
17+
// (%compile.debug_phase 1)
1818
(%compile.debug_phase 2)
19-
(%compile.debug_phase 3)
19+
// (%compile.debug_phase 3)
2020
};
2121

2222
// CHECK-DAG: return{{.*}}42

thorin/dialects.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ Dialect Dialect::load(const std::string& name, Span<std::string> search_paths) {
8585
plugin_path = full_path.string();
8686

8787
std::error_code ignore;
88-
if (bool reg_file = std::filesystem::is_regular_file(full_path, ignore); reg_file && !ignore)
89-
if (handle.reset(dl::open(full_path.string())); handle) break;
88+
if (bool reg_file = std::filesystem::is_regular_file(full_path, ignore); reg_file && !ignore) {
89+
auto path_str = full_path.string();
90+
if (handle.reset(dl::open(path_str)); handle) break;
91+
}
9092
}
9193
if (handle) break;
9294
}

thorin/pass/pipelinebuilder.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class PipelineBuilder {
4141
// void add_pass(const Def*, Args&&...);
4242
template<class P, class... Args>
4343
void add_pass(const Def* def, Args&&... args) {
44-
append_pass_in_end([&](PassMan& man) {
45-
auto pass = (Pass*)man.add<P>(std::forward<Args>(args)...);
44+
append_pass_in_end([&, def, ... args = std::forward<Args>(args)](PassMan& man) {
45+
// auto pass = (Pass*)man.add<P>(std::forward<Args>(args)...);
46+
auto pass = (Pass*)man.add<P>(args...);
4647
remember_pass_instance(pass, def);
4748
});
4849
}
@@ -77,14 +78,14 @@ class PipelineBuilder {
7778
// TODO: move somewhere better (for now here due to template restrictions)
7879
template<class A, class P>
7980
void register_pass(Passes& passes) {
80-
passes[flags_t(Axiom::Base<A>)] = [&](World&, PipelineBuilder& builder, const Def* app) {
81+
passes[flags_t(Axiom::Base<A>)] = [](World&, PipelineBuilder& builder, const Def* app) {
8182
builder.add_pass<P>(app);
8283
};
8384
}
8485

8586
template<class A, class P, class Q>
8687
void register_pass_with_arg(Passes& passes) {
87-
passes[flags_t(Axiom::Base<A>)] = [&](World&, PipelineBuilder& builder, const Def* app) {
88+
passes[flags_t(Axiom::Base<A>)] = [](World&, PipelineBuilder& builder, const Def* app) {
8889
auto pass_arg = (Q*)(builder.get_pass_instance(app->as<App>()->arg()));
8990
builder.add_pass<P>(app, pass_arg);
9091
};

0 commit comments

Comments
 (0)