The literal-conflict fix spells a whole float with its point, and the measuring switch says what it is for

This commit is contained in:
Joseph Ferano 2026-09-26 06:26:24 +07:00
parent 5177586848
commit 0a1f5a3483

View File

@ -3631,7 +3631,10 @@ let restart_sig tys =
let dyn_i64 = Types.Int Types.I64 let dyn_i64 = Types.Int Types.I64
let dyn_f64 = Types.Float Types.F64 let dyn_f64 = Types.Float Types.F64
(* PROTOTYPE switch for measuring the literal rules; removed before merge. *) (* The switch the literal rules of TODO.org's "Dyn unless annotated" were
measured with: [f32] makes an unconstrained float literal f32, [dyn] makes
an unwanted text or vector literal dyn, [log] prints each literal local
inference moved off its default. Deleted once those rules are decided. *)
let lit_mode = try Sys.getenv "FLAN_LIT" with Not_found -> "" let lit_mode = try Sys.getenv "FLAN_LIT" with Not_found -> ""
let lit_has m = List.mem m (String.split_on_char ',' lit_mode) let lit_has m = List.mem m (String.split_on_char ',' lit_mode)
let float_default () = if lit_has "f32" then Types.F32 else Types.F64 let float_default () = if lit_has "f32" then Types.F32 else Types.F64
@ -7331,7 +7334,10 @@ and lit_conflict (k : Ast.expr) name t1 l1 t2 l2 =
| Ast.Call (_, [ { Ast.e = Ast.Float x; _ } ]) -> Printf.sprintf "%g" (-.x) | Ast.Call (_, [ { Ast.e = Ast.Float x; _ } ]) -> Printf.sprintf "%g" (-.x)
| _ -> "..." | _ -> "..."
in in
let lit = if String.length lit > 0 && lit.[0] <> '-' && not (String.contains lit '.') && lit_kind k = Some `Float then lit ^ ".0" else lit in (* %g drops the point from a whole float; put it back so the fix reads as
a float literal. 1e+20 already does. *)
let whole = lit <> "" && String.for_all (fun c -> (c >= '0' && c <= '9') || c = '-') lit in
let lit = if whole && lit_kind k = Some `Float then lit ^ ".0" else lit in
let fix = let fix =
if fln_source k.Ast.loc then Printf.sprintf "let %s: %s = %s" name (tyname l1 t1) lit if fln_source k.Ast.loc then Printf.sprintf "let %s: %s = %s" name (tyname l1 t1) lit
else Printf.sprintf "(%s %s)" (tyname l1 t1) lit else Printf.sprintf "(%s %s)" (tyname l1 t1) lit