Skip to content

Commit

Permalink
Ident_env: Assume unknown types are core types
Browse files Browse the repository at this point in the history
Types that couldn't be found in the environment are looked up in the
list of predefined core types.
This lookup is not expected to fail, as indicated by the presence of an
`assert false`.

This removes the core type lookup and assumes all unknown types are core
types.
  • Loading branch information
Julow committed Jan 23, 2024
1 parent 0bbf974 commit f9ac3b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 43 deletions.
31 changes: 10 additions & 21 deletions src/loader/ident_env.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*)

open Odoc_model
open Predefined
open Names

module Id = Paths.Identifier
Expand Down Expand Up @@ -84,9 +83,6 @@ type items =
| `Include of item list
]

let builtin_idents = List.map snd Predef.builtin_idents


let rec extract_signature_type_items items =
let open Compat in
match items with
Expand Down Expand Up @@ -659,22 +655,17 @@ let find_extension_identifier env id =
let find_value_identifier env id =
Ident.find_same id env.values

(** Lookup a type in the environment. If it isn't found, it's assumed to be a
core type. *)
let find_type env id =
try
(Ident.find_same id env.types :> Id.Path.Type.t)
with Not_found ->
try
(Ident.find_same id env.classes :> Id.Path.Type.t)
with Not_found ->
try
(Ident.find_same id env.class_types :> Id.Path.Type.t)
try (Ident.find_same id env.types :> Id.Path.Type.t)
with Not_found -> (
try (Ident.find_same id env.classes :> Id.Path.Type.t)
with Not_found -> (
try (Ident.find_same id env.class_types :> Id.Path.Type.t)
with Not_found ->
if List.mem id builtin_idents then
match core_type_identifier (Ident.name id) with
| Some id -> (id :> type_ident)
| None -> raise Not_found
else raise Not_found

(Paths.Identifier.Mk.core_type (Ident.name id) :> type_ident)))

let find_class_type env id =
try
(Ident.find_same id env.classes :> Id.Path.ClassType.t)
Expand Down Expand Up @@ -704,9 +695,7 @@ module Path = struct
with Not_found -> assert false

let read_type_ident env id =
try
`Identifier (find_type env id, false)
with Not_found -> assert false
`Identifier (find_type env id, false)

let read_value_ident env id : Paths.Path.Value.t =
`Identifier (find_value_identifier env id, false)
Expand Down
20 changes: 0 additions & 20 deletions src/model/predefined.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,6 @@ let sys_blocked_io_identifier = Mk.core_exception "Sys_blocked_io"
let undefined_recursive_module_identifier =
Mk.core_exception "Undefined_recursive_module"

let core_type_identifier = function
| "int" -> Some int_identifier
| "char" -> Some char_identifier
| "bytes" -> Some bytes_identifier
| "string" -> Some string_identifier
| "float" -> Some float_identifier
| "bool" -> Some bool_identifier
| "unit" -> Some unit_identifier
| "exn" -> Some exn_identifier
| "array" -> Some array_identifier
| "list" -> Some list_identifier
| "option" -> Some option_identifier
| "int32" -> Some int32_identifier
| "int64" -> Some int64_identifier
| "nativeint" -> Some nativeint_identifier
| "lazy_t" -> Some lazy_t_identifier
| "extension_constructor" -> Some extension_constructor_identifier
| "floatarray" -> Some floatarray_identifier
| _ -> None

let core_exception_identifier = function
| "Match_failure" -> Some match_failure_identifier
| "Out_of_memory" -> Some out_of_memory_identifier
Expand Down
2 changes: 0 additions & 2 deletions src/model/predefined.mli
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ val sys_blocked_io_identifier : Identifier.Exception.t

val undefined_recursive_module_identifier : Identifier.Exception.t

val core_type_identifier : string -> Identifier.Type.t option

val core_exception_identifier : string -> Identifier.Exception.t option

val core_constructor_identifier : string -> Identifier.Constructor.t option
Expand Down

0 comments on commit f9ac3b5

Please sign in to comment.