Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ece20ae
feat: add Cslib.Init module and checkInitImports linter
jessealama Oct 26, 2025
c013fcd
fix: address PR feedback on checkInitImports implementation
jessealama Oct 27, 2025
88f7ec2
feat: add allowlist for modules excluded from Cslib.Init
jessealama Oct 27, 2025
c1e573e
refactor: use .erase pattern for exclusions
jessealama Oct 27, 2025
b1e53e5
chore: remove unused namespace opens
jessealama Oct 27, 2025
a7d8804
chore: revert lakefile.toml comment changes
jessealama Oct 27, 2025
5020ca3
style: move copyright to beginning of file
jessealama Oct 27, 2025
831b7cb
refactor: use getRoot to check namespace prefix
jessealama Oct 28, 2025
f18fa9e
refactor: integrate import checks into lake test
jessealama Oct 28, 2025
e83f03e
refactor: simplify CheckCslibComplete with functional style
jessealama Oct 28, 2025
b20382e
use ImportGraph to account for transitive imports
chenson2018 Oct 29, 2025
e7cf196
Merge remote-tracking branch 'refs/remotes/jesse/add-cslib-init' into…
chenson2018 Oct 29, 2025
830f76f
work on CheckCslibComplete, put back Jesse's better error messages
chenson2018 Oct 29, 2025
acdc4c8
import Cslib.Init in Cslib.lean
chenson2018 Oct 29, 2025
5941474
include CslibTests in runner
chenson2018 Oct 29, 2025
586a125
Merge remote-tracking branch 'upstream/main' into add-cslib-init
chenson2018 Oct 29, 2025
836aba5
add Cslib.Init
chenson2018 Oct 29, 2025
d60f1d2
mk_all-check arg in CI
chenson2018 Oct 29, 2025
5841b3a
remove CheckCslibComplete
chenson2018 Oct 29, 2025
5ce159f
format TODOs for the bot
chenson2018 Oct 29, 2025
36f89d2
Merge remote-tracking branch 'upstream/main' into add-cslib-init
chenson2018 Oct 29, 2025
70a8d59
alpha order
chenson2018 Oct 29, 2025
e80fd0a
some CI failures after merge
chenson2018 Oct 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lean_action_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
- uses: leanprover/lean-action@v1
with:
build-args: "--wfail"
mk_all-check: "true"
1 change: 1 addition & 0 deletions Cslib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Cslib.Foundations.Semantics.ReductionSystem.Basic
import Cslib.Foundations.Syntax.HasAlphaEquiv
import Cslib.Foundations.Syntax.HasSubstitution
import Cslib.Foundations.Syntax.HasWellFormed
import Cslib.Init
import Cslib.Languages.CCS.Basic
import Cslib.Languages.CCS.BehaviouralTheory
import Cslib.Languages.CCS.Semantics
Expand Down
1 change: 1 addition & 0 deletions Cslib/Computability/Languages/Language.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Authors: Ching-Tsun Chou

import Mathlib.Computability.Language
import Mathlib.Tactic
import Cslib.Init

/-!
# Language (additional definitions and theorems)
Expand Down
4 changes: 2 additions & 2 deletions Cslib/Computability/Languages/OmegaLanguage.lean
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ theorem le_omegaPow_congr [Inhabited α] {l1 l2 : Language α} (h : l1 ≤ l2) :
theorem omegaPow_of_sub_one [Inhabited α] : (l - 1)^ω = l^ω := by
ext s ; simp

@[simp]
@[simp, nolint simpNF]
theorem zero_omegaPow [Inhabited α] : (0 : Language α)^ω = ⊥ := by
ext s ; simp

@[simp]
@[simp, nolint simpNF]
theorem one_omegaPow [Inhabited α] : (1 : Language α)^ω = ⊥ := by
rw [← omegaPow_of_sub_one, tsub_self, zero_omegaPow]

Expand Down
1 change: 1 addition & 0 deletions Cslib/Foundations/Control/Monad/Free.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright (c) 2025 Tanner Duve. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tanner Duve, Eric Wieser
-/
import Cslib.Init
import Mathlib.Tactic.Lemma
import Mathlib.Tactic.SimpRw

Expand Down
2 changes: 2 additions & 0 deletions Cslib/Foundations/Data/FinFun.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi, Xueying Qin
-/

-- TODO: Notation conflict with Mathlib.Finsupp (both use →₀)
-- import Cslib.Init
import Mathlib.Data.Finset.Basic

/-! # Finite functions
Expand Down
1 change: 1 addition & 0 deletions Cslib/Foundations/Data/HasFresh.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi, Kenny Lau
-/

