Skip to content

[ParseableInterface] Make the module caches relocatable and respect -track-system-dependencies #23665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 3, 2019

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Mar 29, 2019

  1. Honor -track-system-dependencies when building parseable interfaces on demand
    • FIXME: won't be tracked when the top-level invocation isn't tracking dependencies at all
  2. Honor -track-system-dependencies with -build-module-from-parseable-interface
  3. Serialize dependencies in the SDK as SDK-relative paths
    • These are expanded to full paths by appending the SDK path when writing out forwarding modules and when checking dependencies are up-to-date.
  4. Stop serializing .swiftmodule dependencies that are from the regular and prebuilt module caches
    • Note: .swiftmodules in the regular module cache still get reported to the dependency tracker. Is this what we want?

Resolves rdar://problem/49292914

@nathawes nathawes requested review from jrose-apple and harlanhaskins and removed request for jrose-apple March 29, 2019 18:54
@nathawes
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick read and it looks pretty good. @harlanhaskins should probably take a look too, and I'll get back to it a second time later today.

@jrose-apple
Copy link
Contributor

Note: .swiftmodules in the regular module cache still get reported to the dependency tracker. Is this what we want?

I've come to a conclusion on this: if we compile the prebuilt modules out of order, they will load swiftmodules from the regular module cache, and it would be bad to mark those as dependencies.

Copy link
Contributor

@harlanhaskins harlanhaskins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment, otherwise this looks great!

@nathawes
Copy link
Contributor Author

nathawes commented Mar 30, 2019

Note: .swiftmodules in the regular module cache still get reported to the dependency tracker. Is this what we want?

I've come to a conclusion on this: if we compile the prebuilt modules out of order, they will load swiftmodules from the regular module cache, and it would be bad to mark those as dependencies.

Good point! I've updated the SDKDependencies.swift test to build the prebuilt modules in both orders and check they don't have any FILE_DEPENDENCY entries containing the module cache path in either case.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, went through it again and I think it's good! Minor comments only.

@nathawes nathawes force-pushed the it-all-depends-take-2 branch 4 times, most recently from d52c19c to 1e05cff Compare April 1, 2019 19:08
@nathawes
Copy link
Contributor Author

nathawes commented Apr 1, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Apr 1, 2019

Build failed
Swift Test Linux Platform
Git Sha - 03716cb33f7d5085da5ca02ba0554571c3582db9

@nathawes
Copy link
Contributor Author

nathawes commented Apr 1, 2019

@swift-ci please test OS X Platform

1 similar comment
@nathawes
Copy link
Contributor Author

nathawes commented Apr 1, 2019

@swift-ci please test OS X Platform

@nathawes
Copy link
Contributor Author

nathawes commented Apr 1, 2019

@swift-ci please smoke test OS X Platform

@swift-ci
Copy link
Contributor

swift-ci commented Apr 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - 03716cb33f7d5085da5ca02ba0554571c3582db9

@nathawes
Copy link
Contributor Author

nathawes commented Apr 2, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Apr 2, 2019

Build failed
Swift Test OS X Platform
Git Sha - 1e05cff26c2e516f09b7dc586bebae094a83b194

@swift-ci
Copy link
Contributor

swift-ci commented Apr 2, 2019

Build failed
Swift Test Linux Platform
Git Sha - 1e05cff26c2e516f09b7dc586bebae094a83b194

// If Dep is itself a .swiftmodule in the cache dir, pull out its deps
// and include them in our own, so we have a single-file view of
// transitive deps: removes redundancies, and avoids opening and reading
// multiple swiftmodules during future loads.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like pulling these in was redundant? I think everything still works because whenever we load/depend on something from the cache we end up adding its serialized dependencies to the dependency tracker when validating that it's up to date, so they show up as one of the initial dependencies here and get serialized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't sound right. What if it's out of date and then we rebuild it and discover it doesn't depend on some of those files anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParseableInterfaceModuleLoaderImpl::dependenciesAreUpToDate() is called by both forwardingModuleIsUpToDate() and swiftModuleIsUpDate() and adds the dependencies to the tracker regardless of whether they are out of date or not, so looks like that's a bug. I'll add a test for it and update the code to only add them to the tracker if they're all up to date.

In the case that they're not up to date though, we then go down the path of generating the swiftmodule from the interface again, and that adds all the SubInstance's dependencies to the tracker (in collectDepsForSerialization()). Since all of its dependencies must be either up to date or rebuilt too, I think us pulling out the serialized deps here is redundant regardless. Does that make sense, or am I still missing something?

Copy link
Contributor

@jrose-apple jrose-apple Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that dependenciesAreUpToDate adds dependencies to the outer tracker at all. That doesn't seem like its job, and that would explain why this code is here. But having it do that does save us a bit of effort in reading from the cached compiled module twice. It at least deserves to be commented loudly, though, since that name sounds like a pure predicate function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, dependenciesAreUpToDate should probably be renamed here. Good catch noticing that it doesn't check if they actually are up to date 😳

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up making it not add the dependencies and added them a few levels up in findOrBuildLoadableModule and updated it's doc to mention that it adds the dependencies to the dependencyTracker too.

@nathawes
Copy link
Contributor Author

nathawes commented Apr 2, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Apr 2, 2019

Build failed
Swift Test Linux Platform
Git Sha - 934c8ff60150ca848be323e063884fbf10244bb0

@nathawes nathawes force-pushed the it-all-depends-take-2 branch from ff30b30 to 0227614 Compare April 3, 2019 00:43
@nathawes
Copy link
Contributor Author

nathawes commented Apr 3, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Apr 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - ff30b30b31378e364e4d1bad47d913cd3967b537

@swift-ci
Copy link
Contributor

swift-ci commented Apr 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - 934c8ff60150ca848be323e063884fbf10244bb0

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, only small comments left.

@nathawes nathawes force-pushed the it-all-depends-take-2 branch from 0227614 to 46e5c86 Compare April 3, 2019 03:36
@nathawes
Copy link
Contributor Author

nathawes commented Apr 3, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Apr 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - 0227614bedc0979254f9523ce270717333890e9c

@swift-ci
Copy link
Contributor

swift-ci commented Apr 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - 0227614bedc0979254f9523ce270717333890e9c

jrose-apple and others added 7 commits April 3, 2019 06:34
One interesting thing here is that the decision of whether or not to
track system dependencies ends up going into the cache key for a
swiftmodule built from a parseable interface, because it affects that
module's up-to-date check. If we didn't include
-track-system-dependencies in the cache key, we could end up tracking
system dependencies for some modules but not others in the same build.

There's a bit of a bug here where they're /not/ honored if the
top-level invocation isn't tracking /any/ dependencies, but given
how uncommon this flag is in practice that's probably okay for now.

Still TODO: honor this for -build-swiftmodule-from-parseable-interface
as well. That's currently not tracking dependencies at all and it
probably should.
…odule-from-parseable-interface

Updates the subinvocation that builds the parseable interface to respect the
-track-system-dependencies flag of the top-level invocation if present, by
including system dependencies in the produced .swiftmodule.
This allows the SDK to be relocated without automatically resulting in a
rebuild.

Based on an old patch from Jordan Rose.
…module cache or prebuilt module cache

*Their* dependencies are already being serialized out, so this shouldn't affect
up-to-date-checking except by alowing the regular and prebuilt module caches to
be relocated without invalidating their contents. In the case of the prebuilt
module cache, this gets us closer to supporting relocation across machines.
…citly check serialized dependencies

Also use the existing check-is-forwarding-module.py script to check for
forwarding modules, rather than doing it manually.
… adding cached modules to the dependency tracker

This patch modifies ParseableInterfaceBuilder::CollectDepsForSerialization to
avoid serializing dependencies from the runtime resource path into the
swiftmodules generated from .swiftinterface files. This means the module cache
should now be relocatable across machines.

It also modifies ParseableInterfaceModuleLoader to never add any dependencies
from the module cache and prebuilt cache to the dependency tracker (in addition
to the existing behaviour of not serializing them in the generated
swiftmodules). As a result, CollectDepsForSerialization no longer checks if the
dependencies it is given come from the cache as they are provided by the
dependency tracker. It now asserts that's the case instead.
…ent dependency tracker

We previously added dependencies to the tracker inline while validating a cached
module's dependencies were up to date. If one of its dependencies ended up being
out of date though, we shouldn't have added the previous dependencies, as that
means the dependency list itself was also out of date.

This patch changes the behavior to only add the module's dependencies once we've
verified they're all up to date.
@nathawes nathawes force-pushed the it-all-depends-take-2 branch from 46e5c86 to 7144dab Compare April 3, 2019 13:35
@nathawes
Copy link
Contributor Author

nathawes commented Apr 3, 2019

@swift-ci please smoke test

@nathawes nathawes merged commit b8a1f2e into swiftlang:master Apr 3, 2019
@nathawes nathawes deleted the it-all-depends-take-2 branch April 3, 2019 15:02
@compnerd
Copy link
Member

compnerd commented Apr 3, 2019

This caused a regression in the Windows build! https://dev.azure.com/compnerd/windows-swift/_build/results?buildId=971

@nathawes
Copy link
Contributor Author

nathawes commented Apr 3, 2019

Sorry @compnerd! PR to hopefully fix the two parseable interface test failures here: #23773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants