Skip to content

Commit 181f348

Browse files
authored
Wingman: configurable auto search depth (#1771)
* Pass around the entire Config object instaed of just featureset * Make auto gas configurable
1 parent 1976ea2 commit 181f348

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
12
module Wingman.Auto where
23

4+
import Control.Monad.Reader.Class (asks)
35
import Control.Monad.State (gets)
46
import qualified Data.Set as S
57
import Refinery.Tactic
@@ -17,13 +19,14 @@ auto :: TacticsM ()
1719
auto = do
1820
jdg <- goal
1921
skolems <- gets ts_skolems
22+
gas <- asks $ cfg_auto_gas . ctxConfig
2023
current <- getCurrentDefinitions
2124
traceMX "goal" jdg
2225
traceMX "ctx" current
2326
traceMX "skolems" skolems
2427
commit knownStrategies
2528
. tracing "auto"
26-
. localTactic (auto' 4)
29+
. localTactic (auto' gas)
2730
. disallowing RecursiveCall
2831
. S.fromList
2932
$ fmap fst current

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,26 @@ import OccName
1313
import TcRnTypes
1414
import TcType (tcSplitTyConApp, tcSplitPhiTy)
1515
import TysPrim (alphaTys)
16-
import Wingman.FeatureSet (FeatureSet)
1716
import Wingman.Judgements.Theta
1817
import Wingman.Types
1918

2019

2120
mkContext
22-
:: FeatureSet
21+
:: Config
2322
-> [(OccName, CType)]
2423
-> TcGblEnv
2524
-> ExternalPackageState
2625
-> KnownThings
2726
-> [Evidence]
2827
-> Context
29-
mkContext features locals tcg eps kt ev = Context
28+
mkContext cfg locals tcg eps kt ev = Context
3029
{ ctxDefiningFuncs = locals
3130
, ctxModuleFuncs = fmap splitId
3231
. (getFunBindId =<<)
3332
. fmap unLoc
3433
. bagToList
3534
$ tcg_binds tcg
36-
, ctxFeatureSet = features
35+
, ctxConfig = cfg
3736
, ctxInstEnvs =
3837
InstEnvs
3938
(eps_inst_env eps)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ knownStrategies = choice
2929
-- | Guard a tactic behind a feature.
3030
featureGuard :: Feature -> TacticsM a -> TacticsM a
3131
featureGuard feat t = do
32-
fs <- asks ctxFeatureSet
32+
fs <- asks $ cfg_feature_set . ctxConfig
3333
case hasFeature feat fs of
3434
True -> t
3535
False -> empty

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ properties :: Properties
131131
, 'PropertyKey "max_use_ctor_actions" 'TInteger
132132
, 'PropertyKey "features" 'TString
133133
, 'PropertyKey "timeout_duration" 'TInteger
134+
, 'PropertyKey "auto_gas" 'TInteger
134135
]
135136
properties = emptyProperties
137+
& defineIntegerProperty #auto_gas
138+
"The depth of the search tree when performing \"Attempt to fill hole\". Bigger values will be able to derive more solutions, but will take exponentially more time." 4
136139
& defineIntegerProperty #timeout_duration
137140
"The timeout for Wingman actions, in seconds" 2
138141
& defineStringProperty #features
@@ -157,6 +160,7 @@ getTacticConfig pId =
157160
<$> (parseFeatureSet <$> usePropertyLsp #features pId properties)
158161
<*> usePropertyLsp #max_use_ctor_actions pId properties
159162
<*> usePropertyLsp #timeout_duration pId properties
163+
<*> usePropertyLsp #auto_gas pId properties
160164

161165
------------------------------------------------------------------------------
162166
-- | Get the current feature set from the plugin config.
@@ -182,9 +186,9 @@ judgementForHole
182186
:: IdeState
183187
-> NormalizedFilePath
184188
-> Tracked 'Current Range
185-
-> FeatureSet
189+
-> Config
186190
-> MaybeT IO (Tracked 'Current Range, Judgement, Context, DynFlags)
187-
judgementForHole state nfp range features = do
191+
judgementForHole state nfp range cfg = do
188192
let stale a = runStaleIde "judgementForHole" state nfp a
189193

190194
TrackedStale asts amapping <- stale GetHieAst
@@ -206,28 +210,28 @@ judgementForHole state nfp range features = do
206210
eps <- liftIO $ readIORef $ hsc_EPS $ hscEnv henv
207211
kt <- knownThings (untrackedStaleValue tcg) henv
208212

209-
(jdg, ctx) <- liftMaybe $ mkJudgementAndContext features g binds new_rss tcg eps kt
213+
(jdg, ctx) <- liftMaybe $ mkJudgementAndContext cfg g binds new_rss tcg eps kt
210214

211215
dflags <- getIdeDynflags state nfp
212216
pure (fmap realSrcSpanToRange new_rss, jdg, ctx, dflags)
213217

214218

215219

216220
mkJudgementAndContext
217-
:: FeatureSet
221+
:: Config
218222
-> Type
219223
-> TrackedStale Bindings
220224
-> Tracked 'Current RealSrcSpan
221225
-> TrackedStale TcGblEnv
222226
-> ExternalPackageState
223227
-> KnownThings
224228
-> Maybe (Judgement, Context)
225-
mkJudgementAndContext features g (TrackedStale binds bmap) rss (TrackedStale tcg tcgmap) eps kt = do
229+
mkJudgementAndContext cfg g (TrackedStale binds bmap) rss (TrackedStale tcg tcgmap) eps kt = do
226230
binds_rss <- mapAgeFrom bmap rss
227231
tcg_rss <- mapAgeFrom tcgmap rss
228232

229233
let tcs = fmap tcg_binds tcg
230-
ctx = mkContext features
234+
ctx = mkContext cfg
231235
(mapMaybe (sequenceA . (occName *** coerce))
232236
$ unTrack
233237
$ getDefiningBindings <$> binds <*> binds_rss)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ codeActionProvider state plId (CodeActionParams _ _ (TextDocumentIdentifier uri)
7070
| Just nfp <- uriToNormalizedFilePath $ toNormalizedUri uri = do
7171
cfg <- getTacticConfig plId
7272
liftIO $ fromMaybeT (Right $ List []) $ do
73-
(_, jdg, _, dflags) <- judgementForHole state nfp range $ cfg_feature_set cfg
73+
(_, jdg, _, dflags) <- judgementForHole state nfp range cfg
7474
actions <- lift $
7575
-- This foldMap is over the function monoid.
7676
foldMap commandProvider [minBound .. maxBound] $ TacticProviderData
@@ -99,11 +99,10 @@ tacticCmd tac pId state (TacticParams uri range var_name)
9999
| Just nfp <- uriToNormalizedFilePath $ toNormalizedUri uri = do
100100
let stale a = runStaleIde "tacticCmd" state nfp a
101101

102-
features <- getFeatureSet pId
103102
ccs <- getClientCapabilities
104103
cfg <- getTacticConfig pId
105104
res <- liftIO $ runMaybeT $ do
106-
(range', jdg, ctx, dflags) <- judgementForHole state nfp range features
105+
(range', jdg, ctx, dflags) <- judgementForHole state nfp range cfg
107106
let span = fmap (rangeToRealSrcSpan (fromNormalizedFilePath nfp)) range'
108107
TrackedStale pm pmmap <- stale GetAnnotatedParsedSource
109108
pm_span <- liftMaybe $ mapAgeFrom pmmap span

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ data Config = Config
8080
{ cfg_feature_set :: FeatureSet
8181
, cfg_max_use_ctor_actions :: Int
8282
, cfg_timeout_seconds :: Int
83+
, cfg_auto_gas :: Int
84+
}
85+
deriving (Eq, Ord, Show)
86+
87+
emptyConfig :: Config
88+
emptyConfig = Config
89+
{ cfg_feature_set = mempty
90+
, cfg_max_use_ctor_actions = 5
91+
, cfg_timeout_seconds = 2
92+
, cfg_auto_gas = 4
8393
}
8494

8595
------------------------------------------------------------------------------
@@ -398,7 +408,7 @@ data Context = Context
398408
-- ^ The functions currently being defined
399409
, ctxModuleFuncs :: [(OccName, CType)]
400410
-- ^ Everything defined in the current module
401-
, ctxFeatureSet :: FeatureSet
411+
, ctxConfig :: Config
402412
, ctxKnownThings :: KnownThings
403413
, ctxInstEnvs :: InstEnvs
404414
, ctxTheta :: Set CType
@@ -409,7 +419,7 @@ instance Show Context where
409419
[ "Context "
410420
, showsPrec 10 ctxDefiningFuncs ""
411421
, showsPrec 10 ctxModuleFuncs ""
412-
, showsPrec 10 ctxFeatureSet ""
422+
, showsPrec 10 ctxConfig ""
413423
, showsPrec 10 ctxTheta ""
414424
]
415425

@@ -429,7 +439,7 @@ emptyContext
429439
= Context
430440
{ ctxDefiningFuncs = mempty
431441
, ctxModuleFuncs = mempty
432-
, ctxFeatureSet = mempty
442+
, ctxConfig = emptyConfig
433443
, ctxKnownThings = error "empty known things from emptyContext"
434444
, ctxInstEnvs = InstEnvs mempty mempty mempty
435445
, ctxTheta = mempty

0 commit comments

Comments
 (0)