Opened 4 years ago

Closed 18 months ago

Last modified 18 months ago

#5682 closed bug (fixed)

Properly parse promoted data constructor operators

Reported by: lunaris Owned by:
Priority: normal Milestone: 7.8.1
Component: Compiler (Parser) Version: 7.8.1-rc1
Keywords: PolyKinds, ghc-kinds Cc: jpm@…, eir@…, trevor@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case: parser/should_compile/T5682
Blocked By: Blocking:
Related Tickets: #8486 Differential Revisions:

Description

% ghci -XPolyKinds -XTypeOperators
GHCi, version 7.3.20111204: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :k (:)

<interactive>:1:2: parse error on input `:'
Prelude> :k '(:)

<interactive>:1:3: parse error on input `:'
Prelude> :k (':)

<interactive>:1:3: parse error on input `:'
Prelude> :k (Int ': '[Bool])
(Int ': '[Bool]) :: [*]

Change History (21)

comment:1 Changed 4 years ago by dreixel

  • Cc jpm@… added
  • Summary changed from Cannot parse (:) in a KindSignature with -XPolyKinds to Properly parse kind operators (from promoted type operators)

We need to handle kind operators properly in the parser. This is not restricted to the wired-in promoted types; consider, for instance:

data a :+: b = LEFT a | RIGHT b

Currently, the following all fail to parse:

data Sum0 :: * :+: * -> *
data Sum1 :: * ':+: * -> *
data Sum2 :: '(:+:) * * -> *
data Sum3 :: ':+: * * -> *

I guess that Sum3 should indeed fail to parse, but all the others should work.

comment:2 Changed 4 years ago by igloo

  • difficulty set to Unknown
  • Milestone set to 7.4.1

comment:3 Changed 4 years ago by igloo

  • Milestone changed from 7.4.1 to 7.6.1
  • Priority changed from normal to low

comment:4 Changed 3 years ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

comment:5 follow-up: Changed 3 years ago by goldfire

  • Cc eir@… added

I agree with dreixel's examples in spirit, but generally ' is not applied to kinds.

comment:6 in reply to: ↑ 5 Changed 3 years ago by dreixel

Replying to goldfire:

generally ' is not applied to kinds.

Oh, yes, that's true. I think only Sum0 should parse, in fact.

comment:7 Changed 2 years ago by elliottt

  • Cc trevor@… added

comment:8 Changed 19 months ago by dreixel

  • Component changed from Compiler to Compiler (Parser)
  • Owner dreixel deleted
  • Priority changed from low to normal

I don't think this is low priority; #8486 (inability to derive Typeable for promoted :), in particular, is rather annoying. But I'm removing myself as the owner, as I don't really feel comfortable hacking around in the parser...

comment:9 Changed 19 months ago by goldfire

There seems to be two different (but closely related) issues here: (1) parsing promoted data constructor operators, and (2) parsing promoted type constructor operators.

The motivating example at the top of the report is only about issue (1). And, I believe that Pedro (dreixel)'s recent comment is also only about (1).

Pedro's first comment to this ticket, however, is about issue (2). I think issue (2) is unsolvable, due to the presence of * in the grammar of kinds. See #8706.

But, I do think (1) should be doable. Do I feel comfortable in the parser? By no means. But I've done a little poking about in there and might be able to fix this. Hopefully tomorrow. If someone out there does feel comfortable in the parser, I'm happy to let you do it!

comment:10 Changed 19 months ago by dreixel

  • Summary changed from Properly parse kind operators (from promoted type operators) to Properly parse promoted data constructor operators

Richard, I agree that parsing promoted type operators (thus when parsing kinds) is trickier. Let's make this ticket be only about parsing promoted constructor operators (thus when parsing types), and leave #8706 for kinds.

comment:11 Changed 19 months ago by Richard Eisenberg <eir@…>

In 473f12a3be27a00b035f1fdc7050a0ff31bf12ff/ghc:

Fix #5682. Now, '(:) parses.

comment:12 Changed 19 months ago by goldfire

  • Milestone changed from 7.6.2 to 7.8.1
  • Status changed from new to merge

All set here -- I see no reason not to merge.

comment:13 Changed 19 months ago by goldfire

  • Test Case set to parser/should_compile/T5682

comment:14 Changed 19 months ago by goldfire

  • Version changed from 7.3 to 7.8.1-rc1

comment:15 Changed 19 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from merge to closed

Merged in 7.8.

comment:16 Changed 19 months ago by guest

  • Resolution fixed deleted
  • Status changed from closed to new

Promoted tuple constructors (e.g. '(,,)) still don't parse. This patch to compiler/parser/Parser.y.pp fixes it. With this patch, ' can be used with any qcon so the redundant rules have been removed. Using an un-promotable data constructor will give a meaningful error message such as Data constructor ‛(##)’ comes from an un-promotable type ‛(##)’ instead of a parse error.

'(' varop ')' was changed to var because 'id is more consistent than '(`id`) and btype SIMPLEQUOTE varop type (in type and typedoc) allows backquoted identifiers as operators.

1154,1155c1154
<         | SIMPLEQUOTE qconid                          { LL $ HsTyVar $ unLoc $2 }
<         | SIMPLEQUOTE  '(' ')'                        { LL $ HsTyVar $ getRdrName unitDataCon }
---
>         | SIMPLEQUOTE qcon                            { LL $ HsTyVar $ unLoc $2 }
1158,1159c1157
<         | SIMPLEQUOTE '(' qconop ')'                  { LL $ HsTyVar (unLoc $3) }
<         | SIMPLEQUOTE '(' varop  ')'                  { LL $ HsTyVar (unLoc $3) }
---
>         | SIMPLEQUOTE var                             { LL $ HsTyVar $ unLoc $2 }

comment:17 Changed 19 months ago by simonpj

I have not reviewed in detail, but what you say sounds good.

Would someone like to update the user-manual documentation (if necessary), validate, and commit?

Simon

comment:18 Changed 18 months ago by Austin Seipp <austin@…>

In d3af9807ca8a1db0bc9298ea50895ee9df55edb7/ghc:

Really fix #5682 (parsing of promoted datacons)

Patch submitted by an anonymous friend on the bug tracker.

This also fixes TH_RichKinds2 which had a slight message output wibble
(it uses the qualified name of the promoted datacon)

Signed-off-by: Austin Seipp <[email protected]>

comment:19 Changed 18 months ago by thoughtpolice

  • Status changed from new to merge

Thanks, merged!

comment:20 Changed 18 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from merge to closed

comment:21 Changed 18 months ago by Austin Seipp <austin@…>

In 5a576754d745171422d13cd1dba69dd874714cf1/ghc:

Add a test for d3af980 (#5682)

Signed-off-by: Austin Seipp <[email protected]>
Note: See TracTickets for help on using tickets.