on master help sign in
Add back --debug flag, only generate debugger in that case
6585f1fEvan Czaplicki
builder/src/File/Args.hs+2−1
@@ -11,6 +11,7 @@ import qualified Elm.Compiler.Module as Module
11import qualified Elm.Project.Json as Project
11import qualified Elm.Project.Json as Project
12import qualified Elm.Project.Summary as Summary
12import qualified Elm.Project.Summary as Summary
13import qualified Reporting.Exit as Exit
13import qualified Reporting.Exit as Exit
14+import qualified Reporting.Exit.Make as E
14import qualified Reporting.Task as Task
15import qualified Reporting.Task as Task
15
16
16
17
@@ -36,4 +37,4 @@ fromSummary (Summary.Summary _ project _ _ _) =
36 return $ Pkg (Project.getExposed info)
37 return $ Pkg (Project.getExposed info)
37
38
38 Project.App _ ->
39 Project.App _ ->
39− Task.throw Exit.CannotMakeNothing
40+ Task.throw (Exit.Make E.CannotMakeNothing)
builder/src/Generate/Output.hs+3−1
@@ -34,6 +34,7 @@ import qualified Generate.Functions as Functions
34import qualified Generate.Html as Html
34import qualified Generate.Html as Html
35import qualified Generate.Nitpick as Nitpick
35import qualified Generate.Nitpick as Nitpick
36import qualified Reporting.Exit as Exit
36import qualified Reporting.Exit as Exit
37+import qualified Reporting.Exit.Make as E
37import qualified Reporting.Task as Task
38import qualified Reporting.Task as Task
38import qualified Stuff.Paths as Paths
39import qualified Stuff.Paths as Paths
39import Terminal.Args (Parser(..), suggestFiles)
40import Terminal.Args (Parser(..), suggestFiles)
@@ -61,6 +62,7 @@ generate options summary graph@(Crawl.Graph args _ _ _ _) =
61 do objectGraph <- organize summary graph
62 do objectGraph <- organize summary graph
62
63
63 case _mode options of
64 case _mode options of
65+ Obj.Debug -> return ()
64 Obj.Dev -> return ()
66 Obj.Dev -> return ()
65 Obj.Prod -> noDebugUses summary objectGraph
67 Obj.Prod -> noDebugUses summary objectGraph
66
68
@@ -163,7 +165,7 @@ noDebugUses (Summary.Summary _ project _ _ _) graph =
163 return ()
165 return ()
164
166
165 m:ms ->
167 m:ms ->
166− Task.throw (Exit.CannotOptimizeDebug m ms)
168+ Task.throw (Exit.Make (E.CannotOptimizeDebugValues m ms))
167
169
168
170
169noDebugUsesInPackage :: Summary.Summary -> Crawl.Result -> Task.Task ()
171noDebugUsesInPackage :: Summary.Summary -> Crawl.Result -> Task.Task ()
builder/src/Reporting/Exit.hs+19−49
@@ -21,6 +21,7 @@ import qualified Reporting.Exit.Deps as Deps
21import qualified Reporting.Exit.Diff as Diff
21import qualified Reporting.Exit.Diff as Diff
22import qualified Reporting.Exit.Help as Help
22import qualified Reporting.Exit.Help as Help
23import qualified Reporting.Exit.Http as Http
23import qualified Reporting.Exit.Http as Http
24+import qualified Reporting.Exit.Make as Make
24import qualified Reporting.Exit.Publish as Publish
25import qualified Reporting.Exit.Publish as Publish
25
26
26
27
@@ -37,13 +38,12 @@ data Exit
37 | Cycle [Module.Raw] -- TODO write docs to help with this scenario
38 | Cycle [Module.Raw] -- TODO write docs to help with this scenario
38 | Deps Deps.Exit
39 | Deps Deps.Exit
39 | Diff Diff.Exit
40 | Diff Diff.Exit
41+ | Make Make.Exit
40 | Publish Publish.Exit
42 | Publish Publish.Exit
41 | BadHttp String Http.Exit
43 | BadHttp String Http.Exit
42
44
43 -- misc
45 -- misc
44 | NoSolution [Pkg.Name]
46 | NoSolution [Pkg.Name]
45− | CannotMakeNothing
46− | CannotOptimizeDebug Module.Raw [Module.Raw]
47
47
48
48
49
49
@@ -86,17 +86,17 @@ toReport exit =
86 "Whatever your scenario, I hope you have a lovely time using Elm!"
86 "Whatever your scenario, I hope you have a lovely time using Elm!"
87 ]
87 ]
88
88
89− Assets assetError ->
89+ Assets assetExit ->
90− Asset.toReport assetError
90+ Asset.toReport assetExit
91
91
92− Bump bumpError ->
92+ Bump bumpExit ->
93− Bump.toReport bumpError
93+ Bump.toReport bumpExit
94
94
95 Compile e es ->
95 Compile e es ->
96 Help.compilerReport e es
96 Help.compilerReport e es
97
97
98− Crawl crawlError ->
98+ Crawl crawlExit ->
99− Crawl.toReport crawlError
99+ Crawl.toReport crawlExit
100
100
101 Cycle names ->
101 Cycle names ->
102 Help.report "IMPORT CYCLE" Nothing
102 Help.report "IMPORT CYCLE" Nothing
@@ -107,17 +107,20 @@ toReport exit =
107 ++ D.makeLink "import-cycles"
107 ++ D.makeLink "import-cycles"
108 ]
108 ]
109
109
110− Deps depsError ->
110+ Deps depsExit ->
111− Deps.toReport depsError
111+ Deps.toReport depsExit
112
112
113− Diff commandsError ->
113+ Diff commandsExit ->
114− Diff.toReport commandsError
114+ Diff.toReport commandsExit
115
115
116− Publish publishError ->
116+ Make makeExit ->
117− Publish.toReport publishError
117+ Make.toReport makeExit
118
118
119+ Publish publishExit ->
120+ Publish.toReport publishExit
121+
119− BadHttp url httpError ->
122+ BadHttp url httpExit ->
120− Http.toReport url httpError
123+ Http.toReport url httpExit
121
124
122 NoSolution badPackages ->
125 NoSolution badPackages ->
123 case badPackages of
126 case badPackages of
@@ -148,36 +151,3 @@ toReport exit =
148 \ goals, etc. They face obstacles outside of their technical work you will never\
151 \ goals, etc. They face obstacles outside of their technical work you will never\
149 \ know about, so please assume the best and try to be patient and supportive!"
152 \ know about, so please assume the best and try to be patient and supportive!"
150 ]
153 ]
151−
152− CannotMakeNothing ->
153− Help.report "NO INPUT" Nothing
154− "What should I make though? I need more information, like:"
155− [ D.vcat
156− [ D.indent 4 $ D.green "elm make MyThing.elm"
157− , D.indent 4 $ D.green "elm make This.elm That.elm"
158− ]
159− , D.reflow
160− "However many files you give, I will create one JS file out of them."
161− ]
162−
163− CannotOptimizeDebug m ms ->
164− Help.report "DEBUG REMNANTS" Nothing
165− "There are uses of the `Debug` module in the following modules:"
166− [ D.indent 4 $ D.red $ D.vcat $ map (D.fromString . Module.nameToString) (m:ms)
167− , D.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
168− , D.toSimpleNote $
169− "The issue is that --optimize strips out info needed by `Debug` functions.\
170− \ Here are two examples:"
171− , D.indent 4 $ D.reflow $
172− "(1) It shortens record field names. This makes the generated JavaScript is\
173− \ smaller, but `Debug.toString` cannot know the real field names anymore."
174− , D.indent 4 $ D.reflow $
175− "(2) Values like `type Height = Height Float` are unboxed. This reduces\
176− \ allocation, but it also means that `Debug.toString` cannot tell if it is\
177− \ looking at a `Height` or `Float` value."
178− , D.reflow $
179− "There are a few other cases like that, and it will be much worse once we start\
180− \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
181− \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
182− \ exists!"
183− ]
builder/src/Reporting/Exit/Make.hsnew file+75
@@ -0,0 +1,75 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+module Reporting.Exit.Make
3+ ( Exit(..)
4+ , toReport
5+ )
6+ where
7+
8+
9+import qualified Elm.Compiler.Module as Module
10+import qualified Reporting.Doc as D
11+import qualified Reporting.Exit.Help as Help
12+
13+
14+
15+-- EXITS
16+
17+
18+data Exit
19+ = CannotMakeNothing
20+ | CannotOptimizeDebugValues Module.Raw [Module.Raw]
21+ | CannotOptimizeAndDebug
22+
23+
24+
25+-- TO REPORT
26+
27+
28+toReport :: Exit -> Help.Report
29+toReport exit =
30+ case exit of
31+ CannotMakeNothing ->
32+ Help.report "NO INPUT" Nothing
33+ "What should I make though? I need more information, like:"
34+ [ D.vcat
35+ [ D.indent 4 $ D.green "elm make MyThing.elm"
36+ , D.indent 4 $ D.green "elm make This.elm That.elm"
37+ ]
38+ , D.reflow
39+ "However many files you give, I will create one JS file out of them."
40+ ]
41+
42+ CannotOptimizeDebugValues m ms ->
43+ Help.report "DEBUG REMNANTS" Nothing
44+ "There are uses of the `Debug` module in the following modules:"
45+ [ D.indent 4 $ D.red $ D.vcat $ map (D.fromString . Module.nameToString) (m:ms)
46+ , D.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
47+ , D.toSimpleNote $
48+ "The issue is that --optimize strips out info needed by `Debug` functions.\
49+ \ Here are two examples:"
50+ , D.indent 4 $ D.reflow $
51+ "(1) It shortens record field names. This makes the generated JavaScript is\
52+ \ smaller, but `Debug.toString` cannot know the real field names anymore."
53+ , D.indent 4 $ D.reflow $
54+ "(2) Values like `type Height = Height Float` are unboxed. This reduces\
55+ \ allocation, but it also means that `Debug.toString` cannot tell if it is\
56+ \ looking at a `Height` or `Float` value."
57+ , D.reflow $
58+ "There are a few other cases like that, and it will be much worse once we start\
59+ \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
60+ \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
61+ \ exists!"
62+ ]
63+
64+ CannotOptimizeAndDebug ->
65+ Help.docReport "CLASHING FLAGS" Nothing
66+ ( D.fillSep
67+ ["I","cannot","compile","with",D.red "--optimize","and"
68+ ,D.red "--debug","at","the","same","time."
69+ ]
70+ )
71+ [ D.reflow
72+ "I need to take away information to optimize things, and I need to\
73+ \ add information to add the debugger. It is impossible to do both\
74+ \ at once, so pick just one of those flags."
75+ ]
compiler/src/Generate/JavaScript.hs+11−8
@@ -36,7 +36,7 @@ import qualified Reporting.Doc as D
36-- GENERATE MAINS
36-- GENERATE MAINS
37
37
38
38
39−data Mode = Dev | Prod
39+data Mode = Prod | Dev | Debug
40
40
41
41
42data Output
42data Output
@@ -71,8 +71,11 @@ addMain mode graph home _ state =
71toRealMode :: Mode -> Name.Target -> Map.Map N.Name Int -> Name.Mode
71toRealMode :: Mode -> Name.Target -> Map.Map N.Name Int -> Name.Mode
72toRealMode mode target fields =
72toRealMode mode target fields =
73 case mode of
73 case mode of
74+ Debug ->
75+ Name.Dev target Name.DebuggerOn
76+
74 Dev ->
77 Dev ->
75− Name.Dev target
78+ Name.Dev target Name.DebuggerOff
76
79
77 Prod ->
80 Prod ->
78 Name.Prod target (Name.shortenFieldNames fields)
81 Name.Prod target (Name.shortenFieldNames fields)
@@ -85,7 +88,7 @@ toRealMode mode target fields =
85generateForRepl :: Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
88generateForRepl :: Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
86generateForRepl (Opt.Graph _ graph _) iface home name =
89generateForRepl (Opt.Graph _ graph _) iface home name =
87 let
90 let
88− mode = Name.Dev Name.Server
91+ mode = Name.Dev Name.Server Name.DebuggerOff
89 debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
92 debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
90 evalState = addGlobal mode graph debugState (Opt.Global home name)
93 evalState = addGlobal mode graph debugState (Opt.Global home name)
91 in
94 in
@@ -238,7 +241,7 @@ generateCycle mode (Opt.Global home _) cycle =
238 Name.Prod _ _ ->
241 Name.Prod _ _ ->
239 block
242 block
240
243
241− Name.Dev _ ->
244+ Name.Dev _ _ ->
242 JS.Try block Name.dollar $ JS.Throw $ JS.String $
245 JS.Try block Name.dollar $ JS.Throw $ JS.String $
243 "The following top-level definitions are causing infinite recursion:\\n"
246 "The following top-level definitions are causing infinite recursion:\\n"
244 <> drawCycle (map fst cycle)
247 <> drawCycle (map fst cycle)
@@ -310,7 +313,7 @@ addChunk mode builder chunk =
310
313
311 Opt.Debug ->
314 Opt.Debug ->
312 case mode of
315 case mode of
313− Name.Dev _ ->
316+ Name.Dev _ _ ->
314 builder
317 builder
315
318
316 Name.Prod _ _ ->
319 Name.Prod _ _ ->
@@ -318,7 +321,7 @@ addChunk mode builder chunk =
318
321
319 Opt.Prod ->
322 Opt.Prod ->
320 case mode of
323 case mode of
321− Name.Dev _ ->
324+ Name.Dev _ _ ->
322 "_UNUSED" <> builder
325 "_UNUSED" <> builder
323
326
324 Name.Prod _ _ ->
327 Name.Prod _ _ ->
@@ -334,7 +337,7 @@ generateEnum mode (Opt.Global home name) ctorName index =
334 let
337 let
335 definition =
338 definition =
336 case mode of
339 case mode of
337− Name.Dev _ ->
340+ Name.Dev _ _ ->
338 Expr.codeToExpr (Expr.generateCtor mode ctorName index 0)
341 Expr.codeToExpr (Expr.generateCtor mode ctorName index 0)
339
342
340 Name.Prod _ _ ->
343 Name.Prod _ _ ->
@@ -352,7 +355,7 @@ generateBox mode (Opt.Global home name) ctorName =
352 let
355 let
353 definition =
356 definition =
354 case mode of
357 case mode of
355− Name.Dev _ ->
358+ Name.Dev _ _ ->
356 Expr.codeToExpr (Expr.generateCtor mode ctorName Index.first 1)
359 Expr.codeToExpr (Expr.generateCtor mode ctorName Index.first 1)
357
360
358 Name.Prod _ _ ->
361 Name.Prod _ _ ->
compiler/src/Generate/JavaScript/Expression.hs+23−18
@@ -58,7 +58,7 @@ generate mode expression =
58 Opt.Chr char ->
58 Opt.Chr char ->
59 JsExpr $
59 JsExpr $
60 case mode of
60 case mode of
61− Name.Dev _ ->
61+ Name.Dev _ _ ->
62 JS.Call toChar [ JS.String (Text.encodeUtf8Builder char) ]
62 JS.Call toChar [ JS.String (Text.encodeUtf8Builder char) ]
63
63
64 Name.Prod _ _ ->
64 Name.Prod _ _ ->
@@ -81,7 +81,7 @@ generate mode expression =
81
81
82 Opt.VarEnum (Opt.Global home name) index ->
82 Opt.VarEnum (Opt.Global home name) index ->
83 case mode of
83 case mode of
84− Name.Dev _ ->
84+ Name.Dev _ _ ->
85 JsExpr $ JS.Ref (Name.fromGlobal home name)
85 JsExpr $ JS.Ref (Name.fromGlobal home name)
86
86
87 Name.Prod _ _ ->
87 Name.Prod _ _ ->
@@ -90,7 +90,7 @@ generate mode expression =
90 Opt.VarBox (Opt.Global home name) ->
90 Opt.VarBox (Opt.Global home name) ->
91 JsExpr $ JS.Ref $
91 JsExpr $ JS.Ref $
92 case mode of
92 case mode of
93− Name.Dev _ -> Name.fromGlobal home name
93+ Name.Dev _ _ -> Name.fromGlobal home name
94 Name.Prod _ _ -> Name.fromGlobal ModuleName.basics N.identity
94 Name.Prod _ _ -> Name.fromGlobal ModuleName.basics N.identity
95
95
96 Opt.VarCycle home name ->
96 Opt.VarCycle home name ->
@@ -161,7 +161,7 @@ generate mode expression =
161
161
162 Opt.Unit ->
162 Opt.Unit ->
163 case mode of
163 case mode of
164− Name.Dev _ ->
164+ Name.Dev _ _ ->
165 JsExpr $ JS.Ref (Name.fromKernel N.utils "Tuple0")
165 JsExpr $ JS.Ref (Name.fromKernel N.utils "Tuple0")
166
166
167 Name.Prod _ _ ->
167 Name.Prod _ _ ->
@@ -261,7 +261,7 @@ generateCtor mode name index arity =
261
261
262 ctorTag =
262 ctorTag =
263 case mode of
263 case mode of
264− Name.Dev _ -> JS.String (N.toBuilder name)
264+ Name.Dev _ _ -> JS.String (N.toBuilder name)
265 Name.Prod _ _ -> JS.Int (Index.toMachine index)
265 Name.Prod _ _ -> JS.Int (Index.toMachine index)
266 in
266 in
267 generateFunction argNames $ JsExpr $ JS.Object $
267 generateFunction argNames $ JsExpr $ JS.Object $
@@ -363,7 +363,7 @@ generateCall mode func args =
363
363
364 Opt.VarBox _ ->
364 Opt.VarBox _ ->
365 case mode of
365 case mode of
366− Name.Dev _ ->
366+ Name.Dev _ _ ->
367 generateCallHelp mode func args
367 generateCallHelp mode func args
368
368
369 Name.Prod _ _ ->
369 Name.Prod _ _ ->
@@ -744,7 +744,7 @@ generatePath mode path =
744
744
745 Opt.Unbox subPath ->
745 Opt.Unbox subPath ->
746 case mode of
746 case mode of
747− Name.Dev _ ->
747+ Name.Dev _ _ ->
748 JS.Access (generatePath mode subPath) (Name.fromIndex Index.first)
748 JS.Access (generatePath mode subPath) (Name.fromIndex Index.first)
749
749
750 Name.Prod _ _ ->
750 Name.Prod _ _ ->
@@ -872,7 +872,7 @@ generateIfTest mode root (path, test) =
872 DT.IsCtor name index _ _ ->
872 DT.IsCtor name index _ _ ->
873 strictEq (JS.Access value Name.dollar) $
873 strictEq (JS.Access value Name.dollar) $
874 case mode of
874 case mode of
875− Name.Dev _ -> JS.String (N.toBuilder name)
875+ Name.Dev _ _ -> JS.String (N.toBuilder name)
876 Name.Prod _ _ -> JS.Int (Index.toMachine index)
876 Name.Prod _ _ -> JS.Int (Index.toMachine index)
877
877
878 DT.IsInt int ->
878 DT.IsInt int ->
@@ -881,7 +881,7 @@ generateIfTest mode root (path, test) =
881 DT.IsChr char ->
881 DT.IsChr char ->
882 strictEq (JS.String (Text.encodeUtf8Builder char)) $
882 strictEq (JS.String (Text.encodeUtf8Builder char)) $
883 case mode of
883 case mode of
884− Name.Dev _ -> JS.Call (JS.Access value (Name.fromLocal "valueOf")) []
884+ Name.Dev _ _ -> JS.Call (JS.Access value (Name.fromLocal "valueOf")) []
885 Name.Prod _ _ -> value
885 Name.Prod _ _ -> value
886
886
887 DT.IsStr string ->
887 DT.IsStr string ->
@@ -911,7 +911,7 @@ generateCaseValue mode test =
911 case test of
911 case test of
912 DT.IsCtor name index _ _ ->
912 DT.IsCtor name index _ _ ->
913 case mode of
913 case mode of
914− Name.Dev _ -> JS.String (N.toBuilder name)
914+ Name.Dev _ _ -> JS.String (N.toBuilder name)
915 Name.Prod _ _ -> JS.Int (Index.toMachine index)
915 Name.Prod _ _ -> JS.Int (Index.toMachine index)
916
916
917 DT.IsInt int ->
917 DT.IsInt int ->
@@ -941,7 +941,7 @@ generateCaseTest mode root path exampleTest =
941 case exampleTest of
941 case exampleTest of
942 DT.IsCtor _ _ _ opts ->
942 DT.IsCtor _ _ _ opts ->
943 case mode of
943 case mode of
944− Name.Dev _ ->
944+ Name.Dev _ _ ->
945 JS.Access value Name.dollar
945 JS.Access value Name.dollar
946
946
947 Name.Prod _ _ ->
947 Name.Prod _ _ ->
@@ -963,7 +963,7 @@ generateCaseTest mode root path exampleTest =
963
963
964 DT.IsChr _ ->
964 DT.IsChr _ ->
965 case mode of
965 case mode of
966− Name.Dev _ ->
966+ Name.Dev _ _ ->
967 JS.Call (JS.Access value (Name.fromLocal "valueOf")) []
967 JS.Call (JS.Access value (Name.fromLocal "valueOf")) []
968
968
969 Name.Prod _ _ ->
969 Name.Prod _ _ ->
@@ -991,7 +991,7 @@ pathToJsExpr mode root path =
991
991
992 DT.Unbox subPath ->
992 DT.Unbox subPath ->
993 case mode of
993 case mode of
994− Name.Dev _ ->
994+ Name.Dev _ _ ->
995 JS.Access (pathToJsExpr mode root subPath) (Name.fromIndex Index.first)
995 JS.Access (pathToJsExpr mode root subPath) (Name.fromIndex Index.first)
996
996
997 Name.Prod _ _ ->
997 Name.Prod _ _ ->
@@ -1031,8 +1031,13 @@ toDebugMetadata mode interfaces msgType =
1031 Name.Prod _ _ ->
1031 Name.Prod _ _ ->
1032 JS.Int 0
1032 JS.Int 0
1033
1033
1034− Name.Dev _ ->
1034+ Name.Dev _ debugger ->
1035+ case debugger of
1036+ Name.DebuggerOff ->
1037+ JS.Int 0
1038+
1039+ Name.DebuggerOn ->
1035− JS.Json $ Encode.object $
1040+ JS.Json $ Encode.object $
1036− [ ("versions", Encode.object [ ("elm", Pkg.encodeVersion Version.version) ])
1041+ [ ("versions", Encode.object [ ("elm", Pkg.encodeVersion Version.version) ])
1037− , ("types", Type.encodeMetadata (Extract.fromMsg interfaces msgType))
1042+ , ("types", Type.encodeMetadata (Extract.fromMsg interfaces msgType))
1038− ]
1043+ ]
compiler/src/Generate/JavaScript/Name.hs+9−3
@@ -4,6 +4,7 @@ module Generate.JavaScript.Name
4 ( Name
4 ( Name
5 , Mode(..)
5 , Mode(..)
6 , Target(..)
6 , Target(..)
7+ , Debugger(..)
7 , isServer
8 , isServer
8 , toBuilder
9 , toBuilder
9 , fromIndex
10 , fromIndex
@@ -53,13 +54,18 @@ newtype Name =
53
54
54
55
55data Mode
56data Mode
56− = Dev Target
57+ = Dev Target Debugger
57 | Prod Target ShortFieldNames
58 | Prod Target ShortFieldNames
58
59
59
60
60data Target = Client | Server
61data Target = Client | Server
61
62
62
63
64+data Debugger
65+ = DebuggerOn
66+ | DebuggerOff
67+
68+
63type ShortFieldNames =
69type ShortFieldNames =
64 Map.Map N.Name Name
70 Map.Map N.Name Name
65
71
@@ -67,7 +73,7 @@ type ShortFieldNames =
67isServer :: Mode -> Bool
73isServer :: Mode -> Bool
68isServer mode =
74isServer mode =
69 case mode of
75 case mode of
70− Dev target -> isServerHelp target
76+ Dev target _ -> isServerHelp target
71 Prod target _ -> isServerHelp target
77 Prod target _ -> isServerHelp target
72
78
73
79
@@ -124,7 +130,7 @@ fromKernel home name =
124fromField :: Mode -> N.Name -> Name
130fromField :: Mode -> N.Name -> Name
125fromField mode name =
131fromField mode name =
126 case mode of
132 case mode of
127− Dev _ ->
133+ Dev _ _ ->
128 Name (N.toBuilder name)
134 Name (N.toBuilder name)
129
135
130 Prod _ fields ->
136 Prod _ fields ->
elm.cabal+1
@@ -117,6 +117,7 @@ Executable elm
117 Reporting.Exit.Diff,
117 Reporting.Exit.Diff,
118 Reporting.Exit.Help,
118 Reporting.Exit.Help,
119 Reporting.Exit.Http,
119 Reporting.Exit.Http,
120+ Reporting.Exit.Make,
120 Reporting.Exit.Publish,
121 Reporting.Exit.Publish,
121 Reporting.Progress,
122 Reporting.Progress,
122 Reporting.Progress.Bar,
123 Reporting.Progress.Bar,
ui/terminal/src/Main.hs+1
@@ -173,6 +173,7 @@ make =
173
173
174 makeFlags =
174 makeFlags =
175 flags Make.Flags
175 flags Make.Flags
176+ |-- onOff "debug" "Turn on the time-travelling debugger. It allows you to rewind and replay events. The events can be imported/exported into a file, which makes for very precise bug reports!"
176 |-- onOff "optimize" "Turn on optimizations to make code smaller and faster. For example, the compiler renames record fields to be as short as possible and unboxes values to reduce allocation."
177 |-- onOff "optimize" "Turn on optimizations to make code smaller and faster. For example, the compiler renames record fields to be as short as possible and unboxes values to reduce allocation."
177 |-- flag "output" Output.output "Specify the name of the resulting JS file. For example --output=assets/elm.js to generate the JS at assets/elm.js or --output=/dev/null to generate no output at all!"
178 |-- flag "output" Output.output "Specify the name of the resulting JS file. For example --output=assets/elm.js to generate the JS at assets/elm.js or --output=/dev/null to generate no output at all!"
178 |-- flag "report" Make.reportType "You can say --report=json to get error messages as JSON. This is only really useful if you are an editor plugin. Humans should avoid it!"
179 |-- flag "report" Make.reportType "You can say --report=json to get error messages as JSON. This is only really useful if you are an editor plugin. Humans should avoid it!"
ui/terminal/src/Make.hs+27−17
@@ -14,7 +14,10 @@ import qualified System.FilePath as FP
14import qualified Elm.Compiler.Objects as Obj
14import qualified Elm.Compiler.Objects as Obj
15import qualified Elm.Project as Project
15import qualified Elm.Project as Project
16import qualified Generate.Output as Output
16import qualified Generate.Output as Output
17+import qualified Reporting.Exit as Exit
18+import qualified Reporting.Exit.Make as E
17import qualified Reporting.Task as Task
19import qualified Reporting.Task as Task
20+import qualified Reporting.Progress as Progress
18import qualified Reporting.Progress.Json as Json
21import qualified Reporting.Progress.Json as Json
19import qualified Reporting.Progress.Terminal as Terminal
22import qualified Reporting.Progress.Terminal as Terminal
20import Terminal.Args (Parser(..), suggestFiles)
23import Terminal.Args (Parser(..), suggestFiles)
@@ -26,7 +29,8 @@ import Terminal.Args (Parser(..), suggestFiles)
26
29
27data Flags =
30data Flags =
28 Flags
31 Flags
32+ { _debug :: Bool
29− { _optimize :: Bool
33+ , _optimize :: Bool
30 , _output :: Maybe Output.Output
34 , _output :: Maybe Output.Output
31 , _report :: Maybe ReportType
35 , _report :: Maybe ReportType
32 , _docs :: Maybe FilePath
36 , _docs :: Maybe FilePath
@@ -34,23 +38,29 @@ data Flags =
34
38
35
39
36run :: [FilePath] -> Flags -> IO ()
40run :: [FilePath] -> Flags -> IO ()
37−run paths (Flags optimize output report docs) =
41+run paths (Flags debug optimize output report docs) =
38− let
39− mode =
40− if optimize then Obj.Prod else Obj.Dev
41−
42− outputOptions =
43− Output.Options mode Obj.Client output
44−
45− makeReporter =
46− case report of
47− Nothing -> Terminal.create
48− Just Json -> return Json.reporter
49− in
50− do reporter <- makeReporter
42+ do reporter <- toReporter report
51 void $ Task.run reporter $
43 void $ Task.run reporter $
44+ do mode <- toMode debug optimize
52− do summary <- Project.getRoot
45+ summary <- Project.getRoot
46+ let options = Output.Options mode Obj.Client output
53− Project.compile outputOptions docs summary paths
47+ Project.compile options docs summary paths
48+
49+
50+toMode :: Bool -> Bool -> Task.Task Obj.Mode
51+toMode debug optimize =
52+ case (debug, optimize) of
53+ (True , True ) -> Task.throw $ Exit.Make E.CannotOptimizeAndDebug
54+ (False, True ) -> return Obj.Prod
55+ (False, False) -> return Obj.Dev
56+ (True , False) -> return Obj.Debug
57+
58+
59+toReporter :: Maybe ReportType -> IO Progress.Reporter
60+toReporter report =
61+ case report of
62+ Nothing -> Terminal.create
63+ Just Json -> return Json.reporter
54
64
55
65
56
66