Skip to content
Snippets Groups Projects
Commit 7b84c588 authored by Vladislav Zavialov's avatar Vladislav Zavialov Committed by Marge Bot
Browse files

One list in ConPat (part of #25127)

This patch changes PrefixCon to use one list instead of two:

	-data HsConDetails tyarg arg rec
	-  = PrefixCon [tyarg] [arg]
	+data HsConDetails arg rec
	+  = PrefixCon [arg]
	   | RecCon    rec
	   | InfixCon  arg arg

The [tyarg] list is now gone. To understand the effect of this change,
recall that there are three instantiations of HsConDetails:

1. type HsConPatDetails p =
      HsConDetails (HsConPatTyArg (NoGhcTc p))  -- tyarg
                   (LPat p)                     -- arg
                   (HsRecFields p (LPat p))     -- rec

2. type HsConDeclH98Details pass =
      HsConDetails Void                              -- tyarg
                   (HsScaled pass (LBangType pass))  -- arg
                   (XRec pass [LConDeclField pass])  -- rec

3. type HsPatSynDetails pass =
      HsConDetails Void                     -- tyarg
                   (LIdP pass)              -- arg
                   [RecordPatSynField pass] -- rec

In cases (2) and (3), tyarg was instantiated to Void, so the [tyarg]
list was always empty. Its removal is basically a no-op.

The interesting case is (1), which is used in ConPat to represent
pattern matching of the form (MkE @tp1 @tp2 p1 p2).
With this patch, its representation is changed as follows:

  ConPat "MkE" [tp1, tp2] [p1, p2]               -- old
  ConPat "MkE" [InvisP tp1, InvisP tp2, p1, p2]  -- new

The new mixed-list representation is consintent with lambdas, where
InvisP is already used to deal with \ @tp1 @tp2 p1 p2 -> body.

The immediate effect of the new representation is an improvement to
error messages. Consider the pattern (Con x @t y). Previously it
resulted in a parse error because @t could not occur after x. Now it is
reported as [GHC-14964]. Test case: TyAppPat_MisplacedApplication.

In the long term, this is intended as preparation for #18389 and #25127,
which would make (Con x @t y) potentially valid, e.g. if its type is
  Con :: forall a -> forall b. (a, b) -> T

The TH AST is left unchanged for the moment to avoid breakage.
parent 8c96bcb4
No related branches found
No related tags found
Loading
Showing
with 89 additions and 127 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment