Commit Graph

305 Commits

Author SHA1 Message Date
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
dcd256eb4a [Driver] Update argument to SmallVectorImpl instead of std::vector
`CommandSetVector::takeVector` returns a `SmallVector` now.
2024-04-08 08:58:58 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Artem Chikin
73b01dccfc Remove incremental builds from the Legacy driver
The C++-based driver is deprecated and this will help reduce the code surface that requires maintenance as the legacy driver is fully sunset.
2024-01-16 16:34:51 -08:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Hiroshi Yamauchi
b419f68045 Fix the new diagnostic formatter adding extra whitespace on Windows
The swift driver emits extra newlines because it applies the LF ->
CRLF conversions again on the outpt from the child processes. Fix it
by using the binary mode when outputting the output from the child
processes.

Fixes: #64413
2023-05-23 15:33:10 -07:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Josh Soref
66d267e6ff Spelling driver (#42516)
* spelling: associated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: change

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declaration

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependents

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deterministically

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: embedded

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: exclude

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: filesystem

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: given

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: grained

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: incrementality

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: invoke

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: locals

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preexisting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: should

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: supplementary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: suppress

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-22 09:10:43 -07:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Evan Wilde
0aafd09835 F_None was renamed OF_None
This patch updates usages of F_None to OF_None, as LLVM changed that in
commit 3302af9d4c39642bebe64dd60a3aa162fefc44b2.
2021-06-23 10:36:39 -07:00
Nathan Hawes
117f03b2f5 [Driver][Index] Add driver support to specify an overriding output path to record in the index data
The frontend supports this via new options -index-unit-output-path and
-index-unit-output-path-filelist that mirror -o and -output-filelist. These are
intended to allow sharing index data across builds in separate directories (so
different -o values) that are otherwise equivalent as far as the index data is
concerned (e.g. an ASAN build and a non-ASAN build) by supplying the same
-index-unit-output-path for both.

This change updates the driver to add these new options to the frontend
invocation 1) when a new "index-unit-output-path" entry is specified for one
or more input files in the -output-file-map json or 2) if -index-file is
specified, when a new -index-unit-output-path driver option is passed.

Resolves rdar://problem/74816412
2021-03-06 13:44:14 +10:00
Robert Widmann
764df6dc70 Fold Incremental External Dependency Nodes Into External Dependency Nodes
Remove this distinction without a difference. Originally, the thought
was to
1) Isolate the cross-module build infrastructure
2) Provide a signal to the driver that a dependency had swiftdeps info
   in it

But the driver need only notice swiftmodule files as external
dependencies and try to extract that information if it can to divine the
signal it needs. Additionally, we can give it fingerprints as priors to
let it know there might be incremental info to be had.
2021-02-03 11:46:04 -08:00
Robert Widmann
33309037c4 Disable Loading of Priors 2021-02-02 15:04:10 -08:00
Robert Widmann
d4b9dca739 [NFC] Simplify Straight-Line Calls in the Driver 2021-01-13 23:10:36 -08:00
Robert Widmann
cc0d919653 Remove Compiled Source 2021-01-13 23:00:16 -08:00
Robert Widmann
2475095021 Remove Ranges File Type 2021-01-13 22:42:17 -08:00
Robert Widmann
0102c52d18 Remove OutputFileMap's Knowledge of Range Dependencies 2021-01-13 22:14:02 -08:00
Robert Widmann
1c769e736d Remove Range Modality in the Driver 2021-01-13 17:15:38 -08:00
Robert Widmann
d15bcc3670 Remove Argument Parsing For Source Ranges 2021-01-13 17:12:27 -08:00
Robert Widmann
de169acb30 Remove Usages of IncrementalSchemeComparator 2021-01-13 16:53:02 -08:00
Robert Widmann
35c45949a2 Remove IncrementalSchemeComparator 2021-01-13 16:49:19 -08:00
Artem Chikin
47da04fd72 Merge pull request #34417 from artemcm/FrontendParseableOutput
Add support for parseable-output straight from the frontend
2020-12-16 12:59:40 -08:00
Artem Chikin
915186ab47 Refactor Basic/Parseable-Output to remove dependency on Driver & Frontend
Introducing new entry-points that can be used from both Driver and Frontend clients, using an intermediary new type: `DetailedMessagePayload`, when needed.
2020-12-14 11:35:56 -08:00
Daniel Rodríguez Troitiño
322f02aeb9 [driver] Use if/else instead of ternary, to please VS2017.
VS2017 seems to have problems with ternaries where the two branches are
given as std::move() (see https://stackoverflow.com/questions/53374182)
and the compiler was given a warning C4172 "returning address of local
or temporary".

Switching the ternary operator into a `if/else` works correctly for
VS2017 and should work for other compilers too, without changing the
meaning (as far as I see).

This was causing the Windows VS2017 CI to fail compiling the stdlib.
When bisecting, the problem was reduced to the changes in #35034. In a
debugger I managed to see the problem being a heap corruption. With all
the moves I was suspicious that something was being used while
destroyed, but the code was correct. While recompiling the compiler
warning gave me the clue.
2020-12-11 17:34:56 -08:00
Artem Chikin
942cb0855e Implement frontend parseable-output batch job quasi-PID assignment.
Starting at a crude -1000, each invocation primary input will get its own unique quasi-Pid.
Invocations with only one primary (non-batch) will get a real OS Pid.

The selection of the constant starting point matches what the driver does when outputting its parseable output.
2020-12-11 16:01:04 -08:00
Artem Chikin
f09ab5c52f Add support for emitting parseable-outpuit "began" message from swift-frontend 2020-12-11 16:01:03 -08:00
Robert Widmann
859b87fd8c Move The Last Pieces for Cross-Module Incremental Builds
We're going to play a dirty, dirty trick - but it'll make our users'
lives better in the end so stick with me here.

In order to build up an incremental compilation, we need two sources of
dependency information:

1) "Priors" - Swiftdeps with dependency information from the past
   build(s)
