Skip to content

Commit

Permalink
Fix segfault + insert fn decl dummy node
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Nov 8, 2021
1 parent 2497669 commit 4683a26
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
52 changes: 26 additions & 26 deletions src/compiler/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,32 @@ namespace backend {

// Stage 7, jump fix
auto mod = DeviceModule(ctx);
// p.measure("Jump Fix", [&] {
// auto old_instr = std::move(instr);

// int err = futhark_entry_backend_fix_jumps(
// ctx,
// &instr,
// &mod.func_id,
// &mod.func_start,
// &mod.func_size,
// instr,
// functab
// );
// if(err)
// throw futhark::Error(ctx);
// });

// // Stage 8, postprocess
// p.measure("postprocess", [&] {
// int err = futhark_entry_backend_postprocess(
// ctx,
// &mod.instructions,
// instr
// );
// if(err)
// throw futhark::Error(ctx);
// });
p.measure("Jump Fix", [&] {
auto old_instr = std::move(instr);

int err = futhark_entry_backend_fix_jumps(
ctx,
&instr,
&mod.func_id,
&mod.func_start,
&mod.func_size,
old_instr,
functab
);
if(err)
throw futhark::Error(ctx);
});

// Stage 8, postprocess
p.measure("postprocess", [&] {
int err = futhark_entry_backend_postprocess(
ctx,
&mod.instructions,
instr
);
if(err)
throw futhark::Error(ctx);
});

return mod;
}
Expand Down
1 change: 1 addition & 0 deletions src/compiler/bridge.fut
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type front_node_data_type = u32
let NODE_TYPE_LOOKUP = mk_production_array node_type_invalid [
(production_fn_decl_list, node_type_statement_list),
(production_fn_decl, node_type_func_decl),
(production_fn_decl_dummy, node_type_func_decl_dummy),
(production_stat_while, node_type_while_stat),
(production_stat_if, node_type_if_stat),
(production_stat_expr, node_type_expr_stat),
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ namespace frontend {

p.measure("check convergence", [&]{
bool valid;
int err = futhark_entry_frontend_check_convergence(ctx, &valid, node_types, parents, prev_siblings, data_types);
int err = futhark_entry_frontend_check_convergence(ctx, &valid, node_types, parents, prev_siblings);
if (err)
throw futhark::Error(ctx);
if (!valid)
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/frontend.fut
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ entry resolve_data_types [n] (node_types: [n]production.t) (parents: [n]i32) (pr
entry check_return_types [n] (node_types: [n]production.t) (parents: [n]i32) (data_types: [n]data_type): bool =
check_return_types node_types parents data_types

entry check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32) (data_types: [n]data_type): bool =
check_return_paths node_types parents prev_siblings data_types
entry check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32): bool =
check_return_paths node_types parents prev_siblings

entry build_ast [n]
(node_types: *[n]production.t)
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/main.fut
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ entry frontend_resolve_data_types [n] (node_types: [n]production.t) (parents: [n
entry frontend_check_return_types [n] (node_types: [n]production.t) (parents: [n]i32) (data_types: [n]data_type): bool =
frontend.check_return_types node_types parents data_types

entry frontend_check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32) (data_types: [n]data_type): bool =
frontend.check_convergence node_types parents prev_siblings data_types
entry frontend_check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32): bool =
frontend.check_convergence node_types parents prev_siblings

entry frontend_build_ast [n]
(node_types: *[n]production.t)
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/parser/pareas.g
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ start -> fn_decl_list;
fn_decl_list -> fn_decl fn_decl_list;
fn_decl_list [fn_decl_list_end] -> ;

fn_decl -> 'fn' expr compound_stat;
fn_decl -> 'fn' fn_decl_dummy expr compound_stat;

fn_decl_dummy -> ;

type [type_int] -> 'int';
type [type_float] -> 'float';
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/passes/check_return_paths.fut
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ local let iter [n] (expr: [n]bool_expr_node): [n]bool_expr_node =
-- | As type resolving works by first computing a type that is valid for the expression if the program is valid,
-- we cannot also check whether all paths in a function return a value, as this would require picking the child with the
-- right value when analysing an `if_else` node. Instead, this check is performed separately in this pass.
let check_return_paths [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32) (data_types: [n]data_type.t) =
let check_return_paths [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32): bool =
-- The children of each node are going to be its first child and its sibling, so compute those.
let next_siblings = invert prev_siblings
let first_childs =
Expand All @@ -71,7 +71,7 @@ let check_return_paths [n] (node_types: [n]production.t) (parents: [n]i32) (prev
else if node_types[parent] == production_stat_if_else && nty == production_stat_list && next_sibling != -1 then #and
-- Cannot guarantee these types returning, so return false from these.
else if node_types[parent] == production_stat_if || node_types[parent] == production_stat_while then #false
else if nty == production_fn_decl then #true
else if nty == production_fn_decl then #and
-- The return type of a void function maps to true as these don't need to end every path with a return statement.
else if nty == production_type_void && node_types[parent] == production_fn_decl then #true
else #or)
Expand Down

0 comments on commit 4683a26

Please sign in to comment.