diff --git a/analysis/reanalyze/src/arnold.ml b/analysis/reanalyze/src/arnold.ml index 419f0241d8..4221e00adc 100644 --- a/analysis/reanalyze/src/arnold.ml +++ b/analysis/reanalyze/src/arnold.ml @@ -974,16 +974,7 @@ module Compile = struct | Texp_field (e, _lid, _desc) -> e |> expression ~ctx | Texp_record {fields; extended_expression} -> extended_expression - :: (fields |> Array.to_list - |> List.map - (fun - ( _desc, - (record_label_definition : Typedtree.record_label_definition), - _ ) - -> - match record_label_definition with - | Kept _typeExpr -> None - | Overridden (_loc, e) -> Some e)) + :: (fields |> Array.to_list |> List.map (fun (_desc, _lid, e) -> Some e)) |> List.map (expression_opt ~ctx) |> Command.unordered_sequence | Texp_setfield (e1, _loc, _desc, e2) -> diff --git a/analysis/reanalyze/src/dead_value.ml b/analysis/reanalyze/src/dead_value.ml index b532bd5817..425bdf83b2 100644 --- a/analysis/reanalyze/src/dead_value.ml +++ b/analysis/reanalyze/src/dead_value.ml @@ -288,9 +288,9 @@ let rec collect_expr ~config ~decls ~refs ~file_deps ~cross_file ~direct_callees ~pos_from:loc_from.loc_start | Texp_record {fields} -> fields - |> Array.iter (fun (_, record_label_definition, _) -> - match record_label_definition with - | Typedtree.Overridden (_, ({exp_loc} as e)) when exp_loc.loc_ghost -> + |> Array.iter (fun (_, _, (e : Typedtree.expression)) -> + match e with + | {exp_loc} when exp_loc.loc_ghost -> (* Punned field in OCaml projects has ghost location in expression *) let e = {e with exp_loc = {exp_loc with loc_ghost = false}} in collect_expr ~config ~decls ~refs ~file_deps ~cross_file diff --git a/analysis/reanalyze/src/side_effects.ml b/analysis/reanalyze/src/side_effects.ml index b7447ac228..5ada934847 100644 --- a/analysis/reanalyze/src/side_effects.ml +++ b/analysis/reanalyze/src/side_effects.ml @@ -88,11 +88,7 @@ and expr_opt_no_side_effects eo = | None -> true | Some e -> e |> expr_no_side_effects -and field_no_side_effects - ((_ld, rld, _) : _ * Typedtree.record_label_definition * _) = - match rld with - | Kept _typeExpr -> true - | Overridden (_lid, e) -> e |> expr_no_side_effects +and field_no_side_effects (_ld, _lid, e) = e |> expr_no_side_effects and case_no_side_effects : Typedtree.case -> _ = fun {c_guard; c_rhs} -> diff --git a/analysis/src/process_extra.ml b/analysis/src/process_extra.ml index 4f14dc3136..af339909f9 100644 --- a/analysis/src/process_extra.ml +++ b/analysis/src/process_extra.ml @@ -434,10 +434,8 @@ let expr ~env ~(extra : extra) (iter : Tast_iterator.iterator) | Texp_record {fields} -> add_for_record ~env ~extra ~record_type:expression.exp_type (fields |> Array.to_list - |> Utils.filter_map (fun (desc, item, opt) -> - match item with - | Typedtree.Overridden (loc, _) -> Some (loc, desc, (), opt) - | _ -> None)) + |> List.map (fun (desc, (loc : Longident.t Location.loc), _) -> + (loc, desc, (), false))) | Texp_constant constant -> add_loc_item extra expression.exp_loc (Constant constant) (* Skip unit and list literals *) diff --git a/changes/references-omitted-record-fields.fix.md b/changes/references-omitted-record-fields.fix.md new file mode 100644 index 0000000000..00240055e7 --- /dev/null +++ b/changes/references-omitted-record-fields.fix.md @@ -0,0 +1 @@ +- Editor "find references" on a record field no longer lists record literals that leave the optional field out. diff --git a/changes/sparse-record-fields.polish.md b/changes/sparse-record-fields.polish.md new file mode 100644 index 0000000000..22d9b1fb8d --- /dev/null +++ b/changes/sparse-record-fields.polish.md @@ -0,0 +1 @@ +- Stop storing a `None` expression for every optional field a record literal leaves out. Modules with many JSX DOM elements now compile up to 10× faster, use far less memory, and get `.cmt` files up to 30× smaller. diff --git a/compiler/ml/printtyped.ml b/compiler/ml/printtyped.ml index aeef6ee13a..a8b453aca0 100644 --- a/compiler/ml/printtyped.ml +++ b/compiler/ml/printtyped.ml @@ -738,11 +738,9 @@ and value_binding i ppf x = pattern (i + 1) ppf x.vb_pat; expression (i + 1) ppf x.vb_expr -and record_field i ppf = function - | _, Overridden (li, e), opt -> - line i ppf "%a%s\n" fmt_longident li (if opt then "?" else ""); - expression (i + 1) ppf e - | _, Kept _, _ -> line i ppf "" +and record_field i ppf (_, li, e) = + line i ppf "%a\n" fmt_longident li; + expression (i + 1) ppf e and label_x_expression i ppf (l, e) = line i ppf "\n"; diff --git a/compiler/ml/rec_check.ml b/compiler/ml/rec_check.ml index fb8210bd00..a5990c95e5 100644 --- a/compiler/ml/rec_check.ml +++ b/compiler/ml/rec_check.ml @@ -296,10 +296,7 @@ let rec expression : Env.env -> Typedtree.expression -> Use.t = | Record_unboxed _ -> fun x -> x | Record_regular | Record_inlined _ | Record_extension -> Use.guard in - let field env = function - | _, Kept _, _ -> Use.empty - | _, Overridden (_, e), _ -> expression env e - in + let field env (_, _, e) = expression env e in Use.join (use (array field env es)) (option expression env eo) | Texp_ifthenelse (cond, ifso, ifnot) -> Use.( @@ -499,10 +496,10 @@ let check_recursive_bindings valbinds = in Ext_list.iter valbinds (fun {vb_expr} -> match vb_expr.exp_desc with - | Texp_record - {fields = [|(_, Overridden (_, {exp_desc = Texp_function _}), _)|]} - | Texp_function _ -> + | Texp_record {fields = [|(lbl, _, {exp_desc = Texp_function _})|]} + when Array.length lbl.lbl_all = 1 -> () + | Texp_function _ -> () (*TODO: add uncurried function too*) | _ -> check_recursive_expression ids vb_expr) diff --git a/compiler/ml/tast_iterator.ml b/compiler/ml/tast_iterator.ml index 64966ea428..be2375b7ec 100644 --- a/compiler/ml/tast_iterator.ml +++ b/compiler/ml/tast_iterator.ml @@ -169,11 +169,7 @@ let expr sub {exp_extra; exp_desc; exp_env; _} = | Texp_construct (_, _, args) -> List.iter (sub.expr sub) args | Texp_variant (_, expo) -> Option.iter (sub.expr sub) expo | Texp_record {fields; extended_expression; _} -> - Array.iter - (function - | _, Kept _, _ -> () - | _, Overridden (_, exp), _ -> sub.expr sub exp) - fields; + Array.iter (fun (_, _, exp) -> sub.expr sub exp) fields; Option.iter (sub.expr sub) extended_expression | Texp_field (exp, _, _) -> sub.expr sub exp | Texp_setfield (exp1, _, _, exp2) -> diff --git a/compiler/ml/tast_mapper.ml b/compiler/ml/tast_mapper.ml index c3585180b4..1da305bb24 100644 --- a/compiler/ml/tast_mapper.ml +++ b/compiler/ml/tast_mapper.ml @@ -229,10 +229,7 @@ let expr sub x = | Texp_record {fields; representation; extended_expression} -> let fields = Array.map - (function - | label, Kept t, o -> (label, Kept t, o) - | label, Overridden (lid, exp), o -> - (label, Overridden (lid, sub.expr sub exp), o)) + (fun (label, lid, exp) -> (label, lid, sub.expr sub exp)) fields in Texp_record diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 876fc390a2..694081abae 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -958,7 +958,7 @@ type jsx_props = | Jsx_props_spread of expression (** The PPX passes the spread itself when there are no other props *) | Jsx_props_record of { - fields: (label_description * record_label_definition * bool) array; + fields: (label_description * Longident.t loc * expression) array; init: expression option; copy_fields: bool; (** [transl_record]'s choice: copy the fields of [init] one by one, @@ -1017,19 +1017,37 @@ let jsx_children ~multi (lbl : label_description) (child : expression) = Some children | _ -> None +(* All labels of the record a [Texp_record] builds. Its [fields] hold only the + written ones. *) +let all_labels + (fields : (label_description * Longident.t loc * expression) array) = + match fields with + | [||] -> [||] + | _ -> + let lbl, _, _ = fields.(0) in + lbl.lbl_all + +(* Each label of the record with the expression the literal writes for it, if + any, in position order. *) +let fields_by_position fields = + let written = Array.map (fun _ -> None) (all_labels fields) in + Array.iter (fun (lbl, _, exp) -> written.(lbl.lbl_pos) <- Some exp) fields; + Array.mapi (fun i lbl -> (lbl, written.(i))) (all_labels fields) + (* How [transl_record] builds a record: by copying the fields of [init] one by one (or with no [init] at all), or by taking a shallow copy of [init] and setting the other fields. JSX props follow the same rule. TODO: More strategies 3 + 2 * List.length lbl_expr_list >= size (density) *) let record_copies_fields - (fields : (label_description * record_label_definition * bool) array) + (fields : (label_description * Longident.t loc * expression) array) ~(init : expression option) = match init with | None -> true | Some _ -> - Array.length fields < 20 - && not (Array.exists (fun (lbl, _, _) -> lbl.lbl_optional) fields) + let lbl_all = all_labels fields in + Array.length lbl_all < 20 + && not (Array.exists (fun lbl -> lbl.lbl_optional) lbl_all) let jsx_props_of ~multi (props : expression) = match props.exp_desc with @@ -1044,12 +1062,10 @@ let jsx_props_of ~multi (props : expression) = in let children = Array.to_list fields - |> List.find_map (fun ((lbl : label_description), definition, _) -> - match definition with - | Overridden (_, child) - when lbl.lbl_name = "children" && not (is_omitted lbl child) -> + |> List.find_map (fun ((lbl : label_description), _, child) -> + if lbl.lbl_name = "children" && not (is_omitted lbl child) then Some (lbl, child) - | Overridden _ | Kept _ -> None) + else None) in let copy_fields = record_copies_fields fields ~init in let record children = @@ -1058,9 +1074,9 @@ let jsx_props_of ~multi (props : expression) = let is_array = Lambda.record_fields_are_array (Array.map - (fun ((lbl : label_description), _, _) -> + (fun (lbl : label_description) -> (lbl.lbl_runtime_name, lbl.lbl_optional)) - fields) + (all_labels fields)) in match children with (* a record with the runtime names "0", "1", ... is an array *) @@ -1689,27 +1705,32 @@ and transl_jsx_element loc (* An optional prop that is statically [undefined] can be left out, unless it overrides a prop of the spread *) let has_spread = Option.is_some init && not copy_fields in + let field (lbl : label_description) value = + Some (lbl.lbl_runtime_name, lbl.lbl_optional && not has_spread, value) + in + let written (lbl : label_description) value = + if lbl.lbl_name = "children" && Option.is_some children then None + else field lbl (transl_exp value) + in let fields = - Array.to_list fields - |> List.mapi (fun i (lbl, definition, _) -> (i, lbl, definition)) - |> List.filter_map (fun (i, (lbl : label_description), definition) -> - let field value = - Some - (lbl.lbl_runtime_name, lbl.lbl_optional && not has_spread, value) - in - match definition with - | Overridden _ - when lbl.lbl_name = "children" && Option.is_some children -> - None - | Overridden (_, value) -> field (transl_exp value) - | Kept _ when copy_fields -> - field - (prim - ~primitive: - (Pfield (i, Lambda.fld_record lbl.lbl_runtime_name)) - ~args:[var init_id] - loc) - | Kept _ -> None) + match init with + | Some _ when copy_fields -> + (* the props the literal leaves out are copied from [init] *) + fields_by_position fields |> Array.to_list + |> List.filter_map (fun ((lbl : label_description), value) -> + match value with + | Some value -> written lbl value + | None -> + field lbl + (prim + ~primitive: + (Pfield + (lbl.lbl_pos, Lambda.fld_record lbl.lbl_runtime_name)) + ~args:[var init_id] + loc)) + | _ -> + Array.to_list fields + |> List.filter_map (fun (lbl, _, value) -> written lbl value) in let children = Option.map transl_list children in let init, spread = @@ -1749,15 +1770,15 @@ and transl_jsx_element loc and transl_record loc env fields repres opt_init_expr = (* The runtime shape of the record: each field's runtime name, and whether it is optional. *) + let lbl_all = all_labels fields in let field_shape () = - fields - |> Array.map (fun ((lbl : Types.label_description), _, _) -> + lbl_all + |> Array.map (fun (lbl : Types.label_description) -> (lbl.lbl_runtime_name, lbl.lbl_optional)) in let field_names () = - fields - |> Array.map (fun ((lbl : Types.label_description), _, _) -> - lbl.lbl_runtime_name) + lbl_all + |> Array.map (fun (lbl : Types.label_description) -> lbl.lbl_runtime_name) in match (opt_init_expr, repres, fields) with | _ -> ( @@ -1767,9 +1788,12 @@ and transl_record loc env fields repres opt_init_expr = let init_id = Ident.create "init" in let lv = Array.mapi - (fun i (lbl, definition, _) -> - match definition with - | Kept _ -> + (fun i (lbl, value) -> + match (value, opt_init_expr) with + | Some expr, _ -> transl_exp expr + (* an optional field the literal leaves out *) + | None, None -> const const_shape_none + | None, Some _ -> let access = match repres with | Record_regular -> @@ -1781,14 +1805,12 @@ and transl_record loc env fields repres opt_init_expr = Pfield (i + 1, Lambda.fld_record_extension lbl.lbl_runtime_name) in - prim ~primitive:access ~args:[var init_id] loc - | Overridden (_lid, expr) -> transl_exp expr) - fields + prim ~primitive:access ~args:[var init_id] loc) + (fields_by_position fields) in let ll = Array.to_list lv in let mut = - if Array.exists (fun (lbl, _, _) -> lbl.lbl_mut = Mutable) fields then - Mutable + if Array.exists (fun lbl -> lbl.lbl_mut = Mutable) lbl_all then Mutable else Immutable in let lam = @@ -1847,7 +1869,7 @@ and transl_record loc env fields repres opt_init_expr = | _ -> assert false) | Record_extension -> let path = - let label, _, _ = fields.(0) in + let label = lbl_all.(0) in match label.lbl_res.desc with | Tconstr (p, _, _) -> p | _ -> assert false @@ -1865,26 +1887,21 @@ and transl_record loc env fields repres opt_init_expr = (* Take a shallow copy of the init record, then mutate the fields of the copy *) let copy_id = Ident.create "newrecord" in - let update_field cont (lbl, definition, _opt) = - match definition with - | Kept _type -> cont - | Overridden (_lid, expr) -> - let upd = - match repres with - | Record_regular -> - Psetfield (lbl.lbl_pos, Lambda.fld_record_set lbl.lbl_runtime_name) - | Record_inlined _ -> - Psetfield - (lbl.lbl_pos, Lambda.fld_record_inline_set lbl.lbl_runtime_name) - | Record_unboxed _ -> assert false - | Record_extension -> - Psetfield - ( lbl.lbl_pos + 1, - Lambda.fld_record_extension_set lbl.lbl_runtime_name ) - in - seq - (prim ~primitive:upd ~args:[var copy_id; transl_exp expr] loc) - cont + let update_field cont (lbl, _lid, expr) = + let upd = + match repres with + | Record_regular -> + Psetfield (lbl.lbl_pos, Lambda.fld_record_set lbl.lbl_runtime_name) + | Record_inlined _ -> + Psetfield + (lbl.lbl_pos, Lambda.fld_record_inline_set lbl.lbl_runtime_name) + | Record_unboxed _ -> assert false + | Record_extension -> + Psetfield + ( lbl.lbl_pos + 1, + Lambda.fld_record_extension_set lbl.lbl_runtime_name ) + in + seq (prim ~primitive:upd ~args:[var copy_id; transl_exp expr] loc) cont in match opt_init_expr with | None -> assert false diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index c3658e2585..ddb271dfa5 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -384,6 +384,23 @@ let type_option ty = newty (Tconstr (Predef.path_option, [ty], ref Mnil)) let mkexp exp_desc exp_type exp_loc exp_env = {exp_desc; exp_type; exp_loc; exp_env; exp_extra = []; exp_attributes = []} +(* Which labels of a record a literal writes, indexed by [lbl_pos]. *) +let written_labels (lbl_all : label_description array) lbl_exp_list = + let written = Array.make (Array.length lbl_all) false in + List.iter (fun (_, lbl, _, _) -> written.(lbl.lbl_pos) <- true) lbl_exp_list; + written + +(* The fields of a [Texp_record]: the written ones, ordered by [lbl_pos]. *) +let record_fields lbl_exp_list = + let fields = + Array.of_list + (List.map (fun (lid, lbl, exp, _) -> (lbl, lid, exp)) lbl_exp_list) + in + Array.sort + (fun (l1, _, _) (l2, _, _) -> Int.compare l1.lbl_pos l2.lbl_pos) + fields; + fields + let option_none ty loc = let lid = Longident.Lident "None" and env = Env.initial_safe_string () in let cnone = Env.lookup_constructor lid env in @@ -2068,14 +2085,20 @@ let rec is_nonexpansive exp = | Texp_tuple el -> List.for_all is_nonexpansive el | Texp_construct (_, _, el) -> List.for_all is_nonexpansive el | Texp_variant (_, arg) -> is_nonexpansive_opt arg - | Texp_record {fields; extended_expression} -> + | Texp_record {fields; extended_expression} -> ( Array.for_all - (fun (lbl, definition, _) -> - match definition with - | Overridden (_, exp) -> lbl.lbl_mut = Immutable && is_nonexpansive exp - | Kept _ -> true) + (fun (lbl, _, exp) -> lbl.lbl_mut = Immutable && is_nonexpansive exp) fields - && is_nonexpansive_opt extended_expression + && + match extended_expression with + | Some exp -> is_nonexpansive exp + | None -> ( + (* The optional fields the literal leaves out are allocated too *) + match fields with + | [||] -> true + | _ -> + let lbl, _, _ = fields.(0) in + Array.for_all (fun lbl -> lbl.lbl_mut = Immutable) lbl.lbl_all)) | Texp_field (exp, _, _) -> is_nonexpansive exp | Texp_array [] -> false | Texp_ifthenelse (_cond, ifso, ifnot) -> @@ -3039,39 +3062,24 @@ and type_expect_ ?deprecated_context ~context ?(recarg = Rejected) if fields = [] && repr_opt <> None then ([||], Record_regular) else raise (Error (loc, env, Empty_record_literal)) in - let labels_missing = ref [] in - let label_definitions = - let matching_label lbl = - List.find - (fun (_, lbl', _, _) -> lbl'.lbl_pos = lbl.lbl_pos) - lbl_exp_list - in - Array.map - (fun lbl -> - match matching_label lbl with - | lid, _lbl, lbl_exp, _ -> Overridden (lid, lbl_exp) - | exception Not_found -> - if not (label_is_optional lbl) then - labels_missing := lbl.lbl_name :: !labels_missing; - Overridden - ({loc; txt = Lident lbl.lbl_name}, option_none lbl.lbl_arg loc)) - label_descriptions + let written = written_labels label_descriptions lbl_exp_list in + let labels_missing = + Array.to_list label_descriptions + |> List.filter_map (fun lbl -> + if written.(lbl.lbl_pos) || label_is_optional lbl then None + else Some lbl.lbl_name) in - if !labels_missing <> [] then + if labels_missing <> [] then raise (Error ( loc, env, Labels_missing { - labels = List.rev !labels_missing; + labels = labels_missing; jsx_component_info = jsx_component_error_info; } )); - let fields = - Array.map2 - (fun descr def -> (descr, def, false)) - label_descriptions label_definitions - in + let fields = record_fields lbl_exp_list in re { exp_desc = @@ -3126,30 +3134,22 @@ and type_expect_ ?deprecated_context ~context ?(recarg = Rejected) in unify_exp_types ~context:None loc env ty_record (instance env ty_expected); check_duplicates ~get_jsx_component_error_info loc env lbl_exp_list; - let opt_exp, label_definitions = + let opt_exp = let _lid, lbl, _lbl_exp, _opt = List.hd lbl_exp_list in - let matching_label lbl = - List.find - (fun (_, lbl', _, _) -> lbl'.lbl_pos = lbl.lbl_pos) - lbl_exp_list - in + let written = written_labels lbl.lbl_all lbl_exp_list in let ty_exp = instance env exp.exp_type in let unify_kept lbl = let _, ty_arg1, ty_res1 = instance_label false lbl in unify_exp_types ~context:None exp.exp_loc env ty_exp ty_res1; - match matching_label lbl with - | lid, _lbl, lbl_exp, _ -> - (* do not connect result types for overridden labels *) - Overridden (lid, lbl_exp) - | exception Not_found -> + (* do not connect result types for overridden labels *) + if not written.(lbl.lbl_pos) then ( let _, ty_arg2, ty_res2 = instance_label false lbl in unify_exp_types ~context:None loc env ty_arg1 ty_arg2; unify_exp_types ~context:None loc env (instance env ty_expected) - ty_res2; - Kept ty_arg1 + ty_res2) in - let label_definitions = Array.map unify_kept lbl.lbl_all in - (Some {exp with exp_type = ty_exp}, label_definitions) + Array.iter unify_kept lbl.lbl_all; + Some {exp with exp_type = ty_exp} in let num_fields = match lbl_exp_list with @@ -3162,15 +3162,11 @@ and type_expect_ ?deprecated_context ~context ?(recarg = Rejected) None) else opt_exp in - let label_descriptions, representation = - let _, {lbl_all; lbl_repres}, _, _ = List.hd lbl_exp_list in - (lbl_all, lbl_repres) - in - let fields = - Array.map2 - (fun descr def -> (descr, def, false)) - label_descriptions label_definitions + let representation = + let _, {lbl_repres}, _, _ = List.hd lbl_exp_list in + lbl_repres in + let fields = record_fields lbl_exp_list in re { exp_desc = diff --git a/compiler/ml/typedtree.ml b/compiler/ml/typedtree.ml index a72aa2099b..78414d58e0 100644 --- a/compiler/ml/typedtree.ml +++ b/compiler/ml/typedtree.ml @@ -110,11 +110,7 @@ and expression_desc = Longident.t loc * constructor_description * expression list | Texp_variant of label * expression option | Texp_record of { - fields: - (Types.label_description - * record_label_definition - * bool (* optional *)) - array; + fields: (Types.label_description * Longident.t loc * expression) array; representation: Types.record_representation; extended_expression: expression option; } @@ -186,10 +182,6 @@ and function_param = { of the body. *) } -and record_label_definition = - | Kept of Types.type_expr - | Overridden of Longident.t loc * expression - (* Value expressions for the module language *) and module_expr = { mod_desc: module_expr_desc; diff --git a/compiler/ml/typedtree.mli b/compiler/ml/typedtree.mli index 6484730d86..15d7b6750f 100644 --- a/compiler/ml/typedtree.mli +++ b/compiler/ml/typedtree.mli @@ -218,23 +218,22 @@ and expression_desc = *) | Texp_variant of label * expression option | Texp_record of { - fields: - (Types.label_description - * record_label_definition - * bool (* optional *)) - array; + fields: (Types.label_description * Longident.t loc * expression) array; representation: Types.record_representation; extended_expression: expression option; } (** { l1=P1; ...; ln=Pn } (extended_expression = None) { E0 with l1=P1; ...; ln=Pn } (extended_expression = Some E0) - Invariant: n > 0 + [fields] holds only the fields the literal writes, ordered by + [lbl_pos]. A field it leaves out is taken from E0 when there is + one, and is otherwise an optional field set to [None]. The + record's other labels are in [lbl_all] of any written label. If the type is { l1: t1; l2: t2 }, the expression { E0 with t2=P2 } is represented as Texp_record - { fields = [| l1, Kept t1; l2 Override P2 |]; representation; + { fields = [| (l2, lid2, P2) |]; representation; extended_expression = Some E0 } *) | Texp_field of expression * Longident.t loc * label_description @@ -305,10 +304,6 @@ and function_param = { of the body. *) } -and record_label_definition = - | Kept of Types.type_expr - | Overridden of Longident.t loc * expression - (* Value expressions for the module language *) and module_expr = { mod_desc: module_expr_desc; diff --git a/compiler/ml/typedtree_iter.ml b/compiler/ml/typedtree_iter.ml index 3480686a55..da1c37aab7 100644 --- a/compiler/ml/typedtree_iter.ml +++ b/compiler/ml/typedtree_iter.ml @@ -252,11 +252,7 @@ end = struct | None -> () | Some exp -> iter_expression exp) | Texp_record {fields; extended_expression; _} -> ( - Array.iter - (function - | _, Kept _, _ -> () - | _, Overridden (_, exp), _ -> iter_expression exp) - fields; + Array.iter (fun (_, _, exp) -> iter_expression exp) fields; match extended_expression with | None -> () | Some exp -> iter_expression exp) diff --git a/tests/analysis_tests/tests/src/References.res b/tests/analysis_tests/tests/src/References.res index b3762e0b6e..75b774ddb1 100644 --- a/tests/analysis_tests/tests/src/References.res +++ b/tests/analysis_tests/tests/src/References.res @@ -22,4 +22,10 @@ let dd = M.aa // ^ref let _ = -// ^ref \ No newline at end of file +// ^ref + +type labelled = {name: string, label?: string} +let withLabel = {name: "a", label: "b"} +let withoutLabel = {name: "c"} +let _ = withLabel.label +// ^ref \ No newline at end of file diff --git a/tests/analysis_tests/tests/src/expected/References.res.txt b/tests/analysis_tests/tests/src/expected/References.res.txt index f106eb290c..de78420043 100644 --- a/tests/analysis_tests/tests/src/expected/References.res.txt +++ b/tests/analysis_tests/tests/src/expected/References.res.txt @@ -119,3 +119,28 @@ References src/References.res 23:15 } ] +References src/References.res 29:19 +[ + { + "range": { + "end": { "character": 36, "line": 26 }, + "start": { "character": 31, "line": 26 } + }, + "uri": "file:///References.res" + }, + { + "range": { + "end": { "character": 33, "line": 27 }, + "start": { "character": 28, "line": 27 } + }, + "uri": "file:///References.res" + }, + { + "range": { + "end": { "character": 23, "line": 29 }, + "start": { "character": 18, "line": 29 } + }, + "uri": "file:///References.res" + } +] + diff --git a/tests/build_tests/super_errors/expected/record_omitted_mutable_does_not_generalize.res.expected b/tests/build_tests/super_errors/expected/record_omitted_mutable_does_not_generalize.res.expected new file mode 100644 index 0000000000..edf363a80e --- /dev/null +++ b/tests/build_tests/super_errors/expected/record_omitted_mutable_does_not_generalize.res.expected @@ -0,0 +1,16 @@ + + We've found a bug for you! + /.../fixtures/record_omitted_mutable_does_not_generalize.res:5:25-34 + + 3 │ let cell = {tag: 0} + 4 │ cell.value = Some(1) + 5 │ let s: option = cell.value + 6 │ + + This has type: option + But it's expected to have type: option + + The incompatible parts: + int vs string + + You can convert int to string with Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/fixtures/record_omitted_mutable_does_not_generalize.res b/tests/build_tests/super_errors/fixtures/record_omitted_mutable_does_not_generalize.res new file mode 100644 index 0000000000..3bed6cd96a --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/record_omitted_mutable_does_not_generalize.res @@ -0,0 +1,5 @@ +type cell<'a> = {tag: int, mutable value?: 'a} + +let cell = {tag: 0} +cell.value = Some(1) +let s: option = cell.value