[PCH] When pre-validating the headers from the PCH, only validate non-system headers.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 6 Mar 2013 18:12:50 +0000 (18:12 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 6 Mar 2013 18:12:50 +0000 (18:12 +0000)
commit7d23857a07de0aaa0d4a50cf4fe7d32ab86190ae
tree1139769c2e9c4ab70f7c42a90491dad592b1b02d
parent5c2a345e4847c3913cccdecfe6429e09d8d2b1a8
[PCH] When pre-validating the headers from the PCH, only validate non-system headers.

Stat'ing all the headers from the PCH to make sure they are up-to-date takes significant time.
In a particular source file (whose PCH file included Cocoa.h) from total -fsyntax-only time
12% was just stat calls. Change pre-validation to only check non-system headers.

There are some notable disadvantages:

-If a system header, that is not include-guarded, changes after the PCH was created, we will not
find it in the header info table and we will #import it, effectively #importing it twice, thus
we will emit some error due to a multiple definition and after that the "header was modified" error will likely
be emitted, for example something like:

NSDictionary.h:12:1: error: duplicate interface definition for class 'NSDictionary'
@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSSecureCoding, NSFastEnumeration>
^
NSDictionary.h:12:12: note: previous definition is here
@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSSecureCoding, NSFastEnumeration>
           ^
fatal error: file 'NSDictionary.h' has been modified since the precompiled header was built

Though we get the "header was modified" error, this is a bit confusing.

-Theoretically it is possible that such a system header will cause no errors but it will just cause an
unfortunate semantic change, though I find this rather unlikely.

The advantages:

-Reduces compilation time when using a huge PCH like the Cocoa ones
-System headers change very infrequent and when they do, users/build systems should be able to know that
re-building from scratch is needed.

Addresses rdar://13056262

llvm-svn: 176567
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp