[Git][ghc/ghc][wip/backport/issue-23821] If a defaulting plugin made progress, re-zonk wanteds before built-in defaulting
Gergő Érdi (@cactus)
gitlab at gitlab.haskell.org
Wed Aug 16 01:55:38 UTC 2023
Gergő Érdi pushed to branch wip/backport/issue-23821 at Glasgow Haskell Compiler / GHC
Commits:
5a9418d2 by Gergő Érdi at 2023-08-16T02:55:29+01:00
If a defaulting plugin made progress, re-zonk wanteds before built-in defaulting
Fixes #23821.
(cherry picked from commit f369f3c838c610e9464e3f7302f8db16ad814306)
- - - - -
6 changed files:
- compiler/GHC/Tc/Solver.hs
- testsuite/tests/plugins/Makefile
- + testsuite/tests/plugins/T23821.hs
- testsuite/tests/plugins/all.T
- + testsuite/tests/plugins/defaulting-plugin/DefaultInterference.hs
- testsuite/tests/plugins/defaulting-plugin/defaulting-plugin.cabal
Changes:
=====================================
compiler/GHC/Tc/Solver.hs
=====================================
@@ -3599,6 +3599,12 @@ applyDefaultingRules wanteds
; return defaultedGroups
}
+ -- If a defaulting plugin solves a tyvar, some of the wanteds
+ -- will have filled-in metavars by now (see #23281). So we
+ -- re-zonk to make sure the built-in defaulting rules don't try
+ -- to solve the same metavars.
+ ; wanteds <- if or plugin_defaulted then TcS.zonkWC wanteds else pure wanteds
+
; let groups = findDefaultableGroups info wanteds
; traceTcS "applyDefaultingRules {" $
=====================================
testsuite/tests/plugins/Makefile
=====================================
@@ -172,6 +172,10 @@ test-defaulting-plugin:
test-defaulting-plugin-fail:
-"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 test-defaulting-plugin-fail.hs -package-db defaulting-plugin/pkg.test-defaulting-plugin-fail/local.package.conf
+.PHONY: T23821
+T23821:
+ -"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) --make -v0 T23821.hs -package-db defaulting-plugin/pkg.test-defaulting-plugin/local.package.conf
+
.PHONY: plugins-order
plugins-order:
"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) --make -v0 plugins-order.hs -package-db plugin-recomp/pkg.plugins01/local.package.conf -fplugin ImpurePlugin -fplugin PurePlugin -fplugin-opt ImpurePlugin:First_Option -fplugin-opt PurePlugin:Second_Option -fplugin-opt PurePlugin:Second_Option_2 -fplugin FingerprintPlugin -fplugin-opt FingerprintPlugin:1
=====================================
testsuite/tests/plugins/T23821.hs
=====================================
@@ -0,0 +1,12 @@
+{-# OPTIONS_GHC -fplugin DefaultInterference #-}
+{-# LANGUAGE ExtendedDefaultRules #-}
+module Main where
+
+class IsColor a where
+ op :: a -> ()
+
+instance IsColor (Int, Int, Int) where
+ op _ = ()
+
+main :: IO ()
+main = pure $ op (1, 2, 3)
=====================================
testsuite/tests/plugins/all.T
=====================================
@@ -263,6 +263,11 @@ test('test-defaulting-plugin-fail',
pre_cmd('$MAKE -s --no-print-directory -C defaulting-plugin package.test-defaulting-plugin-fail TOP={top}')],
makefile_test, [])
+test('T23821',
+ [extra_files(['defaulting-plugin/']),
+ pre_cmd('$MAKE -s --no-print-directory -C defaulting-plugin package.test-defaulting-plugin TOP={top}')],
+ makefile_test, [])
+
test('plugins-order',
[extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']),
pre_cmd('$MAKE -s --no-print-directory -C plugin-recomp package.plugins01 TOP={top}')
=====================================
testsuite/tests/plugins/defaulting-plugin/DefaultInterference.hs
=====================================
@@ -0,0 +1,32 @@
+module DefaultInterference(plugin) where
+
+import GHC.Driver.Plugins
+import GHC.Tc.Plugin
+import GHC.Tc.Types
+import GHC.Tc.Utils.TcType
+import GHC.Tc.Types.Constraint
+import GHC.Core.Predicate
+import GHC.Tc.Solver
+import GHC.Core.Type
+import GHC.Core.Class
+import GHC.Data.Bag
+import GHC.Builtin.Types (intTy)
+
+plugin :: Plugin
+plugin = defaultPlugin
+ { defaultingPlugin = \_ -> Just DefaultingPlugin
+ { dePluginInit = pure ()
+ , dePluginRun = \ _ -> defaultEverythingToInt
+ , dePluginStop = \ _ -> pure ()
+ }
+ }
+
+defaultEverythingToInt :: WantedConstraints -> TcPluginM [DefaultingProposal]
+defaultEverythingToInt wanteds = pure
+ [ DefaultingProposal tv [intTy] [ct]
+ | ct <- bagToList $ approximateWC True wanteds
+ , Just (cls, tys) <- pure $ getClassPredTys_maybe (ctPred ct)
+ , [ty] <- pure $ filterOutInvisibleTypes (classTyCon cls) tys
+ , Just tv <- pure $ getTyVar_maybe ty
+ , isMetaTyVar tv
+ ]
=====================================
testsuite/tests/plugins/defaulting-plugin/defaulting-plugin.cabal
=====================================
@@ -6,5 +6,5 @@ version: 0.1.0.0
library
default-language: Haskell2010
build-depends: base, ghc, containers
- exposed-modules: DefaultLifted
+ exposed-modules: DefaultLifted DefaultInterference
ghc-options: -Wall
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a9418d204bfbdc9b1b68d67f028a51464008f3e
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a9418d204bfbdc9b1b68d67f028a51464008f3e
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230815/5eb4a96c/attachment-0001.html>
More information about the ghc-commits
mailing list