Ticket #7162: Only-allow-special-NeverActive-syntax-for-RULES.patch

File Only-allow-special-NeverActive-syntax-for-RULES.patch, 2.7 KB (added by afarmer, 17 months ago)

Fix parser to only parse the [~] for RULES pragmas (not INLINE etc)

  • compiler/parser/Parser.y.pp

    From 99f9d5fcb1fc058a4b94e27d5b196167780ec44d Mon Sep 17 00:00:00 2001
    From: Andrew Farmer <afarmer@ittc.ku.edu>
    Date: Thu, 6 Dec 2012 15:47:33 -0600
    Subject: [PATCH] Only allow special NeverActive syntax for RULES.
    
    
    diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp
    index 9db8f41..43f084f 100644
    a b rules :: { OrdList (LHsDecl RdrName) } 
    870870        |  {- empty -}                          { nilOL } 
    871871 
    872872rule    :: { LHsDecl RdrName } 
    873         : STRING activation rule_forall infixexp '=' exp 
     873        : STRING rule_activation rule_forall infixexp '=' exp 
    874874             { LL $ RuleD (HsRule (getSTRING $1)  
    875875                                  ($2 `orElse` AlwaysActive)  
    876876                                  $3 $4 placeHolderNames $6 placeHolderNames) } 
    877877 
    878 activation :: { Maybe Activation }  
     878-- Rules can be specified to be NeverActive, unlike inline/specialize pragmas 
     879rule_activation :: { Maybe Activation }  
    879880        : {- empty -}                           { Nothing } 
    880         | explicit_activation                   { Just $1 } 
     881        | rule_explicit_activation              { Just $1 } 
    881882 
    882 explicit_activation :: { Activation }  -- In brackets 
     883rule_explicit_activation :: { Activation }  -- In brackets 
    883884        : '[' INTEGER ']'               { ActiveAfter  (fromInteger (getINTEGER $2)) } 
    884885        | '[' '~' INTEGER ']'           { ActiveBefore (fromInteger (getINTEGER $3)) } 
    885886        | '[' '~' ']'                   { NeverActive } 
    sigdecl :: { Located (OrdList (LHsDecl RdrName)) } 
    13741375        | '{-# SPECIALISE' 'instance' inst_type '#-}' 
    13751376                { LL $ unitOL (LL $ SigD (SpecInstSig $3)) } 
    13761377 
     1378activation :: { Maybe Activation }  
     1379        : {- empty -}                           { Nothing } 
     1380        | explicit_activation                   { Just $1 } 
     1381 
     1382explicit_activation :: { Activation }  -- In brackets 
     1383        : '[' INTEGER ']'               { ActiveAfter  (fromInteger (getINTEGER $2)) } 
     1384        | '[' '~' INTEGER ']'           { ActiveBefore (fromInteger (getINTEGER $3)) } 
     1385 
    13771386----------------------------------------------------------------------------- 
    13781387-- Expressions 
    13791388 
  • docs/users_guide/glasgow_exts.xml

    diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
    index aac9994..a534f72 100644
    a b The "[2]" means that the rule is active in Phase 2 and subsequent phases. The i 
    93899389notation "[~2]" is also accepted, meaning that the rule is active up to, but not including, 
    93909390Phase 2. 
    93919391</para> 
     9392<para> 
     9393Rules support the special phase-control notation "[~]", which means the rule is never active. 
     9394</para> 
    93929395</listitem> 
    93939396 
    93949397