Skip to content
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

[SR-13881] Inout reference to stored property tuple member takes exclusive access on the whole tuple #56279

Closed
lilyball mannequin opened this issue Nov 20, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Nov 20, 2020

Previous ID SR-13881
Radar rdar://problem/71677686
Original Reporter @lilyball
Type Bug
Status Closed
Resolution Invalid
Environment

Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin19.6.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: a764d3d654f40738ef4fa3561f9864c0

Issue Description:

If I have a tuple stored property in a class and I pass an inout reference to one of the tuple's members to another function, if that function accesses (directly or indirectly) a different member of the same tuple, this produces an exclusive memory access violation.

This is rather surprising to me, it's a stored property with no property observers so I wouldn't expect accessing its members individually to behave any differently than storing the elements in separate properties. It looks like it does this because it's going through a synthesized tup.modify accessor.

class Foo {
    var tup: (
        flag: Bool,
        ary: [Int]
    ) = (false, [])

    func foo() {
        bar(&tup.ary)
    }

    func bar(_ ary: inout [Int]) {
        tup.flag = true
        ary.append(1)
    }
}

Foo().foo()

This produces

Simultaneous accesses to 0x7ffd4ec05ed0, but modification requires exclusive access.
Previous access (a modification) started at main`Foo.tup.modify + 43 (0x100da5a4b).
Current access (a modification) started at:
0    libswiftCore.dylib                 0x00007fff71452750 swift_beginAccess + 568
1    main                               0x0000000100da5a20 Foo.tup.modify + 43
2    main                               0x0000000100da5ad0 Foo.bar(_:) + 47
3    main                               0x0000000100da5a70 Foo.foo() + 74
4    main                               0x0000000100da57d0 main + 54
5    libdyld.dylib                      0x00007fff71b36cc8 start + 1
Fatal access conflict detected.
@typesanitizer
Copy link

@swift-ci create

@eeckstein
Copy link
Member

This is expected behavior. An "access" is always considered to the whole class property, even if only a sub-element (or sub-struct-field) is actually used.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants