Commit Graph

560 Commits

Author SHA1 Message Date
Paolo Tranquilli
10b7b1f183 Merge branch 'main' into redsun82/swift-file-label-caching 2022-07-18 14:02:57 +02:00
Paolo Tranquilli
98fc8812fc Merge 'main' into redsun82/swift-extraction 2022-07-18 11:55:21 +02:00
Paolo Tranquilli
78fc356feb Swift: address review comments 2022-07-18 10:29:20 +02:00
Paolo Tranquilli
5e74df3882 Swift: cache file paths
This required a bit of a generalization of `TrapLabelStore` to not
work only with pointers.
2022-07-14 16:32:33 +02:00
Paolo Tranquilli
22ff8c2c7e Swift: remove redundant braces 2022-07-14 15:40:48 +02:00
Paolo Tranquilli
3e06455ac1 Swift: delete TargetFile's move assignment 2022-07-14 15:39:36 +02:00
Paolo Tranquilli
f1144b9672 Swift: small TypeRepr visit rewording 2022-07-14 06:18:51 +02:00
Paolo Tranquilli
d748cb483d Swift: include cleanup
Fix a problem with `sstream` not being transitively included on macOS.
2022-07-14 06:10:12 +02:00
Paolo Tranquilli
4c53c341f6 Swift: make TargetFile::good() a class invariant
Fallible initialization has been moved to a factory function, and
`commit` has been moved to the destructor.
2022-07-14 06:02:35 +02:00
Paolo Tranquilli
f7dca4d70f Swift: trap output rework
Firstly, this change reworks how inter-process races are resolved.
Moreover some responsability reorganization has led to merging
`TrapArena` and `TrapOutput` again into a `TrapDomain` class.

A `TargetFile` class is introduced, that is successfully created
only for the first process that starts processing a given trap output
file. From then on `TargetFile` simply wraps around `<<` stream
operations, dumping them to a temporary file. When `TargetFile::commit`
is called, the temporary file is moved on to the actual target trap
file.

Processes that lose the race can now just ignore the unneeded
extraction and go on, while previously all processes would carry out
all extractions overwriting each other at the end.

Some of the file system logic contained in `SwiftExtractor.cpp` has been
moved to this class, and two TODOs are solved:
* introducing a better inter process file collision avoidance strategy
* better error handling for trap output operations: if unable to write
  to the trap file (or carry out other basic file operations), we just
  abort.

The changes to `ExprVisitor` and `StmtVisitor` are due to wanting to
hide the raw `TrapDomain::createLabel` from them, and bring more
funcionality under the generic caching/dispatching mechanism.
2022-07-13 11:19:57 +02:00
Paolo Tranquilli
48c71c9407 Swift: add comment about TypeRepr in ASTNode fetching 2022-07-12 12:10:22 +02:00
Paolo Tranquilli
033b239b22 Swift: collapse TypeRepr hierarchy
Now `TypeRepr` is a final class in the AST, which is more or less just
a type with a location in code.

As the frontend does not provide a direct way to get a type from a
type representation, this information must be provided when fetching
the label of a type repr.

This meant:
* removing the type repr field from `EnumIsCaseExpr`: this is a virtual
  AST node introduced in place of some kinds of `IsEpxr`. The type
  repr is still available from the `ConditionalCheckedCastExpr` wrapped
  by this virtual node, and we will rebuild the original `IsExpr` with
  the IPA layer.
* some logic to get the type of keypath roots has been added to
  `KeyPathExpr`. This was done to keep the `TypeRepr` to `Type` relation
  total in the DB, but goes against the design of a dumb extractor. The
  logic could be moved to QL in the future
* in the control flow library, `TypeRepr` children are now ignored. As
  far as I can tell, there is no runtime evaluation going on in
  `TypeRepr`s, so it does not make much sense to have control flow
  through them.
2022-07-12 10:49:14 +02:00
Paolo Tranquilli
39406436bf Swift: extract IfConfigDecl
This also adds `UnresolvedDeclRefExpr` tests, as `IfConfigDecl`
consistently introduces those.
2022-07-11 15:11:13 +02:00
Paolo Tranquilli
7d5dd384c3 Swift: extract UnresolvedPatternExpr 2022-07-11 10:59:00 +02:00
Paolo Tranquilli
7c3cadc9b6 Swift: extract OpenedArchetypeType 2022-07-11 10:48:21 +02:00
Paolo Tranquilli
f9143f7855 Swift: fix extraction of empty files 2022-07-01 15:43:16 +02:00
Paolo Tranquilli
3a975174c3 Swift: extract ImportDecl and ModuleDecl
As `ASTMangler` crashes when called on `ModuleDecl`, we simply use
its name.

This might probably not work reliably in a scenario where multiple
modules are compiled with the same name (like `main`), but this is left
for future work. At the moment this cannot create DB inconsistencies.
2022-07-01 15:29:30 +02:00
Paolo Tranquilli
7a7440a115 Swift: move createEntry to SwiftDispatcher 2022-07-01 15:22:44 +02:00
Paolo Tranquilli
8336c67edb Merge pull request #9762 from github/alexdenisov/vfs-followup
Swift: cleanup
2022-07-01 09:00:54 +02:00
Mathias Vorreiter Pedersen
51e3ff9d09 Merge pull request #9736 from github/redsun82/swift-fix-warnings
Swift: fix QL warnings about overriding methods
2022-06-30 11:44:44 +01:00
Alex Denisov
5a04d62969 Swift: cleanup extraction 2022-06-30 12:32:03 +02:00
Alex Denisov
133a6caaa3 Swift: cleanup output rewriting code 2022-06-30 12:03:53 +02:00
AlexDenisov
d42b752c6d Apply suggestions from code review
Co-authored-by: Paolo Tranquilli <redsun82@github.com>
2022-06-30 11:10:43 +02:00
AlexDenisov
b5c1ec8958 Update swift/extractor/SwiftOutputRewrite.cpp
Co-authored-by: Paolo Tranquilli <redsun82@github.com>
2022-06-30 11:08:23 +02:00
AlexDenisov
6b0e734c47 Update swift/extractor/SwiftOutputRewrite.cpp
Co-authored-by: Paolo Tranquilli <redsun82@github.com>
2022-06-30 11:06:03 +02:00
AlexDenisov
b9f4a09f19 Merge branch 'main' into alexdenisov/swift-multiple-modules 2022-06-30 10:13:34 +02:00
Alex Denisov
1dd3141e2d Swift: address more code review comments 2022-06-30 08:57:22 +02:00
Alex Denisov
35da75f685 Swift: rename method 2022-06-30 08:48:36 +02:00
AlexDenisov
522d48aa33 Apply suggestions from code review
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
2022-06-30 08:47:17 +02:00
Alex Denisov
5233a5e17b Swift: also extract imported modules 2022-06-29 17:27:57 +02:00
Alex Denisov
4d81206a87 Swift: teach extractor to emit build artifacts for later consumption 2022-06-29 10:58:24 +02:00
AlexDenisov
e1ef637c54 Update swift/extractor/SwiftExtractorConfiguration.h
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
2022-06-29 10:16:14 +02:00
Alex Denisov
488befb577 Swift: store TRAP files in a temporary folder until the extraction is complete
Currently, we have a number of assertions in the codebase and certain
assumptions about the AST. These don't always hold, sometimes leading to
a crash in the extractor.
The crashes leave incomplete TRAP files that cannot be imported into the
database.

With this change, we still get those incomplete TRAP files, but we also
get a database in the end (even thoough it is also incomplete as we
cannot import everything).
2022-06-29 07:17:06 +02:00
Paolo Tranquilli
363f7a88a9 Swift: fix QL warnings about overriding methods
The `getName` in `Type.qll` was issuing a warning in other generated
classes having a `getName` from a `name` property in `schema.yml`.

To fix the possible inconsistency, `diagnostic_name` is being renamed to
`name` in the schema. Despite the scary doc comment on
`swift::Type::getString` (namely `for use in diagnostics only`), that
seems to be the right generic naming mechanism for types, and it
coincides with the name we were extracting on types with an explicit
`name` property.

In case we find a case where `Type::getString` gives something wrong,
we can probably just patch it on that specific type class.
2022-06-28 16:30:25 +02:00
Paolo Tranquilli
68a341d72c Swift: use createEntry in the whole type visitor 2022-06-28 12:06:19 +02:00
Paolo Tranquilli
57981384df Swift: extract ProtocolComposition- and BuiltinType 2022-06-28 12:01:36 +02:00
Paolo Tranquilli
41fb55a7a8 Swift: extract all ReferenceStorageTypes 2022-06-24 18:10:31 +02:00
Paolo Tranquilli
fd209e57cd Swift: extract InoutType 2022-06-24 17:29:46 +02:00
Paolo Tranquilli
189a47e30d Swift: extract VariadicSequenceType 2022-06-24 17:15:45 +02:00
Paolo Tranquilli
346110e8dd Swift: extract DynamicSelfType 2022-06-24 16:49:58 +02:00
Paolo Tranquilli
4281605ba7 Swift: extract existential types 2022-06-24 16:28:18 +02:00
Paolo Tranquilli
631156dbc6 Swift: extract Nested- and PrimaryArchetypeType 2022-06-24 16:28:17 +02:00
Paolo Tranquilli
299e1af22e Merge main into redsun82/swift-code-reorg 2022-06-24 13:06:14 +02:00
Paolo Tranquilli
80ffd81b2c Merge pull request #9614 from github/alexdenisov/swift-extract-all-inputs-with-outputs
Swift: extract all output-producing source files, not only primary files
2022-06-24 12:23:36 +02:00
Paolo Tranquilli
a9877ed2fd Swift: split generated C++ files by directory 2022-06-23 14:24:03 +02:00
Paolo Tranquilli
b2ebf63d2e Swift: split generated C++ code into .h and .cpp 2022-06-23 14:22:58 +02:00
AlexDenisov
decb136471 Update swift/extractor/SwiftExtractor.cpp
Co-authored-by: Paolo Tranquilli <redsun82@github.com>
2022-06-23 07:23:17 +02:00
Paolo Tranquilli
cfde68023d Swift: fix includes jumbled by IDE 2022-06-22 18:17:40 +02:00
Paolo Tranquilli
22321aa124 Swift: reorganize code
Visitor code has been split between header and sources to speed up
incremental build. Moreover the code was reorganized using a new `infra`
bazel package (and `visitors` got promoted to a bazel package as well).
2022-06-22 18:11:58 +02:00
Paolo Tranquilli
1fc2bc4938 Swift: really fix tests 2022-06-22 16:15:02 +02:00