mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 01:13:30 +00:00
Rename some functions to avoid ambiguity.
compiler/lp_rational.m:
compiler/polyhedron.m:
Rename a function in each module.
compiler/term_constr_fixpoint.m:
compiler/term_constr_pass2.m:
Conform to the renames.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
% vim: ft=mercury ts=4 sw=4 et
|
||||
%---------------------------------------------------------------------------%
|
||||
% Copyright (C) 1997-2002, 2005-2007, 2009-2012 The University of Melbourne.
|
||||
% Copyright (C) 2015-2021, 2023-2024 The Mercury team.
|
||||
% Copyright (C) 2015-2021, 2023-2025 The Mercury team.
|
||||
% This file may only be copied under the terms of the GNU General
|
||||
% Public License - see the file COPYING in the Mercury distribution.
|
||||
%---------------------------------------------------------------------------%
|
||||
@@ -151,18 +151,22 @@
|
||||
%
|
||||
:- func simplify_constraints(lp_constraint_conj) = lp_constraint_conj.
|
||||
|
||||
% substitute_vars(VarsA, VarsB, Constraints0) = Constraints:
|
||||
% substitute_vars(RenameMap, Constraints0) = Constraints:
|
||||
% substitute_corresponding_vars(VarsA, VarsB, Constraints0) = Constraints:
|
||||
%
|
||||
% Perform variable substitution on the given system of constraints
|
||||
% based upon the mapping that is implicit between the corresponding
|
||||
% elements of the variable lists `VarsA' and `VarsB'.
|
||||
%
|
||||
% based upon either the explicitly-given RenameMap, or the mapping
|
||||
% that is implicit between the corresponding elements of VarsA and VarsB.
|
||||
% If length(VarsA) \= length(VarsB), then throw an exception.
|
||||
%
|
||||
:- func substitute_vars(list(lp_var), list(lp_var), lp_constraint_conj) =
|
||||
lp_constraint_conj.
|
||||
% XXX As of 2025 aug 10, substitute_corresponding_vars is unused,
|
||||
% except by polyhedron.substitute_corresponding_vars, which is
|
||||
% itself unused.
|
||||
%
|
||||
:- func substitute_vars(map(lp_var, lp_var), lp_constraint_conj) =
|
||||
lp_constraint_conj.
|
||||
:- func substitute_corresponding_vars(list(lp_var), list(lp_var),
|
||||
lp_constraint_conj) = lp_constraint_conj.
|
||||
|
||||
% Make the values of all the variables in the set zero.
|
||||
%
|
||||
@@ -733,28 +737,32 @@ is_stronger(eq(Terms, ConstA), lte(negate_lp_terms(Terms), ConstB)) :-
|
||||
is_stronger(lte(Terms, ConstA), lte(Terms, ConstB)) :-
|
||||
ConstB =< zero, ConstA =< ConstB.
|
||||
|
||||
substitute_vars(Old, New, Constraints0) = Constraints :-
|
||||
SubstMap = map.from_corresponding_lists(Old, New),
|
||||
Constraints = list.map(substitute_vars_2(SubstMap), Constraints0).
|
||||
substitute_vars(SubstMap, Constraints0) = Constraints :-
|
||||
Constraints = list.map(substitute_vars_2(SubstMap), Constraints0).
|
||||
substitute_vars(RenameMap, Constraints0) = Constraints :-
|
||||
Constraints = list.map(substitute_vars_in_constraint(RenameMap),
|
||||
Constraints0).
|
||||
|
||||
:- func substitute_vars_2(map(lp_var, lp_var), lp_constraint) = lp_constraint.
|
||||
substitute_corresponding_vars(Old, New, Constraints0) = Constraints :-
|
||||
map.from_corresponding_lists(Old, New, RenameMap),
|
||||
Constraints = list.map(substitute_vars_in_constraint(RenameMap),
|
||||
Constraints0).
|
||||
|
||||
substitute_vars_2(SubstMap, lte(Terms0, Const)) = Result :-
|
||||
Terms = list.map(substitute_term(SubstMap), Terms0),
|
||||
:- func substitute_vars_in_constraint(map(lp_var, lp_var), lp_constraint)
|
||||
= lp_constraint.
|
||||
|
||||
substitute_vars_in_constraint(RenameMap, lte(Terms0, Const)) = Result :-
|
||||
Terms = list.map(substitute_term(RenameMap), Terms0),
|
||||
Result = lte(sum_like_terms(Terms), Const).
|
||||
substitute_vars_2(SubstMap, eq(Terms0, Const)) = Result :-
|
||||
Terms = list.map(substitute_term(SubstMap), Terms0),
|
||||
substitute_vars_in_constraint(RenameMap, eq(Terms0, Const)) = Result :-
|
||||
Terms = list.map(substitute_term(RenameMap), Terms0),
|
||||
Result = eq(sum_like_terms(Terms), Const).
|
||||
substitute_vars_2(_, gte(_, _)) =
|
||||
substitute_vars_in_constraint(_, gte(_, _)) =
|
||||
unexpected($pred, "gte").
|
||||
|
||||
:- func substitute_term(map(lp_var, lp_var), lp_term) = lp_term.
|
||||
|
||||
substitute_term(SubstMap, Term0) = Term :-
|
||||
substitute_term(RenameMap, Term0) = Term :-
|
||||
Term0 = Var0 - Coeff,
|
||||
map.lookup(SubstMap, Var0, Var),
|
||||
map.lookup(RenameMap, Var0, Var),
|
||||
Term = Var - Coeff.
|
||||
|
||||
set_vars_to_zero(Vars, Constraints) =
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
% vim: ft=mercury ts=4 sw=4 et
|
||||
%---------------------------------------------------------------------------%
|
||||
% Copyright (C) 2003, 2005-2007, 2009-2011 The University of Melbourne.
|
||||
% Copyright (C) 2015, 2018-2019, 2021, 2024 The Mercury team.
|
||||
% Copyright (C) 2015, 2018-2019, 2021, 2024-2025 The Mercury team.
|
||||
% This file may only be copied under the terms of the GNU General
|
||||
% Public License - see the file COPYING in the Mercury distribution.
|
||||
%---------------------------------------------------------------------------%
|
||||
@@ -93,7 +93,7 @@
|
||||
|
||||
% Succeeds iff the given polyhedron is the `universe' polyhedron,
|
||||
% that is the one whose constraint representation corresponds to `true'.
|
||||
% (ie. it is unbounded in all dimensions).
|
||||
% (i.e. it is unbounded in all dimensions).
|
||||
%
|
||||
:- pred is_universe(polyhedron::in) is semidet.
|
||||
|
||||
@@ -116,13 +116,13 @@
|
||||
:- pred convex_union(lp_varset::in, polyhedron::in, polyhedron::in,
|
||||
polyhedron::out) is det.
|
||||
|
||||
% As above but takes an extra argument that weakens the approximation even
|
||||
% further if the size of the internal matrices exceeds the supplied
|
||||
% threshold
|
||||
% Does the same job as convex_union, but takes an extra argument
|
||||
% that weakens the approximation even further if the size of the
|
||||
% internal matrices exceeds the supplied threshold.
|
||||
%
|
||||
:- func convex_union(lp_varset, maybe(int), polyhedron, polyhedron)
|
||||
:- func convex_union_max_size(lp_varset, maybe(int), polyhedron, polyhedron)
|
||||
= polyhedron.
|
||||
:- pred convex_union(lp_varset::in, maybe(int)::in, polyhedron::in,
|
||||
:- pred convex_union_max_size(lp_varset::in, maybe(int)::in, polyhedron::in,
|
||||
polyhedron::in, polyhedron::out) is det.
|
||||
|
||||
% Approximate a (convex) polyhedron by a rectangular region
|
||||
@@ -153,8 +153,11 @@
|
||||
% easy to do (at the moment) as the polyhedra are represented as
|
||||
% constraints anyway.
|
||||
%
|
||||
:- func substitute_vars(list(lp_var), list(lp_var), polyhedron) = polyhedron.
|
||||
% XXX As of 2025 aug 10, substitute_corresponding_vars is unused.
|
||||
%
|
||||
:- func substitute_vars(map(lp_var, lp_var), polyhedron) = polyhedron.
|
||||
:- func substitute_corresponding_vars(list(lp_var), list(lp_var),
|
||||
polyhedron) = polyhedron.
|
||||
|
||||
% polyhedron.zero_vars(Set, Polyhedron0) = Polyhedron <=>
|
||||
%
|
||||
@@ -261,20 +264,22 @@ intersection(PolyA, PolyB, polyhedron.intersection(PolyA, PolyB)).
|
||||
%
|
||||
|
||||
convex_union(VarSet, PolyhedronA, PolyhedronB) = Polyhedron :-
|
||||
convex_union(VarSet, no, PolyhedronA, PolyhedronB, Polyhedron).
|
||||
convex_union_max_size(VarSet, no, PolyhedronA, PolyhedronB, Polyhedron).
|
||||
|
||||
convex_union(VarSet, PolyhedronA, PolyhedronB, Polyhedron) :-
|
||||
convex_union(VarSet, no, PolyhedronA, PolyhedronB, Polyhedron).
|
||||
convex_union_max_size(VarSet, no, PolyhedronA, PolyhedronB, Polyhedron).
|
||||
|
||||
convex_union(VarSet, MaxMatrixSize, PolyhedronA, PolyhedronB) = Polyhedron :-
|
||||
convex_union(VarSet, MaxMatrixSize, PolyhedronA, PolyhedronB, Polyhedron).
|
||||
convex_union_max_size(VarSet, MaxMatrixSize, PolyhedronA, PolyhedronB)
|
||||
= Polyhedron :-
|
||||
convex_union_max_size(VarSet, MaxMatrixSize,
|
||||
PolyhedronA, PolyhedronB, Polyhedron).
|
||||
|
||||
convex_union(_, _, empty_poly, empty_poly, empty_poly).
|
||||
convex_union(_, _, eqns(Constraints), empty_poly,
|
||||
convex_union_max_size(_, _, empty_poly, empty_poly, empty_poly).
|
||||
convex_union_max_size(_, _, eqns(Constraints), empty_poly,
|
||||
eqns(Constraints)).
|
||||
convex_union(_, _, empty_poly, eqns(Constraints),
|
||||
convex_union_max_size(_, _, empty_poly, eqns(Constraints),
|
||||
eqns(Constraints)).
|
||||
convex_union(VarSet, MaybeMaxSize, eqns(ConstraintsA),
|
||||
convex_union_max_size(VarSet, MaybeMaxSize, eqns(ConstraintsA),
|
||||
eqns(ConstraintsB), Hull) :-
|
||||
convex_hull([ConstraintsA, ConstraintsB], Hull, MaybeMaxSize, VarSet).
|
||||
|
||||
@@ -560,14 +565,15 @@ project_polyhedron(VarSet, Vars, eqns(Constraints0), Result) :-
|
||||
% Variable substitution.
|
||||
%
|
||||
|
||||
substitute_vars(OldVars, NewVars, Polyhedron0) = Polyhedron :-
|
||||
substitute_vars(RenameMap, Polyhedron0) = Polyhedron :-
|
||||
Constraints0 = polyhedron.non_false_constraints(Polyhedron0),
|
||||
Constraints = lp_rational.substitute_vars(OldVars, NewVars, Constraints0),
|
||||
Constraints = lp_rational.substitute_vars(RenameMap, Constraints0),
|
||||
Polyhedron = polyhedron.from_constraints(Constraints).
|
||||
|
||||
substitute_vars(SubstMap, Polyhedron0) = Polyhedron :-
|
||||
substitute_corresponding_vars(OldVars, NewVars, Polyhedron0) = Polyhedron :-
|
||||
Constraints0 = polyhedron.non_false_constraints(Polyhedron0),
|
||||
Constraints = lp_rational.substitute_vars(SubstMap, Constraints0),
|
||||
Constraints = lp_rational.substitute_corresponding_vars(OldVars, NewVars,
|
||||
Constraints0),
|
||||
Polyhedron = polyhedron.from_constraints(Constraints).
|
||||
|
||||
%---------------------------------------------------------------------------%
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
% vim: ft=mercury ts=4 sw=4 et
|
||||
%-----------------------------------------------------------------------------%
|
||||
% Copyright (C) 2002, 2005-2012 The University of Melbourne.
|
||||
% Copyright (C) 2015, 2017-2024 The Mercury team.
|
||||
% Copyright (C) 2015, 2017-2025 The Mercury team.
|
||||
% This file may only be copied under the terms of the GNU General
|
||||
% Public License - see the file COPYING in the Mercury distribution.
|
||||
%-----------------------------------------------------------------------------%
|
||||
@@ -385,8 +385,8 @@ term_traverse_abstract_disj_linearly_2(Info, Locals, Goal, !Polyhedron) :-
|
||||
SizeVarSet = Info ^ tcfi_varset,
|
||||
term_traverse_abstract_goal(Info, Goal, polyhedron.universe, Polyhedron0),
|
||||
project_polyhedron(SizeVarSet, Locals, Polyhedron0, Polyhedron1),
|
||||
polyhedron.convex_union(SizeVarSet, yes(Info ^ tcfi_max_matrix_size),
|
||||
Polyhedron1, !Polyhedron).
|
||||
polyhedron.convex_union_max_size(SizeVarSet,
|
||||
yes(Info ^ tcfi_max_matrix_size), Polyhedron1, !Polyhedron).
|
||||
|
||||
% This version computes the convex hull pairwise. That is
|
||||
% ( A ; B ; C ; D) is processed as: (( A \/ B ) \/ ( C \/ D)).
|
||||
@@ -394,7 +394,8 @@ term_traverse_abstract_disj_linearly_2(Info, Locals, Goal, !Polyhedron) :-
|
||||
% XXX This code is currently unused.
|
||||
%
|
||||
:- pred term_traverse_abstract_disj_pairwise(list(abstract_goal)::in,
|
||||
list(size_var)::in, fixpoint_info::in, polyhedron::in, polyhedron::out) is det.
|
||||
list(size_var)::in, fixpoint_info::in,
|
||||
polyhedron::in, polyhedron::out) is det.
|
||||
:- pragma consider_used(pred(term_traverse_abstract_disj_pairwise/5)).
|
||||
|
||||
term_traverse_abstract_disj_pairwise(Goals, Locals, Info, !Polyhedron) :-
|
||||
@@ -413,7 +414,7 @@ term_traverse_abstract_disj_pairwise(Goals, Locals, Info, !Polyhedron) :-
|
||||
% Now pairwise convex hull them.
|
||||
HullOp =
|
||||
( func(A, B) = C :-
|
||||
polyhedron.convex_union(SizeVarSet,
|
||||
polyhedron.convex_union_max_size(SizeVarSet,
|
||||
yes(Info ^ tcfi_max_matrix_size), A, B, C)
|
||||
),
|
||||
ConvexUnion = pairwise_map(HullOp, [ polyhedron.empty | Polyhedra0]),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
% vim: ft=mercury ts=4 sw=4 et
|
||||
%-----------------------------------------------------------------------------%
|
||||
% Copyright (C) 2002, 2005-2012 The University of Melbourne.
|
||||
% Copyright (C) 2015-2018, 2020-2024 The Mercury team.
|
||||
% Copyright (C) 2015-2018, 2020-2025 The Mercury team.
|
||||
% This file may only be copied under the terms of the GNU General
|
||||
% Public License - see the file COPYING in the Mercury distribution.
|
||||
%-----------------------------------------------------------------------------%
|
||||
@@ -215,7 +215,8 @@ find_edges_in_goal(Proc, AbstractSCC, ModuleInfo, MaxMatrixSize,
|
||||
DisjConstrs = polyhedron.project_all(SizeVarSet, Locals,
|
||||
DisjConstrs0),
|
||||
Constrs2 = list.foldl(
|
||||
polyhedron.convex_union(SizeVarSet, yes(MaxMatrixSize)),
|
||||
polyhedron.convex_union_max_size(SizeVarSet,
|
||||
yes(MaxMatrixSize)),
|
||||
DisjConstrs, polyhedron.empty),
|
||||
polyhedron.intersection(Constrs2, !Polyhedron)
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user