Skip to content

Commit 2189ce0

Browse files
committed
Add determinism to processing of files.
Files can be processes in different orders on different architectures because of how their layout on disk. Add determinism by using sets instead of lists.
1 parent 7f89112 commit 2189ce0

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

analysis/src/NewCompletions.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ let getItems ~full ~package ~rawOpens ~allFiles ~pos ~parts =
773773
in
774774
(* TODO complete the namespaced name too *)
775775
let localModuleNames =
776-
allFiles
776+
allFiles |> FileSet.elements
777777
|> Utils.filterMap (fun name ->
778778
if Utils.startsWith name suffix && not (String.contains name '-')
779779
then Some {(emptyDeclared name) with item = FileModule name}
@@ -1148,7 +1148,9 @@ let computeCompletions ~uri ~textOpt ~pos =
11481148
| Some full ->
11491149
let rawOpens = PartialParser.findOpens text offset in
11501150
let package = full.package in
1151-
let allFiles = package.projectFiles @ package.dependenciesFiles in
1151+
let allFiles =
1152+
FileSet.union package.projectFiles package.dependenciesFiles
1153+
in
11521154
let findItems ~exact parts =
11531155
let items =
11541156
getItems ~full ~package ~rawOpens ~allFiles ~pos ~parts

analysis/src/Packages.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ let newBsPackage rootPath =
8484
Log.log ("Opens from bsconfig: " ^ (opens |> String.concat " "));
8585
{
8686
SharedTypes.rootPath;
87-
projectFiles = projectFilesAndPaths |> List.map fst;
88-
dependenciesFiles = dependenciesFilesAndPaths |> List.map fst;
87+
projectFiles =
88+
projectFilesAndPaths |> List.map fst
89+
|> SharedTypes.FileSet.of_list;
90+
dependenciesFiles =
91+
dependenciesFilesAndPaths |> List.map fst
92+
|> SharedTypes.FileSet.of_list;
8993
pathsForModule;
9094
opens;
9195
namespace;

analysis/src/ProcessCmt.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,12 @@ struct
734734
else []))
735735

736736
let addFileReference moduleName loc =
737-
Hashtbl.replace extra.fileReferences moduleName
738-
(loc
739-
::
740-
(if Hashtbl.mem extra.fileReferences moduleName then
741-
Hashtbl.find extra.fileReferences moduleName
742-
else []))
737+
let newLocs =
738+
match Hashtbl.find_opt extra.fileReferences moduleName with
739+
| Some oldLocs -> LocationSet.add loc oldLocs
740+
| None -> LocationSet.singleton loc
741+
in
742+
Hashtbl.replace extra.fileReferences moduleName newLocs
743743

744744
let env = QueryEnv.fromFile Collector.file
745745

analysis/src/References.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
426426
maybeLog ("Now checking path " ^ pathToString path);
427427
let thisModuleName = file.moduleName in
428428
let externals =
429-
package.projectFiles
429+
package.projectFiles |> FileSet.elements
430430
|> List.filter (fun name -> name <> file.moduleName)
431431
|> Utils.filterMap (fun name ->
432432
match ProcessCmt.fileForModule ~package name with
@@ -460,7 +460,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
460460
match locItem.locType with
461461
| TopLevelModule moduleName ->
462462
let otherModulesReferences =
463-
package.projectFiles
463+
package.projectFiles |> FileSet.elements
464464
|> Utils.filterMap (fun name ->
465465
match ProcessCmt.fileForModule ~package name with
466466
| None -> None
@@ -469,7 +469,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
469469
match Hashtbl.find_opt full.extra.fileReferences moduleName with
470470
| None -> []
471471
| Some locs ->
472-
locs
472+
locs |> LocationSet.elements
473473
|> List.map (fun loc ->
474474
(Uri2.fromPath loc.Location.loc_start.pos_fname, [loc])))
475475
|> List.flatten

analysis/src/SharedTypes.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,16 @@ type openTracker = {
200200
mutable used : (path * tip * Location.t) list;
201201
}
202202

203+
module LocationSet = Set.Make (struct
204+
include Location
205+
206+
let compare loc1 loc2 = compare loc2 loc1 (* polymorphic compare should be OK *)
207+
end)
208+
203209
type extra = {
204210
internalReferences : (int, Location.t list) Hashtbl.t;
205211
externalReferences : (string, (path * tip * Location.t) list) Hashtbl.t;
206-
fileReferences : (string, Location.t list) Hashtbl.t;
212+
fileReferences : (string, LocationSet.t) Hashtbl.t;
207213
mutable locItems : locItem list;
208214
(* This is the "open location", like the location...
209215
or maybe the >> location of the open ident maybe *)
@@ -213,10 +219,12 @@ type extra = {
213219

214220
type file = string
215221

222+
module FileSet = Set.Make (String)
223+
216224
type package = {
217225
rootPath : filePath;
218-
projectFiles : file list;
219-
dependenciesFiles : file list;
226+
projectFiles : FileSet.t;
227+
dependenciesFiles : FileSet.t;
220228
pathsForModule : (file, paths) Hashtbl.t;
221229
namespace : string option;
222230
opens : string list;

0 commit comments

Comments
 (0)