Skip to content

Commit cea1d79

Browse files
Don't introduce too many variables (#1961)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 505f777 commit cea1d79

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Diff for: plugins/hls-tactics-plugin/src/Wingman/Tactics.hs

+9-7
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,23 @@ intros' names = rule $ \jdg -> do
127127
let g = jGoal jdg
128128
case tacticsSplitFunTy $ unCType g of
129129
(_, _, [], _) -> throwError $ GoalMismatch "intros" g
130-
(_, _, as, b) -> do
130+
(_, _, args, res) -> do
131131
ctx <- ask
132-
let vs = fromMaybe (mkManyGoodNames (hyNamesInScope $ jEntireHypothesis jdg) as) names
133-
num_args = length vs
132+
let occs = fromMaybe (mkManyGoodNames (hyNamesInScope $ jEntireHypothesis jdg) args) names
133+
num_occs = length occs
134134
top_hole = isTopHole ctx jdg
135-
hy' = lambdaHypothesis top_hole $ zip vs $ coerce as
135+
bindings = zip occs $ coerce args
136+
bound_occs = fmap fst bindings
137+
hy' = lambdaHypothesis top_hole bindings
136138
jdg' = introduce ctx hy'
137-
$ withNewGoal (CType $ mkFunTys' (drop num_args as) b) jdg
139+
$ withNewGoal (CType $ mkFunTys' (drop num_occs args) res) jdg
138140
ext <- newSubgoal jdg'
139141
pure $
140142
ext
141-
& #syn_trace %~ rose ("intros {" <> intercalate ", " (fmap show vs) <> "}")
143+
& #syn_trace %~ rose ("intros {" <> intercalate ", " (fmap show bound_occs) <> "}")
142144
. pure
143145
& #syn_scoped <>~ hy'
144-
& #syn_val %~ noLoc . lambda (fmap bvar' vs) . unLoc
146+
& #syn_val %~ noLoc . lambda (fmap bvar' bound_occs) . unLoc
145147

146148

147149
------------------------------------------------------------------------------

Diff for: plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs

+1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ spec = do
3838
metaTest 4 28 "MetaUseSymbol"
3939
metaTest 7 53 "MetaDeepOf"
4040
metaTest 2 34 "MetaWithArg"
41+
metaTest 2 12 "IntrosTooMany"
4142

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
too_many :: a -> b -> c
2+
too_many a b = _
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
too_many :: a -> b -> c
2+
too_many = [wingman| intros a b c d e f g h i j k l m n o p q r s t u v w x y z |]

0 commit comments

Comments
 (0)