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-7430] Segmentation fault: 11 while compiling a function #49973

Closed
swift-ci opened this issue Apr 13, 2018 · 13 comments
Closed

[SR-7430] Segmentation fault: 11 while compiling a function #49973

swift-ci opened this issue Apr 13, 2018 · 13 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7430
Radar rdar://problem/39514010
Original Reporter antoinelamy (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode version 9.3 (9E145)

Swift 4.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee antoinelamy (JIRA)
Priority Medium

md5: 960a61165aea26c1feb87769bf17ba15

Issue Description:

The compiler gives me the following error while trying to compile a function:

1. While emitting SIL for 'bind(viewModel:)' at /.../Utilities/Bindings/SCRATCHObservableModel+Binding.swift:141:5 
2. While silgen emitFunction SIL function "@_T0So11UITextFieldC17E4bindySo08CORETextB9ViewModelC04viewH0_tF". 
 for 'bind(viewModel:)' at /.../Utilities/Bindings/SCRATCHObservableModel+Binding.swift:141:5 
3. While silgen closureexpr SIL function "@_T0So11UITextFieldC17E4bindySo08CORETextB9ViewModelC04viewH0_tFyABcfU_".
 for expression at [/.../Utilities/Bindings/SCRATCHObservableModel+Binding.swift:151:51 - line:162:9] RangeText="{ (textField) in 
  
            DispatchQueue.main.async { [weak textField] in 
                if textField?.isFirstResponder ?? false { 
                    textField?.resignFirstResponder() 
                } 
            } 
        }" 

The function written this way produce no error:

func bind(viewModel: CORETextFieldViewModel) { 
    addAction(events: [.editingDidEndOnExit]) { (textField) in 
        viewModel.returnKeyTapped() 
        DispatchQueue.main.async { [weak textField] in 
            if textField?.isFirstResponder ?? false { 
                textField?.resignFirstResponder() 
            } 
        } 
    } 
} 

Erasing a line produce the error:

func bind(viewModel: CORETextFieldViewModel) { 
    addAction(events: [.editingDidEndOnExit]) { (textField) in 
        DispatchQueue.main.async { [weak textField] in 
            if textField?.isFirstResponder ?? false { 
                textField?.resignFirstResponder() 
            } 
        } 
    } 
} 
@belkadan
Copy link
Contributor

I think we're probably going to need a self-contained test case to make any progress on this, but the "add a line" part makes sense, because it makes that closure body separate from the code that surrounds it. @xedin, @rudkx, is there enough information here to make progress?

@xedin
Copy link
Member

xedin commented Apr 13, 2018

Indeed it would be great to at least get some more information about what is `CORETextFieldViewModel`, `textField`, signature of `addAction` and base of `.editingDidEndOnExit`, otherwise unfortunately this is not very actionable...

@swift-ci
Copy link
Collaborator Author

Comment by Antoine Lamy (JIRA)

I'm pretty sure CORETextFieldViewModel is irrelevant in this issue, could be any NSObject subclass (bridged from objective-c). This function is located in an extension of UITextField so addAction just add itself as target for an action and return a reference to "self" when the action is triggered. If it could be of any help, I could try to extract this code in another project so it would be easier to troubleshoot.

@xedin
Copy link
Member

xedin commented Apr 13, 2018

antoinelamy (JIRA User) If you could extract it, that would be great!

@swift-ci
Copy link
Collaborator Author

Comment by Antoine Lamy (JIRA)

There you go! Just uncomment the mentioned line in Bindings.swift to reproduce the crash. SwiftCompilerCrash.zip

@swift-ci
Copy link
Collaborator Author

Comment by Antoine Lamy (JIRA)

Were you able to reproduce using the provided project?

@xedin
Copy link
Member

xedin commented Apr 18, 2018

Sorry antoinelamy (JIRA User), I got side-tracked by other issues, but this is in my queue.

@xedin
Copy link
Member

xedin commented Apr 18, 2018

@swift-ci create

@xedin
Copy link
Member

xedin commented Jun 7, 2018

antoinelamy (JIRA User) Could you please try with beta 1 build of Xcode 10? Looks like this problem got fixed along the way.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 7, 2018

Comment by Antoine Lamy (JIRA)

@xedin I tested it on Xcode 10 beta 1 on High Sierra and the issue is still present. Did you comment the specified line in the code sample to reproduce?

@xedin
Copy link
Member

xedin commented Jun 7, 2018

antoinelamy (JIRA User) Your previous comment said that I should uncomment that line 🙂 Sorry, I does indeed still crash if that line is commented...

@xedin
Copy link
Member

xedin commented Jun 8, 2018

Looks like this no longer crashes on master but produces "ambiguous expression" error instead, trying to figure out what I need to cherry-pick to 4.2 to fix it there too.

@xedin
Copy link
Member

xedin commented Dec 8, 2020

The issue with captures has been fixed in main - all of the captures are going to be type-checked together with enclosing expression(s) now. Attached project type-checks correctly with and without `viewModel.returnKeyTapped()`. antoinelamy (JIRA User) Please verify using the latest main branch snapshot from swift.org.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants