Skip to content

fix(.../tactic/tactic_state.cpp): 'target' must instantiate goal type - #3

Closed
dselsam wants to merge 1 commit into
leanprover:masterfrom
dselsam:fix_target_instantiate
Closed

dselsam wants to merge 1 commit into
leanprover:masterfrom
dselsam:fix_target_instantiate

Conversation

@dselsam

@dselsam dselsam commented Jun 30, 2018 •

Copy link
Copy Markdown
Contributor

This is a suggested, preemptive fix based on an observed issue in Lean3. The following test fails in Lean3 but works after the PR:

set_option pp.all true
set_option pp.instantiate_mvars false

example (m n : ℕ) : psigma (λ (P : Prop), P) :=
begin
fapply psigma.mk,
exact (nat.add m (nat.succ n) = nat.succ (nat.add m n)),
trace_state,
-- m n : nat
-- ⊢ ?m_1
dunfold nat.add,
tactic.to_expr ``(rfl) >>= λ e, tactic.apply e {md := tactic.transparency.none}
-- @eq.{1} nat (nat.add m (nat.succ n)) (nat.succ (nat.add m n))
-- with
-- @eq.{?l_1} ?m_2 ?m_3 ?m_3
end

The issue is that since the target tactic does not instantiate metavars, the dunfold tactic does not find the desired subterm, even though (without set_option pp.instantiate_mvars false) it looks like the subterm is present, even with set_option pp.all true. There may be performance reasons for not doing it this way, but it seems like an appealing goal for nothing to break in interactive mode because metavars are not instantiated under the hood.

I do not provide a test for Lean4 because there doesn't seem to be a dunfold tactic yet or anything like it.

@dselsam

dselsam commented Jun 30, 2018 •

Copy link
Copy Markdown
Contributor Author

Here is a related issue (in Lean3) that may need a similar fix somewhere:

set_option pp.all true
set_option pp.instantiate_mvars false

structure Foo := (P : Prop) (Q : Prop) (p : P → Q)

example (m n : ℕ) : Foo :=
begin
fapply Foo.mk,
exact (m = n),
exact (m + 1 = n + 1),
intro H,
trace_state,
-- m n : nat
-- ⊢ ?m_1
rw H
-- error: invalid apply tactic, failed to unify
-- @eq.{1} nat (nat.add m (nat.succ n)) (nat.succ (nat.add m n))
-- with
-- @eq.{?l_1} ?m_2 ?m_3 ?m_3
end

@leodemoura

Copy link
Copy Markdown
Member

I am closing this PR because the new tactic monad will be implemented in Lean.

@leodemoura leodemoura closed this Aug 21, 2018
bollu referenced this pull request in bollu/lean4 Apr 4, 2021
/home/bollu/work/lz/test/lambdapure/compile$ (lean ctor.lean 2>&1 | tee exe.mlir | hask-opt) || vim exe.mlir
hask-opt: /home/bollu/work/llvm-project/llvm/include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = mlir::standalone::HaskIntegerConstOp; Y = mlir::Operation; typename llvm::cast_retty<X, Y*>::ret_type = mlir::standalone::HaskIntegerConstOp]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: hask-opt
 #0 0x00007f479b292a3e __interceptor_backtrace.part.0 /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4101:28
 #1 0x00007f479679b61d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/bollu/work/llvm-project/build/./lib/libLLVMSupport.so.13git+0x1b761d)
 #2 0x00007f4796799234 llvm::sys::RunSignalHandlers() (/home/bollu/work/llvm-project/build/./lib/libLLVMSupport.so.13git+0x1b5234)
 #3 0x00007f47967993a3 SignalHandler(int) Signals.cpp:0:0
 #4 0x00007f479afc6960 __restore_rt sigaction.c:0:0
 #5 0x00007f47957a7ef5 raise (/usr/lib/libc.so.6+0x3cef5)
leodemoura added a commit that referenced this pull request Apr 29, 2024
Mathlib is crashing with #4006. Here is the stacktrace produced by Kim:
```
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100000000000a)
  * frame #0: 0x00000001066db21c libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 2816
    frame #1: 0x00000001066dd464 libleanshared.dylib`lean::ir::interpreter::call(lean::name const&, lean::array_ref<lean::object_ref> const&) + 1360
    frame #2: 0x00000001066db394 libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 3192
    frame #3: 0x00000001066dd464 libleanshared.dylib`lean::ir::interpreter::call(lean::name const&, lean::array_ref<lean::object_ref> const&) + 1360
    frame #4: 0x00000001066db394 libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 3192
    frame #5: 0x00000001066dd464 libleanshared.dylib`lean::ir::interpreter::call(lean::name const&, lean::array_ref<lean::object_ref> const&) + 1360
    frame #6: 0x00000001066db394 libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 3192
    frame #7: 0x00000001066df288 libleanshared.dylib`lean::ir::interpreter::stub_m(lean_object**) + 556
    frame #8: 0x00000001066d6ee0 libleanshared.dylib`lean_object* lean::ir::interpreter::with_interpreter<lean_object*>(lean::environment const&, lean::options const&, lean::name const&, std::__1::function<lean_object* (lean::ir::interpreter&)> const&) + 320
    frame #9: 0x00000001066dee84 libleanshared.dylib`lean::ir::interpreter::stub_m_aux(lean_object**) + 92
    frame #10: 0x00000001066deafc libleanshared.dylib`lean::ir::interpreter::stub_9_aux(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*) + 60
    frame #11: 0x00000001066f52a0 libleanshared.dylib`lean_apply_6 + 1748
    frame #12: 0x00000001055d1ac8 libleanshared.dylib`l_Array_forInUnsafe_loop___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__10___lambda__2 + 156
    frame #13: 0x00000001055d47e8 libleanshared.dylib`l_Array_forInUnsafe_loop___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__10___lambda__2___boxed + 144
    frame #14: 0x00000001066f5bcc libleanshared.dylib`lean_apply_7 + 1348
    frame #15: 0x00000001055ccccc libleanshared.dylib`l_Lean_Elab_withInfoTreeContext___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__4 + 528
    frame #16: 0x00000001066f5b6c libleanshared.dylib`lean_apply_7 + 1252
    frame #17: 0x00000001055d1550 libleanshared.dylib`l_Lean_Elab_withLogging___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__6 + 240
    frame #18: 0x00000001055d4cb4 libleanshared.dylib`l_Array_forInUnsafe_loop___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__10 + 940
    frame #19: 0x00000001055d5394 libleanshared.dylib`l___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___lambda__1 + 60
    frame #20: 0x00000001055d5740 libleanshared.dylib`l___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___lambda__1___boxed + 148
    frame #21: 0x00000001066f11f4 libleanshared.dylib`lean_apply_1 + 840
    frame #22: 0x0000000103bce27c libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1 + 24
    frame #23: 0x0000000103bce4ec libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1___boxed + 20
    frame #24: 0x00000001066f10bc libleanshared.dylib`lean_apply_1 + 528
    frame #25: 0x0000000106644260 libleanshared.dylib`lean_profileit + 128
    frame #26: 0x0000000103bce3e0 libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg + 112
    frame #27: 0x00000001055d564c libleanshared.dylib`l___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore + 268
    frame #28: 0x00000001055d6264 libleanshared.dylib`l_Lean_Elab_Term_applyAttributes + 52
    frame #29: 0x000000010597b840 libleanshared.dylib`l_Array_forInUnsafe_loop___at_Lean_Elab_Command_elabAttr___spec__6___lambda__1 + 740
    frame #30: 0x000000010597daf4 libleanshared.dylib`l_Array_forInUnsafe_loop___at_Lean_Elab_Command_elabAttr___spec__6___lambda__1___boxed + 124
    frame #31: 0x00000001066f65d8 libleanshared.dylib`lean_apply_8 + 1252
    frame #32: 0x00000001066f5b6c libleanshared.dylib`lean_apply_7 + 1252
    frame #33: 0x0000000104f587b0 libleanshared.dylib`l___private_Lean_Elab_InfoTree_Main_0__Lean_Elab_withSavedPartialInfoContext___at_Lean_Elab_Command_liftTermElabM___spec__2___rarg___lambda__1 + 344
    frame #34: 0x0000000104f59ec4 libleanshared.dylib`l___private_Lean_Elab_InfoTree_Main_0__Lean_Elab_withSavedPartialInfoContext___at_Lean_Elab_Command_liftTermElabM___spec__2___rarg + 280
    frame #35: 0x0000000104f5af20 libleanshared.dylib`l_Lean_Elab_Command_liftTermElabM___rarg___lambda__1 + 144
    frame #36: 0x00000001066f5ab8 libleanshared.dylib`lean_apply_7 + 1072
    frame #37: 0x0000000105636090 libleanshared.dylib`l_Lean_Elab_Term_TermElabM_run___rarg + 844
    frame #38: 0x0000000104f5b8fc libleanshared.dylib`l_Lean_Elab_Command_liftTermElabM___rarg + 1696
    frame #39: 0x000000010597d67c libleanshared.dylib`l_Array_forInUnsafe_loop___at_Lean_Elab_Command_elabAttr___spec__6 + 928
    frame #40: 0x000000010597de60 libleanshared.dylib`l_Lean_Elab_Command_elabAttr + 772
    frame #41: 0x000000010597e838 libleanshared.dylib`l_Lean_Elab_Command_elabAttr___boxed + 20
    frame #42: 0x00000001066f2cd4 libleanshared.dylib`lean_apply_3 + 868
    frame #43: 0x0000000104f385f8 libleanshared.dylib`l_Lean_Elab_withInfoTreeContext___at___private_Lean_Elab_Command_0__Lean_Elab_Command_elabCommandUsing___spec__2 + 396
    frame #44: 0x0000000104f39e48 libleanshared.dylib`l___private_Lean_Elab_Command_0__Lean_Elab_Command_elabCommandUsing + 484
    frame #45: 0x00000001066f2cf0 libleanshared.dylib`lean_apply_3 + 896
    frame #46: 0x0000000104f341d4 libleanshared.dylib`l_Lean_withTraceNode___at_Lean_Elab_Command_runLinters___spec__11 + 788
    frame #47: 0x00000001066f2d54 libleanshared.dylib`lean_apply_3 + 996
    frame #48: 0x00000001066f2cf0 libleanshared.dylib`lean_apply_3 + 896
    frame #49: 0x0000000104f40e30 libleanshared.dylib`l_Lean_Elab_withLogging___at_Lean_Elab_Command_elabCommand___spec__2 + 104
    frame #50: 0x0000000104f4c51c libleanshared.dylib`l_Lean_Elab_Command_elabCommandTopLevel___lambda__1 + 432
    frame #51: 0x00000001066f10e8 libleanshared.dylib`lean_apply_1 + 572
    frame #52: 0x0000000103bce27c libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1 + 24
    frame #53: 0x0000000103bce4ec libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1___boxed + 20
    frame #54: 0x00000001066f10bc libleanshared.dylib`lean_apply_1 + 528
    frame #55: 0x0000000106644260 libleanshared.dylib`lean_profileit + 128
    frame #56: 0x0000000103bce3e0 libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg + 112
    frame #57: 0x0000000104f4fce0 libleanshared.dylib`l_Lean_Elab_Command_elabCommandTopLevel + 1284
    frame #58: 0x00000001057d2f30 libleanshared.dylib`l_Lean_Elab_Frontend_elabCommandAtFrontend + 1384
    frame #59: 0x00000001057d63b8 libleanshared.dylib`l_Lean_Elab_Frontend_processCommand + 1332
    frame #60: 0x00000001057d6e48 libleanshared.dylib`l_Lean_Elab_Frontend_processCommands + 72
    frame #61: 0x00000001057d7248 libleanshared.dylib`l_Lean_Elab_IO_processCommands + 212
    frame #62: 0x00000001057d83d0 libleanshared.dylib`l_Lean_Elab_runFrontend___lambda__3 + 76
    frame #63: 0x00000001057d96d0 libleanshared.dylib`lean_run_frontend + 2436
    frame #64: 0x00000001065e72b4 libleanshared.dylib`lean::run_new_frontend(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, lean::options const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, lean::name const&, unsigned int, lean::optional<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>> const&, unsigned char) + 244
    frame #65: 0x00000001065e9c8c libleanshared.dylib`lean_main + 8348
    frame #66: 0x0000000184f93f28 dyld`start + 2236
```

cc @Kha
github-merge-queue Bot pushed a commit that referenced this pull request Apr 29, 2024
Mathlib is crashing with #4006. Here is the stacktrace produced by Kim:
```
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100000000000a)
  * frame #0: 0x00000001066db21c libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 2816
    frame #1: 0x00000001066dd464 libleanshared.dylib`lean::ir::interpreter::call(lean::name const&, lean::array_ref<lean::object_ref> const&) + 1360
    frame #2: 0x00000001066db394 libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 3192
    frame #3: 0x00000001066dd464 libleanshared.dylib`lean::ir::interpreter::call(lean::name const&, lean::array_ref<lean::object_ref> const&) + 1360
    frame #4: 0x00000001066db394 libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 3192
    frame #5: 0x00000001066dd464 libleanshared.dylib`lean::ir::interpreter::call(lean::name const&, lean::array_ref<lean::object_ref> const&) + 1360
    frame #6: 0x00000001066db394 libleanshared.dylib`lean::ir::interpreter::eval_body(lean::object_ref const&) + 3192
    frame #7: 0x00000001066df288 libleanshared.dylib`lean::ir::interpreter::stub_m(lean_object**) + 556
    frame #8: 0x00000001066d6ee0 libleanshared.dylib`lean_object* lean::ir::interpreter::with_interpreter<lean_object*>(lean::environment const&, lean::options const&, lean::name const&, std::__1::function<lean_object* (lean::ir::interpreter&)> const&) + 320
    frame #9: 0x00000001066dee84 libleanshared.dylib`lean::ir::interpreter::stub_m_aux(lean_object**) + 92
    frame #10: 0x00000001066deafc libleanshared.dylib`lean::ir::interpreter::stub_9_aux(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*) + 60
    frame #11: 0x00000001066f52a0 libleanshared.dylib`lean_apply_6 + 1748
    frame #12: 0x00000001055d1ac8 libleanshared.dylib`l_Array_forInUnsafe_loop___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__10___lambda__2 + 156
    frame #13: 0x00000001055d47e8 libleanshared.dylib`l_Array_forInUnsafe_loop___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__10___lambda__2___boxed + 144
    frame #14: 0x00000001066f5bcc libleanshared.dylib`lean_apply_7 + 1348
    frame #15: 0x00000001055ccccc libleanshared.dylib`l_Lean_Elab_withInfoTreeContext___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__4 + 528
    frame #16: 0x00000001066f5b6c libleanshared.dylib`lean_apply_7 + 1252
    frame #17: 0x00000001055d1550 libleanshared.dylib`l_Lean_Elab_withLogging___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__6 + 240
    frame #18: 0x00000001055d4cb4 libleanshared.dylib`l_Array_forInUnsafe_loop___at___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___spec__10 + 940
    frame #19: 0x00000001055d5394 libleanshared.dylib`l___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___lambda__1 + 60
    frame #20: 0x00000001055d5740 libleanshared.dylib`l___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore___lambda__1___boxed + 148
    frame #21: 0x00000001066f11f4 libleanshared.dylib`lean_apply_1 + 840
    frame #22: 0x0000000103bce27c libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1 + 24
    frame #23: 0x0000000103bce4ec libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1___boxed + 20
    frame #24: 0x00000001066f10bc libleanshared.dylib`lean_apply_1 + 528
    frame #25: 0x0000000106644260 libleanshared.dylib`lean_profileit + 128
    frame #26: 0x0000000103bce3e0 libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg + 112
    frame #27: 0x00000001055d564c libleanshared.dylib`l___private_Lean_Elab_Term_0__Lean_Elab_Term_applyAttributesCore + 268
    frame #28: 0x00000001055d6264 libleanshared.dylib`l_Lean_Elab_Term_applyAttributes + 52
    frame #29: 0x000000010597b840 libleanshared.dylib`l_Array_forInUnsafe_loop___at_Lean_Elab_Command_elabAttr___spec__6___lambda__1 + 740
    frame #30: 0x000000010597daf4 libleanshared.dylib`l_Array_forInUnsafe_loop___at_Lean_Elab_Command_elabAttr___spec__6___lambda__1___boxed + 124
    frame #31: 0x00000001066f65d8 libleanshared.dylib`lean_apply_8 + 1252
    frame #32: 0x00000001066f5b6c libleanshared.dylib`lean_apply_7 + 1252
    frame #33: 0x0000000104f587b0 libleanshared.dylib`l___private_Lean_Elab_InfoTree_Main_0__Lean_Elab_withSavedPartialInfoContext___at_Lean_Elab_Command_liftTermElabM___spec__2___rarg___lambda__1 + 344
    frame #34: 0x0000000104f59ec4 libleanshared.dylib`l___private_Lean_Elab_InfoTree_Main_0__Lean_Elab_withSavedPartialInfoContext___at_Lean_Elab_Command_liftTermElabM___spec__2___rarg + 280
    frame #35: 0x0000000104f5af20 libleanshared.dylib`l_Lean_Elab_Command_liftTermElabM___rarg___lambda__1 + 144
    frame #36: 0x00000001066f5ab8 libleanshared.dylib`lean_apply_7 + 1072
    frame #37: 0x0000000105636090 libleanshared.dylib`l_Lean_Elab_Term_TermElabM_run___rarg + 844
    frame #38: 0x0000000104f5b8fc libleanshared.dylib`l_Lean_Elab_Command_liftTermElabM___rarg + 1696
    frame #39: 0x000000010597d67c libleanshared.dylib`l_Array_forInUnsafe_loop___at_Lean_Elab_Command_elabAttr___spec__6 + 928
    frame #40: 0x000000010597de60 libleanshared.dylib`l_Lean_Elab_Command_elabAttr + 772
    frame #41: 0x000000010597e838 libleanshared.dylib`l_Lean_Elab_Command_elabAttr___boxed + 20
    frame #42: 0x00000001066f2cd4 libleanshared.dylib`lean_apply_3 + 868
    frame #43: 0x0000000104f385f8 libleanshared.dylib`l_Lean_Elab_withInfoTreeContext___at___private_Lean_Elab_Command_0__Lean_Elab_Command_elabCommandUsing___spec__2 + 396
    frame #44: 0x0000000104f39e48 libleanshared.dylib`l___private_Lean_Elab_Command_0__Lean_Elab_Command_elabCommandUsing + 484
    frame #45: 0x00000001066f2cf0 libleanshared.dylib`lean_apply_3 + 896
    frame #46: 0x0000000104f341d4 libleanshared.dylib`l_Lean_withTraceNode___at_Lean_Elab_Command_runLinters___spec__11 + 788
    frame #47: 0x00000001066f2d54 libleanshared.dylib`lean_apply_3 + 996
    frame #48: 0x00000001066f2cf0 libleanshared.dylib`lean_apply_3 + 896
    frame #49: 0x0000000104f40e30 libleanshared.dylib`l_Lean_Elab_withLogging___at_Lean_Elab_Command_elabCommand___spec__2 + 104
    frame #50: 0x0000000104f4c51c libleanshared.dylib`l_Lean_Elab_Command_elabCommandTopLevel___lambda__1 + 432
    frame #51: 0x00000001066f10e8 libleanshared.dylib`lean_apply_1 + 572
    frame #52: 0x0000000103bce27c libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1 + 24
    frame #53: 0x0000000103bce4ec libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg___lambda__1___boxed + 20
    frame #54: 0x00000001066f10bc libleanshared.dylib`lean_apply_1 + 528
    frame #55: 0x0000000106644260 libleanshared.dylib`lean_profileit + 128
    frame #56: 0x0000000103bce3e0 libleanshared.dylib`l_Lean_profileitIOUnsafe___rarg + 112
    frame #57: 0x0000000104f4fce0 libleanshared.dylib`l_Lean_Elab_Command_elabCommandTopLevel + 1284
    frame #58: 0x00000001057d2f30 libleanshared.dylib`l_Lean_Elab_Frontend_elabCommandAtFrontend + 1384
    frame #59: 0x00000001057d63b8 libleanshared.dylib`l_Lean_Elab_Frontend_processCommand + 1332
    frame #60: 0x00000001057d6e48 libleanshared.dylib`l_Lean_Elab_Frontend_processCommands + 72
    frame #61: 0x00000001057d7248 libleanshared.dylib`l_Lean_Elab_IO_processCommands + 212
    frame #62: 0x00000001057d83d0 libleanshared.dylib`l_Lean_Elab_runFrontend___lambda__3 + 76
    frame #63: 0x00000001057d96d0 libleanshared.dylib`lean_run_frontend + 2436
    frame #64: 0x00000001065e72b4 libleanshared.dylib`lean::run_new_frontend(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, lean::options const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, lean::name const&, unsigned int, lean::optional<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>> const&, unsigned char) + 244
    frame #65: 0x00000001065e9c8c libleanshared.dylib`lean_main + 8348
    frame #66: 0x0000000184f93f28 dyld`start + 2236
