Skip to content

Commit 7a41ab7

Browse files
isovectorjneira
andauthored
Wingman: Low gas warning (#2038)
* Simplify TacticError * OutOfGas machinery * Not enough gas test Co-authored-by: Javier Neira <[email protected]>
1 parent 897109e commit 7a41ab7

File tree

7 files changed

+37
-35
lines changed

7 files changed

+37
-35
lines changed

plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs

+1
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ isRhsHole (unTrack -> rss) (unTrack -> tcs) =
485485

486486

487487
ufmSeverity :: UserFacingMessage -> MessageType
488+
ufmSeverity NotEnoughGas = MtInfo
488489
ufmSeverity TacticErrors = MtError
489490
ufmSeverity TimedOut = MtInfo
490491
ufmSeverity NothingToDo = MtInfo

plugins/hls-tactics-plugin/src/Wingman/Machinery.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ unify goal inst = do
225225
case tryUnifyUnivarsButNotSkolems skolems goal inst of
226226
Just subst ->
227227
modify $ updateSubst subst
228-
Nothing -> cut -- failure (UnificationError inst goal)
228+
Nothing -> cut
229229

230230
cut :: RuleT jdg ext err s m a
231231
cut = RuleT Empty

plugins/hls-tactics-plugin/src/Wingman/Plugin.hs

+7-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ showUserFacingMessage ufm = do
100100
pure $ Left $ mkErr InternalError $ T.pack $ show ufm
101101

102102

103+
mkUserFacingMessage :: [TacticError] -> UserFacingMessage
104+
mkUserFacingMessage errs
105+
| elem OutOfGas errs = NotEnoughGas
106+
mkUserFacingMessage _ = TacticErrors
107+
108+
103109
tacticCmd
104110
:: (T.Text -> TacticsM ())
105111
-> PluginId
@@ -122,7 +128,7 @@ tacticCmd tac pId state (TacticParams uri range var_name)
122128
pure $ join $ case res of
123129
Left errs -> do
124130
traceMX "errs" errs
125-
Left TacticErrors
131+
Left $ mkUserFacingMessage errs
126132
Right rtr ->
127133
case rtr_extract rtr of
128134
L _ (HsVar _ (L _ rdr)) | isHole (occName rdr) ->

plugins/hls-tactics-plugin/src/Wingman/Tactics.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ assume name = rule $ \jdg -> do
6565
{ syn_trace = tracePrim $ "assume " <> occNameString name
6666
, syn_used_vals = S.singleton name
6767
}
68-
Nothing -> cut -- failure $ UndefinedHypothesis name
68+
Nothing -> cut
6969

7070

7171
------------------------------------------------------------------------------
@@ -432,7 +432,7 @@ refine = intros <%> splitSingle
432432

433433

434434
auto' :: Int -> TacticsM ()
435-
auto' 0 = failure NoProgress
435+
auto' 0 = failure OutOfGas
436436
auto' n = do
437437
let loop = auto' (n - 1)
438438
try intros

plugins/hls-tactics-plugin/src/Wingman/Types.hs

+10-29
Original file line numberDiff line numberDiff line change
@@ -361,61 +361,40 @@ instance MetaSubst Int (Synthesized (LHsExpr GhcPs)) where
361361
------------------------------------------------------------------------------
362362
-- | Reasons a tactic might fail.
363363
data TacticError
364-
= UndefinedHypothesis OccName
364+
= OutOfGas
365365
| GoalMismatch String CType
366-
| UnsolvedSubgoals [Judgement]
367-
| UnificationError CType CType
368366
| NoProgress
369367
| NoApplicableTactic
370-
| IncorrectDataCon DataCon
371-
| RecursionOnWrongParam OccName Int OccName
372368
| UnhelpfulRecursion
373369
| UnhelpfulDestruct OccName
374-
| UnhelpfulSplit OccName
375370
| TooPolymorphic
376371
| NotInScope OccName
377372
| TacticPanic String
373+
deriving (Eq)
378374

379375
instance Show TacticError where
380-
show (UndefinedHypothesis name) =
381-
occNameString name <> " is not available in the hypothesis."
376+
show OutOfGas = "Auto ran out of gas"
382377
show (GoalMismatch tac (CType typ)) =
383378
mconcat
384379
[ "The tactic "
385380
, tac
386381
, " doesn't apply to goal type "
387382
, unsafeRender typ
388383
]
389-
show (UnsolvedSubgoals _) =
390-
"There were unsolved subgoals"
391-
show (UnificationError (CType t1) (CType t2)) =
392-
mconcat
393-
[ "Could not unify "
394-
, unsafeRender t1
395-
, " and "
396-
, unsafeRender t2
397-
]
398384
show NoProgress =
399385
"Unable to make progress"
400386
show NoApplicableTactic =
401387
"No tactic could be applied"
402-
show (IncorrectDataCon dcon) =
403-
"Data con doesn't align with goal type (" <> unsafeRender dcon <> ")"
404-
show (RecursionOnWrongParam call p arg) =
405-
"Recursion on wrong param (" <> show call <> ") on arg"
406-
<> show p <> ": " <> show arg
407388
show UnhelpfulRecursion =
408389
"Recursion wasn't productive"
409390
show (UnhelpfulDestruct n) =
410391
"Destructing patval " <> show n <> " leads to no new types"
411-
show (UnhelpfulSplit n) =
412-
"Splitting constructor " <> show n <> " leads to no new goals"
413392
show TooPolymorphic =
414393
"The tactic isn't applicable because the goal is too polymorphic"
415394
show (NotInScope name) =
416395
"Tried to do something with the out of scope name " <> show name
417396
show (TacticPanic err) =
418-
"PANIC: " <> err
397+
"Tactic panic: " <> err
419398

420399

421400
------------------------------------------------------------------------------
@@ -560,16 +539,18 @@ data AgdaMatch = AgdaMatch
560539

561540

562541
data UserFacingMessage
563-
= TacticErrors
542+
= NotEnoughGas
543+
| TacticErrors
564544
| TimedOut
565545
| NothingToDo
566546
| InfrastructureError Text
567547
deriving Eq
568548

569549
instance Show UserFacingMessage where
570-
show TacticErrors = "Wingman couldn't find a solution"
571-
show TimedOut = "Wingman timed out while trying to find a solution"
572-
show NothingToDo = "Nothing to do"
550+
show NotEnoughGas = "Wingman ran out of gas when trying to find a solution. \nTry increasing the `auto_gas` setting."
551+
show TacticErrors = "Wingman couldn't find a solution"
552+
show TimedOut = "Wingman timed out while trying to find a solution"
553+
show NothingToDo = "Nothing to do"
573554
show (InfrastructureError t) = "Internal error: " <> T.unpack t
574555

575556

plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ spec = do
8383

8484

8585
describe "messages" $ do
86-
mkShowMessageTest Auto "" 2 8 "MessageForallA" TacticErrors
87-
mkShowMessageTest Auto "" 7 8 "MessageCantUnify" TacticErrors
86+
mkShowMessageTest Auto "" 2 8 "MessageForallA" TacticErrors
87+
mkShowMessageTest Auto "" 7 8 "MessageCantUnify" TacticErrors
88+
mkShowMessageTest Auto "" 12 8 "MessageNotEnoughGas" NotEnoughGas
8889

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test
2+
:: (a1 -> a2)
3+
-> (a2 -> a3)
4+
-> (a3 -> a4)
5+
-> (a4 -> a5)
6+
-> (a5 -> a6)
7+
-> (a6 -> a7)
8+
-> (a7 -> a8)
9+
-> (a8 -> a9)
10+
-> (a9 -> a10)
11+
-> a1 -> a10
12+
test = _
13+

0 commit comments

Comments
 (0)