Skip to content
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

Unexpected error: index out of bounds caused by the mere presence of a function #534

Closed
1 task done
PeterKementzey opened this issue Jun 17, 2021 · 1 comment
Closed
1 task done

Comments

@PeterKementzey
Copy link

PeterKementzey commented Jun 17, 2021

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

I get an error: index out of bounds because of this function even though I am not even calling it anywhere in the code. If the debug trace is enabled the issue disappears.

Steps to Reproduce

def foo (array : Array Nat) : Nat -> Nat
  | 0 => 0
  | n + 1 =>
    let array := array.filter (!.==5) -- This seems to be necessary to reproduce, the condition does not matter

    if array.isEmpty then 0 else
      let arrayOfLast := #[array.back]
      -- let arrayOfLast := dbgTrace (toString arrayOfLast) (fun _ => arrayOfLast)
      -- Error: if the line above that doesn't do anything is commented out then I get an `Error: index out of bounds message` when running.
      foo arrayOfLast n

def main : IO Unit :=
  IO.println ("hi")
  1. leanpkg build bin
  2. run the executable

Expected behavior: Nothing (printing hi).

Actual behavior: Error: index out of bounds

Reproduces how often: Always

Versions

Lean (version 4.0.0-nightly-2021-06-16, commit 7485ab5, Release)

OS:
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal

Running on WSL 2

@Kha
Copy link
Member

Kha commented Jun 22, 2021

The current eager extraction of closed terms does not mesh well with panics. This will be fixed with #467; in the mean time, I'd advise to compile the code with set_option compiler.extract_closed false, which usually does not introduce significant overhead.

ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this issue Dec 2, 2022
Issues that came up: 
1) my understanding of the lean 4 naming convention is that capital/small letter choices are often dictated to you. However Lean 4 has `not` for bools and `Not` for props. This causes the following issue: in my port I have gone for the name

   ```lean4
   theorem Not_eq_not : ∀ {a b : Bool}, ¬a = !b ↔ a = b
   ```

   What should this theorem be called? The algorithm says `not_eq_not` which is misleading...or is it? It comes up a few times (the others are `not_iff_Not` and `Not_not_eq`)

2) When defining LinearOrder I had to do a lot of unfolding which is not present in Lean 3.
```
instance : LinearOrder Bool where
  le := fun a b => a = false ∨ b = true
  le_refl := by unfold LE.le; decide
  le_trans := by unfold LE.le; decide
  le_antisymm := by unfold LE.le Preorder.toLE; decide
  le_total := by unfold LE.le Preorder.toLE PartialOrder.toPreorder; decide
  decidable_le := by unfold LE.le Preorder.toLE PartialOrder.toPreorder; exact inferInstance
...
```

3) Again on orders: `lt_iff_le_not_le` is not an autoparam so I had to prove it explicitly with `Iff.rfl`. Do autoparams exist in Lean 4 yet? Does this need to be flagged?

4) Because the names of many functions on booleans changed (`bor` -> `or`, `bnot` -> `not` etc) I had to #align a lot of stuff. However the namespace also changed (`bool` -> `Bool`). Am I right in thinking that the few theorems like `bool.lt_iff`, which becomes `Bool.lt_iff` (i.e. the theorem name itself survived the naming change but the namespace did not) do *not* need to be #align ed?

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
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

No branches or pull requests

2 participants