Commit Graph

32 Commits

Author SHA1 Message Date
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
2b2c5dcf79 [NFC] Move findJobsToRecompileWhenNodesChange Into The Headers
So the compiler has a chance to see the definition for itself, rather than having to. manually force a specialization.
2020-12-07 15:22:15 -08:00
Robert Widmann
d3c6d36af9 Fixup Use-of-Temporary
The Optional parameter here was being copied instead of being taken by
const reference. The expectation is that we call this function and
extract the data from a ModuleDepGraphNode node, but instead we were
extracting a copy which would promptly blow up.

Thanks ASAN!
2020-10-07 16:13:03 -07:00
Robert Widmann
38b1da30bd Patch Out Use-Of-Stack-After-Free In Cross Module Dependencies
The fake job is entered into the map to satisfy the tracing machinery.
When that same machinery kicks into gear to print out paths, lookups
into the dictionary will access data has gone out of scope.

For now, cut off the read. There will be another refactoring patch that
keeps these temporaries out of the Driver's data structures entirely.

rdar://70053563
2020-10-07 10:18:57 -07:00
Robert Widmann
d695acfed1 Document 'standalone' Parameters 2020-10-06 11:50:00 -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
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
7917d723c3 Teach the Driver to Read Fine-Grained Dependency Graphs in Swiftdeps Files 2020-09-25 11:36:11 -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
d57967569d Drop Interface Dependency Key APIs
Only external edges need this.
2020-09-21 14:47:39 -06:00
David Ungar
6171c4105b Remove bogus assertion with explanation. 2020-07-14 15:09:04 -07:00
Slava Pestov
d59a76c248 Dependencies: New binary format for fine-grained dependency graph 2020-06-10 15:40:55 -04:00
Ben Langmuir
a46b35b5ca More explicit StringRef -> std::string conversions
On the older compiler/stdlib used by our Ubuntu 16.04 bots, the
construction

        std::pair<std::string, X>(StringRef, X)

fails unless you call `.str()`. Newer compilers/stdlib treat this as an
explicit construction, which is what is now needed on master-next, so it
only fails on Ubuntu 16.04.

rdar://60514063
2020-03-18 09:50:56 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
David Ungar
d06cab7378 .str() for fine-grained 2020-02-18 09:51:35 -07:00
David Ungar
314d1e12c3 Reorganization of SourceFileDepGraph building and mocking. 2020-02-14 21:53:45 -07:00
David Ungar
3ac5cebd8f Small fixes and debugging improvements for SwiftDriverTests 2020-02-08 22:45:30 -08:00
David Ungar
286781fc3e Add a unit test for an individual node change, & add ability to set fingerprints in unit tests. 2020-01-29 16:48:42 -08:00
David Ungar
0a3be7575a unit tests compile 2020-01-27 15:14:46 -08:00
David Ungar
d61f6f2f66 Changes to support per-type-body fingerprints. 2020-01-27 15:14:46 -08:00
David Ungar
f696aabffb Merge pull request #29246 from davidungar/fine-grained-off-but-w-tests-rb
[Incremental] Fixes for fine-grained dependencies + tests for them, but off-by-default
2020-01-22 23:21:33 -08:00
David Zarzycki
f185dd66f1 [QoI] Fix -Wrange-loop-analysis warnings 2020-01-19 13:29:23 -05:00
David Ungar
8c2c4ab391 Fixes for fine-grained dependencies 2020-01-16 13:20:27 -08:00
David Ungar
cc89dad526 Fine-grained and driver fixes.
Restructure fine-grained-dependencies to enable unit testing

Get frontend to emit correct swiftdeps file (fine-grained when needed) and only emit dot file for -emit-fine-grained-dependency-sourcefile-dot-files

Use deterministic order for more information outputs.

Set EnableFineGrainedDependencies consistently in frontend.

Tolerate errors that result in null getExtendedNominal()

Fix memory issue by removing node everywhere.

Break up print routine

Be more verbose so it will compile on Linux.

Sort batchable jobs, too.
2020-01-11 21:57:14 -08:00
Saleem Abdulrasool
b483047afe Revert "[Incremental] Dependency fixes in preparation for fine-grained dependencies" 2020-01-09 19:14:47 -08:00
David Ungar
7889bfbcb1 Improvements inspired by review 2020-01-04 20:54:59 -08:00
David Ungar
6fffe724f2 Fine-grained and driver fixes.
Restructure fine-grained-dependencies to enable unit testing

Get frontend to emit correct swiftdeps file (fine-grained when needed) and only emit dot file for -emit-fine-grained-dependency-sourcefile-dot-files

Use deterministic order for more information outputs.

Set EnableFineGrainedDependencies consistently in frontend.

Tolerate errors that result in null getExtendedNominal()

Fix memory issue by removing node everywhere.

Break up print routine

Be more verbose so it will compile on Linux.

Sort batchable jobs, too.
2020-01-04 14:37:06 -08:00
David Ungar
9bfed89e8c markTransitive & markExternal return the jobs, unfmt 2019-12-08 11:15:51 -08:00
David Ungar
bc068ae68e format 2019-12-04 10:51:18 -08:00
David Ungar
2ff5855c63 Rename DependencyGraphImpl -> CoarseGrainedDependencyGraphImpl, unformatted 2019-12-04 10:51:18 -08:00
David Ungar
6a6e9357ef Change "experimental" to "fine-grained". 2019-12-04 08:50:44 -08:00
David Ungar
496e602bff Renaming files 2019-12-04 08:38:59 -08:00