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-6478] [SE-0143] IRGen Crash with conditional conformance of generic struct #49028

Open
DougGregor opened this issue Nov 27, 2017 · 7 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

@DougGregor
Copy link
Member

Previous ID SR-6478
Radar None
Original Reporter @DougGregor
Type Bug

Attachment: Download

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

md5: f3eea6684af9f3a682ffbda319003a4d

Issue Description:

The following crashes in IR generation when emitting the witness table for the conditional conformance `MySlice: BidirectionalCollection`:

Assertion failed: (result && "get() on unmapped entry?"), function get, file /Users/dgregor/Projects/swift/swift/lib/IRGen/LocalTypeData.h, line 231.
0  swift                    0x00000001104e9408 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001104e8356 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x00000001104e99ce SignalHandler(int) + 366
3  libsystem_platform.dylib 0x00007fff61cf5f5a _sigtramp + 26
4  libsystem_platform.dylib 0x0000000000000001 _sigtramp + 2653987009
5  libsystem_c.dylib        0x00007fff61b2130a abort + 127
6  libsystem_c.dylib        0x00007fff61ae9360 basename_r + 0
7  swift                    0x000000010d239152 swift::irgen::IRGenFunction::getLocalTypeData(swift::CanType, swift::irgen::LocalTypeDataKind) + 114
8  swift                    0x000000010d0dc5d5 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) + 725
9  swift                    0x000000010d0dc291 swift::irgen::emitAssociatedTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::AssociatedType) + 97
10 swift                    0x000000010d0dc178 swift::irgen::emitArchetypeTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>) + 104
11 swift                    0x000000010d1ae6c1 swift::SILWitnessVisitor<(anonymous namespace)::WitnessTableBuilder>::visitProtocolDecl(swift::ProtocolDecl*)::'lambda'()::operator()() const + 1089
12 swift                    0x000000010d1ad173 swift::SILWitnessVisitor<(anonymous namespace)::WitnessTableBuilder>::visitProtocolDecl(swift::ProtocolDecl*) + 835
13 swift                    0x000000010d1a5877 swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 839
@DougGregor
Copy link
Member Author

@slavapestov or @rjmccall, I may ask for your help in understanding how IRGen is supposed to work for these.

@DougGregor
Copy link
Member Author

Significantly reduced so we no longer need the standard library:

protocol P {
  associatedtype A: P 
}

protocol Q: P where A: Q {
}

struct Wrapper<T: P>: P {
  typealias A = Wrapper<T>
}

extension Wrapper: Q where T: Q { }

@DougGregor
Copy link
Member Author

The attached hack-patch works around a substitution issue where we don't have the contextual types we need. It get us to an assertion where, in the process of emitting the witness table `Wrapper<T>: Q`, we emit the witness table access function for `Self.A: Q`, which in this case is also `Wrapper<T>: Q`. We fail in `emitConditionalConformancesBuffer()`, because we're trying to fill in the (abstract) conformance of `T: Q`... which isn't a known fulfillment.

@rjmccall
Copy link
Member

The extra thing that's done for conditional conformances in EmitPolymorphicParameters::bindExtraSources also needs to be done in the conformance's access functions.

@rjmccall
Copy link
Member

We should also do the obvious optimization of adding the self conformance as unscoped local type data; if you do that, you'll need to change the test case to make A a slightly different type that still requires T: Q.

Make sure you do this in the type-metadata access function, too, for which the test case would be an associated type with an unconditional conformance requirement.

@DougGregor
Copy link
Member Author

#13089

@DougGregor
Copy link
Member Author

Merged that PR to get us further, but I'm deeply troubled by the first commit in there. I'm going to hold this bug open until I find a more palatable solution.

@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
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