Skip to content

Commit c33f978

Browse files
committed
refactor away unecessary dot check
1 parent 48a92a2 commit c33f978

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

compiler/syntax/src/res_core.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -4087,8 +4087,7 @@ and parse_atomic_typ_expr ?current_type_name_path ?inline_types ~attrs p =
40874087
args
40884088
|> List.filter (fun (c : Parsetree.core_type) ->
40894089
match c.ptyp_desc with
4090-
| Ptyp_constr ({txt = Lident typename}, _)
4091-
when String.contains typename '.' ->
4090+
| Ptyp_constr ({txt = Lident typename}, _) ->
40924091
inline_types
40934092
|> List.exists (fun (name, _, _) -> name = typename)
40944093
| _ -> false)

compiler/syntax/src/res_printer.ml

+18-13
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ let polyvar_ident_to_string poly_var_ident =
450450
Doc.concat [Doc.text "#"; print_poly_var_ident poly_var_ident]
451451
|> Doc.to_string ~width:80
452452

453+
let find_inline_record_definition inline_record_name
454+
(inline_record_definitions : Parsetree.type_declaration list option) =
455+
match inline_record_definitions with
456+
| None -> None
457+
| Some inline_record_definitions ->
458+
inline_record_definitions
459+
|> List.find_opt (fun (r : Parsetree.type_declaration) ->
460+
r.ptype_name.txt = inline_record_name)
461+
453462
let print_lident l =
454463
let flat_lid_opt lid =
455464
let rec flat accu = function
@@ -1714,21 +1723,17 @@ and print_typ_expr ?inline_record_definitions ~(state : State.t)
17141723
print_object ~state ~inline:false fields open_flag cmt_tbl
17151724
| Ptyp_arrow {arity} -> print_arrow ~arity typ_expr
17161725
| Ptyp_constr ({txt = Lident inline_record_name}, [])
1717-
when inline_record_definitions |> Option.is_some
1718-
&& String.contains inline_record_name '.' -> (
1719-
let inline_record_definitions =
1720-
match inline_record_definitions with
1721-
| None -> []
1722-
| Some v -> v
1723-
in
1724-
let record_definition =
1726+
when inline_record_definitions
1727+
|> find_inline_record_definition inline_record_name
1728+
|> Option.is_some -> (
1729+
match
17251730
inline_record_definitions
1726-
|> List.find_opt (fun (r : Parsetree.type_declaration) ->
1727-
r.ptype_name.txt = inline_record_name)
1728-
in
1729-
match record_definition with
1731+
|> find_inline_record_definition inline_record_name
1732+
with
17301733
| Some {ptype_kind = Ptype_record lds} ->
1731-
print_record_declaration ~inline_record_definitions ~state lds cmt_tbl
1734+
print_record_declaration
1735+
~inline_record_definitions:(inline_record_definitions |> Option.get)
1736+
~state lds cmt_tbl
17321737
| _ -> assert false)
17331738
| Ptyp_constr
17341739
(longident_loc, [{ptyp_desc = Ptyp_object (fields, open_flag)}]) ->

0 commit comments

Comments
 (0)