Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • changelog.d/cmm-import-syntax-changes
    1
    +section: cmm
    
    2
    +synopsis: Changes to Cmm hand-written syntax for symbol imports.
    
    3
    +issues: #27162
    
    4
    +mrs: !15135
    
    5
    +
    
    6
    +description: {
    
    7
    +  In hand-written Cmm, there is syntax to declare symbol names from outside of
    
    8
    +  the current .cmm file (e.g. .c or .cmm files).
    
    9
    +
    
    10
    +  The existing syntax is
    
    11
    +
    
    12
    +  > import foo;         -- for a function
    
    13
    +  > import CLOSURE foo; -- for data
    
    14
    +
    
    15
    +  and this implicitly meant that the symbol (`foo`) could be found in an
    
    16
    +  external shared library, not the current one. There was no syntax to specify
    
    17
    +  that the symbol should be found in the current shared library, i.e. in a
    
    18
    +  .cmm file (or .hs file) in the current Haskell package.
    
    19
    +
    
    20
    +  The new syntax assumes local by default and allows specifying external:
    
    21
    +
    
    22
    +  > import foo;               -- for a function in the current lib
    
    23
    +  > import DATA foo;          -- for data in the current lib
    
    24
    +  > import extern foo;        -- for a function in an external lib
    
    25
    +  > import extern DATA foo;   -- for data in an external lib
    
    26
    +  > import "unitid" foo;      -- for a function in the Haskell unit "unitid"
    
    27
    +  > import "unitid" DATA foo; -- for data in the Haskell unit "unitid"
    
    28
    +
    
    29
    +  In practice, the only platform where this can be expected to make a
    
    30
    +  difference is on Windows, and only when compiling each Haskell package as a
    
    31
    +  separate .dll dynamic library.
    
    32
    +}
    
    33
    +
    
    34
    +

  • compiler/GHC/Cmm/Lexer.x
    ... ... @@ -174,6 +174,8 @@ data CmmToken
    174 174
       | CmmT_return
    
    175 175
       | CmmT_returns
    
    176 176
       | CmmT_import
    
    177
    +  | CmmT_extern
    
    178
    +  | CmmT_DATA
    
    177 179
       | CmmT_switch
    
    178 180
       | CmmT_case
    
    179 181
       | CmmT_default
    
    ... ... @@ -273,6 +275,8 @@ reservedWordsFM = listToUFM $
    273 275
             ( "return",             CmmT_return ),
    
    274 276
             ( "returns",            CmmT_returns ),
    
    275 277
             ( "import",             CmmT_import ),
    
    278
    +        ( "extern",             CmmT_extern ),
    
    279
    +        ( "DATA",               CmmT_DATA ),
    
    276 280
             ( "switch",             CmmT_switch ),
    
    277 281
             ( "case",               CmmT_case ),
    
    278 282
             ( "default",            CmmT_default ),
    

  • compiler/GHC/Cmm/Parser.y
    ... ... @@ -372,6 +372,8 @@ import qualified Data.ByteString.Char8 as BS8
    372 372
             'return'        { L _ (CmmT_return) }
    
    373 373
             'returns'       { L _ (CmmT_returns) }
    
    374 374
             'import'        { L _ (CmmT_import) }
    
    375
    +        'extern'        { L _ (CmmT_extern) }
    
    376
    +        'DATA'          { L _ (CmmT_DATA) }
    
    375 377
             'switch'        { L _ (CmmT_switch) }
    
    376 378
             'case'          { L _ (CmmT_case) }
    
    377 379
             'default'       { L _ (CmmT_default) }
    
    ... ... @@ -643,18 +645,42 @@ importNames
    643 645
     importName
    
    644 646
             :: { (FastString,  CLabel) }
    
    645 647
     
    
    646
    -        -- A label imported without an explicit packageId.
    
    647
    -        --      These are taken to come from some foreign, unnamed package.
    
    648
    +        -- A code label imported from within the same shared library.
    
    648 649
             : NAME
    
    649
    -        { ($1, mkForeignLabel $1 ForeignLabelInExternalPackage IsFunction) }
    
    650
    +        { ($1, mkForeignLabel $1 ForeignLabelInThisPackage IsFunction) }
    
    650 651
     
    
    651
    -        -- as previous 'NAME', but 'IsData'
    
    652
    -        | 'CLOSURE' NAME
    
    653
    -        { ($2, mkForeignLabel $2 ForeignLabelInExternalPackage IsData) }
    
    652
    +        -- A data label imported from within the same shared library.
    
    653
    +        | 'DATA' NAME
    
    654
    +        { ($2, mkForeignLabel $2 ForeignLabelInThisPackage IsData) }
    
    654 655
     
    
    655
    -        -- A label imported with an explicit UnitId.
    
    656
    +        -- CLOSURE is a historical alias for DATA in this context.
    
    657
    +        | 'CLOSURE' NAME
    
    658
    +        { ($2, mkForeignLabel $2 ForeignLabelInThisPackage IsData) }
    
    659
    +
    
    660
    +        -- A code label imported from another unamed shared library. These may
    
    661
    +        -- come from a foreign shared library, or from the shared library for
    
    662
    +        -- an unnamed Haskell package. This corresponds on Windows/PE to
    
    663
    +        -- __declspec(dllimport) in C.
    
    664
    +        | 'extern' NAME
    
    665
    +        { ($2, mkForeignLabel $2 ForeignLabelInExternalPackage IsFunction) }
    
    666
    +
    
    667
    +        -- A data label imported from another unamed shared library.
    
    668
    +        -- This corresponds on Windows/PE to __declspec(dllimport) in C (but
    
    669
    +        -- cmm doesn't know about data vs function symbols so we have to say).
    
    670
    +        | 'extern' 'DATA' NAME
    
    671
    +        { ($3, mkForeignLabel $3 ForeignLabelInExternalPackage IsData) }
    
    672
    +
    
    673
    +        -- A code label imported from the shared library for a Haskell package
    
    674
    +        -- with the given UnitId. Such labels behave as local when used within
    
    675
    +        -- the specified unit, or as extern otherwise.
    
    656 676
             | STRING NAME
    
    657
    -        { ($2, mkCmmCodeLabel (UnitId (mkFastString $1)) $2) }
    
    677
    +        { ($2, mkForeignLabel $2 (ForeignLabelInPackage (UnitId (mkFastString $1))) IsFunction) }
    
    678
    +
    
    679
    +        -- A data label imported from the shared library for a Haskell package
    
    680
    +        -- with the given UnitId. Such labels behave as local when used within
    
    681
    +        -- the specified unit, or as extern otherwise.
    
    682
    +        | STRING 'DATA' NAME
    
    683
    +        { ($3, mkForeignLabel $3 (ForeignLabelInPackage (UnitId (mkFastString $1))) IsData) }
    
    658 684
     
    
    659 685
     
    
    660 686
     names   :: { [FastString] }