Skip to content

Commit 23f7b44

Browse files
committed
Refactor type paths.
1 parent b444f93 commit 23f7b44

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

analysis/src/FindFiles.ml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ let collectFiles directory =
109109
compileds
110110
|> List.map (fun path ->
111111
let modName = getName path in
112-
let compiled = directory /+ path in
113-
let source =
112+
let cmt = directory /+ path in
113+
let resOpt =
114114
Utils.find
115115
(fun name ->
116116
if getName name = modName then Some (directory /+ name) else None)
117117
sources
118118
in
119-
(modName, SharedTypes.Impl (compiled, source)))
119+
(modName, SharedTypes.Impl {cmt; resOpt}))
120120

121121
(* returns a list of (absolute path to cmt(i), relative path from base to source file) *)
122122
let findProjectFiles ~namespace ~path ~sourceDirectories ~libBs =
@@ -141,32 +141,30 @@ let findProjectFiles ~namespace ~path ~sourceDirectories ~libBs =
141141
|> Utils.filterMap (fun file ->
142142
if isImplementation file then (
143143
let moduleName = getName file in
144-
let intf = Hashtbl.find_opt interfaces moduleName in
144+
let resi = Hashtbl.find_opt interfaces moduleName in
145145
Hashtbl.remove interfaces moduleName;
146146
let base = compiledBaseName ~namespace (Files.relpath path file) in
147-
match intf with
148-
| Some intf ->
147+
match resi with
148+
| Some resi ->
149149
let cmti = (libBs /+ base) ^ ".cmti" in
150150
let cmt = (libBs /+ base) ^ ".cmt" in
151151
if Files.exists cmti then
152152
if Files.exists cmt then
153153
(* Log.log("Intf and impl " ++ cmti ++ " " ++ cmt) *)
154154
Some
155155
( moduleName,
156-
SharedTypes.IntfAndImpl (cmti, intf, cmt, file) )
156+
SharedTypes.IntfAndImpl {cmti; resi; cmt; res = file} )
157157
else None
158158
else (
159159
(* Log.log("Just intf " ++ cmti) *)
160-
Log.log
161-
("Bad source file (no cmt/cmti/cmi) " ^ (libBs /+ base)
162-
);
160+
Log.log ("Bad source file (no cmt/cmti/cmi) " ^ (libBs /+ base));
163161
None)
164162
| None ->
165163
let cmt = (libBs /+ base) ^ ".cmt" in
166-
if Files.exists cmt then Some (moduleName, Impl (cmt, Some file))
164+
if Files.exists cmt then
165+
Some (moduleName, Impl {cmt; resOpt = Some file})
167166
else (
168-
Log.log
169-
("Bad source file (no cmt/cmi) " ^ (libBs /+ base));
167+
Log.log ("Bad source file (no cmt/cmi) " ^ (libBs /+ base));
170168
None))
171169
else None)
172170
in
@@ -183,7 +181,7 @@ let findProjectFiles ~namespace ~path ~sourceDirectories ~libBs =
183181
let moduleName = nameSpaceToName namespace in
184182
let cmt = (libBs /+ namespace) ^ ".cmt" in
185183
Log.log ("adding namespace " ^ namespace ^ " : " ^ moduleName ^ " : " ^ cmt);
186-
(moduleName, Impl (cmt, None)) :: result
184+
(moduleName, Impl {cmt; resOpt = None}) :: result
187185

188186
let findDependencyFiles base config =
189187
let open Infix in

