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-13038] unknownObjectRetain crash with -Osize Swift optimization #55484

Open
swift-ci opened this issue Jun 17, 2020 · 13 comments
Open

[SR-13038] unknownObjectRetain crash with -Osize Swift optimization #55484

swift-ci opened this issue Jun 17, 2020 · 13 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13038
Radar rdar://problem/66278990
Original Reporter bullock (JIRA User)
Type Bug

Attachment: Download

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

md5: da2e65be581761f2269c21c9636bc329

Issue Description:

When a formatted or interpolated String is returned from a computed Swift property and assigned to Obj-C instance (e.g. UIKit class) and the Swift optimization level is -Osize, app will crash at runtime with unknownObjectRetain

@swift-ci
Copy link
Collaborator Author

Comment by Sung Min Kim (JIRA)

Afternoon! Any updates on this issue?

bullock (JIRA User) Were you able to find a simple workaround for this? We're solving the issue assigning the text to a variable and then setting the .text from that variable, but this implies changes in the whole project and it's causing crashes on our release branch.

@swift-ci
Copy link
Collaborator Author

Comment by Lance (JIRA)

sungkim23 (JIRA User) We changed the computed var to a function and therefore have to change the call at the call site.

@swift-ci
Copy link
Collaborator Author

Comment by Artsiom Karseka (JIRA)

Guys, do you have any update here? Looks like we have a similar top-rate crash when setting text in UILabel from computed var with interpolated string.

Do you have a robust workaround?

Thank you.

@swift-ci
Copy link
Collaborator Author

Comment by Sung Min Kim (JIRA)

AKarseka (JIRA User) I find it weird no-one from Apple or Swift contributors have noticed this, but we gotta try to get someone to notice this bug, so far, the only way is what bullock (JIRA User) mentioned, either get the value from a func or you can set the computed var to a local variable and then use that variable.

Neither solutions are robust per se, but it's the only way we're able to still ship our app... if we didn't find the workaround we'd have millions of users crashing every day.

@beccadax
Copy link
Contributor

@swift-ci create

@mikeash
Copy link
Contributor

mikeash commented Jul 29, 2020

Thanks for the report and the nice reproducer. I was able to replicate the crash here with Xcode 11.4, and verify that the code generated at the crash site is over-releasing the string. I was not able to replicate it with an Xcode 12 beta, and the code generated with that version looks good. Have you tried this with an Xcode 12 beta? If not, could you try it there and see if it also works for you?

@swift-ci
Copy link
Collaborator Author

Comment by Cezary Wojcik (JIRA)

Glad you're able to reproduce @mikeash! Unfortunately, migrating my actual codebase to Xcode 12 is pretty non-trivial, but w/ this example alone, I'm seeing the same behavior of a crash in Xcode 11.5 and no crash w/ Xcode 12.

Are there possible (comprehensive) workarounds in Xcode 11.4+? Otherwise, means my codebase is probably stuck on using Xcode 11.2.1 until the AppStore is accepting builds from Xcode 12.

@mikeash
Copy link
Contributor

mikeash commented Jul 29, 2020

Since this seems to be a codegen problem in the compiler, it's a bit outside my wheelhouse, but I will ask the people who know about that sort of thing and they or I will report back.

One thing I did notice is that the problem seems to be connected to directly accessing the singleton instance with WordServer.instance. You might try changing that to a func that accesses a private stored property, or something along those lines, to see if that works around it.

@swift-ci
Copy link
Collaborator Author

Comment by Cezary Wojcik (JIRA)

Awesome, thanks for looking into it! Yeah, that kind of workaround works for known instances, but the problem with a really large codebase is that it's hard to identify / fix all possible instances + prevent new ones from getting in. So without comprehensively being able to fix this with some kind of compile flag or similar, can't really risk it.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 7, 2020

Comment by Cezary Wojcik (JIRA)

Hey @mikeash, were you able to get ahold of anyone who could help further? Thanks!

@mikeash
Copy link
Contributor

mikeash commented Aug 7, 2020

We don't seem to have any good ideas for a workaround without applying fixes at specific locations in code. Is this problem narrow enough that you could search for static var and change them all to funcs, or computed properties? Barring that, I think we're stuck waiting for Xcode 12.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 7, 2020

Comment by Cezary Wojcik (JIRA)

I think it's feasible to try to find the existing ones, but a little harder to prevent new ones from sneaking in. Sounds like waiting until Xcode 12 it is - thanks for checking!

@mikeash
Copy link
Contributor

mikeash commented Aug 10, 2020

Glad to be of service, sorry it didn't bear sweeter fruit.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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

3 participants