1 {- Notes about the syntax of interface files
2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 interface "edison" M 4 6 2 ! 406 Module M, version 4, from package 'edison',
6 Fixities version 6, rules version 2
7 Interface syntax version 406
8 ! means M contains orphans
12 import Foo ; To compile M I used nothing from Foo, but it's
13 below me in the hierarchy
15 import Foo ! @ ; Ditto, but the ! means that Foo contains orphans
16 and the @ means that Foo is a boot interface
18 import Foo :: 3 ; To compile M I used everything from Foo, which has
21 import Foo :: 3 2 6 a 1 b 3 c 7 ; To compile M I used Foo. It had
25 and some specific things besides.
31 module ParseIface ( parseIface, parseType, parseRules, parseIdInfo ) where
33 #include "HsVersions.h"
35 import HsSyn -- quite a bit of stuff
36 import RdrHsSyn -- oodles of synonyms
37 import HsTypes ( mkHsForAllTy, mkHsTupCon )
39 import Demand ( mkStrictnessInfo )
40 import Literal ( Literal(..), mkMachInt, mkMachInt64, mkMachWord, mkMachWord64 )
41 import BasicTypes ( Fixity(..), FixityDirection(..),
42 NewOrData(..), Version, initialVersion, Boxity(..)
44 import CostCentre ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
45 import Demand ( StrictnessMark(..) )
46 import CallConv ( cCallConv )
47 import Type ( Kind, mkArrowKind, liftedTypeKind, openTypeKind, usageTypeKind )
48 import IdInfo ( InlinePragInfo(..) )
49 import PrimOp ( CCall(..), CCallTarget(..) )
52 import RnMonad ( ParsedIface(..), ExportItem, IfaceDeprecs )
53 import HscTypes ( WhetherHasOrphans, IsBootInterface, GenAvailInfo(..),
54 ImportVersion, WhatsImported(..),
57 import RdrName ( RdrName, mkRdrUnqual, mkIfaceOrig )
58 import Name ( OccName )
59 import OccName ( mkSysOccFS,
60 tcName, varName, dataName, clsName, tvName,
63 import Module ( ModuleName, PackageName, mkSysModuleNameFS, mkModule )
64 import SrcLoc ( SrcLoc )
65 import CmdLineOpts ( opt_InPackage, opt_IgnoreIfacePragmas )
67 import Class ( DefMeth (..) )
70 import FastString ( tailFS )
73 %name parseIface iface
75 %name parseIdInfo id_info
76 %name parseRules rules_and_deprecs
79 %monad { P }{ thenP }{ returnP }
80 %lexer { lexer } { ITeof }
84 'case' { ITcase } -- Haskell keywords
87 'default' { ITdefault }
88 'deriving' { ITderiving }
98 'instance' { ITinstance }
100 'module' { ITmodule }
101 'newtype' { ITnewtype }
103 'qualified' { ITqualified }
108 'forall' { ITforall } -- GHC extension keywords
109 'foreign' { ITforeign }
110 'export' { ITexport }
112 'dynamic' { ITdynamic }
113 'unsafe' { ITunsafe }
115 'stdcall' { ITstdcallconv }
116 'ccall' { ITccallconv }
118 '__interface' { ITinterface } -- interface keywords
119 '__export' { IT__export }
120 '__depends' { ITdepends }
121 '__forall' { IT__forall }
122 '__letrec' { ITletrec }
123 '__coerce' { ITcoerce }
124 '__inline_me' { ITinlineMe }
125 '__inline_call'{ ITinlineCall }
126 '__DEFAULT' { ITdefaultbranch }
128 '__integer' { ITinteger_lit }
129 '__float' { ITfloat_lit }
130 '__word' { ITword_lit }
131 '__int64' { ITint64_lit }
132 '__word64' { ITword64_lit }
133 '__rational' { ITrational_lit }
134 '__addr' { ITaddr_lit }
135 '__label' { ITlabel_lit }
136 '__litlit' { ITlit_lit }
137 '__string' { ITstring_lit }
138 '__ccall' { ITccall $$ }
140 '__sccC' { ITsccAllCafs }
145 '__P' { ITspecialise }
147 '__U' { ITunfold $$ }
148 '__S' { ITstrict $$ }
151 '__D' { ITdeprecated }
153 '..' { ITdotdot } -- reserved symbols
165 '{' { ITocurly } -- special symbols
167 '{|' { ITocurlybar } -- special symbols
168 '|}' { ITccurlybar } -- special symbols
179 VARID { ITvarid $$ } -- identifiers
181 VARSYM { ITvarsym $$ }
182 CONSYM { ITconsym $$ }
183 QVARID { ITqvarid $$ }
184 QCONID { ITqconid $$ }
185 QVARSYM { ITqvarsym $$ }
186 QCONSYM { ITqconsym $$ }
188 IPVARID { ITipvarid $$ } -- GHC extension
190 PRAGMA { ITpragma $$ }
193 STRING { ITstring $$ }
194 INTEGER { ITinteger $$ }
195 RATIONAL { ITrational $$ }
196 CLITLIT { ITlitlit $$ }
198 UNKNOWN { ITunknown $$ }
201 iface :: { ParsedIface }
202 iface : '__interface' package mod_name
204 orphans checkVersion 'where'
210 rules_and_deprecs_part
212 pi_mod = mkModule $3 $2, -- Module itself
213 pi_vers = $4, -- Module version
215 pi_exports = (fst $5, $9), -- Exports
216 pi_usages = $10, -- Usages
217 pi_fixity = $11, -- Fixies
218 pi_insts = $12, -- Local instances
219 pi_decls = $13, -- Decls
220 pi_rules = (snd $5,fst $14), -- Rules
221 pi_deprecs = snd $14 -- Deprecations
224 -- Versions for exports and rules (optional)
225 sub_versions :: { (Version,Version) }
226 : '[' version version ']' { ($2,$3) }
227 | {- empty -} { (initialVersion, initialVersion) }
229 --------------------------------------------------------------------------
231 import_part :: { [ImportVersion OccName] }
233 | import_decl import_part { $1 : $2 }
235 import_decl :: { ImportVersion OccName }
236 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
237 { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
239 orphans :: { WhetherHasOrphans }
243 is_boot :: { IsBootInterface }
247 whats_imported :: { WhatsImported OccName }
248 whats_imported : { NothingAtAll }
249 | '::' version { Everything $2 }
250 | '::' version version version name_version_pairs { Specifically $2 (Just $3) $5 $4 }
251 | '::' version version name_version_pairs { Specifically $2 Nothing $4 $3 }
253 name_version_pairs :: { [(OccName, Version)] }
254 name_version_pairs : { [] }
255 | name_version_pair name_version_pairs { $1 : $2 }
257 name_version_pair :: { (OccName, Version) }
258 name_version_pair : var_occ version { ($1, $2) }
259 | tc_occ version { ($1, $2) }
262 --------------------------------------------------------------------------
264 exports_part :: { [ExportItem] }
265 exports_part : { [] }
266 | '__export' mod_name entities ';'
267 exports_part { ({-mkSysModuleNameFS-} $2, $3) : $5 }
269 entities :: { [RdrAvailInfo] }
271 | entity entities { $1 : $2 }
273 entity :: { RdrAvailInfo }
274 entity : var_occ { Avail $1 }
275 | tc_occ { AvailTC $1 [$1] }
276 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
277 | tc_occ stuff_inside { AvailTC $1 ($1:$2) }
278 -- Note that the "main name" comes at the beginning
280 stuff_inside :: { [OccName] }
281 stuff_inside : '{' val_occs '}' { $2 }
283 val_occ :: { OccName }
287 val_occs :: { [OccName] }
289 | val_occ val_occs { $1 : $2 }
292 --------------------------------------------------------------------------
294 fix_decl_part :: { [RdrNameFixitySig] }
295 fix_decl_part : {- empty -} { [] }
296 | fix_decls ';' { $1 }
298 fix_decls :: { [RdrNameFixitySig] }
300 | fix_decl fix_decls { $1 : $2 }
302 fix_decl :: { RdrNameFixitySig }
303 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
305 fixity :: { FixityDirection }
306 fixity : 'infixl' { InfixL }
307 | 'infixr' { InfixR }
311 prec : INTEGER { fromInteger $1 }
313 -----------------------------------------------------------------------------
315 csigs :: { [RdrNameSig] }
317 | 'where' '{' csigs1 '}' { $3 }
319 csigs1 :: { [RdrNameSig] }
321 | csig ';' csigs1 { $1 : $3 }
323 csig :: { RdrNameSig }
324 csig : src_loc qvar_name '::' type { ClassOpSig $2 NoDefMeth $4 $1 }
325 | src_loc qvar_name ';' '::' type { ClassOpSig $2 GenDefMeth $5 $1 }
326 | src_loc qvar_name '=' '::' type { mkClassOpSigDM $2 $5 $1 }
328 --------------------------------------------------------------------------
330 instance_decl_part :: { [RdrNameInstDecl] }
331 instance_decl_part : {- empty -} { [] }
332 | instance_decl_part inst_decl { $2 : $1 }
334 inst_decl :: { RdrNameInstDecl }
335 inst_decl : src_loc 'instance' type '=' qvar_name ';'
337 EmptyMonoBinds {- No bindings -}
338 [] {- No user pragmas -}
339 (Just $5) {- Dfun id -}
343 --------------------------------------------------------------------------
345 decls_part :: { [(Version, RdrNameTyClDecl)] }
348 | opt_version decl ';' decls_part { ($1,$2):$4 }
350 decl :: { RdrNameTyClDecl }
351 decl : src_loc qvar_name '::' type maybe_idinfo
352 { IfaceSig $2 $4 ($5 $2) $1 }
353 | src_loc 'type' qtc_name tv_bndrs '=' type
354 { TySynonym $3 $4 $6 $1 }
355 | src_loc 'data' opt_decl_context qtc_name tv_bndrs constrs
356 { mkTyData DataType $3 $4 $5 $6 (length $6) Nothing $1 }
357 | src_loc 'newtype' opt_decl_context qtc_name tv_bndrs newtype_constr
358 { mkTyData NewType $3 $4 $5 $6 1 Nothing $1 }
359 | src_loc 'class' opt_decl_context qtc_name tv_bndrs fds csigs
360 { mkClassDecl $3 $4 $5 $6 $7 Nothing $1 }
362 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
363 maybe_idinfo : {- empty -} { \_ -> [] }
364 | pragma { \x -> if opt_IgnoreIfacePragmas then []
366 POk _ id_info -> id_info
367 PFailed err -> pprPanic "IdInfo parse failed"
371 If a signature decl is being loaded, and opt_IgnoreIfacePragmas is on,
372 we toss away unfolding information.
374 Also, if the signature is loaded from a module we're importing from source,
375 we do the same. This is to avoid situations when compiling a pair of mutually
376 recursive modules, peering at unfolding info in the interface file of the other,
377 e.g., you compile A, it looks at B's interface file and may as a result change
378 its interface file. Hence, B is recompiled, maybe changing its interface file,
379 which will the unfolding info used in A to become invalid. Simple way out is to
380 just ignore unfolding info.
382 [Jan 99: I junked the second test above. If we're importing from an hi-boot
383 file there isn't going to *be* any pragma info. The above comment
384 dates from a time where we picked up a .hi file first if it existed.]
387 pragma :: { ParseResult [HsIdInfo RdrName] }
388 pragma : src_loc PRAGMA { parseIdInfo $2 PState{ bol = 0#, atbol = 1#,
394 -----------------------------------------------------------------------------
396 rules_and_deprecs_part :: { ([RdrNameRuleDecl], IfaceDeprecs) }
397 rules_and_deprecs_part : {- empty -} { ([], Nothing) }
398 | rules_prag { case $1 of
400 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
403 rules_prag :: { ParseResult ([RdrNameRuleDecl], IfaceDeprecs) }
404 rules_prag : src_loc PRAGMA { parseRules $2 PState{ bol = 0#, atbol = 1#,
410 rules_and_deprecs :: { ([RdrNameRuleDecl], IfaceDeprecs) }
411 rules_and_deprecs : rule_prag deprec_prag { ($1, $2) }
414 -----------------------------------------------------------------------------
416 rule_prag :: { [RdrNameRuleDecl] }
417 rule_prag : {- empty -} { [] }
420 rules :: { [RdrNameRuleDecl] }
422 | rule ';' rules { $1:$3 }
424 rule :: { RdrNameRuleDecl }
425 rule : src_loc STRING rule_forall qvar_name
426 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $7 $1 }
428 rule_forall :: { [UfBinder RdrName] }
429 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
431 -----------------------------------------------------------------------------
433 deprec_prag :: { IfaceDeprecs }
434 deprec_prag : {- empty -} { Nothing }
435 | '__D' deprecs { Just $2 }
437 deprecs :: { Either DeprecTxt [(RdrName,DeprecTxt)] }
438 deprecs : STRING { Left $1 }
439 | deprec_list { Right $1 }
441 deprec_list :: { [(RdrName,DeprecTxt)] }
442 deprec_list : deprec { [$1] }
443 | deprec ';' deprec_list { $1 : $3 }
445 deprec :: { (RdrName,DeprecTxt) }
446 deprec : deprec_name STRING { ($1, $2) }
448 deprec_name :: { RdrName }
452 -----------------------------------------------------------------------------
454 version :: { Version }
455 version : INTEGER { fromInteger $1 }
457 opt_version :: { Version }
458 opt_version : version { $1 }
459 | {- empty -} { initialVersion }
461 opt_decl_context :: { RdrNameContext }
462 opt_decl_context : { [] }
463 | context '=>' { $1 }
465 ----------------------------------------------------------------------------
467 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
469 | '=' constrs1 { $2 }
471 constrs1 :: { [RdrNameConDecl] }
472 constrs1 : constr { [$1] }
473 | constr '|' constrs1 { $1 : $3 }
475 constr :: { RdrNameConDecl }
476 constr : src_loc ex_stuff qdata_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
477 | src_loc ex_stuff qdata_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
478 -- We use "data_fs" so as to include ()
480 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
481 newtype_constr : src_loc '=' ex_stuff qdata_name atype { [mk_con_decl $4 $3 (VanillaCon [unbangedType $5]) $1] }
482 | src_loc '=' ex_stuff qdata_name '{' qvar_name '::' atype '}'
483 { [mk_con_decl $4 $3 (RecCon [([$6], unbangedType $8)]) $1] }
485 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
486 ex_stuff : { ([],[]) }
487 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
489 batypes :: { [RdrNameBangType] }
491 | batype batypes { $1 : $2 }
493 batype :: { RdrNameBangType }
494 batype : tatype { unbangedType $1 }
495 | '!' tatype { BangType MarkedStrict $2 }
496 | '!' '!' tatype { BangType MarkedUnboxed $3 }
498 fields1 :: { [([RdrName], RdrNameBangType)] }
499 fields1 : field { [$1] }
500 | field ',' fields1 { $1 : $3 }
502 field :: { ([RdrName], RdrNameBangType) }
503 field : qvar_names1 '::' ttype { ($1, unbangedType $3) }
504 | qvar_names1 '::' '!' ttype { ($1, BangType MarkedStrict $4) }
505 | qvar_names1 '::' '!' '!' ttype { ($1, BangType MarkedUnboxed $5) }
507 --------------------------------------------------------------------------
509 type :: { RdrNameHsType }
510 type : '__forall' tv_bndrs
511 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
512 | btype '->' type { HsFunTy $1 $3 }
515 opt_context :: { RdrNameContext }
519 context :: { RdrNameContext }
520 context : '(' context_list1 ')' { $2 }
521 | '{' context_list1 '}' { $2 } -- Backward compatibility
523 context_list1 :: { RdrNameContext }
524 context_list1 : class { [$1] }
525 | class ',' context_list1 { $1 : $3 }
527 class :: { HsPred RdrName }
528 class : qcls_name atypes { (HsClassP $1 $2) }
529 | ipvar_name '::' type { (HsIParam $1 $3) }
531 types0 :: { [RdrNameHsType] {- Zero or more -} }
532 types0 : {- empty -} { [ ] }
536 types2 :: { [RdrNameHsType] {- Two or more -} }
537 types2 : type ',' type { [$1,$3] }
538 | type ',' types2 { $1 : $3 }
540 btype :: { RdrNameHsType }
542 | btype atype { HsAppTy $1 $2 }
543 | '__u' atype atype { HsUsageTy $2 $3 }
545 atype :: { RdrNameHsType }
546 atype : qtc_name { HsTyVar $1 }
547 | tv_name { HsTyVar $1 }
550 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
551 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
552 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
553 | '[' type ']' { HsListTy $2 }
554 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
555 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
556 | '(' type ')' { $2 }
558 atypes :: { [RdrNameHsType] {- Zero or more -} }
560 | atype atypes { $1 : $2 }
561 --------------------------------------------------------------------------
563 -- versions of type/btype/atype that cant begin with '!' (or '.')
564 -- for use where the kind is definitely known NOT to be '$'
566 ttype :: { RdrNameHsType }
567 ttype : '__forall' tv_bndrs
568 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
569 | tbtype '->' type { HsFunTy $1 $3 }
572 tbtype :: { RdrNameHsType }
573 tbtype : tatype { $1 }
574 | tbtype atype { HsAppTy $1 $2 }
575 | '__u' atype atype { HsUsageTy $2 $3 }
577 tatype :: { RdrNameHsType }
578 tatype : qtc_name { HsTyVar $1 }
579 | tv_name { HsTyVar $1 }
580 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
581 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
582 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
583 | '[' type ']' { HsListTy $2 }
584 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
585 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
586 | '(' type ')' { $2 }
587 ---------------------------------------------------------------------
589 package :: { PackageName }
591 | {- empty -} { opt_InPackage } -- Useful for .hi-boot files,
592 -- which can omit the package Id
593 -- Module loops are always within a package
595 mod_name :: { ModuleName }
596 : CONID { mkSysModuleNameFS $1 }
599 ---------------------------------------------------
600 var_fs :: { EncodedFS }
603 | 'as' { SLIT("as") }
604 | 'qualified' { SLIT("qualified") }
605 | 'hiding' { SLIT("hiding") }
606 | 'forall' { SLIT("forall") }
607 | 'foreign' { SLIT("foreign") }
608 | 'export' { SLIT("export") }
609 | 'label' { SLIT("label") }
610 | 'dynamic' { SLIT("dynamic") }
611 | 'unsafe' { SLIT("unsafe") }
612 | 'with' { SLIT("with") }
613 | 'ccall' { SLIT("ccall") }
614 | 'stdcall' { SLIT("stdcall") }
616 qvar_fs :: { (EncodedFS, EncodedFS) }
620 var_occ :: { OccName }
621 : var_fs { mkSysOccFS varName $1 }
623 var_name :: { RdrName }
624 var_name : var_occ { mkRdrUnqual $1 }
626 qvar_name :: { RdrName }
627 qvar_name : var_name { $1 }
628 | qvar_fs { mkIfaceOrig varName $1 }
630 ipvar_name :: { RdrName }
631 : IPVARID { mkRdrUnqual (mkSysOccFS varName (tailFS $1)) }
633 qvar_names1 :: { [RdrName] }
634 qvar_names1 : qvar_name { [$1] }
635 | qvar_name qvar_names1 { $1 : $2 }
637 var_names :: { [RdrName] }
639 | var_name var_names { $1 : $2 }
641 var_names1 :: { [RdrName] }
642 var_names1 : var_name var_names { $1 : $2 }
644 ---------------------------------------------------
645 -- For some bizarre reason,
646 -- (,,,) is dealt with by the parser
647 -- Foo.(,,,) is dealt with by the lexer
650 data_fs :: { EncodedFS }
654 qdata_fs :: { (EncodedFS, EncodedFS) }
658 data_occ :: { OccName }
659 : data_fs { mkSysOccFS dataName $1 }
661 data_name :: { RdrName }
662 : data_occ { mkRdrUnqual $1 }
664 qdata_name :: { RdrName }
665 qdata_name : data_name { $1 }
666 | qdata_fs { mkIfaceOrig dataName $1 }
668 var_or_data_name :: { RdrName }
672 ---------------------------------------------------
673 tc_occ :: { OccName }
674 : data_fs { mkSysOccFS tcName $1 }
676 tc_name :: { RdrName }
677 : tc_occ { mkRdrUnqual $1 }
679 qtc_name :: { RdrName }
681 | qdata_fs { mkIfaceOrig tcName $1 }
683 ---------------------------------------------------
684 cls_name :: { RdrName }
685 : data_fs { mkRdrUnqual (mkSysOccFS clsName $1) }
687 qcls_name :: { RdrName }
689 | qdata_fs { mkIfaceOrig clsName $1 }
691 ---------------------------------------------------
692 tv_name :: { RdrName }
693 : VARID { mkRdrUnqual (mkSysOccFS tvName $1) }
695 tv_bndr :: { HsTyVarBndr RdrName }
696 : tv_name '::' akind { IfaceTyVar $1 $3 }
697 | tv_name { IfaceTyVar $1 liftedTypeKind }
699 tv_bndrs :: { [HsTyVarBndr RdrName] }
701 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
703 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
705 | tv_bndr tv_bndrs1 { $1 : $2 }
707 ---------------------------------------------------
708 fds :: { [([RdrName], [RdrName])] }
710 | '|' fds1 { reverse $2 }
712 fds1 :: { [([RdrName], [RdrName])] }
713 : fds1 ',' fd { $3 : $1 }
716 fd :: { ([RdrName], [RdrName]) }
717 : varids0 '->' varids0 { (reverse $1, reverse $3) }
719 varids0 :: { [RdrName] }
721 | varids0 tv_name { $2 : $1 }
723 ---------------------------------------------------
726 | akind '->' kind { mkArrowKind $1 $3 }
729 : VARSYM { if $1 == SLIT("*") then
731 else if $1 == SLIT("?") then
733 else if $1 == SLIT("\36") then
734 usageTypeKind -- dollar
735 else panic "ParseInterface: akind"
737 | '(' kind ')' { $2 }
739 --------------------------------------------------------------------------
741 id_info :: { [HsIdInfo RdrName] }
742 : id_info_item { [$1] }
743 | id_info_item id_info { $1 : $2 }
745 id_info_item :: { HsIdInfo RdrName }
746 : '__A' INTEGER { HsArity (fromInteger $2) }
747 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
748 | '__M' { HsCprInfo }
749 | '__S' { HsStrictness (mkStrictnessInfo $1) }
750 | '__C' { HsNoCafRefs }
751 | '__P' qvar_name INTEGER { HsWorker $2 (fromInteger $3) }
753 inline_prag :: { InlinePragInfo }
754 : {- empty -} { NoInlinePragInfo }
755 | '[' from_prag phase ']' { IMustNotBeINLINEd $2 $3 }
757 from_prag :: { Bool }
758 : {- empty -} { True }
761 phase :: { Maybe Int }
762 : {- empty -} { Nothing }
763 | INTEGER { Just (fromInteger $1) }
765 -------------------------------------------------------
766 core_expr :: { UfExpr RdrName }
767 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
768 | 'case' core_expr 'of' var_name
769 '{' core_alts '}' { UfCase $2 $4 $6 }
771 | 'let' '{' core_val_bndr '=' core_expr
772 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
773 | '__letrec' '{' rec_binds '}'
774 'in' core_expr { UfLet (UfRec $3) $6 }
776 | '__litlit' STRING atype { UfLitLit $2 $3 }
780 fexpr :: { UfExpr RdrName }
781 fexpr : fexpr core_arg { UfApp $1 $2 }
782 | scc core_aexpr { UfNote (UfSCC $1) $2 }
783 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
784 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
785 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
788 core_arg :: { UfExpr RdrName }
789 : '@' atype { UfType $2 }
792 core_args :: { [UfExpr RdrName] }
794 | core_arg core_args { $1 : $2 }
796 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
797 core_aexpr : qvar_name { UfVar $1 }
798 | qdata_name { UfVar $1 }
800 | core_lit { UfLit $1 }
801 | '(' core_expr ')' { $2 }
803 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
804 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
805 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
807 | '{' '__ccall' ccall_string type '}'
809 (is_dyn, is_casm, may_gc) = $2
811 target | is_dyn = DynamicTarget (error "CCall dyn target bogus unique")
812 | otherwise = StaticTarget $3
814 ccall = CCall target is_casm may_gc cCallConv
820 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
821 comma_exprs0 : {- empty -} { [ ] }
822 | core_expr { [ $1 ] }
823 | comma_exprs2 { $1 }
825 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
826 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
827 | core_expr ',' comma_exprs2 { $1 : $3 }
829 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
831 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
833 core_alts :: { [UfAlt RdrName] }
835 | core_alt ';' core_alts { $1 : $3 }
837 core_alt :: { UfAlt RdrName }
838 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
840 core_pat :: { (UfConAlt RdrName, [RdrName]) }
841 core_pat : core_lit { (UfLitAlt $1, []) }
842 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
843 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
844 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
845 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
846 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
847 | '__DEFAULT' { (UfDefault, []) }
848 | '(' core_pat ')' { $2 }
850 core_pat_names :: { [RdrName] }
851 core_pat_names : { [] }
852 | core_pat_name core_pat_names { $1 : $2 }
854 -- Tyvar names and variable names live in different name spaces
855 -- so they need to be signalled separately. But we don't record
856 -- types or kinds in a pattern; we work that out from the type
857 -- of the case scrutinee
858 core_pat_name :: { RdrName }
859 core_pat_name : var_name { $1 }
862 comma_var_names1 :: { [RdrName] } -- One or more
863 comma_var_names1 : var_name { [$1] }
864 | var_name ',' comma_var_names1 { $1 : $3 }
866 core_lit :: { Literal }
867 core_lit : integer { mkMachInt $1 }
868 | CHAR { MachChar $1 }
869 | STRING { MachStr $1 }
870 | rational { MachDouble $1 }
871 | '__word' integer { mkMachWord $2 }
872 | '__word64' integer { mkMachWord64 $2 }
873 | '__int64' integer { mkMachInt64 $2 }
874 | '__float' rational { MachFloat $2 }
875 | '__addr' integer { MachAddr $2 }
876 | '__label' STRING { MachLabel $2 }
878 integer :: { Integer }
880 | '-' INTEGER { (-$2) }
882 rational :: { Rational }
884 | '-' RATIONAL { (-$2) }
886 core_bndr :: { UfBinder RdrName }
887 core_bndr : core_val_bndr { $1 }
888 | core_tv_bndr { $1 }
890 core_bndrs :: { [UfBinder RdrName] }
892 | core_bndr core_bndrs { $1 : $2 }
894 core_val_bndr :: { UfBinder RdrName }
895 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
897 core_tv_bndr :: { UfBinder RdrName }
898 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
899 | '@' tv_name { UfTyBinder $2 liftedTypeKind }
901 ccall_string :: { FAST_STRING }
907 ------------------------------------------------------------------------
908 scc :: { CostCentre }
909 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
910 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
911 { NormalCC { cc_name = $3, cc_mod = $4,
912 cc_is_dupd = $5, cc_is_caf = $6 } }
914 cc_name :: { EncodedFS }
918 cc_dup :: { IsDupdCC }
919 cc_dup : { OriginalCC }
922 cc_caf :: { IsCafCC }
926 -------------------------------------------------------------------
928 src_loc :: { SrcLoc }
929 src_loc : {% getSrcLocP }
931 -- Check the project version: this makes sure
932 -- that the project version (e.g. 407) in the interface
933 -- file is the same as that for the compiler that's reading it
934 checkVersion :: { () }
935 : {-empty-} {% checkVersion Nothing }
936 | INTEGER {% checkVersion (Just (fromInteger $1)) }
938 -------------------------------------------------------------------
943 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
945 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc