Skip to content

Commit 4b95bbd

Browse files
committed
2 parents 0889d1a + 1b9e0e6 commit 4b95bbd

File tree

23 files changed

+256
-373
lines changed

23 files changed

+256
-373
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ sudo: true
33

44
# Add new environments to the build here:
55
env:
6-
- GHCVER=8.0.2 CABALVER=1.24
7-
- GHCVER=head CABALVER=head
6+
- GHCVER=7.10.3 CABALVER=1.22
7+
- GHCVER=8.0.2 CABALVER=1.24
8+
- GHCVER=8.2.1 CABALVER=2.0
9+
- GHCVER=head CABALVER=head
810

911
# Allow for develop branch to break
1012
matrix:

bench/allocation-benchmarks/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE OverloadedStrings, TypeApplications #-}
1+
{-# LANGUAGE OverloadedStrings #-}
22

33
import Weigh
44

@@ -8,6 +8,7 @@ import Data.Foldable (for_)
88
import Data.Traversable (for)
99
import GHC.Exts (fromString)
1010

11+
import Language.Rust.Data.InputStream (InputStream)
1112
import Language.Rust.Syntax (SourceFile)
1213
import Language.Rust.Parser (readInputStream, Span, parse')
1314

@@ -47,7 +48,7 @@ main = do
4748
-- Run 'weigh' tests
4849
fileStreams <- for files $ \file -> do { is <- readInputStream file; pure (takeFileName file, is) }
4950
let weigh = do setColumns [ Case, Max, Allocated, GCs, Live ]
50-
for_ fileStreams $ \(file,is) -> func file (parse' @(SourceFile Span)) is
51+
for_ fileStreams $ \(file,is) -> func file (parse' :: InputStream -> SourceFile Span) is
5152
mainWith weigh
5253
(wr, _) <- weighResults weigh
5354
let results = object [ case maybeErr of

bench/timing-benchmarks/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE OverloadedStrings, TypeApplications #-}
1+
{-# LANGUAGE OverloadedStrings #-}
22

33
import Criterion
44
import Criterion.Main (defaultConfig)
@@ -11,6 +11,7 @@ import Data.Foldable (for_)
1111
import Data.Traversable (for)
1212
import GHC.Exts (fromString)
1313

14+
import Language.Rust.Data.InputStream (InputStream)
1415
import Language.Rust.Syntax (SourceFile)
1516
import Language.Rust.Parser (readInputStream, Span, parse')
1617

@@ -50,7 +51,7 @@ main = do
5051
let name = takeFileName f
5152
putStrLn name
5253
is <- readInputStream f
53-
bnch <- benchmarkWith' defaultConfig{ timeLimit = 20 } (nf (parse' @(SourceFile Span)) is)
54+
bnch <- benchmarkWith' defaultConfig{ timeLimit = 20 } (nf (parse' :: InputStream -> SourceFile Span) is)
5455
pure (name, bnch)
5556
let results = object [ fromString name .= object [ "mean" .= m
5657
, "lower bound" .= l

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: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ source-repository head
2020
location: https://github.com/harpocrates/language-rust.git
2121

2222
flag useByteStrings
23-
description: Use ByteString as InputStream datatype
23+
description: Use ByteString instead of String as InputStream datatype
2424
default: True
2525

2626
flag enableQuasiquotes
@@ -51,23 +51,31 @@ 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

58-
other-extensions: OverloadedStrings
57+
other-extensions: FlexibleContexts
58+
, FlexibleInstances
59+
, OverloadedStrings
5960
, OverloadedLists
60-
, DuplicateRecordFields
61+
, StandaloneDeriving
62+
, DeriveFunctor
6163
, DeriveGeneric
64+
, DeriveAnyClass
6265
, DeriveDataTypeable
66+
, TypeFamilies
67+
, TypeOperators
68+
, Rank2Types
69+
, BangPatterns
6370
, CPP
64-
, DeriveFunctor
6571

66-
build-depends: base >=4.9 && <5.0
67-
, prettyprinter >=1.1
68-
, transformers >=0.5 && <0.6
72+
build-depends: base >=4.8 && <5.0
73+
, prettyprinter >=1.0
74+
, transformers >=0.4 && <0.6
6975
, array >=0.5 && <0.6
70-
, deepseq >=1.4.2.0
76+
, deepseq >=1.1
77+
if impl(ghc < 8)
78+
build-depends: semigroups >= 0.18
7179

7280
if flag(useByteStrings)
7381
build-depends: utf8-string >=1.0
@@ -87,11 +95,18 @@ test-suite unit-tests
8795
ParserTest
8896
PrettyTest
8997
CompleteTest
98+
99+
other-extensions: FlexibleContexts
100+
, OverloadedStrings
101+
, OverloadedLists
102+
, ScopedTypeVariables
103+
, UnicodeSyntax
104+
90105
type: exitcode-stdio-1.0
91106
default-language: Haskell2010
92-
build-depends: base >=4.9 && <5.0
93-
, HUnit >=1.5.0.0
94-
, prettyprinter >=1.1
107+
build-depends: base >=4.8 && <5.0
108+
, HUnit >=1.3.0.0
109+
, prettyprinter >=1.0
95110
, test-framework >=0.8.0
96111
, test-framework-hunit >= 0.3.0
97112
, language-rust
@@ -102,50 +117,67 @@ test-suite rustc-tests
102117
main-is: Main.hs
103118
other-modules: Diff
104119
DiffUtils
120+
121+
other-extensions: InstanceSigs
122+
, OverloadedStrings
123+
, OverloadedLists
124+
, MultiParamTypeClasses
125+
, UnicodeSyntax
126+
105127
type: exitcode-stdio-1.0
106128
default-language: Haskell2010
107-
build-depends: base >=4.9 && <5.0
108-
, process >= 1.3
109-
, prettyprinter >=1.1
129+
130+
build-depends: base >=4.8 && <5.0
131+
, process >= 1.4.3
132+
, prettyprinter >=1.0
110133
, bytestring >=0.10
111-
, aeson >= 1.0.0.0
112-
, directory >= 1.3.0.0
134+
, aeson >= 0.11.0.0
135+
, directory >= 1.2.5.0
113136
, filepath >= 1.4.0.0
114137
, test-framework >=0.8.0
115138
, vector >=0.10.0
116139
, text >=1.2.0
117140
, unordered-containers >= 0.2.7
118141
, language-rust
119142
, time >=1.2.0.0
143+
if impl(ghc < 8)
144+
build-depends: semigroups >= 0.18
120145

121146
benchmark timing-benchmarks
122147
hs-source-dirs: bench/timing-benchmarks
123148
ghc-options: -Wall
124149
main-is: Main.hs
150+
151+
other-extensions: OverloadedStrings
152+
125153
type: exitcode-stdio-1.0
126154
default-language: Haskell2010
127-
build-depends: base >=4.9 && <5.0
128-
, process >= 1.3
155+
build-depends: base >=4.8 && <5.0
156+
, process >= 1.4.3
129157
, bytestring >=0.10
130-
, directory >= 1.3.0.0
158+
, directory >= 1.2.5.0
131159
, filepath >= 1.4.0.0
132160
, language-rust
133161
, criterion >=1.1.1.0
134162
, statistics
135-
, aeson >= 1.0.0.0
163+
, aeson >= 0.11.0.0
136164

137165
benchmark allocation-benchmarks
138166
hs-source-dirs: bench/allocation-benchmarks
139167
ghc-options: -Wall
140168
main-is: Main.hs
169+
170+
171+
other-extensions: OverloadedStrings
172+
141173
type: exitcode-stdio-1.0
142174
default-language: Haskell2010
143-
build-depends: base >=4.9 && <5.0
144-
, process >= 1.3
175+
build-depends: base >=4.8 && <5.0
176+
, process >= 1.4.3
145177
, bytestring >=0.10
146-
, directory >= 1.3.0.0
178+
, directory >= 1.2.5.0
147179
, filepath >= 1.4.0.0
148180
, language-rust
149181
, weigh >=0.0.4
150-
, aeson >= 1.0.0.0
182+
, aeson >= 0.11.0.0
151183

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/Data/Position.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Portability : portable
99
1010
Everything to do with describing a position or a contiguous region in a file.
1111
-}
12-
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, CPP, UndecidableInstances, PolyKinds, DeriveAnyClass #-}
12+
{-# LANGUAGE CPP, DeriveDataTypeable, DeriveGeneric, DeriveAnyClass #-}
1313

1414
module Language.Rust.Data.Position (
1515
-- * Positions in files

0 commit comments

Comments
 (0)