mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 05:12:33 +00:00
Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20 Branches: main Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled, the compiler will generate informational messages about if-then-elses that it thinks should be converted to switches for the sake of program reliability. Act on the output generated by this option. compiler/simplify.m: Implement the new option. Fix an old bug that could cause us to generate warnings about code that was OK in one duplicated copy but not in another (where a switch arm's code is duplicated due to the case being selected for more than one cons_id). compiler/options.m: Add the new option. Add a way to test for the bug fix in simplify. doc/user_guide.texi: Document the new option. NEWS: Mention the new option. library/*.m: mdbcomp/*.m: browser/*.m: compiler/*.m: deep_profiler/*.m: Convert if-then-elses to switches at most of the sites suggested by the new option. At the remaining sites, switching to switches would have nontrivial downsides. This typically happens with the switched-on type has many functors, and we treat one or two specially (e.g. cons/2 in the cons_id type). Perform misc cleanups in the vicinity of the if-then-else to switch conversions. In a few cases, improve the error messages generated. compiler/accumulator.m: compiler/hlds_goal.m: (Rename and) move insts for particular kinds of goal from accumulator.m to hlds_goal.m, to allow them to be used in other modules. Using these insts allowed us to eliminate some if-then-elses entirely. compiler/exprn_aux.m: Instead of fixing some if-then-elses, delete the predicates containing them, since they aren't used, and (as pointed out by the new option) would need considerable other fixing if they were ever needed again. compiler/lp_rational.m: Add prefixes to the names of the function symbols on some types, since without those prefixes, it was hard to figure out what type the switch corresponding to an old if-then-else was switching on. tests/invalid/reserve_tag.err_exp: Expect a new, improved error message.
This commit is contained in:
@@ -149,18 +149,24 @@ build_comments(S, comments(!.C), comments(!:C), !IO) :-
|
||||
line_type(Line) = LineType :-
|
||||
list.takewhile(char.is_whitespace, Line, _WhiteSpace, Rest),
|
||||
list.takewhile(is_not_comment_char, Rest, Decl, Comment),
|
||||
( Rest = [] ->
|
||||
(
|
||||
Rest = [],
|
||||
LineType = blank
|
||||
; Comment = [_ | _] ->
|
||||
(
|
||||
Decl = [],
|
||||
LineType = comment(string.from_char_list(Comment))
|
||||
;
|
||||
Decl = [_ | _],
|
||||
LineType = code_and_comment(string.from_char_list(Comment))
|
||||
)
|
||||
;
|
||||
LineType = code
|
||||
Rest = [_ | _],
|
||||
(
|
||||
Comment = [],
|
||||
LineType = code
|
||||
;
|
||||
Comment = [_ | _],
|
||||
(
|
||||
Decl = [],
|
||||
LineType = comment(string.from_char_list(Comment))
|
||||
;
|
||||
Decl = [_ | _],
|
||||
LineType = code_and_comment(string.from_char_list(Comment))
|
||||
)
|
||||
)
|
||||
).
|
||||
|
||||
:- pred is_not_comment_char(char::in) is semidet.
|
||||
|
||||
Reference in New Issue
Block a user