Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On 3/1/21 6:09 PM, Patrick Palka wrote: On Mon, 1 Mar 2021, Jason Merrill wrote: On 2/28/21 12:40 PM, Patrick Palka wrote: On Fri, 12 Feb 2021, Jason Merrill wrote: On 2/10/21 9:41 AM, Patrick Palka wrote: On Tue, 9 Feb 2021, Jason Merrill wrote: On 2/8/21 2:03 PM, Patrick Palka wrote: This sets up the functionality for controlling the initial set of template parameters to pass to normalization when dealing with a constraint-expression that is not associated with some constrained declaration, for instance when normalizing a nested requirement of a requires expression, or the constraints on a placeholder type. The main new ingredient here is the data member norm_info::initial_parms which can be set by callers of the normalization routines to communicate the in-scope template parameters for the supplied constraint-expression, rather than always falling back to using current_template_parms. This patch then uses this functionality in our handling of nested requirements so that we can delay normalizing them until needed for satisfaction. We currently immediately normalize nested requirements at parse time, where we have the necessary template context, and cache the normal form in their TREE_TYPE node. With this patch, we now delay normalization until needed (as with other constraint expressions), and instead store the current value of current_template_parms in their TREE_TYPE node (which we use to restore the template context at normalization time). In the subsequent patch, this functionality will also be used to normalize placeholder type constraints during auto deduction. gcc/cp/ChangeLog: * constraint.cc (build_parameter_mapping): Rely on the caller to determine the in-scope template parameters. (norm_info::norm_info): Delegate the one-parameter constructor to the two-parameter constructor. In the two-parameter constructor, fold in the definition of make_context, set initial_parms appropriately, and don't set the now-removed orig_decl member. (norm_info::make_context): Remove, now that its only use is inlined into the caller. (norm_info::update_context): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. (norm_info::ctx_parms): Define this member function. (norm_info::context): Initialize to NULL_TREE. (norm_info::orig_decl): Remove this data member. (norm_info::initial_parms): Define this data member. (normalize_atom): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. Use info.initial_parms instead of info.orig_decl. (normalize_constraint_expression): Define an overload that takes a norm_info object. Cache the result of normalization. Define the other overload in terms of this one, and handle a NESTED_REQ argument by setting info.initial_parms appropriately. (tsubst_nested_requirement): Go through satisfy_constraint_expression so that we normalize on demand. (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ to current_template_parms. (diagnose_nested_requirements): Go through satisfy_constraint_expression, as with tsubst_nested_requirement. --- gcc/cp/constraint.cc | 140 +++ gcc/cp/cp-tree.h | 4 +- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 39c97986082..56134f8b2bf 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -133,7 +133,7 @@ struct sat_info : subst_info bool diagnose_unsatisfaction; }; -static tree satisfy_constraint (tree, tree, sat_info); +static tree satisfy_constraint_expression (tree, tree, sat_info); /* True if T is known to be some type other than bool. Note that this is false for dependent types and errors. */ @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) return parms; } -/* Build the parameter mapping for EXPR using ARGS. */ +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS + are the template parameters in scope for EXPR. */ static tree -build_parameter_mapping (tree expr, tree args, tree decl) +build_parameter_mapping (tree expr, tree args, tree ctx_parms) { - tree ctx_parms = NULL_TREE; - if (decl) -{ - gcc_assert (TREE_CODE (decl) == TEMPLATE_DECL); - ctx_parms = DECL_TEMPLATE_PARMS (decl); -} - else if (current_template_parms) -{ - /* TODO: This should probably be the only case, but because the -point of declaration of concepts is currently set after the -initializer, the template parameter lists are not available -when normalizing concept definitions, hence the case above. */ - ctx_parms = current_template_parms; -} -
Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On Mon, 1 Mar 2021, Jason Merrill wrote: > On 2/28/21 12:40 PM, Patrick Palka wrote: > > On Fri, 12 Feb 2021, Jason Merrill wrote: > > > > > On 2/10/21 9:41 AM, Patrick Palka wrote: > > > > On Tue, 9 Feb 2021, Jason Merrill wrote: > > > > > > > > > On 2/8/21 2:03 PM, Patrick Palka wrote: > > > > > > This sets up the functionality for controlling the initial set of > > > > > > template parameters to pass to normalization when dealing with a > > > > > > constraint-expression that is not associated with some constrained > > > > > > declaration, for instance when normalizing a nested requirement of a > > > > > > requires expression, or the constraints on a placeholder type. > > > > > > > > > > > > The main new ingredient here is the data member > > > > > > norm_info::initial_parms > > > > > > which can be set by callers of the normalization routines to > > > > > > communicate > > > > > > the in-scope template parameters for the supplied > > > > > > constraint-expression, > > > > > > rather than always falling back to using current_template_parms. > > > > > > > > > > > > This patch then uses this functionality in our handling of nested > > > > > > requirements so that we can delay normalizing them until needed for > > > > > > satisfaction. We currently immediately normalize nested > > > > > > requirements at > > > > > > parse time, where we have the necessary template context, and cache > > > > > > the > > > > > > normal form in their TREE_TYPE node. With this patch, we now delay > > > > > > normalization until needed (as with other constraint expressions), > > > > > > and > > > > > > instead store the current value of current_template_parms in their > > > > > > TREE_TYPE node (which we use to restore the template context at > > > > > > normalization time). > > > > > > > > > > > > In the subsequent patch, this functionality will also be used to > > > > > > normalize placeholder type constraints during auto deduction. > > > > > > > > > > > > gcc/cp/ChangeLog: > > > > > > > > > > > > * constraint.cc (build_parameter_mapping): Rely on the caller > > > > > > to > > > > > > determine the in-scope template parameters. > > > > > > (norm_info::norm_info): Delegate the one-parameter constructor > > > > > > to the two-parameter constructor. In the two-parameter > > > > > > constructor, fold in the definition of make_context, set > > > > > > initial_parms appropriately, and don't set the now-removed > > > > > > orig_decl member. > > > > > > (norm_info::make_context): Remove, now that its only use is > > > > > > inlined into the caller. > > > > > > (norm_info::update_context): Adjust call to > > > > > > build_parameter_mapping to pass in the relevant set of > > > > > > in-scope > > > > > > template parameters. > > > > > > (norm_info::ctx_parms): Define this member function. > > > > > > (norm_info::context): Initialize to NULL_TREE. > > > > > > (norm_info::orig_decl): Remove this data member. > > > > > > (norm_info::initial_parms): Define this data member. > > > > > > (normalize_atom): Adjust call to build_parameter_mapping to > > > > > > pass > > > > > > in the relevant set of in-scope template parameters. Use > > > > > > info.initial_parms instead of info.orig_decl. > > > > > > (normalize_constraint_expression): Define an overload that > > > > > > takes > > > > > > a norm_info object. Cache the result of normalization. > > > > > > Define > > > > > > the other overload in terms of this one, and handle a > > > > > > NESTED_REQ > > > > > > argument by setting info.initial_parms appropriately. > > > > > > (tsubst_nested_requirement): Go through > > > > > > satisfy_constraint_expression so that we normalize on demand. > > > > > > (finish_nested_requirement): Set the TREE_TYPE of the > > > > > > NESTED_REQ > > > > > > to current_template_parms. > > > > > > (diagnose_nested_requirements): Go through > > > > > > satisfy_constraint_expression, as with > > > > > > tsubst_nested_requirement. > > > > > > --- > > > > > > gcc/cp/constraint.cc | 140 > > > > > > +++ > > > > > > gcc/cp/cp-tree.h | 4 +- > > > > > > 2 files changed, 78 insertions(+), 66 deletions(-) > > > > > > > > > > > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > > > > > > index 39c97986082..56134f8b2bf 100644 > > > > > > --- a/gcc/cp/constraint.cc > > > > > > +++ b/gcc/cp/constraint.cc > > > > > > @@ -133,7 +133,7 @@ struct sat_info : subst_info > > > > > > bool diagnose_unsatisfaction; > > > > > > }; > > > > > > -static tree satisfy_constraint (tree, tree, sat_info); > > > > > > +static tree satisfy_constraint_expression (tree, tree, sat_info); > > > > > > /* True if T is known to be some type other than bool. Note > > > > > > that > > > > > > this > > > > > >is false for dependent types and errors. */ > > > > > > @@ -594,26 +594,12 @@ map_a
Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On 2/28/21 12:40 PM, Patrick Palka wrote: On Fri, 12 Feb 2021, Jason Merrill wrote: On 2/10/21 9:41 AM, Patrick Palka wrote: On Tue, 9 Feb 2021, Jason Merrill wrote: On 2/8/21 2:03 PM, Patrick Palka wrote: This sets up the functionality for controlling the initial set of template parameters to pass to normalization when dealing with a constraint-expression that is not associated with some constrained declaration, for instance when normalizing a nested requirement of a requires expression, or the constraints on a placeholder type. The main new ingredient here is the data member norm_info::initial_parms which can be set by callers of the normalization routines to communicate the in-scope template parameters for the supplied constraint-expression, rather than always falling back to using current_template_parms. This patch then uses this functionality in our handling of nested requirements so that we can delay normalizing them until needed for satisfaction. We currently immediately normalize nested requirements at parse time, where we have the necessary template context, and cache the normal form in their TREE_TYPE node. With this patch, we now delay normalization until needed (as with other constraint expressions), and instead store the current value of current_template_parms in their TREE_TYPE node (which we use to restore the template context at normalization time). In the subsequent patch, this functionality will also be used to normalize placeholder type constraints during auto deduction. gcc/cp/ChangeLog: * constraint.cc (build_parameter_mapping): Rely on the caller to determine the in-scope template parameters. (norm_info::norm_info): Delegate the one-parameter constructor to the two-parameter constructor. In the two-parameter constructor, fold in the definition of make_context, set initial_parms appropriately, and don't set the now-removed orig_decl member. (norm_info::make_context): Remove, now that its only use is inlined into the caller. (norm_info::update_context): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. (norm_info::ctx_parms): Define this member function. (norm_info::context): Initialize to NULL_TREE. (norm_info::orig_decl): Remove this data member. (norm_info::initial_parms): Define this data member. (normalize_atom): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. Use info.initial_parms instead of info.orig_decl. (normalize_constraint_expression): Define an overload that takes a norm_info object. Cache the result of normalization. Define the other overload in terms of this one, and handle a NESTED_REQ argument by setting info.initial_parms appropriately. (tsubst_nested_requirement): Go through satisfy_constraint_expression so that we normalize on demand. (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ to current_template_parms. (diagnose_nested_requirements): Go through satisfy_constraint_expression, as with tsubst_nested_requirement. --- gcc/cp/constraint.cc | 140 +++ gcc/cp/cp-tree.h | 4 +- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 39c97986082..56134f8b2bf 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -133,7 +133,7 @@ struct sat_info : subst_info bool diagnose_unsatisfaction; }; -static tree satisfy_constraint (tree, tree, sat_info); +static tree satisfy_constraint_expression (tree, tree, sat_info); /* True if T is known to be some type other than bool. Note that this is false for dependent types and errors. */ @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) return parms; } -/* Build the parameter mapping for EXPR using ARGS. */ +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS + are the template parameters in scope for EXPR. */ static tree -build_parameter_mapping (tree expr, tree args, tree decl) +build_parameter_mapping (tree expr, tree args, tree ctx_parms) { - tree ctx_parms = NULL_TREE; - if (decl) -{ - gcc_assert (TREE_CODE (decl) == TEMPLATE_DECL); - ctx_parms = DECL_TEMPLATE_PARMS (decl); -} - else if (current_template_parms) -{ - /* TODO: This should probably be the only case, but because the -point of declaration of concepts is currently set after the -initializer, the template parameter lists are not available -when normalizing concept definitions, hence the case above. */ - ctx_parms = current_template_parms; -} - tree parms = find_template_parameters (expr, ctx_parms); tree map = map_arguments (parms,
Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On Fri, 12 Feb 2021, Jason Merrill wrote: > On 2/10/21 9:41 AM, Patrick Palka wrote: > > On Tue, 9 Feb 2021, Jason Merrill wrote: > > > > > On 2/8/21 2:03 PM, Patrick Palka wrote: > > > > This sets up the functionality for controlling the initial set of > > > > template parameters to pass to normalization when dealing with a > > > > constraint-expression that is not associated with some constrained > > > > declaration, for instance when normalizing a nested requirement of a > > > > requires expression, or the constraints on a placeholder type. > > > > > > > > The main new ingredient here is the data member norm_info::initial_parms > > > > which can be set by callers of the normalization routines to communicate > > > > the in-scope template parameters for the supplied constraint-expression, > > > > rather than always falling back to using current_template_parms. > > > > > > > > This patch then uses this functionality in our handling of nested > > > > requirements so that we can delay normalizing them until needed for > > > > satisfaction. We currently immediately normalize nested requirements at > > > > parse time, where we have the necessary template context, and cache the > > > > normal form in their TREE_TYPE node. With this patch, we now delay > > > > normalization until needed (as with other constraint expressions), and > > > > instead store the current value of current_template_parms in their > > > > TREE_TYPE node (which we use to restore the template context at > > > > normalization time). > > > > > > > > In the subsequent patch, this functionality will also be used to > > > > normalize placeholder type constraints during auto deduction. > > > > > > > > gcc/cp/ChangeLog: > > > > > > > > * constraint.cc (build_parameter_mapping): Rely on the caller to > > > > determine the in-scope template parameters. > > > > (norm_info::norm_info): Delegate the one-parameter constructor > > > > to the two-parameter constructor. In the two-parameter > > > > constructor, fold in the definition of make_context, set > > > > initial_parms appropriately, and don't set the now-removed > > > > orig_decl member. > > > > (norm_info::make_context): Remove, now that its only use is > > > > inlined into the caller. > > > > (norm_info::update_context): Adjust call to > > > > build_parameter_mapping to pass in the relevant set of in-scope > > > > template parameters. > > > > (norm_info::ctx_parms): Define this member function. > > > > (norm_info::context): Initialize to NULL_TREE. > > > > (norm_info::orig_decl): Remove this data member. > > > > (norm_info::initial_parms): Define this data member. > > > > (normalize_atom): Adjust call to build_parameter_mapping to pass > > > > in the relevant set of in-scope template parameters. Use > > > > info.initial_parms instead of info.orig_decl. > > > > (normalize_constraint_expression): Define an overload that takes > > > > a norm_info object. Cache the result of normalization. Define > > > > the other overload in terms of this one, and handle a NESTED_REQ > > > > argument by setting info.initial_parms appropriately. > > > > (tsubst_nested_requirement): Go through > > > > satisfy_constraint_expression so that we normalize on demand. > > > > (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ > > > > to current_template_parms. > > > > (diagnose_nested_requirements): Go through > > > > satisfy_constraint_expression, as with > > > > tsubst_nested_requirement. > > > > --- > > > >gcc/cp/constraint.cc | 140 > > > > +++ > > > >gcc/cp/cp-tree.h | 4 +- > > > >2 files changed, 78 insertions(+), 66 deletions(-) > > > > > > > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > > > > index 39c97986082..56134f8b2bf 100644 > > > > --- a/gcc/cp/constraint.cc > > > > +++ b/gcc/cp/constraint.cc > > > > @@ -133,7 +133,7 @@ struct sat_info : subst_info > > > > bool diagnose_unsatisfaction; > > > >}; > > > >-static tree satisfy_constraint (tree, tree, sat_info); > > > > +static tree satisfy_constraint_expression (tree, tree, sat_info); > > > > /* True if T is known to be some type other than bool. Note that > > > > this > > > > is false for dependent types and errors. */ > > > > @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) > > > > return parms; > > > >} > > > >-/* Build the parameter mapping for EXPR using ARGS. */ > > > > +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS > > > > + are the template parameters in scope for EXPR. */ > > > > static tree > > > > -build_parameter_mapping (tree expr, tree args, tree decl) > > > > +build_parameter_mapping (tree expr, tree args, tree ctx_parms) > > > >{ > > > > -
Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On 2/10/21 9:41 AM, Patrick Palka wrote: On Tue, 9 Feb 2021, Jason Merrill wrote: On 2/8/21 2:03 PM, Patrick Palka wrote: This sets up the functionality for controlling the initial set of template parameters to pass to normalization when dealing with a constraint-expression that is not associated with some constrained declaration, for instance when normalizing a nested requirement of a requires expression, or the constraints on a placeholder type. The main new ingredient here is the data member norm_info::initial_parms which can be set by callers of the normalization routines to communicate the in-scope template parameters for the supplied constraint-expression, rather than always falling back to using current_template_parms. This patch then uses this functionality in our handling of nested requirements so that we can delay normalizing them until needed for satisfaction. We currently immediately normalize nested requirements at parse time, where we have the necessary template context, and cache the normal form in their TREE_TYPE node. With this patch, we now delay normalization until needed (as with other constraint expressions), and instead store the current value of current_template_parms in their TREE_TYPE node (which we use to restore the template context at normalization time). In the subsequent patch, this functionality will also be used to normalize placeholder type constraints during auto deduction. gcc/cp/ChangeLog: * constraint.cc (build_parameter_mapping): Rely on the caller to determine the in-scope template parameters. (norm_info::norm_info): Delegate the one-parameter constructor to the two-parameter constructor. In the two-parameter constructor, fold in the definition of make_context, set initial_parms appropriately, and don't set the now-removed orig_decl member. (norm_info::make_context): Remove, now that its only use is inlined into the caller. (norm_info::update_context): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. (norm_info::ctx_parms): Define this member function. (norm_info::context): Initialize to NULL_TREE. (norm_info::orig_decl): Remove this data member. (norm_info::initial_parms): Define this data member. (normalize_atom): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. Use info.initial_parms instead of info.orig_decl. (normalize_constraint_expression): Define an overload that takes a norm_info object. Cache the result of normalization. Define the other overload in terms of this one, and handle a NESTED_REQ argument by setting info.initial_parms appropriately. (tsubst_nested_requirement): Go through satisfy_constraint_expression so that we normalize on demand. (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ to current_template_parms. (diagnose_nested_requirements): Go through satisfy_constraint_expression, as with tsubst_nested_requirement. --- gcc/cp/constraint.cc | 140 +++ gcc/cp/cp-tree.h | 4 +- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 39c97986082..56134f8b2bf 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -133,7 +133,7 @@ struct sat_info : subst_info bool diagnose_unsatisfaction; }; -static tree satisfy_constraint (tree, tree, sat_info); +static tree satisfy_constraint_expression (tree, tree, sat_info); /* True if T is known to be some type other than bool. Note that this is false for dependent types and errors. */ @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) return parms; } -/* Build the parameter mapping for EXPR using ARGS. */ +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS + are the template parameters in scope for EXPR. */ static tree -build_parameter_mapping (tree expr, tree args, tree decl) +build_parameter_mapping (tree expr, tree args, tree ctx_parms) { - tree ctx_parms = NULL_TREE; - if (decl) -{ - gcc_assert (TREE_CODE (decl) == TEMPLATE_DECL); - ctx_parms = DECL_TEMPLATE_PARMS (decl); -} - else if (current_template_parms) -{ - /* TODO: This should probably be the only case, but because the -point of declaration of concepts is currently set after the -initializer, the template parameter lists are not available -when normalizing concept definitions, hence the case above. */ - ctx_parms = current_template_parms; -} - tree parms = find_template_parameters (expr, ctx_parms); tree map = map_arguments (parms, args); return map; @@ -645,53 +631,63 @@ parameter_mapping_equivalent_p (tree t1, tree t2)
Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On Tue, 9 Feb 2021, Jason Merrill wrote: > On 2/8/21 2:03 PM, Patrick Palka wrote: > > This sets up the functionality for controlling the initial set of > > template parameters to pass to normalization when dealing with a > > constraint-expression that is not associated with some constrained > > declaration, for instance when normalizing a nested requirement of a > > requires expression, or the constraints on a placeholder type. > > > > The main new ingredient here is the data member norm_info::initial_parms > > which can be set by callers of the normalization routines to communicate > > the in-scope template parameters for the supplied constraint-expression, > > rather than always falling back to using current_template_parms. > > > > This patch then uses this functionality in our handling of nested > > requirements so that we can delay normalizing them until needed for > > satisfaction. We currently immediately normalize nested requirements at > > parse time, where we have the necessary template context, and cache the > > normal form in their TREE_TYPE node. With this patch, we now delay > > normalization until needed (as with other constraint expressions), and > > instead store the current value of current_template_parms in their > > TREE_TYPE node (which we use to restore the template context at > > normalization time). > > > > In the subsequent patch, this functionality will also be used to > > normalize placeholder type constraints during auto deduction. > > > > gcc/cp/ChangeLog: > > > > * constraint.cc (build_parameter_mapping): Rely on the caller to > > determine the in-scope template parameters. > > (norm_info::norm_info): Delegate the one-parameter constructor > > to the two-parameter constructor. In the two-parameter > > constructor, fold in the definition of make_context, set > > initial_parms appropriately, and don't set the now-removed > > orig_decl member. > > (norm_info::make_context): Remove, now that its only use is > > inlined into the caller. > > (norm_info::update_context): Adjust call to > > build_parameter_mapping to pass in the relevant set of in-scope > > template parameters. > > (norm_info::ctx_parms): Define this member function. > > (norm_info::context): Initialize to NULL_TREE. > > (norm_info::orig_decl): Remove this data member. > > (norm_info::initial_parms): Define this data member. > > (normalize_atom): Adjust call to build_parameter_mapping to pass > > in the relevant set of in-scope template parameters. Use > > info.initial_parms instead of info.orig_decl. > > (normalize_constraint_expression): Define an overload that takes > > a norm_info object. Cache the result of normalization. Define > > the other overload in terms of this one, and handle a NESTED_REQ > > argument by setting info.initial_parms appropriately. > > (tsubst_nested_requirement): Go through > > satisfy_constraint_expression so that we normalize on demand. > > (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ > > to current_template_parms. > > (diagnose_nested_requirements): Go through > > satisfy_constraint_expression, as with tsubst_nested_requirement. > > --- > > gcc/cp/constraint.cc | 140 +++ > > gcc/cp/cp-tree.h | 4 +- > > 2 files changed, 78 insertions(+), 66 deletions(-) > > > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > > index 39c97986082..56134f8b2bf 100644 > > --- a/gcc/cp/constraint.cc > > +++ b/gcc/cp/constraint.cc > > @@ -133,7 +133,7 @@ struct sat_info : subst_info > > bool diagnose_unsatisfaction; > > }; > > -static tree satisfy_constraint (tree, tree, sat_info); > > +static tree satisfy_constraint_expression (tree, tree, sat_info); > > /* True if T is known to be some type other than bool. Note that this > > is false for dependent types and errors. */ > > @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) > > return parms; > > } > > -/* Build the parameter mapping for EXPR using ARGS. */ > > +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS > > + are the template parameters in scope for EXPR. */ > > static tree > > -build_parameter_mapping (tree expr, tree args, tree decl) > > +build_parameter_mapping (tree expr, tree args, tree ctx_parms) > > { > > - tree ctx_parms = NULL_TREE; > > - if (decl) > > -{ > > - gcc_assert (TREE_CODE (decl) == TEMPLATE_DECL); > > - ctx_parms = DECL_TEMPLATE_PARMS (decl); > > -} > > - else if (current_template_parms) > > -{ > > - /* TODO: This should probably be the only case, but because the > > -point of declaration of concepts is currently set after the > > -initializer, the template parameter lists are not available > > -when normalizing concept definitions, hence the case above. */ > > - ctx_parms = current_template_parms; > > -} > > - >
Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On 2/9/21 6:04 PM, Jason Merrill wrote: On 2/8/21 2:03 PM, Patrick Palka wrote: This sets up the functionality for controlling the initial set of template parameters to pass to normalization when dealing with a constraint-expression that is not associated with some constrained declaration, for instance when normalizing a nested requirement of a requires expression, or the constraints on a placeholder type. The main new ingredient here is the data member norm_info::initial_parms which can be set by callers of the normalization routines to communicate the in-scope template parameters for the supplied constraint-expression, rather than always falling back to using current_template_parms. This patch then uses this functionality in our handling of nested requirements so that we can delay normalizing them until needed for satisfaction. We currently immediately normalize nested requirements at parse time, where we have the necessary template context, and cache the normal form in their TREE_TYPE node. With this patch, we now delay normalization until needed (as with other constraint expressions), and instead store the current value of current_template_parms in their TREE_TYPE node (which we use to restore the template context at normalization time). In the subsequent patch, this functionality will also be used to normalize placeholder type constraints during auto deduction. gcc/cp/ChangeLog: * constraint.cc (build_parameter_mapping): Rely on the caller to determine the in-scope template parameters. (norm_info::norm_info): Delegate the one-parameter constructor to the two-parameter constructor. In the two-parameter constructor, fold in the definition of make_context, set initial_parms appropriately, and don't set the now-removed orig_decl member. (norm_info::make_context): Remove, now that its only use is inlined into the caller. (norm_info::update_context): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. (norm_info::ctx_parms): Define this member function. (norm_info::context): Initialize to NULL_TREE. (norm_info::orig_decl): Remove this data member. (norm_info::initial_parms): Define this data member. (normalize_atom): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. Use info.initial_parms instead of info.orig_decl. (normalize_constraint_expression): Define an overload that takes a norm_info object. Cache the result of normalization. Define the other overload in terms of this one, and handle a NESTED_REQ argument by setting info.initial_parms appropriately. (tsubst_nested_requirement): Go through satisfy_constraint_expression so that we normalize on demand. (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ to current_template_parms. (diagnose_nested_requirements): Go through satisfy_constraint_expression, as with tsubst_nested_requirement. --- gcc/cp/constraint.cc | 140 +++ gcc/cp/cp-tree.h | 4 +- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 39c97986082..56134f8b2bf 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -133,7 +133,7 @@ struct sat_info : subst_info bool diagnose_unsatisfaction; }; -static tree satisfy_constraint (tree, tree, sat_info); +static tree satisfy_constraint_expression (tree, tree, sat_info); /* True if T is known to be some type other than bool. Note that this is false for dependent types and errors. */ @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) return parms; } -/* Build the parameter mapping for EXPR using ARGS. */ +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS + are the template parameters in scope for EXPR. */ static tree -build_parameter_mapping (tree expr, tree args, tree decl) +build_parameter_mapping (tree expr, tree args, tree ctx_parms) { - tree ctx_parms = NULL_TREE; - if (decl) - { - gcc_assert (TREE_CODE (decl) == TEMPLATE_DECL); - ctx_parms = DECL_TEMPLATE_PARMS (decl); - } - else if (current_template_parms) - { - /* TODO: This should probably be the only case, but because the - point of declaration of concepts is currently set after the - initializer, the template parameter lists are not available - when normalizing concept definitions, hence the case above. */ - ctx_parms = current_template_parms; - } - tree parms = find_template_parameters (expr, ctx_parms); tree map = map_arguments (parms, args); return map; @@ -645,53 +631,63 @@ parameter_mapping_equivalent_p (tree t1, tree t2) struct norm_info : subst_info { - explicit norm_info (tsubst_flags_t complain) - : subst_info (tf_warning_or_error | complain, NULL_TREE), - context() + explicit norm_info (tsubst_flag
Re: [PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
On 2/8/21 2:03 PM, Patrick Palka wrote: This sets up the functionality for controlling the initial set of template parameters to pass to normalization when dealing with a constraint-expression that is not associated with some constrained declaration, for instance when normalizing a nested requirement of a requires expression, or the constraints on a placeholder type. The main new ingredient here is the data member norm_info::initial_parms which can be set by callers of the normalization routines to communicate the in-scope template parameters for the supplied constraint-expression, rather than always falling back to using current_template_parms. This patch then uses this functionality in our handling of nested requirements so that we can delay normalizing them until needed for satisfaction. We currently immediately normalize nested requirements at parse time, where we have the necessary template context, and cache the normal form in their TREE_TYPE node. With this patch, we now delay normalization until needed (as with other constraint expressions), and instead store the current value of current_template_parms in their TREE_TYPE node (which we use to restore the template context at normalization time). In the subsequent patch, this functionality will also be used to normalize placeholder type constraints during auto deduction. gcc/cp/ChangeLog: * constraint.cc (build_parameter_mapping): Rely on the caller to determine the in-scope template parameters. (norm_info::norm_info): Delegate the one-parameter constructor to the two-parameter constructor. In the two-parameter constructor, fold in the definition of make_context, set initial_parms appropriately, and don't set the now-removed orig_decl member. (norm_info::make_context): Remove, now that its only use is inlined into the caller. (norm_info::update_context): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. (norm_info::ctx_parms): Define this member function. (norm_info::context): Initialize to NULL_TREE. (norm_info::orig_decl): Remove this data member. (norm_info::initial_parms): Define this data member. (normalize_atom): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. Use info.initial_parms instead of info.orig_decl. (normalize_constraint_expression): Define an overload that takes a norm_info object. Cache the result of normalization. Define the other overload in terms of this one, and handle a NESTED_REQ argument by setting info.initial_parms appropriately. (tsubst_nested_requirement): Go through satisfy_constraint_expression so that we normalize on demand. (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ to current_template_parms. (diagnose_nested_requirements): Go through satisfy_constraint_expression, as with tsubst_nested_requirement. --- gcc/cp/constraint.cc | 140 +++ gcc/cp/cp-tree.h | 4 +- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 39c97986082..56134f8b2bf 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -133,7 +133,7 @@ struct sat_info : subst_info bool diagnose_unsatisfaction; }; -static tree satisfy_constraint (tree, tree, sat_info); +static tree satisfy_constraint_expression (tree, tree, sat_info); /* True if T is known to be some type other than bool. Note that this is false for dependent types and errors. */ @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) return parms; } -/* Build the parameter mapping for EXPR using ARGS. */ +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS + are the template parameters in scope for EXPR. */ static tree -build_parameter_mapping (tree expr, tree args, tree decl) +build_parameter_mapping (tree expr, tree args, tree ctx_parms) { - tree ctx_parms = NULL_TREE; - if (decl) -{ - gcc_assert (TREE_CODE (decl) == TEMPLATE_DECL); - ctx_parms = DECL_TEMPLATE_PARMS (decl); -} - else if (current_template_parms) -{ - /* TODO: This should probably be the only case, but because the -point of declaration of concepts is currently set after the -initializer, the template parameter lists are not available -when normalizing concept definitions, hence the case above. */ - ctx_parms = current_template_parms; -} - tree parms = find_template_parameters (expr, ctx_parms); tree map = map_arguments (parms, args); return map; @@ -645,53 +631,63 @@ parameter_mapping_equivalent_p (tree t1, tree t2) struct norm_info : subst_info { - explicit norm_info (tsubst_flags_t complain) -: sub
[PATCH 3/4] c++: Delay normalizing nested requirements until satisfaction
This sets up the functionality for controlling the initial set of template parameters to pass to normalization when dealing with a constraint-expression that is not associated with some constrained declaration, for instance when normalizing a nested requirement of a requires expression, or the constraints on a placeholder type. The main new ingredient here is the data member norm_info::initial_parms which can be set by callers of the normalization routines to communicate the in-scope template parameters for the supplied constraint-expression, rather than always falling back to using current_template_parms. This patch then uses this functionality in our handling of nested requirements so that we can delay normalizing them until needed for satisfaction. We currently immediately normalize nested requirements at parse time, where we have the necessary template context, and cache the normal form in their TREE_TYPE node. With this patch, we now delay normalization until needed (as with other constraint expressions), and instead store the current value of current_template_parms in their TREE_TYPE node (which we use to restore the template context at normalization time). In the subsequent patch, this functionality will also be used to normalize placeholder type constraints during auto deduction. gcc/cp/ChangeLog: * constraint.cc (build_parameter_mapping): Rely on the caller to determine the in-scope template parameters. (norm_info::norm_info): Delegate the one-parameter constructor to the two-parameter constructor. In the two-parameter constructor, fold in the definition of make_context, set initial_parms appropriately, and don't set the now-removed orig_decl member. (norm_info::make_context): Remove, now that its only use is inlined into the caller. (norm_info::update_context): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. (norm_info::ctx_parms): Define this member function. (norm_info::context): Initialize to NULL_TREE. (norm_info::orig_decl): Remove this data member. (norm_info::initial_parms): Define this data member. (normalize_atom): Adjust call to build_parameter_mapping to pass in the relevant set of in-scope template parameters. Use info.initial_parms instead of info.orig_decl. (normalize_constraint_expression): Define an overload that takes a norm_info object. Cache the result of normalization. Define the other overload in terms of this one, and handle a NESTED_REQ argument by setting info.initial_parms appropriately. (tsubst_nested_requirement): Go through satisfy_constraint_expression so that we normalize on demand. (finish_nested_requirement): Set the TREE_TYPE of the NESTED_REQ to current_template_parms. (diagnose_nested_requirements): Go through satisfy_constraint_expression, as with tsubst_nested_requirement. --- gcc/cp/constraint.cc | 140 +++ gcc/cp/cp-tree.h | 4 +- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 39c97986082..56134f8b2bf 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -133,7 +133,7 @@ struct sat_info : subst_info bool diagnose_unsatisfaction; }; -static tree satisfy_constraint (tree, tree, sat_info); +static tree satisfy_constraint_expression (tree, tree, sat_info); /* True if T is known to be some type other than bool. Note that this is false for dependent types and errors. */ @@ -594,26 +594,12 @@ map_arguments (tree parms, tree args) return parms; } -/* Build the parameter mapping for EXPR using ARGS. */ +/* Build the parameter mapping for EXPR using ARGS, where CTX_PARMS + are the template parameters in scope for EXPR. */ static tree -build_parameter_mapping (tree expr, tree args, tree decl) +build_parameter_mapping (tree expr, tree args, tree ctx_parms) { - tree ctx_parms = NULL_TREE; - if (decl) -{ - gcc_assert (TREE_CODE (decl) == TEMPLATE_DECL); - ctx_parms = DECL_TEMPLATE_PARMS (decl); -} - else if (current_template_parms) -{ - /* TODO: This should probably be the only case, but because the -point of declaration of concepts is currently set after the -initializer, the template parameter lists are not available -when normalizing concept definitions, hence the case above. */ - ctx_parms = current_template_parms; -} - tree parms = find_template_parameters (expr, ctx_parms); tree map = map_arguments (parms, args); return map; @@ -645,53 +631,63 @@ parameter_mapping_equivalent_p (tree t1, tree t2) struct norm_info : subst_info { - explicit norm_info (tsubst_flags_t complain) -: subst_info (tf_warning_or_error | complain, NULL_TREE), - context(