leanprover / leanprover/lean4

trace messages for type class resolution instantiate metavariables that they shouldn't

Open
#4,285 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

The type class trace messages sometimes show assignments to metavariables that they shouldn't.

In particular this applies to

  • The outer trace node indicating the goal of the type class search
  • "apply {inst.val} to {mvar}"
  • withTraceNodeBefore `Meta.synthInstance.tryResolve (do
    return m!"{mvarTypeBody} ≟ {instTypeBody}")
Context

When using

set_option trace.Meta.synthInstance true
Steps to Reproduce

write

set_option trace.Meta.synthInstance true

#synth HAdd Nat Nat _

Expected behavior:
trace shows

[Meta.synthInstance] ✅ HAdd Nat Nat ?m.4 ▼
  [] new goal HAdd Nat Nat _tc.0 ▼
    [instances] #[@instHAdd] 
  [] ✅ apply @instHAdd to HAdd Nat Nat ?m.5 ▼
    [tryResolve] ✅ HAdd Nat Nat ?m.5 ≟ HAdd ?m.8 ?m.8 ?m.8 
    [] new goal Add Nat ▼
      [instances] #[instAddNat] 
  [] ✅ apply instAddNat to Add Nat ▼
    [tryResolve] ✅ Add Nat ≟ Add Nat 
    [answer] ✅ Add Nat 
  [resume] propagating Add Nat to subgoal Add Nat of HAdd Nat Nat Nat ▼
    [] size: 1 
    [answer] ✅ HAdd Nat Nat Nat 
  [] result instHAdd 

Actual behavior:
trace shows

[Meta.synthInstance] ✅ HAdd Nat Nat Nat ▼
  [] new goal HAdd Nat Nat _tc.0 ▼
    [instances] #[@instHAdd] 
  [] ✅ apply @instHAdd to HAdd Nat Nat Nat ▼
    [tryResolve] ✅ HAdd Nat Nat Nat ≟ HAdd Nat Nat Nat 
    [] new goal Add Nat ▼
      [instances] #[instAddNat] 
  [] ✅ apply instAddNat to Add Nat ▼
    [tryResolve] ✅ Add Nat ≟ Add Nat 
  [resume] propagating Add Nat to subgoal Add Nat of HAdd Nat Nat Nat ▼
    [] size: 1 
  [] result instHAdd 
Versions

All (4.8.0)

isDefEq faces the same problem, but does it correctly
It can be fixed using withTraceNodeBefore, or withMCtx mctxBefore do addMessageContext
I fix this here #4277.

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 Meta.synthInstance trace path and reproduce the issue using set_option trace.Meta.synthInstance true and #synth HAdd Nat Nat _. Compare the outer goal, apply, and tryResolve messages with the expected trace, and inspect withTraceNodeBefore, withMCtx, and addMessageContext; done means those messages no longer show assignments from the surrounding metavariable context.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.