Skip to content

Commit 77c8197

Browse files
cknittclaude
andcommitted
Give platform variants distinct source names and mark forward-ref hooks live
The native and playground variants of a platform module were copied to the same name, so their .cmt locations shared one source path and reanalyze could not tell their declarations apart (it now warns about that). The copy rules use copy#, whose line directive makes locations name platform/native/... or platform/playground/... instead. type_open_, default_error_reporter and record_deprecated_used are called through forward references (Typecore.type_open, error_reporter, Cmt_utils.record_deprecated_used) with optional arguments reanalyze cannot trace, so they are marked [@LiVe] with a comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gLDo8mBJKpNE25WAwT Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 23a70a9 commit 77c8197

9 files changed

Lines changed: 24 additions & 12 deletions

File tree

‎compiler/AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ The Dune `browser` profile builds the playground compiler. Platform-dependent
4545
modules are stored below `platform/native/` and `platform/playground/` in their
4646
owning compiler directory. Rules in that directory's `dune` file copy the
4747
selected implementation into the build directory as an ordinary `.ml` module;
48-
all other profiles select the native source. Generated module paths in errors
49-
or stack traces therefore map back to one of those two source directories.
48+
all other profiles select the native source. The rules use `copy#`, whose line
49+
directive makes locations (in errors, stack traces and `.cmt` files) name the
50+
platform source itself, so the two variants never share source positions.
5051

5152
## Working on the Compiler
5253

‎compiler/core/dune‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
(enabled_if
66
(= %{profile} browser))
77
(action
8-
(copy platform/playground/js_name_of_module_id.ml js_name_of_module_id.ml)))
8+
(copy# platform/playground/js_name_of_module_id.ml js_name_of_module_id.ml)))
99

1010
(rule
1111
(target js_name_of_module_id.ml)
1212
(enabled_if
1313
(<> %{profile} browser))
1414
(action
15-
(copy platform/native/js_name_of_module_id.ml js_name_of_module_id.ml)))
15+
(copy# platform/native/js_name_of_module_id.ml js_name_of_module_id.ml)))
1616

1717
(library
1818
(name core)

‎compiler/ext/dune‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(enabled_if
66
(= %{profile} browser))
77
(action
8-
(copy
8+
(copy#
99
platform/playground/ext_platform_primitives.ml
1010
ext_platform_primitives.ml)))
1111

@@ -14,7 +14,7 @@
1414
(enabled_if
1515
(<> %{profile} browser))
1616
(action
17-
(copy
17+
(copy#
1818
platform/native/ext_platform_primitives.ml
1919
ext_platform_primitives.ml)))
2020

‎compiler/ml/cmt_format_common.ml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ let add_saved_type b =
156156
let get_saved_types () = (current_accumulators ()).saved_types
157157
let set_saved_types l = (current_accumulators ()).saved_types <- l
158158

159-
let record_deprecated_used ?deprecated_context ?migration_template
159+
(* Live: called through a forward reference ({!Cmt_utils.record_deprecated_used}) with optional
160+
arguments that reanalyze cannot trace. *)
161+
let[@live] record_deprecated_used ?deprecated_context ?migration_template
160162
?migration_in_pipe_chain_template source_loc =
161163
let state = current_accumulators () in
162164
state.deprecated_used <-

‎compiler/ml/dune‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(enabled_if
66
(= %{profile} browser))
77
(action
8-
(copy
8+
(copy#
99
platform/playground/cmt_format_persistence.ml
1010
cmt_format_persistence.ml)))
1111

@@ -14,7 +14,7 @@
1414
(enabled_if
1515
(<> %{profile} browser))
1616
(action
17-
(copy platform/native/cmt_format_persistence.ml cmt_format_persistence.ml)))
17+
(copy# platform/native/cmt_format_persistence.ml cmt_format_persistence.ml)))
1818

1919
(library
2020
(name ml)

‎compiler/ml/location.ml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ let error_of_exn exn =
237237

238238
(* taken from https://github.com/rescript-lang/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/parsing/location.ml#L380 *)
239239
(* This is the error report entry point. We'll replace the default reporter with this one. *)
240-
let rec default_error_reporter ?(custom_intro = None) ?(src = None) ppf
240+
(* Live: called through a forward reference ({!error_reporter}) with optional
241+
arguments that reanalyze cannot trace. *)
242+
let[@live] rec default_error_reporter ?(custom_intro = None) ?(src = None) ppf
241243
{loc; msg; sub} =
242244
setup_colors ();
243245
(* open a vertical box. Everything in our message is indented 2 spaces *)

‎compiler/ml/location.mli‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ val default_error_reporter :
107107
formatter ->
108108
error ->
109109
unit
110-
(** Original error reporter for use in hooks. *)
110+
[@@live]
111+
(** Original error reporter for use in hooks. Live: called through
112+
{!error_reporter} with optional arguments that reanalyze cannot trace. *)
111113

112114
val report_exception : formatter -> exn -> unit
113115
(** Reraise the exception if it is unknown. *)

‎compiler/ml/typemod.ml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ let extract_sig_open env loc mty =
8686

8787
(* Compute the environment after opening a module *)
8888

89-
let type_open_ ?used_slot ovf env loc lid =
89+
(* Live: called through a forward reference ({!Typecore.type_open}) with optional
90+
arguments that reanalyze cannot trace. *)
91+
let[@live] type_open_ ?used_slot ovf env loc lid =
9092
let path = Typetexp.lookup_module ~load:true env lid.loc lid.txt in
9193
match Env.open_signature ~loc ?used_slot ovf path env with
9294
| Some env -> (path, env)

‎compiler/ml/typemod.mli‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ val type_open_ :
4141
Location.t ->
4242
Longident.t Asttypes.loc ->
4343
Path.t * Env.t
44+
[@@live]
45+
(* Live: called through {!Typecore.type_open} with optional arguments that
46+
reanalyze cannot trace. *)
4447

4548
val save_signature : string -> Typedtree.signature -> string -> string -> unit
4649

0 commit comments

Comments
 (0)