Skip to content

[build] Remove intermediate pipeline so that we can guarantee that we always have a fresh swift-dispatch when running swift tests. #65829

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
Sep 16, 2023

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented May 10, 2023

In the fullness of time, we want to split the full build-script-impl pipeline so that we can begin moving library like products (libdispatch, foundation) from build-script-impl into build-script. We are not there yet since some of swift's concurrency tests have a dependency on swift dispatch being built. This breaks the build and we need to extract those tests into a separate product. But for now, this makes sense to repair the build.

rdar://89046735
Fixes #53973

@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci test linux platform

@finagolfin
Copy link
Member

@al45tair, would you run the linux CI on this again? The month-old results have been removed.

@al45tair
Copy link
Contributor

@swift-ci test linux platform

@al45tair
Copy link
Contributor

@swift-ci test Windows platform

@finagolfin
Copy link
Member

Linux CI shows libdispatch-dependent tests running again, including several Concurrency tests that have long not been run because of this libdispatch dependency on the linux CI, with several now failing because of some configuration issue:

Failed Tests (33):
  Swift(linux-x86_64) :: Concurrency/Runtime/async.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_task_cancellation_taskGroup.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_task_cancellation_while_running.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_task_priority_current.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_task_sleep.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_task_sleep_cancel.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_cancelAll_only_specific_group.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_cancel_parent_affects_group.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_cancel_then_completions.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_cancel_then_spawn.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_is_empty.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_next_not_invoked_cancelAll.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_next_not_invoked_without_cancelAll.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/async_taskgroup_next_on_completed.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/basic_future.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/custom_executors_complex_equality.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/custom_executors_complex_equality_crash.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/custom_executors_complex_equality_subclass.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/custom_executors_protocol.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/data_race_detection.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/future_fibonacci.swift
  Swift(linux-x86_64) :: Concurrency/Runtime/mainactor.swift
  Swift(linux-x86_64) :: Concurrency/async_task_base_priority.swift
  Swift(linux-x86_64) :: Concurrency/dispatch_inference.swift
  Swift(linux-x86_64) :: Runtime/associated_witness_concurrency.swift
  Swift(linux-x86_64) :: Sanitizers/tsan/basic_future.swift
  Swift(linux-x86_64) :: Sanitizers/tsan/libdispatch.swift
  Swift(linux-x86_64) :: Sanitizers/tsan/mainactor.swift
  Swift(linux-x86_64) :: Sanitizers/tsan/norace-block-release.swift
  Swift(linux-x86_64) :: Sanitizers/tsan/norace-deinit-run-time.swift
  Swift(linux-x86_64) :: stdlib/DispatchData.swift
  Swift(linux-x86_64) :: stdlib/DispatchRenames.swift
  Swift-validation(linux-x86_64) :: Runtime/weak-reference-racetests-dispatch.swift

They all appear to fail because they cannot find the Swift module for Dispatch for some reason:

Command Output (stderr):
--
/home/build-user/swift/test/Concurrency/Runtime/async.swift:11:8: error: cannot load underlying module for 'Dispatch'
import Dispatch
       ^

I don't see this error when running the compiler validation suite on Android without this pull, ie most of these tests pass for me, so this appears to be something specific to the linux CI.

@finagolfin
Copy link
Member

I don't see this error when running the compiler validation suite on Android without this pull, ie most of these tests pass for me, so this appears to be something specific to the linux CI.

Spoke too soon, as I see this on Android too now, will investigate.

@finagolfin
Copy link
Member

finagolfin commented Aug 22, 2023

OK, found the problem: libdispatch requires that non-Darwin platforms have its generic modulemap installed when built for Swift, but wherever that was done was probably removed at some point this year. I have been running these trunk compiler validation tests once a month natively on Android, and I noticed a couple weeks ago that some extra modulemap files were in swift-corelibs-libdispatch/dispatch/ and deleted them, figuring they weren't needed.

After that, I hit these test failures natively on Android too with the Aug. 10 trunk snapshot, since the validation suite looks in the libdispatch source directory directly for that module. I confirmed that was the problem by manually copying swift-corelibs-libdispatch/dispatch/generic/module.modulemap up to swift-corelibs-libdispatch/dispatch/ and these failing libdispatch-dependent tests started passing again.

Looking into the source now, @compnerd, looks like these tests all broke with your swiftlang/swift-corelibs-libdispatch#785, but nobody knew because these tests were not being run on the linux CI. Any idea how we can fix this now?

@finagolfin
Copy link
Member

I took a look at Saleem's libdispatch pull and tried something similar natively on Android, gottesmm#2, which fixed the libdispatch test failures for me and should do the same on this linux CI.

@gottesmm, if you would just get my pull into this branch, we can make sure it works on the linux CI.

@finagolfin
Copy link
Member

@yln, not getting a response on this, maybe you can get this looked at.

@finagolfin
Copy link
Member

@al45tair, could you ping @gottesmm about this? My tries over the last week don't seem to be getting anywhere.

@al45tair
Copy link
Contributor

al45tair commented Sep 5, 2023

@al45tair, could you ping @gottesmm about this? My tries over the last week don't seem to be getting anywhere.

If you haven't already, I'd try pinging him in Slack. I'm definitely not the best person to ask if he isn't responding (because I'm in a different country, whereas others work in the same building as him and could drop by his office). You could try @tbkka if you can't get a reply from @gottesmm?

… always have a fresh swift-dispatch when running swift tests.

In the fullness of time, we want to split the full build-script-impl pipeline so
that we can begin moving library like products (libdispatch, foundation) from
build-script-impl into build-script. We are not there yet since some of swift's
concurrency tests have a dependency on swift dispatch being built. This breaks
the build and we need to extract those tests into a separate product. But for
now, this makes sense to repair the build.

rdar://89046735
@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 5, 2023

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 5, 2023

@finagolfin sorry, I didn't see your ping. I pulled in your commit into this PR and restarted the testing.

@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 5, 2023

FAIL: Swift(linux-x86_64) :: Concurrency/Runtime/async_task_priority_current.swift (555 of 16924)
******************** TEST 'Swift(linux-x86_64) :: Concurrency/Runtime/async_task_priority_current.swift' FAILED ********************
Script:
--
: 'RUN: at line 1';   rm -rf "/home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Concurrency/Runtime/Output/async_task_priority_current.swift.tmp" && mkdir -p "/home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Concurrency/Runtime/Output/async_task_priority_current.swift.tmp" && /home/build-user/build/buildbot_linux/swift-linux-x86_64/bin/swiftc -target x86_64-unknown-linux-gnu -toolchain-stdlib-rpath  -module-cache-path /home/build-user/build/buildbot_linux/swift-linux-x86_64/swift-test-results/x86_64-unknown-linux-gnu/clang-module-cache -swift-version 4  -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.10:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999'  -module-cache-path /home/build-user/build/buildbot_linux/swift-linux-x86_64/swift-test-results/x86_64-unknown-linux-gnu/clang-module-cache /home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift  -Xfrontend -disable-availability-checking -I /home/build-user/swift-corelibs-libdispatch -I /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/src/swift/swift -L /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64 -vfsoverlay /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/dispatch-vfs-overlay.yaml -parse-as-library -o /home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Concurrency/Runtime/Output/async_task_priority_current.swift.tmp/a.out -module-name main  && echo /home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Concurrency/Runtime/Output/async_task_priority_current.swift.tmp/a.out && /usr/bin/env LD_LIBRARY_PATH='/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:/home/build-user/build/buildbot_linux/libdispatch-linux-x86_64'  /home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Concurrency/Runtime/Output/async_task_priority_current.swift.tmp/a.out | /usr/bin/python3.8 /home/build-user/swift/utils/PathSanitizingFileCheck --allow-unused-prefixes --sanitize BUILD_DIR=/home/build-user/build/buildbot_linux/swift-linux-x86_64 --sanitize SOURCE_DIR=/home/build-user/swift --use-filecheck /home/build-user/build/buildbot_linux/llvm-linux-x86_64/bin/FileCheck  --dump-input=always /home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift
--
Exit Code: 1

Command Output (stdout):
--
/home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Concurrency/Runtime/Output/async_task_priority_current.swift.tmp/a.out

--
Command Output (stderr):
--
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:14:25: warning: conformance of 'TaskPriority' to protocol 'CustomStringConvertible' was already stated in the type's module '_Concurrency'
extension TaskPriority: CustomStringConvertible {
                        ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:15:14: note: property 'description' will not be used to satisfy the conformance to 'CustomStringConvertible'
  public var description: String {
             ^
_Concurrency.TaskPriority:2:11: note: 'TaskPriority' declares conformance to protocol 'CustomStringConvertible' here
extension TaskPriority : CustomStringConvertible {
          ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:73:9: warning: expression of type 'Task<(), Never>' is unused
  await x
        ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:74:9: warning: expression of type 'Task<(), Never>' is unused
  await z
        ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:59:9: warning: no 'async' operations occur within 'await' expression
    _ = await z // waiting on `z`, but it won't complete since we're also background
        ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:65:5: warning: no 'async' operations occur within 'await' expression
    await x // escalates x, which waits on z, so z also escalates
    ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:73:3: warning: no 'async' operations occur within 'await' expression
  await x
  ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:74:3: warning: no 'async' operations occur within 'await' expression
  await z
  ^
/home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift:23:60: error: CHECK: expected string not found in input
 print("main priority: \(Task.currentPriority)") // CHECK: main priority: TaskPriority(rawValue: [[#MAIN_PRIORITY:]])
                                                           ^
<stdin>:1:1: note: scanning from here
main priority: TaskPriority.medium
^

Input file: <stdin>
Check file: /home/build-user/swift/test/Concurrency/Runtime/async_task_priority_current.swift

-dump-input=help explains the following input dump.

Input was:
<<<<<<
          1: main priority: TaskPriority.medium 
check:23     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
          2: a1: TaskPriority.medium 
check:23     ~~~~~~~~~~~~~~~~~~~~~~~~
          3: a2: TaskPriority.high 
check:23     ~~~~~~~~~~~~~~~~~~~~~~
          4: a3: TaskPriority.medium 
check:23     ~~~~~~~~~~~~~~~~~~~~~~~~
          5: default done 
check:23     ~~~~~~~~~~~~~
>>>>>>

--

********************

@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 5, 2023

@swift-ci test linux platform

@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 5, 2023

@finagolfin Looks like there is still 1 Linux failure. I am unsure if it is related.

@finagolfin
Copy link
Member

OK, that test fails for me on Android too, looks like it is just written wrong, as it checks for different output than it is producing. I'll look into a fix after an hour or two, as I've got some other work to do now, feel free to try something else in the meantime.

@finagolfin
Copy link
Member

Got a moment to look into it: the test expects the description() method above to be invoked, but it apparently isn't. I see that it's built with -swift-version 4 from the paste above, not sure if that is affecting it.

@etcwilde, you last modified that line of this single failing test, any idea what's going on with this string output issue? If we can get it fixed now, we can get this test running on the CI again.

@finagolfin
Copy link
Member

@gottesmm, disabled that last test on linux in my pull, one last CI run and we can get this in.

Would be good to get this in before the branch, so all these tests will be run for 5.10 too.

@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 7, 2023

@finagolfin I pinged @etcwilde

@etcwilde
Copy link
Contributor

etcwilde commented Sep 7, 2023

It looks like the formatting of the task priority CustomStringConvertible changed in this dispatch.
This test is just verifying the behavior of the priorities, so I don't care too much, so long as the priorities are set right.

It seems like the output should be TaskPriority(rawValue: number) as per

extension TaskPriority: CustomStringConvertible {
  public var description: String {
    "TaskPriority(rawValue: \(rawValue))"
  }
}

But according to the output, printing doing something else.

main priority: TaskPriority.medium
a1: TaskPriority.medium
a2: TaskPriority.high
a3: TaskPriority.medium

It looks like the priorities are matching correctly as expected. I think the fix is to just define a function or just extract the raw task priority value and use that instead of relying on the CustomStringConvertible conformance.

e.g. remove the CustomStringConvertible conformance and replace the usages of Task.currentPriority with Task.currentPriority.rawValue;

// ...
static func main async {
  print("main priority: \(Task.currentPriority.rawValue)") // CHECK: main priority: [[#MAIN_PRIORITY]]
  await test_detach()
  // ...
}

  let a1 = Task.currentPriority
  print("a1: \(a1.rawValue)") // CHECK: a1: [[#MAIN_PRIORITY]]
// ...

We're just checking that we return back to a lower priority correctly.

@finagolfin
Copy link
Member

@etcwilde, will do, this test works on macOS and the simulators now so will need to rerun on the CI to make sure that change won't break.

Is this a platform-breaking bug that needs to be looked into, since invoking the description() method for formatting works on Darwin but not on linux?

@etcwilde
Copy link
Contributor

etcwilde commented Sep 8, 2023

Hmm, give me a sec. #63543 added a CustomStringConvertible conformance to the TaskPriority type here https://github.com/apple/swift/blob/b7c2cb8a9e626f3c573bc4f582858a4533cdd941/stdlib/public/Concurrency/Task.swift#L323-L340.

This should be conflicting with the conformance in the test, so I would expect all of the platforms to have issues here (maybe an error for a redeclaration or ambiguous overload or something), but certainly not choosing a different definition. It might be worth getting a type-checker person in here. There should definitely be consistent behavior across platforms though, assuming they're both building for Swift "5.9" or newer.

@etcwilde
Copy link
Contributor

etcwilde commented Sep 8, 2023

@swift-ci please test

@etcwilde
Copy link
Contributor

etcwilde commented Sep 8, 2023

(Trying to pull logs off of all platforms so I can see if there's anything obviously different between the two)

@etcwilde
Copy link
Contributor

etcwilde commented Sep 8, 2023

From a quick conversation, having multiple conformances to the same protocol might just be UB. Unfortunate that it's not a reliable error message, but I haven't thought enough about what one would need to do to reliably detect it.

If that's the case, we delete the protocol conformance above and we can either go with the official 5.9 description definition, or we can pull the rawValue and match against that. I think the regex for the raw value will maybe be a bit easier, but the string description might be more reliable in case someone decides they want different raw values for the priorities.

@etcwilde
Copy link
Contributor

etcwilde commented Sep 8, 2023

Okay, it is most certainly UB. We should remove the duplicate conformance from the test and fix the thing the test is checking for. I'll let you choose what you want to match against.

@finagolfin
Copy link
Member

finagolfin commented Sep 8, 2023

@etcwilde, thanks for the explanation, I've updated my commit to match those new string descriptions.

@gottesmm, if you would merge my pull into this one, it should pass the linux CI now- I ran it on Android to make sure it works- though the macOS CI should also be rerun to make sure the test changes don't break there.

@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 8, 2023

@finagolfin sounds good

…g/swift-corelibs-libdispatch#785

This allows the tests that use libdispatch to find its modulemap, plus add the
libdispatch compilation flags to one test that was missing them and fix one
async test on linux.
@gottesmm
Copy link
Contributor Author

gottesmm commented Sep 8, 2023

@swift-ci test

@finagolfin
Copy link
Member

Passed all CI now but looking at the log, I notice that all the Swift corelibs up to llbuild are now built before the compiler validation suite is run. This could cause problems when someone is trying out a compiler pull and something inscrutable breaks when building swift-corelibs-foundation, rather than the much cleaner tests in the compiler test suite.

@gottesmm, what do you think about replacing your commit with this patch instead, simply moving libdispatch into the earlier build-script pipeline?

diff --git a/utils/swift_build_support/swift_build_support/build_script_invocation.py b/utils/swift_build_support/swift_build_support/build_script_invocation.py
index 1e54515905c..483e1ffb509 100644
--- a/utils/swift_build_support/swift_build_support/build_script_invocation.py
+++ b/utils/swift_build_support/swift_build_support/build_script_invocation.py
@@ -613,13 +613,13 @@ class BuildScriptInvocation(object):
                                  is_enabled=self.args.build_swift)
         builder.add_impl_product(products.LLDB,
                                  is_enabled=self.args.build_lldb)
+        builder.add_impl_product(products.LibDispatch,
+                                 is_enabled=self.args.build_libdispatch)

         # Begin a new build-script-impl pipeline that builds libraries that we
         # build as part of build-script-impl but that we should eventually move
         # onto build-script products.
         builder.begin_impl_pipeline(should_run_epilogue_operations=True)
-        builder.add_impl_product(products.LibDispatch,
-                                 is_enabled=self.args.build_libdispatch)
         builder.add_impl_product(products.Foundation,
                                  is_enabled=self.args.build_foundation)
         builder.add_impl_product(products.XCTest,

This will make sure libdispatch is built before the compiler validation suite is run, thus enabling all these libdispatch and concurrency tests again, but keeps all the other corelibs split off in a separate pipeline for later. Let me know what you think.

@finagolfin
Copy link
Member

Pinging @gottesmm again, let me know what you think of the libdispatch change I suggested above over the weekend.

@gottesmm
Copy link
Contributor Author

@finagolfin I would rather merge this since it works and then do that as a separate patch. What do you think?

@finagolfin
Copy link
Member

@gottesmm, fine by me, I will submit that once this is in.

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.

[SR-11568] libdispatch build reorganization inadvertently disabled tsan/libdispatch tests on linux CI
4 participants