Skip to content

[Frontend] Lock the swiftmodule when rebuilding from the swiftinterface #36185

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 2 commits into from
Mar 3, 2021

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Feb 26, 2021

When rebuilding a module interface from the textual interface, lock the destination path of the created swiftmodule instead of the source swiftinterface. The swiftinterface files are likely to be in the SDK and may be on a read-only filesystem.

rdar://60247977

I'm reenabling the test at the same time.

@xymus xymus requested review from nkcsgexi and artemcm February 26, 2021 18:17
@xymus
Copy link
Contributor Author

xymus commented Feb 26, 2021

@swift-ci Please smoke test

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

If we have a one-to-many situation where multiple frontends are building the same interface file into multiple binary modules at different paths, we will now spawn more threads and do this in parallel, vs. one-by-one.

I don't imagine being a problem because we are mostly building into the same location in the Module Cache, but do we know of any other scenarios where this could cause trouble?

@xymus
Copy link
Contributor Author

xymus commented Feb 26, 2021

@swift-ci Please smoke test macOS

@xymus
Copy link
Contributor Author

xymus commented Feb 26, 2021

I think this version is more reliable in this scenario because if a different process was waiting on another one to rebuild the module for a different cache it would have been in vain.

I'd like @nkcsgexi opinion on this, in case I missed something.

@xymus
Copy link
Contributor Author

xymus commented Feb 26, 2021

@swift-ci Please smoke test macOS

@xymus
Copy link
Contributor Author

xymus commented Feb 26, 2021

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Feb 28, 2021

@swift-ci Please smoke test macOS

@xymus
Copy link
Contributor Author

xymus commented Feb 28, 2021

@swift-ci Please smoke test Windows

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this, @xymus !

xymus added 2 commits March 2, 2021 11:04
When rebuilding a module interface from the textual interface, lock the
destination path of the created swiftmodule instead of the source
swiftinterface. The swiftinterface files are likely to be in the SDK and
may be on a read-only filesystem.

rdar://60247977
The APIJSON tests used the default module cache and generated different
modules under the same name. This lead some tests to load a different
module than intended. This was made more easily detectable with the lock
on the swiftmodules instead of the swiftinterfaces.
@xymus xymus force-pushed the move-lock-files branch from 8a7f163 to a18c2a1 Compare March 2, 2021 20:44
@xymus
Copy link
Contributor Author

xymus commented Mar 2, 2021

The APIJSON tests were failing because they share a module cache and use the same name for different modules. They were writing to the the same swiftmodule file which then made some parallel tests read from the swiftmodule generated by another test. This was made more easily detectable with the lock on the swiftmodules instead of the swiftinterfaces. Using local module cache should be enough to avoid this. cc @cachemeifyoucan

@swift-ci Please smoke test

@cachemeifyoucan
Copy link
Contributor

The APIJSON tests were failing because they share a module cache and use the same name for different modules. They were writing to the the same swiftmodule file which then made some parallel tests read from the swiftmodule generated by another test. This was made more easily detectable with the lock on the swiftmodules instead of the swiftinterfaces. Using local module cache should be enough to avoid this. cc @cachemeifyoucan

@swift-ci Please smoke test

Thanks for fixing

@xymus
Copy link
Contributor Author

xymus commented Mar 2, 2021

@swift-ci Please smoke test Windows

@xymus xymus merged commit b209f72 into swiftlang:main Mar 3, 2021
@xymus xymus deleted the move-lock-files branch March 3, 2021 00:29
Comment on lines +5 to +21
// RUN: echo 'public func foo() {}' > %t/sdk/Foo.swift
// RUN: %target-swift-frontend-typecheck -emit-module-interface-path %t/sdk/Foo.swiftinterface %t/sdk/Foo.swift -enable-library-evolution
// RUN: chmod a-w %t/sdk

// RUN: touch %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift
// RUN: echo 'import Foo' > %t/file-01.swift
// RUN: echo 'import Foo' > %t/file-02.swift
// RUN: echo 'import Foo' > %t/file-03.swift
// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t -Xfrontend -Rmodule-interface-rebuild -module-cache-path %t/module-cache &> %t/result.txt
// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t/sdk -Xfrontend -Rmodule-interface-rebuild -module-cache-path %t/module-cache &> %t/result.txt
// RUN: %FileCheck %s -check-prefix=CHECK-REBUILD < %t/result.txt

// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t -Xfrontend -Rmodule-interface-rebuild -Xfrontend -disable-interface-lock -module-cache-path %t/module-cache-no-lock &> %t/result.txt
// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t/sdk -Xfrontend -Rmodule-interface-rebuild -Xfrontend -disable-interface-lock -module-cache-path %t/module-cache-no-lock &> %t/result.txt

// RUN: %FileCheck %s -check-prefix=CHECK-REBUILD-NO-LOCK < %t/result.txt

// Reset the permissions
// RUN: chmod a+w %t/sdk
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test is brittle for incremental builds. It really needs a chmod a+x at the start of the test to reset %t/sdk to a known good state before running line 5: echo 'public func foo() {}' > %t/sdk/Foo.swift

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