Skip to content

[Executors] Do not consider Loc validity in determining to emit error/warning about enqueue(_:) #67957

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

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Aug 16, 2023

Description: The introduction of new protocol requirements in protocol Executor required careful and custom handling by the compiler in order to not break ABI/API. This logic made a wrong assumption that it can rely on valid/invalid source location information to determine if "this decl exists and is valid" -- while in reality, we cannot rely on loc at all for making this decision. This happened to work in tests and swiftpm projects because source location was always available.

Symbols may not have valid loc attached just because they're in a different module and we don't have swiftsourceinfo for them. E.g. with Xcode the Archive action does not copy the swiftsourceinfo and thus we end up ALWAYS emitting the error that an implementation is missing -- even if it is there, but we simply trigger the "illegal loc!" case incorrectly.

Solution: Stop relying on the incorrect assumption that a "valid loc" can be used to determine if we have the method or not. This worked by accident, since in swift the unit test suite we entered this missing loc code path.

Instead, we must manually inspect the witnesses and determine that at least one of them is NOT the default implementation provided in the stdlib (because we implement ALL of the requirements in order to introduce the new protocol requirement without breaking API/ABI). The same goes about warnings, since we do not want to emit warnings about the standard library when end-users do something slightly wrong in their adoption -- it is their conformance mistake we must warn about.

Risk: Low
Risk details: The primary error fix is about removing the use of loc information entirely from decision making about emitting errors, i.e. we're removing a buggy source of information from the decision making -- the primary logic all remains the same.

Due to that removal, we also add some warning suppression that previously occurred naturally (correctly "by accident"), by concretely handling the special casing of the concrete extension in _Concurrency module that performs actions we should not warn about in stdlib due to it implementing bin-compat concerns.

Reward: Medium,
Reward details: Projects built in a way where swiftsourceinfo is not available (e.g. in Xcode by running "Archive") are now able to adopt libraries that adopted custom executors -- e.g. like Swift NIO. The reward is medium because custom executor adoption in this pattern isn't quite wide-spread yet.

Review by: @DougGregor @owenv
Testing: Warnings and errors emitted by this are well tested; We also verified a known reproducer using Xcode and "Archive" action is resolved by a compiler with this fix.
Scope: This is a compiler only change.
Radar: rdar://113913291

…ror if all implementations are "default from stdlib" because end-user MUST implement at least one of them
…er them

The standard library's enqueue() does not play by the same rules -- we
provide "deprecated" implementations in  order to remain source/binary
compatible, and showing warnings about this when users make mistake will
only be misleading.
auto extensionModule = extension->getParentModule();
if (extensionModule != concurrencyModule) {
return false;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is important because otherwise user code would be getting non-actionable and very confusing warnings about the standard library.



extension Executor {
func enqueue(_ job: UnownedJob) { // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'NoneExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that we prevent warnings about the "default implementations in the stdlib" on purpose by looking for it, rather than relying on the LoC check, we add this test to make sure we've not accidentally prevented those warnings we DO want to emit -- whenever anything other than the Concurrency module does implement these.

@@ -1,12 +1,9 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-move-only -disable-availability-checking
Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ the flag is not doing anything anymore -> remove

// REQUIRES: concurrency

// rdar://106849189 move-only types should be supported in freestanding mode
// UNSUPPORTED: freestanding

// FIXME: rdar://107112715 test failing on iOS simulator, investigating
Copy link
Contributor Author

@ktoso ktoso Aug 16, 2023

Choose a reason for hiding this comment

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

✅ radar was resolved resolved a while ago

@ktoso ktoso force-pushed the wip-dont-use-loc-validness-in-diagnostics-determination-113913291 branch from 9b33435 to 5e43ba9 Compare August 16, 2023 13:27
@ktoso
Copy link
Contributor Author

ktoso commented Aug 16, 2023

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants