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, IfaceStuff(..) ) 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 CallConv ( cCallConv )
46 import Type ( Kind, mkArrowKind, boxedTypeKind, openTypeKind, usageTypeKind )
47 import IdInfo ( exactArity, InlinePragInfo(..) )
48 import PrimOp ( CCall(..), CCallTarget(..) )
51 import RnMonad ( ParsedIface(..), ExportItem, IfaceDeprecs )
52 import HscTypes ( WhetherHasOrphans, IsBootInterface, GenAvailInfo(..),
53 ImportVersion, WhatsImported(..),
56 import RdrName ( RdrName, mkRdrUnqual, mkIfaceOrig )
57 import Name ( OccName )
58 import OccName ( mkSysOccFS,
59 tcName, varName, ipName, dataName, clsName, tvName,
62 import Module ( ModuleName, PackageName, mkSysModuleNameFS, mkModule )
63 import SrcLoc ( SrcLoc )
64 import CmdLineOpts ( opt_InPackage, opt_IgnoreIfacePragmas )
66 import Class ( DefMeth (..) )
69 import FastString ( tailFS )
74 %monad { P }{ thenP }{ returnP }
75 %lexer { lexer } { ITeof }
79 'case' { ITcase } -- Haskell keywords
82 'default' { ITdefault }
83 'deriving' { ITderiving }
93 'instance' { ITinstance }
96 'newtype' { ITnewtype }
98 'qualified' { ITqualified }
103 'forall' { ITforall } -- GHC extension keywords
104 'foreign' { ITforeign }
105 'export' { ITexport }
107 'dynamic' { ITdynamic }
108 'unsafe' { ITunsafe }
110 'stdcall' { ITstdcallconv }
111 'ccall' { ITccallconv }
113 '__interface' { ITinterface } -- interface keywords
114 '__export' { IT__export }
115 '__depends' { ITdepends }
116 '__forall' { IT__forall }
117 '__letrec' { ITletrec }
118 '__coerce' { ITcoerce }
119 '__inline_me' { ITinlineMe }
120 '__inline_call'{ ITinlineCall }
121 '__DEFAULT' { ITdefaultbranch }
123 '__integer' { ITinteger_lit }
124 '__float' { ITfloat_lit }
125 '__word' { ITword_lit }
126 '__int64' { ITint64_lit }
127 '__word64' { ITword64_lit }
128 '__rational' { ITrational_lit }
129 '__addr' { ITaddr_lit }
130 '__label' { ITlabel_lit }
131 '__litlit' { ITlit_lit }
132 '__string' { ITstring_lit }
133 '__ccall' { ITccall $$ }
135 '__sccC' { ITsccAllCafs }
140 '__P' { ITspecialise }
142 '__U' { ITunfold $$ }
143 '__S' { ITstrict $$ }
146 '__D' { ITdeprecated }
148 '..' { ITdotdot } -- reserved symbols
160 '{' { ITocurly } -- special symbols
162 '{|' { ITocurlybar } -- special symbols
163 '|}' { ITccurlybar } -- special symbols
174 VARID { ITvarid $$ } -- identifiers
176 VARSYM { ITvarsym $$ }
177 CONSYM { ITconsym $$ }
178 QVARID { ITqvarid $$ }
179 QCONID { ITqconid $$ }
180 QVARSYM { ITqvarsym $$ }
181 QCONSYM { ITqconsym $$ }
183 IPVARID { ITipvarid $$ } -- GHC extension
185 PRAGMA { ITpragma $$ }
188 STRING { ITstring $$ }
189 INTEGER { ITinteger $$ }
190 RATIONAL { ITrational $$ }
191 CLITLIT { ITlitlit $$ }
193 UNKNOWN { ITunknown $$ }
196 -- iface_stuff is the main production.
197 -- It recognises (a) a whole interface file
198 -- (b) a type (so that type sigs can be parsed lazily)
199 -- (c) the IdInfo part of a signature (same reason)
201 iface_stuff :: { IfaceStuff }
202 iface_stuff : iface { PIface $1 }
204 | id_info { PIdInfo $1 }
205 | rules_and_deprecs { PRulesAndDeprecs $1 }
207 iface :: { ParsedIface }
208 iface : '__interface' package mod_name
210 orphans checkVersion 'where'
216 rules_and_deprecs_part
218 pi_mod = mkModule $3 $2, -- Module itself
219 pi_vers = $4, -- Module version
221 pi_exports = (fst $5, $9), -- Exports
222 pi_usages = $10, -- Usages
223 pi_fixity = $11, -- Fixies
224 pi_insts = $12, -- Local instances
225 pi_decls = $13, -- Decls
226 pi_rules = (snd $5,fst $14), -- Rules
227 pi_deprecs = snd $14 -- Deprecations
230 -- Versions for exports and rules (optional)
231 sub_versions :: { (Version,Version) }
232 : '[' version version ']' { ($2,$3) }
233 | {- empty -} { (initialVersion, initialVersion) }
235 --------------------------------------------------------------------------
237 import_part :: { [ImportVersion OccName] }
239 | import_decl import_part { $1 : $2 }
241 import_decl :: { ImportVersion OccName }
242 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
243 { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
245 orphans :: { WhetherHasOrphans }
249 is_boot :: { IsBootInterface }
253 whats_imported :: { WhatsImported OccName }
254 whats_imported : { NothingAtAll }
255 | '::' version { Everything $2 }
256 | '::' version version version name_version_pairs { Specifically $2 (Just $3) $5 $4 }
258 name_version_pairs :: { [(OccName, Version)] }
259 name_version_pairs : { [] }
260 | name_version_pair name_version_pairs { $1 : $2 }
262 name_version_pair :: { (OccName, Version) }
263 name_version_pair : var_occ version { ($1, $2) }
264 | tc_occ version { ($1, $2) }
267 --------------------------------------------------------------------------
269 exports_part :: { [ExportItem] }
270 exports_part : { [] }
271 | '__export' mod_name entities ';'
272 exports_part { ({-mkSysModuleNameFS-} $2, $3) : $5 }
274 entities :: { [RdrAvailInfo] }
276 | entity entities { $1 : $2 }
278 entity :: { RdrAvailInfo }
279 entity : var_occ { Avail $1 }
280 | tc_occ { AvailTC $1 [$1] }
281 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
282 | tc_occ stuff_inside { AvailTC $1 ($1:$2) }
283 -- Note that the "main name" comes at the beginning
285 stuff_inside :: { [OccName] }
286 stuff_inside : '{' val_occs '}' { $2 }
288 val_occ :: { OccName }
292 val_occs :: { [OccName] }
294 | val_occ val_occs { $1 : $2 }
297 --------------------------------------------------------------------------
299 fix_decl_part :: { [RdrNameFixitySig] }
300 fix_decl_part : {- empty -} { [] }
301 | fix_decls ';' { $1 }
303 fix_decls :: { [RdrNameFixitySig] }
305 | fix_decl fix_decls { $1 : $2 }
307 fix_decl :: { RdrNameFixitySig }
308 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
310 fixity :: { FixityDirection }
311 fixity : 'infixl' { InfixL }
312 | 'infixr' { InfixR }
316 prec : INTEGER { fromInteger $1 }
318 -----------------------------------------------------------------------------
320 csigs :: { [RdrNameSig] }
322 | 'where' '{' csigs1 '}' { $3 }
324 csigs1 :: { [RdrNameSig] }
326 | csig ';' csigs1 { $1 : $3 }
328 csig :: { RdrNameSig }
329 csig : src_loc qvar_name '::' type { ClassOpSig $2 NoDefMeth $4 $1 }
330 | src_loc qvar_name ';' '::' type { ClassOpSig $2 GenDefMeth $5 $1 }
331 | src_loc qvar_name '=' '::' type { mkClassOpSigDM $2 $5 $1 }
333 --------------------------------------------------------------------------
335 instance_decl_part :: { [RdrNameInstDecl] }
336 instance_decl_part : {- empty -} { [] }
337 | instance_decl_part inst_decl { $2 : $1 }
339 inst_decl :: { RdrNameInstDecl }
340 inst_decl : src_loc 'instance' type '=' qvar_name ';'
342 EmptyMonoBinds {- No bindings -}
343 [] {- No user pragmas -}
344 (Just $5) {- Dfun id -}
348 --------------------------------------------------------------------------
350 decls_part :: { [(Version, RdrNameTyClDecl)] }
353 | opt_version decl ';' decls_part { ($1,$2):$4 }
355 decl :: { RdrNameTyClDecl }
356 decl : src_loc qvar_name '::' type maybe_idinfo
357 { IfaceSig $2 $4 ($5 $2) $1 }
358 | src_loc 'type' qtc_name tv_bndrs '=' type
359 { TySynonym $3 $4 $6 $1 }
360 | src_loc 'data' opt_decl_context qtc_name tv_bndrs constrs
361 { mkTyData DataType $3 $4 $5 $6 (length $6) Nothing $1 }
362 | src_loc 'newtype' opt_decl_context qtc_name tv_bndrs newtype_constr
363 { mkTyData NewType $3 $4 $5 $6 1 Nothing $1 }
364 | src_loc 'class' opt_decl_context qtc_name tv_bndrs fds csigs
365 { mkClassDecl $3 $4 $5 $6 $7 Nothing $1 }
367 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
368 maybe_idinfo : {- empty -} { \_ -> [] }
369 | pragma { \x -> if opt_IgnoreIfacePragmas then []
371 POk _ (PIdInfo id_info) -> id_info
372 PFailed err -> pprPanic "IdInfo parse failed"
376 If a signature decl is being loaded, and opt_IgnoreIfacePragmas is on,
377 we toss away unfolding information.
379 Also, if the signature is loaded from a module we're importing from source,
380 we do the same. This is to avoid situations when compiling a pair of mutually
381 recursive modules, peering at unfolding info in the interface file of the other,
382 e.g., you compile A, it looks at B's interface file and may as a result change
383 its interface file. Hence, B is recompiled, maybe changing its interface file,
384 which will the unfolding info used in A to become invalid. Simple way out is to
385 just ignore unfolding info.
387 [Jan 99: I junked the second test above. If we're importing from an hi-boot
388 file there isn't going to *be* any pragma info. The above comment
389 dates from a time where we picked up a .hi file first if it existed.]
392 pragma :: { ParseResult IfaceStuff }
393 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
399 -----------------------------------------------------------------------------
401 rules_and_deprecs_part :: { ([RdrNameRuleDecl], IfaceDeprecs) }
402 rules_and_deprecs_part : {- empty -} { ([], Nothing) }
403 | pragma { case $1 of
404 POk _ (PRulesAndDeprecs rds) -> rds
405 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
408 rules_and_deprecs :: { ([RdrNameRuleDecl], IfaceDeprecs) }
409 rules_and_deprecs : rule_prag deprec_prag { ($1, $2) }
412 -----------------------------------------------------------------------------
414 rule_prag :: { [RdrNameRuleDecl] }
415 rule_prag : {- empty -} { [] }
418 rules :: { [RdrNameRuleDecl] }
420 | rule ';' rules { $1:$3 }
422 rule :: { RdrNameRuleDecl }
423 rule : src_loc STRING rule_forall qvar_name
424 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $7 $1 }
426 rule_forall :: { [UfBinder RdrName] }
427 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
429 -----------------------------------------------------------------------------
431 deprec_prag :: { IfaceDeprecs }
432 deprec_prag : {- empty -} { Nothing }
433 | '__D' deprecs { Just $2 }
435 deprecs :: { Either DeprecTxt [(RdrName,DeprecTxt)] }
436 deprecs : STRING { Left $1 }
437 | deprec_list { Right $1 }
439 deprec_list :: { [(RdrName,DeprecTxt)] }
440 deprec_list : deprec { [$1] }
441 | deprec ';' deprec_list { $1 : $3 }
443 deprec :: { (RdrName,DeprecTxt) }
444 deprec : deprec_name STRING { ($1, $2) }
446 deprec_name :: { RdrName }
450 -----------------------------------------------------------------------------
452 version :: { Version }
453 version : INTEGER { fromInteger $1 }
455 opt_version :: { Version }
456 opt_version : version { $1 }
457 | {- empty -} { initialVersion }
459 opt_decl_context :: { RdrNameContext }
460 opt_decl_context : { [] }
461 | context '=>' { $1 }
463 ----------------------------------------------------------------------------
465 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
467 | '=' constrs1 { $2 }
469 constrs1 :: { [RdrNameConDecl] }
470 constrs1 : constr { [$1] }
471 | constr '|' constrs1 { $1 : $3 }
473 constr :: { RdrNameConDecl }
474 constr : src_loc ex_stuff qdata_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
475 | src_loc ex_stuff qdata_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
476 -- We use "data_fs" so as to include ()
478 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
479 newtype_constr : src_loc '=' ex_stuff qdata_name atype { [mk_con_decl $4 $3 (VanillaCon [Unbanged $5]) $1] }
480 | src_loc '=' ex_stuff qdata_name '{' qvar_name '::' atype '}'
481 { [mk_con_decl $4 $3 (RecCon [([$6], Unbanged $8)]) $1] }
483 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
484 ex_stuff : { ([],[]) }
485 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
487 batypes :: { [RdrNameBangType] }
489 | batype batypes { $1 : $2 }
491 batype :: { RdrNameBangType }
492 batype : tatype { Unbanged $1 }
493 | '!' tatype { Banged $2 }
494 | '!' '!' tatype { Unpacked $3 }
496 fields1 :: { [([RdrName], RdrNameBangType)] }
497 fields1 : field { [$1] }
498 | field ',' fields1 { $1 : $3 }
500 field :: { ([RdrName], RdrNameBangType) }
501 field : qvar_names1 '::' ttype { ($1, Unbanged $3) }
502 | qvar_names1 '::' '!' ttype { ($1, Banged $4) }
503 | qvar_names1 '::' '!' '!' ttype { ($1, Unpacked $5) }
505 --------------------------------------------------------------------------
507 type :: { RdrNameHsType }
508 type : '__forall' tv_bndrs
509 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
510 | btype '->' type { HsFunTy $1 $3 }
513 opt_context :: { RdrNameContext }
517 context :: { RdrNameContext }
518 context : '(' context_list1 ')' { $2 }
519 | '{' context_list1 '}' { $2 } -- Backward compatibility
521 context_list1 :: { RdrNameContext }
522 context_list1 : class { [$1] }
523 | class ',' context_list1 { $1 : $3 }
525 class :: { HsPred RdrName }
526 class : qcls_name atypes { (HsPClass $1 $2) }
527 | ipvar_name '::' type { (HsPIParam $1 $3) }
529 types0 :: { [RdrNameHsType] {- Zero or more -} }
530 types0 : {- empty -} { [ ] }
534 types2 :: { [RdrNameHsType] {- Two or more -} }
535 types2 : type ',' type { [$1,$3] }
536 | type ',' types2 { $1 : $3 }
538 btype :: { RdrNameHsType }
540 | btype atype { HsAppTy $1 $2 }
541 | '__u' atype atype { HsUsageTy $2 $3 }
543 atype :: { RdrNameHsType }
544 atype : qtc_name { HsTyVar $1 }
545 | tv_name { HsTyVar $1 }
548 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
549 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
550 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
551 | '[' type ']' { HsListTy $2 }
552 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
553 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
554 | '(' type ')' { $2 }
556 atypes :: { [RdrNameHsType] {- Zero or more -} }
558 | atype atypes { $1 : $2 }
559 --------------------------------------------------------------------------
561 -- versions of type/btype/atype that cant begin with '!' (or '.')
562 -- for use where the kind is definitely known NOT to be '$'
564 ttype :: { RdrNameHsType }
565 ttype : '__forall' tv_bndrs
566 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
567 | tbtype '->' type { HsFunTy $1 $3 }
570 tbtype :: { RdrNameHsType }
571 tbtype : tatype { $1 }
572 | tbtype atype { HsAppTy $1 $2 }
573 | '__u' atype atype { HsUsageTy $2 $3 }
575 tatype :: { RdrNameHsType }
576 tatype : qtc_name { HsTyVar $1 }
577 | tv_name { HsTyVar $1 }
578 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
579 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
580 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
581 | '[' type ']' { HsListTy $2 }
582 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
583 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
584 | '(' type ')' { $2 }
585 ---------------------------------------------------------------------
587 package :: { PackageName }
589 | {- empty -} { opt_InPackage } -- Useful for .hi-boot files,
590 -- which can omit the package Id
591 -- Module loops are always within a package
593 mod_name :: { ModuleName }
594 : CONID { mkSysModuleNameFS $1 }
597 ---------------------------------------------------
598 var_fs :: { EncodedFS }
601 | 'as' { SLIT("as") }
602 | 'qualified' { SLIT("qualified") }
603 | 'hiding' { SLIT("hiding") }
604 | 'forall' { SLIT("forall") }
605 | 'foreign' { SLIT("foreign") }
606 | 'export' { SLIT("export") }
607 | 'label' { SLIT("label") }
608 | 'dynamic' { SLIT("dynamic") }
609 | 'unsafe' { SLIT("unsafe") }
610 | 'with' { SLIT("with") }
611 | 'ccall' { SLIT("ccall") }
612 | 'stdcall' { SLIT("stdcall") }
614 qvar_fs :: { (EncodedFS, EncodedFS) }
618 var_occ :: { OccName }
619 : var_fs { mkSysOccFS varName $1 }
621 var_name :: { RdrName }
622 var_name : var_occ { mkRdrUnqual $1 }
624 qvar_name :: { RdrName }
625 qvar_name : var_name { $1 }
626 | qvar_fs { mkIfaceOrig varName $1 }
628 ipvar_name :: { RdrName }
629 : IPVARID { mkRdrUnqual (mkSysOccFS ipName (tailFS $1)) }
631 qvar_names1 :: { [RdrName] }
632 qvar_names1 : qvar_name { [$1] }
633 | qvar_name qvar_names1 { $1 : $2 }
635 var_names :: { [RdrName] }
637 | var_name var_names { $1 : $2 }
639 var_names1 :: { [RdrName] }
640 var_names1 : var_name var_names { $1 : $2 }
642 ---------------------------------------------------
643 -- For some bizarre reason,
644 -- (,,,) is dealt with by the parser
645 -- Foo.(,,,) is dealt with by the lexer
648 data_fs :: { EncodedFS }
652 qdata_fs :: { (EncodedFS, EncodedFS) }
656 data_occ :: { OccName }
657 : data_fs { mkSysOccFS dataName $1 }
659 data_name :: { RdrName }
660 : data_occ { mkRdrUnqual $1 }
662 qdata_name :: { RdrName }
663 qdata_name : data_name { $1 }
664 | qdata_fs { mkIfaceOrig dataName $1 }
666 var_or_data_name :: { RdrName }
670 ---------------------------------------------------
671 tc_occ :: { OccName }
672 : data_fs { mkSysOccFS tcName $1 }
674 tc_name :: { RdrName }
675 : tc_occ { mkRdrUnqual $1 }
677 qtc_name :: { RdrName }
679 | qdata_fs { mkIfaceOrig tcName $1 }
681 ---------------------------------------------------
682 cls_name :: { RdrName }
683 : data_fs { mkRdrUnqual (mkSysOccFS clsName $1) }
685 qcls_name :: { RdrName }
687 | qdata_fs { mkIfaceOrig clsName $1 }
689 ---------------------------------------------------
690 tv_name :: { RdrName }
691 : VARID { mkRdrUnqual (mkSysOccFS tvName $1) }
693 tv_bndr :: { HsTyVarBndr RdrName }
694 : tv_name '::' akind { IfaceTyVar $1 $3 }
695 | tv_name { IfaceTyVar $1 boxedTypeKind }
697 tv_bndrs :: { [HsTyVarBndr RdrName] }
699 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
701 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
703 | tv_bndr tv_bndrs1 { $1 : $2 }
705 ---------------------------------------------------
706 fds :: { [([RdrName], [RdrName])] }
708 | '|' fds1 { reverse $2 }
710 fds1 :: { [([RdrName], [RdrName])] }
711 : fds1 ',' fd { $3 : $1 }
714 fd :: { ([RdrName], [RdrName]) }
715 : varids0 '->' varids0 { (reverse $1, reverse $3) }
717 varids0 :: { [RdrName] }
719 | varids0 tv_name { $2 : $1 }
721 ---------------------------------------------------
724 | akind '->' kind { mkArrowKind $1 $3 }
727 : VARSYM { if $1 == SLIT("*") then
729 else if $1 == SLIT("?") then
731 else if $1 == SLIT("\36") then
732 usageTypeKind -- dollar
733 else panic "ParseInterface: akind"
735 | '(' kind ')' { $2 }
737 --------------------------------------------------------------------------
739 id_info :: { [HsIdInfo RdrName] }
740 : id_info_item { [$1] }
741 | id_info_item id_info { $1 : $2 }
743 id_info_item :: { HsIdInfo RdrName }
744 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
745 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
746 | '__M' { HsCprInfo }
747 | '__S' { HsStrictness (mkStrictnessInfo $1) }
748 | '__C' { HsNoCafRefs }
749 | '__P' qvar_name { HsWorker $2 }
751 inline_prag :: { InlinePragInfo }
752 : {- empty -} { NoInlinePragInfo }
753 | '[' from_prag phase ']' { IMustNotBeINLINEd $2 $3 }
755 from_prag :: { Bool }
756 : {- empty -} { True }
759 phase :: { Maybe Int }
760 : {- empty -} { Nothing }
761 | INTEGER { Just (fromInteger $1) }
763 -------------------------------------------------------
764 core_expr :: { UfExpr RdrName }
765 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
766 | 'case' core_expr 'of' var_name
767 '{' core_alts '}' { UfCase $2 $4 $6 }
769 | 'let' '{' core_val_bndr '=' core_expr
770 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
771 | '__letrec' '{' rec_binds '}'
772 'in' core_expr { UfLet (UfRec $3) $6 }
774 | '__litlit' STRING atype { UfLitLit $2 $3 }
778 fexpr :: { UfExpr RdrName }
779 fexpr : fexpr core_arg { UfApp $1 $2 }
780 | scc core_aexpr { UfNote (UfSCC $1) $2 }
781 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
782 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
783 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
786 core_arg :: { UfExpr RdrName }
787 : '@' atype { UfType $2 }
790 core_args :: { [UfExpr RdrName] }
792 | core_arg core_args { $1 : $2 }
794 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
795 core_aexpr : qvar_name { UfVar $1 }
796 | qdata_name { UfVar $1 }
798 | core_lit { UfLit $1 }
799 | '(' core_expr ')' { $2 }
801 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
802 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
803 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
805 | '{' '__ccall' ccall_string type '}'
807 (is_dyn, is_casm, may_gc) = $2
809 target | is_dyn = DynamicTarget (error "CCall dyn target bogus unique")
810 | otherwise = StaticTarget $3
812 ccall = CCall target is_casm may_gc cCallConv
818 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
819 comma_exprs0 : {- empty -} { [ ] }
820 | core_expr { [ $1 ] }
821 | comma_exprs2 { $1 }
823 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
824 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
825 | core_expr ',' comma_exprs2 { $1 : $3 }
827 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
829 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
831 core_alts :: { [UfAlt RdrName] }
833 | core_alt ';' core_alts { $1 : $3 }
835 core_alt :: { UfAlt RdrName }
836 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
838 core_pat :: { (UfConAlt RdrName, [RdrName]) }
839 core_pat : core_lit { (UfLitAlt $1, []) }
840 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
841 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
842 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
843 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
844 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
845 | '__DEFAULT' { (UfDefault, []) }
846 | '(' core_pat ')' { $2 }
848 core_pat_names :: { [RdrName] }
849 core_pat_names : { [] }
850 | core_pat_name core_pat_names { $1 : $2 }
852 -- Tyvar names and variable names live in different name spaces
853 -- so they need to be signalled separately. But we don't record
854 -- types or kinds in a pattern; we work that out from the type
855 -- of the case scrutinee
856 core_pat_name :: { RdrName }
857 core_pat_name : var_name { $1 }
860 comma_var_names1 :: { [RdrName] } -- One or more
861 comma_var_names1 : var_name { [$1] }
862 | var_name ',' comma_var_names1 { $1 : $3 }
864 core_lit :: { Literal }
865 core_lit : integer { mkMachInt $1 }
866 | CHAR { MachChar $1 }
867 | STRING { MachStr $1 }
868 | rational { MachDouble $1 }
869 | '__word' integer { mkMachWord $2 }
870 | '__word64' integer { mkMachWord64 $2 }
871 | '__int64' integer { mkMachInt64 $2 }
872 | '__float' rational { MachFloat $2 }
873 | '__addr' integer { MachAddr $2 }
874 | '__label' STRING { MachLabel $2 }
876 integer :: { Integer }
878 | '-' INTEGER { (-$2) }
880 rational :: { Rational }
882 | '-' RATIONAL { (-$2) }
884 core_bndr :: { UfBinder RdrName }
885 core_bndr : core_val_bndr { $1 }
886 | core_tv_bndr { $1 }
888 core_bndrs :: { [UfBinder RdrName] }
890 | core_bndr core_bndrs { $1 : $2 }
892 core_val_bndr :: { UfBinder RdrName }
893 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
895 core_tv_bndr :: { UfBinder RdrName }
896 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
897 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
899 ccall_string :: { FAST_STRING }
905 ------------------------------------------------------------------------
906 scc :: { CostCentre }
907 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
908 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
909 { NormalCC { cc_name = $3, cc_mod = $4,
910 cc_is_dupd = $5, cc_is_caf = $6 } }
912 cc_name :: { EncodedFS }
916 cc_dup :: { IsDupdCC }
917 cc_dup : { OriginalCC }
920 cc_caf :: { IsCafCC }
924 -------------------------------------------------------------------
926 src_loc :: { SrcLoc }
927 src_loc : {% getSrcLocP }
929 -- Check the project version: this makes sure
930 -- that the project version (e.g. 407) in the interface
931 -- file is the same as that for the compiler that's reading it
932 checkVersion :: { () }
933 : {-empty-} {% checkVersion Nothing }
934 | INTEGER {% checkVersion (Just (fromInteger $1)) }
936 -------------------------------------------------------------------
941 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
943 data IfaceStuff = PIface ParsedIface
944 | PIdInfo [HsIdInfo RdrName]
945 | PType RdrNameHsType
946 | PRulesAndDeprecs ([RdrNameRuleDecl], IfaceDeprecs)
948 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc