From 1435ef8b2e041cbaefd5215afc4d038de2e214b2 Mon Sep 17 00:00:00 2001 From: Santiago Weight Date: Sun, 4 Dec 2022 22:53:29 -0800 Subject: [PATCH 1/2] wingman: Implement Sandy's simplify-wingman changes --- .../hls-tactics-plugin.cabal | 5 +- .../new/src/Wingman/AbstractLSP.hs | 3 +- .../src/Wingman/AbstractLSP/TacticActions.hs | 45 +- .../new/src/Wingman/Auto.hs | 32 -- .../new/src/Wingman/CodeGen.hs | 40 +- .../new/src/Wingman/Context.hs | 112 ---- .../hls-tactics-plugin/new/src/Wingman/GHC.hs | 35 -- .../new/src/Wingman/Judgements.hs | 84 +-- .../new/src/Wingman/Judgements/SYB.hs | 27 +- .../new/src/Wingman/Judgements/Theta.hs | 235 -------- .../new/src/Wingman/KnownStrategies.hs | 82 --- .../src/Wingman/KnownStrategies/QuickCheck.hs | 109 ---- .../new/src/Wingman/LanguageServer.hs | 133 +---- .../src/Wingman/LanguageServer/Metaprogram.hs | 59 --- .../Wingman/LanguageServer/TacticProviders.hs | 44 +- .../new/src/Wingman/Machinery.hs | 193 +------ .../new/src/Wingman/Metaprogramming/Lexer.hs | 99 ---- .../new/src/Wingman/Metaprogramming/Parser.hs | 501 ------------------ .../Wingman/Metaprogramming/Parser.hs-boot | 7 - .../Metaprogramming/Parser/Documentation.hs | 237 --------- .../src/Wingman/Metaprogramming/ProofState.hs | 117 ---- .../new/src/Wingman/Plugin.hs | 11 +- .../new/src/Wingman/StaticPlugin.hs | 84 +-- .../new/src/Wingman/Tactics.hs | 499 +---------------- .../new/src/Wingman/Types.hs | 137 +---- .../new/test/AutoTupleSpec.hs | 57 -- .../new/test/CodeAction/AutoSpec.hs | 92 ---- .../new/test/CodeAction/DestructAllSpec.hs | 1 - .../new/test/CodeAction/DestructSpec.hs | 3 - .../new/test/CodeAction/RunMetaprogramSpec.hs | 43 -- .../new/test/ProviderSpec.hs | 1 - plugins/hls-tactics-plugin/new/test/Utils.hs | 2 +- .../test/golden/AutoEmptyString.expected.hs | 2 - .../new/test/golden/AutoEmptyString.hs | 2 - .../new/test/golden/AutoEndo.expected.hs | 11 - .../new/test/golden/AutoEndo.hs | 10 - .../golden/AutoForallClassMethod.expected.hs | 12 - .../new/test/golden/AutoForallClassMethod.hs | 12 - .../test/golden/AutoInfixApply.expected.hs | 3 - .../new/test/golden/AutoInfixApply.hs | 3 - .../golden/AutoInfixApplyMany.expected.hs | 3 - .../new/test/golden/AutoInfixApplyMany.hs | 3 - .../test/golden/AutoInfixInfix.expected.hs | 2 - .../new/test/golden/AutoInfixInfix.hs | 2 - .../new/test/golden/AutoPatSynUse.expected.hs | 8 - .../new/test/golden/AutoPatSynUse.hs | 8 - .../new/test/golden/AutoSplitGADT.expected.hs | 12 - .../new/test/golden/AutoSplitGADT.hs | 12 - .../test/golden/AutoThetaEqCtx.expected.hs | 5 - .../new/test/golden/AutoThetaEqCtx.hs | 5 - .../test/golden/AutoThetaEqGADT.expected.hs | 7 - .../new/test/golden/AutoThetaEqGADT.hs | 7 - .../AutoThetaEqGADTDestruct.expected.hs | 8 - .../test/golden/AutoThetaEqGADTDestruct.hs | 8 - .../new/test/golden/AutoThetaFix.expected.hs | 13 - .../new/test/golden/AutoThetaFix.hs | 13 - .../new/test/golden/AutoThetaGADT.expected.hs | 7 - .../new/test/golden/AutoThetaGADT.hs | 7 - .../golden/AutoThetaGADTDestruct.expected.hs | 7 - .../new/test/golden/AutoThetaGADTDestruct.hs | 7 - .../AutoThetaMultipleUnification.expected.hs | 21 - .../golden/AutoThetaMultipleUnification.hs | 21 - .../test/golden/AutoThetaRankN.expected.hs | 8 - .../new/test/golden/AutoThetaRankN.hs | 8 - .../new/test/golden/AutoThetaRefl.expected.hs | 7 - .../new/test/golden/AutoThetaRefl.hs | 7 - .../golden/AutoThetaReflDestruct.expected.hs | 8 - .../new/test/golden/AutoThetaReflDestruct.hs | 8 - .../AutoThetaSplitUnification.expected.hs | 17 - .../test/golden/AutoThetaSplitUnification.hs | 17 - .../new/test/golden/AutoTypeLevel.expected.hs | 21 - .../new/test/golden/AutoTypeLevel.hs | 20 - .../golden/AutoUnusedPatternMatch.expected.hs | 2 - .../new/test/golden/AutoUnusedPatternMatch.hs | 2 - .../new/test/golden/AutoZip.expected.hs | 6 - .../new/test/golden/AutoZip.hs | 3 - .../DestructAllGADTEvidence.expected.hs | 21 - .../test/golden/DestructAllGADTEvidence.hs | 20 - .../test/golden/DestructDataFam.expected.hs | 8 - .../new/test/golden/DestructDataFam.hs | 8 - .../new/test/golden/DestructTyFam.expected.hs | 9 - .../new/test/golden/DestructTyFam.hs | 8 - .../golden/DestructTyToDataFam.expected.hs | 18 - .../new/test/golden/DestructTyToDataFam.hs | 18 - .../new/test/golden/Fgmap.expected.hs | 2 - .../new/test/golden/Fgmap.hs | 2 - .../new/test/golden/FmapBoth.expected.hs | 3 - .../new/test/golden/FmapBoth.hs | 3 - .../new/test/golden/FmapJoin.expected.hs | 2 - .../new/test/golden/FmapJoin.hs | 2 - .../new/test/golden/FmapJoinInLet.expected.hs | 4 - .../new/test/golden/FmapJoinInLet.hs | 4 - .../new/test/golden/GoldenApplicativeThen.hs | 2 - .../test/golden/GoldenArbitrary.expected.hs | 53 -- .../new/test/golden/GoldenArbitrary.hs | 26 - ...ldenArbitrarySingleConstructor.expected.hs | 7 - .../GoldenArbitrarySingleConstructor.hs | 6 - .../test/golden/GoldenBigTuple.expected.hs | 4 - .../new/test/golden/GoldenBigTuple.hs | 4 - .../test/golden/GoldenEitherAuto.expected.hs | 3 - .../new/test/golden/GoldenEitherAuto.hs | 2 - .../new/test/golden/GoldenFish.hs | 5 - .../test/golden/GoldenFmapTree.expected.hs | 5 - .../new/test/golden/GoldenFmapTree.hs | 4 - .../new/test/golden/GoldenFoldr.expected.hs | 3 - .../new/test/golden/GoldenFoldr.hs | 2 - .../test/golden/GoldenFromMaybe.expected.hs | 3 - .../new/test/golden/GoldenFromMaybe.hs | 2 - .../test/golden/GoldenGADTAuto.expected.hs | 7 - .../new/test/golden/GoldenGADTAuto.hs | 7 - .../test/golden/GoldenIdTypeFam.expected.hs | 7 - .../new/test/golden/GoldenIdTypeFam.hs | 7 - .../golden/GoldenIdentityFunctor.expected.hs | 3 - .../new/test/golden/GoldenIdentityFunctor.hs | 3 - .../test/golden/GoldenJoinCont.expected.hs | 4 - .../new/test/golden/GoldenJoinCont.hs | 4 - .../test/golden/GoldenListFmap.expected.hs | 3 - .../new/test/golden/GoldenListFmap.hs | 2 - .../new/test/golden/GoldenNote.expected.hs | 3 - .../new/test/golden/GoldenNote.hs | 2 - .../test/golden/GoldenPureList.expected.hs | 2 - .../new/test/golden/GoldenPureList.hs | 2 - .../test/golden/GoldenSafeHead.expected.hs | 3 - .../new/test/golden/GoldenSafeHead.hs | 2 - .../new/test/golden/GoldenShow.expected.hs | 2 - .../new/test/golden/GoldenShow.hs | 2 - .../test/golden/GoldenShowCompose.expected.hs | 2 - .../new/test/golden/GoldenShowCompose.hs | 2 - .../test/golden/GoldenShowMapChar.expected.hs | 2 - .../new/test/golden/GoldenShowMapChar.hs | 2 - .../test/golden/GoldenSuperclass.expected.hs | 8 - .../new/test/golden/GoldenSuperclass.hs | 8 - .../new/test/golden/GoldenSwap.expected.hs | 2 - .../new/test/golden/GoldenSwap.hs | 2 - .../test/golden/GoldenSwapMany.expected.hs | 2 - .../new/test/golden/GoldenSwapMany.hs | 2 - .../new/test/golden/IntrosTooMany.expected.hs | 2 - .../new/test/golden/IntrosTooMany.hs | 2 - .../test/golden/KnownBigSemigroup.expected.hs | 9 - .../new/test/golden/KnownBigSemigroup.hs | 7 - .../KnownCounterfactualSemigroup.expected.hs | 7 - .../golden/KnownCounterfactualSemigroup.hs | 7 - .../KnownDestructedSemigroup.expected.hs | 5 - .../test/golden/KnownDestructedSemigroup.hs | 5 - .../golden/KnownMissingMonoid.expected.hs | 8 - .../new/test/golden/KnownMissingMonoid.hs | 8 - .../golden/KnownMissingSemigroup.expected.hs | 5 - .../new/test/golden/KnownMissingSemigroup.hs | 5 - .../KnownModuleInstanceSemigroup.expected.hs | 12 - .../golden/KnownModuleInstanceSemigroup.hs | 11 - .../new/test/golden/KnownMonoid.expected.hs | 8 - .../new/test/golden/KnownMonoid.hs | 8 - .../test/golden/KnownPolyMonoid.expected.hs | 8 - .../new/test/golden/KnownPolyMonoid.hs | 8 - .../golden/KnownThetaSemigroup.expected.hs | 5 - .../new/test/golden/KnownThetaSemigroup.hs | 5 - .../new/test/golden/MetaBegin.expected.hs | 1 - .../new/test/golden/MetaBegin.hs | 1 - .../golden/MetaBeginNoWildify.expected.hs | 2 - .../new/test/golden/MetaBeginNoWildify.hs | 2 - .../new/test/golden/MetaBindAll.expected.hs | 2 - .../new/test/golden/MetaBindAll.hs | 2 - .../new/test/golden/MetaBindOne.expected.hs | 2 - .../new/test/golden/MetaBindOne.hs | 2 - .../new/test/golden/MetaCataAST.expected.hs | 23 - .../new/test/golden/MetaCataAST.hs | 11 - .../test/golden/MetaCataCollapse.expected.hs | 14 - .../new/test/golden/MetaCataCollapse.hs | 10 - .../golden/MetaCataCollapseUnary.expected.hs | 8 - .../new/test/golden/MetaCataCollapseUnary.hs | 8 - .../new/test/golden/MetaChoice.expected.hs | 2 - .../new/test/golden/MetaChoice.hs | 2 - .../new/test/golden/MetaDeepOf.expected.hs | 8 - .../new/test/golden/MetaDeepOf.hs | 8 - .../new/test/golden/MetaFundeps.expected.hs | 16 - .../new/test/golden/MetaFundeps.hs | 16 - .../new/test/golden/MetaIdiom.expected.hs | 6 - .../new/test/golden/MetaIdiom.hs | 6 - .../test/golden/MetaIdiomRecord.expected.hs | 8 - .../new/test/golden/MetaIdiomRecord.hs | 8 - .../new/test/golden/MetaLetSimple.expected.hs | 7 - .../new/test/golden/MetaLetSimple.hs | 2 - .../new/test/golden/MetaMaybeAp.expected.hs | 5 - .../new/test/golden/MetaMaybeAp.hs | 11 - .../new/test/golden/MetaPointwise.expected.hs | 8 - .../new/test/golden/MetaPointwise.hs | 7 - .../new/test/golden/MetaTry.expected.hs | 2 - .../new/test/golden/MetaTry.hs | 2 - .../new/test/golden/MetaUseImport.expected.hs | 6 - .../new/test/golden/MetaUseImport.hs | 6 - .../new/test/golden/MetaUseLocal.expected.hs | 7 - .../new/test/golden/MetaUseLocal.hs | 7 - .../new/test/golden/MetaUseMethod.expected.hs | 12 - .../new/test/golden/MetaUseMethod.hs | 12 - .../new/test/golden/MetaUseSymbol.expected.hs | 4 - .../new/test/golden/MetaUseSymbol.hs | 4 - .../new/test/golden/MetaWithArg.expected.hs | 2 - .../new/test/golden/MetaWithArg.hs | 2 - .../test/golden/SubsequentTactics.expected.hs | 2 +- 199 files changed, 119 insertions(+), 4156 deletions(-) delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Auto.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Context.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Judgements/Theta.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies/QuickCheck.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/Metaprogram.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Lexer.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs-boot delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser/Documentation.hs delete mode 100644 plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/ProofState.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/AutoTupleSpec.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/CodeAction/AutoSpec.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/CodeAction/RunMetaprogramSpec.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoEndo.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoEndo.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoZip.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/AutoZip.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/Fgmap.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/Fgmap.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/FmapBoth.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/FmapBoth.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/FmapJoin.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/FmapJoin.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenApplicativeThen.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenFish.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenNote.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenNote.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenShow.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenShow.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBegin.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBegin.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaChoice.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaChoice.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaTry.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaTry.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.expected.hs delete mode 100644 plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.hs diff --git a/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal b/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal index 2ad0a7365e..60075281d7 100644 --- a/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal +++ b/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal @@ -34,7 +34,7 @@ flag pedantic manual: True library - if impl(ghc >= 9.2.1) + if impl(ghc >= 9.3.1) buildable: False else buildable: True @@ -144,7 +144,7 @@ library ViewPatterns test-suite tests - if impl(ghc >= 9.2.1) + if impl(ghc >= 9.3.1) buildable: False else buildable: True @@ -171,6 +171,7 @@ test-suite tests hs-source-dirs: new/test else hs-source-dirs: old/test + ghc-options: -Wall -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs index da1e068ba6..5bf5e6cb90 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs @@ -29,7 +29,6 @@ import Language.LSP.Types hiding (CodeLens, CodeAction) import Wingman.AbstractLSP.Types import Wingman.EmptyCase (fromMaybeT) import Wingman.LanguageServer (getTacticConfig, getIdeDynflags, mkWorkspaceEdits, runStaleIde, showLspMessage, mkShowMessageParams) -import Wingman.StaticPlugin (enableQuasiQuotes) import Wingman.Types @@ -111,7 +110,7 @@ runContinuation plId cont state (fc, b) = do GraftEdit gr -> do ccs <- lift getClientCapabilities TrackedStale pm _ <- mapMaybeT liftIO $ stale GetAnnotatedParsedSource - case mkWorkspaceEdits (enableQuasiQuotes le_dflags) ccs (fc_uri le_fileContext) (unTrack pm) gr of + case mkWorkspaceEdits le_dflags ccs (fc_uri le_fileContext) (unTrack pm) gr of Left errs -> pure $ Just $ ResponseError { _code = InternalError diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs index bb30f27b02..52843af427 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs @@ -4,29 +4,28 @@ module Wingman.AbstractLSP.TacticActions where -import Control.Monad (when) -import Control.Monad.IO.Class (liftIO) -import Control.Monad.Trans (lift) -import Control.Monad.Trans.Maybe (mapMaybeT) -import Data.Foldable -import Data.Maybe (listToMaybe) -import Data.Proxy -import Development.IDE hiding (rangeToRealSrcSpan) -import Development.IDE.Core.UseStale -import Development.IDE.GHC.Compat -import Development.IDE.GHC.ExactPrint -import Generics.SYB.GHC (mkBindListT, everywhereM') -import Wingman.AbstractLSP.Types -import Wingman.CaseSplit -import Wingman.GHC (liftMaybe, isHole, pattern AMatch) -import Wingman.Judgements (jNeedsToBindArgs) -import Wingman.LanguageServer (runStaleIde) -import Wingman.LanguageServer.TacticProviders -import Wingman.Machinery (runTactic, scoreSolution) -import Wingman.Range -import Wingman.Types +import Control.Monad (when) +import Control.Monad.IO.Class (liftIO) +import Control.Monad.Trans (lift) +import Control.Monad.Trans.Maybe (mapMaybeT) +import Data.Maybe (listToMaybe) +import Data.Proxy +import Development.IDE hiding (rangeToRealSrcSpan) import Development.IDE.Core.Service (getIdeOptionsIO) +import Development.IDE.Core.UseStale +import Development.IDE.GHC.Compat +import Development.IDE.GHC.ExactPrint import Development.IDE.Types.Options (IdeTesting(IdeTesting), IdeOptions (IdeOptions, optTesting)) +import Generics.SYB.GHC (mkBindListT, everywhereM') +import Wingman.AbstractLSP.Types +import Wingman.CaseSplit +import Wingman.GHC (liftMaybe, isHole, pattern AMatch) +import Wingman.Judgements (jNeedsToBindArgs) +import Wingman.LanguageServer (runStaleIde) +import Wingman.LanguageServer.TacticProviders +import Wingman.Machinery (runTactic) +import Wingman.Range +import Wingman.Types ------------------------------------------------------------------------------ @@ -41,7 +40,6 @@ makeTacticInteraction cmd = TacticProviderData { tpd_lspEnv = env , tpd_jdg = hj_jdg hj - , tpd_hole_sort = hj_hole_sort hj } ) $ \LspEnv{..} HoleJudgment{..} FileContext{..} var_name -> do @@ -73,9 +71,6 @@ makeTacticInteraction cmd = $ ErrorMessages $ pure NothingToDo _ -> do - for_ (rtr_other_solns rtr) $ \soln -> do - traceMX "other solution" $ syn_val soln - traceMX "with score" $ scoreSolution soln (rtr_jdg rtr) [] traceMX "solution" $ rtr_extract rtr pure $ addTimeoutMessage rtr diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Auto.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Auto.hs deleted file mode 100644 index 3748af1e5b..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Auto.hs +++ /dev/null @@ -1,32 +0,0 @@ - -module Wingman.Auto where - -import Control.Monad.Reader.Class (asks) -import Control.Monad.State (gets) -import qualified Data.Set as S -import Refinery.Tactic -import Wingman.Judgements -import Wingman.KnownStrategies -import Wingman.Machinery (tracing, getCurrentDefinitions) -import Wingman.Tactics -import Wingman.Types - - ------------------------------------------------------------------------------- --- | Automatically solve a goal. -auto :: TacticsM () -auto = do - jdg <- goal - skolems <- gets ts_skolems - gas <- asks $ cfg_auto_gas . ctxConfig - current <- getCurrentDefinitions - traceMX "goal" jdg - traceMX "ctx" current - traceMX "skolems" skolems - commit knownStrategies - . tracing "auto" - . localTactic (auto' gas) - . disallowing RecursiveCall - . S.fromList - $ fmap fst current - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs b/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs index 322a6f5b8c..98556aa2a1 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs @@ -10,10 +10,7 @@ module Wingman.CodeGen ) where -import Control.Lens ((%~), (<>~), (&)) -import Control.Monad.Except -import Control.Monad.Reader (ask) -import Control.Monad.State +import Control.Lens ((%~), (&)) import Data.Bifunctor (second) import Data.Bool (bool) import Data.Functor ((<&>)) @@ -31,7 +28,6 @@ import GHC.SourceGen.Pat import Wingman.CodeGen.Utils import Wingman.GHC import Wingman.Judgements -import Wingman.Judgements.Theta import Wingman.Machinery import Wingman.Naming import Wingman.Types @@ -51,18 +47,14 @@ destructMatches -- 'destructionFor'. Make sure to change that if you ever change this. destructMatches use_field_puns f scrut t jdg = do let hy = jEntireHypothesis jdg - g = jGoal jdg case tacticsGetDataCons $ unCType t of Nothing -> cut -- throwError $ GoalMismatch "destruct" g Just (dcs, apps) -> fmap unzipTrace $ for dcs $ \dc -> do let con = RealDataCon dc - ev = concatMap (mkEvidence . scaledThing) $ dataConInstArgTys dc apps -- We explicitly do not need to add the method hypothesis to -- #syn_scoped - method_hy = foldMap evidenceToHypothesis ev args = conLikeInstOrigArgTys' con apps - ctx <- ask let names_in_scope = hyNamesInScope hy names = mkManyGoodNames (hyNamesInScope hy) args @@ -72,15 +64,8 @@ destructMatches use_field_puns f scrut t jdg = do let hy' = patternHypothesis scrut con jdg $ zip names' $ coerce args - j = withNewCoercions (evidenceToCoercions ev) - $ introduce ctx hy' - $ introduce ctx method_hy - $ withNewGoal g jdg - ext <- f con j + ext <- f con $ introduce hy' jdg pure $ ext - & #syn_trace %~ rose ("match " <> show dc <> " {" <> intercalate ", " (fmap show names') <> "}") - . pure - & #syn_scoped <>~ hy' & #syn_val %~ match [destructed] . unLoc @@ -207,7 +192,6 @@ patSynExTys ps = patSynExTyVars ps destruct' :: Bool -> (ConLike -> Judgement -> Rule) -> HyInfo CType -> Judgement -> Rule destruct' use_field_puns f hi jdg = do - when (isDestructBlacklisted jdg) cut -- throwError NoApplicableTactic let term = hi_name hi ext <- destructMatches @@ -217,7 +201,6 @@ destruct' use_field_puns f hi jdg = do (hi_type hi) $ disallowing AlreadyDestructed (S.singleton term) jdg pure $ ext - & #syn_trace %~ rose ("destruct " <> show term) . pure & #syn_val %~ noLoc . case' (var' term) @@ -226,7 +209,6 @@ destruct' use_field_puns f hi jdg = do -- resulting matches. destructLambdaCase' :: Bool -> (ConLike -> Judgement -> Rule) -> Judgement -> Rule destructLambdaCase' use_field_puns f jdg = do - when (isDestructBlacklisted jdg) cut -- throwError NoApplicableTactic let g = jGoal jdg case splitFunTy_maybe (unCType g) of #if __GLASGOW_HASKELL__ >= 900 @@ -242,18 +224,14 @@ destructLambdaCase' use_field_puns f jdg = do ------------------------------------------------------------------------------ -- | Construct a data con with subgoals for each field. buildDataCon - :: Bool -- Should we blacklist destruct? - -> Judgement + :: Judgement -> ConLike -- ^ The data con to build -> [Type] -- ^ Type arguments for the data con -> RuleM (Synthesized (LHsExpr GhcPs)) -buildDataCon should_blacklist jdg dc tyapps = do +buildDataCon jdg dc tyapps = do args <- case dc of RealDataCon dc' -> do - let (skolems', theta, args) = dataConInstSig dc' tyapps - modify $ \ts -> - evidenceToSubst (foldMap mkEvidence theta) ts - & #ts_skolems <>~ S.fromList skolems' + let (_ , _, args) = dataConInstSig dc' tyapps pure args _ -> -- If we have a 'PatSyn', we can't continue, since there is no @@ -269,12 +247,10 @@ buildDataCon should_blacklist jdg dc tyapps = do $ traverse ( \(arg, n) -> newSubgoal . filterSameTypeFromOtherPositions dc n - . bool id blacklistingDestruct should_blacklist . flip withNewGoal jdg $ CType arg ) $ zip args [0..] pure $ ext - & #syn_trace %~ rose (show dc) . pure & #syn_val %~ mkCon dc tyapps @@ -300,7 +276,6 @@ letForEach rename solve (unHypothesis -> hy) jdg = do case hy of [] -> newSubgoal jdg _ -> do - ctx <- ask let g = jGoal jdg terms <- fmap sequenceA $ for hy $ \hi -> do let name = rename $ hi_name hi @@ -309,7 +284,7 @@ letForEach rename solve (unHypothesis -> hy) jdg = do pure $ fmap ((name,) . unLoc) res let hy' = fmap (g <$) $ syn_val terms matches = fmap (fmap (\(occ, expr) -> valBind (occNameToStr occ) expr)) terms - g <- fmap (fmap unLoc) $ newSubgoal $ introduce ctx (userHypothesis hy') jdg + g <- fmap (fmap unLoc) $ newSubgoal $ introduce (userHypothesis hy') jdg pure $ fmap noLoc $ let' <$> matches <*> g @@ -321,9 +296,8 @@ nonrecLet -> RuleM (Synthesized (LHsExpr GhcPs)) nonrecLet occjdgs jdg = do occexts <- traverse newSubgoal $ fmap snd occjdgs - ctx <- ask ext <- newSubgoal - $ introduce ctx (userHypothesis $ fmap (second jGoal) occjdgs) jdg + $ introduce (userHypothesis $ fmap (second jGoal) occjdgs) jdg pure $ fmap noLoc $ let' <$> traverse diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Context.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Context.hs deleted file mode 100644 index 3c1b40ba1f..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Context.hs +++ /dev/null @@ -1,112 +0,0 @@ -{-# LANGUAGE CPP #-} - -module Wingman.Context where - -import Control.Arrow -import Control.Monad.Reader -import Data.Coerce (coerce) -import Data.Foldable.Extra (allM) -import Data.Maybe (fromMaybe, isJust, mapMaybe) -import qualified Data.Set as S -import Development.IDE.GHC.Compat -import Development.IDE.GHC.Compat.Util -import Wingman.GHC (normalizeType) -import Wingman.Judgements.Theta -import Wingman.Types - -#if __GLASGOW_HASKELL__ >= 900 -import GHC.Tc.Utils.TcType -#endif - - -mkContext - :: Config - -> [(OccName, CType)] - -> TcGblEnv - -> HscEnv - -> ExternalPackageState - -> [Evidence] - -> Context -mkContext cfg locals tcg hscenv eps ev = fix $ \ctx -> - Context - { ctxDefiningFuncs - = fmap (second $ coerce $ normalizeType ctx) locals - , ctxModuleFuncs - = fmap (second (coerce $ normalizeType ctx) . splitId) - . mappend (locallyDefinedMethods tcg) - . (getFunBindId =<<) - . fmap unLoc - . bagToList - $ tcg_binds tcg - , ctxConfig = cfg - , ctxFamInstEnvs = - (eps_fam_inst_env eps, tcg_fam_inst_env tcg) - , ctxInstEnvs = - InstEnvs - (eps_inst_env eps) - (tcg_inst_env tcg) - (tcVisibleOrphanMods tcg) - , ctxTheta = evidenceToThetaType ev - , ctx_hscEnv = hscenv - , ctx_occEnv = tcg_rdr_env tcg - , ctx_module = extractModule tcg - } - - -locallyDefinedMethods :: TcGblEnv -> [Id] -locallyDefinedMethods - = foldMap classMethods - . mapMaybe tyConClass_maybe - . tcg_tcs - - - -splitId :: Id -> (OccName, CType) -splitId = occName &&& CType . idType - - -getFunBindId :: HsBindLR GhcTc GhcTc -> [Id] -getFunBindId (AbsBinds _ _ _ abes _ _ _) - = abes >>= \case - ABE _ poly _ _ _ -> pure poly - _ -> [] -getFunBindId _ = [] - - ------------------------------------------------------------------------------- --- | Determine if there is an instance that exists for the given 'Class' at the --- specified types. Deeply checks contexts to ensure the instance is actually --- real. --- --- If so, this returns a 'PredType' that corresponds to the type of the --- dictionary. -getInstance :: MonadReader Context m => Class -> [Type] -> m (Maybe (Class, PredType)) -getInstance cls tys = do - env <- asks ctxInstEnvs - let (mres, _, _) = lookupInstEnv False env cls tys - case mres of - ((inst, mapps) : _) -> do - -- Get the instantiated type of the dictionary - let df = piResultTys (idType $ is_dfun inst) $ zipWith fromMaybe alphaTys mapps - -- pull off its resulting arguments - let (theta, df') = tcSplitPhiTy df - allM hasClassInstance theta >>= \case - True -> pure $ Just (cls, df') - False -> pure Nothing - _ -> pure Nothing - - ------------------------------------------------------------------------------- --- | Like 'getInstance', but only returns whether or not it succeeded. Can fail --- fast, and uses a cached Theta from the context. -hasClassInstance :: MonadReader Context m => PredType -> m Bool -hasClassInstance predty = do - theta <- asks ctxTheta - case S.member (CType predty) theta of - True -> pure True - False -> do - let (con, apps) = tcSplitTyConApp predty - case tyConClass_maybe con of - Nothing -> pure False - Just cls -> fmap isJust $ getInstance cls apps - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs b/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs index 13562a6ef8..65378b10d5 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs @@ -19,7 +19,6 @@ import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import GHC.SourceGen (lambda) import Generics.SYB (Data, everything, everywhere, listify, mkQ, mkT) -import Wingman.StaticPlugin (pattern MetaprogramSyntax) import Wingman.Types #if __GLASGOW_HASKELL__ >= 900 @@ -163,7 +162,6 @@ containsHole :: Data a => a -> Bool containsHole x = not $ null $ listify ( \case ((HsVar _ (L _ name)) :: HsExpr GhcPs) -> isHole $ occName name - MetaprogramSyntax _ -> True _ -> False ) x @@ -312,24 +310,6 @@ liftMaybe a = MaybeT $ pure a typeCheck :: HscEnv -> TcGblEnv -> HsExpr GhcTc -> IO (Maybe Type) typeCheck hscenv tcg = fmap snd . initDs hscenv tcg . fmap exprType . dsExpr ------------------------------------------------------------------------------- --- | Expand type and data families -normalizeType :: Context -> Type -> Type -normalizeType ctx ty = - let ty' = expandTyFam ctx ty - in case tcSplitTyConApp_maybe ty' of - Just (tc, tys) -> - -- try to expand any data families - case tcLookupDataFamInst_maybe (ctxFamInstEnvs ctx) tc tys of - Just (dtc, dtys, _) -> mkAppTys (mkTyConTy dtc) dtys - Nothing -> ty' - Nothing -> ty' - ------------------------------------------------------------------------------- --- | Expand type families -expandTyFam :: Context -> Type -> Type -expandTyFam ctx = snd . normaliseType (ctxFamInstEnvs ctx) Nominal - ------------------------------------------------------------------------------ -- | Like 'tcUnifyTy', but takes a list of skolems to prevent unification of. @@ -352,18 +332,3 @@ updateSubst :: TCvSubst -> TacticState -> TacticState updateSubst subst s = s { ts_unifier = unionTCvSubst subst (ts_unifier s) } ------------------------------------------------------------------------------- --- | Get the class methods of a 'PredType', correctly dealing with --- instantiation of quantified class types. -methodHypothesis :: PredType -> Maybe [HyInfo CType] -methodHypothesis ty = do - (tc, apps) <- splitTyConApp_maybe ty - cls <- tyConClass_maybe tc - let methods = classMethods cls - tvs = classTyVars cls - subst = zipTvSubst tvs apps - pure $ methods <&> \method -> - let (_, _, ty) = tcSplitSigmaTy $ idType method - in ( HyInfo (occName method) (ClassMethodPrv $ Uniquely cls) $ CType $ substTy subst ty - ) - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Judgements.hs index 0ff03e60ee..6504d0f731 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Judgements.hs @@ -14,8 +14,7 @@ import qualified Data.Set as S import Development.IDE.Core.UseStale (Tracked, unTrack) import Development.IDE.GHC.Compat hiding (isTopLevel) import Development.IDE.Spans.LocalBindings -import Wingman.GHC (algebraicTyCon, normalizeType) -import Wingman.Judgements.Theta +import Wingman.GHC (algebraicTyCon) import Wingman.Types @@ -46,23 +45,6 @@ hySingleton :: OccName -> Hypothesis () hySingleton n = Hypothesis . pure $ HyInfo n UserPrv () -blacklistingDestruct :: Judgement -> Judgement -blacklistingDestruct = - field @"_jBlacklistDestruct" .~ True - - -unwhitelistingSplit :: Judgement -> Judgement -unwhitelistingSplit = - field @"_jWhitelistSplit" .~ False - - -isDestructBlacklisted :: Judgement -> Bool -isDestructBlacklisted = _jBlacklistDestruct - - -isSplitWhitelisted :: Judgement -> Bool -isSplitWhitelisted = _jWhitelistSplit - withNewGoal :: a -> Judgement' a -> Judgement' a withNewGoal t = field @"_jGoal" .~ t @@ -74,28 +56,13 @@ withModifiedGoal :: (a -> a) -> Judgement' a -> Judgement' a withModifiedGoal f = field @"_jGoal" %~ f ------------------------------------------------------------------------------- --- | Add some new type equalities to the local judgement. -withNewCoercions :: [(CType, CType)] -> Judgement -> Judgement -withNewCoercions ev j = - let subst = allEvidenceToSubst mempty $ coerce ev - in fmap (CType . substTyAddInScope subst . unCType) j - & field @"j_coercion" %~ unionTCvSubst subst - - -normalizeHypothesis :: Functor f => Context -> f CType -> f CType -normalizeHypothesis = fmap . coerce . normalizeType -normalizeJudgement :: Functor f => Context -> f CType -> f CType -normalizeJudgement = normalizeHypothesis - - -introduce :: Context -> Hypothesis CType -> Judgement' CType -> Judgement' CType +introduce :: Hypothesis CType -> Judgement' CType -> Judgement' CType -- NOTE(sandy): It's important that we put the new hypothesis terms first, -- since 'jAcceptableDestructTargets' will never destruct a pattern that occurs -- after a previously-destructed term. -introduce ctx hy = - field @"_jHypothesis" %~ mappend (normalizeHypothesis ctx hy) +introduce hy = + field @"_jHypothesis" %~ mappend hy ------------------------------------------------------------------------------ @@ -123,11 +90,6 @@ lambdaHypothesis func = maybe UserPrv (\x -> TopLevelArgPrv x pos count) func ------------------------------------------------------------------------------- --- | Introduce a binding in a recursive context. -recursiveHypothesis :: [(OccName, a)] -> Hypothesis a -recursiveHypothesis = introduceHypothesis $ const $ const RecursivePrv - ------------------------------------------------------------------------------ -- | Introduce a binding in a recursive context. @@ -251,23 +213,11 @@ provAncestryOf :: Provenance -> Set OccName provAncestryOf (TopLevelArgPrv o _ _) = S.singleton o provAncestryOf (PatternMatchPrv (PatVal mo so _ _)) = maybe mempty S.singleton mo <> so -provAncestryOf (ClassMethodPrv _) = mempty provAncestryOf UserPrv = mempty provAncestryOf RecursivePrv = mempty -provAncestryOf ImportPrv = mempty provAncestryOf (DisallowedPrv _ p2) = provAncestryOf p2 ------------------------------------------------------------------------------- --- TODO(sandy): THIS THING IS A BIG BIG HACK --- --- Why? 'ctxDefiningFuncs' is _all_ of the functions currently being defined --- (eg, we might be in a where block). The head of this list is not guaranteed --- to be the one we're interested in. -extremelyStupid__definingFunction :: Context -> OccName -extremelyStupid__definingFunction = - fst . head . ctxDefiningFuncs - patternHypothesis :: Maybe OccName @@ -348,12 +298,6 @@ jAcceptableDestructTargets . jEntireHypothesis ------------------------------------------------------------------------------- --- | If we're in a top hole, the name of the defining function. -isTopHole :: Context -> Judgement' a -> Maybe OccName -isTopHole ctx = - bool Nothing (Just $ extremelyStupid__definingFunction ctx) . _jIsTopHole - unsetIsTopHole :: Judgement' a -> Judgement' a unsetIsTopHole = field @"_jIsTopHole" .~ False @@ -414,21 +358,17 @@ substJdg subst = fmap $ coerce . substTy subst . coerce mkFirstJudgement - :: Context - -> Hypothesis CType + :: Hypothesis CType -> Bool -- ^ are we in the top level rhs hole? -> Type -> Judgement' CType -mkFirstJudgement ctx hy top goal = - normalizeJudgement ctx $ - Judgement - { _jHypothesis = hy - , _jBlacklistDestruct = False - , _jWhitelistSplit = True - , _jIsTopHole = top - , _jGoal = CType goal - , j_coercion = emptyTCvSubst - } +mkFirstJudgement hy top goal = + Judgement + { _jHypothesis = hy + , _jIsTopHole = top + , _jGoal = CType goal + , j_coercion = emptyTCvSubst + } ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs index 8cd6130eb3..15e948f374 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs @@ -4,15 +4,12 @@ -- | Custom SYB traversals module Wingman.Judgements.SYB where -import Data.Foldable (foldl') -import Data.Generics hiding (typeRep) -import qualified Data.Text as T -import Development.IDE.GHC.Compat -import Development.IDE.GHC.Compat.Util (unpackFS) -import GHC.Exts (Any) -import Type.Reflection -import Unsafe.Coerce (unsafeCoerce) -import Wingman.StaticPlugin (pattern WingmanMetaprogram) +import Data.Foldable (foldl') +import Data.Generics hiding (typeRep) +import Development.IDE.GHC.Compat +import GHC.Exts (Any) +import Type.Reflection +import Unsafe.Coerce (unsafeCoerce) ------------------------------------------------------------------------------ @@ -84,15 +81,3 @@ sameTypeModuloLastApp = Nothing -> False _ -> False - -metaprogramAtQ :: SrcSpan -> GenericQ [(SrcSpan, T.Text)] -metaprogramAtQ ss = everythingContaining ss $ mkQ mempty $ \case - L new_span (WingmanMetaprogram program) -> pure (new_span, T.pack $ unpackFS program) - (_ :: LHsExpr GhcTc) -> mempty - - -metaprogramQ :: GenericQ [(SrcSpan, T.Text)] -metaprogramQ = everything (<>) $ mkQ mempty $ \case - L new_span (WingmanMetaprogram program) -> pure (new_span, T.pack $ unpackFS program) - (_ :: LHsExpr GhcTc) -> mempty - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/Theta.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/Theta.hs deleted file mode 100644 index 25bf5a3a21..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/Theta.hs +++ /dev/null @@ -1,235 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE ViewPatterns #-} - -module Wingman.Judgements.Theta - ( Evidence - , getEvidenceAtHole - , mkEvidence - , evidenceToCoercions - , evidenceToSubst - , evidenceToHypothesis - , evidenceToThetaType - , allEvidenceToSubst - ) where - -import Control.Applicative (empty) -import Control.Lens (preview) -import Data.Coerce (coerce) -import Data.Maybe (fromMaybe, mapMaybe, maybeToList) -import Data.Generics.Sum (_Ctor) -import Data.Set (Set) -import qualified Data.Set as S -import Development.IDE.Core.UseStale -import Development.IDE.GHC.Compat hiding (empty) -import Generics.SYB hiding (tyConName, empty, Generic) -import GHC.Generics -import Wingman.GHC -import Wingman.Types - -#if __GLASGOW_HASKELL__ >= 900 -import GHC.Tc.Utils.TcType -#endif - - ------------------------------------------------------------------------------- --- | Something we've learned about the type environment. -data Evidence - -- | The two types are equal, via a @a ~ b@ relationship - = EqualityOfTypes Type Type - -- | We have an instance in scope - | HasInstance PredType - deriving (Show, Generic) - - ------------------------------------------------------------------------------- --- | Given a 'PredType', pull an 'Evidence' out of it. -mkEvidence :: PredType -> [Evidence] -mkEvidence (getEqualityTheta -> Just (a, b)) - = pure $ EqualityOfTypes a b -mkEvidence inst@(tcTyConAppTyCon_maybe -> Just (tyConClass_maybe -> Just cls)) = do - (_, apps) <- maybeToList $ splitTyConApp_maybe inst - let tvs = classTyVars cls - subst = zipTvSubst tvs apps - sc_ev <- traverse (mkEvidence . substTy subst) $ classSCTheta cls - HasInstance inst : sc_ev -mkEvidence _ = empty - - ------------------------------------------------------------------------------- --- | Build a set of 'PredType's from the evidence. -evidenceToThetaType :: [Evidence] -> Set CType -evidenceToThetaType evs = S.fromList $ do - HasInstance t <- evs - pure $ CType t - - ------------------------------------------------------------------------------- --- | Compute all the 'Evidence' implicitly bound at the given 'SrcSpan'. -getEvidenceAtHole :: Tracked age SrcSpan -> Tracked age (LHsBinds GhcTc) -> [Evidence] -getEvidenceAtHole (unTrack -> dst) - = concatMap mkEvidence - . (everything (<>) $ - mkQ mempty (absBinds dst) `extQ` wrapperBinds dst `extQ` matchBinds dst) - . unTrack - - -mkSubst :: Set TyVar -> Type -> Type -> TCvSubst -mkSubst skolems a b = - let tyvars = S.fromList $ mapMaybe getTyVar_maybe [a, b] - -- If we can unify our skolems, at least one is no longer a skolem. - -- Removing them from this set ensures we can get a substitution between - -- the two. But it's okay to leave them in 'ts_skolems' in general, since - -- they won't exist after running this substitution. - skolems' = skolems S.\\ tyvars - in - case tryUnifyUnivarsButNotSkolems skolems' (CType a) (CType b) of - Just subst -> subst - Nothing -> emptyTCvSubst - - -substPair :: TCvSubst -> (Type, Type) -> (Type, Type) -substPair subst (ty, ty') = (substTy subst ty, substTy subst ty') - - ------------------------------------------------------------------------------- --- | Construct a substitution given a list of types that are equal to one --- another. This is more subtle than it seems, since there might be several --- equalities for the same type. We must be careful to push the accumulating --- substitution through each pair of types before adding their equalities. -allEvidenceToSubst :: Set TyVar -> [(Type, Type)] -> TCvSubst -allEvidenceToSubst _ [] = emptyTCvSubst -allEvidenceToSubst skolems ((a, b) : evs) = - let subst = mkSubst skolems a b - in unionTCvSubst subst - $ allEvidenceToSubst skolems - $ fmap (substPair subst) evs - ------------------------------------------------------------------------------- --- | Given some 'Evidence', get a list of which types are now equal. -evidenceToCoercions :: [Evidence] -> [(CType, CType)] -evidenceToCoercions = coerce . mapMaybe (preview $ _Ctor @"EqualityOfTypes") - ------------------------------------------------------------------------------- --- | Update our knowledge of which types are equal. -evidenceToSubst :: [Evidence] -> TacticState -> TacticState -evidenceToSubst evs ts = - updateSubst - (allEvidenceToSubst (ts_skolems ts) . coerce $ evidenceToCoercions evs) - ts - - ------------------------------------------------------------------------------- --- | Get all of the methods that are in scope from this piece of 'Evidence'. -evidenceToHypothesis :: Evidence -> Hypothesis CType -evidenceToHypothesis EqualityOfTypes{} = mempty -evidenceToHypothesis (HasInstance t) = - Hypothesis . excludeForbiddenMethods . fromMaybe [] $ methodHypothesis t - - ------------------------------------------------------------------------------- --- | Given @a ~ b@ or @a ~# b@, returns @Just (a, b)@, otherwise @Nothing@. -getEqualityTheta :: PredType -> Maybe (Type, Type) -getEqualityTheta (splitTyConApp_maybe -> Just (tc, [_k, a, b])) -#if __GLASGOW_HASKELL__ > 806 - | tc == eqTyCon -#else - | nameRdrName (tyConName tc) == eqTyCon_RDR -#endif - = Just (a, b) -getEqualityTheta (splitTyConApp_maybe -> Just (tc, [_k1, _k2, a, b])) - | tc == eqPrimTyCon = Just (a, b) -getEqualityTheta _ = Nothing - - ------------------------------------------------------------------------------- --- | Many operations are defined in typeclasses for performance reasons, rather --- than being a true part of the class. This function filters out those, in --- order to keep our hypothesis space small. -excludeForbiddenMethods :: [HyInfo a] -> [HyInfo a] -excludeForbiddenMethods = filter (not . flip S.member forbiddenMethods . hi_name) - where - forbiddenMethods :: Set OccName - forbiddenMethods = S.map mkVarOcc $ S.fromList - [ -- monadfail - "fail" - -- show - , "showsPrec", "showList" - -- functor - , "<$" - -- applicative - , "liftA2", "<*", "*>" - -- monad - , "return", ">>" - -- alternative - , "some", "many" - -- foldable - , "foldr1", "foldl1", "elem", "maximum", "minimum", "sum", "product" - -- traversable - , "sequenceA", "mapM", "sequence" - -- semigroup - , "sconcat", "stimes" - -- monoid - , "mconcat" - ] - - ------------------------------------------------------------------------------- --- | Extract evidence from 'AbsBinds' in scope. -absBinds :: SrcSpan -> LHsBindLR GhcTc GhcTc -> [PredType] -#if __GLASGOW_HASKELL__ >= 900 -absBinds dst (L src (FunBind w _ _ _)) - | dst `isSubspanOf` src - = wrapper w -absBinds dst (L src (AbsBinds _ _ h _ _ z _)) -#else -absBinds dst (L src (AbsBinds _ _ h _ _ _ _)) -#endif - | dst `isSubspanOf` src - = fmap idType h -#if __GLASGOW_HASKELL__ >= 900 - <> foldMap (absBinds dst) z -#endif -absBinds _ _ = [] - - ------------------------------------------------------------------------------- --- | Extract evidence from 'HsWrapper's in scope -wrapperBinds :: SrcSpan -> LHsExpr GhcTc -> [PredType] -#if __GLASGOW_HASKELL__ >= 900 -wrapperBinds dst (L src (XExpr (WrapExpr (HsWrap h _)))) -#else -wrapperBinds dst (L src (HsWrap _ h _)) -#endif - | dst `isSubspanOf` src - = wrapper h -wrapperBinds _ _ = [] - - ------------------------------------------------------------------------------- --- | Extract evidence from the 'ConPatOut's bound in this 'Match'. -matchBinds :: SrcSpan -> LMatch GhcTc (LHsExpr GhcTc) -> [PredType] -matchBinds dst (L src (Match _ _ pats _)) - | dst `isSubspanOf` src - = everything (<>) (mkQ mempty patBinds) pats -matchBinds _ _ = [] - - ------------------------------------------------------------------------------- --- | Extract evidence from a 'ConPatOut'. -patBinds :: Pat GhcTc -> [PredType] -#if __GLASGOW_HASKELL__ >= 900 -patBinds (ConPat{ pat_con_ext = ConPatTc { cpt_dicts = dicts }}) -#else -patBinds (ConPatOut { pat_dicts = dicts }) -#endif - = fmap idType dicts -patBinds _ = [] - - ------------------------------------------------------------------------------- --- | Extract the types of the evidence bindings in scope. -wrapper :: HsWrapper -> [PredType] -wrapper (WpCompose h h2) = wrapper h <> wrapper h2 -wrapper (WpEvLam v) = [idType v] -wrapper _ = [] - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies.hs b/plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies.hs deleted file mode 100644 index e898358c49..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies.hs +++ /dev/null @@ -1,82 +0,0 @@ -module Wingman.KnownStrategies where - -import Data.Foldable (for_) -import Development.IDE.GHC.Compat.Core -import Refinery.Tactic -import Wingman.Judgements (jGoal) -import Wingman.KnownStrategies.QuickCheck (deriveArbitrary) -import Wingman.Machinery (tracing, getKnownInstance, getCurrentDefinitions) -import Wingman.Tactics -import Wingman.Types - - -knownStrategies :: TacticsM () -knownStrategies = choice - [ known "fmap" deriveFmap - , known "mempty" deriveMempty - , known "arbitrary" deriveArbitrary - , known "<>" deriveMappend - , known "mappend" deriveMappend - ] - - -known :: String -> TacticsM () -> TacticsM () -known name t = do - getCurrentDefinitions >>= \case - [(def, _)] | def == mkVarOcc name -> - tracing ("known " <> name) t - _ -> failure NoApplicableTactic - - -deriveFmap :: TacticsM () -deriveFmap = do - try intros - overAlgebraicTerms homo - choice - [ overFunctions (apply Saturated) >> auto' 2 - , assumption - , recursion - ] - - ------------------------------------------------------------------------------- --- | We derive mappend by binding the arguments, introducing the constructor, --- and then calling mappend recursively. At each recursive call, we filter away --- any binding that isn't in an analogous position. --- --- The recursive call first attempts to use an instance in scope. If that fails, --- it falls back to trying a theta method from the hypothesis with the correct --- name. -deriveMappend :: TacticsM () -deriveMappend = do - try intros - destructAll - split - g <- goal - minst <- getKnownInstance (mkClsOcc "Semigroup") - . pure - . unCType - $ jGoal g - for_ minst $ \(cls, df) -> do - restrictPositionForApplication - (applyMethod cls df $ mkVarOcc "<>") - assumption - try $ - restrictPositionForApplication - (applyByName $ mkVarOcc "<>") - assumption - - ------------------------------------------------------------------------------- --- | We derive mempty by introducing the constructor, and then trying to --- 'mempty' everywhere. This smaller 'mempty' might come from an instance in --- scope, or it might come from the hypothesis theta. -deriveMempty :: TacticsM () -deriveMempty = do - split - g <- goal - minst <- getKnownInstance (mkClsOcc "Monoid") [unCType $ jGoal g] - for_ minst $ \(cls, df) -> do - applyMethod cls df $ mkVarOcc "mempty" - try assumption - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies/QuickCheck.hs b/plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies/QuickCheck.hs deleted file mode 100644 index b14e4b8348..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/KnownStrategies/QuickCheck.hs +++ /dev/null @@ -1,109 +0,0 @@ -module Wingman.KnownStrategies.QuickCheck where - -import Data.Bool (bool) -import Data.Generics (everything, mkQ) -import Data.List (partition) -import Development.IDE.GHC.Compat -import GHC.Exts (IsString (fromString)) -import GHC.List (foldl') -import GHC.SourceGen (int) -import GHC.SourceGen.Binds (match, valBind) -import GHC.SourceGen.Expr (case', lambda, let') -import GHC.SourceGen.Overloaded (App ((@@)), HasList (list)) -import GHC.SourceGen.Pat (conP) -import Refinery.Tactic (goal, rule, failure) -import Wingman.CodeGen -import Wingman.Judgements (jGoal) -import Wingman.Machinery (tracePrim) -import Wingman.Types - - ------------------------------------------------------------------------------- --- | Known tactic for deriving @arbitrary :: Gen a@. This tactic splits the --- type's data cons into terminal and inductive cases, and generates code that --- produces a terminal if the QuickCheck size parameter is <=1, or any data con --- otherwise. It correctly scales recursive parameters, ensuring termination. -deriveArbitrary :: TacticsM () -deriveArbitrary = do - ty <- jGoal <$> goal - case splitTyConApp_maybe $ unCType ty of - Just (gen_tc, [splitTyConApp_maybe -> Just (tc, apps)]) - | occNameString (occName $ tyConName gen_tc) == "Gen" -> do - rule $ \_ -> do - let dcs = tyConDataCons tc - (terminal, big) = partition ((== 0) . genRecursiveCount) - $ fmap (mkGenerator tc apps) dcs - terminal_expr = mkVal "terminal" - oneof_expr = mkVal "oneof" - pure - $ Synthesized (tracePrim "deriveArbitrary") - -- TODO(sandy): This thing is not actually empty! We produced - -- a bespoke binding "terminal", and a not-so-bespoke "n". - -- But maybe it's fine for known rules? - mempty - mempty - mempty - $ noLoc $ case terminal of - [onlyCon] -> genExpr onlyCon -- See #1879 - _ -> let' [valBind (fromString "terminal") $ list $ fmap genExpr terminal] $ - appDollar (mkFunc "sized") $ lambda [bvar' (mkVarOcc "n")] $ - case' (infixCall "<=" (mkVal "n") (int 1)) - [ match [conP (fromString "True") []] $ - oneof_expr @@ terminal_expr - , match [conP (fromString "False") []] $ - appDollar oneof_expr $ - infixCall "<>" - (list $ fmap genExpr big) - terminal_expr - ] - _ -> failure $ GoalMismatch "deriveArbitrary" ty - - ------------------------------------------------------------------------------- --- | Helper data type for the generator of a specific data con. -data Generator = Generator - { genRecursiveCount :: Integer - , genExpr :: HsExpr GhcPs - } - - ------------------------------------------------------------------------------- --- | Make a 'Generator' for a given tycon instantiated with the given @[Type]@. -mkGenerator :: TyCon -> [Type] -> DataCon -> Generator -mkGenerator tc apps dc = do - let dc_expr = var' $ occName $ dataConName dc - args = conLikeInstOrigArgTys' (RealDataCon dc) apps - num_recursive_calls = sum $ fmap (bool 0 1 . doesTypeContain tc) args - mkArbitrary = mkArbitraryCall tc num_recursive_calls - Generator num_recursive_calls $ case args of - [] -> mkFunc "pure" @@ dc_expr - (a : as) -> - foldl' - (infixCall "<*>") - (infixCall "<$>" dc_expr $ mkArbitrary a) - (fmap mkArbitrary as) - - ------------------------------------------------------------------------------- --- | Check if the given 'TyCon' exists anywhere in the 'Type'. -doesTypeContain :: TyCon -> Type -> Bool -doesTypeContain recursive_tc = - everything (||) $ mkQ False (== recursive_tc) - - ------------------------------------------------------------------------------- --- | Generate the correct sort of call to @arbitrary@. For recursive calls, we --- need to scale down the size parameter, either by a constant factor of 1 if --- it's the only recursive parameter, or by @`div` n@ where n is the number of --- recursive parameters. For all other types, just call @arbitrary@ directly. -mkArbitraryCall :: TyCon -> Integer -> Type -> HsExpr GhcPs -mkArbitraryCall recursive_tc n ty = - let arbitrary = mkFunc "arbitrary" - in case doesTypeContain recursive_tc ty of - True -> - mkFunc "scale" - @@ bool (mkFunc "flip" @@ mkFunc "div" @@ int n) - (mkFunc "subtract" @@ int 1) - (n == 1) - @@ arbitrary - False -> arbitrary diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs index c0bba854ff..3e81e5f02b 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs @@ -7,31 +7,27 @@ module Wingman.LanguageServer where -import Control.Arrow ((***)) +import Control.Arrow ((&&&)) import Control.Monad -import Control.Monad.IO.Class import Control.Monad.RWS import Control.Monad.State (State, evalState) import Control.Monad.Trans.Maybe import Data.Bifunctor (first) -import Data.Coerce import Data.Functor ((<&>)) -import Data.Functor.Identity (runIdentity) import qualified Data.HashMap.Strict as Map -import Data.IORef (readIORef) import qualified Data.Map as M import Data.Maybe import Data.Set (Set) import qualified Data.Set as S import qualified Data.Text as T import Data.Traversable -import Development.IDE (hscEnv, getFilesOfInterestUntracked, ShowDiagnostic (ShowDiag), srcSpanToRange, defineNoDiagnostics, IdeAction) -import Development.IDE.Core.PositionMapping (idDelta) +import Development.IDE (getFilesOfInterestUntracked, ShowDiagnostic (ShowDiag), srcSpanToRange, IdeAction) import Development.IDE.Core.RuleTypes import Development.IDE.Core.Rules (usePropertyAction) import Development.IDE.Core.Service (runAction) -import Development.IDE.Core.Shake (IdeState (..), uses, define, use, addPersistentRule) +import Development.IDE.Core.Shake (IdeState (..), uses, define, use) import qualified Development.IDE.Core.Shake as IDE +import qualified Development.IDE.Core.Shake as Shake import Development.IDE.Core.UseStale import Development.IDE.GHC.Compat hiding (empty) import Development.IDE.GHC.Compat.ExactPrint @@ -40,32 +36,23 @@ import Development.IDE.GHC.Error (realSrcSpanToRange) import Development.IDE.GHC.ExactPrint hiding (LogShake, Log) import Development.IDE.Graph (Action, RuleResult, Rules, action) import Development.IDE.Graph.Classes (Hashable, NFData) -import Development.IDE.Spans.LocalBindings (Bindings, getDefiningBindings) +import Development.IDE.Spans.LocalBindings (Bindings) +import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) import GHC.Generics (Generic) import Generics.SYB hiding (Generic) import qualified Ide.Plugin.Config as Plugin import Ide.Plugin.Properties import Ide.PluginUtils (usePropertyLsp) import Ide.Types (PluginId) -import Language.Haskell.GHC.ExactPrint (Transform, modifyAnnsT, addAnnotationsForPretty) import Language.LSP.Server (MonadLsp, sendNotification) -import Language.LSP.Types hiding - (SemanticTokenAbsolute (length, line), - SemanticTokenRelative (length), - SemanticTokensEdit (_start)) +import Language.LSP.Types hiding (SemanticTokenAbsolute (length, line), SemanticTokenRelative (length), SemanticTokensEdit (_start)) import Language.LSP.Types.Capabilities import Prelude hiding (span) -import Retrie (transformA) -import Wingman.Context import Wingman.GHC import Wingman.Judgements -import Wingman.Judgements.SYB (everythingContaining, metaprogramQ, metaprogramAtQ) -import Wingman.Judgements.Theta +import Wingman.Judgements.SYB (everythingContaining) import Wingman.Range -import Wingman.StaticPlugin (pattern WingmanMetaprogram, pattern MetaprogramSyntax) import Wingman.Types -import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) -import qualified Development.IDE.Core.Shake as Shake newtype Log @@ -189,8 +176,6 @@ getTacticConfig pId = Config <$> usePropertyLsp #max_use_ctor_actions pId properties <*> usePropertyLsp #timeout_duration pId properties - <*> usePropertyLsp #auto_gas pId properties - <*> usePropertyLsp #proofstate_styling pId properties getIdeDynflags @@ -203,11 +188,6 @@ getIdeDynflags state nfp = do msr <- unsafeRunStaleIde "getIdeDynflags" state nfp GetModSummaryWithoutTimestamps pure $ ms_hspp_opts $ msrModSummary msr -getAllMetaprograms :: Data a => a -> [String] -getAllMetaprograms = everything (<>) $ mkQ mempty $ \case - WingmanMetaprogram fs -> [ FastString.unpackFS fs ] - (_ :: HsExpr GhcTc) -> mempty - ------------------------------------------------------------------------------ -- | Find the last typechecked module, and find the most specific span, as well @@ -227,24 +207,13 @@ judgementForHole state nfp range cfg = do HAR _ (unsafeCopyAge asts -> hf) _ _ HieFresh -> do range' <- liftMaybe $ mapAgeFrom amapping range binds <- stale GetBindings - tcg@(TrackedStale tcg_t tcg_map) - <- fmap (fmap tmrTypechecked) - $ stale TypeCheck - - hscenv <- stale GhcSessionDeps + tcg <- fmap (fmap tmrTypechecked) $ stale TypeCheck (rss, g) <- liftMaybe $ getSpanAndTypeAtHole range' hf new_rss <- liftMaybe $ mapAgeTo amapping rss - tcg_rss <- liftMaybe $ mapAgeFrom tcg_map new_rss - - -- KnownThings is just the instances in scope. There are no ranges - -- involved, so it's not crucial to track ages. - let henv = untrackedStaleValue hscenv - eps <- liftIO $ readIORef $ hsc_EPS $ hscEnv henv - (jdg, ctx) <- liftMaybe $ mkJudgementAndContext cfg g binds new_rss tcg (hscEnv henv) eps - let mp = getMetaprogramAtSpan (fmap (`RealSrcSpan` Nothing) tcg_rss) tcg_t + (jdg, ctx) <- liftMaybe $ mkJudgementAndContext cfg g binds new_rss tcg dflags <- getIdeDynflags state nfp pure $ HoleJudgment @@ -252,52 +221,34 @@ judgementForHole state nfp range cfg = do , hj_jdg = jdg , hj_ctx = ctx , hj_dflags = dflags - , hj_hole_sort = holeSortFor mp } -holeSortFor :: Maybe T.Text -> HoleSort -holeSortFor = maybe Hole Metaprogram - - mkJudgementAndContext :: Config -> Type -> TrackedStale Bindings -> Tracked 'Current RealSrcSpan -> TrackedStale TcGblEnv - -> HscEnv - -> ExternalPackageState - -> Maybe (Judgement, Context) -mkJudgementAndContext cfg g (TrackedStale binds bmap) rss (TrackedStale tcg tcgmap) hscenv eps = do + -> Maybe (Judgement, Config) +mkJudgementAndContext cfg g (TrackedStale binds bmap) rss (TrackedStale tcg tcgmap) = do binds_rss <- mapAgeFrom bmap rss tcg_rss <- mapAgeFrom tcgmap rss let tcs = fmap tcg_binds tcg - ctx = mkContext cfg - (mapMaybe (sequenceA . (occName *** coerce)) - $ unTrack - $ getDefiningBindings <$> binds <*> binds_rss) - (unTrack tcg) - hscenv - eps - evidence top_provs = getRhsPosVals tcg_rss tcs already_destructed = getAlreadyDestructed (fmap (`RealSrcSpan` Nothing) tcg_rss) tcs local_hy = spliceProvenance top_provs $ hypothesisFromBindings binds_rss binds - evidence = getEvidenceAtHole (fmap (`RealSrcSpan` Nothing) tcg_rss) tcs - cls_hy = foldMap evidenceToHypothesis evidence - subst = ts_unifier $ evidenceToSubst evidence defaultTacticState + subst = ts_unifier defaultTacticState pure ( disallowing AlreadyDestructed already_destructed $ fmap (CType . substTyAddInScope subst . unCType) $ mkFirstJudgement - ctx - (local_hy <> cls_hy) + (local_hy) (isRhsHoleWithoutWhere tcg_rss tcs) g - , ctx + , cfg ) @@ -548,14 +499,6 @@ instance NFData WriteDiagnostics type instance RuleResult WriteDiagnostics = () -data GetMetaprograms = GetMetaprograms - deriving (Eq, Show, Typeable, Generic) - -instance Hashable GetMetaprograms -instance NFData GetMetaprograms - -type instance RuleResult GetMetaprograms = [(Tracked 'Current RealSrcSpan, T.Text)] - wingmanRules :: Recorder (WithPriority Log) -> PluginId -> Rules () wingmanRules recorder plId = do define (cmapWithPrio LogShake recorder) $ \WriteDiagnostics nfp -> @@ -587,21 +530,6 @@ wingmanRules recorder plId = do , Just () ) - defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \GetMetaprograms nfp -> do - TrackedStale tcg tcg_map <- fmap tmrTypechecked <$> useWithStale_ TypeCheck nfp - let scrutinees = traverse (metaprogramQ . tcg_binds) tcg - return $ Just $ flip mapMaybe scrutinees $ \aged@(unTrack -> (ss, program)) -> do - case ss of - RealSrcSpan r _ -> do - rss' <- mapAgeTo tcg_map $ unsafeCopyAge aged r - pure (rss', program) - UnhelpfulSpan _ -> Nothing - - -- This persistent rule helps to avoid blocking HLS hover providers at startup - -- Without it, the GetMetaprograms rule blocks on typecheck and prevents other - -- hover providers from being used to produce a response - addPersistentRule GetMetaprograms $ \_ -> return $ Just ([], idDelta, Nothing) - action $ do files <- getFilesOfInterestUntracked void $ uses WriteDiagnostics $ Map.keys files @@ -628,35 +556,10 @@ mkWorkspaceEdits -> Graft (Either String) ParsedSource -> Either UserFacingMessage WorkspaceEdit mkWorkspaceEdits dflags ccs uri pm g = do - let pm' = runIdentity $ transformA pm annotateMetaprograms - let response = transform dflags ccs uri g pm' + let response = transform dflags ccs uri g pm in first (InfrastructureError . T.pack) response ------------------------------------------------------------------------------- --- | Add ExactPrint annotations to every metaprogram in the source tree. --- Usually the ExactPrint module can do this for us, but we've enabled --- QuasiQuotes, so the round-trip print/parse journey will crash. -annotateMetaprograms :: Data a => a -> Transform a -annotateMetaprograms = everywhereM $ mkM $ \case - L ss (WingmanMetaprogram mp) -> do - let x = L ss $ MetaprogramSyntax mp - let anns = addAnnotationsForPretty [] x mempty - modifyAnnsT $ mappend anns - pure x - (x :: LHsExpr GhcPs) -> pure x - - ------------------------------------------------------------------------------- --- | Find the source of a tactic metaprogram at the given span. -getMetaprogramAtSpan - :: Tracked age SrcSpan - -> Tracked age TcGblEnv - -> Maybe T.Text -getMetaprogramAtSpan (unTrack -> ss) - = fmap snd - . listToMaybe - . metaprogramAtQ ss - . tcg_binds - . unTrack +splitId :: Id -> (OccName, CType) +splitId = occName &&& CType . idType diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/Metaprogram.hs b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/Metaprogram.hs deleted file mode 100644 index e853831a32..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/Metaprogram.hs +++ /dev/null @@ -1,59 +0,0 @@ -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} - -{-# LANGUAGE NoMonoLocalBinds #-} -{-# LANGUAGE RankNTypes #-} - -module Wingman.LanguageServer.Metaprogram - ( hoverProvider - ) where - -import Control.Applicative (empty) -import Control.Monad -import Control.Monad.Trans -import Control.Monad.Trans.Maybe -import Data.List (find) -import Data.Maybe -import qualified Data.Text as T -import Development.IDE (positionToRealSrcLoc, realSrcSpanToRange) -import Development.IDE.Core.Shake (IdeState (..)) -import Development.IDE.Core.UseStale -import Development.IDE.GHC.Compat hiding (empty) -import Ide.Types -import Language.LSP.Types -import Prelude hiding (span) -import Wingman.LanguageServer -import Wingman.Metaprogramming.Parser (attempt_it) -import Wingman.Types - - ------------------------------------------------------------------------------- --- | Provide the "empty case completion" code lens -hoverProvider :: PluginMethodHandler IdeState TextDocumentHover -hoverProvider state plId (HoverParams (TextDocumentIdentifier uri) (unsafeMkCurrent -> pos) _) - | Just nfp <- uriToNormalizedFilePath $ toNormalizedUri uri = do - let loc = fmap (realSrcLocSpan . positionToRealSrcLoc nfp) pos - stale = unsafeRunStaleIdeFast "hoverProvider" state nfp - - cfg <- getTacticConfig plId - liftIO $ fromMaybeT (Right Nothing) $ do - holes <- stale GetMetaprograms - - fmap (Right . Just) $ - case find (flip containsSpan (unTrack loc) . unTrack . fst) holes of - Just (trss, program) -> do - let tr_range = fmap realSrcSpanToRange trss - rsl = realSrcSpanStart $ unTrack trss - HoleJudgment{hj_jdg=jdg, hj_ctx=ctx} <- judgementForHole state nfp tr_range cfg - z <- liftIO $ attempt_it rsl ctx jdg $ T.unpack program - pure $ Hover - { _contents = HoverContents - $ MarkupContent MkMarkdown - $ either T.pack T.pack z - , _range = Just $ unTrack tr_range - } - Nothing -> empty -hoverProvider _ _ _ = pure $ Right Nothing - -fromMaybeT :: Functor m => a -> MaybeT m a -> m a -fromMaybeT def = fmap (fromMaybe def) . runMaybeT diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs index b5a6521b7e..5b038abb14 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs @@ -20,11 +20,9 @@ import Ide.Types import Language.LSP.Types hiding (SemanticTokenAbsolute (..), SemanticTokenRelative (..)) import Prelude hiding (span) import Wingman.AbstractLSP.Types -import Wingman.Auto import Wingman.GHC import Wingman.Judgements import Wingman.Machinery (useNameFromHypothesis, uncoveredDataCons) -import Wingman.Metaprogramming.Parser (parseMetaprogram) import Wingman.Tactics import Wingman.Types @@ -32,7 +30,6 @@ import Wingman.Types ------------------------------------------------------------------------------ -- | A mapping from tactic commands to actual tactics for refinery. commandTactic :: TacticCommand -> T.Text -> TacticsM () -commandTactic Auto = const auto commandTactic Intros = const intros commandTactic IntroAndDestruct = const introAndDestruct commandTactic Destruct = useNameFromHypothesis destruct . mkVarOcc . T.unpack @@ -43,14 +40,11 @@ commandTactic HomomorphismLambdaCase = const homoLambdaCase commandTactic DestructAll = const destructAll commandTactic UseDataCon = userSplit . mkVarOcc . T.unpack commandTactic Refine = const refine -commandTactic BeginMetaprogram = const metaprogram -commandTactic RunMetaprogram = parseMetaprogram ------------------------------------------------------------------------------ -- | The LSP kind tacticKind :: TacticCommand -> T.Text -tacticKind Auto = "fillHole" tacticKind Intros = "introduceLambda" tacticKind IntroAndDestruct = "introduceAndDestruct" tacticKind Destruct = "caseSplit" @@ -61,15 +55,12 @@ tacticKind HomomorphismLambdaCase = "homomorphicLambdaCase" tacticKind DestructAll = "splitFuncArgs" tacticKind UseDataCon = "useConstructor" tacticKind Refine = "refine" -tacticKind BeginMetaprogram = "beginMetaprogram" -tacticKind RunMetaprogram = "runMetaprogram" ------------------------------------------------------------------------------ -- | Whether or not this code action is preferred -- ostensibly refers to -- whether or not we can bind it to a key in vs code? tacticPreferred :: TacticCommand -> Bool -tacticPreferred Auto = True tacticPreferred Intros = True tacticPreferred IntroAndDestruct = True tacticPreferred Destruct = True @@ -80,8 +71,6 @@ tacticPreferred HomomorphismLambdaCase = False tacticPreferred DestructAll = True tacticPreferred UseDataCon = True tacticPreferred Refine = True -tacticPreferred BeginMetaprogram = False -tacticPreferred RunMetaprogram = True mkTacticKind :: TacticCommand -> CodeActionKind @@ -93,47 +82,35 @@ mkTacticKind = -- | Mapping from tactic commands to their contextual providers. See 'provide', -- 'filterGoalType' and 'filterBindingType' for the nitty gritty. commandProvider :: TacticCommand -> TacticProvider -commandProvider Auto = - requireHoleSort (== Hole) $ - provide Auto "" commandProvider Intros = - requireHoleSort (== Hole) $ filterGoalType isFunction $ provide Intros "" commandProvider IntroAndDestruct = - requireHoleSort (== Hole) $ filterGoalType (liftLambdaCase False (\_ -> isJust . algebraicTyCon)) $ provide IntroAndDestruct "" commandProvider Destruct = - requireHoleSort (== Hole) $ filterBindingType destructFilter $ \occ _ -> provide Destruct $ T.pack $ occNameString occ commandProvider DestructPun = - requireHoleSort (== Hole) $ filterBindingType destructPunFilter $ \occ _ -> provide DestructPun $ T.pack $ occNameString occ commandProvider Homomorphism = - requireHoleSort (== Hole) $ filterBindingType homoFilter $ \occ _ -> provide Homomorphism $ T.pack $ occNameString occ commandProvider DestructLambdaCase = - requireHoleSort (== Hole) $ requireExtension LambdaCase $ filterGoalType (isJust . lambdaCaseable) $ provide DestructLambdaCase "" commandProvider HomomorphismLambdaCase = - requireHoleSort (== Hole) $ requireExtension LambdaCase $ filterGoalType (liftLambdaCase False homoFilter) $ provide HomomorphismLambdaCase "" commandProvider DestructAll = - requireHoleSort (== Hole) $ withJudgement $ \jdg -> case _jIsTopHole jdg && jHasBoundArgs jdg of True -> provide DestructAll "" False -> mempty commandProvider UseDataCon = - requireHoleSort (== Hole) $ withConfig $ \cfg -> filterTypeProjection ( guardLength (<= cfg_max_use_ctor_actions cfg) @@ -146,14 +123,8 @@ commandProvider UseDataCon = . occName $ dataConName dcon commandProvider Refine = - requireHoleSort (== Hole) $ provide Refine "" -commandProvider BeginMetaprogram = - requireHoleSort (== Hole) $ - provide BeginMetaprogram "" -commandProvider RunMetaprogram = - withMetaprogram $ \mp -> - provide RunMetaprogram mp + ------------------------------------------------------------------------------ @@ -173,22 +144,9 @@ type TacticProvider data TacticProviderData = TacticProviderData { tpd_lspEnv :: LspEnv , tpd_jdg :: Judgement - , tpd_hole_sort :: HoleSort } -requireHoleSort :: (HoleSort -> Bool) -> TacticProvider -> TacticProvider -requireHoleSort p tp tpd = - case p $ tpd_hole_sort tpd of - True -> tp tpd - False -> [] - -withMetaprogram :: (T.Text -> TacticProvider) -> TacticProvider -withMetaprogram tp tpd = - case tpd_hole_sort tpd of - Metaprogram mp -> tp mp tpd - _ -> [] - ------------------------------------------------------------------------------ -- | Restrict a 'TacticProvider', making sure it appears only when the given diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs index ca082ec65e..fe91e052c6 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs @@ -4,46 +4,29 @@ module Wingman.Machinery where -import Control.Applicative (empty) import Control.Concurrent.Chan.Unagi.NoBlocking (newChan, writeChan, OutChan, tryRead, tryReadChan) -import Control.Lens ((<>~)) import Control.Monad.Reader import Control.Monad.State.Class (gets, modify, MonadState) import Control.Monad.State.Strict (StateT (..), execStateT) -import Control.Monad.Trans.Maybe import Data.Coerce import Data.Foldable -import Data.Functor ((<&>)) import Data.Generics (everything, gcount, mkQ) -import Data.Generics.Product (field') import Data.List (sortBy) import qualified Data.Map as M -import Data.Maybe (mapMaybe, isNothing) -import Data.Monoid (getSum) +import Data.Maybe (isNothing) import Data.Ord (Down (..), comparing) import qualified Data.Set as S -import Data.Traversable (for) -import Development.IDE.Core.Compile (lookupName) import Development.IDE.GHC.Compat hiding (isTopLevel, empty) import Refinery.Future import Refinery.ProofState import Refinery.Tactic import Refinery.Tactic.Internal import System.Timeout (timeout) -import Wingman.Context (getInstance) -import Wingman.GHC (tryUnifyUnivarsButNotSkolems, updateSubst, tacticsGetDataCons, freshTyvars, tryUnifyUnivarsButNotSkolemsMany) +import Wingman.GHC (tryUnifyUnivarsButNotSkolems, updateSubst, tacticsGetDataCons, freshTyvars) import Wingman.Judgements import Wingman.Simplify (simplify) import Wingman.Types -#if __GLASGOW_HASKELL__ < 900 -import FunDeps (fd_eqs, improveFromInstEnv) -import Pair (unPair) -#else -import GHC.Tc.Instance.FunDeps (fd_eqs, improveFromInstEnv) -import GHC.Data.Pair (unPair) -#endif - substCTy :: TCvSubst -> CType -> CType substCTy subst = coerce . substTy subst . coerce @@ -67,13 +50,10 @@ newSubgoal :: Judgement -> Rule newSubgoal j = do - ctx <- ask unifier <- getSubstForJudgement j subgoal - $ normalizeJudgement ctx $ substJdg unifier - $ unsetIsTopHole - $ normalizeJudgement ctx j + $ unsetIsTopHole j tacticToRule :: Judgement -> TacticsM () -> Rule @@ -93,7 +73,7 @@ consumeChan chan = do -- a given tactic. runTactic :: Int -- ^ Timeout - -> Context + -> Config -> Judgement -> TacticsM () -- ^ Tactic to use -> IO (Either [TacticError] RunTacticResults) @@ -125,13 +105,10 @@ runTactic duration ctx jdg t = do flip sortBy solns $ comparing $ \(Proof ext _ holes) -> Down $ scoreSolution ext jdg $ fmap snd holes case sorted of - ((Proof syn _ subgoals) : _) -> + ((Proof syn _ _) : _) -> pure $ Right $ RunTacticResults - { rtr_trace = syn_trace syn - , rtr_extract = simplify $ syn_val syn - , rtr_subgoals = fmap snd subgoals - , rtr_other_solns = reverse . fmap pf_extract $ sorted + { rtr_extract = simplify $ syn_val syn , rtr_jdg = jdg , rtr_ctx = ctx , rtr_timed_out = timed_out @@ -139,31 +116,6 @@ runTactic duration ctx jdg t = do _ -> fmap Left $ consumeChan out_errs -tracePrim :: String -> Trace -tracePrim = flip rose [] - - ------------------------------------------------------------------------------- --- | Mark that a tactic used the given string in its extract derivation. Mainly --- used for debugging the search when things go terribly wrong. -tracing - :: Functor m - => String - -> TacticT jdg (Synthesized ext) err s m a - -> TacticT jdg (Synthesized ext) err s m a -tracing s = mappingExtract (mapTrace $ rose s . pure) - - ------------------------------------------------------------------------------- --- | Mark that a tactic performed recursion. Doing so incurs a small penalty in --- the score. -markRecursion - :: Functor m - => TacticT jdg (Synthesized ext) err s m a - -> TacticT jdg (Synthesized ext) err s m a -markRecursion = mappingExtract (field' @"syn_recursion_count" <>~ 1) - - ------------------------------------------------------------------------------ -- | Map a function over the extract created by a tactic. mappingExtract @@ -187,36 +139,12 @@ scoreSolution -> Judgement -> [Judgement] -> ( Penalize Int -- number of holes - , Reward Bool -- all bindings used - , Penalize Int -- unused top-level bindings - , Penalize Int -- number of introduced bindings - , Reward Int -- number used bindings - , Penalize Int -- number of recursive calls , Penalize Int -- size of extract ) -scoreSolution ext goal holes +scoreSolution ext _ holes = ( Penalize $ length holes - , Reward $ S.null $ intro_vals S.\\ used_vals - , Penalize $ S.size unused_top_vals - , Penalize $ S.size intro_vals - , Reward $ S.size used_vals + length used_user_vals - , Penalize $ getSum $ syn_recursion_count ext , Penalize $ solutionSize $ syn_val ext ) - where - initial_scope = hyByName $ jEntireHypothesis goal - intro_vals = M.keysSet $ hyByName $ syn_scoped ext - used_vals = S.intersection intro_vals $ syn_used_vals ext - used_user_vals = filter (isLocalHypothesis . hi_provenance) - $ mapMaybe (flip M.lookup initial_scope) - $ S.toList - $ syn_used_vals ext - top_vals = S.fromList - . fmap hi_name - . filter (isTopLevel . hi_provenance) - . unHypothesis - $ syn_scoped ext - unused_top_vals = top_vals S.\\ used_vals ------------------------------------------------------------------------------ @@ -254,22 +182,6 @@ unify goal inst = do modify $ updateSubst subst Nothing -> cut ------------------------------------------------------------------------------- --- | Get a substitution out of a theta's fundeps -learnFromFundeps - :: ThetaType - -> RuleM () -learnFromFundeps theta = do - inst_envs <- asks ctxInstEnvs - skolems <- gets ts_skolems - subst <- gets ts_unifier - let theta' = substTheta subst theta - fundeps = foldMap (foldMap fd_eqs . improveFromInstEnv inst_envs (\_ _ -> ())) theta' - case tryUnifyUnivarsButNotSkolemsMany skolems $ fmap unPair fundeps of - Just subst -> - modify $ updateSubst subst - Nothing -> cut - cut :: RuleT jdg ext err s m a cut = RuleT Empty @@ -344,97 +256,6 @@ useNameFromHypothesis f name = do Just hi -> f hi Nothing -> failure $ NotInScope name ------------------------------------------------------------------------------- --- | Lift a function over 'HyInfo's to one that takes an 'OccName' and tries to --- look it up in the hypothesis. -useNameFromContext :: (HyInfo CType -> TacticsM a) -> OccName -> TacticsM a -useNameFromContext f name = do - lookupNameInContext name >>= \case - Just ty -> f $ createImportedHyInfo name ty - Nothing -> failure $ NotInScope name - - ------------------------------------------------------------------------------- --- | Find the type of an 'OccName' that is defined in the current module. -lookupNameInContext :: MonadReader Context m => OccName -> m (Maybe CType) -lookupNameInContext name = do - ctx <- asks ctxModuleFuncs - pure $ case find ((== name) . fst) ctx of - Just (_, ty) -> pure ty - Nothing -> empty - - -getDefiningType - :: TacticsM CType -getDefiningType = do - calling_fun_name <- asks (fst . head . ctxDefiningFuncs) - maybe - (failure $ NotInScope calling_fun_name) - pure - =<< lookupNameInContext calling_fun_name - - ------------------------------------------------------------------------------- --- | Build a 'HyInfo' for an imported term. -createImportedHyInfo :: OccName -> CType -> HyInfo CType -createImportedHyInfo on ty = HyInfo - { hi_name = on - , hi_provenance = ImportPrv - , hi_type = ty - } - - -getTyThing - :: OccName - -> TacticsM (Maybe TyThing) -getTyThing occ = do - ctx <- ask - case lookupOccEnv (ctx_occEnv ctx) occ of - Just (elt : _) -> do - mvar <- lift - $ ExtractM - $ lift - $ lookupName (ctx_hscEnv ctx) (ctx_module ctx) - $ gre_name elt - pure mvar - _ -> pure Nothing - - ------------------------------------------------------------------------------- --- | Like 'getTyThing' but specialized to classes. -knownClass :: OccName -> TacticsM (Maybe Class) -knownClass occ = - getTyThing occ <&> \case - Just (ATyCon tc) -> tyConClass_maybe tc - _ -> Nothing - - ------------------------------------------------------------------------------- --- | Like 'getInstance', but uses a class that it just looked up. -getKnownInstance :: OccName -> [Type] -> TacticsM (Maybe (Class, PredType)) -getKnownInstance f tys = runMaybeT $ do - cls <- MaybeT $ knownClass f - MaybeT $ getInstance cls tys - - ------------------------------------------------------------------------------- --- | Lookup the type of any 'OccName' that was imported. Necessarily done in --- IO, so we only expose this functionality to the parser. Internal Haskell --- code that wants to lookup terms should do it via 'KnownThings'. -getOccNameType - :: OccName - -> TacticsM Type -getOccNameType occ = do - getTyThing occ >>= \case - Just (AnId v) -> pure $ varType v - _ -> failure $ NotInScope occ - - -getCurrentDefinitions :: TacticsM [(OccName, CType)] -getCurrentDefinitions = do - ctx_funcs <- asks ctxDefiningFuncs - for ctx_funcs $ \res@(occ, _) -> - pure . maybe res (occ,) =<< lookupNameInContext occ ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Lexer.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Lexer.hs deleted file mode 100644 index fed7e91bbd..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Lexer.hs +++ /dev/null @@ -1,99 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE OverloadedStrings #-} - -module Wingman.Metaprogramming.Lexer where - -import Control.Applicative -import Control.Monad -import Data.Foldable (asum) -import Data.Text (Text) -import qualified Data.Text as T -import Data.Void -import Development.IDE.GHC.Compat.Core (OccName, mkVarOcc) -import qualified Text.Megaparsec as P -import qualified Text.Megaparsec.Char as P -import qualified Text.Megaparsec.Char.Lexer as L - -type Parser = P.Parsec Void Text - - - -lineComment :: Parser () -lineComment = L.skipLineComment "--" - -blockComment :: Parser () -blockComment = L.skipBlockComment "{-" "-}" - -sc :: Parser () -sc = L.space P.space1 lineComment blockComment - -ichar :: Parser Char -ichar = P.alphaNumChar <|> P.char '_' <|> P.char '\'' - -symchar :: Parser Char -symchar = asum - [ P.symbolChar - , P.char '!' - , P.char '#' - , P.char '$' - , P.char '%' - , P.char '^' - , P.char '&' - , P.char '*' - , P.char '-' - , P.char '=' - , P.char '+' - , P.char ':' - , P.char '<' - , P.char '>' - , P.char ',' - , P.char '.' - , P.char '/' - , P.char '?' - , P.char '~' - , P.char '|' - , P.char '\\' - ] - -lexeme :: Parser a -> Parser a -lexeme = L.lexeme sc - -symbol :: Text -> Parser Text -symbol = L.symbol sc - -symbol_ :: Text -> Parser () -symbol_ = void . symbol - -brackets :: Parser a -> Parser a -brackets = P.between (symbol "[") (symbol "]") - -braces :: Parser a -> Parser a -braces = P.between (symbol "{") (symbol "}") - -parens :: Parser a -> Parser a -parens = P.between (symbol "(") (symbol ")") - -identifier :: Text -> Parser () -identifier i = lexeme (P.string i *> P.notFollowedBy ichar) - -variable :: Parser OccName -variable = lexeme $ do - c <- P.alphaNumChar <|> P.char '(' - fmap mkVarOcc $ case c of - '(' -> do - cs <- P.many symchar - void $ P.char ')' - pure cs - _ -> do - cs <- P.many ichar - pure $ c : cs - -name :: Parser Text -name = lexeme $ do - c <- P.alphaNumChar - cs <- P.many (ichar <|> P.char '-') - pure $ T.pack (c:cs) - -keyword :: Text -> Parser () -keyword = identifier - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs deleted file mode 100644 index a1d4eca4d4..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs +++ /dev/null @@ -1,501 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TypeApplications #-} - -module Wingman.Metaprogramming.Parser where - -import qualified Control.Monad.Combinators.Expr as P -import Data.Either (fromRight) -import Data.Functor -import Data.Maybe (listToMaybe) -import qualified Data.Text as T -import Development.IDE.GHC.Compat (RealSrcLoc, srcLocLine, srcLocCol, srcLocFile) -import Development.IDE.GHC.Compat.Util (unpackFS) -import Refinery.Tactic (failure) -import qualified Refinery.Tactic as R -import qualified Text.Megaparsec as P -import Wingman.Auto -import Wingman.Machinery (useNameFromHypothesis, useNameFromContext, getCurrentDefinitions) -import Wingman.Metaprogramming.Lexer -import Wingman.Metaprogramming.Parser.Documentation -import Wingman.Metaprogramming.ProofState (proofState, layout) -import Wingman.Tactics -import Wingman.Types - - -nullary :: T.Text -> TacticsM () -> Parser (TacticsM ()) -nullary name tac = identifier name $> tac - - -unary_occ :: T.Text -> (OccName -> TacticsM ()) -> Parser (TacticsM ()) -unary_occ name tac = tac <$> (identifier name *> variable) - - ------------------------------------------------------------------------------- --- | Like 'unary_occ', but runs directly in the 'Parser' monad. -unary_occM :: T.Text -> (OccName -> Parser (TacticsM ())) -> Parser (TacticsM ()) -unary_occM name tac = tac =<< (identifier name *> variable) - - -variadic_occ :: T.Text -> ([OccName] -> TacticsM ()) -> Parser (TacticsM ()) -variadic_occ name tac = tac <$> (identifier name *> P.many variable) - - -commands :: [SomeMetaprogramCommand] -commands = - [ command "assumption" Nondeterministic Nullary - "Use any term in the hypothesis that can unify with the current goal." - (pure assumption) - [ Example - Nothing - [] - [EHI "some_a_val" "a"] - (Just "a") - "some_a_val" - ] - - , command "assume" Deterministic (Ref One) - "Use the given term from the hypothesis, unifying it with the current goal" - (pure . assume) - [ Example - Nothing - ["some_a_val"] - [EHI "some_a_val" "a"] - (Just "a") - "some_a_val" - ] - - , command "intros" Deterministic (Bind Many) - ( mconcat - [ "Construct a lambda expression, using the specific names if given, " - , "generating unique names otherwise. When no arguments are given, " - , "all of the function arguments will be bound; otherwise, this " - , "tactic will bind only enough to saturate the given names. Extra " - , "names are ignored." - ]) - (pure . \case - [] -> intros - names -> intros' $ IntroduceOnlyNamed names - ) - [ Example - Nothing - [] - [] - (Just "a -> b -> c -> d") - "\\a b c -> (_ :: d)" - , Example - Nothing - ["aye"] - [] - (Just "a -> b -> c -> d") - "\\aye -> (_ :: b -> c -> d)" - , Example - Nothing - ["x", "y", "z", "w"] - [] - (Just "a -> b -> c -> d") - "\\x y z -> (_ :: d)" - ] - - , command "idiom" Deterministic Tactic - "Lift a tactic into idiom brackets." - (pure . idiom) - [ Example - Nothing - ["(apply f)"] - [EHI "f" "a -> b -> Int"] - (Just "Maybe Int") - "f <$> (_ :: Maybe a) <*> (_ :: Maybe b)" - ] - - , command "intro" Deterministic (Bind One) - "Construct a lambda expression, binding an argument with the given name." - (pure . intros' . IntroduceOnlyNamed . pure) - [ Example - Nothing - ["aye"] - [] - (Just "a -> b -> c -> d") - "\\aye -> (_ :: b -> c -> d)" - ] - - , command "destruct_all" Deterministic Nullary - "Pattern match on every function paramater, in original binding order." - (pure destructAll) - [ Example - (Just "Assume `a` and `b` were bound via `f a b = _`.") - [] - [EHI "a" "Bool", EHI "b" "Maybe Int"] - Nothing $ - T.pack $ init $ unlines - [ "case a of" - , " False -> case b of" - , " Nothing -> _" - , " Just i -> _" - , " True -> case b of" - , " Nothing -> _" - , " Just i -> _" - ] - ] - - , command "destruct" Deterministic (Ref One) - "Pattern match on the argument." - (pure . useNameFromHypothesis destruct) - [ Example - Nothing - ["a"] - [EHI "a" "Bool"] - Nothing $ - T.pack $ init $ unlines - [ "case a of" - , " False -> _" - , " True -> _" - ] - ] - - , command "homo" Deterministic (Ref One) - ( mconcat - [ "Pattern match on the argument, and fill the resulting hole in with " - , "the same data constructor." - ]) - (pure . useNameFromHypothesis homo) - [ Example - (Just $ mconcat - [ "Only applicable when the type constructor of the argument is " - , "the same as that of the hole." - ]) - ["e"] - [EHI "e" "Either a b"] - (Just "Either x y") $ - T.pack $ init $ unlines - [ "case e of" - , " Left a -> Left (_ :: x)" - , " Right b -> Right (_ :: y)" - ] - ] - - , command "application" Nondeterministic Nullary - "Apply any function in the hypothesis that returns the correct type." - (pure application) - [ Example - Nothing - [] - [EHI "f" "a -> b"] - (Just "b") - "f (_ :: a)" - ] - - , command "pointwise" Deterministic Tactic - "Restrict the hypothesis in the holes of the given tactic to align up with the top-level bindings. This will ensure, eg, that the first hole can see only terms that came from the first position in any terms destructed from the top-level bindings." - (pure . flip restrictPositionForApplication (pure ())) - [ Example - (Just "In the context of `f (a1, b1) (a2, b2) = _`. The resulting first hole can see only 'a1' and 'a2', and the second, only 'b1' and 'b2'.") - ["(use mappend)"] - [] - Nothing - "mappend _ _" - ] - - , command "apply" Deterministic (Ref One) - "Apply the given function from *local* scope." - (pure . useNameFromHypothesis (apply Saturated)) - [ Example - Nothing - ["f"] - [EHI "f" "a -> b"] - (Just "b") - "f (_ :: a)" - ] - - , command "split" Nondeterministic Nullary - "Produce a data constructor for the current goal." - (pure split) - [ Example - Nothing - [] - [] - (Just "Either a b") - "Right (_ :: b)" - ] - - , command "ctor" Deterministic (Ref One) - "Use the given data cosntructor." - (pure . userSplit) - [ Example - Nothing - ["Just"] - [] - (Just "Maybe a") - "Just (_ :: a)" - ] - - , command "obvious" Nondeterministic Nullary - "Produce a nullary data constructor for the current goal." - (pure obvious) - [ Example - Nothing - [] - [] - (Just "[a]") - "[]" - ] - - , command "auto" Nondeterministic Nullary - ( mconcat - [ "Repeatedly attempt to split, destruct, apply functions, and " - , "recurse in an attempt to fill the hole." - ]) - (pure auto) - [ Example - Nothing - [] - [EHI "f" "a -> b", EHI "g" "b -> c"] - (Just "a -> c") - "g . f" - ] - - , command "sorry" Deterministic Nullary - "\"Solve\" the goal by leaving a hole." - (pure sorry) - [ Example - Nothing - [] - [] - (Just "b") - "_ :: b" - ] - - , command "unary" Deterministic Nullary - ( mconcat - [ "Produce a hole for a single-parameter function, as well as a hole for " - , "its argument. The argument holes are completely unconstrained, and " - , "will be solved before the function." - ]) - (pure $ nary 1) - [ Example - (Just $ mconcat - [ "In the example below, the variable `a` is free, and will unify " - , "to the resulting extract from any subsequent tactic." - ]) - [] - [] - (Just "Int") - "(_2 :: a -> Int) (_1 :: a)" - ] - - , command "binary" Deterministic Nullary - ( mconcat - [ "Produce a hole for a two-parameter function, as well as holes for " - , "its arguments. The argument holes have the same type but are " - , "otherwise unconstrained, and will be solved before the function." - ]) - (pure $ nary 2) - [ Example - (Just $ mconcat - [ "In the example below, the variable `a` is free, and will unify " - , "to the resulting extract from any subsequent tactic." - ]) - [] - [] - (Just "Int") - "(_3 :: a -> a -> Int) (_1 :: a) (_2 :: a)" - ] - - , command "recursion" Deterministic Nullary - "Fill the current hole with a call to the defining function." - ( pure $ - fmap listToMaybe getCurrentDefinitions >>= \case - Just (self, _) -> useNameFromContext (apply Saturated) self - Nothing -> failure $ TacticPanic "no defining function" - ) - [ Example - (Just "In the context of `foo (a :: Int) (b :: b) = _`:") - [] - [] - Nothing - "foo (_ :: Int) (_ :: b)" - ] - - , command "use" Deterministic (Ref One) - "Apply the given function from *module* scope." - (pure . use Saturated) - [ Example - (Just "`import Data.Char (isSpace)`") - ["isSpace"] - [] - (Just "Bool") - "isSpace (_ :: Char)" - ] - - , command "cata" Deterministic (Ref One) - "Destruct the given term, recursing on every resulting binding." - (pure . useNameFromHypothesis cata) - [ Example - (Just "Assume we're called in the context of a function `f.`") - ["x"] - [EHI "x" "(a, a)"] - Nothing $ - T.pack $ init $ unlines - [ "case x of" - , " (a1, a2) ->" - , " let a1_c = f a1" - , " a2_c = f a2" - , " in _" - ] - ] - - , command "collapse" Deterministic Nullary - "Collapse every term in scope with the same type as the goal." - (pure collapse) - [ Example - Nothing - [] - [ EHI "a1" "a" - , EHI "a2" "a" - , EHI "a3" "a" - ] - (Just "a") - "(_ :: a -> a -> a -> a) a1 a2 a3" - ] - - , command "let" Deterministic (Bind Many) - "Create let-bindings for each binder given to this tactic." - (pure . letBind) - [ Example - Nothing - ["a", "b", "c"] - [ ] - (Just "x") - $ T.pack $ unlines - [ "let a = _1 :: a" - , " b = _2 :: b" - , " c = _3 :: c" - , " in (_4 :: x)" - ] - ] - - , command "try" Nondeterministic Tactic - "Simultaneously run and do not run a tactic. Subsequent tactics will bind on both states." - (pure . R.try) - [ Example - Nothing - ["(apply f)"] - [ EHI "f" "a -> b" - ] - (Just "b") - $ T.pack $ unlines - [ "-- BOTH of:\n" - , "f (_ :: a)" - , "\n-- and\n" - , "_ :: b" - ] - ] - - , command "nested" Nondeterministic (Ref One) - "Nest the given function (in module scope) with itself arbitrarily many times. NOTE: The resulting function is necessarily unsaturated, so you will likely need `with_arg` to use this tactic in a saturated context." - (pure . nested) - [ Example - Nothing - ["fmap"] - [] - (Just "[(Int, Either Bool a)] -> [(Int, Either Bool b)]") - "fmap (fmap (fmap _))" - ] - - , command "with_arg" Deterministic Nullary - "Fill the current goal with a function application. This can be useful when you'd like to fill in the argument before the function, or when you'd like to use a non-saturated function in a saturated context." - (pure with_arg) - [ Example - (Just "Where `a` is a new unifiable type variable.") - [] - [] - (Just "r") - "(_2 :: a -> r) (_1 :: a)" - ] - ] - - - -oneTactic :: Parser (TacticsM ()) -oneTactic = - P.choice - [ parens tactic - , makeParser commands - ] - - -tactic :: Parser (TacticsM ()) -tactic = P.makeExprParser oneTactic operators - -operators :: [[P.Operator Parser (TacticsM ())]] -operators = - [ [ P.InfixR (symbol "|" $> (R.<%>) )] - , [ P.InfixL (symbol ";" $> (>>)) - , P.InfixL (symbol "," $> bindOne) - ] - ] - - -tacticProgram :: Parser (TacticsM ()) -tacticProgram = do - sc - r <- tactic P.<|> pure (pure ()) - P.eof - pure r - - -wrapError :: String -> String -wrapError err = "```\n" <> err <> "\n```\n" - - -fixErrorOffset :: RealSrcLoc -> P.ParseErrorBundle a b -> P.ParseErrorBundle a b -fixErrorOffset rsl (P.ParseErrorBundle ne (P.PosState a n (P.SourcePos _ line col) pos s)) - = P.ParseErrorBundle ne - $ P.PosState a n - (P.SourcePos - (unpackFS $ srcLocFile rsl) - ((<>) line $ P.mkPos $ srcLocLine rsl - 1) - ((<>) col $ P.mkPos $ srcLocCol rsl - 1 + length @[] "[wingman|") - ) - pos - s - ------------------------------------------------------------------------------- --- | Attempt to run a metaprogram tactic, returning the proof state, or the --- errors. -attempt_it - :: RealSrcLoc - -> Context - -> Judgement - -> String - -> IO (Either String String) -attempt_it rsl ctx jdg program = - case P.runParser tacticProgram "" (T.pack program) of - Left peb -> pure $ Left $ wrapError $ P.errorBundlePretty $ fixErrorOffset rsl peb - Right tt -> do - res <- runTactic 2e6 ctx jdg tt - pure $ case res of - Left tes -> Left $ wrapError $ show tes - Right rtr -> Right - $ layout (cfg_proofstate_styling $ ctxConfig ctx) - $ proofState rtr - - -parseMetaprogram :: T.Text -> TacticsM () -parseMetaprogram - = fromRight (pure ()) - . P.runParser tacticProgram "" - - ------------------------------------------------------------------------------- --- | Automatically generate the metaprogram command reference. -writeDocumentation :: IO () -writeDocumentation = - writeFile "COMMANDS.md" $ - unlines - [ "# Wingman Metaprogram Command Reference" - , "" - , prettyReadme commands - ] - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs-boot b/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs-boot deleted file mode 100644 index 607db0e6f3..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser.hs-boot +++ /dev/null @@ -1,7 +0,0 @@ -module Wingman.Metaprogramming.Parser where - -import Wingman.Metaprogramming.Lexer -import Wingman.Types - -tactic :: Parser (TacticsM ()) - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser/Documentation.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser/Documentation.hs deleted file mode 100644 index 44071a5ae7..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/Parser/Documentation.hs +++ /dev/null @@ -1,237 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -Wno-deprecations #-} - -module Wingman.Metaprogramming.Parser.Documentation where - -import Data.Functor ((<&>)) -import Data.List (sortOn) -import Data.String (IsString) -import Data.Text (Text) -import Data.Text.Prettyprint.Doc hiding (parens) -import Data.Text.Prettyprint.Doc.Render.String (renderString) -import Development.IDE.GHC.Compat (OccName) -import qualified Text.Megaparsec as P -import Wingman.Metaprogramming.Lexer (Parser, identifier, variable, parens) -import Wingman.Types (TacticsM) - -import {-# SOURCE #-} Wingman.Metaprogramming.Parser (tactic) - - ------------------------------------------------------------------------------- --- | Is a tactic deterministic or not? -data Determinism - = Deterministic - | Nondeterministic - -prettyDeterminism :: Determinism -> Doc b -prettyDeterminism Deterministic = "deterministic" -prettyDeterminism Nondeterministic = "non-deterministic" - - ------------------------------------------------------------------------------- --- | How many arguments does the tactic take? -data Count a where - One :: Count OccName - Many :: Count [OccName] - -prettyCount :: Count a -> Doc b -prettyCount One = "single" -prettyCount Many = "variadic" - - ------------------------------------------------------------------------------- --- | What sorts of arguments does the tactic take? Currently there is no --- distinction between 'Ref' and 'Bind', other than documentation. --- --- The type index here is used for the shape of the function the parser should --- take. -data Syntax a where - Nullary :: Syntax (Parser (TacticsM ())) - Ref :: Count a -> Syntax (a -> Parser (TacticsM ())) - Bind :: Count a -> Syntax (a -> Parser (TacticsM ())) - Tactic :: Syntax (TacticsM () -> Parser (TacticsM ())) - -prettySyntax :: Syntax a -> Doc b -prettySyntax Nullary = "none" -prettySyntax (Ref co) = prettyCount co <+> "reference" -prettySyntax (Bind co) = prettyCount co <+> "binding" -prettySyntax Tactic = "tactic" - - ------------------------------------------------------------------------------- --- | An example for the documentation. -data Example = Example - { ex_ctx :: Maybe Text -- ^ Specific context information about when the tactic is applicable - , ex_args :: [Var] -- ^ Arguments the tactic was called with - , ex_hyp :: [ExampleHyInfo] -- ^ The hypothesis - , ex_goal :: Maybe ExampleType -- ^ Current goal. Nothing indicates it's uninteresting. - , ex_result :: Text -- ^ Resulting extract. - } - - ------------------------------------------------------------------------------- --- | An example 'HyInfo'. -data ExampleHyInfo = EHI - { ehi_name :: Var -- ^ Name of the variable - , ehi_type :: ExampleType -- ^ Type of the variable - } - - ------------------------------------------------------------------------------- --- | A variable -newtype Var = Var - { getVar :: Text - } - deriving newtype (IsString, Pretty) - - ------------------------------------------------------------------------------- --- | A type -newtype ExampleType = ExampleType - { getExampleType :: Text - } - deriving newtype (IsString, Pretty) - - ------------------------------------------------------------------------------- --- | A command to expose to the parser -data MetaprogramCommand a = MC - { mpc_name :: Text -- ^ Name of the command. This is the token necessary to run the command. - , mpc_syntax :: Syntax a -- ^ The command's arguments - , mpc_det :: Determinism -- ^ Determinism of the command - , mpc_description :: Text -- ^ User-facing description - , mpc_tactic :: a -- ^ Tactic to run - , mpc_examples :: [Example] -- ^ Collection of documentation examples - } - ------------------------------------------------------------------------------- --- | Existentialize the pain away -data SomeMetaprogramCommand where - SMC :: MetaprogramCommand a -> SomeMetaprogramCommand - - ------------------------------------------------------------------------------- --- | Run the 'Parser' of a 'MetaprogramCommand' -makeMPParser :: MetaprogramCommand a -> Parser (TacticsM ()) -makeMPParser (MC name Nullary _ _ t _) = do - identifier name - t -makeMPParser (MC name (Ref One) _ _ t _) = do - identifier name - variable >>= t -makeMPParser (MC name (Ref Many) _ _ t _) = do - identifier name - P.many variable >>= t -makeMPParser (MC name (Bind One) _ _ t _) = do - identifier name - variable >>= t -makeMPParser (MC name (Bind Many) _ _ t _) = do - identifier name - P.many variable >>= t -makeMPParser (MC name Tactic _ _ t _) = do - identifier name - parens tactic >>= t - - ------------------------------------------------------------------------------- --- | Compile a collection of metaprogram commands into a parser. -makeParser :: [SomeMetaprogramCommand] -> Parser (TacticsM ()) -makeParser ps = P.choice $ ps <&> \(SMC mp) -> makeMPParser mp - - ------------------------------------------------------------------------------- --- | Pretty print a command. -prettyCommand :: MetaprogramCommand a -> Doc b -prettyCommand (MC name syn det desc _ exs) = vsep - [ "##" <+> pretty name - , mempty - , "arguments:" <+> prettySyntax syn <> ". " - , prettyDeterminism det <> "." - , mempty - , ">" <+> align (pretty desc) - , mempty - , vsep $ fmap (prettyExample name) exs - , mempty - ] - - ------------------------------------------------------------------------------- --- | Pretty print a hypothesis. -prettyHyInfo :: ExampleHyInfo -> Doc a -prettyHyInfo hi = pretty (ehi_name hi) <+> "::" <+> pretty (ehi_type hi) - - ------------------------------------------------------------------------------- --- | Append the given term only if the first argument has elements. -mappendIfNotNull :: [a] -> a -> [a] -mappendIfNotNull [] _ = [] -mappendIfNotNull as a = as <> [a] - - ------------------------------------------------------------------------------- --- | Pretty print an example. -prettyExample :: Text -> Example -> Doc a -prettyExample name (Example m_txt args hys goal res) = - align $ vsep - [ mempty - , "### Example" - , maybe mempty ((line <>) . (<> line) . (">" <+>) . align . pretty) m_txt - , "Given:" - , mempty - , codeFence $ vsep - $ mappendIfNotNull (fmap prettyHyInfo hys) mempty - <> [ "_" <+> maybe mempty (("::" <+>). pretty) goal - ] - , mempty - , hsep - [ "running " - , enclose "`" "`" $ pretty name <> hsep (mempty : fmap pretty args) - , "will produce:" - ] - , mempty - , codeFence $ align $ pretty res - ] - - ------------------------------------------------------------------------------- --- | Make a haskell code fence. -codeFence :: Doc a -> Doc a -codeFence d = align $ vsep - [ "```haskell" - , d - , "```" - ] - - ------------------------------------------------------------------------------- --- | Render all of the commands. -prettyReadme :: [SomeMetaprogramCommand] -> String -prettyReadme - = renderString - . layoutPretty defaultLayoutOptions - . vsep - . fmap (\case SMC c -> prettyCommand c) - . sortOn (\case SMC c -> mpc_name c) - - - ------------------------------------------------------------------------------- --- | Helper function to build a 'SomeMetaprogramCommand'. -command - :: Text - -> Determinism - -> Syntax a - -> Text - -> a - -> [Example] - -> SomeMetaprogramCommand -command txt det syn txt' a exs = SMC $ - MC - { mpc_name = txt - , mpc_det = det - , mpc_syntax = syn - , mpc_description = txt' - , mpc_tactic = a - , mpc_examples = exs - } - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/ProofState.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/ProofState.hs deleted file mode 100644 index 02e203a1d3..0000000000 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Metaprogramming/ProofState.hs +++ /dev/null @@ -1,117 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE OverloadedStrings #-} -{-# OPTIONS_GHC -Wno-deprecations #-} - -module Wingman.Metaprogramming.ProofState where - -import Data.Bool (bool) -import Data.Functor ((<&>)) -import qualified Data.Text as T -import Data.Text.Prettyprint.Doc -import Data.Text.Prettyprint.Doc.Render.Util.Panic -import Language.LSP.Types (sectionSeparator) -import Wingman.Judgements (jHypothesis) -import Wingman.Types - -renderSimplyDecorated - :: Monoid out - => (T.Text -> out) -- ^ Render plain 'Text' - -> (ann -> out) -- ^ How to render an annotation - -> (ann -> out) -- ^ How to render the removed annotation - -> SimpleDocStream ann - -> out -renderSimplyDecorated text push pop = go [] - where - go _ SFail = panicUncaughtFail - go [] SEmpty = mempty - go (_:_) SEmpty = panicInputNotFullyConsumed - go st (SChar c rest) = text (T.singleton c) <> go st rest - go st (SText _l t rest) = text t <> go st rest - go st (SLine i rest) = - text (T.singleton '\n') <> text (textSpaces i) <> go st rest - go st (SAnnPush ann rest) = push ann <> go (ann : st) rest - go (ann:st) (SAnnPop rest) = pop ann <> go st rest - go [] SAnnPop{} = panicUnpairedPop -{-# INLINE renderSimplyDecorated #-} - - -data Ann - = Goal - | Hypoth - | Status - deriving (Eq, Ord, Show, Enum, Bounded) - -forceMarkdownNewlines :: String -> String -forceMarkdownNewlines = unlines . fmap (<> " ") . lines - -layout :: Bool -> Doc Ann -> String -layout use_styling - = forceMarkdownNewlines - . T.unpack - . renderSimplyDecorated id - (renderAnn use_styling) - (renderUnann use_styling) - . layoutPretty (LayoutOptions $ AvailablePerLine 80 0.6) - -renderAnn :: Bool -> Ann -> T.Text -renderAnn False _ = "" -renderAnn _ Goal = "" -renderAnn _ Hypoth = "```haskell\n" -renderAnn _ Status = "" - -renderUnann :: Bool -> Ann -> T.Text -renderUnann False _ = "" -renderUnann _ Goal = "" -renderUnann _ Hypoth = "\n```\n" -renderUnann _ Status = "" - -proofState :: RunTacticResults -> Doc Ann -proofState RunTacticResults{rtr_subgoals} = - vsep - $ ( annotate Status - . countFinished "goals accomplished 🎉" "goal" - $ length rtr_subgoals - ) - : pretty sectionSeparator - : fmap prettySubgoal rtr_subgoals - - -prettySubgoal :: Judgement -> Doc Ann -prettySubgoal jdg = - vsep $ - [ mempty | has_hy] <> - [ annotate Hypoth $ prettyHypothesis hy | has_hy] <> - [ "⊢" <+> annotate Goal (prettyType (_jGoal jdg)) - , pretty sectionSeparator - ] - where - hy = jHypothesis jdg - has_hy = not $ null $ unHypothesis hy - - -prettyHypothesis :: Hypothesis CType -> Doc Ann -prettyHypothesis hy = - vsep $ unHypothesis hy <&> \hi -> - prettyHyInfo hi - -prettyHyInfo :: HyInfo CType -> Doc Ann -prettyHyInfo hi = viaShow (hi_name hi) <+> "::" <+> prettyType (hi_type hi) - - -prettyType :: CType -> Doc Ann -prettyType (CType ty) = viaShow ty - - -countFinished :: Doc Ann -> Doc Ann -> Int -> Doc Ann -countFinished finished _ 0 = finished -countFinished _ thing n = count thing n - -count :: Doc Ann -> Int -> Doc Ann -count thing n = - pretty n <+> thing <> bool "" "s" (n /= 1) - -textSpaces :: Int -> T.Text -textSpaces n = T.replicate n $ T.singleton ' ' - - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs index b55ee31ae3..c5ef071f45 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs @@ -3,22 +3,20 @@ module Wingman.Plugin where import Control.Monad import Development.IDE.Core.Shake (IdeState (..)) +import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) import Development.IDE.Plugin.CodeAction import qualified Development.IDE.GHC.ExactPrint as E import Ide.Types -import Language.LSP.Types import Prelude hiding (span) import Wingman.AbstractLSP import Wingman.AbstractLSP.TacticActions (makeTacticInteraction) import Wingman.EmptyCase -import Wingman.LanguageServer hiding (Log) import qualified Wingman.LanguageServer as WingmanLanguageServer -import Wingman.LanguageServer.Metaprogram (hoverProvider) +import Wingman.LanguageServer hiding (Log) import Wingman.StaticPlugin -import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) data Log - = LogWingmanLanguageServer WingmanLanguageServer.Log + = LogWingmanLanguageServer WingmanLanguageServer.Log | LogExactPrint E.Log deriving Show @@ -35,8 +33,7 @@ descriptor recorder plId : fmap makeTacticInteraction [minBound .. maxBound] ) $ (defaultPluginDescriptor plId) - { pluginHandlers = mkPluginHandler STextDocumentHover hoverProvider - , pluginRules = wingmanRules (cmapWithPrio LogWingmanLanguageServer recorder) plId + { pluginRules = wingmanRules (cmapWithPrio LogWingmanLanguageServer recorder) plId , pluginConfigDescriptor = defaultConfigDescriptor { configCustomConfig = mkCustomConfig properties diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs b/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs index 42065aa289..0aa5834484 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs @@ -2,25 +2,13 @@ module Wingman.StaticPlugin ( staticPlugin - , metaprogramHoleName - , enableQuasiQuotes - , pattern WingmanMetaprogram - , pattern MetaprogramSyntax ) where import Development.IDE.GHC.Compat -import Development.IDE.GHC.Compat.Util +import GHC.LanguageExtensions.Type (Extension(EmptyCase)) import Ide.Types -import Data.Data -import Generics.SYB -#if __GLASGOW_HASKELL__ >= 900 -import GHC.Driver.Plugins (purePlugin) -#else -import Plugins (purePlugin) -#endif - staticPlugin :: DynFlagsModifications staticPlugin = mempty { dynFlagsModifyGlobal = @@ -31,31 +19,13 @@ staticPlugin = mempty { refLevelHoleFits = Just 0 , maxRefHoleFits = Just 0 , maxValidHoleFits = Just 0 - , staticPlugins = staticPlugins df <> [metaprogrammingPlugin] +#if __GLASGOW_HASKELL__ >= 808 + , staticPlugins = staticPlugins df +#endif } - , dynFlagsModifyParser = enableQuasiQuotes } -pattern MetaprogramSourceText :: SourceText -pattern MetaprogramSourceText = SourceText "wingman-meta-program" - - -pattern WingmanMetaprogram :: FastString -> HsExpr p -pattern WingmanMetaprogram mp <- -#if __GLASGOW_HASKELL__ >= 900 - HsPragE _ (HsPragSCC _ MetaprogramSourceText (StringLiteral NoSourceText mp)) - (L _ ( HsVar _ _)) -#else - HsSCC _ MetaprogramSourceText (StringLiteral NoSourceText mp) - (L _ ( HsVar _ _)) -#endif - - -enableQuasiQuotes :: DynFlags -> DynFlags -enableQuasiQuotes = flip xopt_set QuasiQuotes - - -- | Wingman wants to support destructing of empty cases, but these are a parse -- error by default. So we want to enable 'EmptyCase', but then that leads to -- silent errors without 'Opt_WarnIncompletePatterns'. @@ -63,49 +33,3 @@ allowEmptyCaseButWithWarning :: DynFlags -> DynFlags allowEmptyCaseButWithWarning = flip xopt_set EmptyCase . flip wopt_set Opt_WarnIncompletePatterns - -metaprogrammingPlugin :: StaticPlugin -metaprogrammingPlugin = - StaticPlugin $ PluginWithArgs pluginDefinition [] - where - pluginDefinition = defaultPlugin - { parsedResultAction = worker - , pluginRecompile = purePlugin - } - worker :: Monad m => [CommandLineOption] -> ModSummary -> HsParsedModule -> m HsParsedModule - worker _ _ pm = pure $ pm { hpm_module = addMetaprogrammingSyntax $ hpm_module pm } - -mkMetaprogram :: SrcSpan -> FastString -> HsExpr GhcPs -mkMetaprogram ss mp = -#if __GLASGOW_HASKELL__ >= 900 - HsPragE noExtField (HsPragSCC noExtField MetaprogramSourceText (StringLiteral NoSourceText mp)) -#else - HsSCC noExtField MetaprogramSourceText (StringLiteral NoSourceText mp) -#endif - $ L ss - $ HsVar noExtField - $ L ss - $ mkRdrUnqual metaprogramHoleName - -addMetaprogrammingSyntax :: Data a => a -> a -addMetaprogrammingSyntax = - everywhere $ mkT $ \case - L ss (MetaprogramSyntax mp) -> - L ss $ mkMetaprogram ss mp - (x :: LHsExpr GhcPs) -> x - -metaprogramHoleName :: OccName -metaprogramHoleName = mkVarOcc "_$metaprogram" - -pattern MetaprogramSyntax :: FastString -> HsExpr GhcPs -pattern MetaprogramSyntax mp <- - HsSpliceE _ (HsQuasiQuote _ _ (occNameString . rdrNameOcc -> "wingman") _ mp) - where - MetaprogramSyntax mp = - HsSpliceE noExtField $ - HsQuasiQuote - noExtField - (mkRdrUnqual $ mkVarOcc "splice") - (mkRdrUnqual $ mkVarOcc "wingman") - noSrcSpan - mp diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs index 10d87722cd..e24fb4da95 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs @@ -6,109 +6,26 @@ module Wingman.Tactics , runTactic ) where -import Control.Applicative (Alternative(empty), (<|>)) -import Control.Lens ((&), (%~), (<>~)) -import Control.Monad (filterM, unless) -import Control.Monad (when) -import Control.Monad.Extra (anyM) -import Control.Monad.Reader.Class (MonadReader (ask)) -import Control.Monad.State.Strict (StateT(..), runStateT, execStateT) +import Control.Lens ((&), (%~)) +import Control.Monad (unless) import Data.Bool (bool) import Data.Foldable -import Data.Functor ((<&>)) import Data.Generics.Labels () import Data.List -import Data.List.Extra (dropEnd, takeEnd) -import qualified Data.Map as M import Data.Maybe -import Data.Set (Set) import qualified Data.Set as S -import Data.Traversable (for) import Development.IDE.GHC.Compat hiding (empty) import GHC.Exts -import GHC.SourceGen ((@@)) import GHC.SourceGen.Expr import Refinery.Tactic -import Refinery.Tactic.Internal import Wingman.CodeGen import Wingman.GHC import Wingman.Judgements import Wingman.Machinery import Wingman.Naming -import Wingman.StaticPlugin (pattern MetaprogramSyntax) import Wingman.Types ------------------------------------------------------------------------------- --- | Use something in the hypothesis to fill the hole. -assumption :: TacticsM () -assumption = attemptOn (S.toList . allNames) assume - - ------------------------------------------------------------------------------- --- | Use something named in the hypothesis to fill the hole. -assume :: OccName -> TacticsM () -assume name = rule $ \jdg -> do - case M.lookup name $ hyByName $ jHypothesis jdg of - Just (hi_type -> ty) -> do - unify ty $ jGoal jdg - pure $ - -- This slightly terrible construct is producing a mostly-empty - -- 'Synthesized'; but there is no monoid instance to do something more - -- reasonable for a default value. - (pure (noLoc $ var' name)) - { syn_trace = tracePrim $ "assume " <> occNameString name - , syn_used_vals = S.singleton name <> getAncestry jdg name - } - Nothing -> cut - - ------------------------------------------------------------------------------- --- | Like 'apply', but uses an 'OccName' available in the context --- or the module -use :: Saturation -> OccName -> TacticsM () -use sat occ = do - ctx <- ask - ty <- case lookupNameInContext occ ctx of - Just ty -> pure ty - Nothing -> CType <$> getOccNameType occ - apply sat $ createImportedHyInfo occ ty - - -recursion :: TacticsM () --- TODO(sandy): This tactic doesn't fire for the @AutoThetaFix@ golden test, --- presumably due to running afoul of 'requireConcreteHole'. Look into this! -recursion = requireConcreteHole $ tracing "recursion" $ do - defs <- getCurrentDefinitions - attemptOn (const defs) $ \(name, ty) -> markRecursion $ do - jdg <- goal - -- Peek allows us to look at the extract produced by this block. - peek - ( do - let hy' = recursiveHypothesis defs - ctx <- ask - localTactic (apply Saturated $ HyInfo name RecursivePrv ty) (introduce ctx hy') - <@> fmap (localTactic assumption . filterPosition name) [0..] - ) $ \ext -> do - let pat_vals = jPatHypothesis jdg - -- Make sure that the recursive call contains at least one already-bound - -- pattern value. This ensures it is structurally smaller, and thus - -- suggests termination. - case any (flip M.member pat_vals) $ syn_used_vals ext of - True -> Nothing - False -> Just UnhelpfulRecursion - - -restrictPositionForApplication :: TacticsM () -> TacticsM () -> TacticsM () -restrictPositionForApplication f app = do - -- NOTE(sandy): Safe use of head; context is guaranteed to have a defining - -- binding - name <- head . fmap fst <$> getCurrentDefinitions - f <@> - fmap - (localTactic app . filterPosition name) [0..] - - ------------------------------------------------------------------------------ -- | Introduce a lambda binding every variable. intros :: TacticsM () @@ -133,25 +50,21 @@ intros' params = rule $ \jdg -> do (_, _, [], _) -> cut -- failure $ GoalMismatch "intros" g (_, _, scaledArgs, res) -> do let args = fmap scaledThing scaledArgs - ctx <- ask let gen_names = mkManyGoodNames (hyNamesInScope $ jEntireHypothesis jdg) args occs = case params of IntroduceAllUnnamed -> gen_names IntroduceOnlyNamed names -> names IntroduceOnlyUnnamed n -> take n gen_names num_occs = length occs - top_hole = isTopHole ctx jdg + top_hole = _jIsTopHole jdg bindings = zip occs $ coerce args bound_occs = fmap fst bindings - hy' = lambdaHypothesis top_hole bindings - jdg' = introduce ctx hy' + hy' = lambdaHypothesis (bool Nothing (error "TODO") top_hole) bindings + jdg' = introduce hy' $ withNewGoal (CType $ mkVisFunTys (drop num_occs scaledArgs) res) jdg ext <- newSubgoal jdg' pure $ ext - & #syn_trace %~ rose ("intros {" <> intercalate ", " (fmap show bound_occs) <> "}") - . pure - & #syn_scoped <>~ hy' & #syn_val %~ noLoc . lambda (fmap bvar' bound_occs) . unLoc @@ -173,61 +86,24 @@ introAndDestruct = do for_ hy destruct ------------------------------------------------------------------------------- --- | Case split, and leave holes in the matches. -destructAuto :: HyInfo CType -> TacticsM () -destructAuto hi = requireConcreteHole $ tracing "destruct(auto)" $ do - jdg <- goal - let subtactic = destructOrHomoAuto hi - case isPatternMatch $ hi_provenance hi of - True -> - pruning subtactic $ \jdgs -> - let getHyTypes = S.fromList . fmap hi_type . unHypothesis . jHypothesis - new_hy = foldMap getHyTypes jdgs - old_hy = getHyTypes jdg - in case S.null $ new_hy S.\\ old_hy of - True -> Just $ UnhelpfulDestruct $ hi_name hi - False -> Nothing - False -> subtactic - - ------------------------------------------------------------------------------- --- | When running auto, in order to prune the auto search tree, we try --- a homomorphic destruct whenever possible. If that produces any results, we --- can probably just prune the other side. -destructOrHomoAuto :: HyInfo CType -> TacticsM () -destructOrHomoAuto hi = tracing "destructOrHomoAuto" $ do - jdg <- goal - let g = unCType $ jGoal jdg - ty = unCType $ hi_type hi - - attemptWhen - (rule $ destruct' False (\dc jdg -> - buildDataCon False jdg dc $ snd $ splitAppTys g) hi) - (rule $ destruct' False (const newSubgoal) hi) - $ case (splitTyConApp_maybe g, splitTyConApp_maybe ty) of - (Just (gtc, _), Just (tytc, _)) -> gtc == tytc - _ -> False - - ------------------------------------------------------------------------------ -- | Case split, and leave holes in the matches. destruct :: HyInfo CType -> TacticsM () -destruct hi = requireConcreteHole $ tracing "destruct(user)" $ +destruct hi = requireConcreteHole $ rule $ destruct' False (const newSubgoal) hi ------------------------------------------------------------------------------ -- | Case split, and leave holes in the matches. Performs record punning. destructPun :: HyInfo CType -> TacticsM () -destructPun hi = requireConcreteHole $ tracing "destructPun(user)" $ +destructPun hi = requireConcreteHole $ rule $ destruct' True (const newSubgoal) hi ------------------------------------------------------------------------------ -- | Case split, using the same data constructor in the matches. homo :: HyInfo CType -> TacticsM () -homo hi = requireConcreteHole . tracing "homo" $ do +homo hi = requireConcreteHole $ do jdg <- goal let g = jGoal jdg @@ -242,7 +118,7 @@ homo hi = requireConcreteHole . tracing "homo" $ do rule $ destruct' False - (\dc jdg -> buildDataCon False jdg dc $ snd $ splitAppTys $ unCType $ jGoal jdg) + (\dc jdg -> buildDataCon jdg dc $ snd $ splitAppTys $ unCType $ jGoal jdg) hi @@ -250,93 +126,26 @@ homo hi = requireConcreteHole . tracing "homo" $ do -- | LambdaCase split, and leave holes in the matches. destructLambdaCase :: TacticsM () destructLambdaCase = - tracing "destructLambdaCase" $ rule $ destructLambdaCase' False (const newSubgoal) + rule $ destructLambdaCase' False (const newSubgoal) ------------------------------------------------------------------------------ -- | LambdaCase split, using the same data constructor in the matches. homoLambdaCase :: TacticsM () homoLambdaCase = - tracing "homoLambdaCase" $ - rule $ destructLambdaCase' False $ \dc jdg -> - buildDataCon False jdg dc - . snd - . splitAppTys - . unCType - $ jGoal jdg - - -newtype Saturation = Unsaturated Int - deriving (Eq, Ord, Show) - -pattern Saturated :: Saturation -pattern Saturated = Unsaturated 0 - - -apply :: Saturation -> HyInfo CType -> TacticsM () -apply (Unsaturated n) hi = tracing ("apply' " <> show (hi_name hi)) $ do - jdg <- goal - let g = jGoal jdg - ty = unCType $ hi_type hi - func = hi_name hi - ty' <- freshTyvars ty - let (_, theta, all_args, ret) = tacticsSplitFunTy ty' - saturated_args = dropEnd n all_args - unsaturated_args = takeEnd n all_args - rule $ \jdg -> do - unify g (CType $ mkVisFunTys unsaturated_args ret) - learnFromFundeps theta - ext - <- fmap unzipTrace - $ traverse ( newSubgoal - . blacklistingDestruct - . flip withNewGoal jdg - . CType - . scaledThing - ) saturated_args - pure $ - ext - & #syn_used_vals %~ (\x -> S.insert func x <> getAncestry jdg func) - & #syn_val %~ mkApply func . fmap unLoc - -application :: TacticsM () -application = overFunctions $ apply Saturated - - ------------------------------------------------------------------------------- --- | Choose between each of the goal's data constructors. -split :: TacticsM () -split = tracing "split(user)" $ do - jdg <- goal - let g = jGoal jdg - case tacticsGetDataCons $ unCType g of - Nothing -> failure $ GoalMismatch "split" g - Just (dcs, _) -> choice $ fmap splitDataCon dcs - - ------------------------------------------------------------------------------- --- | Choose between each of the goal's data constructors. Different than --- 'split' because it won't split a data con if it doesn't result in any new --- goals. -splitAuto :: TacticsM () -splitAuto = requireConcreteHole $ tracing "split(auto)" $ do - jdg <- goal - let g = jGoal jdg - case tacticsGetDataCons $ unCType g of - Nothing -> failure $ GoalMismatch "split" g - Just (dcs, _) -> do - case isSplitWhitelisted jdg of - True -> choice $ fmap splitDataCon dcs - False -> do - choice $ flip fmap dcs $ \dc -> requireNewHoles $ - splitDataCon dc + rule $ destructLambdaCase' False $ \dc jdg -> + buildDataCon jdg dc + . snd + . splitAppTys + . unCType + $ jGoal jdg ------------------------------------------------------------------------------ -- | Like 'split', but only works if there is a single matching data -- constructor for the goal. splitSingle :: TacticsM () -splitSingle = tracing "splitSingle" $ do +splitSingle = do jdg <- goal let g = jGoal jdg case tacticsGetDataCons $ unCType g of @@ -344,36 +153,6 @@ splitSingle = tracing "splitSingle" $ do splitDataCon dc _ -> failure $ GoalMismatch "splitSingle" g ------------------------------------------------------------------------------- --- | Like 'split', but prunes any data constructors which have holes. -obvious :: TacticsM () -obvious = tracing "obvious" $ do - pruning split $ bool (Just NoProgress) Nothing . null - - ------------------------------------------------------------------------------- --- | Sorry leaves a hole in its extract -sorry :: TacticsM () -sorry = exact $ var' $ mkVarOcc "_" - - ------------------------------------------------------------------------------- --- | Sorry leaves a hole in its extract -metaprogram :: TacticsM () -metaprogram = exact $ MetaprogramSyntax "" - - ------------------------------------------------------------------------------- --- | Allow the given tactic to proceed if and only if it introduces holes that --- have a different goal than current goal. -requireNewHoles :: TacticsM () -> TacticsM () -requireNewHoles m = do - jdg <- goal - pruning m $ \jdgs -> - case null jdgs || any (/= jGoal jdg) (fmap jGoal jdgs) of - True -> Nothing - False -> Just NoProgress - ------------------------------------------------------------------------------ -- | Attempt to instantiate the given ConLike to solve the goal. @@ -382,13 +161,14 @@ requireNewHoles m = do -- with. splitConLike :: ConLike -> TacticsM () splitConLike dc = - requireConcreteHole $ tracing ("splitDataCon:" <> show dc) $ rule $ \jdg -> do + requireConcreteHole $ rule $ \jdg -> do let g = jGoal jdg case splitTyConApp_maybe $ unCType g of Just (_, apps) -> do - buildDataCon True (unwhitelistingSplit jdg) dc apps + buildDataCon jdg dc apps Nothing -> cut -- failure $ GoalMismatch "splitDataCon" g + ------------------------------------------------------------------------------ -- | Attempt to instantiate the given data constructor to solve the goal. -- @@ -419,6 +199,7 @@ destructAll = do subst <- getSubstForJudgement =<< goal destruct $ fmap (coerce substTy subst) arg + -------------------------------------------------------------------------------- -- | User-facing tactic to implement "Use constructor " userSplit :: OccName -> TacticsM () @@ -437,200 +218,10 @@ userSplit occ = do Nothing -> failure $ NotInScope occ ------------------------------------------------------------------------------- --- | @matching f@ takes a function from a judgement to a @Tactic@, and --- then applies the resulting @Tactic@. -matching :: (Judgement -> TacticsM ()) -> TacticsM () -matching f = TacticT $ StateT $ \s -> runStateT (unTacticT $ f s) s - - -attemptOn :: (Judgement -> [a]) -> (a -> TacticsM ()) -> TacticsM () -attemptOn getNames tac = matching (choice . fmap tac . getNames) - - -localTactic :: TacticsM a -> (Judgement -> Judgement) -> TacticsM a -localTactic t f = do - TacticT $ StateT $ \jdg -> - runStateT (unTacticT t) $ f jdg - - refine :: TacticsM () refine = intros <%> splitSingle -auto' :: Int -> TacticsM () -auto' 0 = failure OutOfGas -auto' n = do - let loop = auto' (n - 1) - try intros - assumption <|> - choice - [ overFunctions $ \fname -> do - requireConcreteHole $ apply Saturated fname - loop - , overAlgebraicTerms $ \aname -> do - destructAuto aname - loop - , splitAuto >> loop - , recursion - ] - -overFunctions :: (HyInfo CType -> TacticsM ()) -> TacticsM () -overFunctions = - attemptOn $ filter (isFunction . unCType . hi_type) - . unHypothesis - . jHypothesis - -overAlgebraicTerms :: (HyInfo CType -> TacticsM ()) -> TacticsM () -overAlgebraicTerms = - attemptOn jAcceptableDestructTargets - - -allNames :: Judgement -> Set OccName -allNames = hyNamesInScope . jHypothesis - - -applyMethod :: Class -> PredType -> OccName -> TacticsM () -applyMethod cls df method_name = do - case find ((== method_name) . occName) $ classMethods cls of - Just method -> do - let (_, apps) = splitAppTys df - let ty = piResultTys (idType method) apps - apply Saturated $ HyInfo method_name (ClassMethodPrv $ Uniquely cls) $ CType ty - Nothing -> failure $ NotInScope method_name - - -applyByName :: OccName -> TacticsM () -applyByName name = do - g <- goal - choice $ unHypothesis (jHypothesis g) <&> \hi -> - case hi_name hi == name of - True -> apply Saturated hi - False -> empty - - ------------------------------------------------------------------------------- --- | Make a function application where the function being applied itself is --- a hole. -applyByType :: Type -> TacticsM () -applyByType ty = tracing ("applyByType " <> show ty) $ do - jdg <- goal - let g = jGoal jdg - ty' <- freshTyvars ty - let (_, _, args, ret) = tacticsSplitFunTy ty' - rule $ \jdg -> do - unify g (CType ret) - ext - <- fmap unzipTrace - $ traverse ( newSubgoal - . blacklistingDestruct - . flip withNewGoal jdg - . CType - . scaledThing - ) args - app <- newSubgoal . blacklistingDestruct $ withNewGoal (CType ty) jdg - pure $ - fmap noLoc $ - foldl' (@@) - <$> fmap unLoc app - <*> fmap (fmap unLoc) ext - - ------------------------------------------------------------------------------- --- | Make an n-ary function call of the form --- @(_ :: forall a b. a -> a -> b) _ _@. -nary :: Int -> TacticsM () -nary n = do - a <- newUnivar - b <- newUnivar - applyByType $ mkVisFunTys (replicate n $ unrestricted a) b - - -self :: TacticsM () -self = - fmap listToMaybe getCurrentDefinitions >>= \case - Just (self, _) -> useNameFromContext (apply Saturated) self - Nothing -> failure $ TacticPanic "no defining function" - - ------------------------------------------------------------------------------- --- | Perform a catamorphism when destructing the given 'HyInfo'. This will --- result in let binding, making values that call the defining function on each --- destructed value. -cata :: HyInfo CType -> TacticsM () -cata hi = do - (_, _, calling_args, _) - <- tacticsSplitFunTy . unCType <$> getDefiningType - freshened_args <- traverse (freshTyvars . scaledThing) calling_args - diff <- hyDiff $ destruct hi - - -- For for every destructed term, check to see if it can unify with any of - -- the arguments to the calling function. If it doesn't, we don't try to - -- perform a cata on it. - unifiable_diff <- flip filterM (unHypothesis diff) $ \hi -> - flip anyM freshened_args $ \ty -> - canUnify (hi_type hi) $ CType ty - - rule $ - letForEach - (mkVarOcc . flip mappend "_c" . occNameString) - (\hi -> self >> commit (assume $ hi_name hi) assumption) - $ Hypothesis unifiable_diff - - -letBind :: [OccName] -> TacticsM () -letBind occs = do - jdg <- goal - occ_tys <- for occs - $ \occ - -> fmap (occ, ) - $ fmap (<$ jdg) - $ fmap CType newUnivar - rule $ nonrecLet occ_tys - - ------------------------------------------------------------------------------- --- | Deeply nest an unsaturated function onto itself -nested :: OccName -> TacticsM () -nested = deepening . use (Unsaturated 1) - - ------------------------------------------------------------------------------- --- | Repeatedly bind a tactic on its first hole -deep :: Int -> TacticsM () -> TacticsM () -deep 0 _ = pure () -deep n t = foldr1 bindOne $ replicate n t - - ------------------------------------------------------------------------------- --- | Try 'deep' for arbitrary depths. -deepening :: TacticsM () -> TacticsM () -deepening t = - asum $ fmap (flip deep t) [0 .. 100] - - -bindOne :: TacticsM a -> TacticsM a -> TacticsM a -bindOne t t1 = t <@> [t1] - - -collapse :: TacticsM () -collapse = do - g <- goal - let terms = unHypothesis $ hyFilter ((jGoal g ==) . hi_type) $ jLocalHypothesis g - case terms of - [hi] -> assume $ hi_name hi - _ -> nary (length terms) <@> fmap (assume . hi_name) terms - - -with_arg :: TacticsM () -with_arg = rule $ \jdg -> do - let g = jGoal jdg - fresh_ty <- newUnivar - a <- newSubgoal $ withNewGoal (CType fresh_ty) jdg - f <- newSubgoal $ withNewGoal (coerce mkVisFunTys [unrestricted fresh_ty] g) jdg - pure $ fmap noLoc $ (@@) <$> fmap unLoc f <*> fmap unLoc a - - ------------------------------------------------------------------------------ -- | Determine the difference in hypothesis due to running a tactic. Also, it -- runs the tactic. @@ -642,51 +233,3 @@ hyDiff m = do g' <- unHypothesis . jEntireHypothesis <$> goal pure $ Hypothesis $ take (length g' - g_len) g' - ------------------------------------------------------------------------------- --- | Attempt to run the given tactic in "idiom bracket" mode. For example, if --- the current goal is --- --- (_ :: [r]) --- --- then @idiom apply@ will remove the applicative context, resulting in a hole: --- --- (_ :: r) --- --- and then use @apply@ to solve it. Let's say this results in: --- --- (f (_ :: a) (_ :: b)) --- --- Finally, @idiom@ lifts this back into the original applicative: --- --- (f <$> (_ :: [a]) <*> (_ :: [b])) --- --- Idiom will fail fast if the current goal doesn't have an applicative --- instance. -idiom :: TacticsM () -> TacticsM () -idiom m = do - jdg <- goal - let hole = unCType $ jGoal jdg - when (isFunction hole) $ - failure $ GoalMismatch "idiom" $ jGoal jdg - case splitAppTy_maybe hole of - Just (applic, ty) -> do - minst <- getKnownInstance (mkClsOcc "Applicative") - . pure - $ applic - case minst of - Nothing -> failure $ GoalMismatch "idiom" $ CType applic - Just (_, _) -> do - rule $ \jdg -> do - expr <- subgoalWith (withNewGoal (CType ty) jdg) m - case unLoc $ syn_val expr of - HsApp{} -> pure $ fmap idiomize expr - RecordCon{} -> pure $ fmap idiomize expr - _ -> unsolvable $ GoalMismatch "idiom" $ jGoal jdg - rule $ newSubgoal . withModifiedGoal (CType . mkAppTy applic . unCType) - Nothing -> - failure $ GoalMismatch "idiom" $ jGoal jdg - -subgoalWith :: Judgement -> TacticsM () -> RuleM (Synthesized (LHsExpr GhcPs)) -subgoalWith jdg t = RuleT $ flip execStateT jdg $ unTacticT t - diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs index 621cc9752e..f4cda19e72 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs @@ -49,8 +49,7 @@ import Data.IORef -- actual tactics via 'commandTactic' and are contextually provided to the -- editor via 'commandProvider'. data TacticCommand - = Auto - | Intros + = Intros | IntroAndDestruct | Destruct | DestructPun @@ -60,15 +59,12 @@ data TacticCommand | DestructAll | UseDataCon | Refine - | BeginMetaprogram - | RunMetaprogram deriving (Eq, Ord, Show, Enum, Bounded) -- | Generate a title for the command. tacticTitle :: TacticCommand -> T.Text -> T.Text tacticTitle = (mappend "Wingman: " .) . go where - go Auto _ = "Attempt to fill hole" go Intros _ = "Introduce lambda" go IntroAndDestruct _ = "Introduce and destruct term" go Destruct var = "Case split on " <> var @@ -79,8 +75,6 @@ tacticTitle = (mappend "Wingman: " .) . go go DestructAll _ = "Split all function arguments" go UseDataCon dcon = "Use constructor " <> dcon go Refine _ = "Refine hole" - go BeginMetaprogram _ = "Use custom tactic block" - go RunMetaprogram _ = "Run custom tactic" ------------------------------------------------------------------------------ @@ -88,8 +82,6 @@ tacticTitle = (mappend "Wingman: " .) . go data Config = Config { cfg_max_use_ctor_actions :: Int , cfg_timeout_seconds :: Int - , cfg_auto_gas :: Int - , cfg_proofstate_styling :: Bool } deriving (Eq, Ord, Show) @@ -97,8 +89,6 @@ emptyConfig :: Config emptyConfig = Config { cfg_max_use_ctor_actions = 5 , cfg_timeout_seconds = 2 - , cfg_auto_gas = 4 - , cfg_proofstate_styling = True } ------------------------------------------------------------------------------ @@ -211,13 +201,8 @@ data Provenance Int -- ^ of how many arguments total? -- | A binding created in a pattern match. | PatternMatchPrv PatVal - -- | A class method from the given context. - | ClassMethodPrv - (Uniquely Class) -- ^ Class -- | A binding explicitly written by the user. | UserPrv - -- | A binding explicitly imported by the user. - | ImportPrv -- | The recursive hypothesis. Present only in the context of the recursion -- tactic. | RecursivePrv @@ -299,8 +284,6 @@ overProvenance f (HyInfo name prv ty) = HyInfo name (f prv) ty -- | The current bindings and goal for a hole to be filled by refinery. data Judgement' a = Judgement { _jHypothesis :: !(Hypothesis a) - , _jBlacklistDestruct :: !Bool - , _jWhitelistSplit :: !Bool , _jIsTopHole :: !Bool , _jGoal :: !a , j_coercion :: TCvSubst @@ -310,8 +293,8 @@ data Judgement' a = Judgement type Judgement = Judgement' CType -newtype ExtractM a = ExtractM { unExtractM :: ReaderT Context IO a } - deriving newtype (Functor, Applicative, Monad, MonadReader Context) +newtype ExtractM a = ExtractM { unExtractM :: ReaderT Config IO a } + deriving newtype (Functor, Applicative, Monad, MonadReader Config) ------------------------------------------------------------------------------ -- | Used to ensure hole names are unique across invocations of runTactic @@ -396,132 +379,42 @@ type TacticsM = TacticT Judgement (Synthesized (LHsExpr GhcPs)) TacticError Tac type RuleM = RuleT Judgement (Synthesized (LHsExpr GhcPs)) TacticError TacticState ExtractM type Rule = RuleM (Synthesized (LHsExpr GhcPs)) -type Trace = Rose String - ------------------------------------------------------------------------------ -- | The extract for refinery. Represents a "synthesized attribute" in the -- context of attribute grammars. In essence, 'Synthesized' describes -- information we'd like to pass from leaves of the tactics search upwards. -- This includes the actual AST we've generated (in 'syn_val'). data Synthesized a = Synthesized - { syn_trace :: Trace - -- ^ A tree describing which tactics were used produce the 'syn_val'. - -- Mainly for debugging when you get the wrong answer, to see the other - -- things it tried. - , syn_scoped :: Hypothesis CType - -- ^ All of the bindings created to produce the 'syn_val'. - , syn_used_vals :: Set OccName - -- ^ The values used when synthesizing the 'syn_val'. - , syn_recursion_count :: Sum Int - -- ^ The number of recursive calls - , syn_val :: a + { syn_val :: a } deriving stock (Eq, Show, Functor, Foldable, Traversable, Generic, Data, Typeable) instance Monad Synthesized where return = pure - Synthesized tr1 sc1 uv1 rc1 a >>= f = + Synthesized a >>= f = case f a of - Synthesized tr2 sc2 uv2 rc2 b -> + Synthesized b -> Synthesized - { syn_trace = tr1 <> tr2 - , syn_scoped = sc1 <> sc2 - , syn_used_vals = uv1 <> uv2 - , syn_recursion_count = rc1 <> rc2 - , syn_val = b + { syn_val = b } -mapTrace :: (Trace -> Trace) -> Synthesized a -> Synthesized a -mapTrace f (Synthesized tr sc uv rc a) = Synthesized (f tr) sc uv rc a - ------------------------------------------------------------------------------ -- | This might not be lawful, due to the semigroup on 'Trace' maybe not being -- lawful. But that's only for debug output, so it's not anything I'm concerned -- about. instance Applicative Synthesized where - pure = Synthesized mempty mempty mempty mempty - Synthesized tr1 sc1 uv1 rc1 f <*> Synthesized tr2 sc2 uv2 rc2 a = - Synthesized (tr1 <> tr2) (sc1 <> sc2) (uv1 <> uv2) (rc1 <> rc2) $ f a - - ------------------------------------------------------------------------------- --- | The Reader context of tactics and rules -data Context = Context - { ctxDefiningFuncs :: [(OccName, CType)] - -- ^ The functions currently being defined - , ctxModuleFuncs :: [(OccName, CType)] - -- ^ Everything defined in the current module - , ctxConfig :: Config - , ctxInstEnvs :: InstEnvs - , ctxFamInstEnvs :: FamInstEnvs - , ctxTheta :: Set CType - , ctx_hscEnv :: HscEnv - , ctx_occEnv :: OccEnv [GlobalRdrElt] - , ctx_module :: Module - } - -instance Show Context where - show Context{..} = mconcat - [ "Context " - , showsPrec 10 ctxDefiningFuncs "" - , showsPrec 10 ctxModuleFuncs "" - , showsPrec 10 ctxConfig "" - , showsPrec 10 ctxTheta "" - ] - - ------------------------------------------------------------------------------- --- | An empty context -emptyContext :: Context -emptyContext - = Context - { ctxDefiningFuncs = mempty - , ctxModuleFuncs = mempty - , ctxConfig = emptyConfig - , ctxFamInstEnvs = mempty - , ctxInstEnvs = InstEnvs mempty mempty mempty - , ctxTheta = mempty - , ctx_hscEnv = error "empty hsc env from emptyContext" - , ctx_occEnv = emptyOccEnv - , ctx_module = error "empty module from emptyContext" - } - - -newtype Rose a = Rose (Tree a) - deriving stock (Eq, Functor, Generic, Data, Typeable) - -instance Show (Rose String) where - show = unlines . dropEveryOther . lines . drawTree . coerce - -dropEveryOther :: [a] -> [a] -dropEveryOther [] = [] -dropEveryOther [a] = [a] -dropEveryOther (a : _ : as) = a : dropEveryOther as - ------------------------------------------------------------------------------- --- | This might not be lawful! I didn't check, and it feels sketchy. -instance (Eq a, Monoid a) => Semigroup (Rose a) where - Rose (Node a as) <> Rose (Node b bs) = Rose $ Node (a <> b) (as <> bs) - sconcat (a :| as) = rose mempty $ a : as - -instance (Eq a, Monoid a) => Monoid (Rose a) where - mempty = Rose $ Node mempty mempty - -rose :: (Eq a, Monoid a) => a -> [Rose a] -> Rose a -rose a [Rose (Node a' rs)] | a' == mempty = Rose $ Node a rs -rose a rs = Rose $ Node a $ coerce rs + pure = Synthesized + Synthesized f <*> Synthesized a = + Synthesized $ f a ------------------------------------------------------------------------------ -- | The results of 'Wingman.Machinery.runTactic' data RunTacticResults = RunTacticResults - { rtr_trace :: Trace - , rtr_extract :: LHsExpr GhcPs - , rtr_subgoals :: [Judgement] - , rtr_other_solns :: [Synthesized (LHsExpr GhcPs)] + { rtr_extract :: LHsExpr GhcPs , rtr_jdg :: Judgement - , rtr_ctx :: Context + , rtr_ctx :: Config , rtr_timed_out :: Bool } deriving Show @@ -549,14 +442,10 @@ instance Show UserFacingMessage where show (InfrastructureError t) = "Internal error: " <> T.unpack t -data HoleSort = Hole | Metaprogram T.Text - deriving (Eq, Ord, Show) - data HoleJudgment = HoleJudgment { hj_range :: Tracked 'Current Range , hj_jdg :: Judgement - , hj_ctx :: Context + , hj_ctx :: Config , hj_dflags :: DynFlags - , hj_hole_sort :: HoleSort } diff --git a/plugins/hls-tactics-plugin/new/test/AutoTupleSpec.hs b/plugins/hls-tactics-plugin/new/test/AutoTupleSpec.hs deleted file mode 100644 index 11ba11e2ae..0000000000 --- a/plugins/hls-tactics-plugin/new/test/AutoTupleSpec.hs +++ /dev/null @@ -1,57 +0,0 @@ -{-# LANGUAGE NumDecimals #-} - -{-# OPTIONS_GHC -fno-warn-orphans #-} - -module AutoTupleSpec where - -import Control.Monad (replicateM) -import Control.Monad.State (evalState) -import Data.Either (isRight) -import Development.IDE.GHC.Compat.Core ( mkVarOcc, mkBoxedTupleTy ) -import System.IO.Unsafe -import Test.Hspec -import Test.QuickCheck -import Wingman.Judgements (mkFirstJudgement) -import Wingman.Machinery -import Wingman.Tactics (auto') -import Wingman.Types - - -spec :: Spec -spec = describe "auto for tuple" $ do - it "should always be able to discover an auto solution" $ do - property $ do - -- Pick some number of variables - n <- choose (1, 7) - let vars = flip evalState defaultTacticState - $ replicateM n newUnivar - -- Pick a random ordering - in_vars <- shuffle vars - -- Randomly associate them into tuple types - in_type <- mkBoxedTupleTy - . fmap mkBoxedTupleTy - <$> randomGroups in_vars - out_type <- mkBoxedTupleTy - . fmap mkBoxedTupleTy - <$> randomGroups vars - pure $ - -- We should always be able to find a solution - unsafePerformIO - (runTactic - 2e6 - emptyContext - (mkFirstJudgement - emptyContext - (Hypothesis $ pure $ HyInfo (mkVarOcc "x") UserPrv $ CType in_type) - True - out_type) - (auto' $ n * 2)) `shouldSatisfy` isRight - - -randomGroups :: [a] -> Gen [[a]] -randomGroups [] = pure [] -randomGroups as = do - n <- choose (1, length as) - (:) <$> pure (take n as) - <*> randomGroups (drop n as) - diff --git a/plugins/hls-tactics-plugin/new/test/CodeAction/AutoSpec.hs b/plugins/hls-tactics-plugin/new/test/CodeAction/AutoSpec.hs deleted file mode 100644 index 4075183ee6..0000000000 --- a/plugins/hls-tactics-plugin/new/test/CodeAction/AutoSpec.hs +++ /dev/null @@ -1,92 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module CodeAction.AutoSpec where - -import Wingman.Types -import Test.Hspec -import Utils - - -spec :: Spec -spec = do - let autoTest = goldenTest Auto "" - autoTestNoWhitespace = goldenTestNoWhitespace Auto "" - - describe "golden" $ do - autoTest 11 8 "AutoSplitGADT" - autoTest 2 11 "GoldenEitherAuto" - autoTest 4 12 "GoldenJoinCont" - autoTest 3 11 "GoldenIdentityFunctor" - autoTest 7 11 "GoldenIdTypeFam" - autoTest 2 15 "GoldenEitherHomomorphic" - autoTest 2 8 "GoldenNote" - autoTest 2 12 "GoldenPureList" - autoTest 2 12 "GoldenListFmap" - autoTest 2 13 "GoldenFromMaybe" - autoTest 2 10 "GoldenFoldr" - autoTest 2 8 "GoldenSwap" - autoTest 4 11 "GoldenFmapTree" - autoTest 7 13 "GoldenGADTAuto" - autoTest 2 12 "GoldenSwapMany" - autoTest 4 12 "GoldenBigTuple" - autoTest 2 10 "GoldenShow" - autoTest 2 15 "GoldenShowCompose" - autoTest 2 8 "GoldenShowMapChar" - autoTest 7 8 "GoldenSuperclass" - autoTest 2 12 "GoldenSafeHead" - autoTest 2 12 "FmapBoth" - autoTest 7 8 "RecordCon" - autoTest 6 8 "NewtypeRecord" - autoTest 2 14 "FmapJoin" - autoTest 2 9 "Fgmap" - autoTest 4 19 "FmapJoinInLet" - autoTest 9 12 "AutoEndo" - autoTest 2 16 "AutoEmptyString" - autoTest 7 35 "AutoPatSynUse" - autoTest 2 28 "AutoZip" - autoTest 2 17 "AutoInfixApply" - autoTest 2 19 "AutoInfixApplyMany" - autoTest 2 25 "AutoInfixInfix" - autoTest 19 12 "AutoTypeLevel" - autoTest 11 9 "AutoForallClassMethod" - autoTest 2 8 "AutoUnusedPatternMatch" - - failing "flaky in CI" $ - autoTest 2 11 "GoldenApplicativeThen" - - failing "not enough auto gas" $ - autoTest 5 18 "GoldenFish" - - describe "theta" $ do - autoTest 12 10 "AutoThetaFix" - autoTest 7 27 "AutoThetaRankN" - autoTest 6 10 "AutoThetaGADT" - autoTest 6 8 "AutoThetaGADTDestruct" - autoTest 4 8 "AutoThetaEqCtx" - autoTest 6 10 "AutoThetaEqGADT" - autoTest 6 8 "AutoThetaEqGADTDestruct" - autoTest 6 10 "AutoThetaRefl" - autoTest 6 8 "AutoThetaReflDestruct" - autoTest 19 30 "AutoThetaMultipleUnification" - autoTest 16 9 "AutoThetaSplitUnification" - - describe "known" $ do - autoTest 25 13 "GoldenArbitrary" - autoTest 6 13 "GoldenArbitrarySingleConstructor" - autoTestNoWhitespace - 6 10 "KnownBigSemigroup" - autoTest 4 10 "KnownThetaSemigroup" - autoTest 6 10 "KnownCounterfactualSemigroup" - autoTest 10 10 "KnownModuleInstanceSemigroup" - autoTest 4 22 "KnownDestructedSemigroup" - autoTest 4 10 "KnownMissingSemigroup" - autoTest 7 12 "KnownMonoid" - autoTest 7 12 "KnownPolyMonoid" - autoTest 7 12 "KnownMissingMonoid" - - - describe "messages" $ do - mkShowMessageTest Auto "" 2 8 "MessageForallA" TacticErrors - mkShowMessageTest Auto "" 7 8 "MessageCantUnify" TacticErrors - mkShowMessageTest Auto "" 12 8 "MessageNotEnoughGas" NotEnoughGas - diff --git a/plugins/hls-tactics-plugin/new/test/CodeAction/DestructAllSpec.hs b/plugins/hls-tactics-plugin/new/test/CodeAction/DestructAllSpec.hs index 488fb3ebad..89579f7ba9 100644 --- a/plugins/hls-tactics-plugin/new/test/CodeAction/DestructAllSpec.hs +++ b/plugins/hls-tactics-plugin/new/test/CodeAction/DestructAllSpec.hs @@ -34,5 +34,4 @@ spec = do destructAllTest 4 23 "DestructAllMany" destructAllTest 2 18 "DestructAllNonVarTopMatch" destructAllTest 2 18 "DestructAllFunc" - destructAllTest 19 18 "DestructAllGADTEvidence" diff --git a/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs b/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs index 2251abfeb2..c0b97fa4c4 100644 --- a/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs +++ b/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs @@ -17,9 +17,6 @@ spec = do destructTest "a" 7 25 "SplitPattern" destructTest "a" 6 18 "DestructPun" destructTest "fp" 31 14 "DestructCthulhu" - destructTest "b" 7 10 "DestructTyFam" - destructTest "b" 7 10 "DestructDataFam" - destructTest "b" 17 10 "DestructTyToDataFam" destructTest "t" 6 10 "DestructInt" describe "layout" $ do diff --git a/plugins/hls-tactics-plugin/new/test/CodeAction/RunMetaprogramSpec.hs b/plugins/hls-tactics-plugin/new/test/CodeAction/RunMetaprogramSpec.hs deleted file mode 100644 index e366c34efe..0000000000 --- a/plugins/hls-tactics-plugin/new/test/CodeAction/RunMetaprogramSpec.hs +++ /dev/null @@ -1,43 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE OverloadedStrings #-} - -module CodeAction.RunMetaprogramSpec where - -import Utils -import Test.Hspec -import Wingman.Types - - -spec :: Spec -spec = do - let metaTest l c f = - goldenTest RunMetaprogram "" l c f - - describe "beginMetaprogram" $ do - goldenTest BeginMetaprogram "" 1 7 "MetaBegin" - goldenTest BeginMetaprogram "" 1 9 "MetaBeginNoWildify" - - describe "golden" $ do - metaTest 6 11 "MetaMaybeAp" - metaTest 2 32 "MetaBindOne" - metaTest 2 32 "MetaBindAll" - metaTest 2 13 "MetaTry" - metaTest 2 74 "MetaChoice" - metaTest 5 40 "MetaUseImport" - metaTest 6 31 "MetaUseLocal" - metaTest 11 11 "MetaUseMethod" - metaTest 9 38 "MetaCataCollapse" - metaTest 7 16 "MetaCataCollapseUnary" - metaTest 10 32 "MetaCataAST" - metaTest 6 46 "MetaPointwise" - metaTest 4 28 "MetaUseSymbol" - metaTest 7 53 "MetaDeepOf" - metaTest 2 34 "MetaWithArg" - metaTest 2 18 "MetaLetSimple" - metaTest 5 9 "MetaIdiom" - metaTest 7 9 "MetaIdiomRecord" - - metaTest 14 10 "MetaFundeps" - - metaTest 2 12 "IntrosTooMany" - diff --git a/plugins/hls-tactics-plugin/new/test/ProviderSpec.hs b/plugins/hls-tactics-plugin/new/test/ProviderSpec.hs index 4eea30f5b3..71e5ffd7a4 100644 --- a/plugins/hls-tactics-plugin/new/test/ProviderSpec.hs +++ b/plugins/hls-tactics-plugin/new/test/ProviderSpec.hs @@ -24,5 +24,4 @@ spec = do goldenTestMany "SubsequentTactics" [ InvokeTactic Intros "" 4 5 , InvokeTactic Destruct "du" 4 8 - , InvokeTactic Auto "" 4 15 ] diff --git a/plugins/hls-tactics-plugin/new/test/Utils.hs b/plugins/hls-tactics-plugin/new/test/Utils.hs index db31d910cf..15c0386bb8 100644 --- a/plugins/hls-tactics-plugin/new/test/Utils.hs +++ b/plugins/hls-tactics-plugin/new/test/Utils.hs @@ -252,7 +252,7 @@ failing _ _ = pure () tacticPath :: FilePath -tacticPath = "old/test/golden" +tacticPath = "test/golden" executeCommandWithResp :: Command -> Session (ResponseMessage 'WorkspaceExecuteCommand) diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.expected.hs deleted file mode 100644 index 8ccb9f083d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -empty_string :: String -empty_string = "" diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.hs deleted file mode 100644 index f04451e24c..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoEmptyString.hs +++ /dev/null @@ -1,2 +0,0 @@ -empty_string :: String -empty_string = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoEndo.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoEndo.expected.hs deleted file mode 100644 index 4b50c6c074..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoEndo.expected.hs +++ /dev/null @@ -1,11 +0,0 @@ -data Synthesized b a = Synthesized - { syn_trace :: b - , syn_val :: a - } - deriving (Eq, Show) - - -mapTrace :: (b -> b) -> Synthesized b a -> Synthesized b a -mapTrace fbb (Synthesized b a) - = Synthesized {syn_trace = fbb b, syn_val = a} - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoEndo.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoEndo.hs deleted file mode 100644 index c92e6adb5b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoEndo.hs +++ /dev/null @@ -1,10 +0,0 @@ -data Synthesized b a = Synthesized - { syn_trace :: b - , syn_val :: a - } - deriving (Eq, Show) - - -mapTrace :: (b -> b) -> Synthesized b a -> Synthesized b a -mapTrace = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.expected.hs deleted file mode 100644 index 5846428ee7..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.expected.hs +++ /dev/null @@ -1,12 +0,0 @@ -{-# LANGUAGE ExplicitForAll #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE MultiParamTypeClasses #-} - -import Data.Functor.Contravariant - -class Semigroupal cat t1 t2 to f where - combine :: cat (to (f x y) (f x' y')) (f (t1 x x') (t2 y y')) - -comux :: forall p a b c d. Semigroupal Op (,) (,) (,) p => p (a, c) (b, d) -> (p a b, p c d) -comux = case combine of { (Op f) -> f } - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.hs deleted file mode 100644 index 9ee00c9255..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoForallClassMethod.hs +++ /dev/null @@ -1,12 +0,0 @@ -{-# LANGUAGE ExplicitForAll #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE MultiParamTypeClasses #-} - -import Data.Functor.Contravariant - -class Semigroupal cat t1 t2 to f where - combine :: cat (to (f x y) (f x' y')) (f (t1 x x') (t2 y y')) - -comux :: forall p a b c d. Semigroupal Op (,) (,) (,) p => p (a, c) (b, d) -> (p a b, p c d) -comux = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.expected.hs deleted file mode 100644 index 367f6e54d9..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -test :: (a -> b -> c) -> a -> (a -> b) -> c -test (/:) a f = a /: f a - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.hs deleted file mode 100644 index 4675331aea..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApply.hs +++ /dev/null @@ -1,3 +0,0 @@ -test :: (a -> b -> c) -> a -> (a -> b) -> c -test (/:) a f = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.expected.hs deleted file mode 100644 index ce40bf0cd6..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -test :: (a -> b -> x -> c) -> a -> (a -> b) -> x -> c -test (/:) a f x = (a /: f a) x - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.hs deleted file mode 100644 index 55a706ab9b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixApplyMany.hs +++ /dev/null @@ -1,3 +0,0 @@ -test :: (a -> b -> x -> c) -> a -> (a -> b) -> x -> c -test (/:) a f x = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.expected.hs deleted file mode 100644 index 7adea169d1..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -test :: (a -> b -> c) -> (c -> d -> e) -> a -> (a -> b) -> d -> e -test (/:) (-->) a f x = (a /: f a) --> x diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.hs deleted file mode 100644 index 729e1a2227..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoInfixInfix.hs +++ /dev/null @@ -1,2 +0,0 @@ -test :: (a -> b -> c) -> (c -> d -> e) -> a -> (a -> b) -> d -> e -test (/:) (-->) a f x = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.expected.hs deleted file mode 100644 index 8addba654f..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE PatternSynonyms #-} - -pattern JustSingleton :: a -> Maybe [a] -pattern JustSingleton a <- Just [a] - -amIASingleton :: Maybe [a] -> Maybe a -amIASingleton (JustSingleton a) = Just a - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.hs deleted file mode 100644 index 25a44666e7..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoPatSynUse.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE PatternSynonyms #-} - -pattern JustSingleton :: a -> Maybe [a] -pattern JustSingleton a <- Just [a] - -amIASingleton :: Maybe [a] -> Maybe a -amIASingleton (JustSingleton a) = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.expected.hs deleted file mode 100644 index 2521b651eb..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.expected.hs +++ /dev/null @@ -1,12 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data GADT b a where - GBool :: b -> GADT b Bool - GInt :: GADT b Int - --- wingman would prefer to use GBool since then it can use its argument. But --- that won't unify with GADT Int, so it is forced to pick GInt and ignore the --- argument. -test :: b -> GADT b Int -test _ = GInt - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.hs deleted file mode 100644 index b15621e091..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoSplitGADT.hs +++ /dev/null @@ -1,12 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data GADT b a where - GBool :: b -> GADT b Bool - GInt :: GADT b Int - --- wingman would prefer to use GBool since then it can use its argument. But --- that won't unify with GADT Int, so it is forced to pick GInt and ignore the --- argument. -test :: b -> GADT b Int -test = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.expected.hs deleted file mode 100644 index cdb8506d01..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.expected.hs +++ /dev/null @@ -1,5 +0,0 @@ -{-# LANGUAGE GADTs #-} - -fun2 :: (a ~ b) => a -> b -fun2 = id -- id - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.hs deleted file mode 100644 index 448a7f5de5..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqCtx.hs +++ /dev/null @@ -1,5 +0,0 @@ -{-# LANGUAGE GADTs #-} - -fun2 :: (a ~ b) => a -> b -fun2 = _ -- id - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.expected.hs deleted file mode 100644 index cea9517794..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Y a b = a ~ b => Y - -fun3 :: Y a b -> a -> b -fun3 Y = id - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.hs deleted file mode 100644 index eae2246722..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADT.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Y a b = a ~ b => Y - -fun3 :: Y a b -> a -> b -fun3 Y = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.expected.hs deleted file mode 100644 index 9f2b954867..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Y a b = a ~ b => Y - -fun3 :: Y a b -> a -> b -fun3 Y a = a - - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.hs deleted file mode 100644 index 2292a3972f..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaEqGADTDestruct.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Y a b = a ~ b => Y - -fun3 :: Y a b -> a -> b -fun3 = _ - - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.expected.hs deleted file mode 100644 index ba8df349e4..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.expected.hs +++ /dev/null @@ -1,13 +0,0 @@ -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE UndecidableInstances #-} - -data Fix f a = Fix (f (Fix f a)) - -instance ( Functor f - -- FIXME(sandy): Unfortunately, the recursion tactic fails to fire - -- on this case. By explicitly adding the @Functor (Fix f)@ - -- dictionary, we can get Wingman to generate the right definition. - , Functor (Fix f) - ) => Functor (Fix f) where - fmap fab (Fix f) = Fix (fmap (fmap fab) f) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.hs deleted file mode 100644 index 014e6441da..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaFix.hs +++ /dev/null @@ -1,13 +0,0 @@ -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE UndecidableInstances #-} - -data Fix f a = Fix (f (Fix f a)) - -instance ( Functor f - -- FIXME(sandy): Unfortunately, the recursion tactic fails to fire - -- on this case. By explicitly adding the @Functor (Fix f)@ - -- dictionary, we can get Wingman to generate the right definition. - , Functor (Fix f) - ) => Functor (Fix f) where - fmap = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.expected.hs deleted file mode 100644 index e74f2aba40..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data X f = Monad f => X - -fun1 :: X f -> a -> f a -fun1 X = pure - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.hs deleted file mode 100644 index e1b20a4b3b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADT.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data X f = Monad f => X - -fun1 :: X f -> a -> f a -fun1 X = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.expected.hs deleted file mode 100644 index 4d4b1f9579..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data X f = Monad f => X - -fun1 :: X f -> a -> f a -fun1 X a = pure a - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.hs deleted file mode 100644 index d92d0bd97d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaGADTDestruct.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data X f = Monad f => X - -fun1 :: X f -> a -> f a -fun1 = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.expected.hs deleted file mode 100644 index 446a4d73b3..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.expected.hs +++ /dev/null @@ -1,21 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -import Data.Kind - -data Nat = Z | S Nat - -data HList (ls :: [Type]) where - HNil :: HList '[] - HCons :: t -> HList ts -> HList (t ': ts) - -data ElemAt (n :: Nat) t (ts :: [Type]) where - AtZ :: ElemAt 'Z t (t ': ts) - AtS :: ElemAt k t ts -> ElemAt ('S k) t (u ': ts) - -lookMeUp :: ElemAt i ty tys -> HList tys -> ty -lookMeUp AtZ (HCons t _) = t -lookMeUp (AtS ea') (HCons t hl') = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.hs deleted file mode 100644 index b0b520347d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaMultipleUnification.hs +++ /dev/null @@ -1,21 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -import Data.Kind - -data Nat = Z | S Nat - -data HList (ls :: [Type]) where - HNil :: HList '[] - HCons :: t -> HList ts -> HList (t ': ts) - -data ElemAt (n :: Nat) t (ts :: [Type]) where - AtZ :: ElemAt 'Z t (t ': ts) - AtS :: ElemAt k t ts -> ElemAt ('S k) t (u ': ts) - -lookMeUp :: ElemAt i ty tys -> HList tys -> ty -lookMeUp AtZ (HCons t hl') = _ -lookMeUp (AtS ea') (HCons t hl') = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.expected.hs deleted file mode 100644 index 23d96223f3..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE RankNTypes #-} - -showMe :: (forall x. Show x => x -> String) -> Int -> String -showMe f = f - -showedYou :: Int -> String -showedYou = showMe (\x -> show x) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.hs deleted file mode 100644 index 0e92ac35f3..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRankN.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE RankNTypes #-} - -showMe :: (forall x. Show x => x -> String) -> Int -> String -showMe f = f - -showedYou :: Int -> String -showedYou = showMe (\x -> _) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.expected.hs deleted file mode 100644 index 9e42bc946e..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Z a b where Z :: Z a a - -fun4 :: Z a b -> a -> b -fun4 Z = id -- id - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.hs deleted file mode 100644 index df15580ad2..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaRefl.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Z a b where Z :: Z a a - -fun4 :: Z a b -> a -> b -fun4 Z = _ -- id - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.expected.hs deleted file mode 100644 index 36aed1af65..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Z a b where Z :: Z a a - -fun4 :: Z a b -> a -> b -fun4 Z a = a -- id - - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.hs deleted file mode 100644 index 3beccba7a5..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaReflDestruct.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data Z a b where Z :: Z a a - -fun4 :: Z a b -> a -> b -fun4 = _ -- id - - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.expected.hs deleted file mode 100644 index e680f0265c..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.expected.hs +++ /dev/null @@ -1,17 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -data A = A -data B = B -data X = X -data Y = Y - - -data Pairrow ax by where - Pairrow :: (a -> b) -> (x -> y) -> Pairrow '(a, x) '(b, y) - -test2 :: (A -> B) -> (X -> Y) -> Pairrow '(A, X) '(B, Y) -test2 = Pairrow - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.hs deleted file mode 100644 index e6ceeb1bcd..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoThetaSplitUnification.hs +++ /dev/null @@ -1,17 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -data A = A -data B = B -data X = X -data Y = Y - - -data Pairrow ax by where - Pairrow :: (a -> b) -> (x -> y) -> Pairrow '(a, x) '(b, y) - -test2 :: (A -> B) -> (X -> Y) -> Pairrow '(A, X) '(B, Y) -test2 = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.expected.hs deleted file mode 100644 index 3668830620..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.expected.hs +++ /dev/null @@ -1,21 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -import Data.Kind - -data Nat = Z | S Nat - -data HList (ls :: [Type]) where - HNil :: HList '[] - HCons :: t -> HList ts -> HList (t ': ts) - -data ElemAt (n :: Nat) t (ts :: [Type]) where - AtZ :: ElemAt 'Z t (t ': ts) - AtS :: ElemAt k t ts -> ElemAt ('S k) t (u ': ts) - -lookMeUp :: ElemAt i ty tys -> HList tys -> ty -lookMeUp AtZ (HCons t _) = t -lookMeUp (AtS ea') (HCons _ hl') = lookMeUp ea' hl' - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.hs deleted file mode 100644 index 40226739db..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoTypeLevel.hs +++ /dev/null @@ -1,20 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -import Data.Kind - -data Nat = Z | S Nat - -data HList (ls :: [Type]) where - HNil :: HList '[] - HCons :: t -> HList ts -> HList (t ': ts) - -data ElemAt (n :: Nat) t (ts :: [Type]) where - AtZ :: ElemAt 'Z t (t ': ts) - AtS :: ElemAt k t ts -> ElemAt ('S k) t (u ': ts) - -lookMeUp :: ElemAt i ty tys -> HList tys -> ty -lookMeUp = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.expected.hs deleted file mode 100644 index 2885a1ca05..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -test :: Bool -> () -test _ = () diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.hs deleted file mode 100644 index 5345192969..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoUnusedPatternMatch.hs +++ /dev/null @@ -1,2 +0,0 @@ -test :: Bool -> () -test = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoZip.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoZip.expected.hs deleted file mode 100644 index 997bc09a33..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoZip.expected.hs +++ /dev/null @@ -1,6 +0,0 @@ -zip_it_up_and_zip_it_out :: [a] -> [b] -> [(a, b)] -zip_it_up_and_zip_it_out _ [] = [] -zip_it_up_and_zip_it_out [] (_ : _) = [] -zip_it_up_and_zip_it_out (a : as') (b : bs') - = (a, b) : zip_it_up_and_zip_it_out as' bs' - diff --git a/plugins/hls-tactics-plugin/new/test/golden/AutoZip.hs b/plugins/hls-tactics-plugin/new/test/golden/AutoZip.hs deleted file mode 100644 index 98d6335988..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/AutoZip.hs +++ /dev/null @@ -1,3 +0,0 @@ -zip_it_up_and_zip_it_out :: [a] -> [b] -> [(a, b)] -zip_it_up_and_zip_it_out = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.expected.hs deleted file mode 100644 index 0e4c0985fa..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.expected.hs +++ /dev/null @@ -1,21 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -import Data.Kind - -data Nat = Z | S Nat - -data HList (ls :: [Type]) where - HNil :: HList '[] - HCons :: t -> HList ts -> HList (t ': ts) - -data ElemAt (n :: Nat) t (ts :: [Type]) where - AtZ :: ElemAt 'Z t (t ': ts) - AtS :: ElemAt k t ts -> ElemAt ('S k) t (u ': ts) - -lookMeUp :: ElemAt i ty tys -> HList tys -> ty -lookMeUp AtZ (HCons t hl') = _w0 -lookMeUp (AtS ea') (HCons t hl') = _w1 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.hs deleted file mode 100644 index 3ac66d5444..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructAllGADTEvidence.hs +++ /dev/null @@ -1,20 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} - -import Data.Kind - -data Nat = Z | S Nat - -data HList (ls :: [Type]) where - HNil :: HList '[] - HCons :: t -> HList ts -> HList (t ': ts) - -data ElemAt (n :: Nat) t (ts :: [Type]) where - AtZ :: ElemAt 'Z t (t ': ts) - AtS :: ElemAt k t ts -> ElemAt ('S k) t (u ': ts) - -lookMeUp :: ElemAt i ty tys -> HList tys -> ty -lookMeUp ea hl = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.expected.hs deleted file mode 100644 index e463935583..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} - -data family Yo -data instance Yo = Heya Int - -test :: Yo -> Int -test (Heya n) = _w0 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.hs deleted file mode 100644 index a93e1974fb..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructDataFam.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} - -data family Yo -data instance Yo = Heya Int - -test :: Yo -> Int -test b = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.expected.hs deleted file mode 100644 index eee4cbd587..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.expected.hs +++ /dev/null @@ -1,9 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} - -type family Yo where - Yo = Bool - -test :: Yo -> Int -test False = _w0 -test True = _w1 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.hs deleted file mode 100644 index 30a9d884b7..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructTyFam.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} - -type family Yo where - Yo = Bool - -test :: Yo -> Int -test b = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.expected.hs deleted file mode 100644 index 3016c4ef4e..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.expected.hs +++ /dev/null @@ -1,18 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE UndecidableInstances #-} - -type family T1 a where - T1 a = T2 Int - -type family T2 a -type instance T2 Int = T3 - -type family T3 where - T3 = Yo - -data family Yo -data instance Yo = Heya Int - -test :: T1 Bool -> Int -test (Heya n) = _w0 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.hs deleted file mode 100644 index 191fa7b044..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/DestructTyToDataFam.hs +++ /dev/null @@ -1,18 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE UndecidableInstances #-} - -type family T1 a where - T1 a = T2 Int - -type family T2 a -type instance T2 Int = T3 - -type family T3 where - T3 = Yo - -data family Yo -data instance Yo = Heya Int - -test :: T1 Bool -> Int -test b = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/Fgmap.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/Fgmap.expected.hs deleted file mode 100644 index 4f4921fa05..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/Fgmap.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -fgmap :: (Functor f, Functor g) => (a -> b) -> (f (g a) -> f (g b)) -fgmap = fmap . fmap diff --git a/plugins/hls-tactics-plugin/new/test/golden/Fgmap.hs b/plugins/hls-tactics-plugin/new/test/golden/Fgmap.hs deleted file mode 100644 index de1968474e..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/Fgmap.hs +++ /dev/null @@ -1,2 +0,0 @@ -fgmap :: (Functor f, Functor g) => (a -> b) -> (f (g a) -> f (g b)) -fgmap = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/FmapBoth.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/FmapBoth.expected.hs deleted file mode 100644 index 825b00ebea..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/FmapBoth.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -fmapBoth :: (Functor f, Functor g) => (a -> b) -> (f a, g a) -> (f b, g b) -fmapBoth fab (fa, ga) = (fmap fab fa, fmap fab ga) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/FmapBoth.hs b/plugins/hls-tactics-plugin/new/test/golden/FmapBoth.hs deleted file mode 100644 index 29d8ea62b2..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/FmapBoth.hs +++ /dev/null @@ -1,3 +0,0 @@ -fmapBoth :: (Functor f, Functor g) => (a -> b) -> (f a, g a) -> (f b, g b) -fmapBoth = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/FmapJoin.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/FmapJoin.expected.hs deleted file mode 100644 index 5dc5026f8b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/FmapJoin.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -fJoin :: (Monad m, Monad f) => f (m (m a)) -> f (m a) -fJoin = fmap (\ m -> m >>= id) diff --git a/plugins/hls-tactics-plugin/new/test/golden/FmapJoin.hs b/plugins/hls-tactics-plugin/new/test/golden/FmapJoin.hs deleted file mode 100644 index 98a40133ea..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/FmapJoin.hs +++ /dev/null @@ -1,2 +0,0 @@ -fJoin :: (Monad m, Monad f) => f (m (m a)) -> f (m a) -fJoin = fmap _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.expected.hs deleted file mode 100644 index ac4b54ae9d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.expected.hs +++ /dev/null @@ -1,4 +0,0 @@ -{-# LANGUAGE ScopedTypeVariables #-} - -fJoin :: forall f m a. (Monad m, Monad f) => f (m (m a)) -> f (m a) -fJoin = let f = ( (\ m -> m >>= id) :: m (m a) -> m a) in fmap f diff --git a/plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.hs b/plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.hs deleted file mode 100644 index e6fe6cbd0d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/FmapJoinInLet.hs +++ /dev/null @@ -1,4 +0,0 @@ -{-# LANGUAGE ScopedTypeVariables #-} - -fJoin :: forall f m a. (Monad m, Monad f) => f (m (m a)) -> f (m a) -fJoin = let f = (_ :: m (m a) -> m a) in fmap f diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenApplicativeThen.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenApplicativeThen.hs deleted file mode 100644 index 29ce9f5132..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenApplicativeThen.hs +++ /dev/null @@ -1,2 +0,0 @@ -useThen :: Applicative f => f Int -> f a -> f a -useThen = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.expected.hs deleted file mode 100644 index 6f7af5c3fd..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.expected.hs +++ /dev/null @@ -1,53 +0,0 @@ --- Emulate a quickcheck import; deriveArbitrary works on any type with the --- right name and kind -data Gen a - -data Obj - = Square Int Int - | Circle Int - | Polygon [(Int, Int)] - | Rotate2 Double Obj - | Empty - | Full - | Complement Obj - | UnionR Double [Obj] - | DifferenceR Double Obj [Obj] - | IntersectR Double [Obj] - | Translate Double Double Obj - | Scale Double Double Obj - | Mirror Double Double Obj - | Outset Double Obj - | Shell Double Obj - | WithRounding Double Obj - - -arbitrary :: Gen Obj -arbitrary - = let - terminal - = [(Square <$> arbitrary) <*> arbitrary, Circle <$> arbitrary, - Polygon <$> arbitrary, pure Empty, pure Full] - in - sized - $ (\ n - -> case n <= 1 of - True -> oneof terminal - False - -> oneof - $ ([(Rotate2 <$> arbitrary) <*> scale (subtract 1) arbitrary, - Complement <$> scale (subtract 1) arbitrary, - (UnionR <$> arbitrary) <*> scale (subtract 1) arbitrary, - ((DifferenceR <$> arbitrary) <*> scale (flip div 2) arbitrary) - <*> scale (flip div 2) arbitrary, - (IntersectR <$> arbitrary) <*> scale (subtract 1) arbitrary, - ((Translate <$> arbitrary) <*> arbitrary) - <*> scale (subtract 1) arbitrary, - ((Scale <$> arbitrary) <*> arbitrary) - <*> scale (subtract 1) arbitrary, - ((Mirror <$> arbitrary) <*> arbitrary) - <*> scale (subtract 1) arbitrary, - (Outset <$> arbitrary) <*> scale (subtract 1) arbitrary, - (Shell <$> arbitrary) <*> scale (subtract 1) arbitrary, - (WithRounding <$> arbitrary) <*> scale (subtract 1) arbitrary] - <> terminal)) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.hs deleted file mode 100644 index f45d2d1fea..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrary.hs +++ /dev/null @@ -1,26 +0,0 @@ --- Emulate a quickcheck import; deriveArbitrary works on any type with the --- right name and kind -data Gen a - -data Obj - = Square Int Int - | Circle Int - | Polygon [(Int, Int)] - | Rotate2 Double Obj - | Empty - | Full - | Complement Obj - | UnionR Double [Obj] - | DifferenceR Double Obj [Obj] - | IntersectR Double [Obj] - | Translate Double Double Obj - | Scale Double Double Obj - | Mirror Double Double Obj - | Outset Double Obj - | Shell Double Obj - | WithRounding Double Obj - - -arbitrary :: Gen Obj -arbitrary = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.expected.hs deleted file mode 100644 index 786e381ca8..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -data Gen a - -data Obj = Obj Int Bool Char String - -arbitrary :: Gen Obj -arbitrary - = (((Obj <$> arbitrary) <*> arbitrary) <*> arbitrary) <*> arbitrary \ No newline at end of file diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.hs deleted file mode 100644 index a6a7d171a3..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenArbitrarySingleConstructor.hs +++ /dev/null @@ -1,6 +0,0 @@ -data Gen a - -data Obj = Obj Int Bool Char String - -arbitrary :: Gen Obj -arbitrary = _ \ No newline at end of file diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.expected.hs deleted file mode 100644 index 1e7ccecde4..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.expected.hs +++ /dev/null @@ -1,4 +0,0 @@ --- There used to be a bug where we were unable to perform a nested split. The --- more serious regression test of this is 'AutoTupleSpec'. -bigTuple :: (a, b, c, d) -> (a, b, (c, d)) -bigTuple (a, b, c, d) = (a, b, (c, d)) diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.hs deleted file mode 100644 index 1ede521a5f..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenBigTuple.hs +++ /dev/null @@ -1,4 +0,0 @@ --- There used to be a bug where we were unable to perform a nested split. The --- more serious regression test of this is 'AutoTupleSpec'. -bigTuple :: (a, b, c, d) -> (a, b, (c, d)) -bigTuple = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.expected.hs deleted file mode 100644 index f7756898e0..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -either' :: (a -> c) -> (b -> c) -> Either a b -> c -either' fac _ (Left a) = fac a -either' _ fbc (Right b) = fbc b diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.hs deleted file mode 100644 index eb34cd8209..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenEitherAuto.hs +++ /dev/null @@ -1,2 +0,0 @@ -either' :: (a -> c) -> (b -> c) -> Either a b -> c -either' = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenFish.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenFish.hs deleted file mode 100644 index ce38700b58..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenFish.hs +++ /dev/null @@ -1,5 +0,0 @@ --- There was an old bug where we would only pull skolems from the hole, rather --- than the entire hypothesis. Because of this, the 'b' here would be --- considered a univar, which could then be unified with the skolem 'c'. -fish :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c -fish amb bmc a = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.expected.hs deleted file mode 100644 index 2b32b3a9cd..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.expected.hs +++ /dev/null @@ -1,5 +0,0 @@ -data Tree a = Leaf a | Branch (Tree a) (Tree a) - -instance Functor Tree where - fmap fab (Leaf a) = Leaf (fab a) - fmap fab (Branch tr' tr_a) = Branch (fmap fab tr') (fmap fab tr_a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.hs deleted file mode 100644 index 679e7902df..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenFmapTree.hs +++ /dev/null @@ -1,4 +0,0 @@ -data Tree a = Leaf a | Branch (Tree a) (Tree a) - -instance Functor Tree where - fmap = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.expected.hs deleted file mode 100644 index 89db0adb76..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -foldr2 :: (a -> b -> b) -> b -> [a] -> b -foldr2 _ b [] = b -foldr2 fabb b (a : as') = fabb a (foldr2 fabb b as') diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.hs deleted file mode 100644 index bade9c1e7a..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenFoldr.hs +++ /dev/null @@ -1,2 +0,0 @@ -foldr2 :: (a -> b -> b) -> b -> [a] -> b -foldr2 = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.expected.hs deleted file mode 100644 index 5b39ea5a4b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -fromMaybe :: a -> Maybe a -> a -fromMaybe a Nothing = a -fromMaybe _ (Just a') = a' diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.hs deleted file mode 100644 index e3046a29c3..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenFromMaybe.hs +++ /dev/null @@ -1,2 +0,0 @@ -fromMaybe :: a -> Maybe a -> a -fromMaybe = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.expected.hs deleted file mode 100644 index 88f33dd2da..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} -module GoldenGADTAuto where -data CtxGADT a where - MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT a - -ctxGADT :: CtxGADT () -ctxGADT = MkCtxGADT () diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.hs deleted file mode 100644 index 1c47dd0e07..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenGADTAuto.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE GADTs #-} -module GoldenGADTAuto where -data CtxGADT a where - MkCtxGADT :: (Show a, Eq a) => a -> CtxGADT a - -ctxGADT :: CtxGADT () -ctxGADT = _auto diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.expected.hs deleted file mode 100644 index 7b3d1beda0..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} - -type family TyFam -type instance TyFam = Int - -tyblah' :: TyFam -> Int -tyblah' = id diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.hs deleted file mode 100644 index be8903fec0..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdTypeFam.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} - -type family TyFam -type instance TyFam = Int - -tyblah' :: TyFam -> Int -tyblah' = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.expected.hs deleted file mode 100644 index 5c509d6507..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -data Ident a = Ident a -instance Functor Ident where - fmap fab (Ident a) = Ident (fab a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.hs deleted file mode 100644 index 6d1de50992..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenIdentityFunctor.hs +++ /dev/null @@ -1,3 +0,0 @@ -data Ident a = Ident a -instance Functor Ident where - fmap = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.expected.hs deleted file mode 100644 index e941214796..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.expected.hs +++ /dev/null @@ -1,4 +0,0 @@ -type Cont r a = ((a -> r) -> r) - -joinCont :: Cont r (Cont r a) -> Cont r a -joinCont f far = f (\ g -> g far) diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.hs deleted file mode 100644 index f2c63714da..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenJoinCont.hs +++ /dev/null @@ -1,4 +0,0 @@ -type Cont r a = ((a -> r) -> r) - -joinCont :: Cont r (Cont r a) -> Cont r a -joinCont = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.expected.hs deleted file mode 100644 index ec44241736..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -fmapList :: (a -> b) -> [a] -> [b] -fmapList _ [] = [] -fmapList fab (a : as') = fab a : fmapList fab as' diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.hs deleted file mode 100644 index 85293daaf4..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenListFmap.hs +++ /dev/null @@ -1,2 +0,0 @@ -fmapList :: (a -> b) -> [a] -> [b] -fmapList = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenNote.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenNote.expected.hs deleted file mode 100644 index 99bc0cd6d0..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenNote.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -note :: e -> Maybe a -> Either e a -note e Nothing = Left e -note _ (Just a) = Right a diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenNote.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenNote.hs deleted file mode 100644 index c9e0c820e4..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenNote.hs +++ /dev/null @@ -1,2 +0,0 @@ -note :: e -> Maybe a -> Either e a -note = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.expected.hs deleted file mode 100644 index 8f2bc80ea7..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -pureList :: a -> [a] -pureList a = a : [] diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.hs deleted file mode 100644 index 3a3293b4ec..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenPureList.hs +++ /dev/null @@ -1,2 +0,0 @@ -pureList :: a -> [a] -pureList = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.expected.hs deleted file mode 100644 index 7f8f73e5b7..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.expected.hs +++ /dev/null @@ -1,3 +0,0 @@ -safeHead :: [x] -> Maybe x -safeHead [] = Nothing -safeHead (x : _) = Just x diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.hs deleted file mode 100644 index 6a5d27c0d1..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSafeHead.hs +++ /dev/null @@ -1,2 +0,0 @@ -safeHead :: [x] -> Maybe x -safeHead = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenShow.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenShow.expected.hs deleted file mode 100644 index 05ba83e9fe..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenShow.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -showMe :: Show a => a -> String -showMe = show diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenShow.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenShow.hs deleted file mode 100644 index 9ec5e27bcf..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenShow.hs +++ /dev/null @@ -1,2 +0,0 @@ -showMe :: Show a => a -> String -showMe = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.expected.hs deleted file mode 100644 index d8a78b3017..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -showCompose :: Show a => (b -> a) -> b -> String -showCompose fba = show . fba diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.hs deleted file mode 100644 index c99768e4e5..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowCompose.hs +++ /dev/null @@ -1,2 +0,0 @@ -showCompose :: Show a => (b -> a) -> b -> String -showCompose = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.expected.hs deleted file mode 100644 index c32357d1a9..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -test :: Show a => a -> (String -> b) -> b -test a f = f (show a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.hs deleted file mode 100644 index 8e6e5eae6b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenShowMapChar.hs +++ /dev/null @@ -1,2 +0,0 @@ -test :: Show a => a -> (String -> b) -> b -test = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.expected.hs deleted file mode 100644 index e0a5dbb565..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -class Super a where - super :: a - -class Super a => Sub a - -blah :: Sub a => a -blah = super - diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.hs deleted file mode 100644 index 86a9fed7bc..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSuperclass.hs +++ /dev/null @@ -1,8 +0,0 @@ -class Super a where - super :: a - -class Super a => Sub a - -blah :: Sub a => a -blah = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.expected.hs deleted file mode 100644 index e09cb3800a..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -swap :: (a, b) -> (b, a) -swap (a, b) = (b, a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.hs deleted file mode 100644 index 9243955c54..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwap.hs +++ /dev/null @@ -1,2 +0,0 @@ -swap :: (a, b) -> (b, a) -swap = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.expected.hs deleted file mode 100644 index 1d2bc0a605..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -swapMany :: (a, b, c, d, e) -> (e, d, c, b, a) -swapMany (a, b, c, d, e) = (e, d, c, b, a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.hs b/plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.hs deleted file mode 100644 index b1f6c0fb2a..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/GoldenSwapMany.hs +++ /dev/null @@ -1,2 +0,0 @@ -swapMany :: (a, b, c, d, e) -> (e, d, c, b, a) -swapMany = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.expected.hs deleted file mode 100644 index 97668d8c90..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -too_many :: a -> b -> c -too_many a b = _w0 diff --git a/plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.hs b/plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.hs deleted file mode 100644 index 066f123a47..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/IntrosTooMany.hs +++ /dev/null @@ -1,2 +0,0 @@ -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 |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.expected.hs deleted file mode 100644 index c97ba98a6a..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.expected.hs +++ /dev/null @@ -1,9 +0,0 @@ -import Data.Monoid - -data Big a = Big [Bool] (Sum Int) String (Endo a) Any - -instance Semigroup (Big a) where - (Big bs sum s en any) <> (Big bs' sum' str en' any') - = Big - (bs <> bs') (sum <> sum') (s <> str) (en <> en') (any <> any') - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.hs deleted file mode 100644 index 49ea10b8b4..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownBigSemigroup.hs +++ /dev/null @@ -1,7 +0,0 @@ -import Data.Monoid - -data Big a = Big [Bool] (Sum Int) String (Endo a) Any - -instance Semigroup (Big a) where - (<>) = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.expected.hs deleted file mode 100644 index 8bef710c69..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE UndecidableInstances #-} - -data Semi = Semi [String] Int - -instance Semigroup Int => Semigroup Semi where - (Semi ss n) <> (Semi strs i) = Semi (ss <> strs) (n <> i) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.hs deleted file mode 100644 index 11e53f4191..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownCounterfactualSemigroup.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE UndecidableInstances #-} - -data Semi = Semi [String] Int - -instance Semigroup Int => Semigroup Semi where - (<>) = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.expected.hs deleted file mode 100644 index 179937cb6a..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.expected.hs +++ /dev/null @@ -1,5 +0,0 @@ -data Test a = Test [a] - -instance Semigroup (Test a) where - (Test a) <> (Test c) = Test (a <> c) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.hs deleted file mode 100644 index ed4182c6d9..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownDestructedSemigroup.hs +++ /dev/null @@ -1,5 +0,0 @@ -data Test a = Test [a] - -instance Semigroup (Test a) where - Test a <> Test c = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.expected.hs deleted file mode 100644 index f64222977b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Mono a = Monoid [String] a - -instance Semigroup (Mono a) where - (<>) = undefined - -instance Monoid (Mono a) where - mempty = Monoid mempty _w0 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.hs deleted file mode 100644 index 7c6bfc5ccd..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingMonoid.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Mono a = Monoid [String] a - -instance Semigroup (Mono a) where - (<>) = undefined - -instance Monoid (Mono a) where - mempty = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.expected.hs deleted file mode 100644 index 3f18919e80..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.expected.hs +++ /dev/null @@ -1,5 +0,0 @@ -data Semi = Semi [String] Int - -instance Semigroup Semi where - (Semi ss n) <> (Semi strs i) = Semi (ss <> strs) _w0 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.hs deleted file mode 100644 index 1193c14a3b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownMissingSemigroup.hs +++ /dev/null @@ -1,5 +0,0 @@ -data Semi = Semi [String] Int - -instance Semigroup Semi where - (<>) = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.expected.hs deleted file mode 100644 index 627217b285..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.expected.hs +++ /dev/null @@ -1,12 +0,0 @@ -data Foo = Foo - -instance Semigroup Foo where - (<>) _ _ = Foo - - -data Bar = Bar Foo Foo - -instance Semigroup Bar where - (Bar foo foo') <> (Bar foo2 foo3) - = Bar (foo <> foo2) (foo' <> foo3) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.hs deleted file mode 100644 index 8a03a029af..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownModuleInstanceSemigroup.hs +++ /dev/null @@ -1,11 +0,0 @@ -data Foo = Foo - -instance Semigroup Foo where - (<>) _ _ = Foo - - -data Bar = Bar Foo Foo - -instance Semigroup Bar where - (<>) = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.expected.hs deleted file mode 100644 index 6ad1e2bf92..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Mono = Monoid [String] - -instance Semigroup Mono where - (<>) = undefined - -instance Monoid Mono where - mempty = Monoid mempty - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.hs deleted file mode 100644 index 0667bee28c..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownMonoid.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Mono = Monoid [String] - -instance Semigroup Mono where - (<>) = undefined - -instance Monoid Mono where - mempty = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.expected.hs deleted file mode 100644 index 317f2e770b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Mono a = Monoid [String] a - -instance Semigroup (Mono a) where - (<>) = undefined - -instance Monoid a => Monoid (Mono a) where - mempty = Monoid mempty mempty - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.hs deleted file mode 100644 index 8ba7bc6d98..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownPolyMonoid.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Mono a = Monoid [String] a - -instance Semigroup (Mono a) where - (<>) = undefined - -instance Monoid a => Monoid (Mono a) where - mempty = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.expected.hs deleted file mode 100644 index 3711af103a..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.expected.hs +++ /dev/null @@ -1,5 +0,0 @@ -data Semi a = Semi a - -instance Semigroup a => Semigroup (Semi a) where - (Semi a) <> (Semi a') = Semi (a <> a') - diff --git a/plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.hs b/plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.hs deleted file mode 100644 index f5e38276fe..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/KnownThetaSemigroup.hs +++ /dev/null @@ -1,5 +0,0 @@ -data Semi a = Semi a - -instance Semigroup a => Semigroup (Semi a) where - (<>) = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBegin.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBegin.expected.hs deleted file mode 100644 index 3c56bdbee9..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBegin.expected.hs +++ /dev/null @@ -1 +0,0 @@ -foo = [wingman||] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBegin.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBegin.hs deleted file mode 100644 index fdfbd7289d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBegin.hs +++ /dev/null @@ -1 +0,0 @@ -foo = _ diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.expected.hs deleted file mode 100644 index c8aa76e837..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo v = [wingman||] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.hs deleted file mode 100644 index 2aa2d1caa3..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBeginNoWildify.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo v = _ - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.expected.hs deleted file mode 100644 index 00421ee479..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo :: a -> (a, a) -foo a = (a, a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.hs deleted file mode 100644 index d25670bca1..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBindAll.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo :: a -> (a, a) -foo a = [wingman| split; assumption |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.expected.hs deleted file mode 100644 index 05f86c9963..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo :: a -> (a, a) -foo a = (a, _w0) diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.hs deleted file mode 100644 index fe6c118829..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaBindOne.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo :: a -> (a, a) -foo a = [wingman| split, assumption |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.expected.hs deleted file mode 100644 index aac10101ec..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.expected.hs +++ /dev/null @@ -1,23 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data AST a where - BoolLit :: Bool -> AST Bool - IntLit :: Int -> AST Int - If :: AST Bool -> AST a -> AST a -> AST a - Equal :: AST a -> AST a -> AST Bool - -eval :: AST a -> a -eval (BoolLit b) = b -eval (IntLit n) = n -eval (If ast ast' ast_a) - = let - ast_c = eval ast - ast'_c = eval ast' - ast_a_c = eval ast_a - in _w0 ast_c ast'_c ast_a_c -eval (Equal ast ast') - = let - ast_c = eval ast - ast'_c = eval ast' - in _w1 ast_c ast'_c - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.hs deleted file mode 100644 index 26e3a03cec..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaCataAST.hs +++ /dev/null @@ -1,11 +0,0 @@ -{-# LANGUAGE GADTs #-} - -data AST a where - BoolLit :: Bool -> AST Bool - IntLit :: Int -> AST Int - If :: AST Bool -> AST a -> AST a -> AST a - Equal :: AST a -> AST a -> AST Bool - -eval :: AST a -> a -eval = [wingman| intros x, cata x; collapse |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.expected.hs deleted file mode 100644 index 58b4fb4ffc..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.expected.hs +++ /dev/null @@ -1,14 +0,0 @@ -{-# LANGUAGE TypeOperators #-} - -import GHC.Generics - -class Yo f where - yo :: f x -> Int - -instance (Yo f, Yo g) => Yo (f :*: g) where - yo (fx :*: gx) - = let - fx_c = yo fx - gx_c = yo gx - in _w0 fx_c gx_c - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.hs deleted file mode 100644 index 14dc163f4d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapse.hs +++ /dev/null @@ -1,10 +0,0 @@ -{-# LANGUAGE TypeOperators #-} - -import GHC.Generics - -class Yo f where - yo :: f x -> Int - -instance (Yo f, Yo g) => Yo (f :*: g) where - yo = [wingman| intros x, cata x, collapse |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.expected.hs deleted file mode 100644 index e9cef291a3..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -import GHC.Generics - -class Yo f where - yo :: f x -> Int - -instance (Yo f) => Yo (M1 _1 _2 f) where - yo (M1 fx) = yo fx - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.hs deleted file mode 100644 index c1abb0acf2..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaCataCollapseUnary.hs +++ /dev/null @@ -1,8 +0,0 @@ -import GHC.Generics - -class Yo f where - yo :: f x -> Int - -instance (Yo f) => Yo (M1 _1 _2 f) where - yo = [wingman| intros x, cata x, collapse |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaChoice.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaChoice.expected.hs deleted file mode 100644 index c9d2f0cff9..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaChoice.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -reassoc :: (a, (b, c)) -> ((a, b), c) -reassoc (a, (b, c)) = ((a, b), c) diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaChoice.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaChoice.hs deleted file mode 100644 index 97e5b424ba..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaChoice.hs +++ /dev/null @@ -1,2 +0,0 @@ -reassoc :: (a, (b, c)) -> ((a, b), c) -reassoc (a, (b, c)) = [wingman| split; split | assume c; assume a | assume b |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.expected.hs deleted file mode 100644 index 90216da0a2..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -whats_it_deep_of - :: (a -> a) - -> [(Int, Either Bool (Maybe [a]))] - -> [(Int, Either Bool (Maybe [a]))] --- The assumption here is necessary to tie-break in favor of the longest --- nesting of fmaps. -whats_it_deep_of f = fmap (fmap (fmap (fmap (fmap f)))) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.hs deleted file mode 100644 index 3afcdcc4e1..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaDeepOf.hs +++ /dev/null @@ -1,8 +0,0 @@ -whats_it_deep_of - :: (a -> a) - -> [(Int, Either Bool (Maybe [a]))] - -> [(Int, Either Bool (Maybe [a]))] --- The assumption here is necessary to tie-break in favor of the longest --- nesting of fmaps. -whats_it_deep_of f = [wingman| nested fmap, assumption |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.expected.hs deleted file mode 100644 index f589d989f7..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.expected.hs +++ /dev/null @@ -1,16 +0,0 @@ -{-# LANGUAGE FunctionalDependencies #-} -{-# LANGUAGE MultiParamTypeClasses #-} - -class Blah a b | a -> b, b -> a -instance Blah Int Bool - -foo :: Int -foo = 10 - -bar :: Blah a b => a -> b -bar = undefined - -qux :: Bool -qux = bar foo - - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.hs deleted file mode 100644 index 36d0d4bf73..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaFundeps.hs +++ /dev/null @@ -1,16 +0,0 @@ -{-# LANGUAGE FunctionalDependencies #-} -{-# LANGUAGE MultiParamTypeClasses #-} - -class Blah a b | a -> b, b -> a -instance Blah Int Bool - -foo :: Int -foo = 10 - -bar :: Blah a b => a -> b -bar = undefined - -qux :: Bool -qux = [wingman| use bar, use foo |] - - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.expected.hs deleted file mode 100644 index 21569c7c19..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.expected.hs +++ /dev/null @@ -1,6 +0,0 @@ -foo :: Int -> Int -> Int -foo = undefined - -test :: Maybe Int -test = (foo <$> _w0) <*> _w1 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.hs deleted file mode 100644 index f9506cb03b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiom.hs +++ /dev/null @@ -1,6 +0,0 @@ -foo :: Int -> Int -> Int -foo = undefined - -test :: Maybe Int -test = [wingman| idiom (use foo) |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.expected.hs deleted file mode 100644 index e39e9a9fab..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Rec = Rec - { a :: Int - , b :: Bool - } - -test :: Maybe Rec -test = (Rec <$> _w0) <*> _w1 - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.hs deleted file mode 100644 index 87397da160..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaIdiomRecord.hs +++ /dev/null @@ -1,8 +0,0 @@ -data Rec = Rec - { a :: Int - , b :: Bool - } - -test :: Maybe Rec -test = [wingman| idiom (ctor Rec) |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.expected.hs deleted file mode 100644 index 54c3678c21..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -test :: Int -test - = let - a = _w0 - b = _w1 - c = _w2 - in _w3 diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.hs deleted file mode 100644 index ae570bae7b..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaLetSimple.hs +++ /dev/null @@ -1,2 +0,0 @@ -test :: Int -test = [wingman| let a b c |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.expected.hs deleted file mode 100644 index e0b60b74fa..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.expected.hs +++ /dev/null @@ -1,5 +0,0 @@ -maybeAp :: Maybe (a -> b) -> Maybe a -> Maybe b -maybeAp Nothing Nothing = Nothing -maybeAp Nothing (Just _) = Nothing -maybeAp (Just _) Nothing = Nothing -maybeAp (Just fab) (Just a) = Just (fab a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.hs deleted file mode 100644 index 6159db4ecd..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaMaybeAp.hs +++ /dev/null @@ -1,11 +0,0 @@ -maybeAp :: Maybe (a -> b) -> Maybe a -> Maybe b -maybeAp = [wingman| - intros, - destruct_all, - obvious, - obvious, - obvious, - ctor Just, - application, - assumption - |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.expected.hs deleted file mode 100644 index f92e7d40af..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.expected.hs +++ /dev/null @@ -1,8 +0,0 @@ -import Data.Monoid - -data Foo = Foo (Sum Int) (Sum Int) - -mappend2 :: Foo -> Foo -> Foo -mappend2 (Foo sum sum') (Foo sum2 sum3) - = Foo (mappend sum sum2) (mappend sum' sum3) - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.hs deleted file mode 100644 index 77572569ff..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaPointwise.hs +++ /dev/null @@ -1,7 +0,0 @@ -import Data.Monoid - -data Foo = Foo (Sum Int) (Sum Int) - -mappend2 :: Foo -> Foo -> Foo -mappend2 = [wingman| intros f1 f2, destruct_all, ctor Foo; pointwise (use mappend); assumption|] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaTry.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaTry.expected.hs deleted file mode 100644 index 0940f9ea21..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaTry.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo :: a -> (b, a) -foo a = (_w0, a) diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaTry.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaTry.hs deleted file mode 100644 index 582189bcbc..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaTry.hs +++ /dev/null @@ -1,2 +0,0 @@ -foo :: a -> (b, a) -foo a = [wingman| split; try (assumption) |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.expected.hs deleted file mode 100644 index c72f18589c..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.expected.hs +++ /dev/null @@ -1,6 +0,0 @@ -import Data.Char - - -result :: Char -> Bool -result = isAlpha - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.hs deleted file mode 100644 index 87ac26bbcb..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseImport.hs +++ /dev/null @@ -1,6 +0,0 @@ -import Data.Char - - -result :: Char -> Bool -result = [wingman| intro c, use isAlpha, assume c |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.expected.hs deleted file mode 100644 index 1afee3471a..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.expected.hs +++ /dev/null @@ -1,7 +0,0 @@ -test :: Int -test = 0 - - -resolve :: Int -resolve = test - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.hs deleted file mode 100644 index 0f791818d1..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseLocal.hs +++ /dev/null @@ -1,7 +0,0 @@ -test :: Int -test = 0 - - -resolve :: Int -resolve = [wingman| use test |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.expected.hs deleted file mode 100644 index acf46a75a0..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.expected.hs +++ /dev/null @@ -1,12 +0,0 @@ -{-# LANGUAGE MultiParamTypeClasses #-} - -class Test where - test :: Int - -instance Test where - test = 10 - - -resolve :: Int -resolve = test - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.hs deleted file mode 100644 index 4723befd10..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseMethod.hs +++ /dev/null @@ -1,12 +0,0 @@ -{-# LANGUAGE MultiParamTypeClasses #-} - -class Test where - test :: Int - -instance Test where - test = 10 - - -resolve :: Int -resolve = [wingman| use test |] - diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.expected.hs deleted file mode 100644 index 85012d7aaf..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.expected.hs +++ /dev/null @@ -1,4 +0,0 @@ -import Data.Monoid - -resolve :: Sum Int -resolve = _w0 <> _w1 diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.hs deleted file mode 100644 index 4afe5f572d..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaUseSymbol.hs +++ /dev/null @@ -1,4 +0,0 @@ -import Data.Monoid - -resolve :: Sum Int -resolve = [wingman| use (<>) |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.expected.hs deleted file mode 100644 index 895e9333c0..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.expected.hs +++ /dev/null @@ -1,2 +0,0 @@ -wat :: a -> b -wat a = _w0 a diff --git a/plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.hs b/plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.hs deleted file mode 100644 index 75c6ab0445..0000000000 --- a/plugins/hls-tactics-plugin/new/test/golden/MetaWithArg.hs +++ /dev/null @@ -1,2 +0,0 @@ -wat :: a -> b -wat a = [wingman| with_arg, assumption |] diff --git a/plugins/hls-tactics-plugin/new/test/golden/SubsequentTactics.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/SubsequentTactics.expected.hs index e638fa311c..45f26168cd 100644 --- a/plugins/hls-tactics-plugin/new/test/golden/SubsequentTactics.expected.hs +++ b/plugins/hls-tactics-plugin/new/test/golden/SubsequentTactics.expected.hs @@ -1,5 +1,5 @@ data Dummy a = Dummy a f :: Dummy Int -> Int -f (Dummy n) = n +f (Dummy n) = _w1 From f8d6634322db2e89f5cdc406f4971a39c5aeef5b Mon Sep 17 00:00:00 2001 From: Santiago Weight Date: Sun, 4 Dec 2022 23:14:14 -0800 Subject: [PATCH 2/2] wingman: support 9.2.4 --- ghcide/src/Development/IDE/Core/Rules.hs | 4 +- ghcide/src/Development/IDE/Plugin.hs | 4 +- ghcide/src/Development/IDE/Plugin/HLS.hs | 2 +- ghcide/src/Development/IDE/Types/Options.hs | 4 +- ghcide/src/Generics/SYB/GHC.hs | 28 +++- hls-plugin-api/src/Ide/Types.hs | 57 ++++--- .../src/Development/IDE/GHC/ExactPrint.hs | 65 +++++--- .../hls-tactics-plugin.cabal | 144 +++++++++++------- .../new/src/Wingman/AbstractLSP.hs | 2 +- .../src/Wingman/AbstractLSP/TacticActions.hs | 46 ++++-- .../new/src/Wingman/CaseSplit.hs | 48 ++++-- .../new/src/Wingman/CodeGen.hs | 44 +++--- .../new/src/Wingman/CodeGen/Utils.hs | 10 +- .../new/src/Wingman/Debug.hs | 6 - .../new/src/Wingman/EmptyCase.hs | 35 +++-- .../hls-tactics-plugin/new/src/Wingman/GHC.hs | 65 ++++++-- .../new/src/Wingman/Judgements/SYB.hs | 31 ++-- .../new/src/Wingman/LanguageServer.hs | 43 +++--- .../Wingman/LanguageServer/TacticProviders.hs | 1 - .../new/src/Wingman/Machinery.hs | 2 +- .../new/src/Wingman/StaticPlugin.hs | 11 +- .../new/src/Wingman/Tactics.hs | 2 +- .../new/src/Wingman/Types.hs | 20 ++- .../new/test/CodeAction/DestructSpec.hs | 1 + .../new/test/CodeLens/EmptyCaseSpec.hs | 2 +- plugins/hls-tactics-plugin/new/test/Utils.hs | 2 +- .../golden/DestructIntNotTopLevel.expected.hs | 9 ++ .../new/test/golden/DestructIntNotTopLevel.hs | 9 ++ .../new/test/golden/LayoutSplitIn.expected.hs | 2 +- .../hls-tactics-plugin/{ => old}/COMMANDS.md | 0 30 files changed, 462 insertions(+), 237 deletions(-) create mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.expected.hs create mode 100644 plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.hs rename plugins/hls-tactics-plugin/{ => old}/COMMANDS.md (100%) diff --git a/ghcide/src/Development/IDE/Core/Rules.hs b/ghcide/src/Development/IDE/Core/Rules.hs index d241541ac6..c6cf581761 100644 --- a/ghcide/src/Development/IDE/Core/Rules.hs +++ b/ghcide/src/Development/IDE/Core/Rules.hs @@ -143,7 +143,7 @@ import Ide.Plugin.Properties (HasProperty, ToHsType, useProperty) import Ide.PluginUtils (configForPlugin) -import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser), +import Ide.Types (GhcOptsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser), PluginId) import Control.Concurrent.STM.Stats (atomically) import Language.LSP.Server (LspT) @@ -338,7 +338,7 @@ getParsedModuleWithCommentsRule recorder = liftIO $ fmap (fmap reset_ms) $ snd <$> getParsedModuleDefinition (hscEnv sess) opt file ms -getModifyDynFlags :: (DynFlagsModifications -> a) -> Action a +getModifyDynFlags :: (GhcOptsModifications -> a) -> Action a getModifyDynFlags f = do opts <- getIdeOptions cfg <- getClientConfigAction def diff --git a/ghcide/src/Development/IDE/Plugin.hs b/ghcide/src/Development/IDE/Plugin.hs index 0e682d6c9f..5d67828e99 100644 --- a/ghcide/src/Development/IDE/Plugin.hs +++ b/ghcide/src/Development/IDE/Plugin.hs @@ -4,13 +4,13 @@ import Data.Default import Development.IDE.Graph import Development.IDE.LSP.Server -import Ide.Types (DynFlagsModifications) +import Ide.Types (GhcOptsModifications) import qualified Language.LSP.Server as LSP data Plugin c = Plugin {pluginRules :: Rules () ,pluginHandlers :: LSP.Handlers (ServerM c) - ,pluginModifyDynflags :: c -> DynFlagsModifications + ,pluginModifyDynflags :: c -> GhcOptsModifications } instance Default (Plugin c) where diff --git a/ghcide/src/Development/IDE/Plugin/HLS.hs b/ghcide/src/Development/IDE/Plugin/HLS.hs index 72aa5d5076..2782383700 100644 --- a/ghcide/src/Development/IDE/Plugin/HLS.hs +++ b/ghcide/src/Development/IDE/Plugin/HLS.hs @@ -125,7 +125,7 @@ rulesPlugins rs = mempty { P.pluginRules = rules } where rules = foldMap snd rs -dynFlagsPlugins :: [(PluginId, DynFlagsModifications)] -> Plugin Config +dynFlagsPlugins :: [(PluginId, GhcOptsModifications)] -> Plugin Config dynFlagsPlugins rs = mempty { P.pluginModifyDynflags = flip foldMap rs $ \(plId, dflag_mods) cfg -> diff --git a/ghcide/src/Development/IDE/Types/Options.hs b/ghcide/src/Development/IDE/Types/Options.hs index 5b59bf0d3b..1856f875b6 100644 --- a/ghcide/src/Development/IDE/Types/Options.hs +++ b/ghcide/src/Development/IDE/Types/Options.hs @@ -26,7 +26,7 @@ import Development.IDE.GHC.Compat as GHC import Development.IDE.Graph import Development.IDE.Types.Diagnostics import Ide.Plugin.Config -import Ide.Types (DynFlagsModifications) +import Ide.Types (GhcOptsModifications) import qualified Language.LSP.Types.Capabilities as LSP data IdeOptions = IdeOptions @@ -71,7 +71,7 @@ data IdeOptions = IdeOptions -- Otherwise, return the result of parsing without Opt_Haddock, so -- that the parsed module contains the result of Opt_KeepRawTokenStream, -- which might be necessary for hlint. - , optModifyDynFlags :: Config -> DynFlagsModifications + , optModifyDynFlags :: Config -> GhcOptsModifications -- ^ Will be called right after setting up a new cradle, -- allowing to customize the Ghc options used , optShakeOptions :: ShakeOptions diff --git a/ghcide/src/Generics/SYB/GHC.hs b/ghcide/src/Generics/SYB/GHC.hs index 8aaf99fa32..b5a97a664f 100644 --- a/ghcide/src/Generics/SYB/GHC.hs +++ b/ghcide/src/Generics/SYB/GHC.hs @@ -1,5 +1,6 @@ {-# LANGUAGE DerivingVia #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE CPP #-} -- | Custom SYB traversals explicitly designed for operating over the GHC AST. module Generics.SYB.GHC @@ -7,7 +8,10 @@ module Generics.SYB.GHC mkBindListT, everywhereM', smallestM, - largestM + largestM, +#if MIN_VERSION_ghc(9,2,1) + genericIsSubspanL +#endif ) where import Control.Monad @@ -16,6 +20,10 @@ import Data.Monoid (Any (Any)) import Development.IDE.GHC.Compat import Development.IDE.Graph.Classes import Generics.SYB +#if MIN_VERSION_ghc(9,2,1) +import GHC (LocatedL) +import GHC.Hs (SrcSpanAnn' (..)) +#endif -- | A generic query intended to be used for calling 'smallestM' and @@ -33,6 +41,24 @@ genericIsSubspan :: genericIsSubspan _ dst = mkQ Nothing $ \case (L span ast :: Located ast) -> Just (dst `isSubspanOf` span, ast) +#if MIN_VERSION_ghc(9,2,1) +-- | A generic query intended to be used for calling 'smallestM' and +-- 'largestM'. If the current node is a 'Located', returns whether or not the +-- given 'SrcSpan' is a subspan. For all other nodes, returns 'Nothing', which +-- indicates uncertainty. The search strategy in 'smallestM' et al. will +-- continue searching uncertain nodes. +genericIsSubspanL :: + forall ast. + Typeable ast => + -- | The type of nodes we'd like to consider. + Proxy (LocatedL ast) -> + SrcSpan -> + GenericQ (Maybe (Bool, ast)) +genericIsSubspanL _ dst = mkQ Nothing $ \case + (L (SrcSpanAnn _ span) ast :: LocatedL ast) -> Just (dst `isSubspanOf` span, ast) +#endif + + -- | Lift a function that replaces a value with several values into a generic -- function. The result doesn't perform any searching, so should be driven via diff --git a/hls-plugin-api/src/Ide/Types.hs b/hls-plugin-api/src/Ide/Types.hs index 8630905274..a3955c4d0b 100644 --- a/hls-plugin-api/src/Ide/Types.hs +++ b/hls-plugin-api/src/Ide/Types.hs @@ -26,8 +26,8 @@ module Ide.Types , IdeCommand(..) , IdeMethod(..) , IdeNotification(..) +, GhcOptsModifications(..) , IdePlugins(IdePlugins, ipMap) -, DynFlagsModifications(..) , ConfigDescriptor(..), defaultConfigDescriptor, configForPlugin, pluginEnabledConfig , CustomConfig(..), mkCustomConfig , FallbackCodeActionParams(..) @@ -109,6 +109,11 @@ import System.FilePath import System.IO.Unsafe import Text.Regex.TDFA.Text () +#if MIN_VERSION_ghc(9,2,0) +import GHC.Plugins (StaticPlugin) +#endif + + -- --------------------------------------------------------------------- data IdePlugins ideState = IdePlugins_ @@ -137,28 +142,40 @@ lookupPluginId ls cmd = pluginId <$> find go ls where go desc = cmd `elem` map commandId (pluginCommands desc) --- | Hooks for modifying the 'DynFlags' at different times of the compilation --- process. Plugins can install a 'DynFlagsModifications' via --- 'pluginModifyDynflags' in their 'PluginDescriptor'. -data DynFlagsModifications = - DynFlagsModifications - { -- | Invoked immediately at the package level. Changes to the 'DynFlags' - -- made in 'dynFlagsModifyGlobal' are guaranteed to be seen everywhere in - -- the compilation pipeline. - dynFlagsModifyGlobal :: DynFlags -> DynFlags - -- | Invoked just before the parsing step, and reset immediately - -- afterwards. 'dynFlagsModifyParser' allows plugins to enable language - -- extensions only during parsing. for example, to let them enable - -- certain pieces of syntax. +{- | Hooks for modifying the 'DynFlags' at different times of the compilation + process. Plugins can install a 'GhcOptsModifications' via + 'pluginModifyDynflags' in their 'PluginDescriptor'. +-} +data GhcOptsModifications = GhcOptsModifications + { dynFlagsModifyGlobal :: DynFlags -> DynFlags + -- ^ Invoked immediately at the package level. Changes to the 'DynFlags' + -- made in 'dynFlagsModifyGlobal' are guaranteed to be seen everywhere in + -- the compilation pipeline. , dynFlagsModifyParser :: DynFlags -> DynFlags + -- ^ Invoked just before the parsing step, and reset immediately + -- afterwards. 'dynFlagsModifyParser' allows plugins to enable language + -- extensions only during parsing. for example, to let them enable + -- certain pieces of syntax. +#if MIN_VERSION_ghc(9,2,0) + , staticPlugins :: [StaticPlugin] +#endif } -instance Semigroup DynFlagsModifications where - DynFlagsModifications g1 p1 <> DynFlagsModifications g2 p2 = - DynFlagsModifications (g2 . g1) (p2 . p1) +#if MIN_VERSION_ghc(9,2,0) +instance Semigroup GhcOptsModifications where + GhcOptsModifications g1 p1 plugins1 <> GhcOptsModifications g2 p2 plugins2 = + GhcOptsModifications (g2 . g1) (p2 . p1) (plugins1 <> plugins2) -instance Monoid DynFlagsModifications where - mempty = DynFlagsModifications id id +instance Monoid GhcOptsModifications where + mempty = GhcOptsModifications id id [] +#else +instance Semigroup GhcOptsModifications where + GhcOptsModifications g1 p1 <> GhcOptsModifications g2 p2 = + GhcOptsModifications (g2 . g1) (p2 . p1) + +instance Monoid GhcOptsModifications where + mempty = GhcOptsModifications id id +#endif -- --------------------------------------------------------------------- @@ -177,7 +194,7 @@ data PluginDescriptor (ideState :: *) = , pluginHandlers :: PluginHandlers ideState , pluginConfigDescriptor :: ConfigDescriptor , pluginNotificationHandlers :: PluginNotificationHandlers ideState - , pluginModifyDynflags :: DynFlagsModifications + , pluginModifyDynflags :: GhcOptsModifications , pluginCli :: Maybe (ParserInfo (IdeCommand ideState)) , pluginFileType :: [T.Text] -- ^ File extension of the files the plugin is responsible for. diff --git a/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs b/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs index 4704afd9eb..e5942711f8 100644 --- a/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs +++ b/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs @@ -20,6 +20,7 @@ module Development.IDE.GHC.ExactPrint transform, transformM, ExactPrint(..), +#endif #if MIN_VERSION_ghc(9,2,1) modifySmallestDeclWithM, modifyMgMatchesT, @@ -54,7 +55,7 @@ module Development.IDE.GHC.ExactPrint where import Control.Applicative (Alternative) -import Control.Arrow (right, (***)) +import Control.Arrow ((***)) import Control.DeepSeq import Control.Monad import qualified Control.Monad.Fail as Fail @@ -67,14 +68,12 @@ import Data.Bool (bool) import Data.Default (Default) import qualified Data.DList as DL import Data.Either.Extra (mapLeft) -import Data.Foldable (Foldable (fold)) import Data.Functor.Classes import Data.Functor.Contravariant import Data.Monoid (All (All), getAll) import qualified Data.Text as T import Data.Traversable (for) import Development.IDE.Core.RuleTypes -import Development.IDE.Core.Service (runAction) import Development.IDE.Core.Shake hiding (Log) import qualified Development.IDE.Core.Shake as Shake import Development.IDE.GHC.Compat hiding (parseImport, @@ -112,6 +111,8 @@ import GHC.Parser.Annotation (AnnContext (..), DeltaPos (SameLine), EpaLocation (EpaDelta), deltaPos) +import GHC (realSrcSpan) +import GHC (LocatedL) #endif #if MIN_VERSION_ghc(9,2,1) @@ -217,7 +218,8 @@ transform :: transform dflags ccs uri f a = do let src = printA a a' <- transformA a $ runGraft f dflags - let res = printA a' + a'' <- transformA a' (pure . makeDeltaAst) + let res = printA a'' pure $ diffText ccs (uri, T.pack src) (T.pack res) IncludeDeletions ------------------------------------------------------------------------------ @@ -277,7 +279,7 @@ needsParensSpace _ = mempty -} graft' :: forall ast a l. - (Data a, Typeable l, ASTElement l ast) => + (Data a, Data l, Typeable l, ASTElement l ast, ExactPrint ast) => -- | Do we need to insert a space before this grafting? In do blocks, the -- answer is no, or we will break layout. But in function applications, -- the answer is yes, or the function call won't get its argument. Yikes! @@ -288,7 +290,9 @@ graft' :: LocatedAn l ast -> Graft (Either String) a graft' needs_space dst val = Graft $ \dflags a -> do -#if MIN_VERSION_ghc(9,2,0) +#if MIN_VERSION_ghc(9,2,1) + L src' val' <- annotate dflags needs_space val +#elif MIN_VERSION_ghc(9,2,0) val' <- annotate dflags needs_space val #else (anns, val') <- annotate dflags needs_space val @@ -299,7 +303,7 @@ graft' needs_space dst val = Graft $ \dflags a -> do ( mkT $ \case (L src _ :: LocatedAn l ast) - | locA src `eqSrcSpan` dst -> val' + | locA src `eqSrcSpan` dst -> L src (makeDeltaAst val') l -> l ) a @@ -351,21 +355,24 @@ graftExprWithM :: (LHsExpr GhcPs -> TransformT m (Maybe (LHsExpr GhcPs))) -> Graft m a graftExprWithM dst trans = Graft $ \dflags a -> do - let (needs_space, mk_parens) = getNeedsSpaceAndParenthesize dst a + let (needs_space, mk_parens) = getNeedsSpaceAndParenthesize dst a everywhereM' ( mkM $ \case - val@(L src _ :: LHsExpr GhcPs) + val@(L src@(SrcSpanAnn (EpAnn anchor _ _) _) _ :: LHsExpr GhcPs) | locA src `eqSrcSpan` dst -> do mval <- trans val case mval of Just val' -> do #if MIN_VERSION_ghc(9,2,0) - val'' <- + (makeDeltaAst -> val'') <- hoistTransform (either Fail.fail pure) - (annotate @AnnListItem @(HsExpr GhcPs) dflags needs_space (mk_parens val')) - pure val'' + (annotate @AnnListItem @(HsExpr GhcPs) dflags True (mk_parens val')) + case val'' of + L (SrcSpanAnn (EpAnn _ extAnn extComments) span) e -> do + pure $ L (SrcSpanAnn (EpAnn anchor extAnn extComments) span) e + _ -> error "" #else (anns, val'') <- hoistTransform (either Fail.fail pure) @@ -380,7 +387,7 @@ graftExprWithM dst trans = Graft $ \dflags a -> do graftWithM :: forall ast m a l. - (Fail.MonadFail m, Data a, Typeable l, ASTElement l ast) => + (Fail.MonadFail m, Data a, Data l, ASTElement l ast) => SrcSpan -> (LocatedAn l ast -> TransformT m (Maybe (LocatedAn l ast))) -> Graft m a @@ -416,12 +423,12 @@ genericGraftWithSmallestM :: forall m a ast. (Monad m, Data a, Typeable ast) => -- | The type of nodes we'd like to consider when finding the smallest. - Proxy (Located ast) -> + Proxy (LocatedL ast) -> SrcSpan -> (DynFlags -> ast -> GenericM (TransformT m)) -> Graft m a genericGraftWithSmallestM proxy dst trans = Graft $ \dflags -> - smallestM (genericIsSubspan proxy dst) (trans dflags) + smallestM (genericIsSubspanL proxy dst) (trans dflags) -- | Run the given transformation only on the largest node in the tree that -- contains the 'SrcSpan'. @@ -641,7 +648,7 @@ class -} graft :: forall a. - (Data a) => + (Data a, Data l, ExactPrint ast) => SrcSpan -> LocatedAn l ast -> Graft (Either String) a @@ -687,7 +694,7 @@ fixAnns ParsedModule {..} = -- | Given an 'LHSExpr', compute its exactprint annotations. -- Note that this function will throw away any existing annotations (and format) -annotate :: (ASTElement l ast, Outputable l) +annotate :: (Data l, ASTElement l ast, Outputable l) #if MIN_VERSION_ghc(9,2,0) => DynFlags -> Bool -> LocatedAn l ast -> TransformT (Either String) (LocatedAn l ast) #else @@ -696,7 +703,10 @@ annotate :: (ASTElement l ast, Outputable l) annotate dflags needs_space ast = do uniq <- show <$> uniqueSrcSpanT let rendered = render dflags ast -#if MIN_VERSION_ghc(9,2,0) +#if MIN_VERSION_ghc(9,2,1) + expr' <- lift $ mapLeft show $ parseAST dflags uniq rendered + pure expr' +#elif MIN_VERSION_ghc(9,2,0) expr' <- lift $ mapLeft show $ parseAST dflags uniq rendered pure $ setPrecedingLines expr' 0 (bool 0 1 needs_space) #else @@ -707,7 +717,6 @@ annotate dflags needs_space ast = do -- | Given an 'LHsDecl', compute its exactprint annotations. annotateDecl :: DynFlags -> LHsDecl GhcPs -> TransformT (Either String) (LHsDecl GhcPs) -#if !MIN_VERSION_ghc(9,2,0) -- The 'parseDecl' function fails to parse 'FunBind' 'ValD's which contain -- multiple matches. To work around this, we split the single -- 'FunBind'-of-multiple-'Match'es into multiple 'FunBind's-of-one-'Match', @@ -720,6 +729,17 @@ annotateDecl dflags let set_matches matches = ValD ext fb { fun_matches = mg { mg_alts = L alt_src matches }} +#if MIN_VERSION_ghc(9,2,0) + alts' <- for alts $ \alt -> do + uniq <- show <$> uniqueSrcSpanT + let rendered = render dflags $ set_matches [alt] + lift (mapLeft show $ parseDecl dflags uniq rendered) >>= \case + (L _ (ValD _ FunBind { fun_matches = MG { mg_alts = L _ [alt']}})) + -> pure alt' + _ -> lift $ Left "annotateDecl: didn't parse a single FunBind match" + + pure $ L src $ set_matches $ makeDeltaAst <$> alts' +#else (anns', alts') <- fmap unzip $ for alts $ \alt -> do uniq <- show <$> uniqueSrcSpanT let rendered = render dflags $ set_matches [alt] @@ -760,8 +780,13 @@ parenthesize = parenthesizeHsExpr appPrec -- | Equality on SrcSpan's. -- Ignores the (Maybe BufSpan) field of SrcSpan's. +#if MIN_VERSION_ghc(9,2,0) +eqSrcSpan :: SrcSpan -> SrcSpan -> Bool +eqSrcSpan (realSrcSpan -> l) (realSrcSpan -> r) = containsSpan l r && containsSpan r l +#else eqSrcSpan :: SrcSpan -> SrcSpan -> Bool eqSrcSpan l r = leftmost_smallest l r == EQ +#endif -- | Equality on SrcSpan's. -- Ignores the (Maybe BufSpan) field of SrcSpan's. @@ -819,5 +844,3 @@ isCommaAnn :: TrailingAnn -> Bool isCommaAnn AddCommaAnn{} = True isCommaAnn _ = False #endif - -#endif diff --git a/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal b/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal index 60075281d7..de59727d53 100644 --- a/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal +++ b/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal @@ -38,45 +38,68 @@ library buildable: False else buildable: True - - if impl(ghc >= 9.2.1) + if impl(ghc >= 9.2) hs-source-dirs: new/src + exposed-modules: + Ide.Plugin.Tactic + Refinery.Future + Wingman.AbstractLSP + Wingman.AbstractLSP.TacticActions + Wingman.AbstractLSP.Types + Wingman.CaseSplit + Wingman.CodeGen + Wingman.CodeGen.Utils + Wingman.Debug + Wingman.EmptyCase + Wingman.GHC + Wingman.Judgements + Wingman.Judgements.SYB + Wingman.LanguageServer + Wingman.LanguageServer.TacticProviders + Wingman.Machinery + Wingman.Naming + Wingman.Plugin + Wingman.Range + Wingman.Simplify + Wingman.StaticPlugin + Wingman.Tactics + Wingman.Types else hs-source-dirs: old/src - exposed-modules: - Ide.Plugin.Tactic - Refinery.Future - Wingman.AbstractLSP - Wingman.AbstractLSP.TacticActions - Wingman.AbstractLSP.Types - Wingman.Auto - Wingman.CaseSplit - Wingman.CodeGen - Wingman.CodeGen.Utils - Wingman.Context - Wingman.Debug - Wingman.EmptyCase - Wingman.GHC - Wingman.Judgements - Wingman.Judgements.SYB - Wingman.Judgements.Theta - Wingman.KnownStrategies - Wingman.KnownStrategies.QuickCheck - Wingman.LanguageServer - Wingman.LanguageServer.Metaprogram - Wingman.LanguageServer.TacticProviders - Wingman.Machinery - Wingman.Metaprogramming.Lexer - Wingman.Metaprogramming.Parser - Wingman.Metaprogramming.Parser.Documentation - Wingman.Metaprogramming.ProofState - Wingman.Naming - Wingman.Plugin - Wingman.Range - Wingman.Simplify - Wingman.StaticPlugin - Wingman.Tactics - Wingman.Types + exposed-modules: + Ide.Plugin.Tactic + Refinery.Future + Wingman.AbstractLSP + Wingman.AbstractLSP.TacticActions + Wingman.AbstractLSP.Types + Wingman.Auto + Wingman.CaseSplit + Wingman.CodeGen + Wingman.CodeGen.Utils + Wingman.Context + Wingman.Debug + Wingman.EmptyCase + Wingman.GHC + Wingman.Judgements + Wingman.Judgements.SYB + Wingman.Judgements.Theta + Wingman.KnownStrategies + Wingman.KnownStrategies.QuickCheck + Wingman.LanguageServer + Wingman.LanguageServer.Metaprogram + Wingman.LanguageServer.TacticProviders + Wingman.Machinery + Wingman.Metaprogramming.Lexer + Wingman.Metaprogramming.Parser + Wingman.Metaprogramming.Parser.Documentation + Wingman.Metaprogramming.ProofState + Wingman.Naming + Wingman.Plugin + Wingman.Range + Wingman.Simplify + Wingman.StaticPlugin + Wingman.Tactics + Wingman.Types ghc-options: -Wall -Wno-name-shadowing -Wredundant-constraints @@ -150,22 +173,39 @@ test-suite tests buildable: True type: exitcode-stdio-1.0 main-is: Main.hs - other-modules: - AutoTupleSpec - CodeAction.AutoSpec - CodeAction.DestructAllSpec - CodeAction.DestructPunSpec - CodeAction.DestructSpec - CodeAction.IntrosSpec - CodeAction.IntroDestructSpec - CodeAction.RefineSpec - CodeAction.RunMetaprogramSpec - CodeAction.UseDataConSpec - CodeLens.EmptyCaseSpec - ProviderSpec - Spec - UnificationSpec - Utils + if impl(ghc >= 9.2) + hs-source-dirs: new/test + other-modules: + CodeAction.DestructAllSpec + CodeAction.DestructPunSpec + CodeAction.DestructSpec + CodeAction.IntrosSpec + CodeAction.IntroDestructSpec + CodeAction.RefineSpec + CodeAction.UseDataConSpec + CodeLens.EmptyCaseSpec + ProviderSpec + Spec + UnificationSpec + Utils + else + hs-source-dirs: old/test + other-modules: + AutoTupleSpec + CodeAction.AutoSpec + CodeAction.DestructAllSpec + CodeAction.DestructPunSpec + CodeAction.DestructSpec + CodeAction.IntrosSpec + CodeAction.IntroDestructSpec + CodeAction.RefineSpec + CodeAction.RunMetaprogramSpec + CodeAction.UseDataConSpec + CodeLens.EmptyCaseSpec + ProviderSpec + Spec + UnificationSpec + Utils if impl(ghc >= 9.2.1) hs-source-dirs: new/test diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs index 5bf5e6cb90..5ed6cec46a 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP.hs @@ -175,7 +175,7 @@ codeActionProvider ) -> PluginMethodHandler IdeState TextDocumentCodeAction codeActionProvider sort k state plId - (CodeActionParams _ _ (TextDocumentIdentifier uri) range _) = do + params@(CodeActionParams _ _ (TextDocumentIdentifier uri) range _) = do fromMaybeT (Right $ List []) $ do let fc = FileContext { fc_uri = uri diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs index 52843af427..965155e1a1 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/AbstractLSP/TacticActions.hs @@ -4,13 +4,27 @@ module Wingman.AbstractLSP.TacticActions where -import Control.Monad (when) -import Control.Monad.IO.Class (liftIO) -import Control.Monad.Trans (lift) -import Control.Monad.Trans.Maybe (mapMaybeT) -import Data.Maybe (listToMaybe) -import Data.Proxy -import Development.IDE hiding (rangeToRealSrcSpan) +import Control.Monad (when) +import Control.Monad.IO.Class (liftIO) +import Control.Monad.Trans (lift) +import Control.Monad.Trans.Maybe (mapMaybeT) +import Data.Foldable +import Data.Maybe (listToMaybe) +import Data.Proxy +import Development.IDE hiding (rangeToRealSrcSpan) +import Development.IDE.Core.UseStale +import Development.IDE.GHC.Compat +import Development.IDE.GHC.ExactPrint +import Generics.SYB.GHC (mkBindListT, everywhereM') +import Wingman.AbstractLSP.Types +import Wingman.CaseSplit +import Wingman.GHC (liftMaybe, isHole, pattern AMatch) +import Wingman.Judgements (jNeedsToBindArgs) +import Wingman.LanguageServer (runStaleIde) +import Wingman.LanguageServer.TacticProviders +import Wingman.Machinery (runTactic, scoreSolution) +import Wingman.Range +import Wingman.Types import Development.IDE.Core.Service (getIdeOptionsIO) import Development.IDE.Core.UseStale import Development.IDE.GHC.Compat @@ -26,6 +40,11 @@ import Wingman.LanguageServer.TacticProviders import Wingman.Machinery (runTactic) import Wingman.Range import Wingman.Types +import GHC (SrcSpanAnn'(SrcSpanAnn)) +import Language.Haskell.GHC.ExactPrint (makeDeltaAst') +import Language.Haskell.GHC.ExactPrint.ExactPrint (showAst) +import Language.Haskell.GHC.ExactPrint.Parsers (parseExpr) +import GHC.Hs (LocatedL) ------------------------------------------------------------------------------ @@ -71,7 +90,7 @@ makeTacticInteraction cmd = $ ErrorMessages $ pure NothingToDo _ -> do - traceMX "solution" $ rtr_extract rtr + -- traceMX "solution" $ rtr_extract rtr pure $ addTimeoutMessage rtr $ pure @@ -112,12 +131,13 @@ graftHole graftHole span rtr | _jIsTopHole (rtr_jdg rtr) = genericGraftWithSmallestM - (Proxy @(Located [LMatch GhcPs (LHsExpr GhcPs)])) span + (Proxy @(LocatedL [LMatch GhcPs (LHsExpr GhcPs)])) span $ \dflags matches -> everywhereM' $ mkBindListT $ \ix -> graftDecl dflags span ix $ \name pats -> splitToDecl + dflags (case not $ jNeedsToBindArgs (rtr_jdg rtr) of -- If the user has explicitly bound arguments, use the -- fixity they wrote. @@ -153,9 +173,9 @@ graftDecl -> (RdrName -> [Pat GhcPs] -> LHsDecl GhcPs) -> LMatch GhcPs (LHsExpr GhcPs) -> TransformT (Either String) [LMatch GhcPs (LHsExpr GhcPs)] -graftDecl dflags dst ix make_decl (L src (AMatch (FunRhs (L _ name) _ _) pats _)) +graftDecl dflags dst ix make_decl (L (SrcSpanAnn _ src) (AMatch (FunRhs (L _ name) _ _) pats _)) | dst `isSubspanOf` src = do - L _ dec <- annotateDecl dflags $ make_decl name pats + L _ dec <- pure $ make_decl name pats case dec of ValD _ FunBind{ fun_matches = MG { mg_alts = L _ alts@(first_match : _)} } -> do @@ -165,8 +185,8 @@ graftDecl dflags dst ix make_decl (L src (AMatch (FunRhs (L _ name) _ _) pats _) -- insert a preceding newline (done in 'annotateDecl') on all -- matches, except for the first one --- since it gets its newline -- from the line above. - when (ix == 0) $ - setPrecedingLinesT first_match 0 0 + -- when (ix == 0) $ + -- setPrecedingLinesT first_match 0 0 pure alts _ -> lift $ Left "annotateDecl didn't produce a funbind" graftDecl _ _ _ _ x = pure $ pure x diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/CaseSplit.hs b/plugins/hls-tactics-plugin/new/src/Wingman/CaseSplit.hs index 373fc9b23b..da3d991ba2 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/CaseSplit.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/CaseSplit.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE EmptyCase #-} module Wingman.CaseSplit ( mkFirstAgda , iterateSplit @@ -5,15 +6,24 @@ module Wingman.CaseSplit ) where import Data.Bool (bool) -import Data.Data -import Data.Generics +import Data.Data hiding (Prefix, Infix) +import Data.Generics hiding (Prefix, Infix) import Data.Set (Set) import qualified Data.Set as S import Development.IDE.GHC.Compat import GHC.Exts (IsString (fromString)) -import GHC.SourceGen (funBindsWithFixity, match, wildP) +import GHC.SourceGen import Wingman.GHC import Wingman.Types +import GHC.SourceGen.Binds +import GHC.SourceGen.Name +import Development.IDE.GHC.ExactPrint (annotateDecl) +import Language.Haskell.GHC.ExactPrint (runTransformT) +import Data.Either (fromRight) +import Language.Haskell.GHC.ExactPrint.Transform (setEntryDP) +import GHC (DeltaPos(..), SrcSpanAnn'(..), EpAnn (..), emptyComments, Anchor (..), realSrcSpan, AnchorOperation (..)) +import GHC.Types.SrcLoc (generatedSrcSpan) +import Language.Haskell.GHC.ExactPrint.ExactPrint (showAst) @@ -65,7 +75,7 @@ containsVar name = everything (||) $ (_ :: Pat GhcPs) -> False ) `extQ` \case - HsRecField lbl _ True -> eqRdrName name $ unLoc $ rdrNameFieldOcc $ unLoc lbl + HsRecField _ lbl _ True -> eqRdrName name $ unLoc $ rdrNameFieldOcc $ unLoc lbl (_ :: HsRecField' (FieldOcc GhcPs) (PatCompat GhcPs)) -> False @@ -74,30 +84,38 @@ containsVar name = everything (||) $ rewriteVarPat :: Data a => RdrName -> Pat GhcPs -> a -> a rewriteVarPat name rep = everywhere $ mkT (\case - VarPat _ (L _ var) | eqRdrName name var -> rep + VarPat xVarPat (L _ var) | eqRdrName name var -> rep (x :: Pat GhcPs) -> x ) `extT` \case - HsRecField lbl _ True + HsRecField ann lbl _ True | eqRdrName name $ unLoc $ rdrNameFieldOcc $ unLoc lbl - -> HsRecField lbl (toPatCompat rep) False + -> HsRecField ann lbl (toPatCompat rep) False (x :: HsRecField' (FieldOcc GhcPs) (PatCompat GhcPs)) -> x ------------------------------------------------------------------------------ -- | Construct an 'HsDecl' from a set of 'AgdaMatch'es. splitToDecl - :: Maybe LexicalFixity + :: DynFlags -> Maybe LexicalFixity -> OccName -- ^ The name of the function -> [AgdaMatch] -> LHsDecl GhcPs -splitToDecl fixity name ams = do - traceX "fixity" fixity $ - noLoc $ - funBindsWithFixity fixity (fromString . occNameString . occName $ name) $ do - AgdaMatch pats body <- ams - pure $ match pats body - +splitToDecl dflags fixity name ams = do + let res = -- traceX "fixity" fixity $ + -- L (SrcSpanAnn (EpAnn (Anchor (realSrcSpan generatedSrcSpan) (MovedAnchor $ DifferentLine 1 0)) mempty emptyComments) generatedSrcSpan) $ + L (SrcSpanAnn EpAnnNotUsed generatedSrcSpan) $ + funBindsWithFixity fixity (fromString . occNameString . occName $ name) $ do + AgdaMatch pats body <- ams + pure $ match pats body + res' = either error (\(a,b,c) -> a) $ runTransformT $ annotateDecl dflags res + -- There is a bug here such that each match doesn't get a delta to be on the next line, and so we manually set thos + -- deltas... + res'' = case res' of + L l (ValD xValD funBind@FunBind {fun_matches=MG xMg (L lMatches (m:ms)) originMg}) -> + L l (ValD xValD (funBind {fun_matches=MG xMg (L lMatches $ (m:(flip setEntryDP (DifferentLine 1 0) <$> ms))) originMg})) + _ -> error "bad" + in res'' ------------------------------------------------------------------------------ -- | Sometimes 'agdaSplit' exposes another opportunity to do 'agdaSplit'. This diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs b/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs index 98556aa2a1..8945c319fb 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen.hs @@ -31,6 +31,7 @@ import Wingman.Judgements import Wingman.Machinery import Wingman.Naming import Wingman.Types +import GHC (EpAnn(..), emptyComments, AnchorOperation (UnchangedAnchor)) destructMatches @@ -84,14 +85,13 @@ destructionFor hy t = do args = conLikeInstOrigArgTys' con apps names = mkManyGoodNames (hyNamesInScope hy) args pure - . noLoc + . noLocA . Match - noExtField + EpAnnNotUsed CaseAlt [toPatCompat $ snd $ mkDestructPat Nothing con names] - . GRHSs noExtField (pure $ noLoc $ GRHS noExtField [] $ noLoc $ var "_") - . noLoc - $ EmptyLocalBinds noExtField + . GRHSs emptyComments (pure $ noLoc $ GRHS EpAnnNotUsed [] $ noLocA $ var "_") + $ EmptyLocalBinds NoExtField @@ -110,17 +110,19 @@ mkDestructPat already_in_scope con names case S.member label_occ in_scope of -- We have a shadow, so use the generated name instead True -> - (name,) $ noLoc $ + (name,) $ noLocA $ HsRecField - (noLoc $ mkFieldOcc $ noLoc $ Unqual label_occ) - (noLoc $ bvar' name) + EpAnnNotUsed + (noLoc $ mkFieldOcc $ noLocA $ Unqual label_occ) + (noLocA $ bvar' name) False -- No shadow, safe to use a pun False -> - (label_occ,) $ noLoc $ + (label_occ,) $ noLocA $ HsRecField - (noLoc $ mkFieldOcc $ noLoc $ Unqual label_occ) - (noLoc $ bvar' label_occ) + EpAnnNotUsed + (noLoc $ mkFieldOcc $ noLocA $ Unqual label_occ) + (noLocA $ bvar' label_occ) True in (names', ) @@ -140,7 +142,7 @@ infixifyPatIfNecessary :: ConLike -> Pat GhcPs -> Pat GhcPs infixifyPatIfNecessary dcon x | conLikeIsInfix dcon = case x of - ConPatIn op (PrefixCon [lhs, rhs]) -> + ConPatIn op (PrefixCon _ [lhs, rhs]) -> ConPatIn op $ InfixCon lhs rhs y -> y | otherwise = x @@ -201,7 +203,7 @@ destruct' use_field_puns f hi jdg = do (hi_type hi) $ disallowing AlreadyDestructed (S.singleton term) jdg pure $ ext - & #syn_val %~ noLoc . case' (var' term) + & #syn_val %~ noLocA . case' (var' term) ------------------------------------------------------------------------------ @@ -216,7 +218,7 @@ destructLambdaCase' use_field_puns f jdg = do #else Just (arg, _) | isAlgType arg -> #endif - fmap (fmap noLoc lambdaCase) <$> + fmap (fmap noLocA lambdaCase) <$> destructMatches use_field_puns f Nothing (CType arg) jdg _ -> cut -- throwError $ GoalMismatch "destructLambdaCase'" g @@ -259,8 +261,8 @@ buildDataCon jdg dc tyapps = do mkApply :: OccName -> [HsExpr GhcPs] -> LHsExpr GhcPs mkApply occ (lhs : rhs : more) | isSymOcc occ - = noLoc $ foldl' (@@) (op lhs (coerceName occ) rhs) more -mkApply occ args = noLoc $ foldl' (@@) (var' occ) args + = noLocA $ foldl' (@@) (op lhs (coerceName occ) rhs) more +mkApply occ args = noLocA $ foldl' (@@) (var' occ) args ------------------------------------------------------------------------------ @@ -285,7 +287,7 @@ letForEach rename solve (unHypothesis -> hy) jdg = do let hy' = fmap (g <$) $ syn_val terms matches = fmap (fmap (\(occ, expr) -> valBind (occNameToStr occ) expr)) terms g <- fmap (fmap unLoc) $ newSubgoal $ introduce (userHypothesis hy') jdg - pure $ fmap noLoc $ let' <$> matches <*> g + pure $ fmap noLocA $ let' <$> matches <*> g ------------------------------------------------------------------------------ @@ -298,7 +300,7 @@ nonrecLet occjdgs jdg = do occexts <- traverse newSubgoal $ fmap snd occjdgs ext <- newSubgoal $ introduce (userHypothesis $ fmap (second jGoal) occjdgs) jdg - pure $ fmap noLoc $ + pure $ fmap noLocA $ let' <$> traverse (\(occ, ext) -> valBind (occNameToStr occ) <$> fmap unLoc ext) @@ -309,12 +311,12 @@ nonrecLet occjdgs jdg = do ------------------------------------------------------------------------------ -- | Converts a function application into applicative form idiomize :: LHsExpr GhcPs -> LHsExpr GhcPs -idiomize x = noLoc $ case unLoc x of +idiomize x = noLocA $ case unLoc x of HsApp _ (L _ (HsVar _ (L _ x))) gshgp3 -> op (bvar' $ occName x) "<$>" (unLoc gshgp3) HsApp _ gsigp gshgp3 -> op (unLoc $ idiomize gsigp) "<*>" (unLoc gshgp3) - RecordCon _ con flds -> - unLoc $ idiomize $ noLoc $ foldl' (@@) (HsVar noExtField con) $ fmap unLoc flds + RecordCon _ con (HsRecFields flds _) -> + unLoc $ idiomize $ noLocA $ foldl' (@@) (HsVar noExtField con) $ fmap (unLoc . hsRecFieldArg . unLoc) flds y -> y diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen/Utils.hs b/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen/Utils.hs index d683db9ffd..158296bd7d 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen/Utils.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/CodeGen/Utils.hs @@ -15,25 +15,25 @@ mkCon con apps (fmap unLoc -> args) | RealDataCon dcon <- con , dcon == nilDataCon , [ty] <- apps - , ty `eqType` charTy = noLoc $ string "" + , ty `eqType` charTy = noLocA $ string "" | RealDataCon dcon <- con , isTupleDataCon dcon = - noLoc $ tuple args + noLocA $ tuple args | RealDataCon dcon <- con , dataConIsInfix dcon , (lhs : rhs : args') <- args = - noLoc $ foldl' (@@) (op lhs (coerceName con_name) rhs) args' + noLocA $ foldl' (@@) (op lhs (coerceName con_name) rhs) args' | Just fields <- getRecordFields con , length fields >= 2 = -- record notation is unnatural on single field ctors - noLoc $ recordConE (coerceName con_name) $ do + noLocA $ recordConE (coerceName con_name) $ do (arg, (field, _)) <- zip args fields pure (coerceName field, arg) | otherwise = - noLoc $ foldl' (@@) (bvar' $ occName con_name) args + noLocA $ foldl' (@@) (bvar' $ occName con_name) args where con_name = conLikeName con diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Debug.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Debug.hs index e637779824..78cd1e0ef2 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Debug.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Debug.hs @@ -54,12 +54,6 @@ traceFX str f a = trace (mappend ("!!!" <> str <> ": ") $ f a) a traceM :: Applicative f => String -> f () trace :: String -> a -> a traceShowId :: Show a => a -> a -#ifdef DEBUG traceM = Debug.Trace.traceM trace = Debug.Trace.trace traceShowId = Debug.Trace.traceShowId -#else -traceM _ = pure () -trace _ = id -traceShowId = id -#endif diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/EmptyCase.hs b/plugins/hls-tactics-plugin/new/src/Wingman/EmptyCase.hs index a13d7c1a65..3b746b9fc0 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/EmptyCase.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/EmptyCase.hs @@ -3,6 +3,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NoMonoLocalBinds #-} +{-# LANGUAGE BangPatterns #-} module Wingman.EmptyCase where @@ -33,7 +34,16 @@ import Wingman.CodeGen (destructionFor) import Wingman.GHC import Wingman.Judgements import Wingman.LanguageServer -import Wingman.Types +import Wingman.Types hiding (traceShowId) +import GHC (LocatedA, SrcSpanAnnA, SrcSpanAnn' (..), EpAnn (..), emptyComments, deltaPos, EpaLocation(..), + AddEpAnn(..)) +import GHC.Hs (LocatedL) +import Debug.Trace +import GHC.Plugins (generatedSrcSpan) +import Language.Haskell.GHC.ExactPrint +import Control.Arrow +import Control.Lens (view, _1, Identity (runIdentity)) +import Data.Either (fromRight) data EmptyCaseT = EmptyCaseT @@ -71,7 +81,7 @@ emptyCaseInteraction = Interaction $ edits <- liftMaybe $ hush $ mkWorkspaceEdits le_dflags ccs fc_uri (unTrack pm) $ graftMatchGroup (RealSrcSpan (unTrack ss) Nothing) $ - noLoc matches + noLocA matches pure ( range , Metadata @@ -83,7 +93,6 @@ emptyCaseInteraction = Interaction $ ) (\ _ _ _ we -> pure $ pure $ RawEdit we) - scrutinzedType :: EmptyCaseSort Type -> Maybe Type scrutinzedType (EmptyCase ty) = pure ty scrutinzedType (EmptyLamCase ty) = @@ -111,15 +120,15 @@ hush (Right a) = Just a -- 'Match's that bind variables. graftMatchGroup :: SrcSpan - -> Located [LMatch GhcPs (LHsExpr GhcPs)] + -> LocatedL [LMatch GhcPs (LHsExpr GhcPs)] -> Graft (Either String) ParsedSource graftMatchGroup ss l = - hoistGraft (runExcept . runExceptString) $ graftExprWithM ss $ \case + hoistGraft (runExcept . runExceptString) $ graftExprWithM ss $ (\case L span (HsCase ext scrut mg) -> do pure $ Just $ L span $ HsCase ext scrut $ mg { mg_alts = l } - L span (HsLamCase ext mg) -> do - pure $ Just $ L span $ HsLamCase ext $ mg { mg_alts = l } - (_ :: LHsExpr GhcPs) -> pure Nothing + L span (HsLamCase ann mg) -> do + pure $ Just $ L span $ HsLamCase ann $ mg { mg_alts = l } + (_ :: LHsExpr GhcPs) -> pure Nothing) fromMaybeT :: Functor m => a -> MaybeT m a -> m a @@ -150,10 +159,10 @@ emptyCaseScrutinees state nfp = do True -> pure empty False -> case ss of - RealSrcSpan r _ -> do + SrcSpanAnn _ (RealSrcSpan r _) -> do rss' <- liftMaybe $ mapAgeTo tcg_map $ unsafeCopyAge aged r pure $ Just (rss', ty) - UnhelpfulSpan _ -> empty + SrcSpanAnn _ (UnhelpfulSpan _) -> empty data EmptyCaseSort a = EmptyCase a @@ -162,9 +171,9 @@ data EmptyCaseSort a ------------------------------------------------------------------------------ -- | Get the 'SrcSpan' and scrutinee of every empty case. -emptyCaseQ :: GenericQ [(SrcSpan, EmptyCaseSort (HsExpr GhcTc))] +emptyCaseQ :: GenericQ [(SrcSpanAnnA, EmptyCaseSort (HsExpr GhcTc))] emptyCaseQ = everything (<>) $ mkQ mempty $ \case - L new_span (Case scrutinee []) -> pure (new_span, EmptyCase scrutinee) - L new_span expr@(LamCase []) -> pure (new_span, EmptyLamCase expr) + (L new_span (CaseTc scrutinee [])) -> pure (new_span, EmptyCase scrutinee) + L new_span expr@(LamCaseTc []) -> pure (new_span, EmptyLamCase expr) (_ :: LHsExpr GhcTc) -> mempty diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs b/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs index 65378b10d5..72e046f8d9 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/GHC.hs @@ -1,5 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE AllowAmbiguousTypes #-} module Wingman.GHC where @@ -78,7 +79,7 @@ tacticsThetaTy (tcSplitSigmaTy -> (_, theta, _)) = theta -- | Get the data cons of a type, if it has any. tacticsGetDataCons :: Type -> Maybe ([DataCon], [Type]) tacticsGetDataCons ty - | Just (_, ty') <- tcSplitForAllTyVarBinder_maybe ty + | Just (_, ty') <- GHC.Tc.Utils.TcType.tcSplitForAllTyVarBinder_maybe ty = tacticsGetDataCons ty' tacticsGetDataCons ty | Just _ <- algebraicTyCon ty @@ -101,7 +102,7 @@ freshTyvars t = do pure $ everywhere (mkT $ \tv -> M.findWithDefault tv tv reps - ) $ snd $ tcSplitForAllTyVars t + ) $ snd $ GHC.Tc.Utils.TcType.tcSplitForAllTyVars t ------------------------------------------------------------------------------ @@ -120,7 +121,7 @@ getRecordFields dc = -- | Is this an algebraic type? algebraicTyCon :: Type -> Maybe TyCon algebraicTyCon ty - | Just (_, ty') <- tcSplitForAllTyVarBinder_maybe ty + | Just (_, ty') <- GHC.Tc.Utils.TcType.tcSplitForAllTyVarBinder_maybe ty = algebraicTyCon ty' algebraicTyCon (splitTyConApp_maybe -> Just (tycon, _)) | tycon == intTyCon = Nothing @@ -217,43 +218,83 @@ pattern Lambda pats body <- ------------------------------------------------------------------------------ -- | A GRHS that contains no guards. -pattern UnguardedRHSs :: LHsExpr p -> GRHSs p (LHsExpr p) +pattern UnguardedRHSs :: LHsExpr GhcPs -> (GRHSs GhcPs (LHsExpr GhcPs)) pattern UnguardedRHSs body <- GRHSs {grhssGRHSs = [L _ (GRHS _ [] body)]} +------------------------------------------------------------------------------ +-- | A GRHS that caontains no guards. +pattern UnguardedRHSsTc :: LHsExpr GhcTc -> (GRHSs GhcTc (LHsExpr GhcTc)) +pattern UnguardedRHSsTc body <- + GRHSs {grhssGRHSs = [L _ (GRHS _ [] body)]} + + ------------------------------------------------------------------------------ -- | A match with a single pattern. Case matches are always 'SinglePatMatch'es. -pattern SinglePatMatch :: PatCompattable p => Pat p -> LHsExpr p -> Match p (LHsExpr p) +pattern SinglePatMatch :: Pat GhcPs -> LHsExpr GhcPs -> Match GhcPs (LHsExpr GhcPs) pattern SinglePatMatch pat body <- Match { m_pats = [fromPatCompat -> pat] , m_grhss = UnguardedRHSs body } +------------------------------------------------------------------------------ +-- | A match with a single pattern. Case matches are always 'SinglePatMatch'es. +pattern SinglePatMatchTc :: Pat GhcTc -> LHsExpr GhcTc -> Match GhcTc (LHsExpr GhcTc) +pattern SinglePatMatchTc pat body <- + Match { m_pats = [fromPatCompat -> pat] + , m_grhss = UnguardedRHSsTc body + } + + ------------------------------------------------------------------------------ -- | Helper function for defining the 'Case' pattern. -unpackMatches :: PatCompattable p => [Match p (LHsExpr p)] -> Maybe [(Pat p, LHsExpr p)] +unpackMatches :: [Match GhcPs (LHsExpr GhcPs)] -> Maybe [(Pat GhcPs, LHsExpr GhcPs)] unpackMatches [] = Just [] unpackMatches (SinglePatMatch pat body : matches) = ((pat, body):) <$> unpackMatches matches unpackMatches _ = Nothing +------------------------------------------------------------------------------ +-- | Helper function for defining the 'Case' pattern. +unpackMatchesTc :: [Match GhcTc (LHsExpr GhcTc)] -> Maybe [(Pat GhcTc, LHsExpr GhcTc)] +unpackMatchesTc [] = Just [] +unpackMatchesTc (SinglePatMatchTc pat body : matches) = + ((pat, body):) <$> unpackMatchesTc matches +unpackMatchesTc _ = Nothing + + ------------------------------------------------------------------------------ -- | A pattern over the otherwise (extremely) messy AST for lambdas. -pattern Case :: PatCompattable p => HsExpr p -> [(Pat p, LHsExpr p)] -> HsExpr p +pattern Case :: HsExpr GhcPs -> [(Pat GhcPs, LHsExpr GhcPs)] -> HsExpr GhcPs pattern Case scrutinee matches <- HsCase _ (L _ scrutinee) MG {mg_alts = L _ (fmap unLoc -> unpackMatches -> Just matches)} +------------------------------------------------------------------------------ +-- | A pattern over the otherwise (extremely) messy AST for lambdas. +pattern CaseTc :: HsExpr GhcTc -> [(Pat GhcTc, LHsExpr GhcTc)] -> HsExpr GhcTc +pattern CaseTc scrutinee matches <- + HsCase _ (L _ scrutinee) + MG {mg_alts = L _ (fmap unLoc -> unpackMatchesTc -> Just matches)} + ------------------------------------------------------------------------------ -- | Like 'Case', but for lambda cases. -pattern LamCase :: PatCompattable p => [(Pat p, LHsExpr p)] -> HsExpr p +pattern LamCase :: [(Pat GhcPs, LHsExpr GhcPs)] -> HsExpr GhcPs pattern LamCase matches <- HsLamCase _ MG {mg_alts = L _ (fmap unLoc -> unpackMatches -> Just matches)} +------------------------------------------------------------------------------ +-- | Like 'Case', but for lambda cases. +pattern LamCaseTc :: [(Pat GhcTc, LHsExpr GhcTc)] -> HsExpr GhcTc +pattern LamCaseTc matches <- + HsLamCase _ + MG {mg_alts = L _ (fmap unLoc -> unpackMatchesTc -> Just matches)} + + ------------------------------------------------------------------------------ -- | Can ths type be lambda-cased? @@ -277,11 +318,11 @@ class PatCompattable p where instance PatCompattable GhcTc where fromPatCompat = unLoc - toPatCompat = noLoc + toPatCompat = noLocA instance PatCompattable GhcPs where fromPatCompat = unLoc - toPatCompat = noLoc + toPatCompat = noLocA type PatCompat pass = LPat pass @@ -298,7 +339,7 @@ pattern TopLevelRHS name ps body where_binds <- (FunRhs (L _ (occName -> name)) _ _) ps (GRHSs _ - [L _ (GRHS _ [] body)] (L _ where_binds)) + [L _ (GRHS _ [] body)] where_binds) liftMaybe :: Monad m => Maybe a -> MaybeT m a liftMaybe a = MaybeT $ pure a @@ -323,7 +364,7 @@ tryUnifyUnivarsButNotSkolems skolems goal inst = tryUnifyUnivarsButNotSkolemsMany :: Set TyVar -> [(Type, Type)] -> Maybe TCvSubst tryUnifyUnivarsButNotSkolemsMany skolems (unzip -> (goal, inst)) = tcUnifyTys - (bool BindMe Skolem . flip S.member skolems) + (bool (const BindMe) (const Apart) . flip S.member skolems) inst goal diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs index 15e948f374..56566326e5 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Judgements/SYB.hs @@ -10,6 +10,7 @@ import Development.IDE.GHC.Compat import GHC.Exts (Any) import Type.Reflection import Unsafe.Coerce (unsafeCoerce) +import Wingman.Debug ------------------------------------------------------------------------------ @@ -21,13 +22,13 @@ everythingContaining => SrcSpan -> GenericQ r -> GenericQ r -everythingContaining dst f = go - where - go :: GenericQ r - go x = - case genericIsSubspan dst x of - Just False -> mempty - _ -> foldl' (<>) (f x) (gmapQ go x) +everythingContaining dst f = everything (<>) f + -- where + -- go :: GenericQ r + -- go x = + -- -- case genericIsSubspan dst x of + -- -- Just False -> mempty + -- _ -> foldl' (<>) (f x) (gmapQ go x) ------------------------------------------------------------------------------ @@ -55,14 +56,14 @@ mkQ1 :: forall a r f -> (forall b. f b -> r) -- ^ Polymorphic match -> a -> r -mkQ1 proxy r br a = - case l_con == a_con && sameTypeModuloLastApp @a @(f ()) of - -- We have proven that the two values share the same constructor, and - -- that they have the same type if you ignore the final application. - -- Therefore, it is safe to coerce @a@ to @f b@, since @br@ is universal - -- over @b@ and can't inspect it. - True -> br $ unsafeCoerce @_ @(f Any) a - False -> r +mkQ1 proxy r br a = undefined + -- case l_con == a_con && sameTypeModuloLastApp @a @(f ()) of + -- -- We have proven that the two values share the same constructor, and + -- -- that they have the same type if you ignore the final application. + -- -- Therefore, it is safe to coerce @a@ to @f b@, since @br@ is universal + -- -- over @b@ and can't inspect it. + -- True -> br $ unsafeCoerce @_ @(f Any) a + -- False -> r where l_con = toConstr proxy a_con = toConstr a diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs index 3e81e5f02b..0d8e0b5bb1 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs @@ -4,6 +4,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NoMonoLocalBinds #-} +{-# LANGUAGE BangPatterns #-} module Wingman.LanguageServer where @@ -53,6 +54,8 @@ import Wingman.Judgements import Wingman.Judgements.SYB (everythingContaining) import Wingman.Range import Wingman.Types +import GHC (EpAnn(..), SrcSpanAnn' (..), SrcSpan (RealSrcSpan)) +import GHC.IO (unsafePerformIO) newtype Log @@ -237,7 +240,7 @@ mkJudgementAndContext cfg g (TrackedStale binds bmap) rss (TrackedStale tcg tcgm let tcs = fmap tcg_binds tcg top_provs = getRhsPosVals tcg_rss tcs - already_destructed = getAlreadyDestructed (fmap (`RealSrcSpan` Nothing) tcg_rss) tcs + already_destructed = getAlreadyDestructed (fmap (`GHC.RealSrcSpan` Nothing) tcg_rss) tcs local_hy = spliceProvenance top_provs $ hypothesisFromBindings binds_rss binds subst = ts_unifier defaultTacticState @@ -264,7 +267,7 @@ getAlreadyDestructed (unTrack -> span) (unTrack -> binds) = (mkQ mempty $ \case Case (HsVar _ (L _ (occName -> var))) _ -> S.singleton var - (_ :: HsExpr GhcTc) -> mempty + (_ :: HsExpr GhcPs) -> mempty ) binds @@ -273,20 +276,16 @@ getSpanAndTypeAtHole -> Tracked age (HieASTs Type) -> Maybe (Tracked age RealSrcSpan, Type) getSpanAndTypeAtHole r@(unTrack -> range) (unTrack -> hf) = do - join $ listToMaybe $ M.elems $ flip M.mapWithKey (getAsts hf) $ \fs ast -> + join $ listToMaybe $ M.elems $ flip M.mapWithKey (getAsts hf) $ \(HiePath fs) ast -> do case selectSmallestContaining (rangeToRealSrcSpan (FastString.unpackFS fs) range) ast of Nothing -> Nothing Just ast' -> do + -- !_ <- Just $ unsafePerformIO $ putStrLn $ unsafeRender ast' let info = nodeInfo ast' ty <- listToMaybe $ nodeType info - guard $ ("HsUnboundVar","HsExpr") `S.member` nodeAnnotations info + guard $ ("HsUnboundVar", "HsExpr") `S.member` nodeAnnotations info + -- TODO filter that this is actually a hole (new GHC api removed identifier info) -- Ensure we're actually looking at a hole here - occ <- (either (const Nothing) (Just . occName) =<<) - . listToMaybe - . S.toList - . M.keysSet - $ nodeIdentifiers info - guard $ isHole occ pure (unsafeCopyAge r $ nodeSpan ast', ty) @@ -312,10 +311,11 @@ getRhsPosVals getRhsPosVals (unTrack -> rss) (unTrack -> tcs) = everything (<>) (mkQ mempty $ \case TopLevelRHS name ps - (L (RealSrcSpan span _) -- body with no guards and a single defn - (HsVar _ (L _ hole))) + -- (L (RealSrcSpan span _) -- body with no guards and a single defn + -- ) + (L (SrcSpanAnn _ span) (HsVar _ (L _ hole))) _ - | containsSpan rss span -- which contains our span + | containsSpan rss $ unsafeRealSrcSpan span -- which contains our span , isHole $ occName hole -- and the span is a hole -> flip evalState 0 $ buildTopLevelHypothesis name ps _ -> mempty @@ -370,7 +370,7 @@ buildPatHy prov (fromPatCompat -> p0) = ConPatOut {pat_con = (L _ con), pat_arg_tys = args, pat_args = f} -> #endif case f of - PrefixCon l_pgt -> + PrefixCon _ l_pgt -> mkDerivedConHypothesis prov con args $ zip [0..] l_pgt InfixCon pgt pgt5 -> mkDerivedConHypothesis prov con args $ zip [0..] [pgt, pgt5] @@ -392,7 +392,7 @@ mkDerivedRecordHypothesis prov dc args (HsRecFields (fmap unLoc -> fs) _) | Just rec_fields <- getRecordFields dc = do let field_lookup = M.fromList $ zip (fmap (occNameFS . fst) rec_fields) [0..] - mkDerivedConHypothesis prov dc args $ fs <&> \(HsRecField (L _ rec_occ) p _) -> + mkDerivedConHypothesis prov dc args $ fs <&> \(HsRecField _ (L _ rec_occ) p _) -> ( field_lookup M.! (occNameFS $ occName $ unLoc $ rdrNameFieldOcc rec_occ) , p ) @@ -467,11 +467,14 @@ isRhsHoleWithoutWhere isRhsHoleWithoutWhere (unTrack -> rss) (unTrack -> tcs) = everything (||) (mkQ False $ \case TopLevelRHS _ _ - (L (RealSrcSpan span _) _) - (EmptyLocalBinds _) -> containsSpan rss span + -- (L (RealSrcSpan span _) _) + (L (SrcSpanAnn _ span) _) + (EmptyLocalBinds _) -> containsSpan rss $ unsafeRealSrcSpan span _ -> False ) tcs +unsafeRealSrcSpan :: SrcSpan -> RealSrcSpan +unsafeRealSrcSpan (GHC.RealSrcSpan span _) = span ufmSeverity :: UserFacingMessage -> MessageType ufmSeverity NotEnoughGas = MtInfo @@ -513,10 +516,12 @@ wingmanRules recorder plId = do holes = everything (<>) (mkQ mempty $ \case - L span (HsVar _ (L _ name)) + L (SrcSpanAnn _ span) (HsVar _ (L _ name)) | isHole (occName name) -> maybeToList $ srcSpanToRange span #if __GLASGOW_HASKELL__ >= 900 + L (SrcSpanAnn _ span) (HsUnboundVar _ occ) +#elif __GLASGOW_HASKELL__ >= 900 L span (HsUnboundVar _ occ) #else L span (HsUnboundVar _ (TrueExprHole occ)) @@ -557,7 +562,7 @@ mkWorkspaceEdits -> Either UserFacingMessage WorkspaceEdit mkWorkspaceEdits dflags ccs uri pm g = do let response = transform dflags ccs uri g pm - in first (InfrastructureError . T.pack) response + first (InfrastructureError . T.pack) response splitId :: Id -> (OccName, CType) diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs index 5b038abb14..5b23e01fd8 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer/TacticProviders.hs @@ -126,7 +126,6 @@ commandProvider Refine = provide Refine "" - ------------------------------------------------------------------------------ -- | Return an empty list if the given predicate doesn't hold over the length guardLength :: (Int -> Bool) -> [a] -> [a] diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs index fe91e052c6..15bbc2f7aa 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Machinery.hs @@ -244,7 +244,7 @@ try' t = commit t $ pure () ------------------------------------------------------------------------------ -- | Sorry leaves a hole in its extract exact :: HsExpr GhcPs -> TacticsM () -exact = rule . const . pure . pure . noLoc +exact = rule . const . pure . pure . noLocA ------------------------------------------------------------------------------ -- | Lift a function over 'HyInfo's to one that takes an 'OccName' and tries to diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs b/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs index 0aa5834484..af9f4a0525 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/StaticPlugin.hs @@ -5,11 +5,10 @@ module Wingman.StaticPlugin ) where import Development.IDE.GHC.Compat -import GHC.LanguageExtensions.Type (Extension(EmptyCase)) import Ide.Types -staticPlugin :: DynFlagsModifications +staticPlugin :: GhcOptsModifications staticPlugin = mempty { dynFlagsModifyGlobal = \df -> allowEmptyCaseButWithWarning @@ -19,10 +18,16 @@ staticPlugin = mempty { refLevelHoleFits = Just 0 , maxRefHoleFits = Just 0 , maxValidHoleFits = Just 0 -#if __GLASGOW_HASKELL__ >= 808 +#if __GLASGOW_HASKELL__ >= 902 +#elif __GLASGOW_HASKELL__ >= 808 , staticPlugins = staticPlugins df #endif } +#if MIN_VERSION_ghc(9,2,0) + , staticPlugins = [] +#else + , staticPlugins = [] +#endif } diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs index e24fb4da95..c485c7da7e 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Tactics.hs @@ -65,7 +65,7 @@ intros' params = rule $ \jdg -> do ext <- newSubgoal jdg' pure $ ext - & #syn_val %~ noLoc . lambda (fmap bvar' bound_occs) . unLoc + & #syn_val %~ noLocA . lambda (fmap bvar' bound_occs) . unLoc ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs index f4cda19e72..40235dc935 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Types.hs @@ -42,6 +42,7 @@ import Refinery.Tactic.Internal (TacticT(TacticT), RuleT (RuleT)) import System.IO.Unsafe (unsafePerformIO) import Wingman.Debug import Data.IORef +import GHC (LocatedA, SrcSpanAnnA) ------------------------------------------------------------------------------ @@ -135,9 +136,6 @@ instance Show (HsDecl GhcPs) where instance Show (Pat GhcPs) where show = unsafeRender -instance Show (LHsSigType GhcPs) where - show = unsafeRender - instance Show TyCon where show = unsafeRender @@ -302,13 +300,19 @@ globalHoleRef :: IORef Int globalHoleRef = unsafePerformIO $ newIORef 10 {-# NOINLINE globalHoleRef #-} -instance MonadExtract Int (Synthesized (LHsExpr GhcPs)) TacticError TacticState ExtractM where +instance MonadExtract + Int + (Synthesized + (LocatedA (HsExpr GhcPs))) + TacticError + TacticState + ExtractM where hole = do u <- lift $ ExtractM $ lift $ readIORef globalHoleRef <* modifyIORef' globalHoleRef (+ 1) pure ( u - , pure . noLoc $ var $ fromString $ occNameString $ occName $ mkMetaHoleName u + , pure . noLocA $ var $ fromString $ occNameString $ occName $ mkMetaHoleName u ) unsolvableHole _ = hole @@ -326,13 +330,13 @@ instance MonadReader r m => MonadReader r (RuleT jdg ext err s m) where mkMetaHoleName :: Int -> RdrName mkMetaHoleName u = mkRdrUnqual $ mkVarOcc $ "_" <> show (Util.mkUnique 'w' u) -instance MetaSubst Int (Synthesized (LHsExpr GhcPs)) where +instance MetaSubst Int (Synthesized (LocatedA (HsExpr GhcPs))) where -- TODO(sandy): This join is to combine the synthesizeds substMeta u val a = join $ a <&> everywhereM (mkM $ \case (L _ (HsVar _ (L _ name))) | name == mkMetaHoleName u -> val - (t :: LHsExpr GhcPs) -> pure t) + (t :: LocatedA (HsExpr GhcPs)) -> pure t) ------------------------------------------------------------------------------ @@ -408,6 +412,8 @@ instance Applicative Synthesized where Synthesized f <*> Synthesized a = Synthesized $ f a +instance Show (LocatedA (HsExpr GhcPs)) where + show = unsafeRender ------------------------------------------------------------------------------ -- | The results of 'Wingman.Machinery.runTactic' diff --git a/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs b/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs index c0b97fa4c4..9ba65832fe 100644 --- a/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs +++ b/plugins/hls-tactics-plugin/new/test/CodeAction/DestructSpec.hs @@ -18,6 +18,7 @@ spec = do destructTest "a" 6 18 "DestructPun" destructTest "fp" 31 14 "DestructCthulhu" destructTest "t" 6 10 "DestructInt" + destructTest "t" 8 6 "DestructIntNotTopLevel" describe "layout" $ do destructTest "b" 4 3 "LayoutBind" diff --git a/plugins/hls-tactics-plugin/new/test/CodeLens/EmptyCaseSpec.hs b/plugins/hls-tactics-plugin/new/test/CodeLens/EmptyCaseSpec.hs index 9ebf7d5043..fc1f477e0d 100644 --- a/plugins/hls-tactics-plugin/new/test/CodeLens/EmptyCaseSpec.hs +++ b/plugins/hls-tactics-plugin/new/test/CodeLens/EmptyCaseSpec.hs @@ -11,7 +11,7 @@ spec = do let test = mkCodeLensTest noTest = mkNoCodeLensTest - describe "golden" $ do + describe "code_lenses" $ do test "EmptyCaseADT" test "EmptyCaseShadow" test "EmptyCaseParens" diff --git a/plugins/hls-tactics-plugin/new/test/Utils.hs b/plugins/hls-tactics-plugin/new/test/Utils.hs index 15c0386bb8..f42c7e4d72 100644 --- a/plugins/hls-tactics-plugin/new/test/Utils.hs +++ b/plugins/hls-tactics-plugin/new/test/Utils.hs @@ -252,7 +252,7 @@ failing _ _ = pure () tacticPath :: FilePath -tacticPath = "test/golden" +tacticPath = "new/test/golden" executeCommandWithResp :: Command -> Session (ResponseMessage 'WorkspaceExecuteCommand) diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.expected.hs new file mode 100644 index 0000000000..9bcfe6666a --- /dev/null +++ b/plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.expected.hs @@ -0,0 +1,9 @@ +import Data.Int + +data Test = Test Int32 + +test :: Test -> Int32 +test = + let t :: Test = undefined + in case t of (Test in') -> _w0 + diff --git a/plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.hs b/plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.hs new file mode 100644 index 0000000000..61fcecca62 --- /dev/null +++ b/plugins/hls-tactics-plugin/new/test/golden/DestructIntNotTopLevel.hs @@ -0,0 +1,9 @@ +import Data.Int + +data Test = Test Int32 + +test :: Test -> Int32 +test = + let t :: Test = undefined + in _ + diff --git a/plugins/hls-tactics-plugin/new/test/golden/LayoutSplitIn.expected.hs b/plugins/hls-tactics-plugin/new/test/golden/LayoutSplitIn.expected.hs index 8095217673..0133ba2418 100644 --- a/plugins/hls-tactics-plugin/new/test/golden/LayoutSplitIn.expected.hs +++ b/plugins/hls-tactics-plugin/new/test/golden/LayoutSplitIn.expected.hs @@ -1,5 +1,5 @@ test :: a test = let a = (1,"bbb") - in case a of { (n, s) -> _w0 } + in case a of (n, s) -> _w0 diff --git a/plugins/hls-tactics-plugin/COMMANDS.md b/plugins/hls-tactics-plugin/old/COMMANDS.md similarity index 100% rename from plugins/hls-tactics-plugin/COMMANDS.md rename to plugins/hls-tactics-plugin/old/COMMANDS.md