Default types vs deriving
Summary
In !12179 (comment 551772) we added the following code:
default ()
data Maybe a = Nothing | Just a
deriving ( Eq -- ^ @since base-2.01
--, Ord -- ^ @since base-2.01
)
-- ???
-- A non-standalone instance will slurp the interface file for GHC.Num.Integer.
-- During simplifyInstanceContexts, a call to GHC.Tc.Utils.Env.tcGetDefaultTys
-- apparently sees mb_defaults = Nothing and thus tries to bring in the
-- default "default" types, including Integer. This seems wrong.
deriving instance Ord a => Ord (Maybe a) -- ^ @since base-2.01
Both standalone and non-standalone instance declarations should "see" the same default types (none here because of the default ()
).
Steps to reproduce
Reproduce with:
{-# LANGUAGE NoImplicitPrelude #-}
module M where
import GHC.Classes
default ()
data Foo a = Nothing | Just a
deriving (Eq, Ord)
-- deriving instance Eq a => Eq (Foo a)
-- deriving instance Ord a => Ord (Foo a)
Build with:
strace -f -e trace=file ghc M.hs -fforce-recomp -fno-code 2>&1 | grep ghc-bignum
We use -fno-code
because the bignum interfaces seem to be loaded during codegen.
Result with standalone deriving:
❯ strace -f -e trace=file ghc-9.8 M.hs -fforce-recomp -fno-code 2>&1 | grep ghc-bignum
openat(AT_FDCWD, "/home/hsyl20/.ghcup/ghc/9.8.1-alpha1/lib/ghc-9.8.0.20230727/bin/../lib/x86_64-linux-ghc-9.8.0.20230727/libHSghc-bignum-1.3-0df6-ghc9.8.0.20230727.so", O_RDONLY|O_CLOEXEC) = 3
Result with non-standalone deriving:
❯ strace -f -e trace=file ghc-9.8 M.hs -fforce-recomp -fno-code 2>&1 | grep ghc-bignum
openat(AT_FDCWD, "/home/hsyl20/.ghcup/ghc/9.8.1-alpha1/lib/ghc-9.8.0.20230727/bin/../lib/x86_64-linux-ghc-9.8.0.20230727/libHSghc-bignum-1.3-0df6-ghc9.8.0.20230727.so", O_RDONLY|O_CLOEXEC) = 3
[pid 172062] stat("/home/hsyl20/.ghcup/ghc/9.8.1-alpha1/lib/ghc-9.8.0.20230727/lib/../lib/x86_64-linux-ghc-9.8.0.20230727/ghc-bignum-1.3-0df6/GHC/Num/Integer.hi", {st_mode=S_IFREG|0644, st_size=47534, ...}) = 0
[pid 172062] openat(AT_FDCWD, "/home/hsyl20/.ghcup/ghc/9.8.1-alpha1/lib/ghc-9.8.0.20230727/lib/../lib/x86_64-linux-ghc-9.8.0.20230727/ghc-bignum-1.3-0df6/GHC/Num/Integer.hi", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 13
Expected behavior
Bignum interfaces shouldn't be loaded with non-standalone deriving.
Environment
- GHC version used: 9.6, 9.8