Skip to content

Simpler symbols #753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3fc7890
Squashed 'ocaml/' changes from 0b0aefb59..b7ec31d47
lukemaurer Jul 26, 2022
600e860
Merge symbol patch into ocaml-jst
lukemaurer Jul 26, 2022
642573e
Adapt symbols patch to flambda2
lukemaurer Jul 27, 2022
ce4436c
Remove `comp_unit` optional argument from `Flambda.global_for_symbol`
lukemaurer Aug 1, 2022
c3dd1d7
Formatting
lukemaurer Aug 1, 2022
8f3ba20
Add missing .cmx file in compiler-libs
lukemaurer Aug 3, 2022
4071a6c
Code review
lukemaurer Aug 5, 2022
46c1194
More fixes for .cinaps as module name
lukemaurer Aug 5, 2022
4af79b9
A bit more code review
lukemaurer Aug 5, 2022
6c38fde
Merge remote-tracking branch 'upstream/main' into simpler-symbols
lukemaurer Aug 5, 2022
d0ff3dd
Compilation fixes
lukemaurer Aug 5, 2022
4804b8b
Merge remote-tracking branch 'upstream/main' into simpler-symbols
lukemaurer Aug 31, 2022
b4b15a8
Fix upstream build and tests
lukemaurer Sep 5, 2022
8d625d0
Code review; re-use `Symbol_utils` in `ocaml/`
lukemaurer Sep 5, 2022
5983c95
Fix `flambda2_import` artifacts in Dune
lukemaurer Sep 5, 2022
7cfafe7
Merge remote-tracking branch 'upstream/main' into simpler-symbols
lukemaurer Sep 21, 2022
976e46d
Code review
lukemaurer Sep 22, 2022
df8dbe1
Fix upstream build
lukemaurer Sep 22, 2022
2a332f4
Merge remote-tracking branch 'upstream/main' into simpler-symbols
lukemaurer Sep 22, 2022
39d6cd0
Remove comment and allow nested packs
lukemaurer Sep 27, 2022
58c7b3e
Revert change that broke dynlink
lukemaurer Sep 28, 2022
53b9498
Put back the `dynlink_nat.c` change and fix `Opttoploop` instead
lukemaurer Sep 28, 2022
589dc7c
Merge remote-tracking branch 'upstream/main' into simpler-symbols
lukemaurer Oct 3, 2022
47b8e86
Cleanups
lukemaurer Oct 3, 2022
2e1680f
Minor code review things
mshinwell Oct 4, 2022
2647aa5
Sync with `ocaml/`
lukemaurer Oct 6, 2022
70d29ed
Merge remote-tracking branch 'upstream/main' into simpler-symbols
lukemaurer Oct 7, 2022
a0714f9
Fix merge error
lukemaurer Oct 7, 2022
031be74
Fix build error after merge
lukemaurer Oct 7, 2022
138926e
More synching with `ocaml/`
lukemaurer Oct 7, 2022
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
10 changes: 5 additions & 5 deletions backend/amd64/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ let emit_float_constant f lbl =
D.qword (Const f)

let emit_global_label s =
let lbl = Compilenv.make_symbol (Some s) in
let lbl = Cmm_helpers.make_symbol s in
add_def_symbol lbl;
let lbl = emit_symbol lbl in
D.global lbl;
Expand Down Expand Up @@ -577,7 +577,7 @@ type probe =

let probe_handler_wrapper_name probe_label =
let w = Printf.sprintf "probe_wrapper_%d" probe_label in
Compilenv.make_symbol (Some w)
Cmm_helpers.make_symbol w
|> emit_symbol

let probes = ref []
Expand Down Expand Up @@ -1327,7 +1327,7 @@ let begin_assembly ~init_dwarf =
D.data ();
emit_global_label "data_begin";