```

cc @Kha
@llllvvuu llllvvuu mentioned this pull request Jun 9, 2024
3 tasks done
github-merge-queue Bot pushed a commit that referenced this pull request May 2, 2025
This PR improves the E-matching pattern inference procedure in `grind`.
Consider the following theorem:
```lean
@[grind →]
theorem eq_empty_of_append_eq_empty {xs ys : Array α} (h : xs ++ ys = #[]) : xs = #[] ∧ ys = #[] :=
  append_eq_empty_iff.mp h
```
Before this PR, `grind` inferred the following pattern:
```lean
@HAppend.hAppend _ _ _ _ #2 #1
```
Note that this pattern would match any `++` application, even if it had
nothing to do with arrays. With this PR, the inferred pattern becomes:
```lean
@HAppend.hAppend (Array #3) (Array _) (Array _) _ #2 #1
```
With the new pattern, the theorem will not be considered by `grind` for
goals that do not involve `Array`s.
meerkatone pushed a commit to meerkatone/lean4 that referenced this pull request Aug 18, 2026
…14814)

This PR fixes an internal error (`unexpected bound variable leanprover#3`) when a
declaration that is not a proposition is used as a `Sym.simp` theorem,
as in `sym => simp [HAdd.hAdd]`. It now produces a proper error message.

The root cause was in `selectEqKey`: it received the conclusion of the
candidate theorem after all leading binders had been stripped into loose
bound variables, and its fallback `isProp` check invoked `inferType` on
an open term. The fix moves the check to `mkTheoremFromDecl` and
`mkTheoremFromExpr`. This also fixes the same crash for valid theorems
whose conclusion is a bound `Prop` variable, such as `∀ (p : Prop), p →
p`.
FawadHa1der added a commit to FawadHa1der/lean4 that referenced this pull request Nov 22, 2026
…atch (K8 row 13)

The patch re-applied two pointer-width gates that only a native 32-bit
stage0 needed; this line's stage0 is native 64-bit. v4.36.0's import took
upstream's stage0 unchanged (the patch no longer applied), and build leanprover#3
(eb79d44) built and gated the line with it: the one confirming build
K8 row 13 waited for.

The import step now restores the tag's stage0 tree outright
(`git restore --source=<tag> --staged --worktree -- stage0`), conflicted or
not. Before, only conflicted stage0 files were replaced, so a cleanly merged
one could mix the previous tag's release-branch copy with master's (the
merge base is on master). Tooling and docs only, outside SRC_PATHS: the
built artifact stays current.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FawadHa1der added a commit to FawadHa1der/lean4 that referenced this pull request Nov 22, 2026
…ives unmerged paths; run keeps errexit and stops after its merge

import ran `git merge --no-ff --no-commit` with its status and stderr thrown
away. When no merge starts (exit 2: an untracked file at a path the tag
adds, say), baa75be's unconditional stage0 restore still staged the tag's
stage0, the unmerged list came back empty, and `git commit` recorded a
one-parent "Merge tag" commit: import printed "merged cleanly" and exited 0,
and run went on to build the line's src with the tag's stage0. import now
leaves git's stderr on screen and dies, nothing committed, unless the merge
exits 0 or 1 with MERGE_HEAD naming the tag's commit (peeled: for an
annotated tag MERGE_HEAD is the tag object). The branch it has just made is
then all there is to undo: import switches back to where HEAD was (a
branch, or a detached commit, as in a linked worktree while the main
checkout holds the line) and deletes the branch, so fixing the cause and
rerunning is enough. Should the tree have changed, or the way back fail, it
says how to do that by hand: leave the branch (`git switch --detach`; the
branch is checked out, so `git branch -D` alone fails) and delete it.

`git restore --source=<tag>` refuses any path left unmerged that the tag does
not have: a stage0 file the previous release branch modified and master
deleted (v4.22.0 -> v4.23.0 had one, v4.29.0 -> v4.30.0 two), or the side
files of a file/directory swap. import then exited 1 half-merged, without its
conflict list. stage0 now leaves the index and the tree first (`git rm -r`)
and comes back whole from the tag; a failure there dies and says so.
--ignore-unmerged is no fix: it leaves the dropped file behind, untracked.

run called `cmd_import "$1" || return $?`, and bash switches errexit off in a
function called left of `||`: a failed switch, restore or commit ran on into
the build (a pre-commit hook refusing the merge commit; the restore above: on
v4.29.0 -> v4.30.0 run then listed 383 "conflicts", 358 of them stage0, and
left stale stage0 files that no conflict named). run calls it plainly now;
its return 20 still ends the script with 20 (bash 3.2.57).

run also went from a clean merge straight into the build, though drift and
delta belong before the first build: a fix to what the build reads
(SRC_PATHS) made after a build costs a rebuild and a re-gate. run now stops
after a merge it made itself, clean or not: with 20 on conflicts, as before,
and with the new exit code 21 after a clean merge, once it has printed
drift's and delta's lists. Run again (the import branch has the tag merged)
and it prints delta, then builds and gates; a delta that fails there stops
it before the build. drift and delta each run as their own process, so that
a failure there stops only them, and errexit stays on inside them. A tag
already on the line leaves nothing to run: exit 0 (before, run went on to
the build, which refused with exit 1). The clean import's message puts drift
and delta before the first build, and the CONFLICTS message names the next
steps (drift, delta, build).

A correction to baa75be's message, which cannot be amended: "(the patch no
longer applied)" is wrong, as are 84d5308's "stage0-line-edits.patch no
longer applies" and 3c0f24c's "(the patch's context moved)". Whenever the
old step ran (on stage0 conflicts only), it could not apply the patch. Its
`git apply --3way` ran while the conflicted stage0 paths were still
unmerged in the index (`git checkout --theirs` resolves none: "does not
exist in index"). Resolved first, it would still have failed: under the
line's `stage0/** binary` the three-way merge conflicts ("Cannot merge binary
files", exit 1). Both failures reproduce with git 2.54.0 and 2.50.1 on the
real blobs. v4.35.0's import met the same step: lean.h and thread.cpp were
among the 100 stage0 paths both sides of its merge changed. A plain `git
apply` of the patch does apply to v4.36.0's stage0, at an offset (lean.h:
223 lines), and upstream had not absorbed the gates (`#ifdef LEAN_EMSCRIPTEN`
at lean.h:3724 and thread.cpp:25). Dropping it stands: the gates changed
only a native 32-bit build, and build leanprover#3 (eb79d44) built and gated
upstream's stage0.

Checked in scratch repos (local upstream, no network) with git 2.54.0 and
2.50.1, the real script in each, from a main checkout and from a linked
worktree:
- untracked file at a path the tag adds: import and run exit 1 with git's
  message, no commit, no build, the new branch deleted and HEAD back where
  it was (the line, another branch, a detached commit); with the file gone,
  the rerun merges. Before: exit 0, a one-parent "Merge tag" commit, and run
  built it. The same with annotated tags. With the way back made to fail,
  the steps the message gives work
- clean import: a two-parent merge whose stage0 is the tag's; run prints
  drift and delta and exits 21; run again prints delta and reaches the
  build. With the previous tag gone, run's own merge still stops (21, a
  note), and the rerun exits 1 before the build
- conflict: import and run exit 20, the build not reached; once the merge is
  committed, run again prints delta and reaches the build
- a tag already on the line: "nothing to run", exit 0, no delta
- a pre-commit hook refusing the commit: run exits 1 before the build
  (before: it started the build on the line's tip, the merge uncommitted)
- stage0 modify/delete and file/directory swaps (toy repos), and the real
  v4.29.0 -> v4.30.0 and v4.22.0 -> v4.23.0 imports: exit 20 with only the
  25 and 27 conflicts outside stage0; stage0's index and tree equal the
  tag's, nothing left behind
- the real line (ac9a26e) and v4.36.0: run exits 20 with the five
  conflicts 84d5308 resolved; with those five set to v4.36.0's first, it
  prints drift (73 files) and delta and exits 21, and run again reaches the
  build
- a rerere replay in stdlib_flags.h, an APFS case-only collision, and a
  detected stage0 rename plus edit still import as before

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants