mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 06:14:59 +00:00
Estimated hours taken: 80 Branches: main The existing representation of goal_paths is suboptimal for several reasons. - Sometimes we need forward goal paths (e.g. to look up goals), and sometimes we need reverse goal paths (e.g. when computing goal paths in the first place). We had two types for them, but - their names, goal_path and goal_path_consable, were not expressive, and - we could store only one of them in goal_infos. - Testing whether goal A is a subgoal of goal B is quite error-prone using either form of goal paths. - Using a goal path as a key in a map, which several compiler passes want to do, requires lots of expensive comparisons. This diff replaces most uses of goal paths with goal ids. A goal id is an integer, so it can be used as a key in faster maps, or even in arrays. Every goal in the body of a procedure gets its id allocated in a depth first search. Since we process each goal before we dive into is descendants, the goal representing the whole body of a procedure always gets goal id 0. The depth first traversal also builds up a map (the containing goal map) that tells us the parent goal of ever subgoal, with the obvious exception of the root goal itself. From the containing goal map, one can compute both reverse and forward goal paths. It can also serve as the basis of an efficient test of whether the goal identified by goal id A is an ancestor of another goal identified by goal id B. We don't yet use this test, but I expect we will in the future. mdbcomp/program_representation.m: Add the goal_id type. Replace the existing goal_path and goal_path_consable types with two new types, forward_goal_path and reverse_goal_path. Since these now have wrappers around the list of goal path steps that identify each kind of goal path, it is now ok to expose their representations. This makes several compiler passes easier to code. Update the set of operations on goal paths to work on the new data structures. Add a couple of step types to represent lambdas and try goals. Their omission prior to this would have been a bug for constraint-based mode analysis, or any other compiler pass prior to the expansion out of lambda and try goals that wanted to use goal paths to identify subgoals. browser/declarative_tree.m: mdbcomp/rtti_access.m: mdbcomp/slice_and_dice.m: mdbcomp/trace_counts.m: slice/mcov.m: deep_profiler/*.m: Conform to the changes in goal path representation. compiler/hlds_goal: Replace the goal_path field with a goal_id field in the goal_info, indicating that from now on, this should be used to identify goals. Keep a reverse_goal_path field in the goal_info for use by RBMM and CTGC. Those analyses were too hard to convert to using goal_ids, especially since RBMM uses goal_paths to identify goals in multi-pass algorithms that should be one-pass and should not NEED to identify any goals for later processing. compiler/goal_path: Add predicates to fill in goal_ids, and update the predicates filling in the now deprecated reverse goal path fields. Add the operations needed by the rest of the compiler on goal ids and containing goal maps. Remove the option to set goal paths using "mode equivalent steps". Constraint based mode analysis now uses goal ids, and can now do its own equivalent optimization quite simply. Move the goal_path module from the check_hlds package to the hlds package. compiler/*.m: Conform to the changes in goal path representation. Most modules now use goal_ids to identify goals, and use a containing goal map to convert the goal ids to goal paths when needed. However, the ctgc and rbmm modules still use (reverse) goal paths. library/digraph.m: library/group.m: library/injection.m: library/pprint.m: library/pretty_printer.m: library/term_to_xml.m: Minor style improvements.
103 lines
3.1 KiB
Mathematica
103 lines
3.1 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2002-2006, 2009-2010 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.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% check_hlds: semantic analysis and error checking (the "front end" HLDS pass).
|
|
|
|
:- module check_hlds.
|
|
:- interface.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Type checking
|
|
%:- module type_analysis.
|
|
:- include_module check_typeclass.
|
|
:- include_module post_typecheck.
|
|
:- include_module purity.
|
|
:- include_module type_constraints.
|
|
:- include_module type_util.
|
|
:- include_module typecheck.
|
|
:- include_module typecheck_errors.
|
|
:- include_module typecheck_info.
|
|
:- include_module typeclasses.
|
|
%:- end_module type_analysis.
|
|
|
|
% Implementation-defined literals
|
|
:- include_module implementation_defined_literals.
|
|
|
|
% Polymorphism transformation.
|
|
:- include_module clause_to_proc.
|
|
:- include_module polymorphism.
|
|
|
|
% Mode analysis
|
|
%:- module mode_analysis.
|
|
:- include_module delay_info.
|
|
:- include_module delay_partial_inst.
|
|
:- include_module inst_match.
|
|
:- include_module inst_util.
|
|
:- include_module mode_constraint_robdd.
|
|
:- include_module mode_constraints.
|
|
:- include_module mode_debug.
|
|
:- include_module mode_errors.
|
|
:- include_module mode_info.
|
|
:- include_module mode_ordering.
|
|
:- include_module mode_util.
|
|
:- include_module modecheck_goal.
|
|
:- include_module modecheck_conj.
|
|
:- include_module modecheck_call.
|
|
:- include_module modecheck_unify.
|
|
:- include_module modecheck_util.
|
|
:- include_module modes.
|
|
:- include_module unify_proc.
|
|
:- include_module unique_modes.
|
|
|
|
% XXX This doesn't belong here but we don't know where it's home is at
|
|
% the moment.
|
|
%
|
|
:- include_module abstract_mode_constraints.
|
|
:- include_module build_mode_constraints.
|
|
:- include_module mcsolver.
|
|
:- include_module ordering_mode_constraints.
|
|
:- include_module prop_mode_constraints.
|
|
|
|
%:- end_module mode_analysis.
|
|
|
|
% Indexing and determinism analysis
|
|
:- include_module cse_detection.
|
|
:- include_module det_analysis.
|
|
:- include_module det_report.
|
|
:- include_module det_util.
|
|
:- include_module switch_detection.
|
|
|
|
% Stratification.
|
|
:- include_module stratify.
|
|
|
|
% Expand try goals
|
|
:- include_module try_expand.
|
|
|
|
% Warnings about simple code
|
|
:- include_module common.
|
|
:- include_module format_call.
|
|
:- include_module simplify.
|
|
|
|
% Warnings about insts with no matching types
|
|
:- include_module inst_check.
|
|
|
|
% Warnings about unused imports
|
|
:- include_module unused_imports.
|
|
|
|
% Output XML representation useful for documentation of module
|
|
:- include_module xml_documentation.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- end_module check_hlds.
|
|
|
|
%-----------------------------------------------------------------------------%
|