This is an archive of the discontinued LLVM Phabricator instance.

[modules] Move generation counter from ExternalASTSource to ASTContext
Changes PlannedPublic

Authored by teemperor on Nov 6 2017, 11:18 PM.

Details

Reviewers
rsmith
Summary

The generation counter mechanism of the AST is currently implemented inside the ExternalASTSource. These counters
work as intended with clang's module setup, but causes problems with cling and ROOT's setup:

In cling we attach multiple ExternalASTSources which will cause the ASTReader to fail. The ASTReader assumes it's the
only attached external source. So it will increase it's own generation counter and then reads the top-level generation
counter of the ASTContext to get back it's own generation counter.

In ROOT we also attach after cling's startup another ExternalASTSource which will further disrupt existing generation
counters. The new multiplexer that is added as the new top level source will essentially reset all existing generation
counters back to zero.

This patch fixes those problems by merging all generation counters into a single one in the ASTContext. This
prevents that sometimes we are incrementing and then reading the different counters. It also prevents
that attaching a new counter or having multiple counters suddenly forces us to keep all those counters
in a consistent state.

Diff Detail

Event Timeline

teemperor created this revision.Nov 6 2017, 11:18 PM
teemperor edited the summary of this revision. (Show Details)
teemperor retitled this revision from Move generation counter from External AST source to ASTContext to [modules] Move generation counter from ExternalASTSource to ASTContext.
teemperor edited the summary of this revision. (Show Details)
teemperor added a reviewer: rsmith.
teemperor added a subscriber: v.g.vassilev.
rsmith added inline comments.Mar 27 2018, 11:46 AM
include/clang/AST/ExternalASTSource.h
461–464

Is there a reason to ask the ExternalASTSource for the generation here rather than directly asking the ASTContext? (Is there any circumstance in which we would expect or even allow them to return different numbers?)

teemperor added inline comments.Mar 27 2018, 12:24 PM
include/clang/AST/ExternalASTSource.h
461–464

ASTContext and ExternalASTSource reference each other and this header only got the fwd decl of ASTContext. Calling it via the ExtASTSource (which works around the fact that we only have a fwd decl) and following the existing workarounds was just less invasive than trying to cleanup this cyclic dependency :)

rsmith added inline comments.Mar 27 2018, 5:43 PM
include/clang/AST/ExternalASTSource.h
461–464

Hm, I'd prefer an approach that we can inline away without IPO. At least we should avoid calling getGeneration twice here.

teemperor planned changes to this revision.Aug 28 2018, 10:54 AM

(Setting this to "Plan changes" so that I know this is waiting on me).