Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
643da00
Split code from closures
mshinwell Nov 15, 2019
cdaf893
Adapt Un_cps to let_code
lthls Dec 19, 2019
d225d11
Fix Code_id.code_symbol
lthls Dec 19, 2019
acb44b3
Remove commented code from tests8.ml
mshinwell Dec 20, 2019
817432c
Minor changes for code
mshinwell Dec 20, 2019
c2efc88
Remove middle_end/flambda2.0/types/basic/term_language_function_decla…
mshinwell Dec 20, 2019
b477fc0
Remove middle_end/flambda2.0/types/basic/term_language_function_decla…
mshinwell Dec 20, 2019
354963b
work
mshinwell Dec 30, 2019
724624e
terms
mshinwell Dec 31, 2019
8572790
terms
mshinwell Dec 31, 2019
e0a9f95
terms
mshinwell Dec 31, 2019
176afb3
terms
mshinwell Dec 31, 2019
35dfe82
terms
mshinwell Dec 31, 2019
1d15de1
terms
mshinwell Dec 31, 2019
4852ac1
terms
mshinwell Dec 31, 2019
4364f71
terms
mshinwell Dec 31, 2019
a1a8ea2
terms
mshinwell Dec 31, 2019
b995571
terms
mshinwell Jan 2, 2020
46e42ba
terms - compiles
mshinwell Jan 2, 2020
3d75d6f
terms - compiles
mshinwell Jan 2, 2020
1325228
terms - compiles
mshinwell Jan 2, 2020
615ecd2
terms - compiles
mshinwell Jan 2, 2020
2deb57d
terms - compiles
mshinwell Jan 2, 2020
1f87b2d
terms - compiles
mshinwell Jan 2, 2020
63ebe6a
terms - compiles
mshinwell Jan 2, 2020
4d920fe
terms - compiles
mshinwell Jan 2, 2020
a1f5e45
terms - compiles - inc new unboxing
mshinwell Jan 2, 2020
ab9a8a9
terms - compiles - inc new unboxing
mshinwell Jan 2, 2020
94c2c1e
deletion
mshinwell Jan 2, 2020
a2e22b0
free names / deletion
mshinwell Jan 2, 2020
9f5fcb9
free names / deletion
mshinwell Jan 2, 2020
7d6982f
free names / deletion
mshinwell Jan 2, 2020
566b2b1
free names / deletion
mshinwell Jan 3, 2020
eb76c4b
printing
mshinwell Jan 3, 2020
11953fb
printing
mshinwell Jan 3, 2020
cb05d6b
printing
mshinwell Jan 3, 2020
f74b5ce
printing
mshinwell Jan 3, 2020
9c745bc
work
mshinwell Jan 3, 2020
56629d6
work
mshinwell Jan 3, 2020
c08aa68
work
mshinwell Jan 3, 2020
8dd324b
SCC compiles
mshinwell Jan 3, 2020
6020ed9
SCC compiles
mshinwell Jan 3, 2020
0b91a92
work
mshinwell Jan 3, 2020
03f2811
Lifting
mshinwell Jan 6, 2020
007a152
Improve simplify_phys_equal
mshinwell Jan 6, 2020
61cbfc3
Improve exception handler annotation on continuations when printing
mshinwell Jan 6, 2020
a9950c4
Remove some useless let-bindings
mshinwell Jan 6, 2020
19904d5
Improve printing of Let_symbol
mshinwell Jan 6, 2020
53c40d3
Remove [Closure_element]
mshinwell Jan 6, 2020
238e139
Improve printing of Let_symbol
mshinwell Jan 6, 2020
7f3bac6
Revert a9950c411a02e3710efa9150f636278db50ca42b
mshinwell Jan 6, 2020
b5eb487
Constant sharing
mshinwell Jan 6, 2020
a231adf
Colours
mshinwell Jan 6, 2020
f5a5272
Indentation
mshinwell Jan 6, 2020
d217ebf
Colours
mshinwell Jan 6, 2020
1547823
Improved printing of Switch
mshinwell Jan 6, 2020
094ec60
Truncate long Debuginfo printing
mshinwell Jan 6, 2020
f2641ff
Formatting
mshinwell Jan 6, 2020
e540556
Improve error in Simplify_named
mshinwell Jan 6, 2020
b4b76fb
Fixing proving of closures
mshinwell Jan 6, 2020
6289655
Lifting
mshinwell Jan 6, 2020
76d2bd0
Various lifting fixes
mshinwell Jan 6, 2020
49e23f6
New example
mshinwell Jan 6, 2020
7ddccca
Add checks and fix bug in let-code
mshinwell Jan 7, 2020
6feae67
Improve diagnostic
mshinwell Jan 7, 2020
a6a0a1b
Unions
mshinwell Jan 7, 2020
a780c11
Fix for invariant check
mshinwell Jan 7, 2020
b1ef7cb
debugging
mshinwell Jan 7, 2020
c5ab772
comments
mshinwell Jan 7, 2020
e7d9179
Remove cruft from tests8
mshinwell Jan 7, 2020
cd6c6ef
Fix problem with invariant check when adding LCs
mshinwell Jan 7, 2020
3f5b478
Remove debug
mshinwell Jan 7, 2020
b48faa5
Fix?
mshinwell Jan 7, 2020
9b5f7cf
Don't forget [Var] deps for SCC
mshinwell Jan 9, 2020
4f98425
Fix Un_cps
lthls Jan 8, 2020
f16dcbd
Scope checks
lthls Jan 8, 2020
64a1fca
Address review comments
lthls Jan 8, 2020
418eb50
Get Compilation_unit correct for external symbols
mshinwell Jan 9, 2020
ef52394
Various fixes
mshinwell Jan 9, 2020
0b6b7db
Fixes for the Makefile build
lthls Jan 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,104 changes: 654 additions & 450 deletions .depend

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ _build

middle_end/flambda2.0/simplify/simplify.ml
middle_end/flambda2.0/terms/flambda.ml
middle_end/flambda2.0/types/flambda_type0.ml
middle_end/flambda2.0/types/flambda_type.ml

/ocamldoc/ocamldoc
/ocamldoc/ocamldoc.opt
Expand Down
48 changes: 28 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ INCLUDES=-I utils -I parsing -I typing -I bytecomp -I file_formats \
-I middle_end/flambda2.0/basic \
-I middle_end/flambda2.0/from_lambda \
-I middle_end/flambda2.0/inlining \
-I middle_end/flambda2.0/lifting \
-I middle_end/flambda2.0/naming \
-I middle_end/flambda2.0/parser \
-I middle_end/flambda2.0/simplify \
Expand Down Expand Up @@ -172,7 +173,9 @@ endif
ASMCOMP_FLAMBDA2=\
middle_end/flambda2.0/to_cmm/un_cps_helper.cmo \
middle_end/flambda2.0/to_cmm/un_cps_closure.cmo \
middle_end/flambda2.0/to_cmm/un_cps_result.cmo \
middle_end/flambda2.0/to_cmm/un_cps_env.cmo \
middle_end/flambda2.0/to_cmm/un_cps_static.cmo \
middle_end/flambda2.0/to_cmm/un_cps.cmo

ASMCOMP=\
Expand Down Expand Up @@ -227,13 +230,14 @@ MIDDLE_END_FLAMBDA2_COMPILENV_DEPS=\
middle_end/flambda2.0/compilenv_deps/symbol.cmo

