From e1344fe7b6a96966281c78e46e777b456d5c2e19 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Thu, 29 Oct 2020 14:03:03 -0400 Subject: [PATCH] c++: Simplify constraint normalization routines Many of the high-level constraint normalization routines allow the caller to supply the initial template arguments for normalization, but in practice all of the callers supply something equivalent to the identity mapping(*). This patch hard-codes this prevalent choice of initial template arguments by making get_normalized_constraints always pass NULL_TREE as the args to normalize_expression. This admits some simplifications in the high-level routines, such as removing their 'args' parameter and consolidating the two versions of normalize_constraint_expression. (*): In particular, a set of generic template arguments or NULL_TREE. In the case of the two-parm version of normalize_constraint_expression, we were suspiciously using the template arguments of a concept-id when normalizing the concept-id as a constraint-expression. gcc/cp/ChangeLog: * constraint.cc (get_normalized_constraints): Remove 'args' parameter. Pass NULL_TREE as the initial template arguments to normalize_expression. (get_normalized_constraints_from_info): Remove 'args' parameter and adjust the call to get_normalized_constraints. (get_normalized_constraints_from_decl): Remove 'args' local variable and adjust call to get_normalized_constraints_from_info. (normalize_concept_definition): Remove 'args' local variable and adjust call to get_normalized_constraints. (normalize_constraint_expression): Remove the two-parameter overload. Remove 'args' parameter from the three-parameter overload and update function comment accordingly. Remove default argument from 'diag' parameter. Adjust call to get_normalized_constraints. (finish_nested_requirement): Adjust call to normalize_constraint_expression. (strictly_subsumes): Remove 'args' parameter. Adjust call to get_normalized_constraints_from_info. (weakly_subsumes): Likewise. * cp-tree.h (strictly_subsumes): Remove 'args' parameter. (weakly_subsumes): Likewise. * pt.c (process_partial_specialization): Adjust call to strictly_subsumes. (is_compatible_template_arg): Adjust call to weakly_subsumes. --- gcc/cp/constraint.cc | 69 +++++++++++++------------------------------- gcc/cp/cp-tree.h | 4 +-- gcc/cp/pt.c | 5 ++-- 3 files changed, 24 insertions(+), 54 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 75457a2dd60..d6354edbe6f 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -759,20 +759,18 @@ normalize_expression (tree t, tree args, norm_info info) static GTY((deletable)) hash_map *normalized_map; static tree -get_normalized_constraints (tree t, tree args, norm_info info) +get_normalized_constraints (tree t, norm_info info) { auto_timevar time (TV_CONSTRAINT_NORM); - return normalize_expression (t, args, info); + return normalize_expression (t, NULL_TREE, info); } /* Returns the normalized constraints from a constraint-info object - or NULL_TREE if the constraints are null. ARGS provide the initial - arguments for normalization and IN_DECL provides the declaration - to which the constraints belong. */ + or NULL_TREE if the constraints are null. IN_DECL provides the + declaration to which the constraints belong. */ static tree -get_normalized_constraints_from_info (tree ci, tree args, tree in_decl, - bool diag = false) +get_normalized_constraints_from_info (tree ci, tree in_decl, bool diag = false) { if (ci == NULL_TREE) return NULL_TREE; @@ -780,8 +778,7 @@ get_normalized_constraints_from_info (tree ci, tree args, tree in_decl, /* Substitution errors during normalization are fatal. */ ++processing_template_decl; norm_info info (in_decl, diag ? tf_norm : tf_none); - tree t = get_normalized_constraints (CI_ASSOCIATED_CONSTRAINTS (ci), - args, info); + tree t = get_normalized_constraints (CI_ASSOCIATED_CONSTRAINTS (ci), info); --processing_template_decl; return t; @@ -843,9 +840,8 @@ get_normalized_constraints_from_decl (tree d, bool diag = false) push_nested_class_guard pncs (DECL_CONTEXT (d)); - tree args = generic_targs_for (tmpl); tree ci = get_constraints (decl); - tree norm = get_normalized_constraints_from_info (ci, args, tmpl, diag); + tree norm = get_normalized_constraints_from_info (ci, tmpl, diag); if (!diag) hash_map_safe_put (normalized_map, tmpl, norm); @@ -866,11 +862,10 @@ normalize_concept_definition (tree tmpl, bool diag = false) if (OVL_P (tmpl)) tmpl = OVL_FIRST (tmpl); gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL); - tree args = generic_targs_for (tmpl); tree def = get_concept_definition (DECL_TEMPLATE_RESULT (tmpl)); ++processing_template_decl; norm_info info (tmpl, diag ? tf_norm : tf_none); - tree norm = get_normalized_constraints (def, args, info); + tree norm = get_normalized_constraints (def, info); --processing_template_decl; if (!diag) @@ -895,42 +890,20 @@ normalize_nontemplate_requirements (tree decl, bool diag = false) return get_normalized_constraints_from_decl (decl, diag); } -/* Normalize an EXPR as a constraint using ARGS. */ +/* Normalize an EXPR as a constraint. */ static tree -normalize_constraint_expression (tree expr, tree args, bool diag = false) +normalize_constraint_expression (tree expr, bool diag) { if (!expr || expr == error_mark_node) return expr; ++processing_template_decl; norm_info info (diag ? tf_norm : tf_none); - tree norm = get_normalized_constraints (expr, args, info); + tree norm = get_normalized_constraints (expr, info); --processing_template_decl; return norm; } -/* Normalize an EXPR as a constraint. */ - -static tree -normalize_constraint_expression (tree expr, bool diag = false) -{ - if (!expr || expr == error_mark_node) - return expr; - - /* For concept checks, use the supplied template arguments as those used - for normalization. Otherwise, there are no template arguments. */ - tree args; - if (concept_check_p (expr)) - { - tree id = unpack_concept_check (expr); - args = TREE_OPERAND (id, 1); - } - else - args = NULL_TREE; - - return normalize_constraint_expression (expr, args, diag); -} - /* 17.4.1.2p2. Two constraints are identical if they are formed from the same expression and the targets of the parameter mapping are equivalent. */ @@ -2998,9 +2971,7 @@ finish_compound_requirement (location_t loc, tree expr, tree type, bool noexcept tree finish_nested_requirement (location_t loc, tree expr) { - /* Currently open template headers have dummy arg vectors, so don't - pass into normalization. */ - tree norm = normalize_constraint_expression (expr, NULL_TREE, false); + tree norm = normalize_constraint_expression (expr, false); /* Build the constraint, saving its normalization as its type. */ tree r = build1 (NESTED_REQ, norm, expr); @@ -3105,25 +3076,25 @@ subsumes_constraints (tree a, tree b) return subsumes (a, b); } -/* Returns true when the constraints in CI (with arguments - ARGS) strictly subsume the associated constraints of TMPL. */ +/* Returns true when the constraints in CI strictly subsume + the associated constraints of TMPL. */ bool -strictly_subsumes (tree ci, tree args, tree tmpl) +strictly_subsumes (tree ci, tree tmpl) { - tree n1 = get_normalized_constraints_from_info (ci, args, NULL_TREE); + tree n1 = get_normalized_constraints_from_info (ci, NULL_TREE); tree n2 = get_normalized_constraints_from_decl (tmpl); return subsumes (n1, n2) && !subsumes (n2, n1); } -/* REturns true when the constraints in CI (with arguments ARGS) subsume - the associated constraints of TMPL. */ +/* Returns true when the constraints in CI subsume the + associated constraints of TMPL. */ bool -weakly_subsumes (tree ci, tree args, tree tmpl) +weakly_subsumes (tree ci, tree tmpl) { - tree n1 = get_normalized_constraints_from_info (ci, args, NULL_TREE); + tree n1 = get_normalized_constraints_from_info (ci, NULL_TREE); tree n2 = get_normalized_constraints_from_decl (tmpl); return subsumes (n1, n2); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 20774f82620..fdb8ee57f0b 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7838,8 +7838,8 @@ extern tree find_template_parameters (tree, tree); extern bool equivalent_constraints (tree, tree); extern bool equivalently_constrained (tree, tree); extern bool subsumes_constraints (tree, tree); -extern bool strictly_subsumes (tree, tree, tree); -extern bool weakly_subsumes (tree, tree, tree); +extern bool strictly_subsumes (tree, tree); +extern bool weakly_subsumes (tree, tree); extern int more_constrained (tree, tree); extern bool at_least_as_constrained (tree, tree); extern bool constraints_equivalent_p (tree, tree); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f31a1a70473..531554d702d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5089,8 +5089,7 @@ process_partial_specialization (tree decl) = TI_ARGS (get_template_info (DECL_TEMPLATE_RESULT (maintmpl))); if (comp_template_args (inner_args, INNERMOST_TEMPLATE_ARGS (main_args)) && (!flag_concepts - || !strictly_subsumes (current_template_constraints (), - main_args, maintmpl))) + || !strictly_subsumes (current_template_constraints (), maintmpl))) { if (!flag_concepts) error ("partial specialization %q+D does not specialize " @@ -8178,7 +8177,7 @@ is_compatible_template_arg (tree parm, tree arg) return false; } - return weakly_subsumes (parm_cons, new_args, arg); + return weakly_subsumes (parm_cons, arg); } // Convert a placeholder argument into a binding to the original -- 2.30.2