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-6746] Strideable conformance with missing Stride typealias triggers segfault in type checking #49295

Closed
swift-ci opened this issue Jan 12, 2018 · 4 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

@swift-ci
Copy link
Collaborator

Previous ID SR-6746
Radar rdar://problem/36483751
Original Reporter dal (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 9.2 (9C40b)

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

macOS 10.13.2 (17C88)

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

md5: 7969d731cd3e4f5ec8a9ed327037cfb9

Issue Description:

An incomplete Strideable conformance for some type `Foo` for which `typealias Stride` is not defined does not produce a conformance error as expected, but instead causes a segmentation fault during type checking on the attempt to resolve `Foo.Stride`.

Reproducing Test Case:

struct Foo: Strideable {
    // typealias Stride = Int
    let x: Int

    func distance(to other: Foo) -> Foo.Stride { return abs(other.x - x) }
    func advanced(by n: Foo.Stride) -> Foo { return Foo(x: x + n) }
}

Output:

0  swift                    0x000000010ed2f36a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010ed2e7a6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fff5f54af5a _sigtramp + 26
3  libsystem_platform.dylib 0x00007ffee45e4408 _sigtramp + 2231997640
4  swift                    0x000000010c78b349 swift::TypeChecker::lookupMemberType(swift::DeclContext*, swift::Type, swift::Identifier, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 1513
5  swift                    0x000000010c7e075e resolveIdentTypeComponent(swift::TypeChecker&, swift::DeclContext*, llvm::ArrayRef<swift::ComponentIdentTypeRepr*>, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 1102
6  swift                    0x000000010c7ddc0a swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 122
7  swift                    0x000000010c7d9b6d (anonymous namespace)::TypeResolver::resolveType(swift::TypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>) + 157
8  swift                    0x000000010c7d9a67 swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 295
9  swift                    0x000000010c7d8c99 swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 441
10 swift                    0x000000010c78f2d2 validateParameterType(swift::ParamDecl*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver&, swift::TypeChecker&) + 130
11 swift                    0x000000010c78f0e6 swift::TypeChecker::typeCheckParameterList(swift::ParameterList*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver&) + 150
12 swift                    0x000000010c765a35 (anonymous namespace)::DeclChecker::visitFuncDecl(swift::FuncDecl*) + 4565
13 swift                    0x000000010c75aef7 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 167
14 swift                    0x000000010c751284 swift::TypeChecker::validateDecl(swift::ValueDecl*) + 1988
15 swift                    0x000000010c8f6861 swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, swift::NLOptions, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 3745
16 swift                    0x000000010c78ac02 swift::TypeChecker::lookupMember(swift::DeclContext*, swift::Type, swift::DeclName, swift::OptionSet<swift::NameLookupFlags, unsigned int>)::$_1::operator()() const + 226
17 swift                    0x000000010c78aac9 swift::TypeChecker::lookupMember(swift::DeclContext*, swift::Type, swift::DeclName, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 281
18 swift                    0x000000010c7a924e (anonymous namespace)::WitnessChecker::lookupValueWitnesses(swift::ValueDecl*, bool*) + 830
19 swift                    0x000000010c7ac064 (anonymous namespace)::ConformanceChecker::inferTypeWitnessesViaValueWitnesses(llvm::SetVector<swift::AssociatedTypeDecl*, std::__1::vector<swift::AssociatedTypeDecl*, std::__1::allocator<swift::AssociatedTypeDecl*> >, llvm::DenseSet<swift::AssociatedTypeDecl*, llvm::DenseMapInfo<swift::AssociatedTypeDecl*> > > const&) + 852
20 swift                    0x000000010c798877 (anonymous namespace)::ConformanceChecker::resolveTypeWitnesses() + 887
21 swift                    0x000000010c7c15fc swift::TypeChecker::resolveTypeWitness(swift::NormalProtocolConformance const*, swift::AssociatedTypeDecl*) + 124
22 swift                    0x000000010c8ff98d swift::NormalProtocolConformance::getTypeWitnessAndDecl(swift::AssociatedTypeDecl*, swift::LazyResolver*, swift::SubstOptions) const + 589
23 swift                    0x000000010c8ff02f swift::ProtocolConformance::getTypeWitnessAndDecl(swift::AssociatedTypeDecl*, swift::LazyResolver*, swift::SubstOptions) const + 463
24 swift                    0x000000010c78b304 swift::TypeChecker::lookupMemberType(swift::DeclContext*, swift::Type, swift::Identifier, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 1444
25 swift                    0x000000010c7e075e resolveIdentTypeComponent(swift::TypeChecker&, swift::DeclContext*, llvm::ArrayRef<swift::ComponentIdentTypeRepr*>, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 1102
26 swift                    0x000000010c7ddc0a swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 122
27 swift                    0x000000010c7d9b6d (anonymous namespace)::TypeResolver::resolveType(swift::TypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>) + 157
28 swift                    0x000000010c7d9a67 swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 295
29 swift                    0x000000010c7d8c99 swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 441
30 swift                    0x000000010c7659b2 (anonymous namespace)::DeclChecker::visitFuncDecl(swift::FuncDecl*) + 4434
31 swift                    0x000000010c75aef7 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 167
32 swift                    0x000000010c75b8db (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 2699
33 swift                    0x000000010c7e99f3 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1731
34 swift                    0x000000010c3129c4 swift::CompilerInstance::performSema() + 4628
35 swift                    0x000000010b688fbb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1371
36 swift                    0x000000010b6871f4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
37 swift                    0x000000010b63be78 main + 12248
38 libdyld.dylib            0x00007fff5f2c9115 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret Test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name Test 
1.  While type-checking 'Foo' at Test.swift:1:1
2.  While type-checking 'distance(to:)' at Test.swift:5:5
3.  While resolving type Foo.Stride at [Test.swift:5:37 - line:5:41] RangeText="Foo.S"
4.  While resolving requirement Swift.(file)._Strideable.Stride in conformance Foo: _Strideable module Test
5.  While validating 'advanced(by:)' at Test.swift:9:5
6.  While type-checking 'advanced(by:)' at Test.swift:9:5
7.  While resolving type Foo.Stride at [Test.swift:9:25 - line:9:29] RangeText="Foo.S"
[1]    17066 segmentation fault  swift Test.swift
@moiseev
Copy link
Mannequin

moiseev mannequin commented Jan 12, 2018

/cc @DougGregor

@moiseev
Copy link
Mannequin

moiseev mannequin commented Jan 12, 2018

@swift-cicreate

@belkadan
Copy link
Contributor

Looks like it no longer crashes in master, which means 4.1 is probably fixed too.

@DougGregor
Copy link
Member

Fixed in 4.1, test is coming in #14159

@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

4 participants