MIDDLE_END_FLAMBDA2_BASIC=\
middle_end/flambda2.0/basic/closure_element.cmo \
middle_end/flambda2.0/basic/id_types.cmo \
middle_end/flambda2.0/basic/continuation.cmo \
middle_end/flambda2.0/basic/name.cmo \
middle_end/flambda2.0/basic/var_within_closure.cmo \
middle_end/flambda2.0/naming/name_mode.cmo \
middle_end/flambda2.0/naming/permutation.cmo \
middle_end/flambda2.0/naming/name_permutation.cmo \
middle_end/flambda2.0/basic/code_id.cmo \
middle_end/flambda2.0/naming/name_occurrences.cmo \
middle_end/flambda2.0/basic/immediate.cmo \
middle_end/flambda2.0/types/kinds/flambda_kind.cmo \
Expand All @@ -247,8 +251,7 @@ MIDDLE_END_FLAMBDA2_BASIC=\
middle_end/flambda2.0/basic/trap_action.cmo \
middle_end/flambda2.0/basic/exn_continuation.cmo \
middle_end/flambda2.0/basic/inline_attribute.cmo \
middle_end/flambda2.0/basic/id_types.cmo \
middle_end/flambda2.0/basic/code_id.cmo \
middle_end/flambda2.0/basic/code_id_or_symbol.cmo \
middle_end/flambda2.0/basic/coeffects.cmo \
middle_end/flambda2.0/basic/effects.cmo \
middle_end/flambda2.0/basic/export_id.cmo \
Expand Down Expand Up @@ -291,17 +294,16 @@ MIDDLE_END_FLAMBDA2_TYPES=\
middle_end/flambda2.0/types/basic/or_bottom_or_absorbing.cmo \
middle_end/flambda2.0/types/basic/or_unknown.cmo \
middle_end/flambda2.0/types/basic/or_unknown_or_bottom.cmo \
middle_end/flambda2.0/types/structures/code_age_relation.cmo \
middle_end/flambda2.0/types/structures/type_structure_intf.cmo \
middle_end/flambda2.0/types/structures/product_intf.cmo \
middle_end/flambda2.0/types/structures/row_like_maps_to_intf.cmo \
middle_end/flambda2.0/types/structures/set_of_closures_contents.cmo \
middle_end/flambda2.0/types/basic/tag_and_size.cmo \
middle_end/flambda2.0/types/basic/tag_or_unknown_and_size.cmo \
middle_end/flambda2.0/types/basic/term_language_function_declaration.cmo \
middle_end/flambda2.0/types/type_descr_intf.cmo \
middle_end/flambda2.0/types/type_head_intf.cmo \
middle_end/flambda2.0/types/flambda_type0.cmo \
middle_end/flambda2.0/types/type_system_intf.cmo \
middle_end/flambda2.0/types/flambda_type.cmo \
middle_end/flambda2.0/types/basic/unit.cmo \
middle_end/flambda2.0/types/basic/or_absorbing.cmo \
middle_end/flambda2.0/types/basic/closure_id_set.cmo \
Expand All @@ -312,10 +314,13 @@ MIDDLE_END_FLAMBDA2_TERMS=\
middle_end/flambda2.0/terms/apply_cont_expr.cmo \
middle_end/flambda2.0/terms/call_kind.cmo \
middle_end/flambda2.0/terms/apply_expr.cmo \
middle_end/flambda2.0/terms/function_declaration.cmo \
middle_end/flambda2.0/terms/function_declarations.cmo \
middle_end/flambda2.0/terms/set_of_closures.cmo \
middle_end/flambda2.0/terms/switch_expr.cmo \
middle_end/flambda2.0/types/flambda_type.cmo \
middle_end/flambda2.0/terms/flambda.cmo \
middle_end/flambda2.0/terms/flambda_static.cmo \
middle_end/flambda2.0/types/flambda_type.cmo
middle_end/flambda2.0/terms/flambda_unit.cmo

MIDDLE_END_FLAMBDA2_SIMPLIFY=\
middle_end/flambda2.0/simplify/env/continuation_use_kind.cmo \
Expand All @@ -330,12 +335,10 @@ MIDDLE_END_FLAMBDA2_SIMPLIFY=\
middle_end/flambda2.0/simplify/env/simplify_env_and_result.cmo \
middle_end/flambda2.0/simplify/env/downwards_acc.cmo \
middle_end/flambda2.0/simplify/env/upwards_acc.cmo \
middle_end/flambda2.0/inlining/inlining_cost.cmo \
middle_end/flambda2.0/inlining/inlining_decision.cmo \
middle_end/flambda2.0/inlining/inlining_transforms.cmo \
middle_end/flambda2.0/simplify/simplify_simple.cmo \
middle_end/flambda2.0/simplify/simplify_import.cmo \
middle_end/flambda2.0/unboxing/unbox_continuation_params.cmo \
middle_end/flambda2.0/lifting/sort_lifted_constants.cmo \
middle_end/flambda2.0/simplify/basic/reachable.cmo \
middle_end/flambda2.0/simplify/simplify_common.cmo \
middle_end/flambda2.0/simplify/simplify_variadic_primitive.cmo \
Expand All @@ -344,10 +347,13 @@ MIDDLE_END_FLAMBDA2_SIMPLIFY=\
middle_end/flambda2.0/simplify/simplify_ternary_primitive.cmo \
middle_end/flambda2.0/simplify/simplify_binary_primitive.cmo \
middle_end/flambda2.0/simplify/simplify_primitive.cmo \
middle_end/flambda2.0/inlining/inlining_cost.cmo \
middle_end/flambda2.0/inlining/inlining_decision.cmo \
middle_end/flambda2.0/inlining/inlining_transforms.cmo \
middle_end/flambda2.0/lifting/reification.cmo \
middle_end/flambda2.0/lifting/reify_continuation_param_types.cmo \
middle_end/flambda2.0/simplify/typing_helpers/continuation_handler_like_intf.cmo \
middle_end/flambda2.0/simplify/typing_helpers/reification.cmo \
middle_end/flambda2.0/utils/monad.cmo \
middle_end/flambda2.0/utils/top_closure.cmo \
middle_end/flambda2.0/simplify/simplify.cmo

MIDDLE_END_FLAMBDA2_FROM_LAMBDA=\
Expand Down Expand Up @@ -1281,15 +1287,15 @@ partialclean::

# Flambda2 recursive modules black magic

FLAMBDA_TYPE0_DEPS=$(shell sed "s|^|middle_end/flambda2.0/types/|g" \
FLAMBDA_TYPE_DEPS=$(shell sed "s|^|middle_end/flambda2.0/types/|g" \
middle_end/flambda2.0/types/rec_modules | tr '\n' ' ')
middle_end/flambda2.0/types/flambda_type0.ml: \
middle_end/flambda2.0/types/template/flambda_type0.templ.ml \
middle_end/flambda2.0/types/flambda_type.ml: \
middle_end/flambda2.0/types/template/flambda_type.templ.ml \
middle_end/flambda2.0/types/rec_modules \
$(FLAMBDA_TYPE0_DEPS)
$(FLAMBDA_TYPE_DEPS)
cd middle_end/flambda2.0/types && \
../scripts/assemble_rec_modules.sh template/flambda_type0.templ.ml \
rec_modules flambda_type0.ml
../scripts/assemble_rec_modules.sh template/flambda_type.templ.ml \
rec_modules flambda_type.ml

FLAMBDA_DEPS=$(shell sed "s|^|middle_end/flambda2.0/terms/|g" \
middle_end/flambda2.0/terms/rec_modules | tr '\n' ' ')
Expand All @@ -1312,7 +1318,7 @@ middle_end/flambda2.0/simplify/simplify.ml: \
rec_modules simplify.ml

beforedepend:: \
middle_end/flambda2.0/types/flambda_type0.ml \
middle_end/flambda2.0/types/flambda_type.ml \
middle_end/flambda2.0/terms/flambda.ml \
middle_end/flambda2.0/simplify/simplify.ml

Expand Down Expand Up @@ -1516,6 +1522,7 @@ partialclean::
middle_end/flambda2.0/basic \
middle_end/flambda2.0/from_lambda \
middle_end/flambda2.0/inlining \
middle_end/flambda2.0/lifting \
middle_end/flambda2.0/naming \
middle_end/flambda2.0/parser \
middle_end/flambda2.0/simplify \
Expand Down Expand Up @@ -1548,6 +1555,7 @@ depend: beforedepend
middle_end/flambda2.0/basic \
middle_end/flambda2.0/from_lambda \
middle_end/flambda2.0/inlining \
middle_end/flambda2.0/lifting \
middle_end/flambda2.0/naming \
middle_end/flambda2.0/parser \
middle_end/flambda2.0/simplify \
Expand Down
17 changes: 9 additions & 8 deletions asmcomp/asmgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ type middle_end2 =
ppf_dump:Format.formatter
-> prefixname:string
-> backend:(module Flambda2_backend_intf.S)
-> size:int
-> filename:string
-> module_ident:Ident.t
-> module_block_size_in_words:int
-> module_initializer:Lambda.lambda
-> Flambda_static.Program.t
-> Flambda_unit.t

let compile_implementation2 ?toplevel ~backend ~filename ~prefixname ~size
~module_ident ~module_initializer ~middle_end ~ppf_dump required_globals =
let compile_implementation2 ?toplevel ~backend ~filename ~prefixname
~size:module_block_size_in_words ~module_ident ~module_initializer
~middle_end ~ppf_dump required_globals =
let asmfile =
if !keep_asm_file || !Emitaux.binary_backend_available
then prefixname ^ ext_asm
Expand All @@ -199,10 +200,10 @@ let compile_implementation2 ?toplevel ~backend ~filename ~prefixname ~size
(fun () ->
Ident.Set.iter Compilenv.require_global required_globals;
let translated_program =
(middle_end : middle_end2) ~backend ~size ~filename ~prefixname
~ppf_dump ~module_ident ~module_initializer
(middle_end : middle_end2) ~backend ~module_block_size_in_words
~filename ~prefixname ~ppf_dump ~module_ident ~module_initializer
in
end_gen_implementation ?toplevel ~ppf_dump Un_cps.program
end_gen_implementation ?toplevel ~ppf_dump Un_cps.unit
translated_program)

let compile_implementation_flambda ?toplevel ~prefixname
Expand All @@ -216,7 +217,7 @@ let compile_implementation_flambda ?toplevel ~prefixname
(fun () ->
Ident.Set.iter Compilenv.require_global required_globals;
end_gen_implementation ?toplevel ~ppf_dump
Un_cps.program program)
Un_cps.unit program)

(* Error report *)

Expand Down
6 changes: 3 additions & 3 deletions asmcomp/asmgen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ type middle_end2 =
ppf_dump:Format.formatter
-> prefixname:string
-> backend:(module Flambda2_backend_intf.S)
-> size:int
-> filename:string
-> module_ident:Ident.t
-> module_block_size_in_words:int
-> module_initializer:Lambda.lambda
-> Flambda_static.Program.t
-> Flambda_unit.t

(** Compile an implementation from Lambda using the given middle end. *)
val compile_implementation2
Expand All @@ -66,7 +66,7 @@ val compile_implementation_flambda
-> prefixname:string
-> ppf_dump:Format.formatter
-> required_globals:Ident.Set.t
-> Flambda_static.Program.t
-> Flambda_unit.t
-> unit

val compile_phrase :
Expand Down
39 changes: 30 additions & 9 deletions driver/optcompile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,34 @@ let (|>>) (x, y) f = (x, f y)

(** Native compilation backend for .ml files. *)

(* XXX *)
module Flambda2_backend = struct
let symbol_for_global' ?comp_unit id =
let symbol_for_module_block id =
assert (Ident.global id);
assert (not (Ident.is_predef id));
let comp_unit =
match comp_unit with
| None -> Compilation_unit.get_current_exn ()
| Some comp_unit -> comp_unit
(* CR mshinwell: Get rid of this "caml" hack *)
Compilation_unit.create id
(Linkage_name.create ("caml" ^ Ident.name id))
in
Symbol.unsafe_create
comp_unit
(Linkage_name.create (Compilenv.symbol_for_global id))

