From a454aaf1d44af364a8eb9d9366625f49f3bb9fe2 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Mon, 4 Dec 2023 16:40:15 -0800 Subject: [PATCH 1/5] feat: Remove stem deduce Some private subproofs are not shown in the catalog and this breaks dependencies --- Pantograph/Symbol.lean | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Pantograph/Symbol.lean b/Pantograph/Symbol.lean index 5fbb0d0..a473b98 100644 --- a/Pantograph/Symbol.lean +++ b/Pantograph/Symbol.lean @@ -6,11 +6,7 @@ def is_symbol_unsafe_or_internal (n: Lean.Name) (info: Lean.ConstantInfo): Bool let nameDeduce: Bool := match n.getRoot with | .str _ name => name.startsWith "_" ∨ name == "Lean" | _ => true - let stemDeduce: Bool := match n with - | .anonymous => true - | .str _ name => name.startsWith "_" - | .num _ _ => true - nameDeduce ∨ stemDeduce ∨ info.isUnsafe + nameDeduce ∨ info.isUnsafe def to_compact_symbol_name (n: Lean.Name) (info: Lean.ConstantInfo): String := let pref := match info with From 07ade4c8221a20b583e49b09d41eca11a5ff69ba Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Mon, 4 Dec 2023 23:36:09 -0800 Subject: [PATCH 2/5] feat: Expose _private names --- Pantograph/Symbol.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pantograph/Symbol.lean b/Pantograph/Symbol.lean index a473b98..07bbc2c 100644 --- a/Pantograph/Symbol.lean +++ b/Pantograph/Symbol.lean @@ -4,7 +4,7 @@ namespace Pantograph def is_symbol_unsafe_or_internal (n: Lean.Name) (info: Lean.ConstantInfo): Bool := let nameDeduce: Bool := match n.getRoot with - | .str _ name => name.startsWith "_" ∨ name == "Lean" + | .str _ name => name == "Lean" | _ => true nameDeduce ∨ info.isUnsafe From 9f2b07757f78b9fd8be86f2f3a052acc534136ef Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Tue, 5 Dec 2023 19:07:00 -0800 Subject: [PATCH 3/5] feat: Display whether a symbol is private --- Pantograph.lean | 1 + Pantograph/Protocol.lean | 1 + Pantograph/Symbol.lean | 11 ++++++----- Test/Catalog.lean | 33 +++++++++++++++++++++++++++++++++ Test/Integration.lean | 4 ++-- Test/Main.lean | 4 +++- 6 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 Test/Catalog.lean diff --git a/Pantograph.lean b/Pantograph.lean index 2f712e7..cc4096d 100644 --- a/Pantograph.lean +++ b/Pantograph.lean @@ -85,6 +85,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do return .ok { type := ← serialize_expression state.options info.type, value? := ← value?.mapM (λ v => serialize_expression state.options v), + isPrivate := Lean.isPrivateName name, typeDependency? := if args.dependency?.getD false then .some <| info.type.getUsedConstants.map (λ n => name_to_ast n) else .none, valueDependency? := if args.dependency?.getD false then info.value?.map (·.getUsedConstants.map (λ n => name_to_ast n)) else .none, module? := module? diff --git a/Pantograph/Protocol.lean b/Pantograph/Protocol.lean index 95c0236..f99acb0 100644 --- a/Pantograph/Protocol.lean +++ b/Pantograph/Protocol.lean @@ -120,6 +120,7 @@ structure LibInspectResult where type: Expression value?: Option Expression := .none module?: Option String + isPrivate: Bool typeDependency?: Option (Array String) := .none valueDependency?: Option (Array String) := .none deriving Lean.ToJson diff --git a/Pantograph/Symbol.lean b/Pantograph/Symbol.lean index 07bbc2c..ba80877 100644 --- a/Pantograph/Symbol.lean +++ b/Pantograph/Symbol.lean @@ -1,12 +1,13 @@ -import Lean.Declaration +import Lean namespace Pantograph def is_symbol_unsafe_or_internal (n: Lean.Name) (info: Lean.ConstantInfo): Bool := - let nameDeduce: Bool := match n.getRoot with - | .str _ name => name == "Lean" - | _ => true - nameDeduce ∨ info.isUnsafe + isLeanSymbol n ∨ (Lean.privateToUserName? n |>.map isLeanSymbol |>.getD false) ∨ info.isUnsafe + where + isLeanSymbol (name: Lean.Name): Bool := match name.getRoot with + | .str _ name => name == "Lean" + | _ => true def to_compact_symbol_name (n: Lean.Name) (info: Lean.ConstantInfo): String := let pref := match info with diff --git a/Test/Catalog.lean b/Test/Catalog.lean new file mode 100644 index 0000000..e082369 --- /dev/null +++ b/Test/Catalog.lean @@ -0,0 +1,33 @@ +import LSpec +import Pantograph.Serial +import Pantograph.Symbol + +namespace Pantograph.Test.Catalog + +open Pantograph +open Lean + +def test_symbol_visibility (env: Environment): IO LSpec.TestSeq := do + let entries: List (Name × Bool) := [ + ("Nat.add_comm".toName, false), + ("Lean.Name".toName, true), + ("_private.Init.0.Lean.Name".toName, true) + ] + let suite := entries.foldl (λ suites (symbol, target) => + let constant := env.constants.find! symbol + let test := LSpec.check symbol.toString ((is_symbol_unsafe_or_internal symbol constant) == target) + LSpec.TestSeq.append suites test) LSpec.TestSeq.done + return suite + + + +def suite: IO LSpec.TestSeq := do + let env: Environment ← importModules + (imports := #["Init"].map (λ str => { module := str.toName, runtimeOnly := false })) + (opts := {}) + (trustLevel := 1) + + return LSpec.group "Catalog" $ + (LSpec.group "Symbol visibility" (← test_symbol_visibility env)) + +end Pantograph.Test.Catalog diff --git a/Test/Integration.lean b/Test/Integration.lean index 65c2da6..bfe1766 100644 --- a/Test/Integration.lean +++ b/Test/Integration.lean @@ -52,7 +52,7 @@ def test_option_modify : IO LSpec.TestSeq := subroutine_step "lib.inspect" [("name", .str "Nat.add_one")] (Lean.toJson ({ - type := { pp? }, module? }: + type := { pp? }, module?, isPrivate := false }: Protocol.LibInspectResult)), subroutine_step "options.set" [("printExprAST", .bool true)] @@ -61,7 +61,7 @@ def test_option_modify : IO LSpec.TestSeq := subroutine_step "lib.inspect" [("name", .str "Nat.add_one")] (Lean.toJson ({ - type := { pp?, sexp? }, module? }: + type := { pp?, sexp? }, module?, isPrivate := false }: Protocol.LibInspectResult)), subroutine_step "options.print" [] diff --git a/Test/Main.lean b/Test/Main.lean index 82d8748..5178e85 100644 --- a/Test/Main.lean +++ b/Test/Main.lean @@ -1,4 +1,5 @@ import LSpec +import Test.Catalog import Test.Holes import Test.Integration import Test.Proofs @@ -13,7 +14,8 @@ def main := do Holes.suite, Integration.suite, Proofs.suite, - Serial.suite + Serial.suite, + Catalog.suite ] let all ← suites.foldlM (λ acc m => do pure $ acc ++ (← m)) LSpec.TestSeq.done LSpec.lspecIO $ all From da74258dd192fc03b4a43aca818ca815466312f8 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Tue, 5 Dec 2023 20:20:08 -0800 Subject: [PATCH 4/5] feat!: Display public name only if name is private --- Pantograph.lean | 2 +- Pantograph/Protocol.lean | 3 ++- Test/Integration.lean | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Pantograph.lean b/Pantograph.lean index cc4096d..958e43c 100644 --- a/Pantograph.lean +++ b/Pantograph.lean @@ -85,7 +85,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do return .ok { type := ← serialize_expression state.options info.type, value? := ← value?.mapM (λ v => serialize_expression state.options v), - isPrivate := Lean.isPrivateName name, + publicName? := Lean.privateToUserName? name |>.map (·.toString), typeDependency? := if args.dependency?.getD false then .some <| info.type.getUsedConstants.map (λ n => name_to_ast n) else .none, valueDependency? := if args.dependency?.getD false then info.value?.map (·.getUsedConstants.map (λ n => name_to_ast n)) else .none, module? := module? diff --git a/Pantograph/Protocol.lean b/Pantograph/Protocol.lean index f99acb0..582ee1d 100644 --- a/Pantograph/Protocol.lean +++ b/Pantograph/Protocol.lean @@ -120,7 +120,8 @@ structure LibInspectResult where type: Expression value?: Option Expression := .none module?: Option String - isPrivate: Bool + -- If the name is private, displays the public facing name + publicName?: Option String := .none typeDependency?: Option (Array String) := .none valueDependency?: Option (Array String) := .none deriving Lean.ToJson diff --git a/Test/Integration.lean b/Test/Integration.lean index bfe1766..65c2da6 100644 --- a/Test/Integration.lean +++ b/Test/Integration.lean @@ -52,7 +52,7 @@ def test_option_modify : IO LSpec.TestSeq := subroutine_step "lib.inspect" [("name", .str "Nat.add_one")] (Lean.toJson ({ - type := { pp? }, module?, isPrivate := false }: + type := { pp? }, module? }: Protocol.LibInspectResult)), subroutine_step "options.set" [("printExprAST", .bool true)] @@ -61,7 +61,7 @@ def test_option_modify : IO LSpec.TestSeq := subroutine_step "lib.inspect" [("name", .str "Nat.add_one")] (Lean.toJson ({ - type := { pp?, sexp? }, module?, isPrivate := false }: + type := { pp?, sexp? }, module? }: Protocol.LibInspectResult)), subroutine_step "options.print" [] From cf856d28801b9df0283cbdbb46c96d89951ca238 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Tue, 5 Dec 2023 20:21:07 -0800 Subject: [PATCH 5/5] chore: Version bump --- Pantograph/Version.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pantograph/Version.lean b/Pantograph/Version.lean index a96b83a..d71bedb 100644 --- a/Pantograph/Version.lean +++ b/Pantograph/Version.lean @@ -1,5 +1,5 @@ namespace Pantograph -def version := "0.2.9" +def version := "0.2.10" end Pantograph