Skip to content

Conversation

@harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Feb 14, 2019

Essentially, this changes how we process the entries in the prebuilt cache dir. Previously, we would always take whatever's in the prebuilt cache, even if its dependencies changed, invalidating it. This emulated the current module loading behavior, where we don't have the option to fall back on recompiling a parseable interface.

With this change, dependencies of prebuilt modules are based on the hash of the contents of the dependency, rather than modification times. Since hashing every dependency is expensive, we install a smaller "forwarding module" in the Regular Cache, which contains the mtimes from the last time we validated the dependencies. On further loads of this module, we will validate dependencies using the forwarding module and then load the underlying module without validating its dependencies.

@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch 6 times, most recently from 2b706ab to a3a0e01 Compare February 19, 2019 00:03
@harlanhaskins harlanhaskins changed the title [WIP] [ParseableInterface] Handle out-of-date modules in the prebuilt cache [ParseableInterface] Handle out-of-date modules in the prebuilt cache Feb 19, 2019
@harlanhaskins harlanhaskins changed the title [ParseableInterface] Handle out-of-date modules in the prebuilt cache [ParseableInterface] Flesh out parseable module loading Feb 19, 2019
@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch 3 times, most recently from 700990e to 77e604f Compare February 19, 2019 22:29
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 77e604ffc329649874105f0948d471f262d2ef79

@harlanhaskins
Copy link
Contributor Author

@swift-ci please test macOS platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 77e604ffc329649874105f0948d471f262d2ef79

@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch from 77e604f to a738308 Compare February 20, 2019 01:23
@harlanhaskins
Copy link
Contributor Author

@swift-ci please python lint

@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch from a738308 to 38b10fa Compare February 20, 2019 01:57
@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch from 38b10fa to 4a049a2 Compare February 20, 2019 23:39
@harlanhaskins
Copy link
Contributor Author

@swift-ci please python lint

@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch 2 times, most recently from 0cc522c to b37bba0 Compare February 21, 2019 00:53
@swift-ci
Copy link
Contributor

swift-ci commented Mar 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - f976477d3daf9cf9fe6d2ba46c2fc934364f4ab9

Harlan Haskins added 2 commits March 5, 2019 11:46
Add a bit to the module to determine whether the dependency’s stored bit pattern is a hash or an mtime.

Prebuilt modules store a hash of their dependencies because we can’t be sure their dependencies will have the same modtime as when they were built.
Since prebuilt modules are going to use hashes for their dependencies, we need a flag to turn that behavior on. By default, we use modification times.
@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch 2 times, most recently from b1d0d17 to c932ec8 Compare March 5, 2019 19:50
Copy link
Contributor

@benlangmuir benlangmuir left a comment

Choose a reason for hiding this comment

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

Something we do for clang modules that I don't see here: if there are multiple processes trying to load the same module, we use lock files to avoid rebuilding the same module concurrently. This isn't needed for correctness if you can keep the just-built module in memory, but it could save battery. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a canonicalized path? If not, maybe it should be?

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's whatever module lookup resolved to, which may have come from command-line search paths. So it probably should be.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a canonicalized path? If not, maybe it should be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the only canonicalization we perform is removing a trailing '/' when it's set. Given that this is a command-line flag, we probably should.

@ghost
Copy link

ghost commented Mar 6, 2019

Based on the number of comments you may wish to refactor and resubmit. This many comments does not mean your idea is bad. Simply that it is not ready for review.

@benlangmuir
Copy link
Contributor

@openloop, I don't think there's anything here that requires a new PR. The author has been working closely with the reviewers to solve the outstanding issues.

Copy link
Contributor

@benlangmuir benlangmuir left a comment

Choose a reason for hiding this comment

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

@harlanhaskins will address the issues I raised about re-reading module files and re-stat-ing as follow-ups, and similarly for the optimization level. My other feedback has been resolved. Thanks!

A ‘forwarding module’ is a YAML file that’s meant to stand in for a .swiftmodule file and provide an up-to-date description of its dependencies, always using modification times.

When a ‘prebuilt module’ is first loaded, we verify that it’s up-to-date by hashing all of its dependencies. Since this is orders of magnitude slower than reading mtimes, we’ll install a `forwarding module` containing the mtimes of the now-validated dependencies.
@harlanhaskins harlanhaskins force-pushed the where-do-i-stash-my-cache-hashes branch from 616a949 to 366bbf4 Compare March 7, 2019 19:37
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 7, 2019

Build failed
Swift Test OS X Platform
Git Sha - c4601da715f626105ff0aeee2479ad516c20aaa2

@swift-ci
Copy link
Contributor

swift-ci commented Mar 7, 2019

Build failed
Swift Test Linux Platform
Git Sha - c4601da715f626105ff0aeee2479ad516c20aaa2

@harlanhaskins
Copy link
Contributor Author

apple/swift-lldb#1328
@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 7, 2019

Build failed
Swift Test OS X Platform
Git Sha - 366bbf4

Copy link
Contributor

@nathawes nathawes 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, Harlan! I only had one trivial comment that I wouldn't worry about unless you have other changes to make anyway.


bool isNormal() const { return kind == Kind::Normal; }
bool isPrebuilt() const { return kind == Kind::Prebuilt; }
bool isForwarding() const { return kind == Kind::Forwarded; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be isForwarded() to match the earlier comments that distinguish the Forwarding module in the regular cache from the Forwarded module in the prebuilt cache?

Copy link
Contributor Author

@harlanhaskins harlanhaskins Mar 7, 2019

Choose a reason for hiding this comment

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

Yep, it should. I'll fix that in a follow-up 😅 It's also unused, so maybe this and isNormal can just go.

@harlanhaskins
Copy link
Contributor Author

apple/swift-lldb#1328
@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2019

Build failed
Swift Test OS X Platform
Git Sha - 366bbf4

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2019

Build failed
Swift Test Linux Platform
Git Sha - 366bbf4

@harlanhaskins
Copy link
Contributor Author

apple/swift-lldb#1328
@swift-ci please test

@swiftlang swiftlang deleted a comment from swift-ci Mar 9, 2019
@harlanhaskins
Copy link
Contributor Author

LLDB failure doesn't seem related.

apple/swift-lldb#1328
@swift-ci please test Linux platform

@swift-ci
Copy link
Contributor

swift-ci commented Mar 9, 2019

Build failed
Swift Test Linux Platform
Git Sha - 366bbf4

@harlanhaskins
Copy link
Contributor Author

apple/swift-lldb#1328
@swift-ci please smoke test Linux platform

@harlanhaskins harlanhaskins merged commit bef1746 into swiftlang:master Mar 10, 2019
harlanhaskins pushed a commit to harlanhaskins/swift that referenced this pull request Mar 11, 2019
…h-my-cache-hashes

[ParseableInterface] Flesh out parseable module loading
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