Commit 477f514f authored by Javran Cheng's avatar Javran Cheng Committed by Austin Seipp

rts: add "-no-rtsopts-suggestions" option

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
parent 03c4893e
...@@ -1657,6 +1657,10 @@ mkExtraObjToLinkIntoBinary dflags = do ...@@ -1657,6 +1657,10 @@ mkExtraObjToLinkIntoBinary dflags = do
text " RtsConfig __conf = defaultRtsConfig;", text " RtsConfig __conf = defaultRtsConfig;",
text " __conf.rts_opts_enabled = " text " __conf.rts_opts_enabled = "
<> text (show (rtsOptsEnabled dflags)) <> semi, <> text (show (rtsOptsEnabled dflags)) <> semi,
text " __conf.rts_opts_suggestions = "
<> text (if rtsOptsSuggestions dflags
then "rtsTrue"
else "rtsFalse") <> semi,
case rtsOpts dflags of case rtsOpts dflags of
Nothing -> Outputable.empty Nothing -> Outputable.empty
Just opts -> ptext (sLit " __conf.rts_opts= ") <> Just opts -> ptext (sLit " __conf.rts_opts= ") <>
......
...@@ -746,6 +746,7 @@ data DynFlags = DynFlags { ...@@ -746,6 +746,7 @@ data DynFlags = DynFlags {
rtsOpts :: Maybe String, rtsOpts :: Maybe String,
rtsOptsEnabled :: RtsOptsEnabled, rtsOptsEnabled :: RtsOptsEnabled,
rtsOptsSuggestions :: Bool,
hpcDir :: String, -- ^ Path to store the .mix files hpcDir :: String, -- ^ Path to store the .mix files
...@@ -1473,6 +1474,7 @@ defaultDynFlags mySettings = ...@@ -1473,6 +1474,7 @@ defaultDynFlags mySettings =
cmdlineFrameworks = [], cmdlineFrameworks = [],
rtsOpts = Nothing, rtsOpts = Nothing,
rtsOptsEnabled = RtsOptsSafeOnly, rtsOptsEnabled = RtsOptsSafeOnly,
rtsOptsSuggestions = True,
hpcDir = ".hpc", hpcDir = ".hpc",
...@@ -2392,6 +2394,8 @@ dynamic_flags = [ ...@@ -2392,6 +2394,8 @@ dynamic_flags = [
, defGhcFlag "rtsopts=some" (NoArg (setRtsOptsEnabled RtsOptsSafeOnly)) , defGhcFlag "rtsopts=some" (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
, defGhcFlag "rtsopts=none" (NoArg (setRtsOptsEnabled RtsOptsNone)) , defGhcFlag "rtsopts=none" (NoArg (setRtsOptsEnabled RtsOptsNone))
, defGhcFlag "no-rtsopts" (NoArg (setRtsOptsEnabled RtsOptsNone)) , defGhcFlag "no-rtsopts" (NoArg (setRtsOptsEnabled RtsOptsNone))
, defGhcFlag "no-rtsopts-suggestions"
(noArg (\d -> d {rtsOptsSuggestions = False} ))
, defGhcFlag "main-is" (SepArg setMainIs) , defGhcFlag "main-is" (SepArg setMainIs)
, defGhcFlag "haddock" (NoArg (setGeneralFlag Opt_Haddock)) , defGhcFlag "haddock" (NoArg (setGeneralFlag Opt_Haddock))
, defGhcFlag "haddock-opts" (hasArg addHaddockOpts) , defGhcFlag "haddock-opts" (hasArg addHaddockOpts)
......
...@@ -2606,6 +2606,14 @@ ...@@ -2606,6 +2606,14 @@
<entry>dynamic</entry> <entry>dynamic</entry>
<entry>-</entry> <entry>-</entry>
</row> </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> <row>
<entry><option>-no-link</option></entry> <entry><option>-no-link</option></entry>
<entry>Omit linking</entry> <entry>Omit linking</entry>
......
...@@ -1219,6 +1219,27 @@ $ cat foo.hspp</screen> ...@@ -1219,6 +1219,27 @@ $ cat foo.hspp</screen>
</listitem> </listitem>
</varlistentry> </varlistentry>
<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> <varlistentry>
<term> <term>
<option>-fno-gen-manifest</option> <option>-fno-gen-manifest</option>
......
...@@ -64,6 +64,9 @@ typedef struct { ...@@ -64,6 +64,9 @@ typedef struct {
// Whether to interpret +RTS options on the command line // Whether to interpret +RTS options on the command line
RtsOptsEnabledEnum rts_opts_enabled; RtsOptsEnabledEnum rts_opts_enabled;
// Whether to give RTS flag suggestions
HsBool rts_opts_suggestions;
// additional RTS options // additional RTS options
const char *rts_opts; const char *rts_opts;
......
...@@ -280,12 +280,14 @@ nextEra( void ) ...@@ -280,12 +280,14 @@ nextEra( void )
era++; era++;
if (era == max_era) { if (era == max_era) {
if (rtsConfig.rts_opts_enabled == RtsOptsAll) { errorBelch("Maximum number of censuses reached.");
errorBelch("maximum number of censuses reached;\n" if (rtsConfig.rts_opts_suggestions == rtsTrue) {
"use +RTS -i to reduce"); if (rtsConfig.rts_opts_enabled == RtsOptsAll) {
} else { errorBelch("Use `+RTS -i' to reduce censuses.");
errorBelch("maximum number of censuses reached;\n" } else {
"Relink with -rtsopts and use `+RTS -i` to reduce"); errorBelch("Relink with -rtsopts and "
"use `+RTS -i' to reduce censuses.");
}
} }
stg_exit(EXIT_FAILURE); stg_exit(EXIT_FAILURE);
} }
......
...@@ -59,6 +59,7 @@ RtsConfig rtsConfig; ...@@ -59,6 +59,7 @@ RtsConfig rtsConfig;
const RtsConfig defaultRtsConfig = { const RtsConfig defaultRtsConfig = {
.rts_opts_enabled = RtsOptsSafeOnly, .rts_opts_enabled = RtsOptsSafeOnly,
.rts_opts_suggestions = rtsTrue,
.rts_opts = NULL, .rts_opts = NULL,
.rts_hs_main = rtsFalse, .rts_hs_main = rtsFalse,
.defaultsHook = FlagDefaultsHook, .defaultsHook = FlagDefaultsHook,
......
...@@ -13,17 +13,24 @@ ...@@ -13,17 +13,24 @@
void void
OutOfHeapHook (W_ request_size, W_ heap_size) /* both sizes in bytes */ OutOfHeapHook (W_ request_size, W_ heap_size) /* both sizes in bytes */
{ {
(void)request_size; /* keep gcc -Wall happy */ (void)request_size; /* keep gcc -Wall happy */
if (heap_size > 0) { if (heap_size > 0) {
errorBelch("Heap exhausted;\n" errorBelch("Heap exhausted;");
"Current maximum heap size is %" FMT_Word errorBelch("Current maximum heap size is %" FMT_Word
" bytes (%" FMT_Word " MB);\n" " bytes (%" FMT_Word " MB).",
"%s `+RTS -M<size>' to increase it.", heap_size, heap_size / (1024*1024));
heap_size, heap_size / (1024*1024),
((rtsConfig.rts_opts_enabled == RtsOptsAll) if (rtsConfig.rts_opts_suggestions == rtsTrue) {
? "use"
: "relink with -rtsopts and use")); if (rtsConfig.rts_opts_enabled == RtsOptsAll) {
} else { errorBelch("Use `+RTS -M<size>' to increase it.");
errorBelch("out of memory"); } else {
} errorBelch("Relink with -rtsopts and "
"use `+RTS -M<size>' to increase it.");
}
}
} else {
errorBelch("Out of memory.\n");
}
} }
...@@ -14,12 +14,15 @@ ...@@ -14,12 +14,15 @@
void void
StackOverflowHook (W_ stack_size) /* in bytes */ StackOverflowHook (W_ stack_size) /* in bytes */
{ {
fprintf(stderr, errorBelch("Stack space overflow: current size %" FMT_Word " bytes.",
"Stack space overflow: current size %" FMT_Word " bytes.\n" stack_size);
"%s `+RTS -Ksize -RTS' to increase it.\n",
stack_size, if (rtsConfig.rts_opts_suggestions == rtsTrue) {
((rtsConfig.rts_opts_enabled == RtsOptsAll) if (rtsConfig.rts_opts_enabled == RtsOptsAll) {
? "Use" errorBelch("Use `+RTS -Ksize -RTS' to increase it.");
: "Relink with -rtsopts and use") } else {
); errorBelch("Relink with -rtsopts and "
"use `+RTS -Ksize -RTS' to increase it.");
}
}
} }
T5644: Heap exhausted; T5644: Heap exhausted;
Current maximum heap size is 20971520 bytes (20 MB); T5644: Current maximum heap size is 20971520 bytes (20 MB).
use `+RTS -M<size>' to increase it. T5644: Use `+RTS -M<size>' to increase it.
T9579_outofheap_rtsall_no_suggestions
T9579_outofheap_rtsall T9579_outofheap_rtsall
T9579_outofheap_rtsnone T9579_outofheap_rtsnone
T9579_outofheap_rtssome T9579_outofheap_rtssome
T9579_stackoverflow_rtsall_no_suggestions
T9579_stackoverflow_rtsall T9579_stackoverflow_rtsall
T9579_stackoverflow_rtsnone T9579_stackoverflow_rtsnone
T9579_stackoverflow_rtssome T9579_stackoverflow_rtssome
...@@ -4,30 +4,42 @@ include $(TOP)/mk/test.mk ...@@ -4,30 +4,42 @@ include $(TOP)/mk/test.mk
T9579_stackoverflow_rtsnone: T9579_stackoverflow_rtsnone:
'$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -K1m \ '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -K1m \
-outputdir tmp_T9579_stackoverflow_rtsnone \ -outputdir tmp_T9579_stackoverflow_rtsnone \
StackOverflow.hs -o T9579_stackoverflow_rtsnone StackOverflow.hs -o T9579_stackoverflow_rtsnone
T9579_stackoverflow_rtssome: T9579_stackoverflow_rtssome:
'$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -K1m \ '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -K1m \
-outputdir tmp_T9579_stackoverflow_rtssome \ -outputdir tmp_T9579_stackoverflow_rtssome \
StackOverflow.hs -o T9579_stackoverflow_rtssome StackOverflow.hs -o T9579_stackoverflow_rtssome
T9579_stackoverflow_rtsall: T9579_stackoverflow_rtsall:
'$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -K1m \ '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -K1m \
-outputdir tmp_T9579_stackoverflow_rtsall \ -outputdir tmp_T9579_stackoverflow_rtsall \
StackOverflow.hs -o 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: T9579_outofheap_rtsnone:
'$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -M1m \ '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=none -fforce-recomp -with-rtsopts -M1m \
-outputdir tmp_T9579_outofheap_rtsnone \ -outputdir tmp_T9579_outofheap_rtsnone \
OutOfHeap.hs -o T9579_outofheap_rtsnone OutOfHeap.hs -o T9579_outofheap_rtsnone
T9579_outofheap_rtssome: T9579_outofheap_rtssome:
'$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -M1m \ '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=some -fforce-recomp -with-rtsopts -M1m \
-outputdir tmp_T9579_outofheap_rtssome \ -outputdir tmp_T9579_outofheap_rtssome \
OutOfHeap.hs -o T9579_outofheap_rtssome OutOfHeap.hs -o T9579_outofheap_rtssome
T9579_outofheap_rtsall: T9579_outofheap_rtsall:
'$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -M1m \ '$(TEST_HC)' $(TEST_HC_OPTS) -rtsopts=all -fforce-recomp -with-rtsopts -M1m \
-outputdir tmp_T9579_outofheap_rtsall \ -outputdir tmp_T9579_outofheap_rtsall \
OutOfHeap.hs -o 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
T9579_outofheap_rtsall: Heap exhausted; T9579_outofheap_rtsall: Heap exhausted;
Current maximum heap size is 1048576 bytes (1 MB); T9579_outofheap_rtsall: Current maximum heap size is 1048576 bytes (1 MB).
use `+RTS -M<size>' to increase it. T9579_outofheap_rtsall: Use `+RTS -M<size>' to increase it.
T9579_outofheap_rtsall_no_suggestions: Heap exhausted;
T9579_outofheap_rtsall_no_suggestions: Current maximum heap size is 1048576 bytes (1 MB).
T9579_outofheap_rtsnone: Heap exhausted; T9579_outofheap_rtsnone: Heap exhausted;
Current maximum heap size is 1048576 bytes (1 MB); T9579_outofheap_rtsnone: Current maximum heap size is 1048576 bytes (1 MB).
relink with -rtsopts and use `+RTS -M<size>' to increase it. T9579_outofheap_rtsnone: Relink with -rtsopts and use `+RTS -M<size>' to increase it.
T9579_outofheap_rtssome: Heap exhausted; T9579_outofheap_rtssome: Heap exhausted;
Current maximum heap size is 1048576 bytes (1 MB); T9579_outofheap_rtssome: Current maximum heap size is 1048576 bytes (1 MB).
relink with -rtsopts and use `+RTS -M<size>' to increase it. T9579_outofheap_rtssome: Relink with -rtsopts and use `+RTS -M<size>' to increase it.
Stack space overflow: current size 99136 bytes. T9579_stackoverflow_rtsall: Stack space overflow: current size 99136 bytes.
Use `+RTS -Ksize -RTS' to increase it. T9579_stackoverflow_rtsall: Use `+RTS -Ksize -RTS' to increase it.
T9579_stackoverflow_rtsall_no_suggestions: Stack space overflow: current size 99136 bytes.
Stack space overflow: current size 99136 bytes. T9579_stackoverflow_rtsnone: Stack space overflow: current size 99136 bytes.
Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it. T9579_stackoverflow_rtsnone: Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it.
Stack space overflow: current size 99136 bytes. T9579_stackoverflow_rtssome: Stack space overflow: current size 99136 bytes.
Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it. T9579_stackoverflow_rtssome: Relink with -rtsopts and use `+RTS -Ksize -RTS' to increase it.
test('T9579_stackoverflow_rtsnone', 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, 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', 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, 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', 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, 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', 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, 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', 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, 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', 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, 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'])
outofmem.exe: out of memory outofmem.exe: Out of memory
outofmem.exe: out of memory outofmem.exe: Out of memory
outofmem2: Heap exhausted; outofmem2: Heap exhausted;
Current maximum heap size is 5242880 bytes (5 MB); outofmem2: Current maximum heap size is 5242880 bytes (5 MB).
use `+RTS -M<size>' to increase it. outofmem2: Use `+RTS -M<size>' to increase it.
overflow1: out of memory overflow1: Out of memory.
overflow2: out of memory overflow2: Out of memory.
overflow3: out of memory overflow3: Out of memory.
simplrun010: Heap exhausted; simplrun010: Heap exhausted;
Current maximum heap size is 10485760 bytes (10 MB); simplrun010: Current maximum heap size is 10485760 bytes (10 MB).
use `+RTS -M<size>' to increase it. simplrun010: Use `+RTS -M<size>' to increase it.
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