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-7371] Illegal instruction: 4 when calling a function #49919

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

[SR-7371] Illegal instruction: 4 when calling a function #49919

swift-ci opened this issue Apr 6, 2018 · 6 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 IRGen LLVM IR generation

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 6, 2018

Previous ID SR-7371
Radar rdar://problem/39239511
Original Reporter Qbyte (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.3; Swift 4.1

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

md5: 80d16503eb4fe0452484c8eaaad06f28

Issue Description:

The following code sample is the minimal example which I could extract from my production code.

If you do the actions described in only one of the comment lines the error ("Command failed due to signal: Illegal instruction: 4") goes away and the project compiles perfectly fine.

protocol TypedParserResultTransferType {
    // Remove type constraint
    associatedtype Result: ParserResult
}

struct AnyTypedParserResultTransferType<P: ParserResult>: TypedParserResultTransferType {
    typealias Result = P
    // Remove property
    let result: P
}

protocol ParserResult {}
protocol StaticParser: ParserResult {}

// Change comformance to ParserResult
protocol TypedStaticParser: StaticParser {
    // Remove type constraint
    associatedtype ResultTransferType: TypedParserResultTransferType
}

// Remove where clause
protocol MutableSelfStaticParser: TypedStaticParser where ResultTransferType == AnyTypedParserResultTransferType<Self> {
    func parseTypeVar() -> AnyTypedParserResultTransferType<Self>
}

extension MutableSelfStaticParser {

    func anyFunction() -> () {
        let t = self.parseTypeVar
        // Remove this and below
        _ = t()
        _ = self.parseTypeVar()
    }
}
@belkadan
Copy link
Contributor

belkadan commented Apr 6, 2018

Ooh, it's a stack overflow in emitValueWitnessTableRef / emitDirectTypeMetadataRef / enumerateFulfillments. That sounds like @rjmccall's recent work.

@swift-ci create

@rjmccall
Copy link
Member

rjmccall commented Apr 7, 2018

I don't believe any of that work is in Swift 4.1, but it doesn't really matter.

@rjmccall
Copy link
Member

rjmccall commented Apr 7, 2018

GenericSignature::getConformanceAccessPath is telling us that the access path to Self: ParserResult (required to build the type metadata for AnyTypedParserResultTransferType<Self>) is

τ_0_0: MutableSelfStaticParser -> τ_0_0: TypedStaticParser -> τ_0_0.ResultTransferType: TypedParserResultTransferType -> τ_0_0.Result: ParserResult

instead of, y'know,

τ_0_0: MutableSelfStaticParser -> τ_0_0: TypedStaticParser -> τ_0_0: StaticParser -> τ_0_0: ParserResult

τ_0_0.ResultTransferType is concretely known to be AnyTypedParserResultTransferType<Self> because of the same-type constraint on MutableSelfStaticParser. Its type metadata must be passed to the associated conformance accessor for τ_0_0.Result: ParserResult. Because it is no longer an archetype, we lose the information that it's available via an associated type accessor, and so we try to build it from scratch, which requires Self: ParserResult.

So this is something we could potentially solve in IRGen by recognizing that we have a better access to AnyTypedParserResultTransferType<Self> than just building it from scratch. But arguably it also ought to be fixed in the AST by not offering us this bizarre access path in the first place.

@rjmccall
Copy link
Member

rjmccall commented Apr 7, 2018

Tagging @slavapestov and @DougGregor.

@rjmccall
Copy link
Member

Still crashes on trunk.

@slavapestov
Copy link
Member

#36101

@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 IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

5 participants