Skip to content

SILGen tests: always build modules and API notes when importing the mock SDK #4622

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

Closed
wants to merge 1 commit into from

Conversation

gribozavr
Copy link
Contributor

Previously, only test/SILGen/objc_nonnull_lie_hack.swift would build the API notes for the 'gizmo' module. Depending on the order in which tests ran, the module cache would either contain the 'gizmo' module with nullability annotations, or without. If we were unlucky and the module cache was created by a test that did not build the API notes, test/SILGen/objc_nonnull_lie_hack.swift failed.

This change also removes 46 instances of -enable-source-import (63 more left in the testsuite).

@gribozavr
Copy link
Contributor Author

@jrose-apple Would you mind reviewing?

@gribozavr
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Sep 3, 2016

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 1ccb7f47759f13409021828efb988c3757fb5b4e
Test requested by - @gribozavr

@gribozavr gribozavr force-pushed the silgen-tests-should-build-modules branch from 1ccb7f4 to ad16044 Compare September 4, 2016 00:21
@gribozavr
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Sep 4, 2016

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - ad1604484a1534f06271a1d2fe698c1b4d78c01a
Test requested by - @gribozavr

@gribozavr gribozavr force-pushed the silgen-tests-should-build-modules branch from ad16044 to c4abeed Compare September 4, 2016 02:17
@gribozavr
Copy link
Contributor Author

@swift-ci Please clean test

@swift-ci
Copy link
Contributor

swift-ci commented Sep 4, 2016

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - ad1604484a1534f06271a1d2fe698c1b4d78c01a
Test requested by - @gribozavr

@gribozavr
Copy link
Contributor Author

@swift-ci Please test

…ock SDK

Previously, only test/SILGen/objc_nonnull_lie_hack.swift would build the
API notes for the 'gizmo' module.  Depending on the order in which tests
ran, the module cache would either contain the 'gizmo' module with
nullability annotations, or without.  If we were unlucky and the module
cache was created by a test that did not build the API notes,
test/SILGen/objc_nonnull_lie_hack.swift failed.

This change also removes 46 instances of '-enable-source-import'
(63 more left in the testsuite).
@gribozavr gribozavr force-pushed the silgen-tests-should-build-modules branch from c4abeed to 80c5cd1 Compare September 6, 2016 05:48
@gribozavr
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor

It might be worth it at this point to fix the actual problem: we don't have a way to prepare the mock-SDK overlays beforehand. Building N copies of the overlays is silly and moderately expensive, and using a standard substitution is both including some unnecessary ones and (in some cases) leaving out some necessary ones as well. It doesn't help that the real overlays get used if the mock ones haven't been built.

@gribozavr
Copy link
Contributor Author

It might be worth it at this point to fix the actual problem: we don't have a way to prepare the mock-SDK overlays beforehand.

While I agree that would be the ultimate fix, this PR is an easy/mechanical change and I have prepared the patch. Are you opposed to landing it as is?

Building N copies of the overlays is silly and moderately expensive

I measured, this change only added 1 second to total testing time on my machine. (Only measured the SilGen directory to cut down the noise.)

@jrose-apple
Copy link
Contributor

You're right, getting -enable-source-import out of more tests is a good thing. How much do we care about SILGen tests accidentally using the real SDK?

@gribozavr
Copy link
Contributor Author

How much do we care about SILGen tests accidentally using the real SDK?

These days nullability is not flipping often, so I don't care that much. What prompted me to create this PR is the difference between APINotes for the gizmo module. All tests importing it should see the apinotes, otherwise (as the PR description explains) depending on the run order, we get test failures.

@jrose-apple
Copy link
Contributor

I agree about that, but that wasn't really the only change. The more I think about it the weirder it seems that %build-silgen-test-overlays would build gizmo's API notes but not objc_protocols_Bas or whatever. How is anyone supposed to know that?

The right answer to the API notes problem is to have API notes treated as a dependency for the module, and we should do that anyway. It's just not as straightforward as it should be (the bug has bounced between @DougGregor, @milseman, and me).

@gribozavr
Copy link
Contributor Author

The more I think about it the weirder it seems that %build-silgen-test-overlays would build gizmo's API notes but not objc_protocols_Bas or whatever. How is anyone supposed to know that?

I can add objc_protocols_Bas to the substitution as well, but it was used in only one test so I decided it is not worth the compilation time.

