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-2503] subtract and subtracting in CharacterSet are not working #4329

Closed
swift-ci opened this issue Aug 28, 2016 · 5 comments
Closed

[SR-2503] subtract and subtracting in CharacterSet are not working #4329

swift-ci opened this issue Aug 28, 2016 · 5 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-2503
Radar None
Original Reporter behrang (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Mac OS X El Capitan 10.11.6

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, RunTimeCrash
Assignee @xwu
Priority Medium

md5: ca6970b5e4b7fc3176b709d6d6897fb9

Issue Description:

`CharacterSet` Instance methods `subtract` and `subtracting` are not working.

Here is an example in Swift REPL:

```swift
import Foundation
var charset1 = CharacterSet(charactersIn: "abc")
let charset2 = CharacterSet(charactersIn: "b")
charset1.subtract(charset2)
```
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)

@belkadan
Copy link

Which version of Xcode are you using?

@xwu
Copy link
Collaborator

xwu commented Aug 29, 2016

I can reproduce using the Xcode 8 beta 6 REPL and in a Playground using the 8/25 toolchain. The same issue also arises with `symmetricDifference`.

In the Playground, evaluation proceeds initially without any problem, but if the code is grayed out and re-evaluated, either automatically or manually by pressing the play button, then the problem described above manifests itself.

It seems to me there is a bad interaction among REPL/Playground code, the internal boxing facility recently introduced (`_MutableBoxing` and `_MutableHandle`), `isKnownUniquelyReferenced`, and the fact that `subtract[ing]` and `symmetricDifference` use a nested series of calls to `intersection` and `union` with rvalues that aren't assigned to temporary variables.

[Edit: To clarify, the current implementations of `intersection` and `union` in `CharacterSet` use `_MutableBoxing` facilities to avoid extraneous copies if the underlying Foundation reference type is known to be uniquely referenced, but it seems that something there goes awry when the result of `intersection` is used as an argument for a call to `union` or vice versa, as happens in `subtract[ing]` and `symmetricDifference`, when these methods are evaluated in the REPL.]

@dduan
Copy link
Collaborator

dduan commented Sep 11, 2016

This issue persists in Xcode GM.

@xwu
Copy link
Collaborator

xwu commented Oct 10, 2016

The underlying issue turns out to be pretty straightforward. `CharacterSet` has no implementation of `subtracting`. The default implementation of `subtracting` in `SetAlgebra` calls `symmetricDifference`, but `CharacterSet.symmetricDifference` calls `subtracting`!

PR #5201 has been created which implements `subtracting` and `subtract`.

@dduan
Copy link
Collaborator

dduan commented Oct 11, 2016

Sweet. Thank you @xwu!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants