Skip to content

Wingman: Low gas warning #2038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ isRhsHole (unTrack -> rss) (unTrack -> tcs) =


ufmSeverity :: UserFacingMessage -> MessageType
ufmSeverity NotEnoughGas = MtInfo
ufmSeverity TacticErrors = MtError
ufmSeverity TimedOut = MtInfo
ufmSeverity NothingToDo = MtInfo
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-tactics-plugin/src/Wingman/Machinery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ unify goal inst = do
case tryUnifyUnivarsButNotSkolems skolems goal inst of
Just subst ->
modify $ updateSubst subst
Nothing -> cut -- failure (UnificationError inst goal)
Nothing -> cut

cut :: RuleT jdg ext err s m a
cut = RuleT Empty
Expand Down
8 changes: 7 additions & 1 deletion plugins/hls-tactics-plugin/src/Wingman/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ showUserFacingMessage ufm = do
pure $ Left $ mkErr InternalError $ T.pack $ show ufm


mkUserFacingMessage :: [TacticError] -> UserFacingMessage
mkUserFacingMessage errs
| elem OutOfGas errs = NotEnoughGas
mkUserFacingMessage _ = TacticErrors


tacticCmd
:: (T.Text -> TacticsM ())
-> PluginId
Expand All @@ -122,7 +128,7 @@ tacticCmd tac pId state (TacticParams uri range var_name)
pure $ join $ case res of
Left errs -> do
traceMX "errs" errs
Left TacticErrors
Left $ mkUserFacingMessage errs
Right rtr ->
case rtr_extract rtr of
L _ (HsVar _ (L _ rdr)) | isHole (occName rdr) ->
Expand Down
4 changes: 2 additions & 2 deletions plugins/hls-tactics-plugin/src/Wingman/Tactics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ assume name = rule $ \jdg -> do
{ syn_trace = tracePrim $ "assume " <> occNameString name
, syn_used_vals = S.singleton name
}
Nothing -> cut -- failure $ UndefinedHypothesis name
Nothing -> cut


------------------------------------------------------------------------------
Expand Down Expand Up @@ -432,7 +432,7 @@ refine = intros <%> splitSingle


auto' :: Int -> TacticsM ()
auto' 0 = failure NoProgress
auto' 0 = failure OutOfGas
auto' n = do
let loop = auto' (n - 1)
try intros
Expand Down
39 changes: 10 additions & 29 deletions plugins/hls-tactics-plugin/src/Wingman/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -361,61 +361,40 @@ instance MetaSubst Int (Synthesized (LHsExpr GhcPs)) where
------------------------------------------------------------------------------
-- | Reasons a tactic might fail.
data TacticError
= UndefinedHypothesis OccName
= OutOfGas
| GoalMismatch String CType
| UnsolvedSubgoals [Judgement]
| UnificationError CType CType
| NoProgress
| NoApplicableTactic
| IncorrectDataCon DataCon
| RecursionOnWrongParam OccName Int OccName
| UnhelpfulRecursion
| UnhelpfulDestruct OccName
| UnhelpfulSplit OccName
| TooPolymorphic
| NotInScope OccName
| TacticPanic String
deriving (Eq)

instance Show TacticError where
show (UndefinedHypothesis name) =
occNameString name <> " is not available in the hypothesis."
show OutOfGas = "Auto ran out of gas"
show (GoalMismatch tac (CType typ)) =
mconcat
[ "The tactic "
, tac
, " doesn't apply to goal type "
, unsafeRender typ
]
show (UnsolvedSubgoals _) =
"There were unsolved subgoals"
show (UnificationError (CType t1) (CType t2)) =
mconcat
[ "Could not unify "
, unsafeRender t1
, " and "
, unsafeRender t2
]
show NoProgress =
"Unable to make progress"
show NoApplicableTactic =
"No tactic could be applied"
show (IncorrectDataCon dcon) =
"Data con doesn't align with goal type (" <> unsafeRender dcon <> ")"
show (RecursionOnWrongParam call p arg) =
"Recursion on wrong param (" <> show call <> ") on arg"
<> show p <> ": " <> show arg
show UnhelpfulRecursion =
"Recursion wasn't productive"
show (UnhelpfulDestruct n) =
"Destructing patval " <> show n <> " leads to no new types"
show (UnhelpfulSplit n) =
"Splitting constructor " <> show n <> " leads to no new goals"
show TooPolymorphic =
"The tactic isn't applicable because the goal is too polymorphic"
show (NotInScope name) =
"Tried to do something with the out of scope name " <> show name
show (TacticPanic err) =
"PANIC: " <> err
"Tactic panic: " <> err


------------------------------------------------------------------------------
Expand Down Expand Up @@ -560,16 +539,18 @@ data AgdaMatch = AgdaMatch


data UserFacingMessage
= TacticErrors
= NotEnoughGas
| TacticErrors
| TimedOut
| NothingToDo
| InfrastructureError Text
deriving Eq

instance Show UserFacingMessage where
show TacticErrors = "Wingman couldn't find a solution"
show TimedOut = "Wingman timed out while trying to find a solution"
show NothingToDo = "Nothing to do"
show NotEnoughGas = "Wingman ran out of gas when trying to find a solution. \nTry increasing the `auto_gas` setting."
show TacticErrors = "Wingman couldn't find a solution"
show TimedOut = "Wingman timed out while trying to find a solution"
show NothingToDo = "Nothing to do"
show (InfrastructureError t) = "Internal error: " <> T.unpack t


Expand Down
5 changes: 3 additions & 2 deletions plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ spec = do


describe "messages" $ do
mkShowMessageTest Auto "" 2 8 "MessageForallA" TacticErrors
mkShowMessageTest Auto "" 7 8 "MessageCantUnify" TacticErrors
mkShowMessageTest Auto "" 2 8 "MessageForallA" TacticErrors
mkShowMessageTest Auto "" 7 8 "MessageCantUnify" TacticErrors
mkShowMessageTest Auto "" 12 8 "MessageNotEnoughGas" NotEnoughGas

13 changes: 13 additions & 0 deletions plugins/hls-tactics-plugin/test/golden/MessageNotEnoughGas.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test
:: (a1 -> a2)
-> (a2 -> a3)
-> (a3 -> a4)
-> (a4 -> a5)
-> (a5 -> a6)
-> (a6 -> a7)
-> (a7 -> a8)
-> (a8 -> a9)
-> (a9 -> a10)
-> a1 -> a10
test = _