leanprover / leanprover/lean4

Internal panic with precompiled module

Open
#1,388 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Consider the file NatCast.lean:

class NatCast (R : Type u) where
  natCast : Nat → R

instance : NatCast Int where
  natCast := sorry

which we precompile by writing in the lakefile

package MyPkg {
   precompileModules := true
}

Then writing

import MyPkg.NatCast

in another file causes

INTERNAL PANIC: executed 'sorry'

We can also reproduce this on the command line with lake env lean OtherFile.lean --load-dynlib=libMyPkg-NatCast.so.

The following code is emitted as an initializer

LEAN_EXPORT lean_object* l_instNatCastInt;
lean_object* lean_sorry(uint8_t);
static lean_object* _init_l_instNatCastInt() {
_start:
{
uint8_t x_1; lean_object* x_2; 
x_1 = 0;
x_2 = lean_sorry(x_1);
return x_2;
}
}
Steps to Reproduce

Expected behavior: No internal panic, import succeeds.

Actual behavior: It fails.

Reproduces how often: 100%

Versions

nightly-2022-07-30

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 by reproducing the failure with NatCast.lean, the lakefile precompileModules setting, and OtherFile.lean using the documented --load-dynlib command. Inspect the generated initializer for l_instNatCastInt and its call to lean_sorry; done means the precompiled module imports successfully without an internal panic.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.