From fc45f32491313d2a44e72d8d59cdf95b1660189d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Facundo=20Dom=C3=ADnguez?= Date: Tue, 9 Dec 2014 18:10:18 -0600 Subject: Implement -XStaticValues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: As proposed in [1], this extension introduces a new syntactic form `static e`, where `e :: a` can be any closed expression. The static form produces a value of type `StaticPtr a`, which works as a reference that programs can "dereference" to get the value of `e` back. References are like `Ptr`s, except that they are stable across invocations of a program. The relevant wiki pages are [2, 3], which describe the motivation/ideas and implementation plan respectively. [1] Jeff Epstein, Andrew P. Black, and Simon Peyton-Jones. Towards Haskell in the cloud. SIGPLAN Not., 46(12):118–129, September 2011. ISSN 0362-1340. [2] https://ghc.haskell.org/trac/ghc/wiki/StaticPointers [3] https://ghc.haskell.org/trac/ghc/wiki/StaticPointers/ImplementationPlan Authored-by: Facundo Domínguez Authored-by: Mathieu Boespflug Authored-by: Alexander Vershilov Test Plan: `./validate` Reviewers: hvr, simonmar, simonpj, austin Reviewed By: simonpj, austin Subscribers: qnikst, bgamari, mboes, carter, thomie, goldfire Differential Revision: https://phabricator.haskell.org/D550 GHC Trac Issues: #7015 --- .../tests/typecheck/should_fail/TcStaticPointersFail01.hs | 11 +++++++++++ .../typecheck/should_fail/TcStaticPointersFail01.stderr | 6 ++++++ .../tests/typecheck/should_fail/TcStaticPointersFail02.hs | 12 ++++++++++++ .../typecheck/should_fail/TcStaticPointersFail02.stderr | 14 ++++++++++++++ .../tests/typecheck/should_fail/TcStaticPointersFail03.hs | 9 +++++++++ .../typecheck/should_fail/TcStaticPointersFail03.stderr | 6 ++++++ testsuite/tests/typecheck/should_fail/all.T | 6 ++++++ 7 files changed, 64 insertions(+) create mode 100644 testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.hs create mode 100644 testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr create mode 100644 testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.hs create mode 100644 testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr create mode 100644 testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.hs create mode 100644 testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.stderr (limited to 'testsuite/tests/typecheck/should_fail') diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.hs b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.hs new file mode 100644 index 0000000000..7221b7369b --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.hs @@ -0,0 +1,11 @@ +{-# LANGUAGE StaticPointers #-} + +module StaticPointersFail01 where + +import GHC.StaticPtr + +f0 :: StaticPtr Int +f0 = static g + +g :: Int -> Int +g = id diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr new file mode 100644 index 0000000000..e41ec7443d --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail01.stderr @@ -0,0 +1,6 @@ + +TcStaticPointersFail01.hs:8:13: + Couldn't match expected type ‘Int’ with actual type ‘Int -> Int’ + Probable cause: ‘g’ is applied to too few arguments + In the body of a static form: g + In the expression: static g diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.hs b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.hs new file mode 100644 index 0000000000..3b4d0ff661 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE StaticPointers #-} +{-# LANGUAGE ImpredicativeTypes #-} + +module StaticPointersFail02 where + +import GHC.StaticPtr + +f1 :: StaticPtr ((forall a . a -> a) -> b) +f1 = static (undefined :: (forall a . a -> a) -> b) + +f2 :: StaticPtr (Monad m => a -> m a) +f2 = static return diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr new file mode 100644 index 0000000000..f11ec28f18 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail02.stderr @@ -0,0 +1,14 @@ + +TcStaticPointersFail02.hs:9:6: + No instance for (Data.Typeable.Internal.Typeable b) + arising from a static form + In the expression: static (undefined :: (forall a. a -> a) -> b) + In an equation for ‘f1’: + f1 = static (undefined :: (forall a. a -> a) -> b) + +TcStaticPointersFail02.hs:12:6: + No instance for (Data.Typeable.Internal.Typeable Monad) + (maybe you haven't applied enough arguments to a function?) + arising from a static form + In the expression: static return + In an equation for ‘f2’: f2 = static return diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.hs b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.hs new file mode 100644 index 0000000000..58e06ee1d8 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE StaticPointers #-} + +module StaticPointersFail03 where + +import GHC.StaticPtr +import Data.Typeable + +f1 :: (Typeable a, Typeable m, Monad m) => a -> m a +f1 = deRefStaticPtr (static return) diff --git a/testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.stderr b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.stderr new file mode 100644 index 0000000000..03a01df842 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.stderr @@ -0,0 +1,6 @@ + +TcStaticPointersFail03.hs:9:29: + No instance for (Monad m) arising from a use of ‘return’ + In the body of a static form: return + In the first argument of ‘deRefStaticPtr’, namely ‘(static return)’ + In the expression: deRefStaticPtr (static return) diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index d3c8941c65..1546b3ae8c 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -328,6 +328,12 @@ test('ContextStack2', normal, compile_fail, ['-ftype-function-depth=10']) test('T8570', extra_clean(['T85570a.o', 'T8570a.hi','T85570b.o', 'T8570b.hi']), multimod_compile_fail, ['T8570', '-v0']) test('T8603', normal, compile_fail, ['']) +test('TcStaticPointersFail01', + when(compiler_lt('ghc', '7.9'), skip), compile_fail, ['']) +test('TcStaticPointersFail02', + when(compiler_lt('ghc', '7.9'), skip), compile_fail, ['']) +test('TcStaticPointersFail03', + when(compiler_lt('ghc', '7.9'), skip), compile_fail, ['']) test('T8806', normal, compile_fail, ['']) test('T8912', normal, compile_fail, ['']) test('T9033', normal, compile_fail, ['']) -- cgit v1.2.1