Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
21f6e9c
typescript: model the numbers, the identity, the evaluation order and…
conao3 Dec 1, 2026
d0de024
c: translate enumerators, case labels, typedefs, and names as C reads…
conao3 Dec 1, 2026
82eb03b
typescript: generate the boundary values, duplicates and equal argume…
conao3 Dec 1, 2026
04526d9
python: translate an operation only for the types whose Lean operatio…
conao3 Dec 1, 2026
44ea2cb
python: compare results exactly and generate boundary values in check…
conao3 Dec 1, 2026
78fbd4f
python: convert subclass values and bounds of int fields as Lean's va…
conao3 Dec 1, 2026
68c88f7
typescript: judge the constraints of a model as its validator does, a…
conao3 Dec 1, 2026
7bdb101
go: give JSON Schemas the tighter of the bounds of a type and of its …
conao3 Dec 1, 2026
9b9ed26
go: translate only operations whose model returns the values of Go
conao3 Dec 1, 2026
e5c7382
python: compare every translated operation with Python on boundary va…
conao3 Dec 1, 2026
4b1a6dd
c: refuse more flags, compare enumerators, labels, names, lengths, an…
conao3 Dec 1, 2026
6133a6c
python: take the builtins before the modules of the user run
conao3 Dec 1, 2026
969b7a6
python: say where the operations are tested
conao3 Dec 1, 2026
1a9e728
go: draw boundary values, infinities, NaN and repeated values in rand…
conao3 Dec 1, 2026
c6ad26c
python: generate large numbers for the functions that compute with float
conao3 Dec 1, 2026
a66d2b6
python: check the range of a subclass value after its conversion
conao3 Dec 1, 2026
f1a3bf6
python: compare fields, augmented assignments and lists of bool and s…
conao3 Dec 1, 2026
7b4bc2c
typescript: compare the models of zod, valibot and arktype with their…
conao3 Dec 1, 2026
dde2881
python: give the type of a tuple field that has a Nat
conao3 Dec 1, 2026
fbcbc34
typescript: read the Nat items of a field as Int
conao3 Dec 1, 2026
84a2b35
php: write no bound that a literal of the type or a JSON number does …
conao3 Dec 1, 2026
fd98859
php: generate NaN, infinities, 2^53 + 1, repeated elements and GMP in…
conao3 Dec 1, 2026
b5c298b
php: model the values that PHP computes, and translate nothing whose …
conao3 Dec 1, 2026
4172a82
docs: the PHP values and names that a translation takes
conao3 Dec 1, 2026
718871e
docs: the values, the numbers and the errors of translated TypeScript…
conao3 Dec 1, 2026
cf2c924
go: write the types of the operations of models, so that instances an…
conao3 Dec 1, 2026
56ae9bc
go: list more refused forms in the fixture
conao3 Dec 1, 2026
abc6c89
python: take the hash of the names of a function from functions and e…
conao3 Dec 1, 2026
6849511
typescript: wait for the slow sync of the test of kept files
conao3 Dec 1, 2026
a609645
c: bound JSON schemas by the Lean conditions, refuse GCC-only float a…
conao3 Dec 1, 2026
5ddbded
c: keep locals apart from the names of the types
conao3 Dec 1, 2026
bc55631
rust: translate no function whose model does not return what Rust ret…
conao3 Dec 1, 2026
bd91cd5
rust: make a function stale when a constant, an alias, a macro or a u…
conao3 Dec 1, 2026
1a3ac13
rust: test functions with the values at the boundaries of their types
conao3 Dec 1, 2026
37cba74
go: refuse int and uint where a 32-bit build is possible, and check s…
conao3 Dec 1, 2026
eb2aada
clojure: correct Int division at the Long bounds and Float.round in t…
conao3 Dec 1, 2026
56edbb2
clojure: give sum types with a field tag and types with equal keyword…
conao3 Dec 1, 2026
6d79fe2
c: qualify the names that the translation writes, and compare more ac…
conao3 Dec 1, 2026
dc1027a
clojure: make the models return what Clojure returns, or have none
conao3 Dec 1, 2026
a65da2d
c: update the lock of verified-clamp and the expected obligations
conao3 Dec 1, 2026
6f0396e
clojure: write a negative zero in parentheses in Lean
conao3 Dec 1, 2026
958ea5f
clojure: print floats as C does
conao3 Dec 1, 2026
2e4dd6f
clojure: refuse functions whose var holds another typed function
conao3 Dec 1, 2026
1633295
rust: convert enums of one variant and of more than 256 variants as L…
conao3 Dec 1, 2026
19664d6
rust: compare the sum of constants and lengths in with_capacity
conao3 Dec 1, 2026
b74e017
rust: compare the models of the operations with Rust, and test what h…
conao3 Dec 1, 2026
32380a7
docs: the Rust functions without a model and the inputs of the tests
conao3 Dec 1, 2026
718ed01
rust: refuse a function whose code is not in src
conao3 Dec 1, 2026
a94f892
rust: pass clippy
conao3 Dec 1, 2026
524c483
clojure: postpone the checks of types that Lean does not know yet
conao3 Dec 1, 2026
c2943bc
rust: check the samples with the items of their models
conao3 Dec 1, 2026
f85f291
c: read the enumerators that have documentation comments
conao3 Dec 1, 2026
a9c7501
clojure: write the malli schema of strings as data
conao3 Dec 1, 2026
8a28828
rust: hash what the names in an item stand for, and the items that ma…
conao3 Dec 1, 2026
411bda9
rust: check the tests and the samples with the hashes of what their n…
conao3 Dec 1, 2026
5d851a6
Merge remote-tracking branch 'origin/unify-s3' into s2-go
conao3 Dec 1, 2026
35c7092
Merge remote-tracking branch 'origin/unify-s3' into s2-c
conao3 Dec 1, 2026
fc59da6
Judge no function that Lean reads with the syntax or the coercions of…
conao3 Dec 1, 2026
82d4037
Merge remote-tracking branch 'origin/unify-s3' into s2-php
conao3 Dec 1, 2026
c38f760
Merge remote-tracking branch 'origin/unify-s3' into s2-typescript
conao3 Dec 1, 2026
0fdc720
Merge remote-tracking branch 'origin/unify-s3' into s2-python
conao3 Dec 1, 2026
8bc5b5c
Merge remote-tracking branch 'origin/unify-s3' into s2-clojure
conao3 Dec 1, 2026
b21d6e8
Merge remote-tracking branch 'origin/unify-s3' into s2-rust
conao3 Dec 1, 2026
1de73db
typescript: judge the length of a string of a model by its characters…
conao3 Dec 1, 2026
17db8ce
rust: pass clippy after the merge
conao3 Dec 1, 2026
00ad883
Merge remote-tracking branch 'origin/unify-embed' into bb/board-task-…
conao3 Dec 1, 2026
1b81f9f
Merge branch 's2-go' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 1, 2026
e41c094
Merge branch 's2-c' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 1, 2026
f2fc578
Merge branch 's2-python' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 1, 2026
a6d0942
typescript: regenerate the locks
conao3 Dec 1, 2026
6f31b55
Merge remote-tracking branch 'origin/unify-embed' into s2-typescript
conao3 Dec 1, 2026
3d74ed2
typescript: a function with undefined does not replace a specificatio…
conao3 Dec 1, 2026
6fd5578
Merge branch 's2-php' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 1, 2026
a99a54c
Merge branch 's2-typescript' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 1, 2026
bf78b37
docs: the syntax and the coercions of a block that leave a function u…
conao3 Dec 1, 2026
1d01416
rust: write the full names that Lean would take for those of a module…
conao3 Dec 2, 2026
73b847e
go, typescript: write a UInt64 in JSON Schemas as the decimals that t…
conao3 Dec 2, 2026
ee14ac5
Merge branch 's2-clojure' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 2, 2026
b0c3509
go: test the coercion of a spec with Lean's own coercion to Option, s…
conao3 Dec 2, 2026
5b58176
rust: keep the functions whose names Aeneas also has, whose bodies Le…
conao3 Dec 2, 2026
b481e6d
typescript: lint the schema test; docs: the decimal strings and the i…
conao3 Dec 2, 2026
8ec12af
docs: wrap the lines of the JSON conventions of TypeScript
conao3 Dec 2, 2026
98e7c37
c: read the decimal strings of UInt64 and USize that the JSON Schema …
conao3 Dec 2, 2026
65d95a4
rust: leave to Lean a name of a declaration that stands for itself
conao3 Dec 2, 2026
21fccff
Merge branch 's2-rust' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 2, 2026
e4c1f83
Merge branch 's2-schema' into bb/board-task-15186-thr_h7fkgc2qif
conao3 Dec 2, 2026
6808160
Merge remote-tracking branch 'origin/unify-embed' into bb/board-task-…
conao3 Dec 2, 2026
30218fb
rust: pass a requires that holds as Ok in the test of the boundary va…
conao3 Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 36 additions & 1 deletion Leanfran/Check.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Lean.Meta.Instances
import Lean.Replay
import Lean.Util.CollectAxioms
import Leanfran.Check.Rejected
import Leanfran.Check.Syntax
import Leanfran.Cli
import Leanfran.Embed.Types
import Leanfran.Module.Job
Expand Down Expand Up @@ -85,12 +86,20 @@ structure Judge where
/-- The modules with files that Lean rejects. -/
rejected : NameSet := {}
checked : IO.Ref Kernel.Environment
tokens : IO.Ref (Option Tokens)
/-- The modules of obligations with what changes how Lean reads them. -/
changes : IO.Ref (NameMap (Option String))

def Judge.new (policy : Policy) (sysroot : FilePath) (env : Environment) (rejected : NameSet := {}) : IO Judge := do
let lib := s!"{sysroot / "lib" / "lean"}/"
let toolchain ← env.header.moduleNames.filterM fun m => return (← findOLean m).toString.startsWith lib
let base ← importModules ((if policy.replay then toolchain else #[]).map fun m => {module := m}) {}
return {policy, rejected, toolchain := toolchain.foldl NameSet.insert {}, checked := ← IO.mkRef base.toKernelEnv}
return {
policy, rejected
toolchain := toolchain.foldl NameSet.insert {}
checked := ← IO.mkRef base.toKernelEnv
tokens := ← IO.mkRef none
changes := ← IO.mkRef {}}

private def moduleOf (env : Environment) (n : Name) : Option Name :=
(env.getModuleIdxFor? n).map fun idx => env.header.moduleNames[idx.toNat]!
Expand Down Expand Up @@ -130,6 +139,30 @@ def rejection (judge : Judge) (env : Environment) (thm : Name) (uses : List Name
let problem ← replayProblem judge env (thm :: uses)
return problem.map (s!"the kernel rejected {thm} or a declaration it uses: {·}")

private def packageModule (module : Name) : IO Bool := do
let components := (← findOLean module).components
return (components.zip (components.drop 1)).any fun (a, b) => a.startsWith ".lake" && b == "packages"

/-- What changes how Lean reads the translated definition of `stmt`. -/
def changedSyntax (judge : Judge) (stmt : Name) : MetaM (Option String) := do
let env ← getEnv
let some module := moduleOf env stmt | return none
if let some found := (← judge.changes.get).find? module then return found
let ours := fun m => judge.toolchain.contains m || within judge.policy.library m
let mut blocks : NameSet := {}
for m in env.header.moduleNames do
unless ours m || within judge.policy.models m || (← packageModule m) do blocks := blocks.insert m
let reading : Reading := {ours, blocks := blocks.contains}
let tokens ← match ← judge.tokens.get with
| some tokens => pure tokens
| none =>
let tokens ← reading.tokens env
judge.tokens.set (some tokens)
pure tokens
let found ← reading.change tokens module
judge.changes.modify (·.insert module found)
return found

def orphanInstance (judge : Judge) (stmt : Name) : MetaM (Option (Name × Name)) := do
let env ← getEnv
let ours := fun (n : Name) => (moduleOf env n).any fun m =>
Expand Down Expand Up @@ -174,6 +207,8 @@ def checkObligation (judge : Judge) (o : ObligationRef) : MetaM Judgement := do
if let some (inst, module) ← orphanInstance judge stmt then
let detail := s!"the translated definition uses the instance {inst} from {module} on standard types"
return result {label, status := .unextracted, detail, file, line}
if let some detail ← changedSyntax judge stmt then
return result {label, status := .unextracted, detail, file, line}
if hasError env judge.rejected thm then
return result {label, status := .failed, detail := s!"Lean rejects the proof {thm}", file, line}
let axioms ← collectAxioms thm
Expand Down
158 changes: 158 additions & 0 deletions Leanfran/Check/Syntax.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import Lean.Elab.Do.Basic
import Lean.Elab.Do.InferControlInfo
import Lean.Elab.Term
import Lean.Meta.Coe
import Lean.Meta.Instances

open Lean Meta

namespace Leanfran.Check

/-- Where a module may change how Lean reads the code of the translated definitions. -/
structure Reading where
/-- The modules of Lean and of the models of the language. -/
ours : Name → Bool
/-- The other modules whose syntax is checked. -/
blocks : Name → Bool

private def Reading.declares (r : Reading) (env : Environment) (n : Name) : Bool :=
match env.getModuleIdxFor? n with
| some index => r.ours env.header.moduleNames[index.toNat]!
| none => true

private def entryOf : ScopedEnvExtension.Entry α → α
| .global a | .scoped _ a => a

private def keyed (attr : KeyedDeclsAttribute γ) (env : Environment) (index : ModuleIdx) : Array Name :=
(attr.ext.ext.getModuleEntries env index).map fun e => (entryOf e).key

private def elaborated (env : Environment) (index : ModuleIdx) : Array Name :=
keyed Elab.macroAttribute env index ++ keyed Elab.Term.termElabAttribute env index ++
keyed Elab.Do.doElemElabAttribute env index ++ keyed Elab.Do.controlInfoElemAttribute env index ++
keyed Elab.Command.commandElabAttribute env index

private def proofCategories : List Name := [`tactic, `conv]

private def inProofs (env : Environment) (kind : Name) : Bool :=
let categories := (Parser.parserExtension.getState env).categories
proofCategories.any fun category => (categories.find? category).any (·.kinds.contains kind)

/-- The first tokens of a parser, or `none` when it starts with something else. -/
private partial def firstTokens (e : Expr) : Option (List String) :=
let e := e.consumeMData
let arg := fun (n : Nat) => e.getAppArgs[n]?.getD default
match e.getAppFn.constName? with
| some ``ParserDescr.symbol | some ``ParserDescr.nonReservedSymbol =>
match arg 0 with
| .lit (.strVal s) => some [s.trimAscii.toString]
| _ => none
| some ``ParserDescr.node => firstTokens (arg 2)
| some ``ParserDescr.trailingNode => firstTokens (arg 3)
| some ``ParserDescr.nodeWithAntiquot => firstTokens (arg 2)
| some ``ParserDescr.unary => if isName (arg 0) `atomic || isName (arg 0) `patternIgnore then firstTokens (arg 1) else none
| some ``ParserDescr.binary =>
if isName (arg 0) `orelse then return (← firstTokens (arg 1)) ++ (← firstTokens (arg 2))
else if isName (arg 0) `andthen then firstTokens (arg 1)
else none
| _ => none
where
isName (e : Expr) (n : Name) : Bool := e.name? == some n

private def parsers (env : Environment) (index : ModuleIdx) : Array (Name × Name) :=
(Parser.parserExtension.ext.getModuleEntries env index).filterMap fun e => match entryOf e with
| .parser category decl _ => some (category, decl)
| _ => none

private def descr (env : Environment) (decl : Name) : Bool × Option (List String) :=
match (env.find? decl).bind (·.value? (allowOpaque := true)) with
| some value => (!value.getAppFn.isConstOf ``ParserDescr.trailingNode, firstTokens value)
| none => (true, none)

/-- The categories with the first tokens of their leading and of their trailing parsers. -/
abbrev Tokens := Std.HashSet (Name × Bool × String)

def Reading.tokens (r : Reading) (env : Environment) : IO Tokens := do
let mut tokens : Tokens := {}
for (category, c) in (← Parser.builtinParserCategoriesRef.get).toList do
for (token, _) in c.tables.leadingTable.toList do tokens := tokens.insert (category, true, token.getString!)
for (token, _) in c.tables.trailingTable.toList do tokens := tokens.insert (category, false, token.getString!)
for index in [0:env.header.moduleNames.size] do
unless r.ours env.header.moduleNames[index]! do continue
for (category, decl) in parsers env index do
let (leading, first) := descr env decl
for token in first.getD [] do tokens := tokens.insert (category, leading, token)
return tokens

private def opening : List String := ["(", "[", "{", "⟨"]

private def parsed (tokens : Tokens) (env : Environment) (index : ModuleIdx) : Option Name :=
(parsers env index).findSome? fun (category, decl) =>
let (leading, first) := descr env decl
let overlaps := fun (token : String) =>
tokens.contains (category, leading, token) || opening.any fun b => token != b && token.startsWith b
if !proofCategories.contains category && first.all (·.any overlaps) then some decl else none

private def coercionClasses : List Name := [``Coe, ``CoeTC, ``CoeOut, ``CoeOTC, ``CoeHead, ``CoeHTC, ``CoeTail, ``CoeHTCT,
``CoeDep, ``CoeT, ``CoeFun, ``CoeSort]

/-- An instance of a module that changes a coercion between types of `r.ours`. -/
def Reading.coercion (r : Reading) (modules : Array Name) : MetaM (Option (Name × Name)) := do
let env ← getEnv
let state := instanceExtension.getState env
let mut found := #[]
for (name, _) in state.instanceNames.toList do
let some index := env.getModuleIdxFor? name | continue
let module := env.header.moduleNames[index.toNat]!
unless modules.contains module do continue
let some info := env.find? name | continue
let target := info.type.getForallBody
unless target.getAppFn.constName?.any coercionClasses.contains do continue
unless target.getUsedConstants.all (r.declares env) do continue
found := found.push (name, module)
if found.isEmpty then return none
for (name, module) in found do
let some info := env.find? name | continue
let changes ← withoutModifyingEnv do
for (other, _) in found do
modifyEnv (instanceExtension.modifyState · (·.eraseCore other))
forallTelescope info.type fun _ target => do
let args := target.getAppArgs
let some source := args[0]? | return false
withLocalDeclD `x source fun x => do
if target.isAppOf ``CoeFun then return (← coerceToFunction? x).isSome
if target.isAppOf ``CoeSort then return (← coerceToSort? x).isSome
let some result := args.back? | return false
if let .some _ ← coerceSimple? x result then return true
return false
if changes then return some (name, module)
return none

/-- The modules that `module` imports, and `module`. -/
private def imported (env : Environment) (module : Name) : Array Name := Id.run do
let mut todo := [module]
let mut seen : NameSet := {}
let mut found := #[]
while let m :: rest := todo do
todo := rest
if seen.contains m then continue
seen := seen.insert m
let some index := env.getModuleIdx? m | continue
found := found.push m
todo := (env.header.moduleData[index.toNat]!.imports.map (·.module)).toList ++ todo
return found

/-- What a module that `module` imports changes in the syntax of Lean and of the models of the language. -/
def Reading.change (r : Reading) (tokens : Tokens) (module : Name) : MetaM (Option String) := do
let env ← getEnv
let modules := (imported env module).filter r.blocks
for m in modules do
let some index := env.getModuleIdx? m | continue
if let some kind := (elaborated env index).find? fun kind => r.declares env kind && !inProofs env kind then
return s!"{m} changes the meaning of the syntax {kind}"
if let some decl := parsed tokens env index then
return s!"the syntax {decl} of {m} overlaps the syntax of Lean"
if let some (inst, m) ← r.coercion modules then
return s!"the instance {inst} of {m} changes a coercion between standard types"
return none

end Leanfran.Check
Loading
Loading