95 Commits

Author SHA1 Message Date
Paolo Tranquilli
46fb041c50 Merge pull request #19384 from github/redsun82/swift-add-logs
Swift: add more debug logs
2025-04-25 17:24:11 +02:00
Paolo Tranquilli
d9a6a630e5 Swift: fix log compilation 2025-04-25 15:37:08 +02:00
Paolo Tranquilli
e71e7a08bb Swift: add more debug logs 2025-04-25 15:20:20 +02:00
Paolo Tranquilli
1ac47a892b Swift: make extractor compile again after 6.1 upgrade 2025-04-23 17:10:54 +02:00
Paolo Tranquilli
524686ce37 Swift: make extractor compilable with Swift 6 2024-10-08 16:39:21 +02:00
Alex Denisov
4133284bc8 Swift: skip declarations marked as unavailable 2023-10-11 10:55:49 +02:00
Paolo Tranquilli
70ff401f21 Swift: replace internal swift mangler with our own
Our mangler is split in two version:
* `SwiftTrapMangler`, with the same behaviour as the previous
  `SwiftMangler`, constructing mangled names with trap label references
* `SwiftRecursiveMangler` that replaces trap label references with
  recursive calls to its own `mangle` functions, effectively rolling out
  the entire chain of references

The latter is used to create lazy trap file names. Hashing is used to
avoid excessively long filenames.
2023-05-31 09:52:20 +02:00
Paolo Tranquilli
d81dc274f6 Swift: make a TODO more assertive as there is a draft PR already 2023-05-26 14:45:29 +02:00
Paolo Tranquilli
2fb6cdc19b Merge branch 'main' into alexdenisov+redsun82/tuple-mangling 2023-05-24 11:16:59 +02:00
Paolo Tranquilli
bce483ddb1 Swift: rename log package to logging 2023-05-04 10:42:39 +02:00
Paolo Tranquilli
9544b96ff1 Merge branch 'main' into redsun82/swift-json 2023-05-04 10:34:11 +02:00
Paolo Tranquilli
1d492f89cc Merge branch 'main' into redsun82/swift-logging-assertions-and-prints 2023-05-03 15:19:08 +02:00
Paolo Tranquilli
f461e719da Swift: fix wrong condition for log 2023-05-03 14:54:28 +02:00
Paolo Tranquilli
3685590a12 Swift: remove version control markers 2023-05-02 10:45:43 +02:00
Paolo Tranquilli
0aed7d56c2 Swift: more mangling 2023-05-02 10:45:42 +02:00
Alex Denisov
125aab8107 Swift: rework fetching and dispatching
* visiting now happens in a later stage than fetching labels. While
  fetching a list of entities to be visited is created, and then acted
  upon in actual extraction. This partially flattens the recursive
  nature of `fetchLabel` into a loop inside `SwiftVisitor::extract`.
  Recursion in `fetchLabel` will only happen on labels fetched while
  naming an entity (calling into `SwiftMangler`).
* The choice whether to name a declaration or type has been moved from
  the translators to `SwiftMangler`. Acting on this choice is contained
  in `SwiftDispatcher::createLabel`.
* The choice whether to emit a body of a declaration has been moved from
  `DeclTranslator` to the dispatcher. This choice is also contained in
  `SwiftDispatcher::createLabel`.
* The simple functionality of the `LabelStore` has been moved to the
  `SwiftDispatcher` as well.
2023-04-25 11:15:27 +02:00
Paolo Tranquilli
14706b42fa Swift: strip parameters from lazy function decl trap names 2023-04-24 17:04:41 +02:00
Paolo Tranquilli
e84bdf5bed Swift: use hashing for lazy decl trap file names
It turns out mangled names can sometimes be too long. While this code
will eventually be replaced by our own mangling, we need to use hashing
to cut down the names.

Module and decl names are preserved in the trap file names for
debuggability.
2023-04-24 14:36:36 +02:00
Paolo Tranquilli
c04ac9c04e Swift: demote wrong assertion 2023-04-24 09:57:51 +02:00
Paolo Tranquilli
dbfd85c505 Swift: replace assertions and prints in main and SwiftExtractor 2023-04-18 12:14:46 +02:00
Paolo Tranquilli
2cfecac545 Swift: remove debug prints 2023-03-29 13:14:44 +02:00
Paolo Tranquilli
f3f17791c3 Swift: extract all source files in WMO mode
WMO stands for whole module optimization. It's a compilation mode where
all sources of a module are compiled together, e.g.
```
swift-frontend -emit-module A.swift B.swift -o Module.swiftmodule
```
This is opposed to incremental mode, where one would do something like
```
swift-frontend -emit-module -primary-file A.swift B.swift -module-name Module -o Module~A.swiftmodule
swift-frontend -emit-module A.swift -primary-file B.swift -module-name Module -o Module~B.swiftmodule
swift-frontend -merge-modules Module~A.swiftmodule Module~B.swiftmodule -o Module.swiftmodule
```

In WMO mode we were skipping extraction of all files after the first
one, because we were filtering in only files with an associated output,
and internally swift only assigns the output to the first input file in
WMO mode (which is just an implementation detail).

This patch refines that filter, by getting all input source files in
case there are no primary inputs.
2023-03-29 10:39:58 +02:00
Alex Denisov
ae7a0c517c Swift: do not allocate mangler statically 2023-03-03 10:28:08 +01:00
Alex Denisov
60c1505097 Swift: address review comments 2023-03-03 10:26:44 +01:00
Alex Denisov
ffcb382705 Swift: only consider Builting and __ObjC declarations as lazy 2023-03-02 20:00:23 +01:00
Alex Denisov
276fec39fc Swift: consider lazy declaration emitted if the process lost in the race 2023-03-01 15:42:44 +01:00
Alex Denisov
ded0e570b0 Swift: extract lazy declarations 2023-03-01 15:22:22 +01:00
Alex Denisov
def9831180 Swift: move decision making out of dispatcher 2023-03-01 12:02:58 +01:00
Alex Denisov
b1aef82117 Swift: move location extraction logic into a separate class 2023-03-01 11:32:50 +01:00
Paolo Tranquilli
5fdb09380c Swift: move TargetTrapDomain to TargetDomains in infra 2023-01-18 10:07:46 +01:00
Paolo Tranquilli
7f389b9f9a Swift: introduce TrapType 2023-01-18 10:07:46 +01:00
Paolo Tranquilli
84b285a4c6 Swift: collect source files 2023-01-18 10:07:46 +01:00
Paolo Tranquilli
33c4a8233c Swift: collect encountered modules 2023-01-18 10:07:46 +01:00
Paolo Tranquilli
c7f13f1036 Swift: collect TRAP files related to an extractor run
In order to do this a mutable `SwiftExtractorState` is introduced.
2023-01-18 10:07:46 +01:00
Paolo Tranquilli
c31c515205 Swift: move TargetFile as managed inside TrapDomain 2023-01-18 10:07:46 +01:00
Paolo Tranquilli
1ba8b6d35a Swift: fix extraction of sources from .. 2022-12-08 15:57:57 +01:00
Alex Denisov
7a3beac494 Swift: resolve symlinks conditionally 2022-12-02 10:07:10 +01:00
Alex Denisov
a2ac1384cb Swift: do not abort if cannot archive a source file 2022-11-22 17:18:40 +01:00
Paolo Tranquilli
7c9fffc201 Swift: rename all visitors to translators 2022-11-03 18:16:53 +01:00
Paolo Tranquilli
3fca25310f Swift: fix copy option 2022-10-27 09:29:05 +02:00
Paolo Tranquilli
22db4932ee Swift: add overwrite_existing to source archiving 2022-10-27 09:26:57 +02:00
Paolo Tranquilli
521e6235b5 Swift: use std::filesystem and picoSHA2
This replaces usages of `llvm::fs` and string manipulation with
`std::filesystem`, also replacing `std::string` with
`std::filesystem::path` where it made sense.

Moreover MD5 hashing used in macOS file remapping was replaced by
SHA256 hashing using a small header-only SHA256 C++ library with an
MIT license, https://github.com/okdshin/PicoSHA2.

File contents hashing was relocated to the newly created `file` library
for later planned reuse.
2022-10-26 13:23:44 +02:00
Alex Denisov
c638789f3e Swift: open(2) interception 2022-09-16 12:02:16 +02:00
Paolo Tranquilli
c9b14b4459 Swift: address review comments 2022-08-26 12:49:19 +02:00
Paolo Tranquilli
ebc7432f46 Swift: implement imported_ and exported_modules
This has expanded the required builtin symbols.
2022-08-26 11:37:14 +02:00
Paolo Tranquilli
a5a58d3dc5 Swift: start with loaded modules for extraction 2022-08-26 11:23:02 +02:00
Paolo Tranquilli
0971ca6a82 Swift: emit <Builtin>.trap instead of .trap 2022-08-26 09:35:19 +02:00
Paolo Tranquilli
2c153f68e1 Swift: replace processed with seen in module visiting 2022-08-26 09:28:38 +02:00
Paolo Tranquilli
d5af30d28d Swift: add comment to getBuiltinDecls 2022-08-26 09:28:02 +02:00
Paolo Tranquilli
df3dc9677f Swift: fix missing extractions from Builtin
There were missing extractions from the Builtin (and other) modules.

This was actually caused by two issues:
* we did not visit all required modules, as for example the `Builtin`
  module does not appear as being imported by anybody (together with
  another mysterious `__Objc` module)
* moreover the `Builtin` module works internally by only creating
  declarations on demand, and does not provide a list of its top level
  declarations.

The first problem was solved by moving module collection to the actual
visiting. This may mean we extract less modules, as we only extract the
modules we actually use something from (recursively). This change can
be reverted if we feel we need it.

The second one was solved by explicitly listing the builtin symbols
encountered during a normal extraction. This does mean this list needs
to be kept up to date.
2022-08-25 15:18:24 +02:00