on master help sign in
Only create a localizer for errors that use it
2357180Evan Czaplicki
compiler/src/Compile.hs+20−11
@@ -20,6 +20,7 @@ import qualified Nitpick.PatternMatches as PatternMatches
20import qualified Optimize.Module as Optimize
20import qualified Optimize.Module as Optimize
21import qualified Reporting.Error as E
21import qualified Reporting.Error as E
22import qualified Reporting.Result as R
22import qualified Reporting.Result as R
23+import qualified Reporting.Render.Type.Localizer as Localizer
23import qualified Type.Constrain.Module as Type
24import qualified Type.Constrain.Module as Type
24import qualified Type.Solve as Type
25import qualified Type.Solve as Type
25
26
@@ -41,9 +42,9 @@ data Artifacts =
41compile :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Artifacts
42compile :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Artifacts
42compile pkg ifaces modul =
43compile pkg ifaces modul =
43 do canonical <- canonicalize pkg ifaces modul
44 do canonical <- canonicalize pkg ifaces modul
44− annotations <- typeCheck canonical
45+ annotations <- typeCheck modul canonical
45 () <- nitpick canonical
46 () <- nitpick canonical
46− objects <- optimize annotations canonical
47+ objects <- optimize modul annotations canonical
47 return (Artifacts canonical annotations objects)
48 return (Artifacts canonical annotations objects)
48
49
49
50
@@ -53,18 +54,22 @@ compile pkg ifaces modul =
53
54
54canonicalize :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Can.Module
55canonicalize :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Can.Module
55canonicalize pkg ifaces modul =
56canonicalize pkg ifaces modul =
56− snd $ R.run E.BadNames $
57− Canonicalize.canonicalize pkg ifaces modul
57+ case snd $ R.run $ Canonicalize.canonicalize pkg ifaces modul of
58+ Right canonical ->
59+ Right canonical
60+
61+ Left errors ->
62+ Left $ E.BadNames errors
58
63
59
64
60−typeCheck :: Can.Module -> Either E.Error (Map.Map Name.Name Can.Annotation)
65+typeCheck :: Src.Module -> Can.Module -> Either E.Error (Map.Map Name.Name Can.Annotation)
61−typeCheck canonical =
66+typeCheck modul canonical =
62 case unsafePerformIO (Type.run =<< Type.constrain canonical) of
67 case unsafePerformIO (Type.run =<< Type.constrain canonical) of
63 Right annotations ->
68 Right annotations ->
64 Right annotations
69 Right annotations
65
70
66 Left errors ->
71 Left errors ->
67− Left (E.BadTypes errors)
72+ Left (E.BadTypes (Localizer.fromModule modul) errors)
68
73
69
74
70nitpick :: Can.Module -> Either E.Error ()
75nitpick :: Can.Module -> Either E.Error ()
@@ -77,7 +82,11 @@ nitpick canonical =
77 Left (E.BadPatterns errors)
82 Left (E.BadPatterns errors)
78
83
79
84
80−optimize :: Map.Map Name.Name Can.Annotation -> Can.Module -> Either E.Error Opt.LocalGraph
85+optimize :: Src.Module -> Map.Map Name.Name Can.Annotation -> Can.Module -> Either E.Error Opt.LocalGraph
81−optimize annotations canonical =
86+optimize modul annotations canonical =
82− snd $ R.run E.BadMains $
83− Optimize.optimize annotations canonical
87+ case snd $ R.run $ Optimize.optimize annotations canonical of
88+ Right localGraph ->
89+ Right localGraph
90+
91+ Left errors ->
92+ Left (E.BadMains (Localizer.fromModule modul) errors)
compiler/src/Reporting/Error.hs+13−14
@@ -43,7 +43,6 @@ data Module =
43 , _time :: File.Time
43 , _time :: File.Time
44 , _source :: B.ByteString
44 , _source :: B.ByteString
45 , _error :: Error
45 , _error :: Error
46− , _localizer :: L.Localizer
47 }
46 }
48
47
49
48
@@ -55,36 +54,36 @@ data Error
55 = BadSyntax Syntax.Error
54 = BadSyntax Syntax.Error
56 | BadImports (NE.List Import.Error)
55 | BadImports (NE.List Import.Error)
57 | BadNames (OneOrMore.OneOrMore Canonicalize.Error)
56 | BadNames (OneOrMore.OneOrMore Canonicalize.Error)
58− | BadTypes (NE.List Type.Error)
57+ | BadTypes L.Localizer (NE.List Type.Error)
58+ | BadMains L.Localizer (OneOrMore.OneOrMore Main.Error)
59 | BadPatterns (NE.List Pattern.Error)
59 | BadPatterns (NE.List Pattern.Error)
60− | BadMains (OneOrMore.OneOrMore Main.Error)
61
60
62
61
63
62
64-- TO REPORT
63-- TO REPORT
65
64
66
65
67−toReports :: L.Localizer -> Code.Source -> Error -> NE.List Report.Report
66+toReports :: Code.Source -> Error -> NE.List Report.Report
68−toReports localizer source err =
67+toReports source err =
69 case err of
68 case err of
70 BadSyntax syntaxError ->
69 BadSyntax syntaxError ->
71 NE.List (Syntax.toReport source syntaxError) []
70 NE.List (Syntax.toReport source syntaxError) []
72
71
73 BadImports errs ->
72 BadImports errs ->
74− fmap Import.toReport errs
73+ fmap (Import.toReport source) errs
75
74
76 BadNames errs ->
75 BadNames errs ->
77 fmap (Canonicalize.toReport source) (OneOrMore.destruct NE.List errs)
76 fmap (Canonicalize.toReport source) (OneOrMore.destruct NE.List errs)
78
77
79− BadTypes errs ->
78+ BadTypes localizer errs ->
80 fmap (Type.toReport source localizer) errs
79 fmap (Type.toReport source localizer) errs
81
80
81+ BadMains localizer errs ->
82+ fmap (Main.toReport localizer source) (OneOrMore.destruct NE.List errs)
83+
82 BadPatterns errs ->
84 BadPatterns errs ->
83 fmap (Pattern.toReport source) errs
85 fmap (Pattern.toReport source) errs
84
86
85− BadMains errs ->
86− fmap (Main.toReport localizer source) (OneOrMore.destruct NE.List errs)
87−
88
87
89
88
90-- TO DOC
89-- TO DOC
@@ -131,10 +130,10 @@ toSeparator beforeModule afterModule =
131
130
132
131
133moduleToDoc :: Module -> D.Doc
132moduleToDoc :: Module -> D.Doc
134−moduleToDoc (Module _ path _ source err localizer) =
133+moduleToDoc (Module _ path _ source err) =
135 let
134 let
136 reports =
135 reports =
137− toReports localizer (Code.toSource source) err
136+ toReports (Code.toSource source) err
138 in
137 in
139 D.vcat $ map (reportToDoc path) (NE.toList reports)
138 D.vcat $ map (reportToDoc path) (NE.toList reports)
140
139
@@ -171,10 +170,10 @@ toJson modules =
171
170
172
171
173moduleToJson :: Module -> E.Value
172moduleToJson :: Module -> E.Value
174−moduleToJson (Module name path _ source err localizer) =
173+moduleToJson (Module name path _ source err) =
175 let
174 let
176 reports =
175 reports =
177− toReports localizer (Code.toSource source) err
176+ toReports (Code.toSource source) err
178 in
177 in
179 E.object
178 E.object
180 [ "path" ==> E.string (Utf8.fromChars path)
179 [ "path" ==> E.string (Utf8.fromChars path)