Skip to content

Commit cdb85f7

Browse files
committed
Revert "only look up project files etc when needed"
This reverts commit bc71f76.
1 parent ea2c9c1 commit cdb85f7

File tree

8 files changed

+119
-148
lines changed

8 files changed

+119
-148
lines changed

analysis/src/Cache.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ let targetFileFromLibBs libBs = Filename.concat libBs ".project-files-cache"
2929
let cacheProject (package : package) =
3030
let cached =
3131
{
32-
projectFiles = Lazy.force package.projectFiles;
33-
dependenciesFiles = Lazy.force package.dependenciesFiles;
34-
pathsForModule = Lazy.force package.pathsForModule;
32+
projectFiles = package.projectFiles;
33+
dependenciesFiles = package.dependenciesFiles;
34+
pathsForModule = package.pathsForModule;
3535
}
3636
in
3737
match BuildSystem.getLibBs package.rootPath with

analysis/src/Cmt.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let fullFromUri ~uri =
3333
if Debug.verbose () then Printf.printf "[cmt] Found incremental cmt\n";
3434
Some cmtInfo
3535
| None -> (
36-
match Hashtbl.find_opt (Lazy.force package.pathsForModule) moduleName with
36+
match Hashtbl.find_opt package.pathsForModule moduleName with
3737
| Some paths ->
3838
let cmt = getCmtPath ~uri paths in
3939
fullForCmt ~moduleName ~package ~uri cmt
@@ -42,8 +42,8 @@ let fullFromUri ~uri =
4242
None))
4343

4444
let fullsFromModule ~package ~moduleName =
45-
if Hashtbl.mem (Lazy.force package.pathsForModule) moduleName then
46-
let paths = Hashtbl.find (Lazy.force package.pathsForModule) moduleName in
45+
if Hashtbl.mem package.pathsForModule moduleName then
46+
let paths = Hashtbl.find package.pathsForModule moduleName in
4747
let uris = getUris paths in
4848
uris |> List.filter_map (fun uri -> fullFromUri ~uri)
4949
else []

analysis/src/CompletionBackEnd.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
10571057
resultModulePath;
10581058
regexpModulePath;
10591059
} =
1060-
Lazy.force package.builtInCompletionModules
1060+
package.builtInCompletionModules
10611061
in
10621062
Some
10631063
(match builtin with
@@ -1316,7 +1316,7 @@ let getOpens ~debug ~rawOpens ~package ~env =
13161316
^ string_of_int (List.length rawOpens)
13171317
^ " "
13181318
^ String.concat " ... " (rawOpens |> List.map pathToString));
1319-
let packageOpens = Lazy.force package.opens in
1319+
let packageOpens = package.opens in
13201320
if debug && packageOpens <> [] then
13211321
Printf.printf "%s\n"
13221322
("Package opens "
@@ -1812,8 +1812,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
18121812
if Debug.verbose () then print_endline "[complete_typed_value]--> Texn";
18131813
[
18141814
create
1815-
((Lazy.force full.package.builtInCompletionModules).exnModulePath
1816-
@ ["Error(error)"]
1815+
(full.package.builtInCompletionModules.exnModulePath @ ["Error(error)"]
18171816
|> ident)
18181817
~kind:(Label "Catches errors from JavaScript errors.")
18191818
~docstring:

analysis/src/Packages.ml

Lines changed: 96 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -74,91 +74,70 @@ let newBsPackage ~rootPath =
7474
let projectFiles, dependenciesFiles, pathsForModule =
7575
match cached with
7676
| Some cached ->
77-
( Lazy.from_val cached.projectFiles,
78-
Lazy.from_val cached.dependenciesFiles,
79-
Lazy.from_val cached.pathsForModule )
77+
( cached.projectFiles,
78+
cached.dependenciesFiles,
79+
cached.pathsForModule )
8080
| None ->
8181
let dependenciesFilesAndPaths =
82-
Lazy.from_fun (fun () ->
83-
match FindFiles.findDependencyFiles rootPath config with
84-
| None -> []
85-
| Some (_dependencyDirectories, dependenciesFilesAndPaths) ->
86-
dependenciesFilesAndPaths)
82+
match FindFiles.findDependencyFiles rootPath config with
83+
| None -> []
84+
| Some (_dependencyDirectories, dependenciesFilesAndPaths) ->
85+
dependenciesFilesAndPaths
8786
in
8887
let sourceDirectories =
89-
Lazy.from_fun (fun () ->
90-
FindFiles.getSourceDirectories ~includeDev:true
91-
~baseDir:rootPath config)
88+
FindFiles.getSourceDirectories ~includeDev:true ~baseDir:rootPath
89+
config
9290
in
9391
let projectFilesAndPaths =
94-
Lazy.from_fun (fun () ->
95-
FindFiles.findProjectFiles
96-
~public:(FindFiles.getPublic config)
97-
~namespace ~path:rootPath
98-
~sourceDirectories:(Lazy.force sourceDirectories)
99-
~libBs)
92+
FindFiles.findProjectFiles
93+
~public:(FindFiles.getPublic config)
94+
~namespace ~path:rootPath ~sourceDirectories ~libBs
10095
in
10196
let pathsForModule =
102-
Lazy.from_fun (fun () ->
103-
makePathsForModule
104-
~projectFilesAndPaths:(Lazy.force projectFilesAndPaths)
105-
~dependenciesFilesAndPaths:
106-
(Lazy.force dependenciesFilesAndPaths))
97+
makePathsForModule ~projectFilesAndPaths
98+
~dependenciesFilesAndPaths
10799
in
108100
let projectFiles =
109-
Lazy.from_fun (fun () ->
110-
projectFilesAndPaths |> Lazy.force |> List.map fst
111-
|> FileSet.of_list)
101+
projectFilesAndPaths |> List.map fst |> FileSet.of_list
112102
in
113103
let dependenciesFiles =
114-
Lazy.from_fun (fun () ->
115-
dependenciesFilesAndPaths |> Lazy.force |> List.map fst
116-
|> FileSet.of_list)
104+
dependenciesFilesAndPaths |> List.map fst |> FileSet.of_list
117105
in
118106
(projectFiles, dependenciesFiles, pathsForModule)
119107
in
120108
Some
121109
(let opens_from_namespace =
122-
Lazy.from_fun (fun () ->
123-
match namespace with
124-
| None -> []
125-
| Some namespace ->
126-
let cmt = Filename.concat libBs namespace ^ ".cmt" in
127-
Hashtbl.add
128-
(Lazy.force pathsForModule)
129-
namespace
130-
(Namespace {cmt});
131-
let path = [FindFiles.nameSpaceToName namespace] in
132-
[path])
110+
match namespace with
111+
| None -> []
112+
| Some namespace ->
113+
let cmt = Filename.concat libBs namespace ^ ".cmt" in
114+
Hashtbl.add pathsForModule namespace (Namespace {cmt});
115+
let path = [FindFiles.nameSpaceToName namespace] in
116+
[path]
133117
in
134118
let opens_from_bsc_flags =
135-
Lazy.from_fun (fun () ->
136-
let bind f x = Option.bind x f in
137-
match Json.get "bsc-flags" config |> bind Json.array with
138-
| Some l ->
139-
List.fold_left
140-
(fun opens item ->
141-
match item |> Json.string with
142-
| None -> opens
143-
| Some s -> (
144-
let parts = String.split_on_char ' ' s in
145-
match parts with
146-
| "-open" :: name :: _ ->
147-
let path = name |> String.split_on_char '.' in
148-
path :: opens
149-
| _ -> opens))
150-
[] l
151-
| None -> [])
119+
let bind f x = Option.bind x f in
120+
match Json.get "bsc-flags" config |> bind Json.array with
121+
| Some l ->
122+
List.fold_left
123+
(fun opens item ->
124+
match item |> Json.string with
125+
| None -> opens
126+
| Some s -> (
127+
let parts = String.split_on_char ' ' s in
128+
match parts with
129+
| "-open" :: name :: _ ->
130+
let path = name |> String.split_on_char '.' in
131+
path :: opens
132+
| _ -> opens))
133+
[] l
134+
| None -> []
152135
in
153136
let opens =
154-
Lazy.from_fun (fun () ->
155-
[
156-
(if uncurried then "PervasivesU" else "Pervasives");
157-
"JsxModules";
158-
]
159-
:: Lazy.force opens_from_namespace
160-
|> List.rev_append (Lazy.force opens_from_bsc_flags)
161-
|> List.map (fun path -> path @ ["place holder"]))
137+
[(if uncurried then "PervasivesU" else "Pervasives"); "JsxModules"]
138+
:: opens_from_namespace
139+
|> List.rev_append opens_from_bsc_flags
140+
|> List.map (fun path -> path @ ["place holder"])
162141
in
163142
{
164143
genericJsxModule;
@@ -171,60 +150,59 @@ let newBsPackage ~rootPath =
171150
opens;
172151
namespace;
173152
builtInCompletionModules =
174-
Lazy.from_fun (fun () ->
175-
if
176-
opens_from_bsc_flags |> Lazy.force
177-
|> List.find_opt (fun opn ->
178-
match opn with
179-
| ["RescriptCore"] -> true
180-
| _ -> false)
181-
|> Option.is_some
182-
then
183-
{
184-
arrayModulePath = ["Array"];
185-
optionModulePath = ["Option"];
186-
stringModulePath = ["String"];
187-
intModulePath = ["Int"];
188-
floatModulePath = ["Float"];
189-
promiseModulePath = ["Promise"];
190-
listModulePath = ["List"];
191-
resultModulePath = ["Result"];
192-
exnModulePath = ["Exn"];
193-
regexpModulePath = ["RegExp"];
194-
}
195-
else if
196-
opens_from_bsc_flags |> Lazy.force
197-
|> List.find_opt (fun opn ->
198-
match opn with
199-
| ["Belt"] -> true
200-
| _ -> false)
201-
|> Option.is_some
202-
then
203-
{
204-
arrayModulePath = ["Array"];
205-
optionModulePath = ["Option"];
206-
stringModulePath = ["Js"; "String2"];
207-
intModulePath = ["Int"];
208-
floatModulePath = ["Float"];
209-
promiseModulePath = ["Js"; "Promise"];
210-
listModulePath = ["List"];
211-
resultModulePath = ["Result"];
212-
exnModulePath = ["Js"; "Exn"];
213-
regexpModulePath = ["Js"; "Re"];
214-
}
215-
else
216-
{
217-
arrayModulePath = ["Js"; "Array2"];
218-
optionModulePath = ["Belt"; "Option"];
219-
stringModulePath = ["Js"; "String2"];
220-
intModulePath = ["Belt"; "Int"];
221-
floatModulePath = ["Belt"; "Float"];
222-
promiseModulePath = ["Js"; "Promise"];
223-
listModulePath = ["Belt"; "List"];
224-
resultModulePath = ["Belt"; "Result"];
225-
exnModulePath = ["Js"; "Exn"];
226-
regexpModulePath = ["Js"; "Re"];
227-
});
153+
(if
154+
opens_from_bsc_flags
155+
|> List.find_opt (fun opn ->
156+
match opn with
157+
| ["RescriptCore"] -> true
158+
| _ -> false)
159+
|> Option.is_some
160+
then
161+
{
162+
arrayModulePath = ["Array"];
163+
optionModulePath = ["Option"];
164+
stringModulePath = ["String"];
165+
intModulePath = ["Int"];
166+
floatModulePath = ["Float"];
167+
promiseModulePath = ["Promise"];
168+
listModulePath = ["List"];
169+
resultModulePath = ["Result"];
170+
exnModulePath = ["Exn"];
171+
regexpModulePath = ["RegExp"];
172+
}
173+
else if
174+
opens_from_bsc_flags
175+
|> List.find_opt (fun opn ->
176+
match opn with
177+
| ["Belt"] -> true
178+
| _ -> false)
179+
|> Option.is_some
180+
then
181+
{
182+
arrayModulePath = ["Array"];
183+
optionModulePath = ["Option"];
184+
stringModulePath = ["Js"; "String2"];
185+
intModulePath = ["Int"];
186+
floatModulePath = ["Float"];
187+
promiseModulePath = ["Js"; "Promise"];
188+
listModulePath = ["List"];
189+
resultModulePath = ["Result"];
190+
exnModulePath = ["Js"; "Exn"];
191+
regexpModulePath = ["Js"; "Re"];
192+
}
193+
else
194+
{
195+
arrayModulePath = ["Js"; "Array2"];
196+
optionModulePath = ["Belt"; "Option"];
197+
stringModulePath = ["Js"; "String2"];
198+
intModulePath = ["Belt"; "Int"];
199+
floatModulePath = ["Belt"; "Float"];
200+
promiseModulePath = ["Js"; "Promise"];
201+
listModulePath = ["Belt"; "List"];
202+
resultModulePath = ["Belt"; "Result"];
203+
exnModulePath = ["Js"; "Exn"];
204+
regexpModulePath = ["Js"; "Re"];
205+
});
228206
uncurried;
229207
}))
230208
| None -> None

analysis/src/ProcessCmt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ let fileForCmt ~moduleName ~cmt ~uri =
663663
Some file)
664664

665665
let fileForModule moduleName ~package =
666-
match Hashtbl.find_opt (Lazy.force package.pathsForModule) moduleName with
666+
match Hashtbl.find_opt package.pathsForModule moduleName with
667667
| Some paths ->
668668
let uri = getUri paths in
669669
let cmt = getCmtPath ~uri paths in

analysis/src/References.ml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let getLocItem ~full ~pos ~debug =
6666
| [
6767
({locType = Typed (_, _, LocalReference _)} as li1);
6868
({locType = Typed (_, _, GlobalReference ("Js_OO", ["unsafe_downgrade"], _))}
69-
as li2);
69+
as li2);
7070
li3;
7171
]
7272
(* For older compiler 9.0 or earlier *)
@@ -211,9 +211,7 @@ let definedForLoc ~file ~package locKind =
211211

212212
(** Find alternative declaration: from res in case of interface, or from resi in case of implementation *)
213213
let alternateDeclared ~(file : File.t) ~package (declared : _ Declared.t) tip =
214-
match
215-
Hashtbl.find_opt (Lazy.force package.pathsForModule) file.moduleName
216-
with
214+
match Hashtbl.find_opt package.pathsForModule file.moduleName with
217215
| None -> None
218216
| Some paths -> (
219217
match paths with
@@ -364,7 +362,7 @@ let definitionForLocItem ~full:{file; package} locItem =
364362
None
365363
| TopLevelModule name -> (
366364
maybeLog ("Toplevel " ^ name);
367-
match Hashtbl.find_opt (Lazy.force package.pathsForModule) name with
365+
match Hashtbl.find_opt package.pathsForModule name with
368366
| None -> None
369367
| Some paths ->
370368
let uri = getUri paths in
@@ -488,8 +486,7 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
488486
maybeLog ("Now checking path " ^ pathToString path);
489487
let thisModuleName = file.moduleName in
490488
let externals =
491-
Lazy.force package.projectFiles
492-
|> FileSet.elements
489+
package.projectFiles |> FileSet.elements
493490
|> List.filter (fun name -> name <> file.moduleName)
494491
|> List.map (fun moduleName ->
495492
Cmt.fullsFromModule ~package ~moduleName
@@ -524,8 +521,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
524521
match locItem.locType with
525522
| TopLevelModule moduleName ->
526523
let otherModulesReferences =
527-
Lazy.force package.projectFiles
528-
|> FileSet.elements
524+
package.projectFiles |> FileSet.elements
529525
|> Utils.filterMap (fun name ->
530526
match ProcessCmt.fileForModule ~package name with
531527
| None -> None
@@ -543,7 +539,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
543539
|> List.flatten
544540
in
545541
let targetModuleReferences =
546-
match Hashtbl.find_opt (Lazy.force package.pathsForModule) moduleName with
542+
match Hashtbl.find_opt package.pathsForModule moduleName with
547543
| None -> []
548544
| Some paths ->
549545
let moduleSrcToRef src = {uri = Uri.fromPath src; locOpt = None} in

0 commit comments

Comments
 (0)