c++: Clean up normalization and satisfaction routines
authorPatrick Palka <ppalka@redhat.com>
Wed, 3 Mar 2021 17:01:13 +0000 (12:01 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 3 Mar 2021 17:01:13 +0000 (12:01 -0500)
commit662ef5b54de8f77080a19e03f31b162c04ba273f
tree719af4f3e7349cf7da230988be93761b19817c04
parent39d7eb8a73d5f8c09db20926a98181181d9dd2c2
c++: Clean up normalization and satisfaction routines

This patch mostly performs some straightforward refactoring:

  - Renamed satisfy_constraint to satisfy_normalized_constraints
  - Renamed the three-parameter version of satisfy_constraint_expression
    to satisfy_nondeclaration_constraints
  - Removed normalize_(non)?template_requirements
  - Removed satisfy_associated_constraints (and made its callers
    check for dependent template args sooner, before normalization)
  - Removed the tsubst_flags_t parameter of evaluate_concept_check
  - Combined the two versions of constraint_satisfaction_value
  - Combined the two versions of constraint_satisfied_p

Additionally, this patch removes the handling of general
constraint-expressions from satisfy_nondeclaration_constraints, and
hence constraints_satisfied_p and constraint_satisfaction_value now take
only things that carry their own template information needed for
normalization, and, as a special case, REQUIRES_EXPRs.  But the latter
now get evaluated directly via tsubst_requires_expr rather than going
through satisfaction.

(That we used to evaluate REQUIRES_EXPR via satisfaction might even be a
correctness issue: since we cache satisfaction in special ways that don't
apply to regular evaluation, going through satisfaction could in theory
cause us to reuse a cached value for a REQUIRES_EXPR when we shouldn't
have.)

gcc/cp/ChangeLog:

* constexpr.c (cxx_eval_call_expression): Adjust call to
evaluate_concept_check.
(cxx_eval_constant_expression) <case REQUIRES_EXPR>: Use
evaluate_requires_expression instead of
satisfy_constraint_expression.
<case TEMPLATE_ID_EXPR>: Adjust call to evaluate_concept_check.
* constraint.cc (struct sat_info): Adjust comment about which
satisfaction entrypoints use noisy-unsat.
(normalize_template_requirements): Remove (and adjust callers
appropriately).
(normalize_nontemplate_requirements): Likewise.
(tsubst_nested_requirement): Use constraint_satisfaction_value
instead of satisfy_constraint_expression, which'll do the
noisy replaying of ill-formed quiet satisfaction for us.
(decl_satisfied_cache): Adjust comment.
(satisfy_constraint): Rename to ...
(satisfy_normalized_constraints): ... this.
(satisfy_associated_constraints): Remove (and make its
callers check for dependent arguments).
(satisfy_constraint_expression): Rename to ...
(satisfy_nondeclaration_constraints): ... this.  Assert that
'args' is empty when 't' is a concept-id.  Removing handling
bare constraint-expressions, and handle REQUIRES_EXPRs
specially.  Adjust comment accordingly.
(satisfy_declaration_constraints): Assert in the two-parameter
version that 't' is not a TEMPLATE_DECL.  Adjust following
removal of normalize_(non)?template_requirements and
satisfy_asociated_constraints.
(constraint_satisfaction_value): Combine the two- and
three-parameter versions in the natural way.
(constraints_satisfied_p): Combine the one- and two-parameter
versions in the natural way.  Improve documentation.
(evaluate_requires_expr): Define.
(evaluate_concept_check): Remove 'complain' parameter.  Use
constraint_satisfaction_value instead of
satisfy_constraint_expression.
(diagnose_nested_requirement): Adjust following renaming of
satisfy_constraint_expression.
(diagnose_constraints): Handle REQUIRES_EXPR by going through
diagnose_requires_expr directly instead of treating it as a
constraint-expression.  Improve documentation.
* cp-gimplify.c (cp_genericize_r) <case CALL_EXPR>: Adjust call
to evaluate_concept_check.
<case REQUIRES_EXPR>: Use evaluate_requires_expr instead of
constraints_satisfied_p.
<case TEMPLATE_ID_EXPR>: Adjust call to evaluate_concept_check.
* cp-tree.h (evaluate_requires_expr): Declare.
(evaluate_concept_check): Remove tsubst_flag_t parameter.
(satisfy_constraint_expression): Remove declaration.
(constraints_satisfied_p): Remove one-parameter declaration.
Add a default argument to the two-parameter declaration.
* cvt.c (convert_to_void): Adjust call to
evaluate_concept_check.
gcc/cp/constexpr.c
gcc/cp/constraint.cc
gcc/cp/cp-gimplify.c
gcc/cp/cp-tree.h
gcc/cp/cvt.c