mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 15:26:31 +00:00
Estimated hours taken: 45 Branches: main Some work on the intermodule analysis framework. The main changes are that modules and analysis results have statuses associated with them, which are saved in the `.analysis' files, and there is now code to handle intermodule dependency graphs (that record which modules are dependent on a particular analysis result). Automatic recompilation of modules that use out of date or invalid analysis results from other modules is not handled yet. analysis/README: analysis/analysis.m: analysis/analysis.file.m: Remove the `FuncInfo' type variable everywhere. This was originally designed to be used by analyses to store "extra" information that would be passed from an analysis implementation through the analysis framework, back to methods defined by the analysis implementation itself. The main problem was that `FuncInfo' made `Call' or `Answer' values hard to compare, as a `FuncInfo' value always had to be present for a comparison to be made (because the methods in the partial_order typeclass required FuncInfos). One example of when this is hard to satisfy is when we are ready to write everything out to disk at the end of all analyses. At this step there is much comparing of Call and Answer values, but this step is not invoked by any particular analysis pass. To compare values we would need to get the FuncInfos from somewhere, which means we would have to store FuncInfos in the analysis_info maps as well. And any time you have two FuncInfos, you need to choose one of the FuncInfos arbitrarily. Since FuncInfos would have to be read/written with every Call and Answer value, including IMDGs, I have changed it so that that any information which might be be stored in a `FuncInfo' should be stored in the corresponding `Call' value itself. Change the format of analysis result files to include an overall status for the module and a status for each analysis result. The statuses record whether the module or analysis result could be improved by further compilation, or if the module or analysis result is no longer valid. Add code to read and write intermodule dependency graphs (IMDGs). The IMDG file for module M records all the modules which depend on an analysis result for a procedure defined in M. Bump analysis file format version numbers as they are incompatible with earlier versions. compiler/mercury_compile.m: Make `mercury_compile_after_front_end' use state variables for copies of the HLDS and update it to match changes in the intermodule analysis framework. compiler/mmc_analysis.m: Add the trail usage analysis to the list of analyses to be used with the intermodule analysis framework. Update the entry for unused argument elimination. Add predicate `module_id_func_id'. compiler/add_pragma.m: compiler/hlds_module.m: compiler/trailing_analysis.m: Make the trail usage analysis pass able to make use of the intermodule analysis framework. Associate each `trailing_status' in the `trailing_info' map with an `analysis_status', i.e. whether it is optimal or not. compiler/unused_args.m: Update to match the removal of `FuncInfo' arguments and the addition of analysis statuses. Record the unused argument analysis result for a procedure even if all of the procedures arguments are used, so that callers of the procedure will know not to request more precise answers. Record the dependence of the current module on analysis results from other modules. compiler/goal_util.m: Add predicate `pred_proc_ids_from_goal/2'. compiler/make.m: compiler/make.dependencies.m: compiler/make.program_target.m: compiler/make.util.m: compiler/modules.m: scripts/Mmake.vars.in: Make `mmc --make' and `mmake' realclean `.analysis', `.imdg' and `.request' files of non-library modules. Files for imported library modules won't be deleted, but they probably shouldn't be generated in the first place. NEWS: library/list.m: Add a `list.map2_foldl2' predicate. compiler/Mmakefile: Add the `analysis' directory to the list of directories to be processed by mtags.
89 lines
3.0 KiB
Mathematica
89 lines
3.0 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2003-2006 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: mmc_analysis.m
|
|
% Main author: stayl
|
|
%
|
|
% Specify Mercury compiler analyses to be used with the
|
|
% inter-module analysis framework.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module transform_hlds__mmc_analysis.
|
|
|
|
:- interface.
|
|
|
|
:- import_module analysis.
|
|
:- import_module hlds.hlds_module.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module mdbcomp.prim_data.
|
|
:- import_module parse_tree.prog_data.
|
|
|
|
:- type mmc ---> mmc.
|
|
|
|
:- instance compiler(mmc).
|
|
|
|
:- func module_name_to_module_id(module_name) = module_id.
|
|
:- func module_id_to_module_name(module_id) = module_name.
|
|
|
|
:- func pred_or_func_name_arity_to_func_id(pred_or_func, string, arity,
|
|
proc_id) = func_id.
|
|
|
|
:- pred module_id_func_id(module_info::in, pred_proc_id::in,
|
|
module_id::out, func_id::out) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module parse_tree.modules.
|
|
:- import_module parse_tree.prog_out.
|
|
:- import_module parse_tree.prog_util.
|
|
:- import_module transform_hlds.trailing_analysis.
|
|
:- import_module transform_hlds.unused_args.
|
|
|
|
:- import_module bool.
|
|
:- import_module std_util.
|
|
:- import_module string.
|
|
|
|
:- instance compiler(mmc) where [
|
|
compiler_name(mmc) = "mmc",
|
|
|
|
analyses(mmc, "trail_usage") =
|
|
'new analysis_type'(
|
|
unit1 `with_type` unit(any_call),
|
|
unit1 `with_type` unit(trailing_analysis_answer)),
|
|
|
|
analyses(mmc, "unused_args") =
|
|
'new analysis_type'(
|
|
unit1 `with_type` unit(unused_args_call),
|
|
unit1 `with_type` unit(unused_args_answer)),
|
|
|
|
module_id_to_file_name(mmc, ModuleId, Ext, FileName) -->
|
|
module_name_to_file_name(module_id_to_module_name(ModuleId),
|
|
Ext, yes, FileName)
|
|
].
|
|
|
|
module_name_to_module_id(ModuleName) = ModuleId :-
|
|
sym_name_to_string(ModuleName, ModuleId).
|
|
|
|
module_id_to_module_name(ModuleId) = ModuleName :-
|
|
string_to_sym_name(ModuleId, ".", ModuleName).
|
|
|
|
pred_or_func_name_arity_to_func_id(PredOrFunc, Name, Arity, ProcId) = FuncId :-
|
|
FuncId0 = simple_call_id_to_string(PredOrFunc
|
|
- unqualified(Name)/Arity),
|
|
proc_id_to_int(ProcId, ProcInt),
|
|
FuncId = FuncId0 ++ "-" ++ int_to_string(ProcInt).
|
|
|
|
module_id_func_id(ModuleInfo, proc(PredId, ProcId), ModuleId, FuncId) :-
|
|
module_info_pred_info(ModuleInfo, PredId, PredInfo),
|
|
PredModule = pred_info_module(PredInfo),
|
|
PredName = pred_info_name(PredInfo),
|
|
PredOrFunc = pred_info_is_pred_or_func(PredInfo),
|
|
PredArity = pred_info_orig_arity(PredInfo),
|
|
ModuleId = module_name_to_module_id(PredModule),
|
|
FuncId = pred_or_func_name_arity_to_func_id(PredOrFunc,
|
|
PredName, PredArity, ProcId).
|