Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Conversation

@thumphries
Copy link

This is an attempt to revive the Annot backend. This backend serialises type checking information into a textual format that looks as follows:

unHtml
Hydrant.Data
23
5
1
unHtml :: Html -> Builder

unAttribute
Hydrant.Data
45
1
1
unAttribute :: Attribute -> (Text, Text)

This file format is then consumed by HsColour to add type annotations to highlighted source code. These type annotations appear when moused over. An example can be seen here.

This work was largely done by Ranjit Jhala in 2013. It was fully merged into HsColour, but stalled on the way into Haddock because of an unwanted syb dependency. Nowadays we have copied large swaths of SYB into Haddock, so integrating this work is easy enough.

While I would rather see this work reimplemented as part of the fancy new hyperlinked backend, I feel the fact that HsColour already supports this format makes completing this backend worthwhile.

-- nor NameSet because these are blank after type checking.
skipGuards :: [TypeRep]
skipGuards = [ typeRep (Proxy :: Proxy NameSet)
, typeRep (Proxy :: Proxy (PostTc Id Kind))]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally sure if this is still necessary - I saw no ill effect from turning these off. The rationale behind them is in Tamar's 2011 blog post linked above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok I guess.

@thumphries
Copy link
Author

thumphries commented Nov 24, 2017

Most of this code is straight out of the 2013 version. I've cleaned up a few bits that bothered me.

It currently descends into deriving clauses, which seems wrong, I'll try to fix it. Leads to typeclass methods appearing underneath the derivation:

screen shot 2017-11-24 at 9 19 29 am

, not (isGeneratedId v)
]

-- | Filter out compiler-generated names like @$trModule@ or @$cmappend@.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a better way to do this, I'd love to know about it! The IdDetails are completely blank for all IDs by the time it gets here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is ugly but I am not sure there are other ways to check if an Id is compiler generated.

getNames src z = [(unsafePpr x, (x, idLoc src x)) | x <- findIds z]

renderId :: Id -> String
renderId = showSDocForUser unsafeGlobalDynFlags neverQualify . pprTyThing showSub . AnId
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using unsafeGlobalDynFlags throughout. Since we run after typechecking this seems safe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please thread DynFlags through. Relying on global state breaks my reasoning.

@alexbiehl
Copy link
Member

Thank you for your effort! This sounds definitely interesting! I will have a look later.

getNames src z = [(unsafePpr x, (x, idLoc src x)) | x <- findIds z]

renderId :: Id -> String
renderId = showSDocForUser unsafeGlobalDynFlags neverQualify . pprTyThing showSub . AnId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please thread DynFlags through. Relying on global state breaks my reasoning.

-- nor NameSet because these are blank after type checking.
skipGuards :: [TypeRep]
skipGuards = [ typeRep (Proxy :: Proxy NameSet)
, typeRep (Proxy :: Proxy (PostTc Id Kind))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok I guess.

, not (isGeneratedId v)
]

-- | Filter out compiler-generated names like @$trModule@ or @$cmappend@.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is ugly but I am not sure there are other ways to check if an Id is compiler generated.

-- source generation flag).
, ifaceTokenizedSrc :: !(Maybe [RichToken])

, ifaceTcSource :: TypecheckedSource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's signal here that ifaceTcSource is evaluated.

@harpocrates
Copy link
Collaborator

harpocrates commented Jan 4, 2018

FWIW, if the generation of the AnnMap moves out of its own module, incorporating this into the hyperlinked backed should be quite easy. In fact, once this gets merged, I don't mind walking through the plumbing of all that myself (I think it would be a convenient feature indeed!).

@thumphries
Copy link
Author

Awesome! Sorry I let this languish, I was busy moving job and country. Will revive the PR this weekend.

@ntc2
Copy link
Contributor

ntc2 commented May 9, 2018

This PR was closed accidentally, see this comment for how to reopen.

@thumphries thumphries changed the base branch from master to ghc-8.4 May 9, 2018 19:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants