on master help sign in
Only create a localizer for errors that use it

I do not really like adding arguments as is needed for this, but it is good that other situations do not need to create a dummy localizer.

commit23571802f2f8c240b952c30a0f129dbf58001735 authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 1 May 2019, 15:17 (7 years ago) parent66b6eaa
2 files changed+33−25
compiler/src/Compile.hs+20−11 compiler/src/Reporting/Error.hs+13−14
compiler/src/Compile.hs+20−11
@@ -20,6 +20,7 @@ import qualified Nitpick.PatternMatches as PatternMatches
2020import qualified Optimize.Module as Optimize
2121import qualified Reporting.Error as E
2222import qualified Reporting.Result as R
23+import qualified Reporting.Render.Type.Localizer as Localizer
2324import qualified Type.Constrain.Module as Type
2425import qualified Type.Solve as Type
2526
@@ -41,9 +42,9 @@ data Artifacts =
4142compile :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Artifacts
4243compile pkg ifaces modul =
4344 do canonical <- canonicalize pkg ifaces modul
44− annotations <- typeCheck canonical
45+ annotations <- typeCheck modul canonical
4546 () <- nitpick canonical
46− objects <- optimize annotations canonical
47+ objects <- optimize modul annotations canonical
4748 return (Artifacts canonical annotations objects)
4849
4950
@@ -53,18 +54,22 @@ compile pkg ifaces modul =
5354
5455canonicalize :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Can.Module
5556canonicalize 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
5863
5964
60−typeCheck :: Can.Module -> Either E.Error (Map.Map Name.Name Can.Annotation)
61−typeCheck canonical =
65+typeCheck :: Src.Module -> Can.Module -> Either E.Error (Map.Map Name.Name Can.Annotation)
66+typeCheck modul canonical =
6267 case unsafePerformIO (Type.run =<< Type.constrain canonical) of
6368 Right annotations ->
6469 Right annotations
6570
6671 Left errors ->
67− Left (E.BadTypes errors)
72+ Left (E.BadTypes (Localizer.fromModule modul) errors)
6873
6974
7075nitpick :: Can.Module -> Either E.Error ()
@@ -77,7 +82,11 @@ nitpick canonical =
7782 Left (E.BadPatterns errors)
7883
7984
80−optimize :: Map.Map Name.Name Can.Annotation -> Can.Module -> Either E.Error Opt.LocalGraph
81−optimize annotations canonical =
82− snd $ R.run E.BadMains $
83− Optimize.optimize annotations canonical
85+optimize :: Src.Module -> Map.Map Name.Name Can.Annotation -> Can.Module -> Either E.Error Opt.LocalGraph
86+optimize modul 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 =
4343 , _time :: File.Time
4444 , _source :: B.ByteString
4545 , _error :: Error
46− , _localizer :: L.Localizer
4746 }
4847
4948
@@ -55,36 +54,36 @@ data Error
5554 = BadSyntax Syntax.Error
5655 | BadImports (NE.List Import.Error)
5756 | 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)
5959 | BadPatterns (NE.List Pattern.Error)
60− | BadMains (OneOrMore.OneOrMore Main.Error)
6160
6261
6362
6463-- TO REPORT
6564
6665
67−toReports :: L.Localizer -> Code.Source -> Error -> NE.List Report.Report
68−toReports localizer source err =
66+toReports :: Code.Source -> Error -> NE.List Report.Report
67+toReports source err =
6968 case err of
7069 BadSyntax syntaxError ->
7170 NE.List (Syntax.toReport source syntaxError) []
7271
7372 BadImports errs ->
74− fmap Import.toReport errs
73+ fmap (Import.toReport source) errs
7574
7675 BadNames errs ->
7776 fmap (Canonicalize.toReport source) (OneOrMore.destruct NE.List errs)
7877
79− BadTypes errs ->
78+ BadTypes localizer errs ->
8079 fmap (Type.toReport source localizer) errs
8180
81+ BadMains localizer errs ->
82+ fmap (Main.toReport localizer source) (OneOrMore.destruct NE.List errs)
83+
8284 BadPatterns errs ->
8385 fmap (Pattern.toReport source) errs
8486
85− BadMains errs ->
86− fmap (Main.toReport localizer source) (OneOrMore.destruct NE.List errs)
87−
8887
8988
9089-- TO DOC
@@ -131,10 +130,10 @@ toSeparator beforeModule afterModule =
131130
132131
133132moduleToDoc :: Module -> D.Doc
134−moduleToDoc (Module _ path _ source err localizer) =
133+moduleToDoc (Module _ path _ source err) =
135134 let
136135 reports =
137− toReports localizer (Code.toSource source) err
136+ toReports (Code.toSource source) err
138137 in
139138 D.vcat $ map (reportToDoc path) (NE.toList reports)
140139
@@ -171,10 +170,10 @@ toJson modules =
171170
172171
173172moduleToJson :: Module -> E.Value
174−moduleToJson (Module name path _ source err localizer) =
173+moduleToJson (Module name path _ source err) =
175174 let
176175 reports =
177− toReports localizer (Code.toSource source) err
176+ toReports (Code.toSource source) err
178177 in
179178 E.object
180179 [ "path" ==> E.string (Utf8.fromChars path)