-
Notifications
You must be signed in to change notification settings - Fork 89
Backend_impl / Compilenv changes for Flambda 2 #97
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(include_subdirs no) | ||
|
||
(library | ||
(name flambda2_backend_intf) | ||
(wrapped false) | ||
(flags (:standard -principal -nostdlib -open Flambda2)) | ||
(libraries stdlib ocamlcommon ocamlbytecomp ocamloptcomp | ||
flambda2_compilenv_deps flambda2) | ||
) |
126 changes: 126 additions & 0 deletions
126
middle_end/flambda2/backend_intf/flambda2_backend_impl.ml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* OCaml *) | ||
(* *) | ||
(* Pierre Chambart, OCamlPro *) | ||
(* Mark Shinwell and Leo White, Jane Street Europe *) | ||
(* *) | ||
(* Copyright 2013--2021 OCamlPro SAS *) | ||
(* Copyright 2014--2021 Jane Street Group LLC *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of *) | ||
(* the GNU Lesser General Public License version 2.1, with the *) | ||
(* special exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
[@@@ocaml.warning "+a-30-40-41-42"] | ||
|
||
module Flambda1_compilation_unit = Compilation_unit | ||
mshinwell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
module Flambda1_linkage_name = Linkage_name | ||
|
||
module Compilation_unit = struct | ||
include Flambda2_compilenv_deps.Compilation_unit | ||
|
||
let of_flambda1_compilation_unit comp_unit = | ||
let ident = Flambda1_compilation_unit.get_persistent_ident comp_unit in | ||
let linkage_name = | ||
comp_unit | ||
|> Flambda1_compilation_unit.get_linkage_name | ||
|> Flambda1_linkage_name.to_string | ||
|> Flambda2_compilenv_deps.Linkage_name.create | ||
in | ||
create ident linkage_name | ||
end | ||
|
||
module Linkage_name = Flambda2_compilenv_deps.Linkage_name | ||
module Symbol = Flambda2_compilenv_deps.Symbol | ||
|
||
let symbol_for_module_block id = | ||
assert (Ident.global id); | ||
assert (not (Ident.is_predef id)); | ||
let comp_unit = | ||
Compilenv.unit_for_global id | ||
|> Compilation_unit.of_flambda1_compilation_unit | ||
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 find_predef_exn name = | ||
let matches ident = String.equal (Ident.name ident) name in | ||
match List.find matches Predef.all_predef_exns with | ||
| exception Not_found -> | ||
Misc.fatal_errorf "Cannot find predef exn '%s'" name | ||
| ident -> ident | ||
|
||
let division_by_zero = | ||
symbol_for_global' | ||
~comp_unit:(Compilation_unit.predefined_exception ()) | ||
Predef.ident_division_by_zero | ||
|
||
let invalid_argument = | ||
symbol_for_global' | ||
~comp_unit:(Compilation_unit.predefined_exception ()) | ||
(find_predef_exn "Invalid_argument") | ||
|
||
let all_predefined_exception_symbols = | ||
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 | ||
|
||
let size_int = Arch.size_int | ||
let big_endian = Arch.big_endian | ||
|
||
let max_sensible_number_of_arguments = | ||
Proc.max_arguments_for_tailcalls - 1 | ||
|
||
let set_global_info info = Compilenv.flambda2_set_export_info info | ||
|
||
let get_global_info comp_unit = | ||
(* The Flambda simplifier should have returned the typing information | ||
for the predefined exception compilation unit before getting here. *) | ||
assert (not (Compilation_unit.is_predefined_exception comp_unit)); | ||
if Compilation_unit.is_external_symbols comp_unit then None | ||
else | ||
let id = | ||
(* CR mshinwell: Unsure how to construct this properly. Also see CR | ||
in Closure_conversion about the linkage names of module blocks *) | ||
Compilation_unit.get_persistent_ident comp_unit | ||
in | ||
match Compilenv.get_global_info' id with | ||
| None | Some (Flambda2 None) -> None | ||
| Some (Flambda2 (Some info)) -> Some info | ||
| Some (Clambda _) -> | ||
(* CR mshinwell: This should be a user error, not a fatal error. | ||
Same below. *) | ||
Misc.fatal_errorf "The .cmx file for unit %a was compiled with \ | ||
the Closure middle-end, not Flambda 2, and cannot be loaded" | ||
Compilation_unit.print comp_unit | ||
| Some (Flambda1 _) -> | ||
Misc.fatal_errorf "The .cmx file for unit %a was compiled with \ | ||
the Flambda 1 middle-end, not Flambda 2, and cannot be loaded" | ||
Compilation_unit.print comp_unit |
19 changes: 19 additions & 0 deletions
19
middle_end/flambda2/backend_intf/flambda2_backend_impl.mli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* OCaml *) | ||
(* *) | ||
(* Pierre Chambart, OCamlPro *) | ||
(* Mark Shinwell and Leo White, Jane Street Europe *) | ||
(* *) | ||
(* Copyright 2013--2021 OCamlPro SAS *) | ||
(* Copyright 2014--2021 Jane Street Group LLC *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of *) | ||
(* the GNU Lesser General Public License version 2.1, with the *) | ||
(* special exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
[@@@ocaml.warning "+a-30-40-41-42"] | ||
|
||
include Flambda_backend_intf.S |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.