Skip to content

Ignore self-cycles on bsb_helper to suppress false positives #5393

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 6 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
13 changes: 10 additions & 3 deletions jscomp/bsb_helper/bsb_helper_depfile_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ let oc_cmi buf namespace source =

When ns is turned on, `B` is interprted as `Ns-B` which is a cyclic dependency,
it can be errored out earlier

#5368: It turns out there are many false positives on detecting self-cycles (see: `jscomp/build_tests/zerocycle`)
To properly solve this, we would need to `jscomp/ml/depend.ml` because
cmi and cmj is broken in the first place (same problem as in ocaml/ocaml#4618).
So we will just ignore the self-cycles. Even if there is indeed a self-cycle, it should fail to compile anyway.
*)
let oc_deps (ast_file : string) (is_dev : bool) (db : Bsb_db_decode.t)
(namespace : string option) (buf : Ext_buffer.t) (kind : [ `impl | `intf ])
Expand Down Expand Up @@ -133,9 +138,11 @@ let oc_deps (ast_file : string) (is_dev : bool) (db : Bsb_db_decode.t)
while !offset < size do
let next_tab = String.index_from s !offset magic_sep_char in
let dependent_module = String.sub s !offset (next_tab - !offset) in
if dependent_module = cur_module_name then (
prerr_endline ("FAILED: " ^ cur_module_name ^ " has a self cycle");
exit 2);
if dependent_module = cur_module_name then
(*prerr_endline ("FAILED: " ^ cur_module_name ^ " has a self cycle");
exit 2*)
(* #5368 ignore self dependencies *) ()
else
(match Bsb_db_decode.find db dependent_module is_dev with
| None -> ()
| Some { dir_name; case } ->
Expand Down
14 changes: 14 additions & 0 deletions jscomp/build_tests/zerocycle/src/bar.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// one-file false positive

module Nested = {
module Bar = {
type t = private int
}
}

open Nested

module Bar = {
open Bar
let t : t = Obj.magic(42)
}
1 change: 1 addition & 0 deletions jscomp/build_tests/zerocycle/src/demo2.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Foo2 = {}
2 changes: 2 additions & 0 deletions jscomp/build_tests/zerocycle/src/foo2.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
open Demo2
include Foo2