Skip to content

stdlib: fix availability for internal COW checks. #37945

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 3 commits into from
Jun 22, 2021

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Jun 16, 2021

Those checks should only be done if linked with a built library, but not when linked with the OS libraries.

Also: disable COW checking by default, and enable it for specific tests
COW checking needs that all libraries are consistently compiled with asserts enabled. This is not the case for the Foundation overlay anymore.
Therefore it does not work with some tests which interop with Foundation.
The solution here is to disable COW checking by default, but enable it for Array tests which do not interop with Foundation.

rdar://79412058

@eeckstein eeckstein requested a review from shahmishal June 16, 2021 07:03
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein force-pushed the fix-cow-check-availability branch from 27d1dce to e08b9b9 Compare June 16, 2021 07:20
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@benrimmington
Copy link
Contributor

benrimmington commented Jun 16, 2021

Could you add a -Xfrontend -define-availability macro to a CMake file?

EDIT: And somehow protect the 9999 versions from accidental Find & Replace?

if(enable_assertions)
  # "9999" means: enable if linked with a built library,
  # but not when linked with the OS libraries.
  # Note: this must not be changed to a "real" OS version.
  set(v9999 9999)
  list(APPEND swift_stdlib_compile_flags "-Xfrontend" "-define-availability")
  list(APPEND swift_stdlib_compile_flags "-Xfrontend" "\"SwiftStdlib_InternalCOWChecks:macOS ${v9999}, iOS ${v9999}, watchOS ${v9999}, tvOS ${v9999}\"")
endif()
@available(SwiftStdlib_InternalCOWChecks, *)

if #available(SwiftStdlib_InternalCOWChecks, *) {

@eeckstein eeckstein force-pushed the fix-cow-check-availability branch from e08b9b9 to f8849a0 Compare June 16, 2021 17:36
@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - f8849a0e1cc068016ced409d4be144dab1cba6ac

@varungandhi-apple
Copy link
Contributor

Tracking radar: rdar://79412058 (Fix availability for internal COW checks)

@eeckstein
Copy link
Contributor Author

@benrimmington That's an excellent idea! Unfortunately there are some problems when this goes through a swift interface file: https://ci.swift.org/job/swift-PR-macos/27765/console

@benrimmington
Copy link
Contributor

benrimmington commented Jun 16, 2021

Why are the failures only for watchOS simulator?

Swift.swiftmodule/i386-apple-watchos-simulator.swiftinterface:6029:39: error: expected version number
      if #available(_InternalCOWChecks, *) {
                                      ^

You could try adding a version number to the macro name:

-list(APPEND swift_stdlib_compile_flags "-Xfrontend" "_InternalCOWChecks:macOS ${v9999}, iOS ${v9999}, watchOS ${v9999}, tvOS ${v9999}")
+list(APPEND swift_stdlib_compile_flags "-Xfrontend" "_InternalCOWChecks 1:macOS ${v9999}, iOS ${v9999}, watchOS ${v9999}, tvOS ${v9999}")

-@available(_InternalCOWChecks, *)
+@available(_InternalCOWChecks 1, *)

-if #available(_InternalCOWChecks, *) {
+if #available(_InternalCOWChecks 1, *) {

EDIT: Changed the macro name to use version 1.

@eeckstein
Copy link
Contributor Author

Adding a version number does not help. The problem is that as soon as it goes through a swiftinterface file, the availability macro is missing. It would be required to add the macro to all swift compiler invocations.

Why are the failures only for watchOS simulator?

I think it depends on the installed Xcode what module files need to be rebuilt for which platform.

@benrimmington
Copy link
Contributor

Adding a version number does not help.

The new Concurrency module uses a similar SwiftStdlib 5.5 macro, without this issue AFAIK.

The problem is that as soon as it goes through a swiftinterface file, the availability macro is missing.

The macro shouldn't be required by swiftinterface files, according to the #33439 description:

The use of availability macros in the @available specification is expanded at parsing and should not be visible in any compiler outputs. This includes the swiftinterfaces which will show the full classic availability specification.

* move all ObjC array tests into a separate file ArraysObjc.swift.gyb
* merge the remaining Arrays.swift.gyb and ArrayNew.swift.gyb files
* move the utilities from ArrayTypesAndHelpers.swift into its only use into ArraysObjc.swift.gyb
Those checks should only be done if linked with a built library, but not when linked with the OS libraries.
@eeckstein eeckstein force-pushed the fix-cow-check-availability branch from f8849a0 to 9a68c5f Compare June 17, 2021 09:31
@eeckstein
Copy link
Contributor Author

eeckstein commented Jun 17, 2021

ok, seems to be a problem with generating swiftinterface files. I'll let this up to someone else to investigate and fix.

Let's land this change to unblock CI. We can do the fine tuning later.

@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9a68c5fb4bb526f9aa08fdebbcb4481fd8dd3fe5

@eeckstein
Copy link
Contributor Author

@swift-ci test macOS

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test macOS

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9a68c5fb4bb526f9aa08fdebbcb4481fd8dd3fe5

@eeckstein
Copy link
Contributor Author

@swift-ci test macOS

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9a68c5fb4bb526f9aa08fdebbcb4481fd8dd3fe5

COW checking needs that all libraries are consistently compiled with asserts enabled. This is not the case for the Foundation overlay anymore.
Therefore it does not work with some tests which interop with Foundation.

The solution here is to disable COW checking by default, but enable it for Array tests which do not interop with Foundation.
@eeckstein eeckstein force-pushed the fix-cow-check-availability branch from 9a68c5f to 0831240 Compare June 17, 2021 14:14
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@kavon
Copy link
Member

kavon commented Jun 22, 2021

@swift-ci please smoke test macOS platform

@eeckstein eeckstein merged commit 53fc177 into swiftlang:main Jun 22, 2021
@eeckstein eeckstein deleted the fix-cow-check-availability branch June 22, 2021 05:20
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