If you are saying that %build-silgen-test-overlays is a bad name, then I agree that at this point it is a bad name, and it should be something like %build-silgen-test-fixture. What do you think?

@jrose-apple
Copy link
Contributor

My problem isn't with the name, it's that I have no idea what it does. Before I would assume it built the overlays equivalent to the real ones, i.e. anything related to the public SDK. (In practice these substitutions build a few things up to Foundation; no AppKit or UIKit and no support modules like Dispatch.) I'm realizing now that that is a shaky assumption as well.

I don't want to get into this situation:

"My test isn't working."
"Do you have %build-silgen-test-overlays?"
"Oh, no. Do I need that?"
"Usually you need it if you use anything from SILGen's mock SDK."
"Okay, that makes sense, I guess. ...Nope, still doesn't work."
"Hm. Oh, it doesn't build that one."
"Huh. Why not?"
"Probably only one other test was using it."
"Well, should I add it to the substitution, or...?"

The answer might be "if it's used by more than one test", but that's not a very satisfying answer to me. The reason the substitutions were added were partially the repetition, but more because the dependencies of a module aren't obvious from the test. That doesn't apply to leaf modules imported by just the one test.

@gribozavr
Copy link
Contributor Author

@jrose-apple Are you opposed to this PR landing as is? I'm still getting spurious failures in the testsuite locally because of the reasons I explained in the PR description. We even had this on the bots: https://ci.swift.org/job/swift-PR-osx/3518/console

@jrose-apple
Copy link
Contributor

If we're just looking for a quick fix, we can use a separate module cache for that one test. That shouldn't force the decision here.

@gribozavr
Copy link
Contributor Author

My problem isn't with the name, it's that I have no idea what it does.

It builds an environment for the SILGen tests. You said:

Rather than remember which of %empty-directory, %target-build-xyz-overlays, etc. needs to go at the top of each test, lit should just do it.

If %build-silgen-test-overlay was implicitly injected by lit, I don't think it addresses your concern that you don't understand what it does -- it might even be worse because you don't understand what it does, and you don't see it in your test file. So I'm confused by now.

"Well, should I add it to the substitution, or...?"
The answer might be "if it's used by more than one test",

So what would be the ideal solution? That the test source would be somehow scanned for dependencies and everything was automatically built? (But how do you determine build parameters then? Some tests require special parameters, for example, enabling resilience.)

jrose-apple added a commit to jrose-apple/swift that referenced this pull request Sep 15, 2016
Discussed in swiftlang#4622. Filed
rdar://problem/28313536 to make sure we re-enable it.
jrose-apple added a commit that referenced this pull request Sep 15, 2016
#4789)

Discussed in #4622. Filed
rdar://problem/28313536 to make sure we re-enable it.
@slavapestov
Copy link
Contributor

@gribozavr @jrose-apple What's the latest on this? I would love to see this get merged in. We really need to get rid of -enable-source-import.

@jrose-apple
Copy link
Contributor

This is really only coincidentally related to -enable-source-import. The argument was mostly over what needs to be spelled out explicitly and what should be folded into a substitution.

It's actually possible that with Doug fixing the issue of API notes not being included as module dependencies (apple/swift-clang@1bc5dd5) that we don't hit the original issue that prompted this whole thing, but that doesn't mean it's not worthwhile to get rid of -enable-source-import.

@slavapestov
Copy link
Contributor

@jrose-apple Gentle poke about this PR

@jrose-apple
Copy link
Contributor

Doesn't deserve to be gentle. :-) Thanks, Slava.

@jrose-apple jrose-apple self-assigned this Jan 10, 2017
@CodaFi
Copy link
Contributor

CodaFi commented Nov 14, 2019

@jrose-apple What do you want to do about this pull request?

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 80c5cd1

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 80c5cd1

@jrose-apple
Copy link
Contributor

I now/still believe #20957 is the right answer to this whole mess, but as neither me nor Dmitri are currently working on Swift…

I do think it always makes sense to be consistent about API notes for mock modules, but that doesn't need this whole patch.

@DougGregor
Copy link
Member

Yeah, let's close this.

@DougGregor DougGregor closed this Dec 6, 2019
@DougGregor DougGregor deleted the silgen-tests-should-build-modules branch December 6, 2019 00:29
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.

6 participants