llvm-project
f5fdd43b - [clang] Refactor `ASTUnit::LoadFromASTFile()` (#164265)

Commit
92 days ago
[clang] Refactor `ASTUnit::LoadFromASTFile()` (#164265) This PR refactors `ASTUnit::LoadFromASTFile()` to be easier to follow. Conceptually, it tries to read an AST file, adopt the serialized options, and set up `Sema` and `ASTContext` to deserialize the AST file contents on-demand. The implementation of this used to be spread across an `ASTReaderListener` and the function in question. Figuring out what listener method gets called when and how it's supposed to interact with the rest of the functionality was very unclear. The `FileManager`'s VFS was being swapped-out during deserialization, the options were being adopted by `Preprocessor` and others just-in-time to pass `ASTReader`'s validation checks, and the target was being initialized somewhere in between all of this. This lead to a very muddy semantics. This PR splits `ASTUnit::LoadFromASTFile()` into three distinct steps: 1. Read out the options from the AST file. 2. Initialize objects from the VFS to the `ASTContext`. 3. Load the AST file and hook it up with the compiler objects. This should be much easier to understand, and I've done my best to clearly document the remaining gotchas. (This was originally motivated by the desire to remove `FileManager::setVirtualFileSystem()` and make it impossible to swap out VFSs from underneath `FileManager` mid-compile.)
Author
Parents
Loading