Skip to content

Conversation

@meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Nov 13, 2025

  • Annotate subscript and count of MutableSpan and OutputSpan with @_semantics. Span's subscript was already annotated with @_semantics and doesn't need a similar change.
  • Use _assumeNonNegative for OutputSpan's count

@meg-gupta
Copy link
Contributor Author

Based on #85476

@meg-gupta meg-gupta requested review from atrick and glessard November 13, 2025 09:46
@meg-gupta meg-gupta marked this pull request as ready for review November 13, 2025 09:46
@meg-gupta meg-gupta requested review from a team and eeckstein as code owners November 13, 2025 09:46
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta force-pushed the mutablespanbitwisecopyable branch from 0d0c1d5 to 1d6440e Compare November 13, 2025 17:03
@meg-gupta meg-gupta changed the title Rewrite MutableSpan subscript for BitwiseCopyable elements Update MutableSpan and OutputSpan Nov 13, 2025
@meg-gupta
Copy link
Contributor Author

@swift-ci

@atrick
Copy link
Contributor

atrick commented Nov 13, 2025

I'll just trust that the fixed_storage @_semantics are correct. They make sense to me but aren't documented.

If @glessard thinks it's worth adding new entry points in the stdlib to work around optimization barriers, then I won't object.

My primary concern is that we're avoiding fixing optimizer support for mark_dependence. The mark_dep should already be converted to [nonescaping]. Soon, it seems like we will also care about optimization in the presence of non-Copyable and borrowed values.

@meg-gupta
Copy link
Contributor Author

meg-gupta commented Nov 13, 2025

@atrick I can document the semantics as a follow on. They have been in use for Span and InlineArray.

My primary concern is that we're avoiding fixing optimizer support for mark_dependence. The mark_dep should already be converted to [nonescaping]

Agree mark_dependence [nonescaping] is not handled well. But it didn't seem relevant for the tests whose bounds check optimizations were blocked in SIL due to the lack of semantics.

@glessard I would like to merge the semantics and _assumeNonNegative changes at the very least. BitwiseCopyable specializations are useful too but it's fine to not merge.

@glessard
Copy link
Contributor

I agree with the semantics and _assumeNonNegative changes. The stdlib team's consensus is to prefer not to have the BitwiseCopyable specializations (and in fact we would like to remove them from Span.) How big is the gain from them? How distant is the prospect of them being no better than the optimizer?

@glessard
Copy link
Contributor

@swift-ci please test

@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableSpan where Element: BitwiseCopyable {
@_alwaysEmitIntoClient
public subscript(_ position: Index) -> Element {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect that these have to be @inline(always), if we're going to have them.

@meg-gupta meg-gupta force-pushed the mutablespanbitwisecopyable branch from 1d6440e to c93163c Compare November 13, 2025 21:54
@meg-gupta
Copy link
Contributor Author

I removed the BitwiseCopyable specializations from this PR.

@meg-gupta
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@glessard glessard left a comment

Choose a reason for hiding this comment

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

Thanks @meg-gupta

@meg-gupta meg-gupta enabled auto-merge November 14, 2025 00:22
@meg-gupta meg-gupta merged commit 4ebc087 into swiftlang:main Nov 14, 2025
5 checks passed
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.

4 participants