Skip to content

Commit c1cc39e

Browse files
committed
make compilation context state invariant explicit, fix some potential bugs, clean up
1 parent a488d60 commit c1cc39e

11 files changed

+363
-415
lines changed

jscomp/core/js_output.ml

+13-19
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,32 @@ let dummy =
5050

5151
let output_of_expression
5252
(continuation : continuation)
53-
(should_return : Lam_compile_context.return_type)
5453
(lam : Lam.t) (exp : J.expression) : t =
55-
begin match continuation, should_return with
56-
| EffectCall, ReturnFalse ->
54+
begin match continuation with
55+
| EffectCall ReturnFalse ->
5756
if Lam_analysis.no_side_effects lam
5857
then dummy
5958
else {block = []; value = Some exp ; output_finished = False}
60-
| Declare (kind, n), ReturnFalse ->
59+
| Declare (kind, n)->
6160
make [ S.define_variable ~kind n exp]
62-
| Assign n ,ReturnFalse ->
61+
| Assign n ->
6362
make [S.assign n exp ]
64-
| EffectCall, ReturnTrue _ ->
63+
| EffectCall (ReturnTrue _) ->
6564
make [S.return_stmt exp] ~output_finished:True
66-
| (Declare _ | Assign _ ), ReturnTrue _ ->
67-
make [S.unknown_lambda lam] ~output_finished:True
68-
| NeedValue, _ ->
65+
| NeedValue _ ->
6966
{block = []; value = Some exp; output_finished = False }
7067
end
7168

7269
let output_of_block_and_expression
7370
(continuation : continuation)
74-
(should_return : Lam_compile_context.return_type)
75-
(lam : Lam.t) (block : J.block) exp : t =
76-
match continuation, should_return with
77-
| EffectCall, ReturnFalse -> make block ~value:exp
78-
| Declare (kind,n), ReturnFalse ->
71+
(block : J.block) exp : t =
72+
match continuation with
73+
| EffectCall ReturnFalse -> make block ~value:exp
74+
| Declare (kind,n) ->
7975
make (block @ [ S.define_variable ~kind n exp])
80-
| Assign n, ReturnFalse -> make (block @ [S.assign n exp])
81-
| EffectCall, ReturnTrue _ -> make (block @ [S.return_stmt exp]) ~output_finished:True
82-
| (Declare _ | Assign _), ReturnTrue _ ->
83-
make [S.unknown_lambda lam] ~output_finished:True
84-
| NeedValue, (ReturnTrue _ | ReturnFalse) ->
76+
| Assign n -> make (block @ [S.assign n exp])
77+
| EffectCall (ReturnTrue _) -> make (block @ [S.return_stmt exp]) ~output_finished:True
78+
| NeedValue (ReturnTrue _ | ReturnFalse) ->
8579
make block ~value:exp
8680

8781

jscomp/core/js_output.mli

-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ val dummy : t
8989

9090
val output_of_expression :
9191
Lam_compile_context.continuation ->
92-
Lam_compile_context.return_type ->
9392
Lam.t -> (* original lambda *)
9493
J.expression -> (* compiled expression *)
9594
t
@@ -98,8 +97,6 @@ val output_of_expression :
9897
*)
9998
val output_of_block_and_expression :
10099
Lam_compile_context.continuation ->
101-
Lam_compile_context.return_type ->
102-
Lam.t ->
103100
J.block ->
104101
J.expression ->
105102
t

0 commit comments

Comments
 (0)