]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: cache the normal form of a concept-id
authorPatrick Palka <ppalka@redhat.com>
Sun, 20 Nov 2022 18:02:24 +0000 (13:02 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sun, 20 Nov 2022 18:02:24 +0000 (13:02 -0500)
commit1ad735dbfcce07dd913f82308619324171825c58
tree5c582e002eaf2fcd0b57c1600f3a7299ae59a3ee
parentb36a5f8404d7c3681435b497ef6b27d69cba0a14
c++: cache the normal form of a concept-id

We already cache the overall normal form of a declaration's constraints
(under the assumption that it can't change over the translation unit).
But if we have something like

  template<class T> concept complicated = /* ... */;
  template<class T> void f() requires complicated<T> && /* ... */;
  template<class T> void g() requires complicated<T> && /* ... */;

then despite this high-level caching we'd still redundantly have to
expand the concept-id complicated<T> twice, once during normalization of
f's constraints and again during normalization of g's.  Ideally, we'd
reuse the previously computed normal form of complicated<T> the second
time around.

To that end this patch introduces an intermediate layer of caching
during constraint normalization -- caching of the normal form of a
concept-id -- that sits between our high-level caching of the overall
normal form of a declaration's constraints and our low-level caching of
each individual atomic constraint.

It turns out this caching generalizes normalize_concept_check's caching
of the normal form of a concept definition (which is equivalent to the
normal form of the concept-id C<gtargs> where gtargs is C's generic
arguments) so this patch unifies the caching accordingly.

gcc/cp/ChangeLog:

* constraint.cc (struct norm_entry): Define.
(struct norm_hasher): Define.
(norm_cache): Define.
(normalize_concept_check): Add function comment.  Cache the
the normal form of the substituted concept-id.  Canonicalize
generic arguments as NULL_TREE.  Don't coerce arguments unless
they were substituted.
(normalize_concept_definition): Simplify.  Use norm_cache
instead of normalized_map.
gcc/cp/constraint.cc