Skip to content

Commit

Permalink
Don't introduce too many variables (haskell#1961)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and jneira committed Jun 25, 2021
1 parent a566d91 commit 80ecf98
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
16 changes: 9 additions & 7 deletions plugins/hls-tactics-plugin/src/Wingman/Tactics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,23 @@ intros' names = rule $ \jdg -> do
let g = jGoal jdg
case tacticsSplitFunTy $ unCType g of
(_, _, [], _) -> throwError $ GoalMismatch "intros" g
(_, _, as, b) -> do
(_, _, args, res) -> do
ctx <- ask
let vs = fromMaybe (mkManyGoodNames (hyNamesInScope $ jEntireHypothesis jdg) as) names
num_args = length vs
let occs = fromMaybe (mkManyGoodNames (hyNamesInScope $ jEntireHypothesis jdg) args) names
num_occs = length occs
top_hole = isTopHole ctx jdg
hy' = lambdaHypothesis top_hole $ zip vs $ coerce as
bindings = zip occs $ coerce args
bound_occs = fmap fst bindings
hy' = lambdaHypothesis top_hole bindings
jdg' = introduce ctx hy'
$ withNewGoal (CType $ mkFunTys' (drop num_args as) b) jdg
$ withNewGoal (CType $ mkFunTys' (drop num_occs args) res) jdg
ext <- newSubgoal jdg'
pure $
ext
& #syn_trace %~ rose ("intros {" <> intercalate ", " (fmap show vs) <> "}")
& #syn_trace %~ rose ("intros {" <> intercalate ", " (fmap show bound_occs) <> "}")
. pure
& #syn_scoped <>~ hy'
& #syn_val %~ noLoc . lambda (fmap bvar' vs) . unLoc
& #syn_val %~ noLoc . lambda (fmap bvar' bound_occs) . unLoc


------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ spec = do
metaTest 4 28 "MetaUseSymbol"
metaTest 7 53 "MetaDeepOf"
metaTest 2 34 "MetaWithArg"
metaTest 2 12 "IntrosTooMany"

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
too_many :: a -> b -> c
too_many a b = _
2 changes: 2 additions & 0 deletions plugins/hls-tactics-plugin/test/golden/IntrosTooMany.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
too_many :: a -> b -> c
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 comments on commit 80ecf98

Please sign in to comment.