Skip to content

Faulty exclusivity check in Data.mutableSpan implementation #81218

Open
@glessard

Description

@glessard

Description

While implementing the Data.mutableSpan property (swiftlang/swift-foundation#1276), I tried to compose mutableSpan around the existing implementation of mutableBytes, and return a typed view. However, using the mutableBytes accessor within the mutableSpan accessor causes an exclusivity check to fail.

Reproduction

In swiftlang/swift-foundation#1276 , when changing the conditional compilation condition of the mutableSpan accessor (data.swift, line 2272) to true, an exclusivity check fails with the message:
"Overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable."

The alternative implementation manually inlines the mutableBytes implementation, and that compiles successfully.

Expected behavior

Composing one accessor in terms of the other should work.

Environment

Toolchain built from top-of-tree, April 29th 2025.

Additional information

This issue was cloned by rdar://150396586

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.exclusivity

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions