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-3987] Compiler crashes in generic function with inout tuple parameter holding function type #46572

Closed
palimondo mannequin opened this issue Feb 17, 2017 · 4 comments
Assignees
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

@palimondo
Copy link
Mannequin

palimondo mannequin commented Feb 17, 2017

Previous ID SR-3987
Radar None
Original Reporter @palimondo
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Xcode Version 8.2.1 (8C1002)
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: 21011a122103c12274c52bc07e87d5ac

duplicates:

  • SR-3450 Closure with an 'inout' closure argument crashes the compiler when supplied to generic function

Issue Description:

Compiling this:

extension Sequence {
    public typealias Predicate = (Iterator.Element) -> Bool
    public typealias PredicatedIterator = (predicate: Predicate, iterator: Self.Iterator)
    
    internal func nextMatch(state: inout PredicatedIterator) -> Iterator.Element? {
        guard let e = state.iterator.next() else { return nil }
        return state.predicate(e) ? e : nil
    }
    
    public func _prefix (while predicate: @escaping Predicate) ->
        UnfoldSequence<Self.Iterator.Element, PredicatedIterator> {
            return sequence(state: (predicate, makeIterator()), next: nextMatch)
    }

}

crashes the compiler with following error:

inout writeback in abstraction difference thunk not yet implemented
input value   %1 = argument of bb0 : $*(predicate: @callee_owned (@in Self.Iterator.Element) -> @out Bool, iterator: Self.Iterator)
output type $*(predicate: @callee_owned (@in Self.Iterator.Element) -> Bool, iterator: Self.Iterator)

It is however possible to work around this issue and achieve similar result, if instead of using the tuple to store the state, one creates generic struct to hold the same values. See commented code at the end of the attached test case for the implementation of the workaround.

This might be duplicate of SR-3450, though I think that given the workaround with struct works and covers a different use case than using a closure as state directly: I'm trying to store the closure inside a state tuple.

@belkadan
Copy link
Contributor

Looks like it still crashes on near-master too. @swiftix, whose area is this?

@swiftix
Copy link
Mannequin

swiftix mannequin commented Feb 20, 2017

It happens in SILGen. @jckarter or @gottesmm would be the right people to ask, I'd say.

@slavapestov
Copy link
Member

This is a known limitation in SILGen. We need to implement re-abstraction for inout values.

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented Feb 21, 2017

In case the implementation of re-abstraction does not make it into the next release, can this case not crash the compiler and report error instead?

@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

3 participants