import Cslib.Init
import Mathlib.Algebra.Field.Rat
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Algebra.Ring.Int.Defs
Expand Down
1 change: 1 addition & 0 deletions Cslib/Foundations/Data/Nat/Segment.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ching-Tsun Chou
-/

import Cslib.Init
import Mathlib.Algebra.Order.Sub.Basic
import Mathlib.Data.Nat.Nth
import Mathlib.Tactic
Expand Down
1 change: 1 addition & 0 deletions Cslib/Foundations/Data/OmegaSequence/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright (c) 2025 Ching-Tsun Chou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ching-Tsun Chou, Fabrizio Montesi
-/
import Cslib.Init
import Mathlib.Data.Nat.Notation
import Mathlib.Data.FunLike.Basic
import Mathlib.Logic.Function.Iterate
Expand Down
6 changes: 3 additions & 3 deletions Cslib/Foundations/Data/OmegaSequence/Flatten.lean
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ theorem append_flatten [Inhabited α] {ls : ωSequence (List α)} (h_ls : ∀ k,
induction n generalizing ls <;> grind [tail_eq_drop, take_succ]

/-- The length of `(ls.take n).flatten` is `ls.cumLen n`. -/
@[simp, scoped grind =]
theorem length_flatten_take [Inhabited α] {ls : ωSequence (List α)} (h_ls : ∀ k, (ls k).length > 0)
@[simp, nolint simpNF, scoped grind =]
theorem length_flatten_take {ls : ωSequence (List α)} (h_ls : ∀ k, (ls k).length > 0)
(n : ℕ) : (ls.take n).flatten.length = ls.cumLen n := by
induction n <;> grind [take_succ']

Expand Down Expand Up @@ -169,7 +169,7 @@ theorem toSegs_def (s : ωSequence α) (f : ℕ → ℕ) (n : ℕ) :

/-- `(s.toSegs f).cumLen` is `f` itself. -/
@[simp]
theorem segment_toSegs_cumLen [Inhabited α] {f : ℕ → ℕ}
theorem segment_toSegs_cumLen {f : ℕ → ℕ}
(hm : StrictMono f) (h0 : f 0 = 0) (s : ωSequence α) :
(s.toSegs f).cumLen = f := by
ext n
Expand Down
1 change: 1 addition & 0 deletions Cslib/Foundations/Data/Relation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi, Thomas Waring, Chris Henson
-/

import Cslib.Init
import Mathlib.Logic.Relation

/-! # Relations -/
Expand Down
2 changes: 2 additions & 0 deletions Cslib/Foundations/Semantics/LTS/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi
-/

-- TODO: Causes type elaboration ambiguities in downstream files (Automata)
-- import Cslib.Init
import Mathlib.Tactic.Lemma
import Mathlib.Data.Finite.Defs
import Mathlib.Data.Fintype.Basic
Expand Down
1 change: 1 addition & 0 deletions Cslib/Foundations/Semantics/ReductionSystem/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi, Thomas Waring
-/

import Cslib.Init
import Mathlib.Logic.Relation
import Mathlib.Util.Notation3

Expand Down
2 changes: 2 additions & 0 deletions Cslib/Foundations/Syntax/HasAlphaEquiv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi
-/

import Cslib.Init

namespace Cslib

/-- Typeclass for the α-equivalence notation `x =α y`. -/
Expand Down
2 changes: 2 additions & 0 deletions Cslib/Foundations/Syntax/HasSubstitution.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi
-/

import Cslib.Init

namespace Cslib

/-- Typeclass for substitution relations and access to their notation. -/
Expand Down
2 changes: 2 additions & 0 deletions Cslib/Foundations/Syntax/HasWellFormed.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi
-/

import Cslib.Init

namespace Cslib

/-- Typeclass for types equipped with a well-formedness predicate. -/
Expand Down
18 changes: 18 additions & 0 deletions Cslib/Init.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/-
Copyright (c) 2025 Jesse Alama. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jesse Alama
-/

import Mathlib.Init
import Cslib.Foundations.Lint.Basic

/-!
# CSLib Initialization

This is the root file in CSLib: it is imported by virtually *all* CSLib files.
For this reason, the imports of this file are carefully curated.

Similar to Mathlib.Init, this file imports linters that should be active by default
throughout the CSLib library.
-/
1 change: 1 addition & 0 deletions Cslib/Languages/CCS/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi
-/

import Cslib.Init
import Mathlib.Init

/-! # Calculus of Communicating Systems (CCS)
Expand Down
2 changes: 2 additions & 0 deletions Cslib/Logics/LinearLogic/CLL/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi
-/

-- TODO: Syntax elaboration conflicts
-- import Cslib.Init
import Aesop
import Mathlib.Tactic.ApplyAt
import Mathlib.Order.Notation
Expand Down
2 changes: 1 addition & 1 deletion CslibTests.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CslibTests.CCS
import CslibTests.DFA
import CslibTests.FreeMonad
import CslibTests.HasFresh
import CslibTests.LTS
import CslibTests.LambdaCalculus
import CslibTests.Lint
import CslibTests.LTS
import CslibTests.ReductionSystem
12 changes: 11 additions & 1 deletion lakefile.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "cslib"
version = "0.1.0"
defaultTargets = ["Cslib"]
testDriver = "CslibTests"
testDriver = "runTests"

[leanOptions]
weak.linter.mathlibStandardSet = true
Expand All @@ -25,3 +25,13 @@ globs = ["Cslib.*"]
[[lean_lib]]
name = "CslibTests"
globs = ["CslibTests.+"]

[[lean_exe]]
name = "checkInitImports"
srcDir = "scripts"
root = "CheckInitImports"

[[lean_exe]]
name = "runTests"
srcDir = "scripts"
root = "RunTests"
58 changes: 58 additions & 0 deletions scripts/CheckInitImports.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/-
Copyright (c) 2025 Jesse Alama. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jesse Alama, Chris Henson
-/

import Lean
import Mathlib.Lean.CoreM
import Batteries.Data.List.Basic
import ImportGraph.Imports

open Lean Core Elab Command

/-!
# Check Init Imports

This script checks that all CSLib modules (transitively) import Cslib.Init.
-/

/-- Modules with technical constraints preventing Cslib.Init import -/
def exceptions : List Name := [
-- Circular dependency (imported by Cslib.Init)
`Cslib.Foundations.Lint.Basic,
`Cslib.Init,

-- Type elaboration issues in downstream files
`Cslib.Foundations.Semantics.LTS.Basic,
`Cslib.Foundations.Semantics.LTS.TraceEq,
`Cslib.Computability.Automata.DA,
`Cslib.Computability.Automata.DFA,
`Cslib.Computability.Automata.DFAToNFA,
`Cslib.Computability.Automata.EpsilonNFA,
`Cslib.Computability.Automata.EpsilonNFAToNFA,
`Cslib.Computability.Automata.NA,
`Cslib.Computability.Automata.NFA,
`Cslib.Computability.Automata.NFAToDFA,

-- Notation conflict with Mathlib.Finsupp (→₀)
`Cslib.Foundations.Data.FinFun,

-- Syntax elaboration conflicts
`Cslib.Logics.LinearLogic.CLL.Basic,
`Cslib.Logics.LinearLogic.CLL.CutElimination,
`Cslib.Logics.LinearLogic.CLL.MProof,
`Cslib.Logics.LinearLogic.CLL.PhaseSemantics.Basic,
]

def main : IO UInt32 := do
let searchPath ← addSearchPathFromEnv (← getBuiltinSearchPath (← findSysroot))
CoreM.withImportModules #[`Cslib] (searchPath := searchPath) (trustLevel := 1024) do
let env ← getEnv
let graph := env.importGraph.transitiveClosure
let noInitGraph :=
graph.filter (fun name imports => name.getRoot = `Cslib ∧ !imports.contains `Cslib.Init)
let diff := noInitGraph.keys.diff exceptions
if diff.length > 0 then
IO.eprintln s!"error: the following modules do not import `Cslib.Init`: {diff}"
return diff.length.toUInt32
41 changes: 41 additions & 0 deletions scripts/RunTests.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/-
Copyright (c) 2025 Jesse Alama. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jesse Alama
-/

/-!
# Test Runner

This script runs all CSLib tests including:
- Building the CslibTests library
- Running init imports validation
-/

def main (_ : List String) : IO UInt32 := do
-- build CslibTests
IO.println "building CslibTests..."
let CslibTestsResult ← IO.Process.spawn {
cmd := "lake"
args := #["build", "CslibTests"]
} >>= (·.wait)

if CslibTestsResult != 0 then
IO.eprintln "\n✗ CslibTests build failed"
return CslibTestsResult
else
println! ""

-- Run init imports check
IO.println "\nChecking init imports..."
let checkResult ← IO.Process.spawn {
cmd := "lake"
args := #["exe", "checkInitImports"]
} >>= (·.wait)

if checkResult != 0 then
IO.eprintln "\n✗ Init imports check failed"
return checkResult

IO.println "\n✓ All tests passed"
return 0