Commit 66f73ee4 by simonpj@microsoft.com

### Fix a deriving bug, arising from recent refactoring

This one is a hangover from something I did a month or two ago, but
didn't get quite right.  tcSimplifyDefault should not check for no-instances;
instead the checkValidInstance in TcDeriv does so.

Conal's DeepArrow needs this fix.  Test is drv015.

parent 041c35e5
 ... ... @@ -877,6 +877,26 @@ extendLocalInstEnv dfuns thing_inside ; setGblEnv env' thing_inside } \end{code} Note [Deriving context] ~~~~~~~~~~~~~~~~~~~~~~~ With -fglasgow-exts, we allow things like (C Int a) in the simplified context for a derived instance declaration, because at a use of this instance, we might know that a=Bool, and have an instance for (C Int Bool) We nevertheless insist that each predicate meets the termination conditions. If not, the deriving mechanism generates larger and larger constraints. Example: data Succ a = S a data Seq a = Cons a (Seq (Succ a)) | Nil deriving Show Note the lack of a Show instance for Succ. First we'll generate instance (Show (Succ a), Show a) => Show (Seq a) and then instance (Show (Succ (Succ a)), Show (Succ a), Show a) => Show (Seq a) and so on. Instead we want to complain of no instance for (Show (Succ a)). %************************************************************************ %* * \subsection[TcDeriv-normal-binds]{Bindings for the various classes} ... ...
 ... ... @@ -2374,43 +2374,19 @@ tcSimplifyDeriv orig tyvars theta ; wanteds <- newDictBndrsO orig (substTheta tenv theta) ; (irreds, _) <- topCheckLoop doc wanteds -- Insist that the context of a derived instance declaration -- consists of constraints of form (C a b), where a,b are -- type variables -- NB: the caller will further check the tv_dicts for -- legal instance-declaration form ; let (tv_dicts, non_tv_dicts) = partition isTyVarDict irreds ; addNoInstanceErrs non_tv_dicts ; let rev_env = zipTopTvSubst tvs (mkTyVarTys tyvars) simpl_theta = substTheta rev_env (map dictPred tv_dicts) simpl_theta = substTheta rev_env (map dictPred irreds) -- This reverse-mapping is a pain, but the result -- should mention the original TyVars not TcTyVars -- NB: the caller will further check the tv_dicts for -- legal instance-declaration form ; return simpl_theta } where doc = ptext SLIT("deriving classes for a data type") \end{code} Note [Deriving context] ~~~~~~~~~~~~~~~~~~~~~~~ With -fglasgow-exts, we allow things like (C Int a) in the simplified context for a derived instance declaration, because at a use of this instance, we might know that a=Bool, and have an instance for (C Int Bool) We nevertheless insist that each predicate meets the termination conditions. If not, the deriving mechanism generates larger and larger constraints. Example: data Succ a = S a data Seq a = Cons a (Seq (Succ a)) | Nil deriving Show Note the lack of a Show instance for Succ. First we'll generate instance (Show (Succ a), Show a) => Show (Seq a) and then instance (Show (Succ (Succ a)), Show (Succ a), Show a) => Show (Seq a) and so on. Instead we want to complain of no instance for (Show (Succ a)). @tcSimplifyDefault@ just checks class-type constraints, essentially; ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8285747170448303, "perplexity": 15253.150824497181}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-05/segments/1642320306335.77/warc/CC-MAIN-20220128182552-20220128212552-00220.warc.gz"}