augustss / MicroHs

Haskell implemented with combinators
Other
367 stars 25 forks source link

impossible error happens when printing `TypeExports` #47

Closed Rewbert closed 4 months ago

Rewbert commented 4 months ago

I am trying to compile a very silly module

module Main where

data MMaybe a = MJust a | MNothing

main :: IO ()
main = putStrLn $ show (5 :: Int)

If I derive Show for TypeExport and ValueExport and add a function tTypeExports to get the [TypeExport] out of a TModule a, and then try to print them in Compile.hs, the compiler crashes with an impossible error.

Directly after the call to typeCheck in the function compileModule, I add liftIO $ putStrLn $ show $ tTypeExports tmdl. The compiler recursively compiles modules that are needed to compile the current one, and only when it reaches the module Data.Typeable does this line produce this error. If I guard the print statement to only fire when the module is not called Data.Typeable, there are no problems.

Maybe some problem with laziness, and the print statement forces some problem to manifest? The commit pushing the diff compared to your master, to trigger this bug, is here: https://github.com/Rewbert/MicroHs/commit/4ce90ddacdde5d31560167bbda3d373220a54940

Rewbert commented 4 months ago

I need to leave for the day now, but I managed to narrow it down to the call to impossible in getAssocs, in Typecheck.hs.

augustss commented 4 months ago

Is it compiling the boot file for Data.Typeable or the real module? I suspect that after compiling the boot file, some invariant might be violated. Try only printing for the real file.

augustss commented 4 months ago

You probably don't want to print when compiling a boot file anyway, since the real module will appear later.

Rewbert commented 4 months ago

Hm right, it is indeed the boot module throwing this error. What is the purpose of these modules, in contrast to the real module?

augustss commented 4 months ago

Same purpose as for GHC: to break cyclic import chains. Check out the GHC documentation, it works the same way.

augustss commented 4 months ago

I'm closing this, since it was an issue with boot imports.