let symbol_for_global' ?comp_unit id =
if Ident.global id && not (Ident.is_predef id) then
symbol_for_module_block id
else
let comp_unit =
match comp_unit with
| Some comp_unit -> comp_unit
| None ->
if Ident.is_predef id then Compilation_unit.predefined_exception ()
else Compilation_unit.get_current_exn ()
in
Symbol.unsafe_create
comp_unit
(Linkage_name.create (Compilenv.symbol_for_global id))

let closure_symbol _ = failwith "Not yet implemented"

let division_by_zero =
Expand All @@ -56,10 +72,15 @@ module Flambda2_backend = struct
Predef.ident_invalid_argument

let all_predefined_exception_symbols =
Symbol.Set.of_list [
division_by_zero;
invalid_argument;
] (* CR mshinwell: and the rest... *)
Predef.all_predef_exns
|> List.map (fun ident ->
symbol_for_global' ~comp_unit:(Compilation_unit.predefined_exception ())
ident)
|> Symbol.Set.of_list

let () =
assert (Symbol.Set.mem division_by_zero all_predefined_exception_symbols);
assert (Symbol.Set.mem invalid_argument all_predefined_exception_symbols)

let symbol_for_global' id : Symbol.t = symbol_for_global' id

Expand Down
11 changes: 11 additions & 0 deletions flambdatest/mlexamples/let_symbol_order_atexit.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type 'a ref = { mutable contents : 'a }
external ref : 'a -> 'a ref = "%makemutable"
external ( ! ) : 'a ref -> 'a = "%field0"
let id () = ()
external sys_exit : int -> 'a = "caml_sys_exit"
let exit_function = ref id
let do_at_exit () = (!exit_function) ()
let _at_exit _f = ()
let exit retcode =
do_at_exit ();
sys_exit retcode
31 changes: 31 additions & 0 deletions flambdatest/mlexamples/let_symbol_order_atexit.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(* val at_exit : (unit -> unit) -> unit *)

val exit : int -> 'a
val do_at_exit : unit -> unit
(*

(let
(id/7 = (function param/9 0a)
exit_function/11 = (makemutable 0 id/7)
do_at_exit/12 = (function param/14 (apply (field_mut 0 exit_function/11) 0a))
_at_exit/15 = (function _f/17 0a)
exit/18 = (function retcode/20[int] (seq (apply do_at_exit/12 0a) (caml_sys_exit retcode/20))))
(makeblock 0 exit/18 do_at_exit/12))

*)


(*

val do_at_exit : unit -> unit
val exit : int -> 'a

(let
(id/7 = (function param/9 0a)
exit_function/11 = (makemutable 0 id/7)
do_at_exit/12 = (function param/14 (apply (field_mut 0 exit_function/11) 0a))
_at_exit/15 = (function _f/17 0a)
exit/18 = (function retcode/20[int] (seq (apply do_at_exit/12 0a) (caml_sys_exit retcode/20))))
(makeblock 0 do_at_exit/12 exit/18))

*)
2 changes: 1 addition & 1 deletion flambdatest/mlexamples/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ let foo3 arr f i =
let f c m n x' y' =
let x = if c < 0 then x' else x' + 10 in
let y = if c < 0 then y' else y' + 20 in
x + y
x + y, 2L
12 changes: 12 additions & 0 deletions flambdatest/mlexamples/tests0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type t =
| A
| B of int
| C of int

let f () =
let x = A in
match x with
| A -> 0
| B _ -> 1
| C _ -> 2

3 changes: 3 additions & 0 deletions flambdatest/mlexamples/tests10.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(* needs -rectypes *)

let rec f () = f, f
7 changes: 7 additions & 0 deletions flambdatest/mlexamples/tests4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ let pr2162_1 z x y =
float_of_int a -. b
*)

let pr2162_2_first z x y =
let a, b =
if z then (x * 2, y *. 3.)
else (x, y +. 0.)
in
float_of_int a -. b

let pr2162_2 z x y =
let a, b =
if z then (x * 2, y *. 3.)
Expand Down
Loading