Skip to content

Commit 677b680

Browse files
panglesdjonludlam
authored andcommitted
Revert "Adding support for resolving constructor and datatype"
This reverts commit 9eee684.
1 parent f5f47ce commit 677b680

File tree

7 files changed

+14
-412
lines changed

7 files changed

+14
-412
lines changed

src/xref2/compile.ml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,15 @@ let type_path : Env.t -> Paths.Path.Type.t -> Paths.Path.Type.t =
2121
| Ok p' -> `Resolved Lang_of.(Path.resolved_type (empty ()) p')
2222
| Error _ -> p)
2323

24-
(* and value_path : Env.t -> Paths.Path.Value.t -> Paths.Path.Value.t = *)
25-
(* fun env p -> *)
26-
(* match p with *)
27-
(* | `Resolved _ -> p *)
28-
(* | _ -> ( *)
29-
(* let cp = Component.Of_Lang.(value_path (empty ()) p) in *)
30-
(* match Tools.resolve_value_path env cp with *)
31-
(* | Ok p' -> `Resolved Lang_of.(Path.resolved_value (empty ()) p') *)
32-
(* | Error _ -> p) *)
33-
34-
(* and constructor_path : *)
35-
(* Env.t -> Paths.Path.Constructor.t -> Paths.Path.Constructor.t = *)
36-
(* fun env p -> *)
37-
(* match p with *)
38-
(* | `Resolved _ -> p *)
39-
(* | _ -> ( *)
40-
(* let cp = Component.Of_Lang.(constructor_path (empty ()) p) in *)
41-
(* match Tools.resolve_constructor_path env cp with *)
42-
(* | Ok p' -> `Resolved Lang_of.(Path.resolved_constructor (empty ()) p') *)
43-
(* | Error _ -> p) *)
24+
and value_path : Env.t -> Paths.Path.Value.t -> Paths.Path.Value.t =
25+
fun env p ->
26+
match p with
27+
| `Resolved _ -> p
28+
| _ -> (
29+
let cp = Component.Of_Lang.(value_path (empty ()) p) in
30+
match Tools.resolve_value_path env cp with
31+
| Ok p' -> `Resolved Lang_of.(Path.resolved_value (empty ()) p')
32+
| Error _ -> p)
4433

4534
and module_type_path :
4635
Env.t -> Paths.Path.ModuleType.t -> Paths.Path.ModuleType.t =

src/xref2/errors.ml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ module Tools_error = struct
7272
(* Could not find the module in the environment *)
7373
| `Parent of parent_lookup_error ]
7474

75-
and simple_datatype_lookup_error =
76-
[ `LocalDataType of
77-
Env.t * Ident.path_datatype
78-
(* Internal error: Found local path during lookup *)
79-
| `Find_failure
80-
(* Internal error: the type was not found in the parent signature *)
81-
| `Lookup_failureT of
82-
Identifier.Path.Type.t
83-
(* Could not find the module in the environment *)
84-
| `Parent of parent_lookup_error ]
85-
8675
and simple_value_lookup_error =
8776
[ `LocalValue of
8877
Env.t * Ident.path_value
@@ -94,17 +83,6 @@ module Tools_error = struct
9483
(* Could not find the module in the environment *)
9584
| `Parent of parent_lookup_error ]
9685

97-
and simple_constructor_lookup_error =
98-
[ `LocalConstructor of
99-
Env.t * Ident.constructor
100-
(* Internal error: Found local path during lookup *)
101-
| `Find_failure
102-
(* Internal error: the type was not found in the parent signature *)
103-
| `Lookup_failureC of
104-
Identifier.Path.Constructor.t
105-
(* Could not find the module in the environment *)
106-
| `ParentC of simple_datatype_lookup_error ]
107-
10886
and parent_lookup_error =
10987
[ `Parent_sig of
11088
expansion_of_module_error
@@ -132,8 +110,6 @@ module Tools_error = struct
132110
type any =
133111
[ simple_type_lookup_error
134112
| simple_value_lookup_error
135-
| simple_constructor_lookup_error
136-
| simple_datatype_lookup_error
137113
| simple_module_type_lookup_error
138114
| simple_module_type_expr_of_module_error
139115
| simple_module_lookup_error
@@ -171,10 +147,6 @@ module Tools_error = struct
171147
| `LocalMT (_, id) -> Format.fprintf fmt "Local id found: %a" Ident.fmt id
172148
| `Local (_, id) -> Format.fprintf fmt "Local id found: %a" Ident.fmt id
173149
| `LocalType (_, id) -> Format.fprintf fmt "Local id found: %a" Ident.fmt id
174-
| `LocalDataType (_, id) ->
175-
Format.fprintf fmt "Local id found: %a" Ident.fmt id
176-
| `LocalConstructor (_, id) ->
177-
Format.fprintf fmt "Local id found: %a" Ident.fmt id
178150
| `LocalValue (_, id) ->
179151
Format.fprintf fmt "Local id found: %a" Ident.fmt id
180152
| `Find_failure -> Format.fprintf fmt "Find failure"
@@ -196,14 +168,9 @@ module Tools_error = struct
196168
Format.fprintf fmt "Lookup failure (value): %a"
197169
Component.Fmt.model_identifier
198170
(m :> Odoc_model.Paths.Identifier.t)
199-
| `Lookup_failureC m ->
200-
Format.fprintf fmt "Lookup failure (constructor): %a"
201-
Component.Fmt.model_identifier
202-
(m :> Odoc_model.Paths.Identifier.t)
203171
| `ApplyNotFunctor -> Format.fprintf fmt "Apply module is not a functor"
204172
| `Class_replaced -> Format.fprintf fmt "Class replaced"
205173
| `Parent p -> pp fmt (p :> any)
206-
| `ParentC p -> pp fmt (p :> any)
207174
| `UnexpandedTypeOf t ->
208175
Format.fprintf fmt "Unexpanded `module type of` expression: %a"
209176
Component.Fmt.module_type_type_of_desc t
@@ -239,9 +206,7 @@ let is_unexpanded_module_type_of =
239206
| `Find_failure -> false
240207
| `Lookup_failure _ -> false
241208
| `Lookup_failure_root _ -> false
242-
| `Lookup_failureC _ -> false
243209
| `Parent p -> inner (p :> any)
244-
| `ParentC p -> inner (p :> any)
245210
| `Parent_sig p -> inner (p :> any)
246211
| `Parent_module_type p -> inner (p :> any)
247212
| `Parent_expr p -> inner (p :> any)
@@ -259,8 +224,6 @@ let is_unexpanded_module_type_of =
259224
| `Lookup_failureT _ -> false
260225
| `Lookup_failureV _ -> false
261226
| `LocalType _ -> false
262-
| `LocalDataType _ -> false
263-
| `LocalConstructor _ -> false
264227
| `LocalValue _ -> false
265228
| `Class_replaced -> false
266229
| `OpaqueClass -> false
@@ -335,7 +298,6 @@ type what =
335298
| `Module of Identifier.Module.t
336299
| `Module_type of Identifier.Signature.t
337300
| `Module_path of Cpath.module_
338-
| `Constructor_path of Cpath.constructor
339301
| `Module_type_path of Cpath.module_type
340302
| `Module_type_U of Component.ModuleType.U.expr
341303
| `Include of Component.Include.decl
@@ -388,7 +350,6 @@ let report ~(what : what) ?tools_error action =
388350
| `Type cfrag -> r "type" type_fragment cfrag
389351
| `Type_path path -> r "type" type_path path
390352
| `Value_path path -> r "value" value_path path
391-
| `Constructor_path path -> r "constructor" constructor_path path
392353
| `Class_type_path path -> r "class_type" class_type_path path
393354
| `With_module frag -> r "module substitution" module_fragment frag
394355
| `With_module_type frag ->

src/xref2/find.ml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ let type_in_sig sg name =
111111
Some (`FClassType (N.class_type' id, c))
112112
| _ -> None)
113113

114-
let datatype_in_sig sg name =
115-
find_in_sig sg (function
116-
| Signature.Type (id, _, m) when N.type_ id = name ->
117-
Some (`FType (N.type' id, Delayed.get m))
118-
| _ -> None)
119-
120114
type removed_type =
121115
[ `FType_removed of TypeName.t * TypeExpr.t * TypeDecl.Equation.t ]
122116

@@ -127,8 +121,6 @@ type careful_module_type =
127121

128122
type careful_type = [ type_ | removed_type ]
129123

130-
type careful_datatype = [ datatype | removed_type ]
131-
132124
type careful_class = [ class_ | removed_type ]
133125

134126
let careful_module_in_sig sg name =
@@ -164,10 +156,11 @@ let careful_type_in_sig sg name =
164156
| Some _ as x -> x
165157
| None -> removed_type_in_sig sg name
166158

167-
let careful_datatype_in_sig sg name =
168-
match datatype_in_sig sg name with
169-
| Some _ as x -> x
170-
| None -> removed_type_in_sig sg name
159+
let datatype_in_sig sg name =
160+
find_in_sig sg (function
161+
| Signature.Type (id, _, t) when N.type_ id = name ->
162+
Some (`FType (N.type' id, Component.Delayed.get t))
163+
| _ -> None)
171164

172165
let class_in_sig sg name =
173166
filter_in_sig sg (function
@@ -184,18 +177,6 @@ let careful_class_in_sig sg name =
184177
| Some _ as x -> x
185178
| None -> removed_type_in_sig sg name
186179

187-
let constructor_in_type (typ : TypeDecl.t) name =
188-
let rec find_cons = function
189-
| ({ TypeDecl.Constructor.name = name'; _ } as cons) :: _ when name' = name
190-
->
191-
Some (`FConstructor cons)
192-
| _ :: tl -> find_cons tl
193-
| [] -> None
194-
in
195-
match typ.representation with
196-
| Some (Variant cons) -> find_cons cons
197-
| Some (Record _) | Some Extensible | None -> None
198-
199180
let any_in_type (typ : TypeDecl.t) name =
200181
let rec find_cons = function
201182
| ({ TypeDecl.Constructor.name = name'; _ } as cons) :: _ when name' = name

src/xref2/find.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ val extension_in_sig : Signature.t -> string -> extension option
7171

7272
val any_in_type : TypeDecl.t -> string -> any_in_type option
7373

74-
val constructor_in_type : TypeDecl.t -> string -> constructor option
75-
7674
val any_in_typext : Extension.t -> string -> extension option
7775

7876
val method_in_class_signature : ClassSignature.t -> string -> method_ option
@@ -116,8 +114,6 @@ type careful_module_type =
116114

117115
type careful_type = [ type_ | removed_type ]
118116

119-
type careful_datatype = [ datatype | removed_type ]
120-
121117
type careful_class = [ class_ | removed_type ]
122118

123119
val careful_module_in_sig : Signature.t -> string -> careful_module option
@@ -127,6 +123,4 @@ val careful_module_type_in_sig :
127123

128124
val careful_type_in_sig : Signature.t -> string -> careful_type option
129125

130-
val careful_datatype_in_sig : Signature.t -> string -> careful_datatype option
131-
132126
val careful_class_in_sig : Signature.t -> string -> careful_class option

src/xref2/link.ml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ let rec should_reresolve : Paths.Path.Resolved.t -> bool =
106106
should_reresolve (x :> t) || should_resolve (y :> Paths.Path.t)
107107
| `CanonicalType (x, y) ->
108108
should_reresolve (x :> t) || should_resolve (y :> Paths.Path.t)
109-
| `CanonicalDataType (x, y) ->
110-
should_reresolve (x :> t) || should_resolve (y :> Paths.Path.t)
111109
| `Apply (x, y) ->
112110
should_reresolve (x :> t) || should_reresolve (y :> Paths.Path.Resolved.t)
113111
| `SubstT (x, y) -> should_reresolve (x :> t) || should_reresolve (y :> t)
@@ -122,19 +120,12 @@ let rec should_reresolve : Paths.Path.Resolved.t -> bool =
122120
| `ModuleType (p, _)
123121
| `Module (p, _) ->
124122
should_reresolve (p :> t)
125-
| `Constructor (p, _) -> should_reresolve (p :> t)
126123
| `OpaqueModule m -> should_reresolve (m :> t)
127124
| `OpaqueModuleType m -> should_reresolve (m :> t)
128125

129126
and should_resolve : Paths.Path.t -> bool =
130127
fun p -> match p with `Resolved p -> should_reresolve p | _ -> true
131128

132-
(* and should_resolve_constructor : Paths.Path.Constructor.t -> bool = *)
133-
(* fun p -> *)
134-
(* match p with *)
135-
(* | `Resolved p -> should_reresolve (p :> Paths.Path.Resolved.t) *)
136-
(* | _ -> true *)
137-
138129
let type_path : Env.t -> Paths.Path.Type.t -> Paths.Path.Type.t =
139130
fun env p ->
140131
if not (should_resolve (p :> Paths.Path.t)) then p
@@ -171,27 +162,6 @@ let value_path : Env.t -> Paths.Path.Value.t -> Paths.Path.Value.t =
171162
Errors.report ~what:(`Value_path cp) ~tools_error:e `Lookup;
172163
p)
173164

174-
let constructor_path :
175-
Env.t -> Paths.Path.Constructor.t -> Paths.Path.Constructor.t =
176-
fun env p ->
177-
(* if not (should_resolve (p : Paths.Path.Constructor.t :> Paths.Path.t)) then p *)
178-
(* else *)
179-
if not (should_resolve_constructor p) then p
180-
else
181-
let cp = Component.Of_Lang.(constructor_path (empty ()) p) in
182-
match cp with
183-
| `Resolved p ->
184-
let result = Tools.reresolve_constructor env p in
185-
`Resolved Lang_of.(Path.resolved_constructor (empty ()) result)
186-
| _ -> (
187-
match Tools.resolve_constructor_path env cp with
188-
| Ok p' ->
189-
let result = Tools.reresolve_constructor env p' in
190-
`Resolved Lang_of.(Path.resolved_constructor (empty ()) result)
191-
| Error e ->
192-
Errors.report ~what:(`Constructor_path cp) ~tools_error:e `Lookup;
193-
p)
194-
195165
let class_type_path : Env.t -> Paths.Path.ClassType.t -> Paths.Path.ClassType.t
196166
=
197167
fun env p ->

0 commit comments

Comments
 (0)