rts: add "-no-rtsopts-suggestions" option
authorJavran Cheng <Javran.c@gmail.com>
Wed, 6 May 2015 12:47:20 +0000 (07:47 -0500)
committerAustin Seipp <austin@well-typed.com>
Wed, 6 May 2015 12:50:49 +0000 (07:50 -0500)
Depends on D767

Setting this flag prevents RTS from giving RTS suggestions like "Use
`+RTS -Ksize -RTS' to increase it."

According to the comment @rwbarton made in #9579, sometimes "+RTS"
suggestions don't make sense (e.g. when the program is precompiled and
installed through package managers), we can encourage people to
distribute binaries with either "-no-rtsopts-suggestions" or "-rtsopts".

Reviewed By: erikd, austin

Differential Revision: https://phabricator.haskell.org/D809

GHC Trac Issues: #9579

28 files changed:
compiler/main/DriverPipeline.hs
compiler/main/DynFlags.hs
docs/users_guide/flags.xml
docs/users_guide/phases.xml
includes/RtsAPI.h
rts/ProfHeap.c
rts/RtsFlags.c
rts/hooks/OutOfHeap.c
rts/hooks/StackOverflow.c
testsuite/tests/rts/T5644/T5644.stderr
testsuite/tests/rts/T9579/.gitignore
testsuite/tests/rts/T9579/Makefile
testsuite/tests/rts/T9579/T9579_outofheap_rtsall.stderr
testsuite/tests/rts/T9579/T9579_outofheap_rtsall_no_suggestions.stderr [new file with mode: 0644]
testsuite/tests/rts/T9579/T9579_outofheap_rtsnone.stderr
testsuite/tests/rts/T9579/T9579_outofheap_rtssome.stderr
testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall.stderr
testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall_no_suggestions.stderr [new file with mode: 0644]
testsuite/tests/rts/T9579/T9579_stackoverflow_rtsnone.stderr
testsuite/tests/rts/T9579/T9579_stackoverflow_rtssome.stderr
testsuite/tests/rts/T9579/all.T
testsuite/tests/rts/outofmem.stderr
testsuite/tests/rts/outofmem.stderr-i386-unknown-mingw32
testsuite/tests/rts/outofmem2.stderr
testsuite/tests/rts/overflow1.stderr
testsuite/tests/rts/overflow2.stderr
testsuite/tests/rts/overflow3.stderr
testsuite/tests/simplCore/should_run/simplrun010.stderr

index c86667c..1a21202 100644 (file)
@@ -1657,6 +1657,10 @@ mkExtraObjToLinkIntoBinary dflags = do
       text " RtsConfig __conf = defaultRtsConfig;",
       text " __conf.rts_opts_enabled = "
           <> text (show (rtsOptsEnabled dflags)) <> semi,
+      text " __conf.rts_opts_suggestions = "
+          <> text (if rtsOptsSuggestions dflags
+                      then "rtsTrue"
+                      else "rtsFalse") <> semi,
       case rtsOpts dflags of
          Nothing   -> Outputable.empty
          Just opts -> ptext (sLit "    __conf.rts_opts= ") <>
index f078c51..d8f5169 100644 (file)
@@ -746,6 +746,7 @@ data DynFlags = DynFlags {
 
   rtsOpts               :: Maybe String,
   rtsOptsEnabled        :: RtsOptsEnabled,
+  rtsOptsSuggestions    :: Bool,
 
   hpcDir                :: String,      -- ^ Path to store the .mix files
 
@@ -1473,6 +1474,7 @@ defaultDynFlags mySettings =
         cmdlineFrameworks       = [],
         rtsOpts                 = Nothing,
         rtsOptsEnabled          = RtsOptsSafeOnly,
+        rtsOptsSuggestions      = True,
 
         hpcDir                  = ".hpc",
 
@@ -2392,6 +2394,8 @@ dynamic_flags = [
   , defGhcFlag "rtsopts=some"   (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
   , defGhcFlag "rtsopts=none"   (NoArg (setRtsOptsEnabled RtsOptsNone))
   , defGhcFlag "no-rtsopts"     (NoArg (setRtsOptsEnabled RtsOptsNone))
+  , defGhcFlag "no-rtsopts-suggestions"
+      (noArg (\d -> d {rtsOptsSuggestions = False} ))
   , defGhcFlag "main-is"        (SepArg setMainIs)
   , defGhcFlag "haddock"        (NoArg (setGeneralFlag Opt_Haddock))
   , defGhcFlag "haddock-opts"   (hasArg addHaddockOpts)
index f62fe22..de6c2c8 100644 (file)
             <entry>-</entry>
           </row>
           <row>
+            <entry><option>-no-rtsopts-suggestions</option></entry>
+            <entry>Don't print RTS suggestions about linking with
+              <literal>-rtsopts</literal>.
+            </entry>
+            <entry>dynamic</entry>
+            <entry>-</entry>
+          </row>
+          <row>
             <entry><option>-no-link</option></entry>
             <entry>Omit linking</entry>
             <entry>dynamic</entry>
index 8994ffe..05037b7 100644 (file)
@@ -1221,6 +1221,27 @@ $ cat foo.hspp</screen>
 
       <varlistentry>
         <term>
+          <option>-no-rtsopts-suggestions</option>
+          <indexterm><primary><option>-no-rtsopts-suggestions</option></primary></indexterm>
+        </term>
+        <listitem>
+          <para>
+            This option disables RTS suggestions about linking with <option>-rtsopts</option>
+            when they are not available.
+
+            These suggestions would be unhelpful if the users have installed Haskell programs
+            through their package managers.
+            With this option enabled, these suggestions will not appear.
+
+            It is recommended for people distributing binaries
+            to build with either <option>-rtsopts</option> or
+            <option>-no-rtsopts-suggestions</option>.
+          </para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>
           <option>-fno-gen-manifest</option>
           <indexterm><primary><option>-fno-gen-manifest</option></primary>
           </indexterm>
index 853a3a5..3b6de0f 100644 (file)
@@ -64,6 +64,9 @@ typedef struct {
     // Whether to interpret +RTS options on the command line
     RtsOptsEnabledEnum rts_opts_enabled;
 
+    // Whether to give RTS flag suggestions
+    HsBool rts_opts_suggestions;
+
     // additional RTS options
     const char *rts_opts;
 
index ba1adcd..25112a7 100644 (file)
@@ -280,12 +280,14 @@ nextEra( void )
         era++;
 
         if (era == max_era) {
-            if (rtsConfig.rts_opts_enabled == RtsOptsAll) {
-                errorBelch("maximum number of censuses reached;\n"
-                           "use +RTS -i to reduce");
-            } else {
-                errorBelch("maximum number of censuses reached;\n"
-                           "Relink with -rtsopts and use `+RTS -i` to reduce");
+            errorBelch("Maximum number of censuses reached.");
+            if (rtsConfig.rts_opts_suggestions == rtsTrue) {
+                if (rtsConfig.rts_opts_enabled == RtsOptsAll)  {
+                    errorBelch("Use `+RTS -i' to reduce censuses.");
+                } else  {
+                    errorBelch("Relink with -rtsopts and "
+                               "use `+RTS -i' to reduce censuses.");
+                }
             }
             stg_exit(EXIT_FAILURE);
         }
index 0fbd05a..94a6c0e 100644 (file)
@@ -59,6 +59,7 @@ RtsConfig rtsConfig;
 
 const RtsConfig defaultRtsConfig  = {
     .rts_opts_enabled = RtsOptsSafeOnly,
+    .rts_opts_suggestions = rtsTrue,
     .rts_opts = NULL,
     .rts_hs_main = rtsFalse,
     .defaultsHook = FlagDefaultsHook,
index bb87528..5e68750 100644 (file)
 void
 OutOfHeapHook (W_ request_size, W_ heap_size) /* both sizes in bytes */
 {
-  (void)request_size;   /* keep gcc -Wall happy */
-  if (heap_size > 0) {
-      errorBelch("Heap exhausted;\n"
-                 "Current maximum heap size is %" FMT_Word
-                 " bytes (%" FMT_Word " MB);\n"
-                 "%s `+RTS -M<size>' to increase it.",
-                 heap_size, heap_size / (1024*1024),
-                 ((rtsConfig.rts_opts_enabled == RtsOptsAll)
-                  ? "use"
-                  : "relink with -rtsopts and use"));
-  } else {
-      errorBelch("out of memory");
-  }
+    (void)request_size;   /* keep gcc -Wall happy */
+    if (heap_size > 0) {
+        errorBelch("Heap exhausted;");
+        errorBelch("Current maximum heap size is %" FMT_Word
+                   " bytes (%" FMT_Word " MB).",
+                   heap_size, heap_size / (1024*1024));
+
+        if (rtsConfig.rts_opts_suggestions == rtsTrue) {
+
+            if (rtsConfig.rts_opts_enabled == RtsOptsAll) {
+                errorBelch("Use `+RTS -M<size>' to increase it.");
+            } else {
+                errorBelch("Relink with -rtsopts and "
+                           "use `+RTS -M<size>' to increase it.");
+            }
+
+        }
+    } else {
+        errorBelch("Out of memory.\n");
+    }
 }
index 1ae8603..602700a 100644 (file)
 void
 StackOverflowHook (W_ stack_size)    /* in bytes */
 {
-    fprintf(stderr,
-            "Stack space overflow: current size %" FMT_Word " bytes.\n"
-            "%s `+RTS -Ksize -RTS' to increase it.\n",
-            stack_size,
-            ((rtsConfig.rts_opts_enabled == RtsOptsAll)
-             ? "Use"
-             : "Relink with -rtsopts and use")
-            );
+    errorBelch("Stack space overflow: current size %" FMT_Word " bytes.",
+               stack_size);
+
+    if (rtsConfig.rts_opts_suggestions == rtsTrue) {
+        if (rtsConfig.rts_opts_enabled == RtsOptsAll) {
+            errorBelch("Use `+RTS -Ksize -RTS' to increase it.");
+        } else {
+            errorBelch("Relink with -rtsopts and "
+                       "use `+RTS -Ksize -RTS' to increase it.");
+        }
+    }
 }
index 198dceb..e5b0ab9 100644 (file)
@@ -1,3 +1,3 @@
 T5644: Heap exhausted;
-Current maximum heap size is 20971520 bytes (20 MB);
-use `+RTS -M<size>' to increase it.
+T5644: Current maximum heap size is 20971520 bytes (20 MB).
+T5644: Use `+RTS -M<size>' to increase it.
index e3a88e5..3c118b0 100644 (file)
@@ -1,6 +1,8 @@
+T9579_outofheap_rtsall_no_suggestions
 T9579_outofheap_rtsall
 T9579_outofheap_rtsnone
 T9579_outofheap_rtssome
+T9579_stackoverflow_rtsall_no_suggestions
 T9579_stackoverflow_rtsall
 T9579_stackoverflow_rtsnone
 T9579_stackoverflow_rtssome
index a205eac..b05f0c4 100644 (file)
@@ -4,30 +4,42 @@ include $(TOP)/mk/test.mk
 
 T9579_stackoverflow_rtsnone:
        '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -K1m \
-                -outputdir tmp_T9579_stackoverflow_rtsnone \
-                StackOverflow.hs -o T9579_stackoverflow_rtsnone
+               -outputdir tmp_T9579_stackoverflow_rtsnone \
+               StackOverflow.hs -o T9579_stackoverflow_rtsnone
 
 T9579_stackoverflow_rtssome:
        '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -K1m \
-                -outputdir tmp_T9579_stackoverflow_rtssome \
-                StackOverflow.hs -o T9579_stackoverflow_rtssome
+               -outputdir tmp_T9579_stackoverflow_rtssome \
+               StackOverflow.hs -o T9579_stackoverflow_rtssome
 
 T9579_stackoverflow_rtsall:
        '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all  -fforce-recomp -with-rtsopts -K1m \
-                -outputdir tmp_T9579_stackoverflow_rtsall \
-                StackOverflow.hs -o T9579_stackoverflow_rtsall
+               -outputdir tmp_T9579_stackoverflow_rtsall \
+               StackOverflow.hs -o T9579_stackoverflow_rtsall
+
+T9579_stackoverflow_rtsall_no_suggestions:
+       '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -K1m \
+               -no-rtsopts-suggestions \
+               -outputdir tmp_T9579_stackoverflow_rtsall_no_suggestions \
+               StackOverflow.hs -o T9579_stackoverflow_rtsall_no_suggestions
 
 T9579_outofheap_rtsnone:
        '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -M1m \
-                -outputdir tmp_T9579_outofheap_rtsnone \
-                OutOfHeap.hs -o T9579_outofheap_rtsnone
+               -outputdir tmp_T9579_outofheap_rtsnone \
+               OutOfHeap.hs -o T9579_outofheap_rtsnone
 
 T9579_outofheap_rtssome:
        '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -M1m \
-                -outputdir tmp_T9579_outofheap_rtssome \
-                OutOfHeap.hs -o T9579_outofheap_rtssome
+               -outputdir tmp_T9579_outofheap_rtssome \
+               OutOfHeap.hs -o T9579_outofheap_rtssome
 
 T9579_outofheap_rtsall:
        '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all  -fforce-recomp -with-rtsopts -M1m \
-                -outputdir tmp_T9579_outofheap_rtsall \
-                OutOfHeap.hs -o T9579_outofheap_rtsall
+               -outputdir tmp_T9579_outofheap_rtsall \
+               OutOfHeap.hs -o T9579_outofheap_rtsall
+
+T9579_outofheap_rtsall_no_suggestions:
+       '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -M1m \
+               -no-rtsopts-suggestions \
+               -outputdir tmp_T9579_outofheap_rtsall_no_suggestions \
+               OutOfHeap.hs -o T9579_outofheap_rtsall_no_suggestions
index 4fb0b86..3d7cfe7 100644 (file)
@@ -1,3 +1,3 @@
 T9579_outofheap_rtsall: Heap exhausted;
-Current maximum heap size is 1048576 bytes (1 MB);
-use `+RTS -M<size>' to increase it.
+T9579_outofheap_rtsall: Current maximum heap size is 1048576 bytes (1 MB).
+T9579_outofheap_rtsall: Use `+RTS -M<size>' to increase it.
diff --git a/testsuite/tests/rts/T9579/T9579_outofheap_rtsall_no_suggestions.stderr b/testsuite/tests/rts/T9579/T9579_outofheap_rtsall_no_suggestions.stderr
new file mode 100644 (file)
index 0000000..c5d1ce3
--- /dev/null
@@ -0,0 +1,2 @@
+T9579_outofheap_rtsall_no_suggestions: Heap exhausted;
+T9579_outofheap_rtsall_no_suggestions: Current maximum heap size is 1048576 bytes (1 MB).
index ce7e05f..3bc2096 100644 (file)
@@ -1,3 +1,3 @@
 T9579_outofheap_rtsnone: Heap exhausted;
-Current maximum heap size is 1048576 bytes (1 MB);
-relink with -rtsopts and use `+RTS -M<size>' to increase it.
+T9579_outofheap_rtsnone: Current maximum heap size is 1048576 bytes (1 MB).
+T9579_outofheap_rtsnone: Relink with -rtsopts and use `+RTS -M<size>' to increase it.
index 25b88e4..a6f0377 100644 (file)
@@ -1,3 +1,3 @@
 T9579_outofheap_rtssome: Heap exhausted;
-Current maximum heap size is 1048576 bytes (1 MB);
-relink with -rtsopts and use `+RTS -M<size>' to increase it.
+T9579_outofheap_rtssome: Current maximum heap size is 1048576 bytes (1 MB).
+T9579_outofheap_rtssome: Relink with -rtsopts and use `+RTS -M<size>' to increase it.
index fd7fe19..16404b8 100644 (file)
@@ -1,2 +1,2 @@
-Stack space overflow: current size 99136 bytes.
-Use `+RTS -Ksize -RTS' to increase it.
+T9579_stackoverflow_rtsall: Stack space overflow: current size 99136 bytes.
+T9579_stackoverflow_rtsall: Use `+RTS -Ksize -RTS' to increase it.
diff --git a/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall_no_suggestions.stderr b/testsuite/tests/rts/T9579/T9579_stackoverflow_rtsall_no_suggestions.stderr
new file mode 100644 (file)
index 0000000..29a04b5
--- /dev/null
@@ -0,0 +1 @@
+T9579_stackoverflow_rtsall_no_suggestions: Stack space overflow: current size 99136 bytes.
index 0287e36..9151add 100644 (file)
@@ -1,2 +1,2 @@
-Stack space overflow: current size 99136 bytes.
-Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it.
+T9579_stackoverflow_rtsnone: Stack space overflow: current size 99136 bytes.
+T9579_stackoverflow_rtsnone: Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it.
index 0287e36..3bbfefe 100644 (file)
@@ -1,2 +1,2 @@
-Stack space overflow: current size 99136 bytes.
-Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it.
+T9579_stackoverflow_rtssome: Stack space overflow: current size 99136 bytes.
+T9579_stackoverflow_rtssome: Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it.
index 8b6880c..e029b4a 100644 (file)
@@ -1,29 +1,64 @@
 test('T9579_stackoverflow_rtsnone',
-     [exit_code(2)],
+     [exit_code(2),
+      extra_clean([ 'tmp_T9579_stackoverflow_rtsnone/Main.hi',
+                    'tmp_T9579_stackoverflow_rtsnone/Main.o' ])],
        run_command,
-     ['$MAKE -s --no-print-directory T9579_stackoverflow_rtsnone && ./T9579_stackoverflow_rtsnone'])
+     ['$MAKE -s --no-print-directory T9579_stackoverflow_rtsnone \
+       && ./T9579_stackoverflow_rtsnone'])
 
 test('T9579_stackoverflow_rtssome',
-     [exit_code(2)],
+     [exit_code(2),
+      extra_clean([ 'tmp_T9579_stackoverflow_rtssome/Main.hi',
+                    'tmp_T9579_stackoverflow_rtssome/Main.o' ])],
        run_command,
-     ['$MAKE -s --no-print-directory T9579_stackoverflow_rtssome && ./T9579_stackoverflow_rtssome'])
+     ['$MAKE -s --no-print-directory T9579_stackoverflow_rtssome \
+       && ./T9579_stackoverflow_rtssome'])
 
 test('T9579_stackoverflow_rtsall',
-     [exit_code(2)],
+     [exit_code(2),
+      extra_clean([ 'tmp_T9579_stackoverflow_rtsall/Main.hi',
+                    'tmp_T9579_stackoverflow_rtsall/Main.o' ])],
        run_command,
-     ['$MAKE -s --no-print-directory T9579_stackoverflow_rtsall && ./T9579_stackoverflow_rtsall'])
+     ['$MAKE -s --no-print-directory T9579_stackoverflow_rtsall \
+       && ./T9579_stackoverflow_rtsall'])
+
+test('T9579_stackoverflow_rtsall_no_suggestions',
+     [exit_code(2),
+      extra_clean([ 'tmp_T9579_stackoverflow_rtsall_no_suggestions/Main.hi',
+                    'tmp_T9579_stackoverflow_rtsall_no_suggestions/Main.o' ])],
+       run_command,
+     ['$MAKE -s --no-print-directory T9579_stackoverflow_rtsall_no_suggestions \
+       && ./T9579_stackoverflow_rtsall_no_suggestions'])
 
 test('T9579_outofheap_rtsnone',
-     [exit_code(251)],
+     [exit_code(251),
+      extra_clean([ 'tmp_T9579_outofheap_rtsnone/Main.hi',
+                    'tmp_T9579_outofheap_rtsnone/Main.o' ])],
        run_command,
-     ['$MAKE -s --no-print-directory T9579_outofheap_rtsnone && ./T9579_outofheap_rtsnone'])
+     ['$MAKE -s --no-print-directory T9579_outofheap_rtsnone \
+      && ./T9579_outofheap_rtsnone'])
 
 test('T9579_outofheap_rtssome',
-     [exit_code(251)],
+     [exit_code(251),
+      extra_clean([ 'tmp_T9579_outofheap_rtssome/Main.hi',
+                    'tmp_T9579_outofheap_rtssome/Main.o' ])],
        run_command,
-     ['$MAKE -s --no-print-directory T9579_outofheap_rtssome && ./T9579_outofheap_rtssome'])
+     ['$MAKE -s --no-print-directory T9579_outofheap_rtssome \
+       && ./T9579_outofheap_rtssome'])
 
 test('T9579_outofheap_rtsall',
-     [exit_code(251)],
+     [exit_code(251),
+      extra_clean([ 'tmp_T9579_outofheap_rtsall/Main.hi',
+                    'tmp_T9579_outofheap_rtsall/Main.o' ])],
+
+       run_command,
+     ['$MAKE -s --no-print-directory T9579_outofheap_rtsall \
+       && ./T9579_outofheap_rtsall'])
+
+test('T9579_outofheap_rtsall_no_suggestions',
+     [exit_code(251),
+      extra_clean([ 'tmp_T9579_outofheap_rtsall_no_suggestions/Main.hi',
+                    'tmp_T9579_outofheap_rtsall_no_suggestions/Main.o' ])],
        run_command,
-     ['$MAKE -s --no-print-directory T9579_outofheap_rtsall && ./T9579_outofheap_rtsall'])
+     ['$MAKE -s --no-print-directory T9579_outofheap_rtsall_no_suggestions \
+       && ./T9579_outofheap_rtsall_no_suggestions'])
index 81856a7..4b16ce9 100644 (file)
@@ -1 +1 @@
-outofmem.exe: out of memory
+outofmem.exe: Out of memory
index 8fb459b..e4548d0 100644 (file)
@@ -1,3 +1,3 @@
 outofmem2: Heap exhausted;
-Current maximum heap size is 5242880 bytes (5 MB);
-use `+RTS -M<size>' to increase it.
+outofmem2: Current maximum heap size is 5242880 bytes (5 MB).
+outofmem2: Use `+RTS -M<size>' to increase it.
index 734ca95..77ef3ac 100644 (file)
@@ -1 +1,2 @@
-overflow1: out of memory
+overflow1: Out of memory.
+
index be65509..0e57a8e 100644 (file)
@@ -1 +1,2 @@
-overflow2: out of memory
+overflow2: Out of memory.
+
index 6c804e5..aec2225 100644 (file)
@@ -1 +1,2 @@
-overflow3: out of memory
+overflow3: Out of memory.
+
index a2a586d..4d524d3 100644 (file)
@@ -1,3 +1,3 @@
 simplrun010: Heap exhausted;
-Current maximum heap size is 10485760 bytes (10 MB);
-use `+RTS -M<size>' to increase it.
+simplrun010: Current maximum heap size is 10485760 bytes (10 MB).
+simplrun010: Use `+RTS -M<size>' to increase it.