-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation Fault with mutual, HashMap, and string interpolation #5188
Comments
I can reproduce.
|
Compiling this with static lean_object* _init_l_test___rarg___closed__6() {
_start:
{
lean_object* x_1; lean_object* x_2; lean_object* x_3;
x_1 = l_update___rarg___closed__2;
x_2 = lean_unsigned_to_nat(0u);
x_3 = lean_array_fget(x_1, x_2);
return x_3;
} At the static lean_object* _init_l_update___rarg___closed__2() {
_start:
{
lean_object* x_1; lean_object* x_2;
x_1 = lean_unsigned_to_nat(0u);
x_2 = lean_mk_empty_array_with_capacity(x_1);
return x_2;
} And the debugger:
|
Looking into the IR the
What is probably happening here, is that the compiler pulled out import Lean.Data.HashMap
mutual
inductive Foo
| Foo (bar : Bar)
inductive Bar
| Foo (foo : Foo)
| Baz (baz : String)
end
mutual
def eToString : Foo → String
| Foo.Foo c => cToString c
def cToString : Bar → String
| Bar.Foo e => eToString e
| Bar.Baz c => c
end
instance : ToString Foo := ⟨eToString⟩
instance : ToString Bar := ⟨cToString⟩
def update (_ : Nat × Nat) (_ : Array String) (w : Lean.HashMap (Nat × Nat) (Array String)) :=
w.insert (0,0) #[]
set_option compiler.extract_closed false in
def test (x : String) (y : Foo) (z : Lean.HashMap (Nat × Nat) (Array String)): Option (String × (Option String) × (Option String) × String × (Lean.HashMap (Nat × Nat) (Array String))) := do
pure $ (
((toString (← (Array.filter (fun _ => true) #[y])[0]?)).split (· = '0')).getD 0 "",
none,
"",
"",
update (x.length, x.length) #[s!"{x}", s!"{x}"] z
)
def main : IO Unit := pure () |
Prerequisites
Please put an X between the brackets as you perform the following steps:
https://github.com/leanprover/lean4/issues
Avoid dependencies to Mathlib or Batteries.
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
The code has a segmentation fault when run.
Context
Here is a discussion on Zulip.
Steps to Reproduce
lake new test
cd test
Main.lean
to have the following contentslake build
./.lake/build/bin/test
Expected behavior: The code should compile and run.
Actual behavior: It produces a segmentation fault.
Versions
"4.10.0" and "4.12.0-nightly-2024-08-27"
macOS Monterey Version 12.4
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: