Skip to content

Commit 172733f

Browse files
septractclaude
andcommitted
Remove redundant keyword escaping fallback and explicit class renames
The lean_reserved_names fallback in backend_common and the explicit declare {lean} rename type Eq = Eq0 / Ord = Ord0 in basic_classes.lem were added to work around a Cerberus team build issue (stale object files). Since rename_top_level already handles keyword escaping via lean_constants, both mechanisms were redundant. Keeps: typed_ast_syntax.ml class rename support (genuine infrastructure fix — declare rename type now works for classes), and the test cases for prefix/guard/show keyword patterns. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c8ffabd commit 172733f

File tree

5 files changed

+4
-29
lines changed

5 files changed

+4
-29
lines changed

lean-lib/LemLib/Function.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open Lem_Basic_classes
1818
/- removed value specification -/
1919

2020
/-
21-
def id0 {a : Type} (x : a) : a := x -/
21+
def id {a : Type} (x : a) : a := x -/
2222
/- removed value specification -/
2323

2424
/- removed top-level value definition -/
@@ -36,7 +36,7 @@ def rev_apply {a : Type} {b : Type} (x : a) (f : a → b) : b := f x
3636
/- removed value specification -/
3737

3838
/-
39-
def flip0 {a : Type} {b : Type} {c : Type} (f : a → b → c) : b → a → c := (fun (x : b) (y : a) => f y x) -/
39+
def flip {a : Type} {b : Type} {c : Type} (f : a → b → c) : b → a → c := (fun (x : b) (y : a) => f y x) -/
4040
/- removed value specification -/
4141

4242
def curry {a : Type} {b : Type} {c : Type} (f : (a ×b) → c) : a → b → c := (fun (a1 : a) (b1 : b) => f (a1, b1))

library/basic_classes.lem

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ( Eq 'a )
2323
val (=) [`isEqual`] : 'a -> 'a -> bool
2424
val (<>) [`isInequal`] : 'a -> 'a -> bool
2525
end
26-
declare {lean} rename type Eq = Eq0
2726

2827
declare coq target_rep function isEqual = infix `=`
2928
declare lean target_rep function isEqual = infix `==`
@@ -157,7 +156,6 @@ class ( Ord 'a )
157156
val (>) [`isGreater`] : 'a -> 'a -> bool
158157
val (>=) [`isGreaterEqual`] : 'a -> 'a -> bool
159158
end
160-
declare {lean} rename type Ord = Ord0
161159

162160
declare coq target_rep function isLess = `isLess`
163161
declare coq target_rep function isLessEqual = `isLessEqual`

src/backend_common.ml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,6 @@ let imported_modules_to_strings env target dir iml relative =
373373
for non-library target reps only. *)
374374
let on_cr_simple_applied : (bool -> string -> unit) ref = ref (fun _ _ -> ())
375375

376-
(* Lean reserved names fallback. When rename_top_level doesn't fire
377-
(e.g., due to build environment issues), the backend can still
378-
escape names by appending "0". Set by lean_backend.ml at startup. *)
379-
let lean_reserved_names : NameSet.t ref = ref NameSet.empty
380-
381-
(* Check if a name needs escaping for Lean and apply the "0" suffix.
382-
Used as a fallback when type_rename/class_rename/target_rename is empty. *)
383-
let lean_escape_reserved (n : Name.t) : Name.t =
384-
if NameSet.mem n !lean_reserved_names then
385-
Name.from_string (String.concat "" [Name.to_string n; "0"])
386-
else n
387-
388376
module Make(A : sig
389377
val env : env;;
390378
val target : Target.target;;
@@ -453,8 +441,6 @@ let const_ref_to_name n0 use_ascii c =
453441
| (Some ascii, true) -> ascii
454442
| _ -> n_no_ascii
455443
in
456-
(* Fallback: if rename_top_level didn't fire, check lean_reserved_names *)
457-
let n = lean_escape_reserved n in
458444
let n' = Name.replace_lskip (Name.add_lskip n) (Name.get_lskip n0) in
459445
n'
460446

@@ -599,8 +585,6 @@ let type_path_to_name n0 (p : Path.t) : Name.lskips_t =
599585
let l = Ast.Trans (false, "type_path_to_name", None) in
600586
let td = Types.type_defs_lookup l A.env.t_env p in
601587
let n = type_descr_to_name A.target p td in
602-
(* Fallback: if rename_top_level didn't fire, check lean_reserved_names *)
603-
let n = lean_escape_reserved n in
604588
let n' = Name.replace_lskip (Name.add_lskip n) (Name.get_lskip n0) in
605589
n'
606590

@@ -609,9 +593,9 @@ let class_path_to_name (p : Path.t) : Name.t =
609593
| Some (Types.Tc_class cd) ->
610594
begin match Target.Targetmap.apply_target cd.Types.class_rename A.target with
611595
| Some (_, n) -> n
612-
| None -> lean_escape_reserved (Path.get_name p)
596+
| None -> Path.get_name p
613597
end
614-
| _ -> lean_escape_reserved (Path.get_name p)
598+
| _ -> Path.get_name p
615599

616600
let type_id_to_ident_aux (p : Path.t id) =
617601
let l = Ast.Trans (false, "type_id_to_ident", None) in

src/backend_common.mli

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ val imported_modules_to_strings : env -> Target.target -> string -> Imported_Mod
112112
Set by the Lean backend to collect per-file import requirements. *)
113113
val on_cr_simple_applied : (bool -> string -> unit) ref
114114

115-
(** Lean reserved names fallback. When rename_top_level doesn't fire,
116-
the backend escapes names that collide with Lean keywords by
117-
appending "0". Set by lean_backend.ml at startup from lean_constants. *)
118-
val lean_reserved_names : Typed_ast.NameSet.t ref
119-
120115
module Make(A : sig
121116
val env : env;;
122117
val target : Target.target;;

src/main.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ end
277277

278278
let transform_for_target libpath modules env targ =
279279
let consts = Initial_env.read_target_constants libpath targ in
280-
(* Make reserved names available to backend_common for fallback escaping *)
281-
Backend_common.lean_reserved_names := consts;
282280

283281
let _ = check_env_for_target targ env in
284282

0 commit comments

Comments
 (0)