@@ -1038,42 +1038,59 @@ getClientConfigAction defValue = do
10381038 Just (Success c) -> return c
10391039 _ -> return defValue
10401040
1041- -- | For now we always use bytecode
1041+ -- | For now we always use bytecode unless something uses unboxed sums and tuples along with TH
10421042getLinkableType :: NormalizedFilePath -> Action (Maybe LinkableType )
1043- getLinkableType f = do
1044- needsComp <- use_ NeedsCompilation f
1045- pure $ if needsComp then Just BCOLinkable else Nothing
1043+ getLinkableType f = use_ NeedsCompilation f
10461044
10471045needsCompilationRule :: Rules ()
10481046needsCompilationRule = defineEarlyCutoff $ \ NeedsCompilation file -> do
1049- -- It's important to use stale data here to avoid wasted work.
1050- -- if NeedsCompilation fails for a module M its result will be under-approximated
1051- -- to False in its dependencies. However, if M actually used TH, this will
1052- -- cause a re-evaluation of GetModIface for all dependencies
1053- -- (since we don't need to generate object code anymore).
1054- -- Once M is fixed we will discover that we actually needed all the object code
1055- -- that we just threw away, and thus have to recompile all dependencies once
1056- -- again, this time keeping the object code.
1057- (ms,_) <- fst <$> useWithStale_ GetModSummaryWithoutTimestamps file
1058- -- A file needs object code if it uses TemplateHaskell or any file that depends on it uses TemplateHaskell
1059- res <-
1060- if uses_th_qq ms
1061- then pure True
1062- else do
1063- graph <- useNoFile GetModuleGraph
1064- case graph of
1065- -- Treat as False if some reverse dependency header fails to parse
1066- Nothing -> pure False
1067- Just depinfo -> case immediateReverseDependencies file depinfo of
1068- -- If we fail to get immediate reverse dependencies, fail with an error message
1069- Nothing -> fail $ " Failed to get the immediate reverse dependencies of " ++ show file
1070- Just revdeps -> anyM (fmap (fromMaybe False ) . use NeedsCompilation ) revdeps
1047+ graph <- useNoFile GetModuleGraph
1048+ res <- case graph of
1049+ -- Treat as False if some reverse dependency header fails to parse
1050+ Nothing -> pure Nothing
1051+ Just depinfo -> case immediateReverseDependencies file depinfo of
1052+ -- If we fail to get immediate reverse dependencies, fail with an error message
1053+ Nothing -> fail $ " Failed to get the immediate reverse dependencies of " ++ show file
1054+ Just revdeps -> do
1055+ -- It's important to use stale data here to avoid wasted work.
1056+ -- if NeedsCompilation fails for a module M its result will be under-approximated
1057+ -- to False in its dependencies. However, if M actually used TH, this will
1058+ -- cause a re-evaluation of GetModIface for all dependencies
1059+ -- (since we don't need to generate object code anymore).
1060+ -- Once M is fixed we will discover that we actually needed all the object code
1061+ -- that we just threw away, and thus have to recompile all dependencies once
1062+ -- again, this time keeping the object code.
1063+ -- A file needs to be compiled if any file that depends on it uses TemplateHaskell or needs to be compiled
1064+ (ms,_) <- fst <$> useWithStale_ GetModSummaryWithoutTimestamps file
1065+ (modsums,needsComps) <- par (map (fmap (fst . fst )) <$> usesWithStale GetModSummaryWithoutTimestamps revdeps)
1066+ (uses NeedsCompilation revdeps)
1067+ pure $ computeLinkableType ms modsums (map join needsComps)
10711068
10721069 pure (Just $ BS. pack $ show $ hash res, ([] , Just res))
10731070 where
10741071 uses_th_qq (ms_hspp_opts -> dflags) =
10751072 xopt LangExt. TemplateHaskell dflags || xopt LangExt. QuasiQuotes dflags
10761073
1074+ unboxed_tuples_or_sums (ms_hspp_opts -> d) =
1075+ xopt LangExt. UnboxedTuples d || xopt LangExt. UnboxedSums d
1076+
1077+ computeLinkableType :: ModSummary -> [Maybe ModSummary ] -> [Maybe LinkableType ] -> Maybe LinkableType
1078+ computeLinkableType this deps xs
1079+ | Just ObjectLinkable `elem` xs = Just ObjectLinkable -- If any dependent needs object code, so do we
1080+ | Just BCOLinkable `elem` xs = Just this_type -- If any dependent needs bytecode, then we need to be compiled
1081+ | any (maybe False uses_th_qq) deps = Just this_type -- If any dependent needs TH, then we need to be compiled
1082+ | otherwise = Nothing -- If none of these conditions are satisfied, we don't need to compile
1083+ where
1084+ -- How should we compile this module? (assuming we do in fact need to compile it)
1085+ -- Depends on whether it uses unboxed tuples or sums
1086+ this_type
1087+ #if defined(GHC_PATCHED_UNBOXED_BYTECODE)
1088+ = BCOLinkable
1089+ #else
1090+ | unboxed_tuples_or_sums this = ObjectLinkable
1091+ | otherwise = BCOLinkable
1092+ #endif
1093+
10771094-- | Tracks which linkables are current, so we don't need to unload them
10781095newtype CompiledLinkables = CompiledLinkables { getCompiledLinkables :: Var (ModuleEnv UTCTime ) }
10791096instance IsIdeGlobal CompiledLinkables
0 commit comments