Commit 027acf63 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Merge branch 'master' of ssh://git.haskell.org/ghc

parents bec932ef 22c4d60b
......@@ -144,7 +144,6 @@ data CmmToken
| CmmT_else
| CmmT_export
| CmmT_section
| CmmT_align
| CmmT_goto
| CmmT_if
| CmmT_call
......@@ -228,7 +227,6 @@ reservedWordsFM = listToUFM $
( "else", CmmT_else ),
( "export", CmmT_export ),
( "section", CmmT_section ),
( "align", CmmT_align ),
( "goto", CmmT_goto ),
( "if", CmmT_if ),
( "call", CmmT_call ),
......
......@@ -309,7 +309,6 @@ import Data.Maybe
'else' { L _ (CmmT_else) }
'export' { L _ (CmmT_export) }
'section' { L _ (CmmT_section) }
'align' { L _ (CmmT_align) }
'goto' { L _ (CmmT_goto) }
'if' { L _ (CmmT_if) }
'call' { L _ (CmmT_call) }
......
......@@ -30,12 +30,6 @@ ghc_memcmp( HsPtr a1, HsPtr a2, HsInt len )
return (memcmp((char *)a1, a2, len));
}
HsInt
ghc_memcmp_off( HsPtr a1, HsInt i, HsPtr a2, HsInt len )
{
return (memcmp((char *)a1 + i, a2, len));
}
void
enableTimingStats( void ) /* called from the driver */
{
......
......@@ -9,7 +9,6 @@
// Out-of-line string functions, see PrimPacked.lhs
HsInt ghc_strlen( HsAddr a );
HsInt ghc_memcmp( HsAddr a1, HsAddr a2, HsInt len );
HsInt ghc_memcmp_off( HsAddr a1, HsInt i, HsAddr a2, HsInt len );
void enableTimingStats( void );
......
......@@ -595,7 +595,7 @@ rnPatSynBind _sig_fn bind@(PSB { psb_id = L _ name
; fvs' `seq` -- See Note [Free-variable space leak]
return (bind', [name], fvs1)
-- See Note [Pattern synonym wrappers don't yield dependencies]
-- See Note [Pattern synonym builders don't yield dependencies]
}
where
lookupVar = wrapLocM lookupOccRn
......@@ -606,10 +606,10 @@ rnPatSynBind _sig_fn bind@(PSB { psb_id = L _ name
2 (ptext (sLit "Use -XPatternSynonyms to enable this extension"))
{-
Note [Pattern synonym wrappers don't yield dependencies]
Note [Pattern synonym builders don't yield dependencies]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When renaming a pattern synonym that has an explicit wrapper,
references in the wrapper definition should not be used when
When renaming a pattern synonym that has an explicit builder,
references in the builder definition should not be used when
calculating dependencies. For example, consider the following pattern
synonym definition:
......@@ -622,9 +622,9 @@ In this case, 'P' needs to be typechecked in two passes:
1. Typecheck the pattern definition of 'P', which fully determines the
type of 'P'. This step doesn't require knowing anything about 'f',
since the wrapper definition is not looked at.
since the builder definition is not looked at.
2. Typecheck the wrapper definition, which needs the typechecked
2. Typecheck the builder definition, which needs the typechecked
definition of 'f' to be in scope.
This behaviour is implemented in 'tcValBinds', but it crucially
......
......@@ -313,9 +313,9 @@ tcValBinds top_lvl binds sigs thing_inside
; tcExtendIdEnv3 [(idName id, id) | id <- poly_ids] (mkVarSet nwc_tvs) $ do
{ (binds', (extra_binds', thing)) <- tcBindGroups top_lvl sig_fn prag_fn binds $ do
{ thing <- thing_inside
-- See Note [Pattern synonym wrappers don't yield dependencies]
; patsyn_workers <- mapM tcPatSynBuilderBind patsyns
; let extra_binds = [ (NonRecursive, worker) | worker <- patsyn_workers ]
-- See Note [Pattern synonym builders don't yield dependencies]
; patsyn_builders <- mapM tcPatSynBuilderBind patsyns
; let extra_binds = [ (NonRecursive, builder) | builder <- patsyn_builders ]
; return (extra_binds, thing) }
; return (binds' ++ extra_binds', thing) }}
where
......
......@@ -191,7 +191,13 @@ tc_patsyn_finish lname dir is_infix lpat'
(ex_tvs, subst, prov_theta, prov_ev_binds, prov_dicts)
wrapped_args
pat_ty
= do { (matcher_id, matcher_bind) <- tcPatSynMatcher lname lpat'
= do { traceTc "tc_patsyn_finish {" $
ppr (unLoc lname) $$ ppr (unLoc lpat') $$
ppr (univ_tvs, req_theta, req_ev_binds, req_dicts) $$
ppr (ex_tvs, subst, prov_theta, prov_ev_binds, prov_dicts) $$
ppr wrapped_args $$
ppr pat_ty
; (matcher_id, matcher_bind) <- tcPatSynMatcher lname lpat'
(univ_tvs, req_theta, req_ev_binds, req_dicts)
(ex_tvs, subst, prov_theta, prov_ev_binds, prov_dicts)
wrapped_args
......@@ -350,38 +356,38 @@ tcPatSynBuilderBind PSB{ psb_id = L loc name, psb_def = lpat
| otherwise -- Bidirectional
= do { patsyn <- tcLookupPatSyn name
; let Just (worker_id, need_dummy_arg) = patSynBuilder patsyn
; let Just (builder_id, need_dummy_arg) = patSynBuilder patsyn
-- Bidirectional, so patSynBuilder returns Just
match_group' | need_dummy_arg = add_dummy_arg match_group
| otherwise = match_group
bind = FunBind { fun_id = L loc (idName worker_id)
bind = FunBind { fun_id = L loc (idName builder_id)
, fun_infix = False
, fun_matches = match_group'
, fun_co_fn = idHsWrapper
, bind_fvs = placeHolderNamesTc
, fun_tick = [] }
; sig <- instTcTySigFromId worker_id
; sig <- instTcTySigFromId builder_id
-- See Note [Redundant constraints for builder]
; (worker_binds, _, _) <- tcPolyCheck NonRecursive (const []) sig (noLoc bind)
; traceTc "tcPatSynDecl worker" $ ppr worker_binds
; return worker_binds }
; (builder_binds, _, _) <- tcPolyCheck NonRecursive (const []) sig (noLoc bind)
; traceTc "tcPatSynBuilderBind }" $ ppr builder_binds
; return builder_binds }
where
Just match_group = mb_match_group
mb_match_group
mb_match_group
= case dir of
Unidirectional -> Nothing
ExplicitBidirectional explicit_mg -> Just explicit_mg
ImplicitBidirectional -> fmap mk_mg (tcPatToExpr args lpat)
mk_mg :: LHsExpr Name -> MatchGroup Name (LHsExpr Name)
mk_mg body = mkMatchGroupName Generated [wrapper_match]
mk_mg body = mkMatchGroupName Generated [builder_match]
where
wrapper_args = [L loc (VarPat n) | L loc n <- args]
wrapper_match = mkMatch wrapper_args body EmptyLocalBinds
builder_args = [L loc (VarPat n) | L loc n <- args]
builder_match = mkMatch builder_args body EmptyLocalBinds
args = case details of
PrefixPatSyn args -> args
......
......@@ -361,13 +361,47 @@ compilation and registration of multiple packages (whose source code is
specified by the Backpack file). A Backpack file replaces use of
\texttt{-shape-of}, \texttt{-sig-of} and \texttt{-package} flags.\footnote{Backpack files are \emph{generated} by Cabal. Cabal is responsible for downloading source files, resolving what versions of packages are to be used, executing conditional statements. Once the Cabal files are compiled into a Backpack file, it is passed to GHC, which is responsible for instantiating holes and compiling the packages. The package descriptions in a Backpack file are not full Cabal packages, but contain the minimum information necessary for GHC to work: they are more akin to entries in the installed package database (with some differences).}\footnote{One design goal of this separate package language from Cabal is that it can more easily be incorporated into a language specification, without needing the specification to pull in a full description of Cabal.}
Here is a very simple Backpack file which defines two packages:\footnote{It could have been written as two separate files: the effect of processing this Backpack file is to compile both packages simultaneously.}
\begin{verbatim}
package a
exposed-modules: A
package b
includes: a
exposed-modules: B
\end{verbatim}
Here is a more complicated Backpack file taking advantage of the availability
of signatures in Backpack:
\begin{verbatim}
installed package base
installed-id: base-4.0.6-0123456789abcdef
package p
includes: base
exposed-modules: P
other-modules: InternalsP
required-signatures: Map
source-dir: /srv/code/p
installed-id: p-2.0.1-abcdef0123456789
p-2.0.1-def0123456789abc
package q
includes: base, p (Map as QMap)
exposed-modules: Q
other-modules: QMap
source-dir: /srv/code/q
\end{verbatim}
A Backpack file consists of a list of named packages, each of which
is composed of fields (similar to fields in Cabal package description)
which specify various aspects of the package. A package may optionally
be an \emph{installed} package (specified by the \texttt{installed}
keyword), in which case the package refers to an existing package
(with no holes) in the installed package database; in this case,
all fields are omitted except for \texttt{id}, which identifies the
all fields are omitted except for \texttt{installed-id}, which identifies the
specific package in use.
All packages in a Backpack file live in the global namespace.
......@@ -379,10 +413,12 @@ backpack ::= package_0
...
package_n
package ::= ["installed"] "package" pkgname
package ::= "package" pkgname
field_0
...
field_n
| "installed package" pkgname
"installed-id:" ipid
pkgname ::= /* package name, e.g. containers (no version!) */
......@@ -393,7 +429,6 @@ field ::= "includes:" includes
| "required-signatures:" modnames
| "reexported-modules:" reexports
| "source-dir:" path
| "installed-ids:" ipids
| pkgdb_field
\end{verbatim}
......@@ -417,7 +452,14 @@ allowed. Each package has all exposed modules and signatures are
brought into scope under their original names, unless there is a
parenthesized, comma-separated thinning and renaming specification which
causes only the specified modules are brought into scope (under new
names, if the \texttt{as} keyword is used).
names, if the \texttt{as} keyword is used). Here is an example
\texttt{includes} field, which brings into scope all exposed modules
from \texttt{base}, \texttt{P1} and \texttt{P2} from \texttt{p}, and
\texttt{Q} from \texttt{q} under the name \texttt{MyQ}.
\begin{verbatim}
includes: base, p (P1, P2), q (Q as MyQ)
\end{verbatim}
Package inclusion is the mechanism by which holes are instantiated:
a hole and an implementation which are brought in the same scope with
......@@ -434,16 +476,27 @@ modnames ::= modname_0 ... modname_n
The \texttt{exposed-modules}, \texttt{other-modules},
\texttt{exposed-signatures} and \texttt{required-signatures} are exactly
analogous to their Cabal counterparts, and consist of lists of module names
which are to be compiled from the package's source directory.
which are to be compiled from the package's source directory. For example,
to expose modules \texttt{P} and \texttt{Q}, you would write:
\begin{verbatim}
exposed-modules: P Q
\end{verbatim}
\subsection{\texttt{reexported-modules}}
\begin{verbatim}
reexports ::= modname "as" modname
reexports ::= reexport_0 "," ... "," reexport_n
reexport ::= modname "as" modname
| modname
\end{verbatim}
The \texttt{reexported-modules} field is exactly analogous to its Cabal
counterpart, and allows reexporting an in-scope module under a different name.\footnote{This is different from \emph{aliasing} in the original Backpack language, since reexported modules are not visible in the current package.}
counterpart, and allows reexporting an in-scope module under a different name.\footnote{This is different from \emph{aliasing} in the original Backpack language, since reexported modules are not visible in the current package.} For example, to reexport a locally available module \texttt{P} under the name \texttt{Q}, write:
\begin{verbatim}
reexported-modules: P as Q
\end{verbatim}
\subsection{\texttt{source-dir}}
......@@ -456,32 +509,39 @@ the package in question live, e.g. if \texttt{source-dir: /foo}
then we expect the \texttt{hs} file for module \texttt{A} to live
in \texttt{/foo/A.hs}.
\subsection{\texttt{installed-ids}}
\subsection{\texttt{installed-id}}
\begin{verbatim}
ipids ::= ipid_0 ... ipid_n
ipid ::= /* installed package ID, e.g. containers-0.8-HASH */
\end{verbatim}
The \texttt{installed-ids} field specifies existing, \emph{compiled} packages in
the installed package database, which should be used when possible
instead of recompiling the package in question. If the package in
question is an \emph{indefinite} package (with holes), there may be
multiple \texttt{installed-ids}, corresponding to compilations of the package
with different hole instantiations.
The \texttt{installed-id} field specifies an existing, \emph{compiled} package in
the installed package database, which should be used. This information
is only used in the case of an \texttt{installed package} entry, because
we would otherwise not have enough information to calculate a package
key for the package. It is analogous to the \texttt{-package-id} flag.
The \texttt{installed-ids} field is mandatory for an \texttt{installed package}:
it specifies the installed package database entry which can be used
to find the omitted installed package database fields.
\Red{This is enough if, in a package database, a given package key is
unique. If package keys are not unique, it might also be necessary
to explicitly provide multiple multiple \texttt{installed-id}s for
an indefinite package, corresponding to valid compilations of the
package with different hole instantiations. This never happens with
current Cabal, since version numbers are built into package keys.}
\subsection{Installed package database fields}
\begin{verbatim}
pkgdb_field ::= ...
\end{verbatim}
GHC's installed package database supports a number of other fields
which are necessary for GHC to build some packages, e.g., the \texttt{extraLibraries}
field which specifies operating system libraries which also have to
be linked in. Backpack packages accept any fields which are valid in the
installed package database, except for: \texttt{name}, \texttt{id}, \texttt{key}
and \texttt{instantiated-with} (which are computed by GHC itself).
The full list of available fields can be found in the \texttt{bin-package-db}
package.
\subsection{Structure of a Backpack file}
......
......@@ -285,6 +285,8 @@ scavenge_large_srt_bitmap( StgLargeSRT *large_srt )
for (i = 0; i < size / BITS_IN(W_); i++) {
bitmap = large_srt->l.bitmap[i];
// skip zero words: bitmaps can be very sparse, and this helps
// performance a lot in some cases.
if (bitmap != 0) {
for (j = 0; j < BITS_IN(W_); j++) {
if ((bitmap & 1) != 0) {
......
module LinkerUnload (init) where
import GHC
import DynFlags
import Linker
import System.Environment
import MonadUtils ( MonadIO(..) )
foreign export ccall loadPackages :: IO ()
loadPackages :: IO ()
loadPackages = do
[libdir] <- getArgs
runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
let dflags' = dflags { hscTarget = HscNothing
, ghcLink = LinkInMemory }
pkgs <- setSessionDynFlags dflags'
dflags <- getSessionDynFlags
liftIO $ Linker.linkPackages dflags pkgs
......@@ -102,30 +102,13 @@ T7037:
T7040_ghci_setup :
'$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -c T7040_ghci_c.c
LOCAL_GHC_PKG = '$(GHC_PKG)' --no-user-package-db
BASE_DIR = $(shell $(LOCAL_GHC_PKG) field base library-dirs | sed 's/^[^:]*: *//')
BASE_LIB = $(shell $(LOCAL_GHC_PKG) field base hs-libraries | sed 's/^[^:]*: *//')
GHC_PRIM_DIR = $(shell $(LOCAL_GHC_PKG) field ghc-prim library-dirs | sed 's/^[^:]*: *//')
GHC_PRIM_LIB = $(shell $(LOCAL_GHC_PKG) field ghc-prim hs-libraries | sed 's/^[^:]*: *//')
# We need to get first library directory here in order to get rid of
# system gmp library directory installation when ghc is configured
# with --with-gmp-libraries=<dir> parameter
INTEGER_GMP_DIR = $(shell $(LOCAL_GHC_PKG) field integer-gmp library-dirs \
| sed 's/^[^:]*: *//' | head -1)
INTEGER_GMP_LIB = $(shell $(LOCAL_GHC_PKG) field integer-gmp hs-libraries | sed 's/^.*: *//')
BASE = $(BASE_DIR)/lib$(BASE_LIB).a
GHC_PRIM = $(GHC_PRIM_DIR)/lib$(GHC_PRIM_LIB).a
INTEGER_GMP = $(INTEGER_GMP_DIR)/lib$(INTEGER_GMP_LIB).a
.PHONY: linker_unload
linker_unload:
$(RM) Test.o Test.hi
"$(TEST_HC)" $(TEST_HC_OPTS) -c Test.hs -v0
# -rtsopts causes a warning
"$(TEST_HC)" $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload.c -o linker_unload -no-hs-main -optc-Werror -threaded
./linker_unload $(BASE) $(GHC_PRIM) $(INTEGER_GMP)
"$(TEST_HC)" LinkerUnload.hs -package ghc $(filter-out -rtsopts, $(TEST_HC_OPTS)) linker_unload.c -o linker_unload -no-hs-main -optc-Werror
./linker_unload "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
# -----------------------------------------------------------------------------
# Testing failures in the RTS linker. We should be able to repeatedly
......
......@@ -2,11 +2,10 @@
#include <stdio.h>
#include <stdlib.h>
#include "Rts.h"
#if defined(mingw32_HOST_OS)
#include <malloc.h>
#endif
#include <string.h>
#define ITERATIONS 10000
#define ITERATIONS 1000
#if defined(mingw32_HOST_OS)
#define OBJPATH L"Test.o"
......@@ -16,16 +15,7 @@
typedef int testfun(int);
void loadPkg(pathchar *path)
{
int r;
r = loadArchive(path);
if (!r) {
errorBelch("loadObjs(%s) failed", path);
exit(1);
}
}
extern void loadPackages(void);
int main (int argc, char *argv[])
{
......@@ -38,24 +28,7 @@ int main (int argc, char *argv[])
initLinker_(0);
for (i=1; i < argc; i++) {
#if defined(mingw32_HOST_OS)
size_t len = mbstowcs(NULL, argv[i], 0) + 1;
if (len == -1) {
errorBelch("invalid multibyte sequence in argument %d: %s", i, argv[i]);
exit(1);
}
wchar_t *buf = (wchar_t*)_alloca(len * sizeof(wchar_t));
size_t len2 = mbstowcs(buf, argv[i], len);
if (len != len2 + 1) {
errorBelch("something fishy is going on in argument %d: %s", i, argv[i]);
exit(1);
}
loadPkg(buf);
#else
loadPkg(argv[i]);
#endif
}
loadPackages();
for (i=0; i < ITERATIONS; i++) {
r = loadObj(OBJPATH);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment