Skip to content

Add a single-threaded stdlib mode, use it for the 'minimal' stdlib #33437

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 5 commits into from
Aug 25, 2020

Conversation

kubamracek
Copy link
Contributor

No description provided.

@kubamracek kubamracek force-pushed the stdlib-singlethreaded branch from d46ad0a to 6e35f92 Compare August 18, 2020 02:24
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@gottesmm
Copy link
Contributor

@kubamracek Are you sure that all rr operations will be non-atomic? I wouldn't rely on the current support in the compiler for emitting non-atomic rr. The compiler only attempts to keep things non-atomic as a "best effort". Better in your case to just add a flag to the runtime to ensure that ARC operations always go to the non-atomic variant.

@gottesmm
Copy link
Contributor

@kubamracek or you could leave everything alone and just have them forward to the non-atomic implementation if the flag is set that way we aren't changing the external ABI interface of the library.

@kubamracek
Copy link
Contributor Author

kubamracek commented Aug 18, 2020

Are you sure that all rr operations will be non-atomic?

No, and actually I'm pretty sure some will stay as atomic. However, my motivation here is just an "optimization", and if I discover places that are still using atomics when they don't need to, I plan to fix them up with separate PRs.

add a flag to the runtime to ensure that ARC operations always go to the non-atomic variant
just have them forward to the non-atomic implementation if the flag is set

That sounds reasonable. Let me try to prepare this in a separate PR.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6e35f92a3c4fb29f34c64d2c17ee90aca6318155

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6e35f92a3c4fb29f34c64d2c17ee90aca6318155

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

The change looks reasonable to me. I really like the idea that @gottesmm has to use shims, and if the shims are static I think that could be an interesting approach as well. Since this form hasn't shipped yet it does make sense to simply do the more straightforward changes that @kubamracek has proposed.

LGTM, but please make sure that @gottesmm is okay with it as well before merging.

@kubamracek kubamracek force-pushed the stdlib-singlethreaded branch from 5f5b61f to 121c763 Compare August 24, 2020 15:24
@kubamracek
Copy link
Contributor Author

@gottesmm Are you okay with the state of this PR?

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5f5b61ff0f778cb9b9bff597170c15d210100a58

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 5f5b61ff0f778cb9b9bff597170c15d210100a58

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@gottesmm
Copy link
Contributor

I talked with Kuba offline. I asked him in follow on 1-2 follow on PRs to:

  1. Eliminate NONATOMIC_RC. That was just an experimental flag from some time ago that isn't needed today.
  2. Change the 10 atomic operations in HeapObject.cpp to be non-atomic if the Single threaded runtime mode is set. The change is really small. Example:
HeapObject *swift::swift_retain(HeapObject *object) {
  CALL_IMPL(swift_retain, (object));
}

becomes

HeapObject *swift::swift_retain(HeapObject *object) {
#if SINGLE_THREAD_FLAG
  CALL_IMPL(swift_nonatomic_retain, (object));
#else
  CALL_IMPL(swift_retain, (object));
#endif
}

Thanks for your work here Kuba!

@benrimmington
Copy link
Contributor

@swift-ci Please test Windows platform

@kubamracek kubamracek merged commit 9ead8d5 into swiftlang:master Aug 25, 2020
@kubamracek kubamracek deleted the stdlib-singlethreaded branch August 25, 2020 13:03
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