Skip to content

swiftinterface generator confuses @exclusivity(unchecked) and @_optimize(none) on Windows #76279

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

Open
grynspan opened this issue Sep 5, 2024 · 8 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. serialization Area → compiler: Serialization & deserialization textual interfaces Windows Platform: Windows

Comments

@grynspan
Copy link
Contributor

grynspan commented Sep 5, 2024

After merging swiftlang/swift-testing#655, CI started failing with a very curious error:

T:/105/swift/Testing.swiftinterface:156:2: error: '@_optimize(none)' attribute cannot be applied to stored properties
154 | }
155 | @usableFromInline
156 | @_optimize(none) nonisolated(unsafe) internal var failureBreakpointValue: Swift.Int
    |  `- error: '@_optimize(none)' attribute cannot be applied to stored properties
157 | @usableFromInline
158 | @inline(never) internal func failureBreakpoint()

T:/105/swift/Testing.swiftinterface:4:1: error: failed to verify module interface of 'Testing' due to the errors above; the textual interface may be broken by project issues or a compiler bug
  2 | // swift-compiler-version: Swift version 6.1-dev (LLVM bb83b24e1f07337, Swift c3368800501a32d)
  3 | // swift-module-flags: -target x86_64-unknown-windows-msvc -disable-objc-interop -enable-library-evolution -module-link-name Testing -swift-version 6 -O -enable-experimental-feature AccessLevelOnImport -enable-upcoming-feature ExistentialAny -enable-upcoming-feature InternalImportsByDefault -module-name Testing
  4 | public import Swift
    | `- error: failed to verify module interface of 'Testing' due to the errors above; the textual interface may be broken by project issues or a compiler bug

  5 | public import _Concurrency

  6 | public import _StringProcessing

<unknown>:0: error: verify-module-interface command failed with exit code 1 (use -v to see invocation)

This makes no sense because failureBreakpointValue does not have @_optimize(none) on it, it has @exclusivity(unchecked). This issue appears to only affect Windows builds so far.

CI compiler info:

  2 | // swift-compiler-version: Swift version 6.1-dev (LLVM fb5d83939c06f77, Swift a3589c0f0595cad)
  3 | // swift-module-flags: -target x86_64-unknown-windows-msvc -disable-objc-interop -enable-library-evolution -module-link-name Testing -swift-version 6 -O -enable-experimental-feature AccessLevelOnImport -enable-upcoming-feature ExistentialAny -enable-upcoming-feature InternalImportsByDefault -module-name Testing
@grynspan grynspan added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. textual interfaces Windows Platform: Windows labels Sep 5, 2024
grynspan added a commit to swiftlang/swift-testing that referenced this issue Sep 5, 2024
@tshortli tshortli self-assigned this Sep 5, 2024
grynspan added a commit to swiftlang/swift-testing that referenced this issue Sep 5, 2024
Works around the issue described in
swiftlang/swift#76279.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@stmontgomery
Copy link
Contributor

We've gotten reports now that this is affecting Android and FreeBSD, and in some cases Linux (rdar://151357567).

@stmontgomery
Copy link
Contributor

There's a recent build log here: https://ci.swift.org/job/swift-bootstrap-ubuntu-24_04-x86_64/142/console

In that log, I notice

warning: using (deprecated) legacy driver, Swift installation does not contain swift-driver at: '/home/build-user/stages/stage2/usr/bin/swift-driver-new'

