TimeM's `✓` tick breaks when HasWellFormed is imported
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Lĩnh vực
- compilers
Hướng nghiên cứu
Bắt đầu bằng cách so sánh các khai báo ký hiệu trong Cslib/Algorithms/Lean/TimeM.lean và Cslib/Foundations/Syntax/HasWellFormed.lean, sau đó tái hiện MWE với từng tổ hợp import. Quyết định giữa việc giới hạn phạm vi, đổi tên hoặc thêm whitespace guard, và xác minh rằng tick dạng ngắn được ghi trong tài liệu biên dịch được với import đầy đủ của Cslib.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Cslib's own ✓ notations conflict with each other: TimeM's tick, a leading do-element macro, is captured by HasWellFormed's global postfix whenever both are imported. The practical effect is that the documented TimeM syntax works when importing the module on its own and silently breaks for anyone who imports Cslib as a whole. This is the same class of problem as #631 (a global notation without a whitespace guard reaching across line breaks).
The problem
Two notations share the ✓ token:
-- Cslib/Algorithms/Lean/TimeM.lean
macro "✓" body:doElem : doElem => `(doElem| ✓[1] $body)
-- Cslib/Foundations/Syntax/HasWellFormed.lean
notation x:max "✓" => HasWellFormed.wf x
The second one is global and has no whitespace guard, so with both in scope the parser does not stop at the end of the do item before the tick: it sees the ✓ on the next line and reads it as the postfix applied to the previous expression. The tick is consumed, and the errors land on the line above it, which makes this quite hard to diagnose.
MWE
import Cslib.Algorithms.Lean.TimeM
open Cslib.Algorithms.Lean in
def f (n : Nat) : TimeM Nat Nat := do
let m := n
✓ return m
This compiles. Add import Cslib.Foundations.Syntax.HasWellFormed (or just use import Cslib) and it fails with
error: failed to synthesize instance of type class Cslib.HasWellFormed ℕ -- on the `let m := n` line
error: Application type mismatch: m has type Prop but is expected to have type ℕ
because let m := n has become let m := n✓, i.e. HasWellFormed.wf n : Prop.
How I encountered this
I ran into this with the treap exercise from the Theoretical Computer Science Proving in Lean challenge in the ICML 2026 AI for Math workshop. The challenge's TreapLogic task file implements treap split and merge, instrumented with TimeM to count operations, and uses the tick exactly as documented:
def mergeT (l r : TreapNode Key Prio) : TimeM ℕ (TreapNode Key Prio) := do
match l, r with
...
| BinaryTree.node kp_1 l_1 r_1, BinaryTree.node kp_2 l_2 r_2 =>
if kp_1.prio ≥ kp_2.prio then
...
else
let new_l ← mergeT (BinaryTree.node kp_1 l_1 r_1) l_2
let new_r := r_2
✓ return (BinaryTree.node kp_2 new_l new_r)
The file compiles with import Cslib.Algorithms.Lean.TimeM alone. With import Cslib it fails with two errors. On the let new_r := r_2 line, Lean reports failed to synthesize Cslib.HasWellFormed (BinaryTree (KeyPrioPair Key Prio)): the postfix has consumed the tick from the line below, so the binding is really parsed as let new_r := r_2✓, i.e. HasWellFormed.wf r_2, which makes new_r a Prop instead of the intended BinaryTree (KeyPrioPair Key Prio). The return line below then fails with a type mismatch, because BinaryTree.node kp_2 new_l new_r expects new_r to be that tree — which it would have been, had the binding not been rewritten. Both messages point at code that is correct as written, which makes this hard to diagnose.
Two workarounds exist. Replacing ✓ with ✓[1] is the reliable one, since ✓[ is a longer token and is not captured by the postfix. Reordering the do block so that a let x ← e bind sits directly above the tick also works, because an arrow-bind's right-hand side ends at the line break — though this is fragile and easy to break again when editing. Either way, the documented short form should work as written.
Possible fixes
There are a few ways this could be addressed:
- Declare the
HasWellFormedpostfix asscoped(it is the intruding side;TimeM's macros only fire in do-element position). - Rename one of the two, as #393 did for the context-fill notation (
c[t]→c<[t]). - Give the postfix a whitespace guard so it cannot reach across line breaks.
Once it's decided how to fix this, I would be happy to make a PR.
Environment
- Reproduced on current main (
d6c0b90, 2026-06-12, toolchain v4.31.0-rc2): the MWE and the treap example both compile with theTimeMimport alone and fail withHasWellFormedin scope.
- Ngôn ngữ chính
- Lean
- Star
- 847
- Fork
- 234
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 49
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của leanprover/cslib
-
`listFullBeta_cons_r` should rename to `listFullBeta_concat_r`Có thể đã có người làm @lengyijun đã nhận 134 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
leanprover/cslib#784 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
logic
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
leanprover/cslib#74 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
dependency-incompatibility
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 45/100
leanprover/cslib#1271 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Generalize `RelationAlgebra`Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
leanprover/cslib#1262 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BetaAt.appR doesn't require LC N, weakening BetaAt.lc_r, not consistent with FullBetaCó thể đã có người làm @Digger-Rockwell đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
leanprover/cslib#1243 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của leanprover/cslib
Issue tương tự
-
module: exir
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
pytorch/executorch#25620 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
node:url: url.parse and url.resolve report name parse/resolve instead of Node's urlParse/urlResolveĐang mởarea:stdlib effort:S impact:low parity type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs triage transpiler
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
oven-sh/bun#49514 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bad-antics/lateralus-lang#880 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue review: medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
puddi-lang/puddi#17 ·