summaryrefslogtreecommitdiff
path: root/testsuite/tests/driver/sigof01
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@cs.stanford.edu>2014-08-07 18:32:12 +0100
committerEdward Z. Yang <ezyang@cs.stanford.edu>2014-10-24 15:49:41 -0700
commitaa4799534225e3fc6bbde0d5e5eeab8868cc3111 (patch)
tree60d77acae2286263a1c75d87d93d333bce5b01c0 /testsuite/tests/driver/sigof01
parent5bb73d79a83bca57dc431421ca1e022f34b8dec9 (diff)
downloadhaskell-aa4799534225e3fc6bbde0d5e5eeab8868cc3111.tar.gz
Implementation of hsig (module signatures), per #9252
Summary: Module signatures, like hs-boot files, are Haskell modules which omit value definitions and contain only signatures. This patchset implements one particular aspect of module signature, namely compiling them against a concrete implementation. It works like this: when we compile an hsig file, we must be told (via the -sig-of flag) what module this signature is implementing. The signature is compiled into an interface file which reexports precisely the entities mentioned in the signature file. We also verify that the interface is compatible with the implementation. This feature is useful in a few situations: 1. Like explicit import lists, signatures can be used to reduce sensitivity to upstream changes. However, a signature can be defined once and then reused by many modules. 2. Signatures can be used to quickly check if a new upstream version is compatible, by typechecking just the signatures and not the actual modules. 3. A signature can be used to mediate separate modular development, where the signature is used as a placeholder for functionality which is loaded in later. (This is only half useful at the moment, since typechecking against signatures without implementations is not implemented in this patchset.) Unlike hs-boot files, hsig files impose no performance overhead. This patchset punts on the type class instances (and type families) problem: instances simply leak from the implementation to the signature. You can explicitly specify what instances you expect to have, and those will be checked, but you may get more instances than you asked for. Our eventual plan is to allow hiding instances, but to consider all transitively reachable instances when considering overlap and soundness. ToDo: signature merging: when a module is provided by multiple signatures for the same base implementation, we should not consider this ambiguous. ToDo: at the moment, signatures do not constitute use-sites, so if you write a signature for a deprecated function, you won't get a warning when you compile the signature. Future work: The ability to feed in shaping information so that we can take advantage of more type equalities than might be immediately evident. Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate and new tests Reviewers: simonpj, simonmar, hvr, austin Subscribers: simonmar, relrod, ezyang, carter, goldfire Differential Revision: https://phabricator.haskell.org/D130 GHC Trac Issues: #9252
Diffstat (limited to 'testsuite/tests/driver/sigof01')
-rw-r--r--testsuite/tests/driver/sigof01/A.hs10
-rw-r--r--testsuite/tests/driver/sigof01/B.hsig6
-rw-r--r--testsuite/tests/driver/sigof01/Main.hs6
-rw-r--r--testsuite/tests/driver/sigof01/Makefile23
-rw-r--r--testsuite/tests/driver/sigof01/all.T9
-rw-r--r--testsuite/tests/driver/sigof01/sigof01.stdout3
-rw-r--r--testsuite/tests/driver/sigof01/sigof01m.stdout7
7 files changed, 64 insertions, 0 deletions
diff --git a/testsuite/tests/driver/sigof01/A.hs b/testsuite/tests/driver/sigof01/A.hs
new file mode 100644
index 0000000000..644432a283
--- /dev/null
+++ b/testsuite/tests/driver/sigof01/A.hs
@@ -0,0 +1,10 @@
+module A where
+data T = T
+ deriving (Show)
+x = True
+y = False
+mkT = T
+class Foo a where
+ foo :: a -> a
+instance Foo Bool where
+ foo = not
diff --git a/testsuite/tests/driver/sigof01/B.hsig b/testsuite/tests/driver/sigof01/B.hsig
new file mode 100644
index 0000000000..289d3bcb18
--- /dev/null
+++ b/testsuite/tests/driver/sigof01/B.hsig
@@ -0,0 +1,6 @@
+module B where
+data T
+x :: Bool
+mkT :: T
+class Foo a where
+ foo :: a -> a
diff --git a/testsuite/tests/driver/sigof01/Main.hs b/testsuite/tests/driver/sigof01/Main.hs
new file mode 100644
index 0000000000..c90cfaf1db
--- /dev/null
+++ b/testsuite/tests/driver/sigof01/Main.hs
@@ -0,0 +1,6 @@
+import B
+y = foo x
+main = do
+ print y
+ print mkT
+ print (foo y)
diff --git a/testsuite/tests/driver/sigof01/Makefile b/testsuite/tests/driver/sigof01/Makefile
new file mode 100644
index 0000000000..a54a1b97e4
--- /dev/null
+++ b/testsuite/tests/driver/sigof01/Makefile
@@ -0,0 +1,23 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+# -fforce-recomp makes lots of driver tests trivially pass, so we
+# filter it out from $(TEST_HC_OPTS).
+TEST_HC_OPTS_NO_RECOMP = $(filter-out -fforce-recomp,$(TEST_HC_OPTS))
+
+S01_OPTS=$(TEST_HC_OPTS_NO_RECOMP) -outputdir tmp_sigof01 -i -itmp_sigof01
+sigof01:
+ rm -rf tmp_sigof01
+ mkdir tmp_sigof01
+ '$(TEST_HC)' $(S01_OPTS) -c A.hs
+ '$(TEST_HC)' $(S01_OPTS) -c B.hsig -sig-of main:A
+ '$(TEST_HC)' $(S01_OPTS) -c Main.hs
+ '$(TEST_HC)' $(S01_OPTS) tmp_sigof01/A.o tmp_sigof01/Main.o -o tmp_sigof01/Main
+ tmp_sigof01/Main
+
+sigof01m:
+ rm -rf tmp_sigof01m
+ mkdir tmp_sigof01m
+ '$(TEST_HC)' $(TEST_HC_OPTS_NO_RECOMP) -outputdir tmp_sigof01m --make Main.hs -sig-of "B is main:A" -o tmp_sigof01m/Main
+ tmp_sigof01m/Main
diff --git a/testsuite/tests/driver/sigof01/all.T b/testsuite/tests/driver/sigof01/all.T
new file mode 100644
index 0000000000..d0cdc3c02c
--- /dev/null
+++ b/testsuite/tests/driver/sigof01/all.T
@@ -0,0 +1,9 @@
+test('sigof01',
+ [ clean_cmd('rm -rf tmp_sigof01') ],
+ run_command,
+ ['$MAKE -s --no-print-directory sigof01'])
+
+test('sigof01m',
+ [ clean_cmd('rm -rf tmp_sigof01m') ],
+ run_command,
+ ['$MAKE -s --no-print-directory sigof01m'])
diff --git a/testsuite/tests/driver/sigof01/sigof01.stdout b/testsuite/tests/driver/sigof01/sigof01.stdout
new file mode 100644
index 0000000000..bb614cd2a0
--- /dev/null
+++ b/testsuite/tests/driver/sigof01/sigof01.stdout
@@ -0,0 +1,3 @@
+False
+T
+True
diff --git a/testsuite/tests/driver/sigof01/sigof01m.stdout b/testsuite/tests/driver/sigof01/sigof01m.stdout
new file mode 100644
index 0000000000..a7fdd8298e
--- /dev/null
+++ b/testsuite/tests/driver/sigof01/sigof01m.stdout
@@ -0,0 +1,7 @@
+[1 of 3] Compiling A ( A.hs, tmp_sigof01m/A.o )
+[2 of 3] Compiling B[sig of A] ( B.hsig, nothing )
+[3 of 3] Compiling Main ( Main.hs, tmp_sigof01m/Main.o )
+Linking tmp_sigof01m/Main ...
+False
+T
+True