Skip to content

Keep Role Annotations in the renamed syntax tree

Currently role annotations are present in the parsed representation, but missing from the renamed version of the syntax tree. GHC should keep them instead. I found no evidence that this would be intended, we even have rnRoleAnnots that should return the renamed annotations.

Keeping role annotations would help tooling to be consistent. For example, renaming the datatype should also rename its occurrence in the role annotation.

Minimal example:

A.hs

module A where
import B
data A x = A B

B.hs

module B where
import {-# SOURCE #-} A
data B = B (A ())

A.hs-boot

{-# LANGUAGE RoleAnnotations #-}
module A where
type role A phantom -- the role annotation is needed here
data A x

When inspecting the representation using the GHC API, the role is present in the parsed representation:

module A where  -- Parsed module
type role A phantom
data A x

But missing from the renamed one:

(data A x, [import (implicit) Prelude], Nothing, Nothing) -- RenamedSource
Trac metadata
Trac field Value
Version 8.2.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information