@@ -9,6 +9,7 @@ import Unison.ABT qualified as ABT
9
9
import Unison.Builtin.Decls (tupleTerm , pattern TupleTerm' )
10
10
import Unison.Codebase.CodeLookup qualified as CL
11
11
import Unison.Codebase.CodeLookup.Util qualified as CL
12
+ import Unison.Codebase.Runtime.Profile
12
13
import Unison.Hashing.V2.Convert qualified as Hashing
13
14
import Unison.Parser.Ann (Ann )
14
15
import Unison.Prelude
@@ -27,6 +28,22 @@ import Unison.WatchKind qualified as WK
27
28
28
29
type Error = P. Pretty P. ColorText
29
30
31
+ data Response
32
+ = DecompErrs [Error ]
33
+ | Profile (P. Pretty P. ColorText )
34
+ | EmptyResponse
35
+
36
+ instance Semigroup Response where
37
+ DecompErrs l <> DecompErrs r = DecompErrs (l <> r)
38
+ d@ (DecompErrs _) <> _ = d
39
+ _ <> d@ (DecompErrs _) = d
40
+ p@ (Profile _) <> _ = p
41
+ _ <> p@ (Profile _) = p
42
+ EmptyResponse <> r = r
43
+
44
+ instance Monoid Response where
45
+ mempty = EmptyResponse
46
+
30
47
type Term v = Term. Term v ()
31
48
32
49
data CompileOpts = COpts
@@ -41,8 +58,9 @@ data Runtime v = Runtime
41
58
evaluate ::
42
59
CL. CodeLookup v IO () ->
43
60
PPE. PrettyPrintEnv ->
61
+ ProfileSpec ->
44
62
Term v ->
45
- IO (Either Error ([ Error ] , Term v )),
63
+ IO (Either Error (Response , Term v )),
46
64
compileTo ::
47
65
CompileOpts ->
48
66
CL. CodeLookup v IO () ->
@@ -65,7 +83,7 @@ type WatchResults v a =
65
83
-- Bindings:
66
84
( [(v , Term v )],
67
85
-- Map watchName (loc, hash, expression, value, isHit)
68
- [ Error ] ,
86
+ Response ,
69
87
Map v (a , WatchKind , Reference. Id , Term v , Term v , IsCacheHit )
70
88
)
71
89
)
@@ -83,11 +101,12 @@ evaluateWatches ::
83
101
(Var v ) =>
84
102
CL. CodeLookup v IO a ->
85
103
PPE. PrettyPrintEnv ->
104
+ ProfileSpec ->
86
105
(Reference. Id -> IO (Maybe (Term v ))) ->
87
106
Runtime v ->
88
107
TypecheckedUnisonFile v a ->
89
108
IO (WatchResults v a )
90
- evaluateWatches code ppe evaluationCache rt tuf = do
109
+ evaluateWatches code ppe prof evaluationCache rt tuf = do
91
110
-- 1. compute hashes for everything in the file
92
111
let m :: Map v (Reference. Id , Term. Term v a )
93
112
m = fmap (\ (_a, id , _wk, tm, _tp) -> (id , tm)) (UF. hashTermsId tuf)
@@ -113,7 +132,7 @@ evaluateWatches code ppe evaluationCache rt tuf = do
113
132
cl = void (CL. fromTypecheckedUnisonFile tuf) <> void code
114
133
-- 4. evaluate it and get all the results out of the tuple, then
115
134
-- create the result Map
116
- out <- evaluate rt cl ppe bigOl'LetRec
135
+ out <- evaluate rt cl ppe prof bigOl'LetRec
117
136
case out of
118
137
Right (errs, out) -> do
119
138
let (bindings, results) = case out of
@@ -150,21 +169,22 @@ evaluateTerm' ::
150
169
CL. CodeLookup v IO a ->
151
170
(Reference. Id -> IO (Maybe (Term v ))) ->
152
171
PPE. PrettyPrintEnv ->
172
+ ProfileSpec ->
153
173
Runtime v ->
154
174
Term. Term v a ->
155
- IO (Either Error ([ Error ] , Term v ))
156
- evaluateTerm' codeLookup cache ppe rt tm = do
175
+ IO (Either Error (Response , Term v ))
176
+ evaluateTerm' codeLookup cache ppe prof rt tm = do
157
177
result <- cache (Hashing. hashClosedTerm tm)
158
178
case result of
159
- Just r -> pure (Right ([] , r))
179
+ Just r -> pure (Right (EmptyResponse , r))
160
180
Nothing -> do
161
181
let tuf =
162
182
UF. typecheckedUnisonFile
163
183
mempty
164
184
mempty
165
185
mempty
166
186
[(WK. RegularWatch , [(Var. nameds " result" , mempty , tm, mempty <$> mainType rt)])]
167
- r <- evaluateWatches (void codeLookup) ppe cache rt (void tuf)
187
+ r <- evaluateWatches (void codeLookup) ppe prof cache rt (void tuf)
168
188
pure $
169
189
r <&> \ (_, errs, map ) ->
170
190
case Map. elems map of
@@ -175,7 +195,8 @@ evaluateTerm ::
175
195
(Var v , Monoid a ) =>
176
196
CL. CodeLookup v IO a ->
177
197
PPE. PrettyPrintEnv ->
198
+ ProfileSpec ->
178
199
Runtime v ->
179
200
Term. Term v a ->
180
- IO (Either Error ([ Error ] , Term v ))
201
+ IO (Either Error (Response , Term v ))
181
202
evaluateTerm codeLookup = evaluateTerm' codeLookup noCache
0 commit comments