Treatment of unknown pragmas

Simon Marlow marlowsd at gmail.com
Wed Oct 17 14:22:57 UTC 2018


On Wed, 17 Oct 2018 at 15:02, Ben Gamari <ben at smart-cactus.org> wrote:

> Simon Marlow <marlowsd at gmail.com> writes:
>
> > Simon - GHC provides some protection against mistyped pragma names, in
> the
> > form of the -Wunrecognised-pragmas warning, but only for {-# ... #-}
> > pragmas. If tools decide to use their own pragma syntax, they don't
> benefit
> > from this. That's one downside, in addition to the others that Neil
> > mentioned.
> >
> > You might say we shouldn't care about mistyped pragma names. If the user
> > accidentally writes {- HLNIT -} and it is silently ignored, that's not
> our
> > problem. OK, but we cared about it enough for the pragmas that GHC
> > understands to add the special warning, and it's reasonable to expect
> that
> > HLint users also care about it.
> >
> If this is the case then in my opinion HLint should be the one that
> checks for mis-spelling.


But there's no way that HLint can know what is a misspelled pragma name.

If we look beyond HLint, there is no way that
> GHC could know generally what tokens are misspelled pragmas and which
> are tool names.
>

Well this is the problem we created by adding -Wunrecognised-pragmas :)
Now GHC has to know what all the correctly-spelled pragma names are, and
the HLint diff is just following this path.

Arguably -Wunrecognised-pragmas is ill-conceived.  I'm surprised we didn't
have this discussion when it was added (or maybe we did?). But since we
have it, it comes with an obligation to have a centralised registry of
pragma names, which is currently in GHC. (it doesn't have to be in the
source code, of course)

I'm trying to view the pragma question from the perspective of setting a
> precedent for other tools. If a dozen Haskell tools were to approach us
> tomorrow and ask for similar treatment to HLint it's clear that
> hardcoding pragma lists in the lexer would be unsustainable.
>
> Is this likely to happen? Of course not. However, it is an indication to
> me that the root cause of this current debate is our lack of a good
> extensible pragmas. It seems to me that introducing a tool pragma
> convention, from which tool users can claim namespaces at will, is the
> right way to fix this.
>

And sacrifice checking for misspelled pragma names in those namespaces?
Sure we can say {-# TOOL FOO .. #-} is ignored by GHC, but then nothing wil
notice if you say {-# TOOL HLNIT ... #-} by mistake.  If we decide to do
that then fine, it just seems like an inconsistent design.

Cheers
Simon


>
> Cheers,
>
> - Ben
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20181017/c6f114dd/attachment.html>


More information about the ghc-devs mailing list