Permalink
Browse files

Implement --no-max-error-line-width, as requested in Mantis #308.

compiler/options.m:
   Change the type of the max_error_line_width option from int to maybe_int.
   Change its documentation accordingly.

doc/user_guide.texi:
   Change the option's documentation here as well.

compiler/globals.m:
   Since this is the compiler's first maybe_int option, add a predicate
   to look up such options.

compiler/error_util.m:
   If the user specifies --no-max-error-line-width, do not try to pack the
   words of an error paragraph into lines; just return all the words on one
   line.

   Factor out some common code in the group_words predicate, and give that
   predicate a more accurate name.

tests/invalid/any_to_ground_in_ite_cond_nomax.{m,err_exp}:
   Add this copy of the existing any_to_ground_in_ite_cond test case.

tests/invalid/Mercury.options::
   Specify --no-max-error-line-width for the new test case.

tests/invalid/Mmakefile:
   Enable the new test.
  • Loading branch information...
1 parent 70526c5 commit 29eeb366286c841393d3f2e2d9953f501541820d @zsomogyi zsomogyi committed Feb 21, 2014
View
@@ -804,8 +804,9 @@ pred print_anything(T::in, io::di, io::uo) is det
!First, !PrintedSome, !IO) :-
(
Component = always(ComponentPieces),
- globals.lookup_int_option(Globals, max_error_line_width, MaxWidth),
- do_write_error_pieces(!.First, MaybeContext, Indent, MaxWidth,
+ globals.lookup_maybe_int_option(Globals, max_error_line_width,
+ MaybeMaxWidth),
+ do_write_error_pieces(!.First, MaybeContext, Indent, MaybeMaxWidth,
ComponentPieces, !IO),
!:First = do_not_treat_as_first,
!:PrintedSome = printed_something
@@ -823,9 +824,9 @@ pred print_anything(T::in, io::di, io::uo) is det
globals.lookup_bool_option(Globals, verbose_errors, VerboseErrors),
(
VerboseErrors = yes,
- globals.lookup_int_option(Globals, max_error_line_width,
- MaxWidth),
- do_write_error_pieces(!.First, MaybeContext, Indent, MaxWidth,
+ globals.lookup_maybe_int_option(Globals, max_error_line_width,
+ MaybeMaxWidth),
+ do_write_error_pieces(!.First, MaybeContext, Indent, MaybeMaxWidth,
ComponentPieces, !IO),
!:First = do_not_treat_as_first,
!:PrintedSome = printed_something
@@ -836,14 +837,15 @@ pred print_anything(T::in, io::di, io::uo) is det
;
Component = verbose_and_nonverbose(VerbosePieces, NonVerbosePieces),
globals.lookup_bool_option(Globals, verbose_errors, VerboseErrors),
- globals.lookup_int_option(Globals, max_error_line_width, MaxWidth),
+ globals.lookup_maybe_int_option(Globals, max_error_line_width,
+ MaybeMaxWidth),
(
VerboseErrors = yes,
- do_write_error_pieces(!.First, MaybeContext, Indent, MaxWidth,
+ do_write_error_pieces(!.First, MaybeContext, Indent, MaybeMaxWidth,
VerbosePieces, !IO)
;
VerboseErrors = no,
- do_write_error_pieces(!.First, MaybeContext, Indent, MaxWidth,
+ do_write_error_pieces(!.First, MaybeContext, Indent, MaybeMaxWidth,
NonVerbosePieces, !IO),
globals.io_set_extra_error_info(yes, !IO)
),
@@ -916,30 +918,35 @@ pred print_anything(T::in, io::di, io::uo) is det
is_or_are([_, _ | _]) = "are".
write_error_pieces_plain(Globals, Components, !IO) :-
- globals.lookup_int_option(Globals, max_error_line_width, MaxWidth),
- do_write_error_pieces(treat_as_first, no, 0, MaxWidth, Components, !IO).
+ globals.lookup_maybe_int_option(Globals, max_error_line_width,
+ MaybeMaxWidth),
+ do_write_error_pieces(treat_as_first, no, 0, MaybeMaxWidth,
+ Components, !IO).
write_error_plain_with_progname(ProgName, Msg, !IO) :-
MaxWidth = 79,
Components = [fixed(ProgName ++ ":"), words(Msg)],
- do_write_error_pieces(treat_as_first, no, 0, MaxWidth, Components, !IO).
+ do_write_error_pieces(treat_as_first, no, 0, yes(MaxWidth),
+ Components, !IO).
write_error_pieces(Globals, Context, Indent, Components, !IO) :-
- globals.lookup_int_option(Globals, max_error_line_width, MaxWidth),
- do_write_error_pieces(treat_as_first, yes(Context), Indent, MaxWidth,
+ globals.lookup_maybe_int_option(Globals, max_error_line_width,
+ MaybeMaxWidth),
+ do_write_error_pieces(treat_as_first, yes(Context), Indent, MaybeMaxWidth,
Components, !IO).
write_error_pieces_maybe_with_context(Globals, MaybeContext, Indent,
Components, !IO) :-
- globals.lookup_int_option(Globals, max_error_line_width, MaxWidth),
- do_write_error_pieces(treat_as_first, MaybeContext, Indent, MaxWidth,
+ globals.lookup_maybe_int_option(Globals, max_error_line_width,
+ MaybeMaxWidth),
+ do_write_error_pieces(treat_as_first, MaybeContext, Indent, MaybeMaxWidth,
Components, !IO).
:- pred do_write_error_pieces(maybe_treat_as_first::in,
- maybe(prog_context)::in, int::in, int::in, list(format_component)::in,
- io::di, io::uo) is det.
+ maybe(prog_context)::in, int::in, maybe(int)::in,
+ list(format_component)::in, io::di, io::uo) is det.
-do_write_error_pieces(TreatAsFirst, MaybeContext, FixedIndent, MaxWidth,
+do_write_error_pieces(TreatAsFirst, MaybeContext, FixedIndent, MaybeMaxWidth,
Components, !IO) :-
% The fixed characters at the start of the line are:
% filename
@@ -967,8 +974,16 @@ pred print_anything(T::in, io::di, io::uo) is det
),
convert_components_to_paragraphs(Components, Paragraphs),
FirstIndent = (TreatAsFirst = treat_as_first -> 0 ; 1),
- Remain = MaxWidth - (ContextLength + FixedIndent),
- group_words(TreatAsFirst, FirstIndent, Paragraphs, Remain, Lines),
+ (
+ MaybeMaxWidth = yes(MaxWidth),
+ Remain = MaxWidth - (ContextLength + FixedIndent),
+ MaybeRemain = yes(Remain)
+ ;
+ MaybeMaxWidth = no,
+ MaybeRemain = no
+ ),
+ divide_paragraphs_into_lines(TreatAsFirst, FirstIndent, Paragraphs,
+ MaybeRemain, Lines),
write_lines(Lines, MaybeContext, FixedIndent, !IO).
:- func indent_increment = int.
@@ -1383,15 +1398,21 @@ pred print_anything(T::in, io::di, io::uo) is det
list(string) % The words on the line.
).
- % Groups the given words into lines. The first line can have up to Max
- % characters on it; the later lines (if any) up to Max-2 characters.
- % The given list of paragraphs must be nonempty, since we always return
+ % Groups the words in the given paragraphs into lines. The first line
+ % can have up to Max characters on it; the later lines (if any) up
+ % to Max-2 characters.
+ %
+ % If MaybeMax is `no', handle it as if Max were infinity (i.e. put
+ % everything in each paragraph on one line).
+ %
+ % The given list of paragraphs should be nonempty, since we always return
% at least one line.
%
-:- pred group_words(maybe_treat_as_first::in, int::in, list(paragraph)::in,
- int::in, list(error_line)::out) is det.
+:- pred divide_paragraphs_into_lines(maybe_treat_as_first::in, int::in,
+ list(paragraph)::in, maybe(int)::in, list(error_line)::out) is det.
-group_words(TreatAsFirst, CurIndent, Paras, Max, Lines) :-
+divide_paragraphs_into_lines(TreatAsFirst, CurIndent, Paras, MaybeMax,
+ Lines) :-
(
Paras = [],
Lines = []
@@ -1408,25 +1429,31 @@ pred print_anything(T::in, io::di, io::uo) is det
NextIndent = RestIndent + FirstIndentDelta,
BlankLine = error_line(CurIndent, []),
- list.duplicate(NumBlankLines, BlankLine, BlankLines),
+ list.duplicate(NumBlankLines, BlankLine, FirstParaBlankLines),
(
FirstParaWords = [],
- group_words(TreatAsFirst, NextIndent, LaterParas, Max, RestLines),
- Lines = BlankLines ++ RestLines
+ NextTreatAsFirst = TreatAsFirst,
+ FirstParaLines = []
;
FirstParaWords = [FirstWord | LaterWords],
- get_line_of_words(FirstWord, LaterWords, CurIndent, Max,
- LineWords, RestWords),
- CurLine = error_line(CurIndent, LineWords),
-
- group_nonfirst_line_words(RestWords, RestIndent, Max,
- ParaRestLines),
- ParaLines = [CurLine | ParaRestLines],
-
- group_words(do_not_treat_as_first, NextIndent, LaterParas,
- Max, RestLines),
- Lines = ParaLines ++ BlankLines ++ RestLines
- )
+ NextTreatAsFirst = do_not_treat_as_first,
+ (
+ MaybeMax = yes(Max),
+ get_line_of_words(FirstWord, LaterWords, CurIndent, Max,
+ LineWords, RestWords),
+ CurLine = error_line(CurIndent, LineWords),
+
+ group_nonfirst_line_words(RestWords, RestIndent, Max,
+ FirstParaRestLines),
+ FirstParaLines = [CurLine | FirstParaRestLines]
+ ;
+ MaybeMax = no,
+ FirstParaLines = [error_line(CurIndent, FirstParaWords)]
+ )
+ ),
+ divide_paragraphs_into_lines(NextTreatAsFirst, NextIndent, LaterParas,
+ MaybeMax, LaterParaLines),
+ Lines = FirstParaLines ++ FirstParaBlankLines ++ LaterParaLines
).
:- pred group_nonfirst_line_words(list(string)::in, int::in, int::in,
View
@@ -300,6 +300,8 @@
:- mode lookup_bool_option(in, in, out) is det.
:- mode lookup_bool_option(in, in, in) is semidet. % implied
:- pred lookup_int_option(globals::in, option::in, int::out) is det.
+:- pred lookup_maybe_int_option(globals::in, option::in, maybe(int)::out)
+ is det.
:- pred lookup_string_option(globals::in, option::in, string::out) is det.
:- pred lookup_maybe_string_option(globals::in, option::in, maybe(string)::out)
is det.
@@ -727,6 +729,14 @@
unexpected($module, $pred, "invalid int option")
).
+lookup_maybe_int_option(Globals, Option, Value) :-
+ lookup_option(Globals, Option, OptionData),
+ ( OptionData = maybe_int(MaybeInt) ->
+ Value = MaybeInt
+ ;
+ unexpected($module, $pred, "invalid maybe_int option")
+ ).
+
lookup_maybe_string_option(Globals, Option, Value) :-
lookup_option(Globals, Option, OptionData),
( OptionData = maybe_string(MaybeString) ->
View
@@ -1242,7 +1242,7 @@
line_numbers - bool(yes),
auto_comments - bool(no),
frameopt_comments - bool(no),
- max_error_line_width - int(79),
+ max_error_line_width - maybe_int(yes(79)),
show_dependency_graph - bool(no),
imports_graph - bool(no),
dump_trace_counts - accumulating([]),
@@ -4005,6 +4005,7 @@
"--max-error-line-width <n>",
"\tSet the maximum width of an error message line to <n> characters",
"\t(unless a long single word forces the line over this limit).",
+ "\tSpecifying --no-max-error-line-width removes the limit.",
"--show-dependency-graph",
"\tWrite out the dependency graph to `<module>.dependency_graph'.",
"--imports-graph",
View
@@ -7206,6 +7206,7 @@ or in Mercury (with @samp{--convert-to-mercury}).
@findex --max-error-line-width
Set the maximum width of an error message line to @var{N} characters
(unless a long single word forces the line over this limit).
+Specifying --no-max-error-line-width removes the limit.
@sp 1
@item --show-dependency-graph
@@ -12,6 +12,7 @@ MCFLAGS-assert_in_interface = --no-intermodule-optimization \
--verbose-error-messages
MCFLAGS-actual_expected = --no-intermodule-optimization
+MCFLAGS-any_to_ground_in_ite_cond_nomax = --no-max-error-line-width
# Mantis bug 238 shows up in bug238.m only with --constraint-propagation.
MCFLAGS-bug238 = --constraint-propagation
MCFLAGS-children = --no-intermodule-optimization
View
@@ -37,6 +37,7 @@ SINGLEMODULE= \
any_passed_as_ground \
any_should_not_match_bound \
any_to_ground_in_ite_cond \
+ any_to_ground_in_ite_cond_nomax \
anys_in_negated_contexts \
assert_in_interface \
bad_finalise_decl \
@@ -0,0 +1,6 @@
+any_to_ground_in_ite_cond_nomax.m:036: In clause for `main(di, uo)':
+any_to_ground_in_ite_cond_nomax.m:036: in argument 1 of call to predicate `any_to_ground_in_ite_cond_nomax.p'/1:
+any_to_ground_in_ite_cond_nomax.m:036: scope error: attempt to bind a non-local variable inside the condition of an if-then-else.
+any_to_ground_in_ite_cond_nomax.m:036: Variable `X' has instantiatedness `any',
+any_to_ground_in_ite_cond_nomax.m:036: expected instantiatedness was `ground'.
+For more information, recompile with `-E'.
@@ -0,0 +1,52 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%
+% This version of the any_to_ground_in_ite_cond.m test case contains identical
+% code, but is compiled with --no-max-error-line-width to test that option.
+%
+%-----------------------------------------------------------------------------%
+
+:- module any_to_ground_in_ite_cond_nomax.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io :: di, io :: uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int, list, std_util.
+
+:- solver type st where representation is int.
+
+%-----------------------------------------------------------------------------%
+
+% We shouldn't be able to ground a solver variable in the
+% condition of an if-then-else.
+%
+main(!IO) :-
+ i(X),
+ promise_pure (
+ if p(X) then
+ io.write_string("aye\n", !IO)
+ else
+ io.write_string("nay\n", !IO)
+ ).
+
+:- pred i(st::oa) is det.
+
+i(X) :- promise_pure(impure X = 'representation to any st/0'(42)).
+
+:- pred p(st::(any >> ground)) is semidet.
+
+:- pragma foreign_proc("C", p(_X::(any >> ground)), [promise_pure],
+ "SUCCESS_INDICATOR = MR_TRUE;").
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

0 comments on commit 29eeb36

Please sign in to comment.