[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

Matheus Izvekov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 20 09:16:55 PDT 2022


mizvekov added a comment.

In D133468#3802727 <https://reviews.llvm.org/D133468#3802727>, @davrec wrote:

> what is the different principle behind choosing a different underlying type?   Why can't the underlying type for `t29`/`t32` be sugar for X1 and friends too?

The underlying type is taken from the mechanism implemented in D130308 <https://reviews.llvm.org/D130308>, but it's not a different principle. We are still trying to keep the information they have in common, and go towards the canonical state when there is a difference.

> If we absolutely have to allow these types to diverge, we need very good documentation that helps them answer this.

We are adding the minimum amount of new information to the AST to get what we want: A TypedefType which can have an underlying different from the one in the declaration it references.
This is the minimum we need in order to be able to represent a resugared typedef, without losing the information that the type came from a typedef in the first place.

Otherwise, just knowing that they can diverge doesn't help much, they would still be missing the reason of why they diverged, and that will depend on what mechanisms were at play.

There is an engineering compromise in that we don't want to pack new AST nodes that help fully expose that some divergence was created either by type combination, or by template specialization resugaring (when that is implemented), to avoid ballooning complexity with information that might not be useful.

But if that information were important, that could justify the cost in memory and complexity. Do you foresee any need for it?

Otherwise, the `isDivergent()` flag is there just for exposition / debugging purposes when looking at the AST dump, as I find that helpful.
But we could not add the method and not print a flag in the AST dumper, implementing just the behavior change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133468/new/

https://reviews.llvm.org/D133468



More information about the cfe-commits mailing list