2) "Posteriors" - Swiftdeps with dependencies from after we rebuild the
   file or module or whatever

With normal swift files built in incremental mode, the priors are given by the
swiftdeps files which are generated parallel to a swift file and usually
placed in the build directory alongside the object files. Because we
have entries in the output file map, we can always know where these
swiftdeps files are. The priors are integrated by the driver and then
the build is scheduled. As the build runs and jobs complete, their
swiftdeps are reloaded and re-integrated. The resulting changes are then
traversed and more jobs are scheduled if necessary. These give us the
posteriors we desire.

A module flips this on its head. The swiftdeps information serialized
in a module functions as the *posterior* since the driver consuming the
module has no way of knowing how to rebuild the module, and because its
dependencies are, for all intents and purposes, fixed in time. The
missing piece of the puzzle is the priors. That is, we need some way of
knowing what the "past" interface of the module looked like so we can
compare it to the "present" interface. Moreover, we need to always know
where to look for these priors.

We solve this problem by serializing a file alongside the build record:
the "external" build record. This is given by a... creative encoding
of multiple source file dependency graphs into a single source file
dependency graph. The rough structure of this is:

   SourceFile => interface <BUILD_RECORD>.external
   | - Incremental External Dependency => interface <MODULE_1>.swiftmodule
   | | - <dependency> ...
   | | - <dependency> ...
   | | - <dependency> ...
   | - Incremental External Dependency => interface <MODULE_2>.swiftmodule
   | | - <dependency> ...
   | | - <dependency> ...
   | - Incremental External Dependency => interface <MODULE_3>.swiftmodule
   | - ...

Sorta, `cat`'ing a bunch of source file dependency graphs together but
with incremental external dependency nodes acting as glue.

Now for the trick:

We have to unpack this structure and integrate it to get our priors.
This is easy. The tricky bit comes in integrate itself. Because the
top-level source file node points directly at the external build record,
not the original swift modules that defined these dependency nodes, we
swap the key it wants to use (the external build record) for the
incremental external dependency acting as the "parent" of the dependency
node. We do this by following the arc we carefully laid down in the
structure above.

For rdar://69595010
Goes a long way towards rdar://48955139, rdar://64238133
2020-12-10 18:45:21 -08:00
Robert Widmann
d4e76d0a47 [NFC] Use Result::code to Simplify Some Callsites 2020-12-09 19:28:50 -08:00
Robert Widmann
3ecb0b0b06 [NFC] Move "HadAbnormalExit" Flag Into Compilation::Result 2020-12-09 19:25:56 -08:00
Robert Widmann
d815e2724a [NFC] Add Compilation::Result
In order to extract the module dependency graph from the compilation the driver just ran, define a separate semantic type to hold a result code and the graph itself.
2020-12-09 19:25:56 -08:00
Robert Widmann
9075d32495 [NFC] Delete An Unused Entrypoint 2020-12-07 15:19:28 -08:00
Robert Widmann
e2e19dcf82 Add Compilation "Wave" Assertion in +Asserts Builds
The "wave" of a compilation job describes the number of indirections through other compile jobs the driver required to reach the decision to schedule a job. In incremental mode, it should always be the case that it takes no more than two complete waves to arrive at a fixpoint in the build. This is a natural consequence of the structure of the dependencies emitted by the Swift frontend - namely we rely on transitivity in dependency arcs.

A quick proof sketch: Suppose an arbitrary perturbation of the inputs to an incremental compilation session are made. In the first wave, dependency edges from the prior build's state (the "zeroeth wave") are loaded and the files corresponding to invalidated edges are scheduled into the first wave. Supposing the second wave is not the null set - the trivial case - there are additional arcs that were invalidated. Now suppose that there were a third wave. Take an arbitrary arc invalidated by this third wave. It must be the case that the file containing the use is not new - else it would be scheduled. Further it must be the case that its def was not invalidated by the zeroeth or first waves of compilation otherwise we would have scheduled it into the first or second waves. Finally, it must have a use that was discovered in the second wave. But in order for that use to have been included in the second wave, there must have been an invalidated arc created by the first wave. By transitivity of dependency arcs, there must therefore be a dependency arc from a definition invalidated in the first wave to our third wave job, which implies that the file would be scheduled into the second wave!

[Insert contradiction pig image here]
2020-10-21 19:36:43 -07:00
Robert Widmann
d793878923 Schedule merge-modules When modulewrap Job is in the Queue
In order to unblock the SwiftWASM project, which relies on an
incremental build of the Swift driver that relies on the merge-modules
job always being run. The situation appears to be something like this:

1) An incremental build is run
2) Temporary swiftmodule outputs are laid down
3) merge-modules is skipped
4) modulewrap is run anyways and reads the empty temp file

We should fix this by skipping modulewrap if we can skip merge-modules.
But for now, be conservative and fall back to the status quo behavior of
always running merge-modules whenever we encounter a modulewrap job.
2020-10-13 15:28:12 -07:00
Robert Widmann
4f49b6ab81 Merge pull request #34231 from CodaFi/skippy
Skip Merge-Modules When We Can
2020-10-08 14:41:01 -07:00
Robert Widmann
164bd08623 Merge pull request #34219 from CodaFi/negative-externalities
Keep a Cache of Externally-Dependent Jobs
2020-10-07 19:40:30 -07:00
Robert Widmann
cecb7c8313 Schedule MergeModules Incrementally
Plumb the logic necessary to schedule merge-modules incrementally. This means that if any inputs jobs to merge-modules run, merge-modules is run. But, if they are all skipped, merge-modules will be skipped as well.

This requires some light special-casing of the legacy driver's incremental job handling because it assumes in a few places it can always extract a swiftdeps file. This invariant will be further broken when the precompile step for bridging headers is skipped as well.

rdar://65893400
2020-10-07 16:57:14 -07:00
Robert Widmann
84f9ba3004 Use ModuleInputs instead of a Vector to build MergeModules 2020-10-07 16:56:48 -07:00
Robert Widmann
d29dcf8901 [NFC] Upgrade CompileJobAction::InputInfo::Status to an enum class 2020-10-07 16:56:48 -07:00
Robert Widmann
8fbcdf392f [NFC] Use IncrementalJobAction to Supersede getFirstSwiftPrimaryInput()
This function was being used in a roundabout way to test for a compile job action. But the actual data itself was not being used.
2020-10-07 12:08:21 -07:00
Robert Widmann
b0f0587963 Keep a Cache of Externally-Dependent Jobs
A more durable form of #34218. Keep a side cache of externally-dependent
jobs for now. This ensures our pseudo-Jobs don't get prematurely
deallocated before the tracing machinery has had a chance to report the
structure of the Job graph.

rdar://70053563
2020-10-07 10:39:17 -07:00
Robert Widmann
d7cd605c31 Adjust the Registration of the Pseudo-Job for External Incremental Dependencies
Register the module the external dependencies ride in with the pseudo-job in the Driver. This is a hack.
2020-10-05 18:42:28 -07:00
Robert Widmann
964f640636 Drop "Private Deps" Flag
In order for type body fingerprints to work, these declarations must always be included. Drop the ability to turn this off.
2020-10-01 14:40:45 -07:00
Robert Widmann
74765a8ba8 Remove Type Body Fingerprints Flags
This infrastructure has more than proven itself. Drop the code paths and tests supporting the status quo.
2020-10-01 13:09:00 -07:00
Robert Widmann
e35f060144 Install Incremental External Dependency Integration Code
An incremental build involving incremental external dependencies behaves as a hybrid between an external dependency and a normal swiftdeps-laden Swift file.

In the simplest case, we will fall back to the behavior of a plain external dependency today. That is, we will check its timestamp, then schedule all jobs that involve these external dependencies if it is out of date.

Where things get interesting is when cross-module incremental builds are enabled. In such a case, we know that a previous compiler has already emitted serialized swiftdeps information inside of a swiftmodule file. Moreover, we know that that swiftmodule file was loaded by the build of the current swift module. Finally, thanks to the previous stack of commits, we now know exactly how to extract this information from the swiftmodule file. To bring this all home, we unpack incremental dependency information from external dependencies, then integrate them into the current dependency graph - as though they were any other swiftdeps file. This neatly extends the single-module incremental logic to the multi-module case.
2020-09-25 11:45:58 -06:00
Robert Widmann
3ba33b93eb Install Faux Cross-Module Incremental Infrastructure In Driver
Treat any incremental external depends like normal external depends. This will eventually become the fallback behavior for cross-module incremental builds.
2020-09-25 01:16:01 -06:00
Robert Widmann
48415ad228 [NFC] Stage in driver flags for experimental cross-module incremental builds 2020-09-24 17:10:57 -06:00
Robert Widmann
14188f4428 Remove ~moduleonly Duplicate of Compilation Record
We thought we would need this while exploring  certain pre-build optimizations a la rdar://problem/37725110. This information was never used.
2020-09-24 11:42:06 -06:00
David Ungar
6171c4105b Remove bogus assertion with explanation. 2020-07-14 15:09:04 -07:00