[commit: ghc] master: resolve T13704 (abfb91f)
git at git.haskell.org
git at git.haskell.org
Tue Oct 2 14:00:50 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/abfb91fb0ea27eb618f297b1d3ba60cfa021afe0/ghc
>---------------------------------------------------------------
commit abfb91fb0ea27eb618f297b1d3ba60cfa021afe0
Author: chessai <chessai1996 at gmail.com>
Date: Tue Oct 2 14:46:08 2018 +0200
resolve T13704
Summary: allow -main-is to change export list for default module
header, allowing one to change the entry point to one's program.
Test Plan: ./validate
Reviewers: bgamari, nomeata, mpickering
Reviewed By: mpickering
Subscribers: mpickering, rwbarton, carter
GHC Trac Issues: #13704
Differential Revision: https://phabricator.haskell.org/D5189
>---------------------------------------------------------------
abfb91fb0ea27eb618f297b1d3ba60cfa021afe0
.gitignore | 6 ++++++
compiler/typecheck/TcRnExports.hs | 13 ++++++-------
docs/users_guide/bugs.rst | 28 ++++++++++++++++++++++++++++
testsuite/tests/module/T13704.hs | 3 +++
testsuite/tests/module/all.T | 2 +-
5 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/.gitignore b/.gitignore
index c72d044..83fa7ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -209,3 +209,9 @@ GIT_COMMIT_ID
# Output of ghc-in-ghci
/.ghci-objects/
+
+# -----------------------------------------------------------------------------
+# ghc.nix
+ghc.nix/
+
+
diff --git a/compiler/typecheck/TcRnExports.hs b/compiler/typecheck/TcRnExports.hs
index dbe2b4b..1b57608 100644
--- a/compiler/typecheck/TcRnExports.hs
+++ b/compiler/typecheck/TcRnExports.hs
@@ -33,7 +33,7 @@ import DataCon
import PatSyn
import Maybes
import Util (capitalise)
-
+import FastString (fsLit)
import Control.Monad
import DynFlags
@@ -124,19 +124,18 @@ tcRnExports explicit_mod exports
-- list, to avoid bleating about re-exporting a deprecated
-- thing (especially via 'module Foo' export item)
do {
- -- If the module header is omitted altogether, then behave
- -- as if the user had written "module Main(main) where..."
- -- EXCEPT in interactive mode, when we behave as if he had
+ -- In interactive mode, we behave as if he had
-- written "module Main where ..."
- -- Reason: don't want to complain about 'main' not in scope
- -- in interactive mode
; dflags <- getDynFlags
+ ; let default_main = case mainFunIs dflags of
+ Just main_fun -> mkUnqual varName (fsLit main_fun)
+ Nothing -> main_RDR_Unqual
; let real_exports
| explicit_mod = exports
| ghcLink dflags == LinkInMemory = Nothing
| otherwise
= Just (noLoc [noLoc (IEVar noExt
- (noLoc (IEName $ noLoc main_RDR_Unqual)))])
+ (noLoc (IEName $ noLoc default_main)))])
-- ToDo: the 'noLoc' here is unhelpful if 'main'
-- turns out to be out of scope
diff --git a/docs/users_guide/bugs.rst b/docs/users_guide/bugs.rst
index aee8dc5..0290622 100644
--- a/docs/users_guide/bugs.rst
+++ b/docs/users_guide/bugs.rst
@@ -173,6 +173,34 @@ same context. For example, this is fine: ::
.. _infelicities-Modules:
+Default Module headers with -main-is
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The Haskell2010 report specifies in <https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-990005.1> that
+
+ "An abbreviated form of module, consisting only of the module body,
+ is permitted. If this is used, the header is assumed to be
+ `module Main(main) where`."
+
+Consider the following program: ::
+
+ -- file: Main.hs
+ program :: IO ()
+ program = return ()
+
+Under the report, this would fail with ``ghc -main-is Main.program Main.hs``
+with the following errors: ::
+
+ Main.hs:1:1: error:
+ Not in scope: 'main'
+ Perhaps you meant 'min' (imported from Prelude)
+
+ Main.hs:1:1: error:
+ The main IO action 'program' is not exported by module 'Main'
+
+GHC's flag '-main-is' allows one to change the entry point name so that
+the above example would succeed.
+
Module system and interface files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/testsuite/tests/module/T13704.hs b/testsuite/tests/module/T13704.hs
new file mode 100644
index 0000000..38b1cb7
--- /dev/null
+++ b/testsuite/tests/module/T13704.hs
@@ -0,0 +1,3 @@
+program = return ()
+
+-- meant to be compiled with 'ghc -main-is Main.program T13704.hs'
diff --git a/testsuite/tests/module/all.T b/testsuite/tests/module/all.T
index e862413..dbba44f 100644
--- a/testsuite/tests/module/all.T
+++ b/testsuite/tests/module/all.T
@@ -284,4 +284,4 @@ test('T11970B', normal, compile_fail, [''])
test('MultiExport', normal, compile, [''])
test('T13528', normal, compile, [''])
test('T13622', normal, compile, [''])
-
+test('T13704', normal, compile, ['-main-is Main.program'])
More information about the ghc-commits
mailing list