Draft: Sized primitive literals
Implementation of Sized primitive literals proposal, adding syntax for defining Int8#
, Word32#
etc. literals.
Closes #21422 (closed) .
Short description of changes:
- add various lexing and parsing bits to support changes described in proposal
- add a handful of tests: poles, range overflows, cases
- add user guide page for new extension
Remaining work:
-
check ghc/haddock submodule change(s) -
do the Cabal flag change (see Note [Adding a language extension]
incompiler/GHC/Driver/Session.hs
) -
small bits -
update :since:
to-do in user guide
-
Other things:
- error messages: disallowed suffix (not
#Int8
etc.)? currently will fail with parse error - add some motivating examples to user guide page: easier parsing, define e.g.
Word8#
directly rather than via coercion
Possible points of discussion:
- Does
ExtendedLiterals
implyMagicHash
? It borrows some syntax, but is otherwise standalone (and is much more localised). It works fine without. But if you're usingExtendedLiterals
, you'll often wantMagicHash
too. - Should we prepare the lexer for extension by parsing arbitrary strings e.g.
#MyCustomType
? That might also help us provide better error messages. - The extension name is generic, but it's currently limited to sized numeric primitives. The docs should probably avoid mentioning the possible further extensions (or mention it offhand out of the way).
This is my first change to GHC. I'm keeping the template text for now below as a reminder and to give me links to further documentation.
Thank you for your contribution to GHC!
Please take a few moments to verify that your commits fulfill the following:
-
are either individually buildable or squashed -
have commit messages which describe what they do (referring to Notes and tickets using #NNNN
syntax when appropriate) -
have added source comments describing your change. For larger changes you likely should add a Note and cross-reference it from the relevant places. -
add a testcase to the testsuite. -
replace this message with a description motivating your change
If you have any questions don't hesitate to open your merge request and inquire
in a comment. If your patch isn't quite done yet please do add prefix your MR
title with WIP:
.