Commit Graph

684 Commits

Author SHA1 Message Date
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
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
Xi Ge
e4916b8c85 Front-end: add a front-end action to print supported features of the compiler
This could help swift-driver to check whether a compiler feature is supported so
it could adjust arguments accordingly.
2020-11-09 14:34:49 -08: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
703eece10d [NFC] Extract ModuleInputs as a Separate Utility
The driver will eventually use this to compute the input status of a merge-modules job.
2020-10-07 16:56:48 -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
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
Artem Chikin
12c356b3d2 Merge pull request #34028 from artemcm/dependencies-prescan
[Dependency Scanner] Add option to execute an import prescan
2020-09-22 14:48:56 -07:00
Artem Chikin
e0dbba569b [Dependency Scanner] Add option to execute an import prescan
With this option enabled, the dependency scanner gathers all import statements in source files of the main module (non-transitive) and outputs a list of imported modules.
This will be used by build systems and the swift-driver as a way to avoid redundant re-scanning in incremental contexts.
2020-09-22 11:04:31 -07:00
Michael Gottesman
f196c16532 Merge pull request #32430 from kateinoigakukun/katei/llvm-lto-driver
[LTO] Support LLVM LTO for driver
2020-09-18 14:49:07 -05:00
Xi Ge
c25d6ff08b ModuleInterface: avoid verifying textual interfaces without -enable-library-evolution
Textual interfaces without -enable-library-evolution aren't properly supported. We should
avoid verifying them too.

rdar://68223978
2020-09-09 12:16:22 -07:00
Yuta Saito
43fb346b67 [Frontend] Set up output file .swiftmodule.summary
This patch focus on teaching frontend and driver to emit this file.
The actual serialization and deserialization implementation will come
later.
2020-08-27 00:41:16 +09:00
Brent Royal-Gordon
f82420491c Verify interfaces by default in assert compilers
Isolated into its own commit so that it can be reverted easily.
2020-08-07 17:45:04 -07:00
Brent Royal-Gordon
5f523fee66 Add flag to verify just-emitted module interfaces
The driver can now schedule jobs which typecheck just-emitted module interfaces to ensure that they can be consumed later. This can be enabled manually by passing `-verify-emitted-module-interface` to the driver.
2020-08-07 17:45:03 -07:00
Dario Rexin
7e60a73335 Merge pull request #33168 from drexin/wip-fix-resource-folder
Properly compute resource folder when linking statically
2020-08-04 12:52:38 -07:00
Yuta Saito
d6cddaabb5 [LTO] Support LLVM LTO for driver
This commit adds LTO support for handling linker options and LLVM BC
emission. Even for ELF, swift-autolink-extract is unnecessary because
linker options are embeded in LLVM BC content when LTO.
2020-07-31 10:17:59 +09:00
Dario Rexin
0850436d9f Properly compute resource folder when linking statically
- deduplicate the logic to compute the resource folder
- install headers and module files in shared and static resource folders
- forward -static flag when calling swiftc with -print-target-info
2020-07-30 15:07:03 -07:00
Artem Chikin
746e89b252 Rename external dependencies to placeholder dependencies. 2020-07-27 09:24:36 -07:00
Artem Chikin
b5af62f93f Add new dependency kind (swiftExternal) to model external dependencies. 2020-07-27 09:24:35 -07:00
Artem Chikin
c52982c9de Add option to accept external module dependency map as input
With: `-external-dependency-module-map-file`
2020-07-27 09:24:35 -07:00
Doug Gregor
ad9a7efaca [Driver] .tbd files are linker inputs 2020-06-17 10:27:49 -07:00
Keith Smiley
1b77448d37 Add path remapping with -coverage-prefix-map to coverage data
Previously the path to covered files in the __LLVM_COV / __llvm_covmap
section were absolute. This made remote builds with coverage information
difficult because all machines would have to have the same build root.
This change uses the values for `-coverage-prefix-map` to remap files in
the coverage info to relative paths. These paths work correctly with
llvm-cov when it is run from the same source directory as the
compilation, or from a different directory using the `-path-equivalence`
argument.

This is analogous to this change in clang https://reviews.llvm.org/D81122
2020-06-15 17:38:34 -07:00
Saleem Abdulrasool
71309a8fa9 Revert "[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows" 2020-06-07 11:25:48 -07:00
Saleem Abdulrasool
d0131ba6be Merge pull request #31146 from kateinoigakukun/katei/enable-lang-agnostic-lto
[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows
2020-06-05 11:38:09 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Yuta Saito
915c4a6997 [LTO] Support LLVM level link time optimization
This commit adds -lto flag for driver to enable LTO at LLVM level.
When -lto=llvm given, compiler emits LLVM bitcode file instead of object
file and perform thin LTO using libLTO.dylib plugin.
When -lto=llvm-full given, perform full LTO instead of thin LTO.
2020-05-31 08:12:52 +09:00
Slava Pestov
368d47429d Frontend: Remove coarse-grained dependency graph implementation 2020-04-29 16:55:53 -04:00
Doug Gregor
33cdd61835 Fast dependency scanning for Swift
Implement a new "fast" dependency scanning option,
`-scan-dependencies`, in the Swift frontend that determines all
of the source file and module dependencies for a given set of
Swift sources. It covers four forms of modules:

1) Swift (serialized) module files, by reading the module header
2) Swift interface files, by parsing the source code to find imports
3) Swift source modules, by parsing the source code to find imports
4) Clang modules, using Clang's fast dependency scanning tool

A single `-scan-dependencies` operation maps out the full
dependency graph for the given Swift source files, including all
of the Swift and Clang modules that may need to be built, such
that all of the work can be scheduled up front by the Swift
driver or any other build system that understands this
option. The dependency graph is emitted as JSON, which can be
consumed by these other tools.
2020-04-24 12:58:41 -07:00
Doug Gregor
c59abcd543 Merge pull request #31154 from DougGregor/restrict-simulator-inference
[Darwin] Restrict inference of the simulator environment
2020-04-20 12:54:37 -07:00
Doug Gregor
b63e9a6bcf [Frontend] Infer simulator environment in the frontend, too.
Some code paths that see target triples go through the frontend
without seeing the driver. Therefore, perform the same "simulator"
inference for x86 iOS/tvOS/watchOS triples also in the frontend,
to ensure that we remain compatible. Also make sure that
-print-target-info performs the appropriate adjustment.
2020-04-20 08:50:35 -07:00
Doug Gregor
38e3621bf1 [Driver] Infer simulator-ness for iOS/tvOS/watchOS.
Localize the hack to infer simulator-ness of the target in the driver
itself, when it first processes the target. Emit a warning about the
missing "-simulator" and correct the triple immediately.

This gives a longer grace period for tools that might still not pass
through the simulator environment, while narrowing the hack.
2020-04-20 08:50:35 -07:00
Artem Chikin
c11f013101 Merge pull request #31099 from artemcm/NoWarningsAsErrorsOption
Add compiler option to *disable* warnings-as-errors
2020-04-20 08:35:53 -07:00
Saleem Abdulrasool
fbbf61f297 Revert "[Darwin] Further restrict inference of the simulator environment" 2020-04-19 16:43:22 -07:00
Doug Gregor
22cdddd84e Merge pull request #30771 from DougGregor/stop-inferring-simulator
[Darwin] Further restrict inference of the simulator environment
2020-04-17 20:59:39 -07:00
Artem Chikin
c3b0232c2c Add compiler option to *disable* warnings-as-errors
`-no-warnings-as-errors`

This functionality is required for build systems to be able to overload/disable a given Swift project's preference of treating warnings as errors.

Resolves rdar://problem/35699776
2020-04-17 12:10:26 -07:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
Doug Gregor
8339f32184 [Frontend] Infer simulator environment in the frontend, too.
Some code paths that see target triples go through the frontend
without seeing the driver. Therefore, perform the same "simulator"
inference for x86 iOS/tvOS/watchOS triples also in the frontend,
to ensure that we remain compatible. Also make sure that
-print-target-info performs the appropriate adjustment.
2020-04-16 21:42:43 -07:00
Doug Gregor
643491e37c [Driver] Infer simulator-ness for iOS/tvOS/watchOS.
Localize the hack to infer simulator-ness of the target in the driver
itself, when it first processes the target. Emit a warning about the
missing "-simulator" and correct the triple immediately.

This gives a longer grace period for tools that might still not pass
through the simulator environment, while narrowing the hack.
2020-04-16 13:24:11 -07:00
Doug Gregor
970ff6b818 [Driver] Read SDK version information to pass to the Darwin linker.
Recent-ish SDKs for Darwin platforms include an SDKSettings.json
file with version information and Catalyst SDK version mappings. Read
these (when available) and use them to pass the appropriate SDK
version down to the Darwin linker via `-platform_version`.

Finishes rdar://problem/55972144.
2020-04-02 21:07:26 -07:00
Alex Langford
8953af519f [Driver] Don't pass ELF shared objects to swift-autolink-extract
Prior to performing linking on ELF platforms (except the PS4) we extract
autolink information from the object files that will be used during linking.
The current implementation passes all the linker inputs that are marked as an
TY_Object to swift-autolink-extract. There are a two cases where this is
not necessary or problematic.

In the first case, we are looking at an ELF shared object. Although
harmless, this is wasted work. Specifically, the `.swift1_autolink_entries`
entry in the object files are marked as `SHF_EXCLUDE`, meaning they will not be
merged into the final product during linking.

In the second case, we are linking against a linker script that looks like an
ELF shared object (ends with `.so`). In the previous case, the autolink-extract
step will succeed even if it does unnecessary work. In this case, the
autolink-extract step will fail because it cannot recognize the linker script as
an object file. You will observe an error something like this:
```
<unknown>:0: error: error opening input file '/path/to/libLinkerScript.so'
(The file was not recognized as a valid object file
```
Although your linker will know what to do with it, autolink-extract will halt
before you get to that point.
2020-03-17 21:54:00 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Robert Widmann
ef149d5c86 Merge pull request #30135 from CodaFi/verily-i-depend-on-thee
[Incremental] Introducing: DependencyVerifier
2020-03-03 22:01:38 -08:00
Robert Widmann
f85ec3825f Address review feedback 2020-03-03 16:46:04 -08:00
Visoiu Mistrih Francis
aaab1869af Merge pull request #29650 from francisvm/sil-remark-streamer
[Remarks] Add a specialized RemarkStreamer for SIL remarks
2020-03-03 09:30:17 -08:00
Francis Visoiu Mistrih
e724ebab6b [Remarks] Add a specialized RemarkStreamer for SIL remarks
This allows the usage of the whole remark infrastructure developed in
LLVM, which includes a new binary format, metadata in object files, etc.

This gets rid of the YAMLTraits-based remark serialization and does the
plumbing for hooking to LLVM's main remark streamer.

For more about the idea behind LLVM's main remark streamer, see the
docs/Remarks.rst changes in https://reviews.llvm.org/D73676.

The flags are now:

* -save-optimization-record: enable remarks, defaults to YAML
* -save-optimization-record=<format>: enable remarks, use <format> for
serialization
* -save-optimization-record-passes <regex>: only serialize passes that
match <regex>.

The YAMLTraits in swift had a different `flow` setting for the debug
location, resulting in some test changes.
2020-03-02 18:33:20 -08:00