mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 21:35:49 +00:00
Estimated hours taken: 12 Branches: main Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail. The problem was not in lco.m, but in follow_code.m. In some cases, (specifically, the LCMC version of insert_2 in sparse_bitset.m), follow_code.m moved an impure goal (store_at_ref) into the arms of an if-then-else without marking those arms, or the if-then-else, as impure. The next pass, simplify, then deleted the entire if-then-else, since it had no outputs. (The store_at_ref that originally appeared after the if-then-else was the only consumer of its only output.) The fix is to get follow_code.m to make branched control structures such as if-then-elses, as well as their arms, semipure or impure if a goal being moved into them is semipure or impure, or if they came from an semipure or impure conjunction. Improve the optimization of the LCMC version of sparse_bitset.insert_2, which had a foreign_proc invocation of bits_per_int in it: replace such invocations with a unification of the bits_per_int constant if not cross compiling. Add a new option, --optimize-constructor-last-call-null. When set, LCMC will assign NULLs to the fields not yet filled in, to avoid any junk happens to be there from being followed by the garbage collector's mark phase. This diff also makes several other changes that helped me to track down the bug above. compiler/follow_code.m: Make the fix described above. Delete all the provisions for --prev-code; it won't be implemented. Don't export a predicate that is not now used anywhere else. compiler/simplify.m: Make the optimization described above. compiler/lco.m: Make sure that the LCMC specialized procedure is a predicate, not a function: having a function with the mode LCMC_insert_2(in, in) = in looks wrong. To avoid name collisions when a function and a predicate with the same name and arity have LCMC applied to them, include the predicate vs function status of the original procedure included in the name of the new procedure. Update the sym_name of calls to LCMC variants, not just the pred_id, because without that, the HLDS dump looks misleading. compiler/pred_table.m: Don't have optimizations like LCMC insert new predicates at the front of the list of predicates. Maintain the list of predicates in the module as a two part list, to allow efficient addition of new pred_ids at the (logical) end without using O(N^2) algorithms. Having predicates in chronological order makes it easier to look at HLDS dumps and .c files. compiler/hlds_module.m: Make module_info_predids return a module_info that is physically updated though logically unchanged. compiler/options.m: Add --optimize-constructor-last-call-null. Make the options --dump-hlds-pred-id, --debug-opt-pred-id and --debug-opt-pred-name into accumulating options, to allow the user to specify more than one predicate to be dumped (e.g. insert_2 and its LCMC variant). Delete --prev-code. doc/user_guide.texi: Document the changes in options.m. compiler/code_info.m: Record the value of --optimize-constructor-last-call-null in the code_info, to avoid lookup at every cell construction. compiler/unify_gen.m: compiler/var_locn.m: When deciding whether a cell can be static or not, make sure that we never make static a cell that has some fields initialized with dummy zeros, to be filled in for real later. compiler/hlds_out.m: For goals that are semipure or impure, note this fact. This info was lost when I changed the representation of impurity from markers to a field. mdbcomp/prim_data.m: Rename some ambiguous function symbols. compiler/intermod.m: compiler/trans_opt.m: Rename the main predicates (and some function symbols) of these modules to avoid ambiguity and to make them more expressive. compiler/llds.m: Don't print line numbers for foreign_code fragments if the user has specified --no-line-numbers. compiler/make.dependencies.m: compiler/mercury_to_mercury.m: compiler/recompilation.usage.m: Don't use io.write to write out information to files we may need to parse again, because this is vulnerable to changes to the names of function symbols (e.g. the one to mdbcomp/prim_data.m). The compiler still contains some uses of io.write, but they are for debugging. I added an item to the todo list of the one exception, ilasm.m. compiler/recompilation.m: Rename a misleading function symbol name. compiler/parse_tree.m: Don't import recompilation.m here. It is not needed (all the components of parse_tree that need recompilation.m already import it themselves), and deleting the import avoids recompiling almost everything when recompilation.m changes. compiler/*.m: Conform to the changes above. compiler/*.m: browser/*.m: slice/*.m: Conform to the change to mdbcomp. library/sparse_bitset.m: Use some better variable names.
243 lines
9.3 KiB
Mathematica
243 lines
9.3 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-2007 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: hlds_error_util.m.
|
|
% Main author: zs.
|
|
%
|
|
% This module contains code that can be helpful in the formatting of
|
|
% error messages. It builds upon parse_tree.error_util, and extends it
|
|
% with predicates that access HLDS data structures.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module hlds.hlds_error_util.
|
|
:- interface.
|
|
|
|
:- import_module hlds.hlds_module.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module parse_tree.prog_data.
|
|
:- import_module parse_tree.error_util.
|
|
|
|
:- import_module assoc_list.
|
|
:- import_module list.
|
|
:- import_module pair.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% Predicates to convert predicate and procedure names to strings.
|
|
%
|
|
|
|
:- type should_module_qualify
|
|
---> should_module_qualify
|
|
; should_not_module_qualify.
|
|
|
|
:- func describe_one_pred_name(module_info, should_module_qualify, pred_id)
|
|
= list(format_component).
|
|
|
|
:- func describe_one_pred_info_name(should_module_qualify, pred_info)
|
|
= list(format_component).
|
|
|
|
:- func describe_one_pred_name_mode(module_info, should_module_qualify,
|
|
pred_id, inst_varset, list(mer_mode)) = list(format_component).
|
|
|
|
:- func describe_several_pred_names(module_info, should_module_qualify,
|
|
list(pred_id)) = list(format_component).
|
|
|
|
:- func describe_one_proc_name(module_info, should_module_qualify,
|
|
pred_proc_id) = list(format_component).
|
|
|
|
:- func describe_one_proc_name_mode(module_info, should_module_qualify,
|
|
pred_proc_id) = list(format_component).
|
|
|
|
:- func describe_several_proc_names(module_info, should_module_qualify,
|
|
list(pred_proc_id)) = list(format_component).
|
|
|
|
:- func describe_one_call_site(module_info, should_module_qualify,
|
|
pair(pred_proc_id, prog_context)) = list(format_component).
|
|
|
|
:- func describe_several_call_sites(module_info, should_module_qualify,
|
|
assoc_list(pred_proc_id, prog_context)) = list(format_component).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.special_pred.
|
|
:- import_module mdbcomp.prim_data.
|
|
:- import_module libs.compiler_util.
|
|
:- import_module parse_tree.mercury_to_mercury.
|
|
:- import_module parse_tree.prog_mode.
|
|
:- import_module parse_tree.prog_out.
|
|
:- import_module parse_tree.prog_util.
|
|
|
|
:- import_module int.
|
|
:- import_module string.
|
|
:- import_module list.
|
|
:- import_module term.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% NOTE: the code of this predicate duplicates the functionality of
|
|
% hlds_out.write_pred_id. Changes here should be made there as well.
|
|
%
|
|
describe_one_pred_name(Module, ShouldModuleQualify, PredId) = Pieces :-
|
|
module_info_pred_info(Module, PredId, PredInfo),
|
|
Pieces = describe_one_pred_info_name(ShouldModuleQualify, PredInfo).
|
|
|
|
describe_one_pred_info_name(ShouldModuleQualify, PredInfo) = Pieces :-
|
|
PredName = pred_info_name(PredInfo),
|
|
ModuleName = pred_info_module(PredInfo),
|
|
Arity = pred_info_orig_arity(PredInfo),
|
|
PredOrFunc = pred_info_is_pred_or_func(PredInfo),
|
|
adjust_func_arity(PredOrFunc, OrigArity, Arity),
|
|
pred_info_get_markers(PredInfo, Markers),
|
|
pred_info_get_origin(PredInfo, Origin),
|
|
( Origin = origin_special_pred(SpecialId - TypeCtor) ->
|
|
special_pred_description(SpecialId, Descr),
|
|
TypeCtor = type_ctor(TypeSymName0, TypeArity),
|
|
(
|
|
ShouldModuleQualify = should_module_qualify,
|
|
TypeSymName = TypeSymName0
|
|
;
|
|
ShouldModuleQualify = should_not_module_qualify,
|
|
TypeSymName = unqualified(unqualify_name(TypeSymName0))
|
|
),
|
|
( TypeArity = 0 ->
|
|
Pieces = [words(Descr), words("for type"),
|
|
sym_name(TypeSymName)]
|
|
;
|
|
Pieces = [words(Descr), words("for type constructor"),
|
|
sym_name(TypeSymName)]
|
|
)
|
|
; check_marker(Markers, marker_class_instance_method) ->
|
|
Pieces = [words("type class method implementation")]
|
|
; pred_info_get_goal_type(PredInfo, goal_type_promise(PromiseType)) ->
|
|
Pieces = [words("`" ++ promise_to_string(PromiseType) ++ "'"),
|
|
words("declaration")]
|
|
;
|
|
( check_marker(Markers, marker_class_method) ->
|
|
Prefix = [words("type class"), p_or_f(PredOrFunc), words("method")]
|
|
;
|
|
Prefix = [p_or_f(PredOrFunc)]
|
|
),
|
|
(
|
|
ShouldModuleQualify = should_module_qualify,
|
|
PredSymName = qualified(ModuleName, PredName)
|
|
;
|
|
ShouldModuleQualify = should_not_module_qualify,
|
|
PredSymName = unqualified(PredName)
|
|
),
|
|
Pieces = Prefix ++ [sym_name_and_arity(PredSymName / OrigArity)]
|
|
).
|
|
|
|
describe_one_pred_name_mode(Module, ShouldModuleQualify, PredId, InstVarSet,
|
|
ArgModes0) = Pieces :-
|
|
module_info_pred_info(Module, PredId, PredInfo),
|
|
ModuleName = pred_info_module(PredInfo),
|
|
PredName = pred_info_name(PredInfo),
|
|
Arity = pred_info_orig_arity(PredInfo),
|
|
PredOrFunc = pred_info_is_pred_or_func(PredInfo),
|
|
list.length(ArgModes0, NumArgModes),
|
|
% We need to strip off the extra type_info arguments inserted at the
|
|
% front by polymorphism.m - we only want the last `Arity' of them.
|
|
( list.drop(NumArgModes - Arity, ArgModes0, ArgModes) ->
|
|
strip_builtin_qualifiers_from_mode_list(ArgModes, StrippedArgModes)
|
|
;
|
|
unexpected(this_file, "describe_one_pred_name_mode: bad argument list")
|
|
),
|
|
(
|
|
PredOrFunc = pf_predicate,
|
|
ArgModesPart = arg_modes_to_string(InstVarSet, StrippedArgModes)
|
|
;
|
|
PredOrFunc = pf_function,
|
|
pred_args_to_func_args(StrippedArgModes, FuncArgModes, FuncRetMode),
|
|
ArgModesPart = arg_modes_to_string(InstVarSet, FuncArgModes)
|
|
++ " = " ++ mercury_mode_to_string(FuncRetMode, InstVarSet)
|
|
),
|
|
string.append_list([
|
|
"`",
|
|
module_qualification(ModuleName, ShouldModuleQualify),
|
|
PredName,
|
|
"'",
|
|
ArgModesPart], Descr),
|
|
Pieces = [words(Descr)].
|
|
|
|
describe_several_pred_names(Module, ShouldModuleQualify, PredIds) = Pieces :-
|
|
PiecesList = list.map(describe_one_pred_name(Module, ShouldModuleQualify),
|
|
PredIds),
|
|
Pieces = component_lists_to_pieces(PiecesList).
|
|
|
|
describe_one_proc_name(Module, ShouldModuleQualify, proc(PredId, ProcId))
|
|
= Pieces :-
|
|
PredPieces = describe_one_pred_name(Module, ShouldModuleQualify, PredId),
|
|
proc_id_to_int(ProcId, ProcIdInt),
|
|
string.int_to_string(ProcIdInt, ProcIdStr),
|
|
Pieces = PredPieces ++ [words("mode"), words(ProcIdStr)].
|
|
|
|
describe_one_proc_name_mode(Module, ShouldModuleQualify, proc(PredId, ProcId))
|
|
= Pieces :-
|
|
module_info_pred_proc_info(Module, PredId, ProcId, _, ProcInfo),
|
|
proc_info_get_argmodes(ProcInfo, ArgModes),
|
|
proc_info_get_inst_varset(ProcInfo, InstVarSet),
|
|
Pieces = describe_one_pred_name_mode(Module, ShouldModuleQualify,
|
|
PredId, InstVarSet, ArgModes).
|
|
|
|
describe_several_proc_names(Module, ShouldModuleQualify, PPIds) = Pieces :-
|
|
PiecesList = list.map(describe_one_proc_name(Module, ShouldModuleQualify),
|
|
PPIds),
|
|
Pieces = component_lists_to_pieces(PiecesList).
|
|
|
|
describe_one_call_site(Module, ShouldModuleQualify, PPId - Context) = Pieces :-
|
|
ProcNamePieces = describe_one_proc_name(Module, ShouldModuleQualify,
|
|
PPId),
|
|
term.context_file(Context, FileName),
|
|
term.context_line(Context, LineNumber),
|
|
string.int_to_string(LineNumber, LineNumberStr),
|
|
Pieces = ProcNamePieces ++
|
|
[words("at"), fixed(FileName ++ ":" ++ LineNumberStr)].
|
|
|
|
describe_several_call_sites(Module, ShouldModuleQualify, Sites) = Pieces :-
|
|
PiecesList = list.map(describe_one_call_site(Module, ShouldModuleQualify),
|
|
Sites),
|
|
Pieces = component_lists_to_pieces(PiecesList).
|
|
|
|
:- func module_qualification(module_name, should_module_qualify) = string.
|
|
|
|
module_qualification(ModuleName, ShouldModuleQualify) = ModuleQualification :-
|
|
(
|
|
ShouldModuleQualify = should_module_qualify,
|
|
ModuleQualification = sym_name_to_string(ModuleName) ++ "."
|
|
;
|
|
ShouldModuleQualify = should_not_module_qualify,
|
|
ModuleQualification = ""
|
|
).
|
|
|
|
:- func arg_modes_to_string(inst_varset, list(mer_mode)) = string.
|
|
|
|
arg_modes_to_string(InstVarSet, ArgModes) = Str :-
|
|
(
|
|
ArgModes = [],
|
|
Str = ""
|
|
;
|
|
ArgModes = [_ | _],
|
|
ArgsStr = mercury_mode_list_to_string(ArgModes, InstVarSet),
|
|
Str = "(" ++ ArgsStr ++ ")"
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- func this_file = string.
|
|
|
|
this_file = "hlds_error_util.m".
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module hlds_error_util.
|
|
%-----------------------------------------------------------------------------%
|