Skip to content

Verify that just-emitted module interfaces parse and typecheck #33114

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 6 commits into from
Aug 25, 2020

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Jul 25, 2020

This PR makes Swift verify module interfaces and private module interfaces after emitting them. To do this, it adds a new frontend mode, -typecheck-module-from-interface, and modifies the driver to optionally schedule a typechecking job for each emitted module interface after merge-modules.

This is currently done unconditionally, but I'll probably add some kind of flag later on to turn it on only when requested. This extra verification step is enabled by default in assert compilers, but can be enabled in any compiler by passing the -verify-emitted-module-interface flag to the driver.

Fixes rdar://66710563.

@beccadax beccadax force-pushed the check-your-interfaces-at-the-door branch from 68453ce to d602bca Compare August 3, 2020 08:19
@beccadax beccadax marked this pull request as ready for review August 3, 2020 08:19
@beccadax beccadax changed the title WIP: Verify that just-emitted module interfaces parse and typecheck Verify that just-emitted module interfaces parse and typecheck Aug 3, 2020
@beccadax
Copy link
Contributor Author

beccadax commented Aug 3, 2020

@swift-ci please test

@beccadax beccadax requested review from harlanhaskins and nkcsgexi and removed request for harlanhaskins August 3, 2020 08:21
@beccadax
Copy link
Contributor Author

beccadax commented Aug 3, 2020

I still need to figure out how this should interact with the prebuild script's -check-only flag. Should that mode use -typecheck-from-module-interface instead of -compile-from-module-interface?

Edit: No. -check-only still builds modules from the interfaces (and needs to do so); it just skips work that's unnecessary if we know the prebuilt cache will be thrown away quickly.

@swift-ci
Copy link
Contributor

swift-ci commented Aug 3, 2020

Build failed
Swift Test OS X Platform
Git Sha - d602bca81e4e03262bdd117ebdf4eb2c62b1b00d

@swift-ci
Copy link
Contributor

swift-ci commented Aug 3, 2020

Build failed
Swift Test Linux Platform
Git Sha - d602bca81e4e03262bdd117ebdf4eb2c62b1b00d

@@ -116,6 +116,8 @@ class FrontendOptions {

/// Build from a swiftinterface, as close to `import` as possible
CompileModuleFromInterface,
/// Same as CompileModuleFromInterface, but stopping after typechecking
TypecheckModuleFromInterface,
Copy link
Contributor

Choose a reason for hiding this comment

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

Great addition overall! Why not we just reuse CompileModuleFromInterface action instead of defining a new one? We could potentially add another flag to indicate stopping after typechecking for -compile-module-from-interface. Maintaining an additional frontend action doesn't seem appealing to me.

Copy link
Contributor Author

@beccadax beccadax Aug 3, 2020

Choose a reason for hiding this comment

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

-typecheck and -compile-module-from-interface are both compiler modes (ModeOpts), so they're mutually exclusive. Also note that their behavior is pretty different—if you take a look at the FrontendOptions.cpp diff, ActionType::TypecheckModuleFromInterface's behavior tends to match ActionType::Typecheck, not ActionType::CompileModuleFromInterface.

There's something to be said for the idea of removing -compile-module-from-interface and instead having people use -emit-module to do that; either there would be a flag to restart the compilation in the module interface builder, or this would just happen automatically when you passed a module interface. This would have a couple of nice benefits, like allowing other flags such as -dump-ast or -emit-sil. But that would be a much bigger change and I'm not sure it can be fully justified.

(Ultimately, I think the new driver probably ought to treat .swiftinterface inputs as implicitly being requests to either compile or typecheck the interface—not sure which. But that's a whole different story, and I think it's better handled in the new driver instead of the old one.)

@beccadax beccadax force-pushed the check-your-interfaces-at-the-door branch from d602bca to 43a8e5e Compare August 3, 2020 19:04
@beccadax beccadax force-pushed the check-your-interfaces-at-the-door branch from 43a8e5e to 5488473 Compare August 7, 2020 23:00
@beccadax
Copy link
Contributor Author

beccadax commented Aug 7, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Aug 7, 2020

Build failed
Swift Test Linux Platform
Git Sha - d602bca81e4e03262bdd117ebdf4eb2c62b1b00d

@swift-ci
Copy link
Contributor

swift-ci commented Aug 7, 2020

Build failed
Swift Test OS X Platform
Git Sha - d602bca81e4e03262bdd117ebdf4eb2c62b1b00d

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.
Isolated into its own commit so that it can be reverted easily.
@beccadax
Copy link
Contributor Author

beccadax commented Aug 8, 2020

SwiftPM test is failing:

18:14:35 Test Case '-[CommandsTests.BuildToolTests testParseableInterfaces]' started.
18:14:35 /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-master/swiftpm/Tests/CommandsTests/BuildToolTests.swift:205: error: -[CommandsTests.BuildToolTests testParseableInterfaces] : failed - error: failed parsing the Swift compiler output: unexpected JSON message: : keyNotFound(CodingKeys(stringValue: "outputs", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"outputs\", intValue: nil) (\"outputs\").", underlyingError: nil))

Seems totally plausible that something might need to be updated there.

@beccadax
Copy link
Contributor Author

With swiftlang/swift-package-manager#2854

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 5488473c17bf85906223f8b79b4943844c725012

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5488473c17bf85906223f8b79b4943844c725012

@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax beccadax merged commit 8fbd449 into swiftlang:master Aug 25, 2020
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.

3 participants