aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/ModuleManager.cpp
AgeCommit message (Collapse)AuthorFilesLines
2014-11-21[modules] When explicitly importing a module, it's fine for the imported moduleRichard Smith1-0/+7
to be newer than we were expecting. That happens if .pcm's get moved between file systems during a distributed build. (It's still not OK for them to actually be different, though, so we still check the size and signature matches.) llvm-svn: 222507
2014-11-08Check module signature when the module has already been loadedBen Langmuir1-7/+13
We may need to verify the signature on subsequent imports as well, just like we verify the size/modtime: @import A; @import B; // imports A @import C; // imports A llvm-svn: 221569
2014-10-26Make VFS and FileManager match the current MemoryBuffer API.Benjamin Kramer1-13/+12
This eliminates converting back and forth between the 3 formats and gives us a more homogeneous interface. llvm-svn: 220657
2014-10-24[Modules] Free modules that failed signature verification.Benjamin Kramer1-0/+1
The control flow and ownership is weird enough so unique_ptr doesn't help here :( llvm-svn: 220569
2014-10-23Add a "signature" to AST files to verify that they haven't changedBen Langmuir1-0/+18
Since the order of the IDs in the AST file (e.g. DeclIDs, SelectorIDs) is not stable, it is not safe to load an AST file that depends on another AST file that has been rebuilt since the importer was built, even if "nothing changed". We previously used size and modtime to check this, but I've seen cases where a module rebuilt quickly enough to foil this check and caused very hard to debug build errors. To save cycles when we're loading the AST, we just generate a random nonce value and check that it hasn't changed when we load an imported module, rather than actually hash the whole file. This is slightly complicated by the fact that we need to verify the signature inside addModule, since we might otherwise consider that a mdoule is "OutOfDate" when really it is the importer that is out of date. I didn't see any regressions in module load time after this change. llvm-svn: 220493
2014-10-22[modules] Initial support for explicitly loading .pcm files.Richard Smith1-1/+1
Implicit module builds are not well-suited to a lot of build systems. In particular, they fare badly in distributed build systems, and they lead to build artifacts that are not tracked as part of the usual dependency management process. This change allows explicitly-built module files (which are already supported through the -emit-module flag) to be explicitly loaded into a build, allowing build systems to opt to manage module builds and dependencies themselves. This is only the first step in supporting such configurations, and it should be considered experimental and subject to change or removal for now. llvm-svn: 220359
2014-08-26Return a std::unique_ptr from getBufferForFile. NFC.Rafael Espindola1-3/+3
llvm-svn: 216476
2014-08-18Store std::unique_ptr in InMemoryBuffers. NFC.Rafael Espindola1-11/+12
llvm-svn: 215928
2014-08-17Repace SmallPtrSet with SmallPtrSetImpl in function arguments to avoid ↵Craig Topper1-1/+1
needing to mention the size. llvm-svn: 215869
2014-07-06Update for llvm api change.Rafael Espindola1-1/+5
llvm-svn: 212408
2014-06-20Avoid invalidating successfully loaded module filesBen Langmuir1-22/+17
Successfully loaded module files may be referenced in other ModuleManagers, so don't invalidate them. Two related things are fixed: 1) I thought the last module in the manager was always the one that failed, but it isn't. So check explicitly against the list of vetted modules from ReadASTCore. 2) We now keep the file descriptor of pcm file open, which avoids the possibility of having two different pcms for the same module loaded when building in parallel with headers being modified during a build. <rdar://problem/16835846> llvm-svn: 211330
2014-06-12Include system_error directly.Rafael Espindola1-1/+1
llvm-svn: 210802
2014-06-12Replace llvm::error_code with std::error_code.Rafael Espindola1-1/+1
llvm-svn: 210780
2014-05-30Invalidate the file system cache entries for files that may rebuildBen Langmuir1-5/+21
This reapplies r209910 with a fix for the assertion failures hit on the buildbots. original commit message: I thought we could get away without this, but it means that the FileEntry objects actually refer to the wrong files, since pcms are not updated inplace, they are atomically renamed into place after compiling a module. So we are close to the original behaviour of invalidating the cache for all modules being removed, but now we should only invalidate the ones that depend on whichever module failed to load. Unfortunately I haven't come up with a new test that didn't require a race between parallel invocations of clang. <rdar://problem/17038180> llvm-svn: 209922
2014-05-30Revert "Invalidate the file system cache entries for files that may rebuild"Ben Langmuir1-18/+5
This reverts commit r209910, which is breaking some of the bots. llvm-svn: 209911
2014-05-30Invalidate the file system cache entries for files that may rebuildBen Langmuir1-5/+18
I thought we could get away without this, but it means that the FileEntry objects actually refer to the wrong files, since pcms are not updated inplace, they are atomically renamed into place after compiling a module. So we are close to the original behaviour of invalidating the cache for all modules being removed, but now we should only invalidate the ones that depend on whichever module failed to load. Unfortunately I haven't come up with a new test that didn't require a race between parallel invocations of clang. <rdar://problem/17038180> llvm-svn: 209910
2014-05-22[C++11] Use 'nullptr'. Serialization edition.Craig Topper1-8/+8
llvm-svn: 209392
2014-05-20Speculative fix for Windows buildbot after r209138Ben Langmuir1-0/+5
It appears that Windows doesn't like renaming over open files, which we do in clearOutputFiles. The file being compiled should be safe to removed, but this isn't very satisfying - we don't want to manually manage the lifetime of files we cannot prove have no references. llvm-svn: 209195
2014-05-19Don't refresh stat() info for pcm filesBen Langmuir1-13/+1
Follow-up fix for 209138. Actually, since we already have this file open, we don't want to refresh the stat() info, since that might be newer than what we have open (bad!). llvm-svn: 209143
2014-05-19Fix use-after-free and spurious error during module loadBen Langmuir1-2/+13
FileManager::invalidateCache is not safe to call when there may be existing references to the file. What module load failure needs is to refresh so stale stat() info isn't stored. This may be the last user of invalidateCache; I'll take a look and remove it if possible in a future commit. This caused a use-after-free error as well as a spurious error message that a module was "found in both 'X.pcm' and 'X.pcm'" in some cases. llvm-svn: 209138
2014-05-04Fix a use-after-free bug I recently introduced in lookupModuleFileBen Langmuir1-4/+3
llvm-svn: 207932
2014-05-01Avoid a potential race between stat() and open() of ASTFileBen Langmuir1-1/+5
We need to open an ASTFile while checking its expected size and modification time, or another clang instance can modify the file between the stat() and the open(). llvm-svn: 207735
2014-04-14Allow multiple modules with the same name to coexist in the module cacheBen Langmuir1-2/+3
To differentiate between two modules with the same name, we will consider the path the module map file that they are defined by* part of the ‘key’ for looking up the precompiled module (pcm file). Specifically, this patch renames the precompiled module (pcm) files from cache-path/<module hash>/Foo.pcm to cache-path/<module hash>/Foo-<hash of module map path>.pcm In addition, I’ve taught the ASTReader to re-resolve the names of imported modules during module loading so that if the header search context changes between when a module was originally built and when it is loaded we can rebuild it if necessary. For example, if module A imports module B first time: clang -I /path/to/A -I /path/to/B ... second time: clang -I /path/to/A -I /different/path/to/B ... will now rebuild A as expected. * in the case of inferred modules, we use the module map file that allowed the inference, not the __inferred_module.map file, since the inferred file path is the same for every inferred module. llvm-svn: 206201
2014-03-03[C++11] Remove a now unnecessary use of std::function for a remove_ifChandler Carruth1-4/+3
predicate. The wrapper used by SetVector was erroneously requiring an adaptable predicate. It has been fixed and we really don't want to require an indirect call for every predicate evaluation. llvm-svn: 202744
2014-03-01[C++11] Replace verbose functors with succinct lambdasBenjamin Kramer1-17/+3
No functionality change. llvm-svn: 202590
2014-02-20Recommit virtual file systemBen Langmuir1-1/+1
Previously reverted in r201755 due to causing an assertion failure. I've removed the offending assertion, and taught the CompilerInstance to create a default virtual file system inside createFileManager. In the future, we should be able to reach into the CompilerInvocation to customize this behaviour without breaking clients that don't care. llvm-svn: 201818
2014-02-20Reverting the virtual file system implementation, because it triggers an ↵Juergen Ributzka1-1/+1
assertion in our internal build bots. This reverts commits 201618, 201635, 201636, 201639, 201685, 201691, and 201696. llvm-svn: 201755
2014-02-19Initial implementation of virtual file systemBen Langmuir1-1/+1
This adds the minimum virtual file system support to start migrating FileManager onto the VFS. Originally discussed here: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-February/035188.html Differential Revision: http://llvm-reviews.chandlerc.com/D2745 llvm-svn: 201618
2014-02-12Add an option to allow Clang verify source files for a module only once duringDmitri Gribenko1-0/+10
the build When Clang loads the module, it verifies the user source files that the module was built from. If any file was changed, the module is rebuilt. There are two problems with this: 1. correctness: we don't verify system files (there are too many of them, and stat'ing all of them would take a lot of time); 2. performance: the same module file is verified again and again during a single build. This change allows the build system to optimize source file verification. The idea is based on the fact that while the project is being built, the source files don't change. This allows us to verify the module only once during a single build session. The build system passes a flag, -fbuild-session-timestamp=, to inform Clang of the time when the build started. The build system also requests to enable this feature by passing -fmodules-validate-once-per-build-session. If these flags are not passed, the behavior is not changed. When Clang verifies the module the first time, it writes out a timestamp file. Then, when Clang loads the module the second time, it finds a timestamp file, so it can compare the verification timestamp of the module with the time when the build started. If the verification timestamp is too old, the module is verified again, and the timestamp file is updated. llvm-svn: 201224
2013-09-05Add a bit more info to modules fatal error.Eli Friedman1-2/+4
Just a minor tweak to make it easier to track down the cause of fatal errors with modules. llvm-svn: 190108
2013-08-24This wasn't headers, just missing namespaces.Benjamin Kramer1-1/+0
/me bows head in shame. llvm-svn: 189172
2013-08-24Add missing includes.Benjamin Kramer1-1/+2
llvm-svn: 189171
2013-08-23Use pop_back_val() instead of both back() and pop_back().Robert Wilhelm1-2/+1
No functionality change intended. llvm-svn: 189112
2013-06-11Include Path.h instead of PathV2.h.Rafael Espindola1-1/+1
I am about to move PathV2.h to Path.h. llvm-svn: 183795
2013-03-27<rdar://problem/13509689> Introduce -module-file-info option that provides ↵Douglas Gregor1-1/+13
information about a particular module file. This option can be useful for end users who want to know why they ended up with a ton of different variants of the "std" module in their module cache. This problem should go away over time, as we reduce the need for module variants, but it will never go away entirely. llvm-svn: 178148
2013-03-22<rdar://problem/13479539> Simplify ModuleManager/GlobalModuleIndex ↵Douglas Gregor1-47/+18
interaction to eliminate a pile of extraneous stats(). The refactoring in r177367 introduced a serious performance bug where the "lazy" resolution of module file names in the global module index to actual module file entries in the module manager would perform repeated negative stats(). The new interaction requires the module manager to inform the global module index when a module file has been loaded, eliminating the extraneous stat()s and a bunch of bookkeeping on both sides. llvm-svn: 177750
2013-03-21Remove unused variable.Benjamin Kramer1-3/+0
llvm-svn: 177657
2013-03-19<rdar://problem/13363214> Eliminate race condition between module rebuild ↵Douglas Gregor1-26/+90
and the global module index. The global module index was querying the file manager for each of the module files it knows about at load time, to prune out any out-of-date information. The file manager would then cache the results of the stat() falls used to find that module file. Later, the same translation unit could end up trying to import one of the module files that had previously been ignored by the module cache, but after some other Clang instance rebuilt the module file to bring it up-to-date. The stale stat() results in the file manager would trigger a second rebuild of the already-up-to-date module, causing failures down the line. The global module index now lazily resolves its module file references to actual AST reader module files only after the module file has been loaded, eliminating the stat-caching race. Moreover, the AST reader can communicate to its caller that a module file is missing (rather than simply being out-of-date), allowing us to simplify the module-loading logic and allowing the compiler to recover if a dependent module file ends up getting deleted. llvm-svn: 177367
2013-02-08Never cache the result of a module file lookup.Douglas Gregor1-3/+6
llvm-svn: 174744
2013-01-28Eliminate memory allocation from most invocations ofDouglas Gregor1-13/+38
ModuleManager::visit() by keeping a free list of the two data structures used to store state (a preallocated stack and a visitation number vector). Improves -fsyntax-only performance for my modules test case by 2.8%. Modules has pulled ahead by almost 10% with the global module index. llvm-svn: 173692
2013-01-25Improve coordination between the module manager and the global moduleDouglas Gregor1-5/+51
index, optimizing the operation that skips lookup in modules where we know the identifier will not be found. This makes the global module index optimization actually useful, providing an 8.5% speedup over modules without the global module index for -fsyntax-only. llvm-svn: 173529
2013-01-25Optimize ModuleManager::visit() by precomputing the visitation orderDouglas Gregor1-65/+82
and limiting ourselves to two memory allocations. 10% speedup in -fsyntax-only time for modules. With this change, we can actually see some performance different from the global module index, but it's still about 1%. llvm-svn: 173512
2013-01-25Implement the reader of the global module index and wire it into theDouglas Gregor1-2/+3
AST reader. The global module index tracks all of the identifiers known to a set of module files. Lookup of those identifiers looks first in the global module index, which returns the set of module files in which that identifier can be found. The AST reader only needs to look into those module files and any module files not known to the global index (e.g., because they were (re)built after the global index), reducing the number of on-disk hash tables to visit. For an example source I'm looking at, we go from 237844 total identifier lookups into on-disk hash tables down to 126817. Unfortunately, this does not translate into a performance advantage. At best, it's a wash once the global module index has been built, but that's ignore the cost of building the global module index (which is itself fairly large). Profiles show that the global module index code is far less efficient than it should be; optimizing it might give enough of an advantage to justify its continued inclusion. llvm-svn: 173405
2013-01-21Give ModuleFiles an index, so that we can use indexed vectors ratherDouglas Gregor1-20/+30
than DenseMaps and SmallPtrSets for module-visitation data. ~2.6% speedup for modules. llvm-svn: 173081
2012-11-30Actually keep track of the source locations at which particular moduleDouglas Gregor1-4/+8
files are loaded. llvm-svn: 169027
2012-11-07When loading a module fails because it is out of date, rebuild thatDouglas Gregor1-0/+39
module in place. <rdar://problem/10138913> llvm-svn: 167539
2012-10-03Set the file entry for a Module* that was created during deserializationArgyrios Kyrtzidis1-1/+2
of a module file. llvm-svn: 165086
2012-01-18Optimize unqualified/global name lookup in modules by introducing aDouglas Gregor1-2/+3
generational scheme for identifiers that avoids searching the hash tables of a given module more than once for a given identifier. Previously, loading any new module invalidated all of the previous lookup results for all identifiers, causing us to perform the lookups repeatedly. llvm-svn: 148412
2011-11-30Promote ModuleMap::Module to a namespace-scope class in the BasicDouglas Gregor1-25/+25
library, since modules cut across all of the libraries. Rename serialization::Module to serialization::ModuleFile to side-step the annoying naming conflict. Prune a bunch of ModuleMap.h includes that are no longer needed (most files only needed the Module type). llvm-svn: 145538
2011-10-11Add support for viewing the module graph via Graphviz, for debuggingDouglas Gregor1-0/+49
purposes. llvm-svn: 141697