* [PATCH] c++: replace tf_norm with a local flag
@ 2024-05-03 15:26 Patrick Palka
2024-05-06 22:21 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2024-05-03 15:26 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, Patrick Palka
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
for trunk?
-- >8 --
The tf_norm flag controlling whether to build diagnostic information
during constraint normalization doesn't need to be a global tsubst flag,
and is confusingly named. This patch replaces it with a boolean flag
local to normalization.
gcc/cp/ChangeLog:
* constraint.cc (norm_info::norm_info): Take a boolean parameter
instead of tsubst_flags_t.
(norm_info::generate_diagnostics): Turn this predicate function
into a data member.
(normalize_logical_operation): Adjust after norm_info changes.
(normalize_concept_check): Likewise.
(normalize_atom): Likewise.
(get_normalized_constraints_from_info): Likewise.
(normalize_concept_definition): Likewise.
(normalize_constraint_expression): Likewise.
(normalize_placeholder_type_constraints): Likewise.
(satisfy_nondeclaration_constraints): Likewise.
* cp-tree.h (enum tsubst_flags): Remove tf_norm.
---
gcc/cp/constraint.cc | 40 ++++++++++++++++++++--------------------
gcc/cp/cp-tree.h | 3 +--
2 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8a3b5d80ba7..3f0dab79bcd 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -622,33 +622,29 @@ parameter_mapping_equivalent_p (tree t1, tree t2)
struct norm_info : subst_info
{
- explicit norm_info (tsubst_flags_t cmp)
- : norm_info (NULL_TREE, cmp)
+ explicit norm_info (bool diag)
+ : norm_info (NULL_TREE, diag)
{}
/* Construct a top-level context for DECL. */
- norm_info (tree in_decl, tsubst_flags_t complain)
- : subst_info (tf_warning_or_error | complain, in_decl)
+ norm_info (tree in_decl, bool diag)
+ : subst_info (tf_warning_or_error, in_decl),
+ generate_diagnostics (diag)
{
if (in_decl)
{
initial_parms = DECL_TEMPLATE_PARMS (in_decl);
- if (generate_diagnostics ())
+ if (generate_diagnostics)
context = build_tree_list (NULL_TREE, in_decl);
}
else
initial_parms = current_template_parms;
}
- bool generate_diagnostics() const
- {
- return complain & tf_norm;
- }
-
void update_context(tree expr, tree args)
{
- if (generate_diagnostics ())
+ if (generate_diagnostics)
{
tree map = build_parameter_mapping (expr, args, ctx_parms ());
context = tree_cons (map, expr, context);
@@ -679,6 +675,10 @@ struct norm_info : subst_info
template parameters of ORIG_DECL. */
tree initial_parms = NULL_TREE;
+
+ /* Whether to build diagnostic information during normalization. */
+
+ bool generate_diagnostics;
};
static tree normalize_expression (tree, tree, norm_info);
@@ -693,7 +693,7 @@ normalize_logical_operation (tree t, tree args, tree_code c, norm_info info)
tree t1 = normalize_expression (TREE_OPERAND (t, 1), args, info);
/* Build a new info object for the constraint. */
- tree ci = info.generate_diagnostics()
+ tree ci = info.generate_diagnostics
? build_tree_list (t, info.context)
: NULL_TREE;
@@ -777,7 +777,7 @@ normalize_concept_check (tree check, tree args, norm_info info)
if (!norm_cache)
norm_cache = hash_table<norm_hasher>::create_ggc (31);
norm_entry *entry = nullptr;
- if (!info.generate_diagnostics ())
+ if (!info.generate_diagnostics)
{
/* Cache the normal form of the substituted concept-id (when not
diagnosing). */
@@ -831,7 +831,7 @@ normalize_atom (tree t, tree args, norm_info info)
if (info.in_decl && concept_definition_p (info.in_decl))
ATOMIC_CONSTR_EXPR_FROM_CONCEPT_P (atom) = true;
- if (!info.generate_diagnostics ())
+ if (!info.generate_diagnostics)
{
/* Cache the ATOMIC_CONSTRs that we return, so that sat_hasher::equal
later can cheaply compare two atoms using just pointer equality. */
@@ -910,7 +910,7 @@ get_normalized_constraints_from_info (tree ci, tree in_decl, bool diag = false)
/* Substitution errors during normalization are fatal. */
++processing_template_decl;
- norm_info info (in_decl, diag ? tf_norm : tf_none);
+ norm_info info (in_decl, diag);
tree t = get_normalized_constraints (CI_ASSOCIATED_CONSTRAINTS (ci), info);
--processing_template_decl;
@@ -1012,7 +1012,7 @@ normalize_concept_definition (tree tmpl, bool diag)
gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL);
tree def = get_concept_definition (DECL_TEMPLATE_RESULT (tmpl));
++processing_template_decl;
- norm_info info (tmpl, diag ? tf_norm : tf_none);
+ norm_info info (tmpl, diag);
tree norm = get_normalized_constraints (def, info);
--processing_template_decl;
@@ -1035,7 +1035,7 @@ normalize_constraint_expression (tree expr, norm_info info)
if (!expr || expr == error_mark_node)
return expr;
- if (!info.generate_diagnostics ())
+ if (!info.generate_diagnostics)
if (tree *p = hash_map_safe_get (normalized_map, expr))
return *p;
@@ -1043,7 +1043,7 @@ normalize_constraint_expression (tree expr, norm_info info)
tree norm = get_normalized_constraints (expr, info);
--processing_template_decl;
- if (!info.generate_diagnostics ())
+ if (!info.generate_diagnostics)
hash_map_safe_put<hm_ggc> (normalized_map, expr, norm);
return norm;
@@ -3190,7 +3190,7 @@ normalize_placeholder_type_constraints (tree t, bool diag)
? TMPL_PARMS_DEPTH (initial_parms) + 1 : 1),
make_tree_vec (0), initial_parms);
- norm_info info (diag ? tf_norm : tf_none);
+ norm_info info (diag);
info.initial_parms = initial_parms;
return normalize_constraint_expression (constr, info);
}
@@ -3226,7 +3226,7 @@ satisfy_nondeclaration_constraints (tree t, tree args, sat_info info)
}
else if (TREE_CODE (t) == NESTED_REQ)
{
- norm_info ninfo (info.noisy () ? tf_norm : tf_none);
+ norm_info ninfo (info.noisy ());
/* The TREE_TYPE contains the set of template parameters that were in
scope for this nested requirement; use them as the initial template
parameters for normalization. */
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index bc8e22cc39f..d4e216e361e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5696,8 +5696,7 @@ enum tsubst_flags {
declaration. */
tf_no_cleanup = 1 << 10, /* Do not build a cleanup
(build_target_expr and friends) */
- tf_norm = 1 << 11, /* Build diagnostic information during
- constraint normalization. */
+ /* 1 << 11 is free to use. */
tf_tst_ok = 1 << 12, /* Allow a typename-specifier to name
a template (C++17 or later). */
tf_dguide = 1 << 13, /* Building a deduction guide from a ctor. */
--
2.45.0.31.gd4cc1ec35f
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: replace tf_norm with a local flag
2024-05-03 15:26 [PATCH] c++: replace tf_norm with a local flag Patrick Palka
@ 2024-05-06 22:21 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-05-06 22:21 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 5/3/24 11:26, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
> for trunk?
OK.
> -- >8 --
>
> The tf_norm flag controlling whether to build diagnostic information
> during constraint normalization doesn't need to be a global tsubst flag,
> and is confusingly named. This patch replaces it with a boolean flag
> local to normalization.
>
> gcc/cp/ChangeLog:
>
> * constraint.cc (norm_info::norm_info): Take a boolean parameter
> instead of tsubst_flags_t.
> (norm_info::generate_diagnostics): Turn this predicate function
> into a data member.
> (normalize_logical_operation): Adjust after norm_info changes.
> (normalize_concept_check): Likewise.
> (normalize_atom): Likewise.
> (get_normalized_constraints_from_info): Likewise.
> (normalize_concept_definition): Likewise.
> (normalize_constraint_expression): Likewise.
> (normalize_placeholder_type_constraints): Likewise.
> (satisfy_nondeclaration_constraints): Likewise.
> * cp-tree.h (enum tsubst_flags): Remove tf_norm.
> ---
> gcc/cp/constraint.cc | 40 ++++++++++++++++++++--------------------
> gcc/cp/cp-tree.h | 3 +--
> 2 files changed, 21 insertions(+), 22 deletions(-)
>
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 8a3b5d80ba7..3f0dab79bcd 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -622,33 +622,29 @@ parameter_mapping_equivalent_p (tree t1, tree t2)
>
> struct norm_info : subst_info
> {
> - explicit norm_info (tsubst_flags_t cmp)
> - : norm_info (NULL_TREE, cmp)
> + explicit norm_info (bool diag)
> + : norm_info (NULL_TREE, diag)
> {}
>
> /* Construct a top-level context for DECL. */
>
> - norm_info (tree in_decl, tsubst_flags_t complain)
> - : subst_info (tf_warning_or_error | complain, in_decl)
> + norm_info (tree in_decl, bool diag)
> + : subst_info (tf_warning_or_error, in_decl),
> + generate_diagnostics (diag)
> {
> if (in_decl)
> {
> initial_parms = DECL_TEMPLATE_PARMS (in_decl);
> - if (generate_diagnostics ())
> + if (generate_diagnostics)
> context = build_tree_list (NULL_TREE, in_decl);
> }
> else
> initial_parms = current_template_parms;
> }
>
> - bool generate_diagnostics() const
> - {
> - return complain & tf_norm;
> - }
> -
> void update_context(tree expr, tree args)
> {
> - if (generate_diagnostics ())
> + if (generate_diagnostics)
> {
> tree map = build_parameter_mapping (expr, args, ctx_parms ());
> context = tree_cons (map, expr, context);
> @@ -679,6 +675,10 @@ struct norm_info : subst_info
> template parameters of ORIG_DECL. */
>
> tree initial_parms = NULL_TREE;
> +
> + /* Whether to build diagnostic information during normalization. */
> +
> + bool generate_diagnostics;
> };
>
> static tree normalize_expression (tree, tree, norm_info);
> @@ -693,7 +693,7 @@ normalize_logical_operation (tree t, tree args, tree_code c, norm_info info)
> tree t1 = normalize_expression (TREE_OPERAND (t, 1), args, info);
>
> /* Build a new info object for the constraint. */
> - tree ci = info.generate_diagnostics()
> + tree ci = info.generate_diagnostics
> ? build_tree_list (t, info.context)
> : NULL_TREE;
>
> @@ -777,7 +777,7 @@ normalize_concept_check (tree check, tree args, norm_info info)
> if (!norm_cache)
> norm_cache = hash_table<norm_hasher>::create_ggc (31);
> norm_entry *entry = nullptr;
> - if (!info.generate_diagnostics ())
> + if (!info.generate_diagnostics)
> {
> /* Cache the normal form of the substituted concept-id (when not
> diagnosing). */
> @@ -831,7 +831,7 @@ normalize_atom (tree t, tree args, norm_info info)
> if (info.in_decl && concept_definition_p (info.in_decl))
> ATOMIC_CONSTR_EXPR_FROM_CONCEPT_P (atom) = true;
>
> - if (!info.generate_diagnostics ())
> + if (!info.generate_diagnostics)
> {
> /* Cache the ATOMIC_CONSTRs that we return, so that sat_hasher::equal
> later can cheaply compare two atoms using just pointer equality. */
> @@ -910,7 +910,7 @@ get_normalized_constraints_from_info (tree ci, tree in_decl, bool diag = false)
>
> /* Substitution errors during normalization are fatal. */
> ++processing_template_decl;
> - norm_info info (in_decl, diag ? tf_norm : tf_none);
> + norm_info info (in_decl, diag);
> tree t = get_normalized_constraints (CI_ASSOCIATED_CONSTRAINTS (ci), info);
> --processing_template_decl;
>
> @@ -1012,7 +1012,7 @@ normalize_concept_definition (tree tmpl, bool diag)
> gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL);
> tree def = get_concept_definition (DECL_TEMPLATE_RESULT (tmpl));
> ++processing_template_decl;
> - norm_info info (tmpl, diag ? tf_norm : tf_none);
> + norm_info info (tmpl, diag);
> tree norm = get_normalized_constraints (def, info);
> --processing_template_decl;
>
> @@ -1035,7 +1035,7 @@ normalize_constraint_expression (tree expr, norm_info info)
> if (!expr || expr == error_mark_node)
> return expr;
>
> - if (!info.generate_diagnostics ())
> + if (!info.generate_diagnostics)
> if (tree *p = hash_map_safe_get (normalized_map, expr))
> return *p;
>
> @@ -1043,7 +1043,7 @@ normalize_constraint_expression (tree expr, norm_info info)
> tree norm = get_normalized_constraints (expr, info);
> --processing_template_decl;
>
> - if (!info.generate_diagnostics ())
> + if (!info.generate_diagnostics)
> hash_map_safe_put<hm_ggc> (normalized_map, expr, norm);
>
> return norm;
> @@ -3190,7 +3190,7 @@ normalize_placeholder_type_constraints (tree t, bool diag)
> ? TMPL_PARMS_DEPTH (initial_parms) + 1 : 1),
> make_tree_vec (0), initial_parms);
>
> - norm_info info (diag ? tf_norm : tf_none);
> + norm_info info (diag);
> info.initial_parms = initial_parms;
> return normalize_constraint_expression (constr, info);
> }
> @@ -3226,7 +3226,7 @@ satisfy_nondeclaration_constraints (tree t, tree args, sat_info info)
> }
> else if (TREE_CODE (t) == NESTED_REQ)
> {
> - norm_info ninfo (info.noisy () ? tf_norm : tf_none);
> + norm_info ninfo (info.noisy ());
> /* The TREE_TYPE contains the set of template parameters that were in
> scope for this nested requirement; use them as the initial template
> parameters for normalization. */
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index bc8e22cc39f..d4e216e361e 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -5696,8 +5696,7 @@ enum tsubst_flags {
> declaration. */
> tf_no_cleanup = 1 << 10, /* Do not build a cleanup
> (build_target_expr and friends) */
> - tf_norm = 1 << 11, /* Build diagnostic information during
> - constraint normalization. */
> + /* 1 << 11 is free to use. */
> tf_tst_ok = 1 << 12, /* Allow a typename-specifier to name
> a template (C++17 or later). */
> tf_dguide = 1 << 13, /* Building a deduction guide from a ctor. */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-06 22:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-03 15:26 [PATCH] c++: replace tf_norm with a local flag Patrick Palka
2024-05-06 22:21 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).