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-6850] Conditional conformance crasher: condition on inner type #49399

Closed
airspeedswift opened this issue Jan 26, 2018 · 4 comments
Closed
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

@airspeedswift
Copy link
Member

Previous ID SR-6850
Radar rdar://problem/36906751
Original Reporter @airspeedswift
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @DougGregor
Priority Medium

md5: e8456335d92edf60e1adcc1da963def0

Issue Description:

The following currently crashes on compilation.

The cause appears to be that the Inner type is defined conditionally (when Bound: Strideable) but the conditional conformance leaves this out.

To fix the crasher, add the necessary conditions for Inner to exist. Instead this should be implied, or generate a compiler warning. (my preference is implied, and I think that's more in keeping with other similar situations)

This is a reduction of the implementation for CountableRange.Index: Hashable where Bound: Hashable

struct S<T: Comparable> { }

// Inner only exists where T: Strideable
extension S where T: Strideable {
struct Inner { }

var inner: Inner { return Inner() }
}

extension S.Inner: Equatable {
static func == (lhs: S<T>.Inner, rhs: S<T>.Inner) -> Bool { return true }
}

// T: Strideable should be inferred, or maybe required,
// but currently it just crashes on compilation
extension S.Inner: Hashable 
where T: Hashable 
// uncomment to make it compile...
// , T: Strideable
{
var hashValue: Int { return 0 }
}

let s = S<Int>()
let i = s.inner.hashValue

print(i)
@airspeedswift
Copy link
Member Author

@swift-ci create

@huonw
Copy link
Mannequin

huonw mannequin commented Jan 30, 2018

Reduced slightly:

protocol P {}
protocol Q { func foo() }

struct S<T> {}

extension S where T: P {
    struct Inner {}
}

extension S.Inner: Q where T: Q {
    func foo() {}
}

Backtrace:

9  swift                    0x000000010e8af6cb swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap const&, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 507
10 swift                    0x000000010e6df0e9 swift::irgen::FulfillmentMap::searchNominalTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 521
11 swift                    0x000000010e6dea7b swift::irgen::FulfillmentMap::searchTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::irgen::IsExact_t, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 843
12 swift                    0x000000010e6de842 swift::irgen::FulfillmentMap::searchTypeMetadata(swift::irgen::IRGenModule&, swift::CanType, swift::irgen::IsExact_t, unsigned int, swift::irgen::MetadataPath&&, swift::irgen::FulfillmentMap::InterestingKeysCallback const&) + 274
13 swift                    0x000000010ea1a38b swift::irgen::LocalTypeDataCache::addAbstractForTypeMetadata(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::IsExact_t, llvm::Value*) + 187
14 swift                    0x000000010ea1a2bf swift::irgen::IRGenFunction::bindLocalTypeDataFromTypeMetadata(swift::CanType, swift::irgen::IsExact_t, llvm::Value*) + 207
15 swift                    0x000000010e8bfd2c (anonymous namespace)::EmitPolymorphicParameters::bindExtraSource(swift::irgen::MetadataSource const&, swift::irgen::Explosion&, swift::irgen::WitnessMetadata*) + 620
16 swift                    0x000000010e8ad319 (anonymous namespace)::EmitPolymorphicParameters::emit(swift::irgen::Explosion&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 137
17 swift                    0x000000010e8ad23e swift::irgen::emitPolymorphicParameters(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::Explosion&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 78
18 swift                    0x000000010e9a4ce5 emitEntryPointArgumentsNativeCC((anonymous namespace)::IRGenSILFunction&, swift::SILBasicBlock*, swift::irgen::Explosion&) + 1157
19 swift                    0x000000010e99f7a5 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 1605

@huonw
Copy link
Mannequin

huonw mannequin commented Jan 31, 2018

Possibly fixed in #14293

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 5, 2018

Yeah, that PR fixed it.

@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

2 participants