I have wondered if perhaps the legacy Swift driver is related to this issue, because we recently saw a similar issue with parsing macro declarations from a .swiftinterface (#81346) and that only reproduced when using the legacy driver.

@stmontgomery
Copy link
Contributor

Minimal reproducer:

> cat test.swift
@exclusivity(unchecked)
@usableFromInline nonisolated(unsafe) var failureBreakpointValue = 0

> cat test2.swift
// Intentionally empty.

> swiftc --version
Apple Swift version 6.1 (swift-6.1-RELEASE)

> swiftc -disallow-use-new-driver -v -emit-module -emit-module-interface-path MyMod.swiftinterface -enable-library-evolution -module-name MyMod test.swift test2.swift

...

MyMod.swiftinterface:10:2: error: '@_optimize(none)' attribute cannot be applied to stored properties
 8 | import _SwiftConcurrencyShims
 9 | @usableFromInline
10 | @_optimize(none) nonisolated(unsafe) internal var failureBreakpointValue: Swift.Int
   |  `- error: '@_optimize(none)' attribute cannot be applied to stored properties
11 | 

MyMod.swiftinterface:1:1: error: failed to verify module interface of 'MyMod' due to the errors above; the textual interface may be broken by project issues or a compiler bug
 1 | // swift-interface-format-version: 1.0
   | `- error: failed to verify module interface of 'MyMod' due to the errors above; the textual interface may be broken by project issues or a compiler bug
 2 | // swift-compiler-version: Apple Swift version 6.1 (swift-6.1-RELEASE)
 3 | // swift-module-flags: -target arm64-apple-darwin24.2.0 -enable-objc-interop -enable-library-evolution -module-name MyMod

@tshortli tshortli added the serialization Area → compiler: Serialization & deserialization label May 16, 2025
@tshortli tshortli assigned xymus and unassigned tshortli May 16, 2025
@tshortli
Copy link
Contributor

This is not a textual interfaces bug but rather a bug with -merge-modules (which is a deprecated compilation mode that is only supported by the legacy Swift driver) causing the AST to be incorrect. I think the recommendation here is to adopt -wmo if use of the legacy Swift driver can't be avoided. I don't think fixing bugs in -merge-modules is something we want to do unless absolutely necessary, but I defer to @xymus on that.

@3405691582
Copy link
Member

3405691582 commented May 16, 2025

Since swiftpm now depends on swift-testing to build, this bites the swiftpm and the stage2 bootstrap also.

The bootstrap_stage2 preset doesn't build the new driver (for whatever reason), but even manually specifying to build the new early Swift driver and/or "late" Swift driver seems to trip this up.

@xymus
Copy link
Contributor

xymus commented May 16, 2025

Generating swiftinterfaces from a merge-module job was never properly supported, it had a tendency to generate bad code and confuse attributes at printing like this. When using the legacy C++ driver the only option to emit usable swiftinterfaces is to use whole-module compilation. The new driver incremental mode (emit-module-separately) does support swiftinterface properly so there's no need to force using whole-module when using the new driver.

Is it possible to update the configuration to use only wmo if we're restricted to using the legacy driver?

I assume this was an issue only in debug builds as release should already use wmo. As a risky alternative, you could disable the swiftinterface verification only in debug builds and expect clients to use only the binary swiftmodule locally. We should never distribute this swiftinterface of course.

@stmontgomery
Copy link
Contributor

Is it possible to update the configuration to use only wmo if we're restricted to using the legacy driver?

@etcwilde is doing this in #81622

I assume this was an issue only in debug builds as release should already use wmo.

Actually no, not until the above PR, as we discovered! It seems as though WMO has not been enabled in any CMake builds of swift-testing, even those intended for release/distribution.

@etcwilde
Copy link
Contributor

WMO doesn't always work with the old driver, as it sometimes tries to pass objects and static archives to the frontend as source files, resulting in broken builds as well. I did try to teach CMake to make release builds use WMO, but that had to be rolled back to avoid these kinds of build failures:

    CMakeFiles\cmTC_28bcb.dir\main.swift.obj:3:269: warning: nul character embedded in middle of file
     1 | d�       :       .text           �   4  �
                                                                   P`.data               u              @ 0∩┐╜.bss                                ∩┐╜ 0∩┐╜.xdata            u              @ [email protected]           4   }  ∩┐╜          P`.text           "   ∩┐╜  ∩┐╜          P`.text           "
                                                                    -          P`.text              I               P`.rdata
     2 |    J              @ @/419              T  \         @ [email protected]             f              @ @.sw5hash           h              @ @.drectve        ∩┐╜   x
     3 |  .pdata
                             q  }         @ [email protected]            ∩┐╜              @[email protected]                          @[email protected]            A              @[email protected]
                                                                                                                                                                              ∩┐╜  ∩┐╜         @[email protected]
                                                                                                                                                                                                                     ∩┐╜  ∩┐╜         @[email protected]
                             �  �         @0@H��X�   �    H�D$(H�T$0H�
       |                                                                                                                                                                                                                                                                   `- warning: nul character embedded in middle of file
     4 |     �   A�   �    H�L$(I��H��H�T$0L�
     5 |     L∩┐╜JL∩┐╜H∩┐╜H∩┐╜    H∩┐╜∩┐∩┐╜    H∩┐╜D$P∩┐╜    H∩┐╜D$8H∩┐╜T$H∩┐╜    L∩┐╜D$HH∩┐╜L$PI∩┐╜∩┐╜H∩┐╜∩┐╜H∩┐╜T$8H∩┐╜D$@H∩┐╜D$ ∩┐╜    H∩┐╜L$@∩┐╜    H∩┐╜L$H∩┐╜    H∩┐╜L$P∩┐╜    1∩┐╜H∩┐╜∩┐╜X∩┐╜
                                                                                                                                                                                                      /       ␦    -   0    D   1    V   2    _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. serialization Area → compiler: Serialization & deserialization textual interfaces Windows Platform: Windows
Projects
None yet
Development

No branches or pull requests

6 participants