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-8666] Segmentation fault: 11 (related to dynamically querying conditional conformance?) #51181

Closed
swift-ci opened this issue Aug 30, 2018 · 4 comments

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Aug 30, 2018

Previous ID SR-8666
Radar rdar://problem/43893945
Original Reporter HumZ (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10.0 beta 6 (10L232m)
swiftc 4.2

jb@jb-mbp:~ $ swiftc --version
Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.10.44)
Target: x86_64-apple-darwin17.7.0
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash, Runtime
Assignee None
Priority Medium

md5: b2587dfbc014710348b508e12c07fc00

duplicates:

  • SR-8215 warning: Swift runtime does not yet support dynamically querying conditional conformance

Issue Description:

The following code produces Segmentation fault: 11 on runtime after building with swiftc 4.2:

import Darwin

private protocol AnyChangeTracker {
    var myVariable: Any? { get }
    var isModified: Bool { get }
}

protocol ChangeTrackerType {
    associatedtype Value
    var originalValue: Value { get }
    var value: Value { get set }
    var isModified: Bool { get }
}

extension ChangeTrackerType where Value: Equatable {
    var isModified: Bool {
    return value != originalValue
    }
}

struct ChangeTracker<T: Equatable>: ChangeTrackerType {
    let originalValue: T
    var value: T

    init(value: T) {
    originalValue = value
    self.value = value
    }
}

extension ChangeTracker: AnyChangeTracker where Value: OptionalType, Value.Wrapped: Equatable {
    var myVariable: Any? {
    return value
    }
}

protocol OptionalType {
    associatedtype Wrapped
    var value: Wrapped? { get }
}

extension Optional: OptionalType {
    var value: Wrapped? {
    return self
    }
}

let s: Any = ChangeTracker<String?>(value: "Foo")

guard let s = s as? AnyChangeTracker else {
    print("Does not comply to AnyChangeTracker")
    exit(0)
}

print(s.myVariable ?? "nil")

When building with swiftc 4.1.2, running produces the warning

warning: Swift runtime does not yet support dynamically querying conditional conformance ('Crash.ChangeTracker<Swift.Optional<Swift.String>>': 'Crash.(AnyChangeTracker in _A1D8A7F4C436C7DDBF73EA9DCC81F3E0)')

and typecasting fails

@hamishknight
Copy link
Collaborator

@hamishknight hamishknight commented Aug 30, 2018

@belkadan The linked SR covers the behaviour OP gets under 4.1, but not the runtime crash they get in 4.2.

Here's a reduced example:

protocol Q {
  associatedtype Wrapped
}
struct R<Wrapped> : Q {}

protocol P {}
protocol Z {}
struct S<T> {}
extension S : P where T : Q, T.Wrapped : Z {}

let s: Any = S<R<Int>>()
print(s is P) // boom.

Backtrace:

0.  Program arguments: /Users/Hamish/Desktop/swift-dev/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -interpret /Users/Hamish/Desktop/newplayground/newplayground/main.swift -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -color-diagnostics -module-name main
0  swift                    0x0000000107237b08 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000107236ae8 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x0000000107238122 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff7bd01f5a _sigtramp + 26
4  libsystem_platform.dylib 0x0000000111dd9088 _sigtramp + 2517463368
5  libsystem_platform.dylib 0x000000010b638388 _sigtramp + 2408801352
6  libswiftCore.dylib       0x000000010b210110 swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, llvm::function_ref<swift::TargetMetadata<swift::InProcess> const* (unsigned int)>, llvm::function_ref<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>) + 304
7  libswiftCore.dylib       0x000000010b20ff3c swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const + 396
8  libswiftCore.dylib       0x000000010b21123b swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*)::$_4::operator()(swift::TargetProtocolConformanceDescriptor<swift::InProcess> const&, swift::TargetMetadata<swift::InProcess> const*) const + 75
9  libswiftCore.dylib       0x000000010b210cb1 swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 817
10 libswiftCore.dylib       0x000000010b1ec2ed swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**) + 29
11 libswiftCore.dylib       0x000000010b1f07e7 _conformsToProtocols(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 231
12 libswiftCore.dylib       0x000000010b1ef896 _dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 502
13 libswiftCore.dylib       0x000000010b6380ca _dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 4491818
14 swift                    0x00000001040a53ad llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 461
15 swift                    0x00000001040a8e31 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1329
16 swift                    0x0000000103502615 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 3621
17 swift                    0x00000001034aed9c performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14828
18 swift                    0x00000001034aa364 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2932
19 swift                    0x000000010345f56d main + 685
20 libdyld.dylib            0x00007fff7b9f3015 start + 1
fish: 'xcrun ./swift /Users/Hamish/Desk…' terminated by signal SIGSEGV (Address boundary error)

Using:

Swift version 4.2-dev (LLVM 2157f50b75, Clang 257fa19143, Swift b72d7e2cf9)
Target: x86_64-apple-darwin17.7.0

@belkadan
Copy link
Contributor

@belkadan belkadan commented Aug 30, 2018

Ah, sorry, I saw the error message and jumped to dup it. Good catch.

@DougGregor, @jckarter?

@jckarter
Copy link
Member

@jckarter jckarter commented Aug 30, 2018

@swift-ci create

@DougGregor
Copy link
Member

@DougGregor DougGregor commented Oct 7, 2018

This is already fixed on master. I'm pulling the original test case into #19754

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants