Skip to content

Commit

Permalink
Improve handling of escaping procedures (type 'any' return)
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Dec 29, 2022
1 parent 3739b2c commit 9a96192
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/compiler/flx_cpp_backend/flx_gen_exe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,16 @@ print_endline ("gen_exe: " ^ string_of_bexe bsym_table 0 exe);
code

| BEXE_fun_return (sr,e) ->

begin match e with
| BEXPR_varname _,BTYP_fix (0,_) ->
" // elide return of variable of type any\n"

| BEXPR_coerce ( (BEXPR_varname _,BTYP_fix (0,_)),_),_ ->
" // elide return of coerced variable of type any\n"

| _ ->

let _,t = e in
(if with_comments then
" //" ^ src_str ^ ": type "^tn t^"\n"
Expand All @@ -833,6 +843,7 @@ print_endline ("gen_exe: " ^ string_of_bexe bsym_table 0 exe);
| BTYP_fix (0,_) -> " "^ge sr e^"; // non-returning\n"
| _ -> " return "^ge sr e^"; // "^tn t^ "\n"
end
end

| BEXE_nop (_,s) -> " //Nop: " ^ s ^ "\n"

Expand Down
19 changes: 17 additions & 2 deletions src/compiler/flx_opt/flx_special_inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,27 @@ open Flx_use
open Flx_util
open Flx_bid

(* Returns and expression e in which subexpressions are replaced by variables,
(* UNRAVEL an expression.
Returns an expression e in which subexpressions are replaced by variables,
and the variables are initialised in the executable instructions,
so the exe containing this expression, after replacement, has to run
after the exes it returns.
The exes returned are in reverse order. Called by Flx_inline_calls.
ISSUE: this routine leads to a screwup if an expression has type 'any'
which means it doesn't return. In this case the evaluation is assigned
to a variable, but the back end throws the initialisation out.
So the variable never gets set. This is fine, because if we escaped
any use of the variable won't happen, because the use has to happen
AFTER the initialisation (temporaly).
Unfortunately we seem to end up returning an *undefined* variable in the
generated C++, which has the type of the returning branch of a
conditional. It's NOT clear to me how the variable is considered used,
and is in the symbol table, but doesn't get defined.
*)
let special_inline syms uses bsym_table caller heavily_inline_bbdcl hic excludes sr e =
let nth ls n = try List.nth ls n with _ ->
Expand Down Expand Up @@ -297,7 +312,7 @@ print_endline ("New expr = " ^ sbe bsym_table e' ^ " type " ^ sbt bsym_table (sn
let rxs = hic revariable callee xs in
exes' := rev rxs @ !exes';
(*
print_endline ("new var type " ^ sbt bsym_table t);
print_endline ("new var '"^urvid^"' type " ^ sbt bsym_table t);
*)
bexpr_varname t (urv,[])
end
Expand Down

0 comments on commit 9a96192

Please sign in to comment.