Skip to content

Commit

Permalink
deprecated BlockExpr
Browse files Browse the repository at this point in the history
* added warning
* polished error handling
  • Loading branch information
leissa committed Apr 26, 2024
1 parent fcd8884 commit caf78d9
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 91 deletions.
25 changes: 8 additions & 17 deletions include/thorin/util/dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,6 @@ class Error : std::exception {
size_t num_notes() const { return num_notes_; }
///@}

void clear() {
num_errors_ = 0;
num_warnings_ = 0;
num_notes_ = 0;
msgs_.clear();
}

/// If errors occured, claim them and throw.
void ack() {
if (num_errors() != 0) {
auto errors = std::move(*this);
throw errors;
}
}

/// @name Add formatted message
///@{
template<class... Args> Error& msg(Loc loc, Tag tag, const char* s, Args&&... args) {
Expand All @@ -89,7 +74,14 @@ class Error : std::exception {
assert(num_errors() > 0 || num_warnings() > 0); /* */ ++num_notes_; return msg(loc, Tag::Note, s, std::forward<Args&&>(args)...);
}
// clang-format on
//@}
///@}

/// @name Handle Errors/Warnings
///@{
void clear();
/// If errors occured, claim them and throw; if warnings occured, claim them and report to @p os.
void ack(std::ostream& os = std::cerr);
///@}

friend std::ostream& operator<<(std::ostream& o, Tag tag) {
// clang-format off
Expand All @@ -109,7 +101,6 @@ class Error : std::exception {

friend void swap(Error& e1, Error& e2) noexcept {
using std::swap;
;
// clang-format off
swap(e1.msgs_, e2.msgs_);
swap(e1.num_errors_, e2.num_errors_);
Expand Down
6 changes: 3 additions & 3 deletions src/thorin/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
namespace thorin::ast {

AST::~AST() {
assert(error().num_errors() == 0 && "please encounter any errors before destroying this class");
if (error().num_warnings() != 0)
driver().WLOG("{} warning(s) encountered while compiling module\n{}", error().num_warnings(), error());
assert(error().num_errors() == 0 && error().num_warnings() == 0
&& "please encounter any errors before destroying this class");
}

Annex& AST::name2annex(Dbg dbg) {
Expand Down Expand Up @@ -173,6 +172,7 @@ void Module::compile(AST& ast) const {
bind(ast);
ast.error().ack();
emit(ast);
if (ast.error().num_warnings() != 0) std::cerr << ast.error();
}

AST load_plugins(World& world, View<Sym> plugins) {
Expand Down
2 changes: 2 additions & 0 deletions src/thorin/ast/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ void AxiomDecl::bind(Scopes& s) const {
}

void LetDecl::bind(Scopes& s) const {
s.push();
value()->bind(s);
s.pop();
ptrn()->bind(s);
}

Expand Down
2 changes: 2 additions & 0 deletions src/thorin/ast/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ Ptr<Expr> Parser::parse_block_expr() {
eat(Tag::D_brace_l);
auto expr = parse_expr("final expression in a block expression");
expect(Tag::D_brace_r, "block expression");
ast().warn(track, "block expression is deprecated; use a (possibly parenthesized) declaration expression instead");

return ptr<BlockExpr>(track, std::move(expr));
}

Expand Down
48 changes: 23 additions & 25 deletions src/thorin/plug/clos/clos.thorin
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@
.ax %clos.clos_conv_phase: %compile.Phase;
.ax %clos.lower_typed_clos_phase: %compile.Phase;

.let clos_opt1_phase = {
.let eta_red = %clos.eta_red_bool_pass .tt;
.let eta_exp = %compile.eta_exp_pass eta_red;
%compile.pass_phase (%compile.pass_list
eta_red
eta_exp
(%compile.scalerize_pass eta_exp)
)
};
.let clos_opt2_phase = {
.let nullptr = %compile.nullptr_pass;
%compile.pass_phase (%compile.pass_list
nullptr
(%compile.scalerize_pass nullptr)
%clos.branch_clos_pass
(%mem.copy_prop_pass (nullptr, nullptr, .tt))
%clos.lower_typed_clos_prep_pass
%clos.clos2sjlj_pass
)
};
.let clos_phases = {
.let nullptr = %compile.nullptr_pass;
.let clos_opt1_phase =
.let eta_red = %clos.eta_red_bool_pass .tt;
.let eta_exp = %compile.eta_exp_pass eta_red;
%compile.pass_phase (%compile.pass_list
eta_red
eta_exp
(%compile.scalerize_pass eta_exp)
);

.let clos_opt2_phase =
.let nullptr = %compile.nullptr_pass;
%compile.pass_phase
(%compile.pass_list
nullptr
(%compile.scalerize_pass nullptr)
%clos.branch_clos_pass
(%mem.copy_prop_pass (nullptr, nullptr, .tt))
%clos.lower_typed_clos_prep_pass
%clos.clos2sjlj_pass);

.let clos_phases =
.let nullptr = %compile.nullptr_pass;
%compile.combined_phase
(%compile.phase_list
(%compile.single_pass_phase nullptr)
Expand All @@ -75,6 +75,4 @@
%clos.clos_conv_phase
clos_opt1_phase
clos_opt2_phase
%clos.lower_typed_clos_phase
)
};
%clos.lower_typed_clos_phase);
16 changes: 7 additions & 9 deletions src/thorin/plug/compile/compile.thorin
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,21 @@
/// ### Phases
///
// TODO: allow functions by inlining them first
.let optimization_pass_list = {
.let optimization_pass_list =
.let eta_red = %compile.eta_red_pass;
.let eta_exp = %compile.eta_exp_pass eta_red;
%compile.pass_list
%compile.beta_red_pass
eta_red
eta_exp
(%compile.scalerize_pass eta_exp)
(%compile.tail_rec_elim_pass eta_red)
};
.let optimization_phase = {
%compile.pass_phase optimization_pass_list
};
(%compile.tail_rec_elim_pass eta_red);

.let optimization_phase = %compile.pass_phase optimization_pass_list;
///
/// ### Pipelines
///
.let default_core_pipeline = {
.let default_core_pipeline =
.let nullptr = %compile.nullptr_pass;
%compile.pipe
(%compile.single_pass_phase nullptr)
Expand All @@ -142,8 +140,8 @@
optimization_phase
(%compile.single_pass_phase %compile.internal_cleanup_pass)
(%compile.single_pass_phase %compile.lam_spec_pass)
(%compile.single_pass_phase %compile.ret_wrap_pass)
};
(%compile.single_pass_phase %compile.ret_wrap_pass);

.lam .extern _fallback_compile(): %compile.Pipeline = default_core_pipeline;
///
/// ### Dependent Passes and Phases
Expand Down
13 changes: 6 additions & 7 deletions src/thorin/plug/direct/direct.thorin
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
///
/// ### Phases
///
.let direct_phases = {
%compile.combined_phase (%compile.phase_list
(%compile.single_pass_phase %direct.ds2cps_pass)
(%compile.single_pass_phase %direct.cps2ds_pass)
optimization_phase
)
};
.let direct_phases =
%compile.combined_phase
(%compile.phase_list
(%compile.single_pass_phase %direct.ds2cps_pass)
(%compile.single_pass_phase %direct.cps2ds_pass)
optimization_phase);
13 changes: 6 additions & 7 deletions src/thorin/plug/matrix/matrix.thorin
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,14 @@
///
/// ### Phases
///
.let matrix_lower_phase = {
.let matrix_lower_phase =
%compile.phases_to_phase (⊤:.Nat)
(
(%compile.pass_phase (%compile.pass_list
%matrix.lower_matrix_high_level_map_reduce
%matrix.lower_matrix_medium_level
)),
(%compile.pass_phase
(%compile.pass_list
%matrix.lower_matrix_high_level_map_reduce
%matrix.lower_matrix_medium_level)),
// TODO: only in map_red namespace
%compile.single_pass_phase %matrix.internal_map_reduce_cleanup,
%matrix.lower_matrix_low_level
)
};
);
11 changes: 4 additions & 7 deletions src/thorin/plug/mem/mem.thorin
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
///
.ax %mem.add_mem_phase: %compile.Phase;

.let mem_opt_pass_list = {
.let mem_opt_pass_list =
.let beta_red = %compile.beta_red_pass;
.let eta_red = %compile.eta_red_pass;
.let eta_exp = %compile.eta_exp_pass eta_red;
Expand All @@ -125,10 +125,7 @@
eta_red
eta_exp
(%mem.ssa_pass eta_exp)
(%mem.copy_prop_pass (beta_red, eta_exp, .ff))
};
(%mem.copy_prop_pass (beta_red, eta_exp, .ff));

.let mem_opt_phase = %compile.pass_phase mem_opt_pass_list;
.let mem_prep_phase = %compile.passes_to_phase (⊤:.Nat) (
%mem.remem_elim_pass,
%mem.alloc2malloc_pass
);
.let mem_prep_phase = %compile.passes_to_phase (⊤:.Nat) (%mem.remem_elim_pass, %mem.alloc2malloc_pass);
32 changes: 16 additions & 16 deletions src/thorin/plug/opt/opt.thorin
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
///
/// ### Pipelines
///
.lam .extern _default_compile []: %compile.Pipeline = {
.lam .extern _default_compile []: %compile.Pipeline =
.let nullptr = %compile.nullptr_pass;
.let nullphase = %compile.single_pass_phase nullptr;
%compile.pipe
Expand All @@ -41,20 +41,21 @@
mem_opt_pass_list
))
)
(plugin_cond_phase (%compile.autodiff_plugin,
%compile.combined_phase (%compile.phase_list
(%compile.single_pass_phase %autodiff.ad_eval_pass)
// optimization_phase
(%compile.single_pass_phase %autodiff.ad_zero_pass)
)
))
(plugin_cond_phase
(%compile.autodiff_plugin,
%compile.combined_phase
(%compile.phase_list
(%compile.single_pass_phase %autodiff.ad_eval_pass)
// optimization_phase
(%compile.single_pass_phase %autodiff.ad_zero_pass))))
(plugin_cond_phase (%compile.direct_plugin, direct_phases))
(plugin_cond_phase (%compile.matrix_plugin,
%compile.combined_phase (%compile.phase_list
matrix_lower_phase
(plugin_cond_phase (%compile.direct_plugin, direct_phases))
(plugin_cond_phase (%compile.affine_plugin, %compile.single_pass_phase %affine.lower_for_pass))
)))
(plugin_cond_phase
(%compile.matrix_plugin,
%compile.combined_phase
(%compile.phase_list
matrix_lower_phase
(plugin_cond_phase (%compile.direct_plugin, direct_phases))
(plugin_cond_phase (%compile.affine_plugin, %compile.single_pass_phase %affine.lower_for_pass)))))
(%compile.single_pass_phase %compile.internal_cleanup_pass)
(plugin_cond_phase (%compile.clos_plugin, clos_phases))
(%compile.single_pass_phase %compile.lam_spec_pass)
Expand All @@ -72,5 +73,4 @@
%compile.pass_list
(plugin_cond_pass (%compile.refly_plugin, %refly.remove_dbg_perm_pass))
))
)
};
);
20 changes: 20 additions & 0 deletions src/thorin/util/dbg.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
#include "thorin/util/dbg.h"

#include <fe/loc.cpp.h>

namespace thorin {

void Error::clear() {
num_errors_ = 0;
num_warnings_ = 0;
num_notes_ = 0;
msgs_.clear();
}

/// If errors occured, claim them and throw; if warnings occured, claim them and report to @p os.
void Error::ack(std::ostream& os) {
auto e = std::move(*this);
if (e.num_errors() != 0) throw e;
if (e.num_warnings() != 0) print(os, "{} warning(s) encountered\n{}", e.num_warnings(), e);
}

} // namespace thorin

0 comments on commit caf78d9

Please sign in to comment.