This is an archive of the discontinued LLVM Phabricator instance.

[AST] NFC: Introduce new class GenericSelectionExpr::Association
AbandonedPublic

Authored by steveire on Jan 19 2019, 4:11 AM.

Details

Summary

As a type, this can be visited upon. This is similar in spirit to the
BlockDecl::Capture type.

Diff Detail

Event Timeline

steveire created this revision.Jan 19 2019, 4:11 AM
riccibruno added inline comments.
include/clang/AST/Expr.h
5020

I know that this is not part of this patch, but these arrays are begging
to be tail-allocated if you want to have a go at it.

5047

What about some comments ? I can guess but it is better to have
too much doc than not enough imho.

aaron.ballman added inline comments.Jan 21 2019, 5:34 AM
include/clang/AST/Expr.h
5068

Rather than gin these objects up on demand every time they're needed, I'd prefer to see the class store Association objects directly. I don't think it will be easy to do that and still support getAssocExprs() and getAssocTypeSourceInfos(), so I think those APIs should be removed in favor of this one. There's currently not many uses of getAssocExprs() or getAssocTypeSourceInfos() (I spot one each in Clang) so migration to the new API should not be onerous.

This should also have a range-based accessor version so that users aren't required to use iterative loops to access the information (a lot of the places you're already touching could use that range-based interface).

lib/AST/ASTDumper.cpp
1467

Don't use auto here.

lib/AST/StmtPrinter.cpp
1266

Don't use auto.

lib/AST/StmtProfile.cpp
1263

Or here (or anywhere similar in this patch; I'll stop commenting on them).

steveire marked 2 inline comments as done.Jan 21 2019, 5:51 AM
steveire added inline comments.
include/clang/AST/Expr.h
5068

I would prefer that too, but it doesn't seem to be possible. This is a sub-range of the SubExprs returned from children().

In theory, that could be split into two members, but then you would need a range library to recombine them and implement children(): https://godbolt.org/z/ZVamdC

This seems to be the best approach for now, and AFAIK it excludes a range-accessor.

aaron.ballman added inline comments.Jan 21 2019, 7:07 AM
include/clang/AST/Expr.h
5068

I would prefer that too, but it doesn't seem to be possible. This is a sub-range of the SubExprs returned from children().

Ugh, you're right. :-(

In theory, that could be split into two members, but then you would need a range library to recombine them and implement children(): https://godbolt.org/z/ZVamdC

We have zip iterators that could be used to implement this, I believe. (see STLExtras.h)

Alternatively, we could tail-allocate the Association objects with (perhaps references to) pointers back into the Expr tail-allocated array. Not ideal, but does provide a clean interface.

@riccibruno may have other ideas on how to pack the arrays, as he's done a lot of this work recently.

steveire marked an inline comment as done.Jan 21 2019, 7:37 AM
steveire added inline comments.
include/clang/AST/Expr.h
5068

We have zip iterators that could be used to implement this, I believe.

You're right, there is a concat there, but on second thought - because Association and Stmt don't share a base, I don't think it can work.

Alternatively, we could tail-allocate the Association objects with (perhaps references to) pointers back into the Expr tail-allocated array. Not ideal, but does provide a clean interface.

Perhaps this can work, but I don't know how to do it. If you have scope for it in your part of the efforts, it would be a good way to get this unblocked.

aaron.ballman added inline comments.Jan 21 2019, 7:58 AM
include/clang/AST/Expr.h
5068

Perhaps this can work, but I don't know how to do it. If you have scope for it in your part of the efforts, it would be a good way to get this unblocked.

I'll put some time into it today and see where it goes. You may be right that this is more work than it's worth, so we'll see.

riccibruno added inline comments.Jan 21 2019, 8:37 AM
include/clang/AST/Expr.h
5068

I don't see what would prevent tail-allocating the array of sub-expression and the array of TypeSourceInfo, and removing the getAssocExpr, getAssocTypeSourceInfo, getAssocType interface in favor of a single getAssociation. Then create a range version of getAssociation using the fact that if you know where you are in the sub-expression array, you know where is the corresponding TypeSourceInfo. To know which index correspond to the selected sub-expression you could use one of the low bits in the TypeSourceInfo pointers.

This means that children is still simple to implement, and users can use a single unified
interface via getAssociation and the range version associations(). From the point of view of the users it would be like if the Association objects were stored contiguously.

Some small additional remarks if you are already modifying this class.

include/clang/AST/Expr.h
5021

It is possible to stuff one SourceLocation in the bit-fields of Stmt to save one more pointer.

5113

I believe these LLVM_READONLY are pointless here.

5125

Move this friend decl to the top ?

riccibruno added inline comments.Jan 23 2019, 6:19 AM
include/clang/AST/Expr.h
5068

Made a patch which roughly the above idea: D57098

steveire abandoned this revision.Jan 29 2019, 3:24 PM

An alternative was written and committed.