analysis/src/Packages.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let newBsPackage rootPath =
4848
|> List.iter (fun (name, paths) ->
4949
Log.log name;
5050
match paths with
51-
| SharedTypes.Impl (cmt, _) -> Log.log ("impl " ^ cmt)
51+
| SharedTypes.Impl {cmt} -> Log.log ("impl " ^ cmt)
5252
| _ -> Log.log "Both");
5353
let pathsForModule =
5454
makePathsForModule ~projectFilesAndPaths ~dependenciesFilesAndPaths
@@ -59,7 +59,7 @@ let newBsPackage rootPath =
5959
| Some namespace ->
6060
let cmt = Filename.concat libBs namespace ^ ".cmt" in
6161
Log.log ("############ Namespaced as " ^ namespace ^ " at " ^ cmt);
62-
Hashtbl.add pathsForModule namespace (Impl (cmt, None));
62+
Hashtbl.add pathsForModule namespace (Impl {cmt; resOpt = None});
6363
[FindFiles.nameSpaceToName namespace]
6464
in
6565
Log.log ("Dependency dirs " ^ String.concat " " dependencyDirectories);

analysis/src/References.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ let alternateDeclared ~(file : File.t) ~package declared tip =
188188
| Some paths -> (
189189
maybeLog ("paths for " ^ file.moduleName);
190190
match paths with
191-
| IntfAndImpl (_, intf, _, impl) -> (
191+
| IntfAndImpl {resi; res} -> (
192192
maybeLog "Have both!!";
193-
let intfUri = Uri2.fromPath intf in
194-
let implUri = Uri2.fromPath impl in
195-
if intfUri = file.uri then
196-
match ProcessCmt.getFullFromCmt ~uri:implUri with
193+
let resiUri = Uri2.fromPath resi in
194+
let resUri = Uri2.fromPath res in
195+
if resiUri = file.uri then
196+
match ProcessCmt.getFullFromCmt ~uri:resUri with
197197
| None -> None
198198
| Some {file; extra} -> (
199199
match
@@ -203,7 +203,7 @@ let alternateDeclared ~(file : File.t) ~package declared tip =
203203
| None -> None
204204
| Some declared -> Some (file, extra, declared))
205205
else
206-
match ProcessCmt.getFullFromCmt ~uri:intfUri with
206+
match ProcessCmt.getFullFromCmt ~uri:resiUri with
207207
| None -> None
208208
| Some {file; extra} -> (
209209
match

analysis/src/SharedTypes.ml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,29 @@ end
114114
type filePath = string
115115

116116
type paths =
117-
| Impl of filePath * filePath option
118-
(* .cm(t)i, .mli, .cmt, .rei *)
119-
| IntfAndImpl of filePath * filePath * filePath * filePath
117+
| Impl of {cmt : filePath; resOpt : filePath option}
118+
| IntfAndImpl of {
119+
cmti : filePath;
120+
resi : filePath;
121+
cmt : filePath;
122+
res : filePath;
123+
}
120124

121125
open Infix
122126

123127
let showPaths paths =
124128
match paths with
125-
| Impl (cmt, src) -> Printf.sprintf "Impl(%s, %s)" cmt (src |? "nil")
126-
| IntfAndImpl (cmti, srci, cmt, src) ->
127-
Printf.sprintf "IntfAndImpl(%s, %s, %s, %s)" cmti srci cmt src
129+
| Impl {cmt; resOpt} -> Printf.sprintf "Impl(%s, %s)" cmt (resOpt |? "nil")
130+
| IntfAndImpl {cmti; resi; cmt; res} ->
131+
Printf.sprintf "IntfAndImpl(%s, %s, %s, %s)" cmti resi cmt res
128132

129133
let getSrc p =
130-
match p with Impl (_, s) -> s | IntfAndImpl (_, s, _, _) -> Some s
134+
match p with Impl {resOpt} -> resOpt | IntfAndImpl {resi} -> Some resi
131135

132136
let getCmt ?(interface = true) p =
133137
match p with
134-
| Impl (c, _) -> c
135-
| IntfAndImpl (cint, _, cimpl, _) -> if interface then cint else cimpl
138+
| Impl {cmt} -> cmt
139+
| IntfAndImpl {cmti; cmt} -> if interface then cmti else cmt
136140

137141
let emptyDeclared name =
138142
{

0 commit comments

Comments
 (0)