Skip to content

Commit 6626953

Browse files
authored
Merge pull request #76 from phischu/v0.7.0
v0.7.0
2 parents 2fb2de0 + 53647d5 commit 6626953

File tree

14 files changed

+220
-199
lines changed

14 files changed

+220
-199
lines changed

.travis.yml

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,74 @@
1-
language: haskell
2-
notifications:
3-
email: false
4-
install: /bin/true
5-
script: travis_retry ./ci-test
1+
# This file has been generated -- see https://github.com/hvr/multi-ghc-travis
2+
language: c
3+
sudo: false
4+
5+
cache:
6+
directories:
7+
- $HOME/.cabsnap
8+
- $HOME/.cabal/packages
9+
10+
before_cache:
11+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
12+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar
13+
14+
matrix:
15+
include:
16+
- env: CABALVER=1.24 GHCVER=7.8.4
17+
compiler: ": #GHC 7.8.4"
18+
addons: {apt: {packages: [cabal-install-1.24,ghc-7.8.4,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}
19+
- env: CABALVER=1.24 GHCVER=7.10.1
20+
compiler: ": #GHC 7.10.1"
21+
addons: {apt: {packages: [cabal-install-1.24,ghc-7.10.1,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}
22+
- env: CABALVER=1.24 GHCVER=8.0.1
23+
compiler: ": #GHC 8.0.1"
24+
addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}
25+
26+
before_install:
27+
- unset CC
28+
- export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:/opt/alex/3.1.7/bin:/opt/happy/1.19.5/bin:$PATH
29+
30+
install:
31+
- cabal --version
32+
- echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
33+
- if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];
34+
then
35+
zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz >
36+
$HOME/.cabal/packages/hackage.haskell.org/00-index.tar;
37+
fi
38+
- travis_retry cabal update -v
39+
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
40+
- cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt
41+
- sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt
42+
43+
# check whether current requested install-plan matches cached package-db snapshot
44+
- if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;
45+
then
46+
echo "cabal build-cache HIT";
47+
rm -rfv .ghc;
48+
cp -a $HOME/.cabsnap/ghc $HOME/.ghc;
49+
cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/;
50+
else
51+
echo "cabal build-cache MISS";
52+
rm -rf $HOME/.cabsnap;
53+
mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;
54+
cabal install --only-dependencies --enable-tests --enable-benchmarks;
55+
fi
56+
57+
# snapshot package-db on cache miss
58+
- if [ ! -d $HOME/.cabsnap ];
59+
then
60+
echo "snapshotting package-db to build-cache";
61+
mkdir $HOME/.cabsnap;
62+
cp -a $HOME/.ghc $HOME/.cabsnap/ghc;
63+
cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/;
64+
fi
65+
66+
# Here starts the actual work to be performed for the package under test;
67+
# any command which exits with a non-zero exit code causes the build to fail.
68+
script:
69+
- if [ -f configure.ac ]; then autoreconf -i; fi
70+
- cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging
71+
- cabal build # this builds all libraries and executables (including tests/benchmarks)
72+
- cabal test
73+
74+
# EOF

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Changes
44
Version 0.7.0
55
-------------
66

7+
* Improve annotation performance
78
* Relax bounds on aeson
89
* Relax bounds on transformers
10+
* Bugfixes
911

1012
Version 0.6.0
1113
-------------

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ haskell-names does name and module resolution for haskell-src-exts AST.
55

66
Namely, it can do the following:
77

8-
* for a liat of modules, compute the lists of symbols they export.
8+
* For a list of modules, compute the list of symbols each module exports.
99
This is called `resolve`.
10-
* for each name in a module, figure out what it refers to — whether it's bound
10+
* For each name in a module, figure out what it refers to — whether it's bound
1111
locally (say, by a `where` clause) or globally (and then give its origin).
1212
This is called `annotate`.
1313

@@ -23,8 +23,8 @@ a development version of [haskell-src-exts][hse].
2323
Environments
2424
-----------------
2525

26-
An environment is a map from module name to list of entities the module exports.
27-
Entities are for example types, class, functions etc. We store these lists in
26+
An environment is a map from module name to list of symbols the module exports.
27+
Symbols are for example types, classes, functions etc. We persist these lists in
2828
a JSON format.
2929
For example, here are a couple of entries from `Prelude.names`:
3030

@@ -151,8 +151,6 @@ main = do
151151

152152
### API documentation
153153

154-
See [haskell-names haddock documentation][doc-index].
155-
156154
The core module you need is [Language.Haskell.Names][]
157155

158156
Other modules are more experimental, less documented, and you probably don't need

ci-test

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

haskell-names.cabal

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Homepage: http://documentup.com/haskell-suite/haskell-names
1111
Stability: Experimental
1212
Build-Type: Simple
1313
Cabal-Version: >= 1.10
14+
Tested-With: GHC == 7.8.4, GHC == 7.10.1, GHC == 8.0.1
1415

1516
extra-source-files:
1617
README.md
@@ -243,7 +244,9 @@ Library
243244
, aeson >= 0.8.0.2 && < 0.12
244245
, bytestring >= 0.10.4.0 && < 0.11
245246
, data-lens-light >= 0.1.2.1 && < 0.2
246-
, traverse-with-class >= 0.2.0.3 && < 0.3
247+
, traverse-with-class >= 0.2.0.3 && < 0.3
248+
if impl(ghc <= 7.8)
249+
Build-depends: tagged >= 0.8.4 && < 0.9
247250
Hs-source-dirs: src
248251
Ghc-options: -Wall -fno-warn-name-shadowing
249252

@@ -287,5 +290,5 @@ Test-suite test
287290
, filemanip >= 0.3.6.3 && < 0.4
288291
, pretty-show >= 1.6.1 && < 1.7
289292
, traverse-with-class >= 0.2.0.3 && < 0.3
290-
, haskell-names >= 0.6.0 && < 0.7
293+
, haskell-names >= 0.7.0 && < 0.8
291294

src/Language/Haskell/Names/Annotated.hs

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,18 @@ annotateRec
4242
annotateRec _ sc a = go sc a where
4343
go :: forall a . Resolvable a => Scope -> a -> a
4444
go sc a
45-
| ReferenceV <- getL nameCtx sc
46-
, Just (Refl :: QName (Scoped l) :~: a) <- eqT
47-
= lookupValue (fmap sLoc a) sc <$ a
48-
| ReferenceT <- getL nameCtx sc
49-
, Just (Refl :: QName (Scoped l) :~: a) <- eqT
50-
= lookupType (fmap sLoc a) sc <$ a
51-
| ReferenceUV <- getL nameCtx sc
52-
, Just (Refl :: Name (Scoped l) :~: a) <- eqT
53-
= lookupMethod (fmap sLoc a) sc <$ a
54-
| ReferenceUT <- getL nameCtx sc
55-
, Just (Refl :: QName (Scoped l) :~: a) <- eqT
56-
= lookupAssociatedType (fmap sLoc a) sc <$ a
57-
| BindingV <- getL nameCtx sc
58-
, Just (Refl :: Name (Scoped l) :~: a) <- eqT
59-
= Scoped ValueBinder (sLoc . ann $ a) <$ a
60-
| BindingT <- getL nameCtx sc
61-
, Just (Refl :: Name (Scoped l) :~: a) <- eqT
62-
= Scoped TypeBinder (sLoc . ann $ a) <$ a
45+
| Just (Refl :: QName (Scoped l) :~: a) <- eqT
46+
= lookupQName (fmap sLoc a) sc <$ a
47+
| Just (Refl :: Name (Scoped l) :~: a) <- eqT
48+
= lookupName (fmap sLoc a) sc <$ a
6349
| Just (Refl :: FieldUpdate (Scoped l) :~: a) <- eqT
6450
= case a of
65-
FieldPun l n -> FieldPun l (lookupValue (sLoc <$> n) sc <$ n)
51+
FieldPun l qname -> FieldPun l (lookupQName (sLoc <$> qname) sc <$ qname)
6652
FieldWildcard l -> FieldWildcard (Scoped (RecExpWildcard namesRes) (sLoc l)) where
6753
namesRes = do
6854
f <- sc ^. wcNames
69-
let qn = setAnn (sLoc l) (UnQual () (annName (wcFieldName f)))
70-
case lookupValue qn sc of
55+
let qname = setAnn (sLoc l) (UnQual () (annName (wcFieldName f)))
56+
case lookupQName qname sc of
7157
Scoped info@(GlobalSymbol _ _) _ -> return (wcFieldName f,info)
7258
Scoped info@(LocalValue _) _ -> return (wcFieldName f,info)
7359
_ -> []
@@ -77,60 +63,74 @@ annotateRec _ sc a = go sc a where
7763
= let
7864
namesRes = do
7965
f <- sc ^. wcNames
80-
let qn = UnQual () (annName (wcFieldName f))
81-
Scoped (GlobalSymbol symbol _) _ <- return (lookupValue qn sc)
66+
let qname = UnQual () (annName (wcFieldName f))
67+
Scoped (GlobalSymbol symbol _) _ <- return (lookupQName qname (exprV sc))
8268
return (symbol {symbolModule = wcFieldModuleName f})
83-
in PFieldWildcard (Scoped (RecPatWildcard namesRes) (sLoc l))
69+
in PFieldWildcard (Scoped (RecPatWildcard namesRes) (sLoc l))
8470
| otherwise
8571
= rmap go sc a
8672

87-
lookupValue :: QName l -> Scope -> Scoped l
88-
lookupValue (Special l _) _ = Scoped None l
89-
lookupValue qn sc = Scoped nameInfo (ann qn)
90-
where
91-
nameInfo =
92-
case Local.lookupValue qn $ getL lTable sc of
93-
Right r -> LocalValue r
94-
_ ->
95-
case Global.lookupValue qn $ getL gTable sc of
96-
Global.SymbolFound r -> GlobalSymbol r (sQName qn)
97-
Global.Error e -> ScopeError e
98-
Global.Special -> None
99-
100-
lookupType :: QName l -> Scope -> Scoped l
101-
lookupType (Special l _) _ = Scoped None l
102-
lookupType qn sc = Scoped nameInfo (ann qn)
103-
where
104-
nameInfo =
105-
case Global.lookupType qn $ getL gTable sc of
106-
Global.SymbolFound r -> GlobalSymbol r (sQName qn)
107-
Global.Error e -> ScopeError e
108-
Global.Special -> None
109-
110-
lookupMethod :: Name l -> Scope -> Scoped l
111-
lookupMethod n sc = Scoped nameInfo (ann qn)
112-
where
113-
nameInfo =
114-
case Global.lookupMethodOrAssociate qn $ getL gTable sc of
115-
Global.SymbolFound r -> GlobalSymbol r (sQName qn)
116-
Global.Error e -> ScopeError e
117-
Global.Special -> None
118-
qn = qualifyName (getL instQual sc) n
119-
120-
lookupAssociatedType :: QName l -> Scope -> Scoped l
121-
lookupAssociatedType qn sc = Scoped nameInfo (ann qn)
122-
where
123-
nameInfo =
124-
case Global.lookupMethodOrAssociate qn' $ getL gTable sc of
125-
Global.SymbolFound r -> GlobalSymbol r (sQName qn)
126-
Global.Error e -> ScopeError e
127-
Global.Special -> None
128-
qn' = case qn of
129-
UnQual _ n -> qualifyName (getL instQual sc) n
130-
_ -> qn
73+
74+
lookupQName :: QName l -> Scope -> Scoped l
75+
lookupQName (Special l _) _ = Scoped None l
76+
lookupQName qname scope = Scoped nameInfo (ann qname) where
77+
78+
nameInfo = case getL nameCtx scope of
79+
80+
ReferenceV -> case Local.lookupValue qname (getL lTable scope) of
81+
Right srcloc -> LocalValue srcloc
82+
_ ->
83+
checkUniqueness (Global.lookupValue qname globalTable)
84+
85+
ReferenceT ->
86+
checkUniqueness (Global.lookupType qname globalTable)
87+
88+
ReferenceUT ->
89+
checkUniqueness (Global.lookupMethodOrAssociate qname' globalTable) where
90+
qname' = case qname of
91+
UnQual _ name -> qualifyName (getL instQual scope) name
92+
_ -> qname
93+
94+
_ -> None
95+
96+
globalTable = getL gTable scope
97+
98+
checkUniqueness symbols = case symbols of
99+
[] -> ScopeError (ENotInScope qname)
100+
[symbol] -> GlobalSymbol symbol (sQName qname)
101+
_ -> ScopeError (EAmbiguous qname symbols)
102+
103+
104+
lookupName :: Name l -> Scope -> Scoped l
105+
lookupName name scope = Scoped nameInfo (ann name) where
106+
107+
nameInfo = case getL nameCtx scope of
108+
109+
ReferenceUV ->
110+
checkUniqueness qname (Global.lookupMethodOrAssociate qname globalTable) where
111+
qname = qualifyName (getL instQual scope) name
112+
113+
SignatureV ->
114+
checkUniqueness qname (Global.lookupValue qname globalTable) where
115+
qname = qualifyName (Just (getL moduName scope)) name
116+
117+
BindingV -> ValueBinder
118+
119+
BindingT -> TypeBinder
120+
121+
_ -> None
122+
123+
globalTable = getL gTable scope
124+
125+
checkUniqueness qname symbols = case symbols of
126+
[] -> ScopeError (ENotInScope qname)
127+
[symbol] -> GlobalSymbol symbol (sQName qname)
128+
_ -> ScopeError (EAmbiguous qname symbols)
129+
131130

132131
qualifyName :: Maybe UnAnn.ModuleName -> Name l -> QName l
133132
qualifyName Nothing n = UnQual (ann n) n
134-
qualifyName (Just (UnAnn.ModuleName moduleName)) n = Qual (ann n) annotatedModuleName n
135-
where
133+
qualifyName (Just (UnAnn.ModuleName moduleName)) n =
134+
Qual (ann n) annotatedModuleName n where
136135
annotatedModuleName = ModuleName (ann n) moduleName
136+

0 commit comments

Comments
 (0)