-
Notifications
You must be signed in to change notification settings - Fork 7
Bootstrapping
What does PASTA's bootstrap process do, and why do we do it?
-
Maintain liveness of the AST, via an underlying
shared_ptrto pasta'sASTImpl. This part of the design had eventual python bindings in mind. If you've ever used Clang's Python bindings, then you can be bit by this annoying issue where the Python object tracking theclang::ASTContextgoes out of scope, and then you start getting UAFs on all of your accessed to other things inside of the AST. In general, I find these kinds of clang/llvm/mlir designs where you have a big context object that isn't kept alive by their children/etc to be problematic from a binding perspective. -
Comprehensively replace
clang::SourceLocationandclang::SourceRangewithpasta::Tokenandpasta::TokenRange. Clang's source locations / ranges, and evenclang::Token, are underpowered APIs that suck to use. -
Present value types everywhere, and communicate when something can be optional/missing. Clang's AST API is all pointer based. You don't know if a given method returning a
clang::Decl *can returnnullptror not. The same goes for whether or not that method willassert. So the bootstrap process is responsible to knowing the set of "nullable" methods, and wrapping their return values withstd::optional. A lot of this was just manually hitting these cases, or superficial ctrl+f forreturn nullptr;in various.hor.cppfiles, and then we also have a more automated "blowtorch" method of trying to discover these to better keep on top of the problem. -
Regularize things. E.g.
Decls,Stmts,Types,Attrsshould all have aKindenum. In Clang, it's close but not quite like that. Sometimes they're scoped inside a class, or called things likeTypeClass. Other regularization is for renaming to make things nicer to read, e.g. dropping thegeton getters, expanding contractions likeDecltoDeclaration, etc. -
Providing all the other things, like all the enums, all in one place (
pasta/Forward.h) so that we pasta can present a self-contained world to the api that is completely independent of Clang APIs. Redistributing libraries+headers+cmake of a pre-compiled clang (i.e. invcpkg) is annoying/problematic, and reduces the utility of pasta as a library. Thus, pasta is designed to be more easily packaged. -
Replacing problematic methods, and providing better variants. Some methods are problematic, e.g.
FunctionDecl::getParameterSourceRangeorFunctionDecl::getEllipsisLoc. These are problematic because their results are often completely wrong, as they rely onclang::SourceLocations possibly embedded inclang::Types, which are deduplicated, and so could be based on far-away-in-the-past locations. -
Introducing new utility functions, e.g.
pasta::Type::SizeInBits. -
Unify
clang::Typeandclang::QualTypeunder a single type hierarchy in PASTA.