leanprover / leanprover/lean4

`withSynthesize` tries to solve unrelated universe constraints

Open
#13,875 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

When there are existing postponed universe constraints before running withSynthesize, withSynthesize k (postpone := .no) will attempt to solve them and throw if it failed to solve them. This means that when there is a not yet solvable universe constraint, withSynthesize k will fail, no matter what action k is (even a no-op)!

Context

That nasty problem when using String pattern functions with a (·.someCharFunction) pattern and somewhere after a match. This was originally discussed at #general > deprecated_module @ 💬 but someone independently reported this issue on Discord, causing me to look deeper into the root cause.

Steps to Reproduce
set_option pp.mvars false

/--
error: stuck at solving universe constraint
  1 =?= imax _ _
while trying to unify
  (x : ?_) → ?_ x : Sort (imax _ _)
with
  (x : ?_) → ?_ x : Sort (imax _ _)
-/
#guard_msgs in
example (s : String) (x : Nat) : String :=
  let := s.all (·.isAlphanum) -- creates a universe constraint `1 =?= imax _ _`
  match x with
  | _ => s -- runs withSynthesize for elaborating `_` and thus tries to solve `1 =?= imax _ _` (oh no!)

Expected behavior:
Elaborating _ doesn't produce any new universe constraints, so withSynthesize shouldn't try to solve any and just succeed.

Actual behavior:
withSynthesize tries to solve all universe constraints and fails, giving an error to the user.

Versions

Lean 4.31.0, commit c47a0c7cf035381a2bcdd4cdf2442782eb4a5214

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied minimal Lean reproducer and the withSynthesize entry point. Reproduce the existing postponed universe constraint, then inspect how withSynthesize k (postpone := .no) handles constraints created before and during k. Done means the example succeeds when elaborating _ creates no new universe constraints, while newly created constraints retain their expected behavior.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.