Re: [PATCH 5/6] c++: Clean up normalization / satisfaction routines

2021-03-02 Thread Jason Merrill via Gcc-patches

On 3/2/21 11:25 AM, Patrick Palka wrote:

On Mon, 1 Mar 2021, Jason Merrill wrote:


On 2/28/21 12:58 PM, Patrick Palka wrote:

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 bare
constraint-expressions from satisfy_nondeclaration_constraints, and
hence constraints_satisfied_p and constraint_satisfaction_value now only
take things that carry their own template information needed for
normalization.  In practice, this only means it's no longer possible to
evaluate bare REQUIRES_EXPRs via the satisfaction routines, and so this
patch adjusts the affected callers to instead use tsubst_requires_expr.


It's probably better to have a different entry point than tsubst_requires_expr
for callers that have nothing to do with templates.  Whether that's a one-line
wrapper for the call to tsubst_requires_expr ("evaluate_requires_expr"?) or
calling tsubst_requires_expr from satisfy_nondeclaration_constraints, I don't
have an opinion either way.


For convenience, the function diagnose_constraints continues to accept
REQUIRES_EXPRs, but it now handles them by calling diagnose_require_expr
directly.


This might argue for the latter choice above.


Ah, I didn't consider the option of continuing to handle REQUIRES_EXPRs
from satisfy_nondeclaration_constraints by evaluating them directly.

Here's a patch that implements this.  I opted to add a
evaluate_requires_expr wrapper as well, since

   evaluate_requires_expr (t)

is much more readable than

   constant_boolean_node (constraints_satisfied_p (t),
  boolean_type_node)

(Note the added TODO in satisfy_nondeclaration_constraints, which'll be
fixed in a new version of the REQUIRES_EXPR evaluation/diagnostic
unification patch.)


OK.


-- >8 --

Subject: [PATCH] c++: Clean up normalization / 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) : Use
evaluate_requires_expression instead of
satisfy_constraint_expression.
: 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
   

Re: [PATCH 5/6] c++: Clean up normalization / satisfaction routines

2021-03-02 Thread Patrick Palka via Gcc-patches
On Mon, 1 Mar 2021, Jason Merrill wrote:

> On 2/28/21 12:58 PM, Patrick Palka wrote:
> > 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 bare
> > constraint-expressions from satisfy_nondeclaration_constraints, and
> > hence constraints_satisfied_p and constraint_satisfaction_value now only
> > take things that carry their own template information needed for
> > normalization.  In practice, this only means it's no longer possible to
> > evaluate bare REQUIRES_EXPRs via the satisfaction routines, and so this
> > patch adjusts the affected callers to instead use tsubst_requires_expr.
> 
> It's probably better to have a different entry point than tsubst_requires_expr
> for callers that have nothing to do with templates.  Whether that's a one-line
> wrapper for the call to tsubst_requires_expr ("evaluate_requires_expr"?) or
> calling tsubst_requires_expr from satisfy_nondeclaration_constraints, I don't
> have an opinion either way.
> 
> > For convenience, the function diagnose_constraints continues to accept
> > REQUIRES_EXPRs, but it now handles them by calling diagnose_require_expr
> > directly.
> 
> This might argue for the latter choice above.

Ah, I didn't consider the option of continuing to handle REQUIRES_EXPRs
from satisfy_nondeclaration_constraints by evaluating them directly.

Here's a patch that implements this.  I opted to add a
evaluate_requires_expr wrapper as well, since

  evaluate_requires_expr (t)

is much more readable than

  constant_boolean_node (constraints_satisfied_p (t),
 boolean_type_node)

(Note the added TODO in satisfy_nondeclaration_constraints, which'll be
fixed in a new version of the REQUIRES_EXPR evaluation/diagnostic
unification patch.)

-- >8 --

Subject: [PATCH] c++: Clean up normalization / 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) : Use
evaluate_requires_expression instead of
satisfy_constraint_expression.
: 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 

Re: [PATCH 5/6] c++: Clean up normalization / satisfaction routines

2021-03-01 Thread Jason Merrill via Gcc-patches

On 2/28/21 12:58 PM, Patrick Palka wrote:

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 bare
constraint-expressions from satisfy_nondeclaration_constraints, and
hence constraints_satisfied_p and constraint_satisfaction_value now only
take things that carry their own template information needed for
normalization.  In practice, this only means it's no longer possible to
evaluate bare REQUIRES_EXPRs via the satisfaction routines, and so this
patch adjusts the affected callers to instead use tsubst_requires_expr.


It's probably better to have a different entry point than 
tsubst_requires_expr for callers that have nothing to do with templates. 
 Whether that's a one-line wrapper for the call to tsubst_requires_expr 
("evaluate_requires_expr"?) or calling tsubst_requires_expr from 
satisfy_nondeclaration_constraints, I don't have an opinion either way.



For convenience, the function diagnose_constraints continues to accept
REQUIRES_EXPRs, but it now handles them by calling diagnose_require_expr
directly.


This might argue for the latter choice above.


(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) : Use
tsubst_requires_expr instead of satisfy_constraint_expression.
: 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.  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_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) : Adjust call
to evaluate_concept_check.
: Use tsubst_requires_expr instead of
constraints_satisfied_p.
: Adjust call to evaluate_concept_check.
* cp-tree.h (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   |   6 +-
  gcc/cp/constraint.cc | 210 ---
  gcc/cp/cp-gimplify.c |   7 +-
  gcc/cp/cp-tree.h |   6 +-
  gcc/cp/cvt.c |   2 +-
  5 files 

[PATCH 5/6] c++: Clean up normalization / satisfaction routines

2021-02-28 Thread Patrick Palka via Gcc-patches
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 bare
constraint-expressions from satisfy_nondeclaration_constraints, and
hence constraints_satisfied_p and constraint_satisfaction_value now only
take things that carry their own template information needed for
normalization.  In practice, this only means it's no longer possible to
evaluate bare REQUIRES_EXPRs via the satisfaction routines, and so this
patch adjusts the affected callers to instead use tsubst_requires_expr.
For convenience, the function diagnose_constraints continues to accept
REQUIRES_EXPRs, but it now handles them by calling diagnose_require_expr
directly.

(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) : Use
tsubst_requires_expr instead of satisfy_constraint_expression.
: 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.  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_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) : Adjust call
to evaluate_concept_check.
: Use tsubst_requires_expr instead of
constraints_satisfied_p.
: Adjust call to evaluate_concept_check.
* cp-tree.h (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   |   6 +-
 gcc/cp/constraint.cc | 210 ---
 gcc/cp/cp-gimplify.c |   7 +-
 gcc/cp/cp-tree.h |   6 +-
 gcc/cp/cvt.c |   2 +-
 5 files changed, 85 insertions(+), 146 deletions(-)

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index cd0a68e9fd6..f940e3e5985 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2257,7 +2257,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree 
t,
 {
   /* Handle concept checks separately.  */
   if (concept_check_p (t))
-return evaluate_concept_check (t, tf_warning_or_error);
+return evaluate_concept_check (t);