···8686 Types
8787 (Nicolas Chataing, review by Jacques Garrigue)
88888989+- #10555: Do not use ghost locations for type constraints
9090+ (Nicolás Ojeda Bär, report by Anton Bachin, review by Thomas Refis)
9191+8992### Build system:
90939194- #10471: Fix detection of arm32 architectures with musl in the configure
···103106 Moreover, poll point insertion must be disabled for `caml_send*`,
104107 otherwise the derived pointer is live across a poll point.
105108 (Vincent Laviron and Xavier Leroy, review by Xavier Leroy and Sadiq Jaffer)
109109+110110+- #10539: Field kinds should be kept when copying types
111111+ Losing the sharing meant that one could desynchronize them between several
112112+ occurences of self, allowing a method to be both public and hidden,
113113+ which broke type soundness.
114114+ (Jacques Garrigue, review by Leo White)
106115107116- #10542: Fix detection of immediate64 types through unboxed types.
108117 (Leo White, review by Stephen Dolan and Gabriel Scherer)
···700709- #10468: Correctly pretty print local type substitution, e.g. type t := ...,
701710 with -dsource
702711 (Matt Else, review by Florian Angeletti)
712712+713713+- #10550, #10551: fix pretty-print of gadt-pattern-with-type-vars
714714+ (Chet Murthy, review by Gabriel Scherer)
703715704716OCaml 4.12, maintenance version
705717-------------------------------
···208208209209let mkexp_constraint ~loc e (t1, t2) =
210210 match t1, t2 with
211211- | Some t, None -> ghexp ~loc (Pexp_constraint(e, t))
212212- | _, Some t -> ghexp ~loc (Pexp_coerce(e, t1, t))
211211+ | Some t, None -> mkexp ~loc (Pexp_constraint(e, t))
212212+ | _, Some t -> mkexp ~loc (Pexp_coerce(e, t1, t))
213213 | None, None -> assert false
214214215215let mkexp_opt_constraint ~loc e = function
···218218219219let mkpat_opt_constraint ~loc p = function
220220 | None -> p
221221- | Some typ -> ghpat ~loc (Ppat_constraint(p, typ))
221221+ | Some typ -> mkpat ~loc (Ppat_constraint(p, typ))
222222223223let syntax_error () =
224224 raise Syntaxerr.Escape_error
···389389let loc_lident (id : string Location.loc) : Longident.t Location.loc =
390390 loc_map (fun x -> Lident x) id
391391392392-let exp_of_longident ~loc lid =
393393- let lid = make_ghost (loc_map (fun id -> Lident (Longident.last id)) lid) in
394394- ghexp ~loc (Pexp_ident lid)
392392+let exp_of_longident lid =
393393+ let lid = loc_map (fun id -> Lident (Longident.last id)) lid in
394394+ Exp.mk ~loc:lid.loc (Pexp_ident lid)
395395396396-let exp_of_label ~loc lbl =
397397- mkexp ~loc (Pexp_ident (loc_lident lbl))
396396+let exp_of_label lbl =
397397+ Exp.mk ~loc:lbl.loc (Pexp_ident (loc_lident lbl))
398398399399let pat_of_label lbl =
400400 Pat.mk ~loc:lbl.loc (Ppat_var (loc_last lbl))
···26322632 | label = mkrhs(label_longident)
26332633 c = type_constraint?
26342634 eo = preceded(EQUAL, expr)?
26352635- { let e =
26352635+ { let constraint_loc, label, e =
26362636 match eo with
26372637 | None ->
26382638 (* No pattern; this is a pun. Desugar it. *)
26392639- exp_of_longident ~loc:$sloc label
26392639+ $sloc, make_ghost label, exp_of_longident label
26402640 | Some e ->
26412641- e
26412641+ ($startpos(c), $endpos), label, e
26422642 in
26432643- label, mkexp_opt_constraint ~loc:$sloc e c }
26432643+ label, mkexp_opt_constraint ~loc:constraint_loc e c }
26442644;
26452645%inline object_expr_content:
26462646 xs = separated_or_terminated_nonempty_list(SEMI, object_expr_field)
···26492649%inline object_expr_field:
26502650 label = mkrhs(label)
26512651 oe = preceded(EQUAL, expr)?
26522652- { let e =
26522652+ { let label, e =
26532653 match oe with
26542654 | None ->
26552655 (* No expression; this is a pun. Desugar it. *)
26562656- exp_of_label ~loc:$sloc label
26562656+ make_ghost label, exp_of_label label
26572657 | Some e ->
26582658- e
26582658+ label, e
26592659 in
26602660 label, e }
26612661;
···28432843 label = mkrhs(label_longident)
28442844 octy = preceded(COLON, core_type)?
28452845 opat = preceded(EQUAL, pattern)?
28462846- { let label, pat =
28462846+ { let constraint_loc, label, pat =
28472847 match opat with
28482848 | None ->
28492849 (* No pattern; this is a pun. Desugar it.
28502850 But that the pattern was there and the label reconstructed (which
28512851 piece of AST is marked as ghost is important for warning
28522852 emission). *)
28532853- make_ghost label, pat_of_label label
28532853+ $sloc, make_ghost label, pat_of_label label
28542854 | Some pat ->
28552855- label, pat
28552855+ ($startpos(octy), $endpos), label, pat
28562856 in
28572857- label, mkpat_opt_constraint ~loc:$sloc pat octy
28572857+ label, mkpat_opt_constraint ~loc:constraint_loc pat octy
28582858 }
28592859;
28602860
+3-1
parsing/pprintast.ml
···9595let needs_spaces txt =
9696 first_is '*' txt || last_is '*' txt
97979898+let string_loc ppf x = fprintf ppf "%s" x.txt
9999+98100(* add parentheses to binders when they are in fact infix or prefix operators *)
99101let protect_ident ppf txt =
100102 let format : (_, _, _) format =
···446448 pp f "%a@;%a" longident_loc li (simple_pattern ctxt) x
447449 | Some (vl, x) ->
448450 pp f "%a@ (type %a)@;%a" longident_loc li
449449- (list ~sep:"@ " tyvar_loc) vl
451451+ (list ~sep:"@ " string_loc) vl
450452 (simple_pattern ctxt) x
451453 | None -> pp f "%a" longident_loc li)
452454 | _ -> simple_pattern ctxt f x
···57575858let x = function { contents : int = i } -> i;;
59596060+let _ =
6161+ object val foo = 12 method x foo = {< foo >} end
6262+;;
6363+6064(* Local open *)
61656266let x = M.{ contents = 3 };;
+2
testsuite/tests/parsetree/source.ml
···74417441let g y =
74427442 let f ~y = y + 1 in
74437443 f ~(y:int)
74447444+74457445+let goober a = match a with C (type a b) y -> y
+73
testsuite/tests/typing-objects/field_kind.ml
···11+(* TEST
22+ * expect
33+*)
44+55+type _ t = Int : int t;;
66+[%%expect{|
77+type _ t = Int : int t
88+|}]
99+1010+let o =
1111+ object (self)
1212+ method private x = 3
1313+ method m : type a. a t -> a = fun Int -> (self#x : int)
1414+ end;;
1515+[%%expect{|
1616+val o : < m : 'a. 'a t -> 'a > = <obj>
1717+|}]
1818+1919+let o' =
2020+ object (self : 's)
2121+ method private x = 3
2222+ method m : type a. a t -> 's -> a = fun Int other -> (other#x : int)
2323+ end;;
2424+2525+let aargh = assert (o'#m Int o' = 3);;
2626+[%%expect{|
2727+Lines 2-5, characters 2-5:
2828+2 | ..object (self : 's)
2929+3 | method private x = 3
3030+4 | method m : type a. a t -> 's -> a = fun Int other -> (other#x : int)
3131+5 | end..
3232+Warning 15 [implicit-public-methods]: the following private methods were made public implicitly:
3333+ x.
3434+val o' : < m : 'a. 'a t -> 'b -> 'a; x : int > as 'b = <obj>
3535+val aargh : unit = ()
3636+|}]
3737+3838+let o2 =
3939+ object (self : 's)
4040+ method private x = 3
4141+ method m : 's -> int = fun other -> (other#x : int)
4242+ end;;
4343+[%%expect{|
4444+Lines 2-5, characters 2-5:
4545+2 | ..object (self : 's)
4646+3 | method private x = 3
4747+4 | method m : 's -> int = fun other -> (other#x : int)
4848+5 | end..
4949+Warning 15 [implicit-public-methods]: the following private methods were made public implicitly:
5050+ x.
5151+val o2 : < m : 'a -> int; x : int > as 'a = <obj>
5252+|}]
5353+5454+let o3 =
5555+ object (self : 's)
5656+ method private x = 3
5757+ method m : 's -> int = fun other ->
5858+ let module M = struct let other = other end in (M.other#x : int)
5959+ end;;
6060+6161+let aargh = assert (o3#m o3 = 3);;
6262+[%%expect{|
6363+Lines 2-6, characters 2-5:
6464+2 | ..object (self : 's)
6565+3 | method private x = 3
6666+4 | method m : 's -> int = fun other ->
6767+5 | let module M = struct let other = other end in (M.other#x : int)
6868+6 | end..
6969+Warning 15 [implicit-public-methods]: the following private methods were made public implicitly:
7070+ x.
7171+val o3 : < m : 'a -> int; x : int > as 'a = <obj>
7272+val aargh : unit = ()
7373+|}]
+2
toplevel/toploop.ml
···9696 use_input ppf ~wrap_in_module:true name
9797let use_input ppf name =
9898 use_input ppf ~wrap_in_module:false name
9999+let use_file ppf name =
100100+ use_input ppf (File name)
99101100102let use_silently ppf name =
101103 Misc.protect_refs
+1
toplevel/toploop.mli
···9595val use_output : formatter -> string -> bool
9696val use_silently : formatter -> input -> bool
9797val mod_use_input : formatter -> input -> bool
9898+val use_file : formatter -> string -> bool
9899 (* Read and execute commands from a file.
99100 [use_input] prints the types and values of the results.
100101 [use_silently] does not print them.
+3-21
typing/btype.ml
···494494495495 val redirect_desc: copy_scope -> type_expr -> type_desc -> unit
496496497497- val dup_kind: copy_scope -> field_kind option ref -> unit
498498-499497 val with_scope: (copy_scope -> 'a) -> 'a
500498end = struct
501499 type copy_scope = {
502500 mutable saved_desc : (transient_expr * type_desc) list;
503501 (* Save association of generic nodes with their description. *)
504504-505505- mutable saved_kinds: field_kind option ref list;
506506- (* duplicated kind variables *)
507507-508508- mutable new_kinds : field_kind option ref list;
509509- (* new kind variables *)
510502 }
511503512504 let redirect_desc copy_scope ty desc =
···514506 copy_scope.saved_desc <- (ty, ty.desc) :: copy_scope.saved_desc;
515507 Transient_expr.set_desc ty desc
516508517517- let dup_kind copy_scope r =
518518- assert (Option.is_none !r);
519519- if not (List.memq r copy_scope.new_kinds) then begin
520520- copy_scope.saved_kinds <- r :: copy_scope.saved_kinds;
521521- let r' = ref None in
522522- copy_scope.new_kinds <- r' :: copy_scope.new_kinds;
523523- r := Some (Fvar r')
524524- end
525525-526509 (* Restore type descriptions. *)
527527- let cleanup { saved_desc; saved_kinds; _ } =
528528- List.iter (fun (ty, desc) -> Transient_expr.set_desc ty desc) saved_desc;
529529- List.iter (fun r -> r := None) saved_kinds
510510+ let cleanup { saved_desc; _ } =
511511+ List.iter (fun (ty, desc) -> Transient_expr.set_desc ty desc) saved_desc
530512531513 let with_scope f =
532532- let scope = { saved_desc = []; saved_kinds = []; new_kinds = [] } in
514514+ let scope = { saved_desc = [] } in
533515 let res = f scope in
534516 cleanup scope;
535517 res
-3
typing/btype.mli
···185185 val redirect_desc: copy_scope -> type_expr -> type_desc -> unit
186186 (* Temporarily change a type description *)
187187188188- val dup_kind: copy_scope -> field_kind option ref -> unit
189189- (* Save a None field_kind, and make it point to a fresh Fvar *)
190190-191188 val with_scope: (copy_scope -> 'a) -> 'a
192189 (* [with_scope f] calls [f] and restores saved type descriptions
193190 before returning its result. *)
-8
typing/ctype.ml
···11191119 (* Return a new copy *)
11201120 Tvariant (copy_row copy true row keep more')
11211121 end
11221122- | Tfield (_p, k, _ty1, ty2) ->
11231123- begin match field_kind_repr k with
11241124- Fabsent -> Tlink (copy ty2)
11251125- | Fpresent -> copy_type_desc copy desc
11261126- | Fvar r ->
11271127- For_copy.dup_kind scope r;
11281128- copy_type_desc copy desc
11291129- end
11301122 | Tobject (ty1, _) when partial <> None ->
11311123 Tobject (copy ty1, ref None)
11321124 | _ -> copy_type_desc ?keep_names copy desc