Skip to content

Commit 812d05f

Browse files
committed
Fix difference tests and restricted vis. syntax
* filter out 'mod <name>;' items when getting external sources (they mess with rustc) * support new syntax for restricted paths: 'pub (in <path>)' * fix bugs where OS is unable to allocate threads when there are too many (>250) difference tests * remove 'Annotated' class (the compile time cost of more generics, combined with the complexity and ugliness of the code do not justify the decrease in code size) * silence warnings * add a 'Handle' based interface to 'InputStream' * update difference tests to latest nightly
1 parent 79f3bc4 commit 812d05f

File tree

12 files changed

+36
-107
lines changed

12 files changed

+36
-107
lines changed

get-rust-sources.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ curl https://api.github.com/orgs/rust-lang-nursery/repos > rust-lang-nursery.jso
5252
# Check the file is longer than 2000 lines
5353
if (( 1000 < $(wc -l < "$FILE") ))
5454
then
55-
cp $FILE $DEST_FILE
55+
# copy the file over, but filter out lines which contain a reference to a 'mod <name>;'
56+
# since those cause some issues for the rust compiler (it will go looking for those files
57+
# even during parsing.
58+
grep -Ev "(#\[macro_use\]|mod\s+\w+;)" $FILE > $DEST_FILE
5659
fi
5760

5861
done;

language-rust.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ library
5151
Language.Rust.Pretty.Literals
5252
Language.Rust.Pretty.Util
5353
Language.Rust.Syntax.AST
54-
Language.Rust.Syntax.Annotated
5554
Language.Rust.Syntax.Ident
5655
Language.Rust.Syntax.Token
5756

src/Language/Rust/Data/InputStream.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ module Language.Rust.Data.InputStream (
1515
-- * InputStream type
1616
InputStream, countLines, inputStreamEmpty,
1717
-- * Introduction forms
18-
readInputStream, inputStreamFromString,
18+
readInputStream, hReadInputStream, inputStreamFromString,
1919
-- * Elimination forms
2020
inputStreamToString, takeByte, takeChar, takeChars,
2121
) where
2222

2323
import Data.Word (Word8)
2424
import Data.Coerce (coerce)
2525
import Data.String (IsString(..))
26+
import System.IO
2627

2728
#ifndef NO_BYTESTRING
2829
import qualified Data.ByteString as BS
@@ -36,6 +37,9 @@ import qualified Data.Char as Char
3637
-- | Read a file into an 'InputStream'
3738
readInputStream :: FilePath -> IO InputStream
3839

40+
-- | Read an 'InputStream' from a 'Handle'
41+
hReadInputStream :: Handle -> IO InputStream
42+
3943
-- | Convert 'InputStream' to 'String'
4044
inputStreamToString :: InputStream -> String
4145
{-# INLINE inputStreamToString #-}
@@ -75,6 +79,7 @@ takeChar bs = let Just res = BE.uncons (coerce bs) in coerce res
7579
inputStreamEmpty = BS.null . coerce
7680
takeChars n = BE.toString . BE.take n . coerce
7781
readInputStream f = coerce <$> BS.readFile f
82+
hReadInputStream h = coerce <$> BS.hGetContents h
7883
inputStreamToString = BE.toString . coerce
7984
inputStreamFromString = IS . BE.fromString
8085
countLines = length . BE.lines . coerce
@@ -90,6 +95,7 @@ takeChar (IS ~(c:str)) = (c, IS str)
9095
inputStreamEmpty (IS str) = null str
9196
takeChars n (IS str) = take n str
9297
readInputStream f = IS <$> readFile f
98+
hReadInputStream h = IS <$> hGetContents h
9399
inputStreamToString = coerce
94100
inputStreamFromString = IS
95101
countLines (IS str) = length . lines $ str

src/Language/Rust/Parser/Internal.y

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,9 @@ vis :: { Spanned (Visibility Span) }
14201420
: {- empty -} %prec VIS { Spanned InheritedV mempty }
14211421
| pub %prec VIS { Spanned PublicV (spanOf $1) }
14221422
| pub '(' crate ')' { Spanned CrateV ($1 # $4) }
1423-
| pub '(' mod_path ')' { Spanned (RestrictedV $3) ($1 # $4) }
1423+
| pub '(' in mod_path ')' { Spanned (RestrictedV $4) ($1 # $5) }
1424+
| pub '(' super ')' { Spanned (RestrictedV (Path False [("super", NoParameters mempty)] (spanOf $3))) ($1 # $4) }
1425+
| pub '(' self ')' { Spanned (RestrictedV (Path False [("self", NoParameters mempty)] (spanOf $3))) ($1 # $4) }
14241426
14251427
def :: { Spanned Defaultness }
14261428
: {- empty -} %prec DEF { pure Final }

src/Language/Rust/Pretty/Internal.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ printPolarity Positive = mempty
665665
printVis :: Visibility a -> Doc a
666666
printVis PublicV = "pub"
667667
printVis CrateV = "pub(crate)"
668-
printVis (RestrictedV path) = "pub(" <> printPath path False <> ")"
668+
printVis (RestrictedV path@(Path False (("super", NoParameters _) :| _) _)) = "pub(" <> printPath path False <> ")"
669+
printVis (RestrictedV path@(Path False (("self", NoParameters _) :| _) _)) = "pub(" <> printPath path False <> ")"
670+
printVis (RestrictedV path) = "pub(" <> "in" <+> printPath path False <> ")"
669671
printVis InheritedV = mempty
670672

671673
-- | Print a foreign item (@print_foreign_item@)

src/Language/Rust/Pretty/Literals.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import Data.Word (Word8)
2828
printLit :: Lit a -> Doc a
2929
printLit lit = noIndent $ case lit of
3030
(Str str Cooked s x) -> annotate x (hcat [ "\"", foldMap escapeChar str, "\"", suf s ])
31-
(Str str (Raw n) s x) -> annotate x (hcat [ "r", pad n, "\"", string hardline str, "\"", pad n, suf s ])
31+
(Str str (Raw m) s x) -> annotate x (hcat [ "r", pad m, "\"", string hardline str, "\"", pad m, suf s ])
3232
(ByteStr str Cooked s x) -> annotate x (hcat [ "b\"", foldMap escapeByte str, "\"", suf s ])
33-
(ByteStr str (Raw n) s x) -> annotate x (hcat [ "br", pad n, "\"", string hardline (map byte2Char str), "\"", pad n, suf s ])
33+
(ByteStr str (Raw m) s x) -> annotate x (hcat [ "br", pad m, "\"", string hardline (map byte2Char str), "\"", pad m, suf s ])
3434
(Char c s x) -> annotate x (hcat [ "'", escapeChar c, "'", suf s ])
3535
(Byte b s x) -> annotate x (hcat [ "b'", escapeByte b, "'", suf s ])
3636
(Int b i s x) -> annotate x (hcat [ printIntLit i b, suf s ])
@@ -39,7 +39,7 @@ printLit lit = noIndent $ case lit of
3939
(Bool False s x) -> annotate x (hcat [ "false", suf s ])
4040
where
4141
pad :: Int -> Doc a
42-
pad n = pretty (replicate n '#')
42+
pad m = pretty (replicate m '#')
4343

4444
suf :: Suffix -> Doc a
4545
suf = pretty . show
@@ -99,7 +99,7 @@ escapeChar c | c <= '\x7f' = escapeByte (char2Byte c)
9999

100100
-- | Convert a number to its padded hexadecimal form
101101
padHex :: Integral a => Int -> a -> Doc b
102-
padHex n 0 = pretty (replicate n '0')
103-
padHex n m = let (m',r) = m `divMod` 0x10
104-
in padHex (n-1) m' <> pretty (intToDigit (fromIntegral r))
102+
padHex i 0 = pretty (replicate i '0')
103+
padHex i m = let (m',r) = m `divMod` 0x10
104+
in padHex (i-1) m' <> pretty (intToDigit (fromIntegral r))
105105

src/Language/Rust/Pretty/Util.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module Language.Rust.Pretty.Util where
2626

2727
import Data.Monoid ((<>))
2828
import Data.List (mapAccumL)
29-
import Data.String (IsString(..))
3029

3130
import qualified Data.Text.Prettyprint.Doc as PP
3231
import Data.Text.Prettyprint.Doc.Internal.Type (Doc(..))

src/Language/Rust/Syntax.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ module Language.Rust.Syntax (
1515
module Language.Rust.Syntax.Ident,
1616
-- * Tokens
1717
module Language.Rust.Syntax.Token,
18-
-- * Annotations
19-
module Language.Rust.Syntax.Annotated
2018
) where
2119

2220
import Language.Rust.Syntax.AST
2321
import Language.Rust.Syntax.Ident
2422
import Language.Rust.Syntax.Token
25-
import Language.Rust.Syntax.Annotated
2623

2724
-- Using import/export shortcut screws up Haddock
2825
{-# ANN module "HLint: ignore Use import/export shortcut" #-}

src/Language/Rust/Syntax/AST.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ module Language.Rust.Syntax.AST (
4444

4545
import {-# SOURCE #-} Language.Rust.Syntax.Token (Token, Delim)
4646
import Language.Rust.Syntax.Ident (Ident, Name)
47-
import Language.Rust.Syntax.Annotated
4847
import Language.Rust.Data.Position
4948

5049
import GHC.Generics (Generic, Generic1)

src/Language/Rust/Syntax/Annotated.hs

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)