Skip to content

Commit

Permalink
uid_of_path can use the decl_id if shapes fail
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfirere committed Oct 31, 2023
1 parent 7b73c6a commit cc867ed
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/analysis/locate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,20 @@ let uid_of_path ~config ~env ~ml_or_mli ~decl_uid path namespace =
Logger.fmt (fun fmt -> Shape.Uid.print fmt decl_uid);
log ~title:"uid_of_path" "Alias scrapped: %a"
Logger.fmt (fun fmt -> Shape.Uid.print fmt uid);
Some uid
uid
| `ML ->
let shape = Env.shape_of_path ~namespace env path in
log ~title:"shape_of_path" "initial: %a"
Logger.fmt (fun fmt -> Shape.print fmt shape);
let r = Shape_reduce.weak_reduce env shape in
log ~title:"shape_of_path" "reduced: %a"
Logger.fmt (fun fmt -> Shape.print fmt r);
r.uid
match r.uid with
| Some uid -> uid
| None ->
log ~title:"shape_of_path" "no uid; fallback to Declaration uid: %a"
Logger.fmt (fun fmt -> Shape.Uid.print fmt decl_uid);
decl_uid

let from_uid ~config ~ml_or_mli uid loc path =
let loc_of_comp_unit comp_unit =
Expand All @@ -387,7 +392,7 @@ let from_uid ~config ~ml_or_mli uid loc path =
in
let title = "from_uid" in
match uid with
| Some (Shape.Uid.Item { comp_unit; _ } as uid) ->
| Shape.Uid.Item { comp_unit; _ } as uid ->
let locopt =
if Env.get_unit_name () = comp_unit then begin
log ~title "We look for %a in the current compilation unit."
Expand Down Expand Up @@ -430,7 +435,7 @@ let from_uid ~config ~ml_or_mli uid loc path =
| Some (uid, loc) -> `Found (Some uid, loc)
| None -> `Not_found (Path.name path, None)
end
| Some (Compilation_unit comp_unit as uid) ->
| Compilation_unit comp_unit as uid ->
begin
log ~title "Got the uid of a compilation unit: %a"
Logger.fmt (fun fmt -> Shape.Uid.print fmt uid);
Expand All @@ -439,9 +444,7 @@ let from_uid ~config ~ml_or_mli uid loc path =
| _ -> log ~title "Failed to load the shapes";
`Not_found (Path.name path, None)
end
| Some (Predef _ | Internal) -> assert false
| None -> log ~title "No UID found, fallbacking to lookup location.";
`Found (None, loc)
| Predef _ | Internal -> assert false

let locate ~config ~env ~ml_or_mli decl_uid loc path ns =
let uid = uid_of_path ~config ~env ~ml_or_mli ~decl_uid path ns in
Expand Down

0 comments on commit cc867ed

Please sign in to comment.