1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
{-# LANGUAGE FlexibleContexts #-}
module GHC.Iface.Errors
( badIfaceFile
, cannotFindInterface
, cantFindInstalledErr
, cannotFindModule
) where
import GHC.Platform.Profile
import GHC.Platform.Ways
import GHC.Utils.Panic.Plain
import GHC.Driver.Session
import GHC.Driver.Env
import GHC.Driver.Errors.Types
import GHC.Data.Maybe
import GHC.Prelude
import GHC.Unit
import GHC.Unit.Env
import GHC.Unit.Finder.Types
import GHC.Utils.Outputable as Outputable
import GHC.Iface.Errors.Types
-- -----------------------------------------------------------------------------
-- Error messages
badIfaceFile :: String -> SDoc -> SDoc
badIfaceFile file err
= vcat [text "Bad interface file:" <+> text file,
nest 4 err]
cannotFindInterface :: UnitState -> Maybe HomeUnit -> Profile
-> ModuleName -> InstalledFindResult -> MissingInterfaceError
cannotFindInterface us mhu p mn ifr =
CantFindErr us FindingInterface $
cantFindInstalledErr us mhu p mn ifr
cantFindInstalledErr
:: UnitState
-> Maybe HomeUnit
-> Profile
-> ModuleName
-> InstalledFindResult
-> CantFindInstalled
cantFindInstalledErr unit_state mhome_unit profile mod_name find_result
= CantFindInstalled mod_name more_info
where
build_tag = waysBuildTag (profileWays profile)
more_info
= case find_result of
InstalledNoPackage pkg
-> NoUnitIdMatching pkg (searchPackageId unit_state (PackageId (unitIdFS pkg)))
InstalledNotFound files mb_pkg
| Just pkg <- mb_pkg
, notHomeUnitId mhome_unit pkg
-> not_found_in_package pkg files
| null files
-> NotAModule
| otherwise
-> CouldntFindInFiles files
_ -> panic "cantFindInstalledErr"
not_found_in_package pkg files
| build_tag /= ""
= let
build = if build_tag == "p" then "profiling"
else "\"" ++ build_tag ++ "\""
in
MissingPackageWayFiles build pkg files
| otherwise
= MissingPackageFiles pkg files
cannotFindModule :: HscEnv -> ModuleName -> FindResult -> MissingInterfaceError
cannotFindModule hsc_env = cannotFindModule'
(hsc_dflags hsc_env)
(hsc_unit_env hsc_env)
(targetProfile (hsc_dflags hsc_env))
cannotFindModule' :: DynFlags -> UnitEnv -> Profile -> ModuleName -> FindResult
-> MissingInterfaceError
cannotFindModule' dflags unit_env profile mod res =
CantFindErr (ue_units unit_env) FindingModule $
cantFindErr (checkBuildingCabalPackage dflags)
unit_env
profile
mod
res
cantFindErr
:: BuildingCabalPackage -- ^ Using Cabal?
-> UnitEnv
-> Profile
-> ModuleName
-> FindResult
-> CantFindInstalled
cantFindErr _ _ _ mod_name (FoundMultiple mods)
= CantFindInstalled mod_name (MultiplePackages mods)
cantFindErr using_cabal unit_env profile mod_name find_result
= CantFindInstalled mod_name more_info
where
mhome_unit = ue_homeUnit unit_env
more_info
= case find_result of
NoPackage pkg
-> NoUnitIdMatching (toUnitId pkg) []
NotFound { fr_paths = files, fr_pkg = mb_pkg
, fr_mods_hidden = mod_hiddens, fr_pkgs_hidden = pkg_hiddens
, fr_unusables = unusables, fr_suggestions = suggest }
| Just pkg <- mb_pkg
, Nothing <- mhome_unit -- no home-unit
-> not_found_in_package (toUnitId pkg) files
| Just pkg <- mb_pkg
, Just home_unit <- mhome_unit -- there is a home-unit but the
, not (isHomeUnit home_unit pkg) -- module isn't from it
-> not_found_in_package (toUnitId pkg) files
| not (null suggest)
-> ModuleSuggestion suggest files
| null files && null mod_hiddens &&
null pkg_hiddens && null unusables
-> NotAModule
| otherwise
-> GenericMissing using_cabal
(map ((\uid -> (uid, lookupUnit (ue_units unit_env) uid))) pkg_hiddens)
mod_hiddens unusables files
_ -> panic "cantFindErr"
build_tag = waysBuildTag (profileWays profile)
not_found_in_package pkg files
| build_tag /= ""
= let
build = if build_tag == "p" then "profiling"
else "\"" ++ build_tag ++ "\""
in
MissingPackageWayFiles build pkg files
| otherwise
= MissingPackageFiles pkg files
|