emit_named_text_section (Compilenv.make_symbol (Some "code_begin"));
emit_named_text_section (Cmm_helpers.make_symbol "code_begin");
emit_global_label "code_begin";
if system = S_macosx then I.nop (); (* PR#4690 *)
()
Expand Down Expand Up @@ -1641,7 +1641,7 @@ let end_assembly dwarf =
(* Emit probe handler wrappers *)
List.iter emit_probe_handler_wrapper !probes;

emit_named_text_section (Compilenv.make_symbol (Some "code_end"));
emit_named_text_section (Cmm_helpers.make_symbol "code_end");
if system = S_macosx then I.nop ();
(* suppress "ld warning: atom sorting error" *)

Expand Down Expand Up @@ -1686,7 +1686,7 @@ let end_assembly dwarf =
};

if system = S_linux then begin
let frametable = emit_symbol (Compilenv.make_symbol (Some "frametable")) in
let frametable = emit_symbol (Cmm_helpers.make_symbol "frametable") in
D.size frametable (ConstSub (ConstThis, ConstLabel frametable))
end;

Expand Down
10 changes: 5 additions & 5 deletions backend/arm64/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,28 +1089,28 @@ let data l =
let begin_assembly ~init_dwarf:_ =
reset_debug_info();
` .file \"\"\n`; (* PR#7037 *)
let lbl_begin = Compilenv.make_symbol (Some "data_begin") in
let lbl_begin = Cmm_helpers.make_symbol "data_begin" in
` .data\n`;
` .globl {emit_symbol lbl_begin}\n`;
`{emit_symbol lbl_begin}:\n`;
let lbl_begin = Compilenv.make_symbol (Some "code_begin") in
let lbl_begin = Cmm_helpers.make_symbol "code_begin" in
emit_named_text_section lbl_begin;
` .globl {emit_symbol lbl_begin}\n`;
`{emit_symbol lbl_begin}:\n`

let end_assembly _dwarf =
let lbl_end = Compilenv.make_symbol (Some "code_end") in
let lbl_end = Cmm_helpers.make_symbol "code_end" in
emit_named_text_section lbl_end;
` .globl {emit_symbol lbl_end}\n`;
`{emit_symbol lbl_end}:\n`;
let lbl_end = Compilenv.make_symbol (Some "data_end") in
let lbl_end = Cmm_helpers.make_symbol "data_end" in
` .data\n`;
` .quad 0\n`; (* PR#6329 *)
` .globl {emit_symbol lbl_end}\n`;
`{emit_symbol lbl_end}:\n`;
` .quad 0\n`;
` .align 3\n`; (* #7887 *)
let lbl = Compilenv.make_symbol (Some "frametable") in
let lbl = Cmm_helpers.make_symbol "frametable" in
` .globl {emit_symbol lbl}\n`;
`{emit_symbol lbl}:\n`;
emit_frames
Expand Down
47 changes: 25 additions & 22 deletions backend/asmgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open Dwarf_ocaml

type error =
| Assembler_error of string
| Mismatched_for_pack of string option
| Mismatched_for_pack of Compilation_unit.Prefix.t
| Asm_generation of string * Emitaux.error

exception Error of error
Expand Down Expand Up @@ -68,15 +68,13 @@ let should_save_cfg_before_emit () =
should_save_ir_after Compiler_pass.Simplify_cfg && (not !start_from_emit)

let linear_unit_info =
{ Linear_format.unit_name = "";
{ Linear_format.unit = Compilation_unit.dummy;
items = [];
for_pack = None;
}

let new_cfg_unit_info () =
{ Cfg_format.unit_name = "";
{ Cfg_format.unit = Compilation_unit.dummy;
items = [];
for_pack = None;
}

let cfg_unit_info = new_cfg_unit_info ()
Expand All @@ -92,20 +90,17 @@ let reset () =
start_from_emit := false;
Compiler_pass_map.iter (fun pass (cfg_unit_info : Cfg_format.cfg_unit_info) ->
if should_save_ir_after pass then begin
cfg_unit_info.unit_name <- Compilenv.current_unit_name ();
cfg_unit_info.unit <- Compilation_unit.get_current_exn ();
cfg_unit_info.items <- [];
cfg_unit_info.for_pack <- !Clflags.for_package;
end)
pass_to_cfg;
if should_save_before_emit () then begin
linear_unit_info.unit_name <- Compilenv.current_unit_name ();
linear_unit_info.unit <- Compilation_unit.get_current_exn ();
linear_unit_info.items <- [];
linear_unit_info.for_pack <- !Clflags.for_package;
end;
if should_save_cfg_before_emit () then begin
cfg_unit_info.unit_name <- Compilenv.current_unit_name ();
cfg_unit_info.unit <- Compilation_unit.get_current_exn ();
cfg_unit_info.items <- [];
cfg_unit_info.for_pack <- !Clflags.for_package;
end

let save_data dl =
Expand Down Expand Up @@ -500,13 +495,17 @@ let compile_unit ~output_prefix ~asm_filename ~keep_asm ~obj_filename ~may_reduc

let build_dwarf ~asm_directives:(module Asm_directives : Asm_targets.Asm_directives_intf.S) sourcefile =
let unit_name =
Compilation_unit.get_persistent_ident (Compilation_unit.get_current_exn ())
(* CR lmaurer: This doesn't actually need to be an [Ident.t] *)
Symbol.for_current_unit ()
|> Symbol.linkage_name
|> Linkage_name.to_string
|> Ident.create_persistent
in
let code_begin =
Compilenv.make_symbol (Some "code_begin") |> Asm_targets.Asm_symbol.create
Cmm_helpers.make_symbol "code_begin" |> Asm_targets.Asm_symbol.create
in
let code_end =
Compilenv.make_symbol (Some "code_end") |> Asm_targets.Asm_symbol.create
Cmm_helpers.make_symbol "code_end" |> Asm_targets.Asm_symbol.create
in
Dwarf.create
~sourcefile
Expand Down Expand Up @@ -657,10 +656,12 @@ let compile_implementation_flambda2 unix ?toplevel ?(keep_symbol_tables=true)
let linear_gen_implementation unix filename =
let open Linear_format in
let linear_unit_info, _ = restore filename in
(match !Clflags.for_package, linear_unit_info.for_pack with
| None, None -> ()
| Some expected, Some saved when String.equal expected saved -> ()
| _, saved -> raise(Error(Mismatched_for_pack saved)));
let current_package = Compilation_unit.Prefix.from_clflags () in
let saved_package =
Compilation_unit.for_pack_prefix linear_unit_info.unit
in
if not (Compilation_unit.Prefix.equal current_package saved_package)
then raise(Error(Mismatched_for_pack saved_package));
let emit_item ~dwarf = function
| Data dl -> emit_data dl
| Func f -> emit_fundecl ~dwarf f
Expand All @@ -687,13 +688,15 @@ let report_error ppf = function
fprintf ppf "Assembler error, input left in file %a"
Location.print_filename file
| Mismatched_for_pack saved ->
let msg = function
| None -> "without -for-pack"
| Some s -> "with -for-pack "^s
let msg prefix =
if Compilation_unit.Prefix.is_empty prefix
then "without -for-pack"
else "with -for-pack " ^ Compilation_unit.Prefix.to_string prefix
in
fprintf ppf
"This input file cannot be compiled %s: it was generated %s."
(msg !Clflags.for_package) (msg saved)
(msg (Compilation_unit.Prefix.from_clflags ()))
(msg saved)
| Asm_generation(fn, err) ->
fprintf ppf
"Error producing assembly code for %s: %a"
Expand Down
2 changes: 1 addition & 1 deletion backend/asmgen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ val compile_phrase

type error =
| Assembler_error of string
| Mismatched_for_pack of string option
| Mismatched_for_pack of Compilation_unit.Prefix.t
| Asm_generation of string * Emitaux.error

exception Error of error
Expand Down
3 changes: 1 addition & 2 deletions backend/asmlibrarian.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ let create_archive file_list lib_name =
let units =
List.map (fun (unit, crc) ->
Cmm_helpers.Generic_fns_tbl.add genfns unit.ui_generic_fns;
{ li_name = unit.ui_name;
li_symbol = unit.ui_symbol;
{ li_name = unit.ui_unit;
li_crc = crc;
li_defines = unit.ui_defines;
li_force_link = unit.ui_force_link;
Expand Down
Loading