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-8240] SEGFAULT: Crash when referring to nested type of specified generic type in initializer of extension #50772

Closed
swift-ci opened this issue Jul 12, 2018 · 4 comments
Labels
assertion failure Bug → crash: An assertion failure 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 swift 4.2 type checker Area → compiler: Semantic analysis TypeResolver types Feature: types

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 12, 2018

Previous ID SR-8240
Radar rdar://problem/42136457
Original Reporter neightchan (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Version 10.0 beta 3 (10L201y)

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

md5: ae5ff02c9fd110a4c1ec21fa77fae859

Issue Description:

The following code segfaults the compiler

struct Box<Representation> {
    let value: Representation
}

enum Repr {}

enum Other {}

extension Repr {
  typealias RawEnum = Other
}

extension Box where Representation == Repr {
  init(rawEnumValue: Representation.RawEnum) {
    fatalError()
  }
}

Note however that Representation.RawEnum can be used without segfault in some cases (including static methods):

extension Box where Representation == Visibility {
  static var rawEnumValue: Representation.RawEnum {
    fatalError()
  }

  var rawEnumValue: Representation.RawEnum {
    fatalError()
  }
}

Segfault (from Xcode 10 beta 3 with default toolchain) follows:

main.swift:22:37: error: 'Representation' does not have a member type named 'RawEnum'; did you mean 'RawEnum'?
  init(rawEnumValue: Representation.RawEnum) {
                                    ^~~~~~~
                                    RawEnum
0  swift                    0x000000010aaa2fea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010aaa23a6 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff6f0d4f5a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000003 _sigtramp + 2431824067
4  swift                    0x00000001081bf0fe swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 142
5  swift                    0x00000001081ba553 (anonymous namespace)::TypeResolver::resolveType(swift::TypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>) + 243
6  swift                    0x00000001081b99ca swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 362
7  swift                    0x0000000108168a66 validateParameterType(swift::ParamDecl*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver&, swift::TypeChecker&) + 134
8  swift                    0x00000001081687eb swift::TypeChecker::typeCheckParameterList(swift::ParameterList*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver&) + 251
9  swift                    0x000000010815cc49 checkGenericFuncSignature(swift::TypeChecker&, swift::GenericSignatureBuilder*, swift::AbstractFunctionDecl*, swift::GenericTypeResolver&) + 265
10 swift                    0x000000010815cad7 swift::TypeChecker::validateGenericFuncSignature(swift::AbstractFunctionDecl*) + 1431
11 swift                    0x0000000108134c93 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 22547
12 swift                    0x00000001081324cb (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 12363
13 swift                    0x00000001081ccb02 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1714
14 swift                    0x0000000107e4ebd0 swift::CompilerInstance::performSema() + 5616
15 swift                    0x00000001070fa4f4 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1892
16 swift                    0x00000001070f8304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
17 swift                    0x00000001070acce5 main + 18917
18 libdyld.dylib            0x00007fff6edc6015 start + 1
19 libdyld.dylib            0x0000000000000042 start + 2435031086
Stack dump:
0.  Program arguments: /Applications/Xcode-9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file main.swift -target x86_64-apple-ios11.3 -enable-objc-interop -sdk /Applications/Xcode-9.4.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -I /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Products/Debug-iphonesimulator -F /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /path/to/.../DerivedData/ModuleCache.noindex -swift-version 4 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -I/path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/swift-overrides.hmap -Xcc -iquote -Xcc /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/PermanentScratchpadIosCommandSwift41-generated-files.hmap -Xcc -I/path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/PermanentScratchpadIosCommandSwift41-own-target-headers.hmap -Xcc -I/path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/PermanentScratchpadIosCommandSwift41-all-target-headers.hmap -Xcc -iquote -Xcc /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/PermanentScratchpadIosCommandSwift41-project-headers.hmap -Xcc -I/path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Products/Debug-iphonesimulator/include -Xcc -I/path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/DerivedSources/x86_64 -Xcc -I/path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/path/to/Working/Directory -emit-module-doc-path /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/Objects-normal/x86_64/main~partial.swiftdoc -serialize-diagnostics-path /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/Objects-normal/x86_64/main.dia -module-name PermanentScratchpadIosCommandSwift41 -emit-module-path /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-dependencies-path /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/Objects-normal/x86_64/main.swiftdeps -o /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Build/Intermediates.noindex/PermanentScratchpadIosCommandSwift41.build/Debug-iphonesimulator/PermanentScratchpadIosCommandSwift41.build/Objects-normal/x86_64/main.o -index-store-path /path/to/.../DerivedData/PermanentScratchpadIosCommandSwift41-eclrgvflzkwdsibageuqwgybzaqn/Index/DataStore -index-system-modules 
1.  While type-checking extension of Box<Repr> at main.swift:21:1
2.  While type-checking 'init(rawEnumValue:)' at main.swift:22:3
3.  While resolving type Representation.RawEnum at main.swift:22:22 - line:22:37] RangeText="Representation.R"
@belkadan
Copy link
Contributor

@swift-ci create

@huonw
Copy link
Mannequin

huonw mannequin commented Jul 17, 2018

Backtrace with asserts on:

sr8240.swift:14:39: error: 'Representation' does not have a member type named 'RawEnum'; did you mean 'RawEnum'?
    init(rawEnumValue: Representation.RawEnum) {
                                      ^~~~~~~
                                      RawEnum
shouldn't have a concrete decl here
UNREACHABLE executed at /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/Sema/TypeCheckGeneric.cpp:229!
0  swift                    0x00000001117a3aa8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001117a2ce7 llvm::sys::RunSignalHandlers() + 39
2  swift                    0x00000001117a4122 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff5c244f5a _sigtramp + 26
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 2749083840
5  libsystem_c.dylib        0x00007fff5bfe21ae abort + 127
6  swift                    0x00000001117430e4 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 532
7  swift                    0x000000010ee84c39 swift::CompleteGenericTypeResolver::resolveDependentMemberType(swift::Type, swift::DeclContext*, swift::SourceRange, swift::ComponentIdentTypeRepr*) + 2089
8  swift                    0x000000010eee4377 resolveIdentTypeComponent(swift::TypeChecker&, swift::DeclContext*, llvm::ArrayRef<swift::ComponentIdentTypeRepr*>, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*) + 599
9  swift                    0x000000010eee3d70 swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*) + 144
10 swift                    0x000000010eee47de swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*) + 158
11 swift                    0x000000010eee3501 swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*) + 145
12 swift                    0x000000010ee90545 validateParameterType(swift::ParamDecl*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver&, swift::TypeChecker&) + 117
13 swift                    0x000000010ee903b7 swift::TypeChecker::typeCheckParameterList(swift::ParameterList*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver&) + 487
14 swift                    0x000000010ee86a4a checkGenericFuncSignature(swift::TypeChecker&, swift::GenericSignatureBuilder*, swift::AbstractFunctionDecl*, swift::GenericTypeResolver&) + 266
15 swift                    0x000000010ee86879 swift::TypeChecker::validateGenericFuncSignature(swift::AbstractFunctionDecl*) + 2153
16 swift                    0x000000010ee59b25 swift::TypeChecker::validateDecl(swift::ValueDecl*) + 10997
17 swift                    0x000000010ee542c0 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 272
18 swift                    0x000000010ee6badb (anonymous namespace)::DeclChecker::visitExtensionDecl(swift::ExtensionDecl*) + 459
19 swift                    0x000000010ee5429c (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 236
20 swift                    0x000000010ee541a6 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 38
21 swift                    0x000000010eef33a8 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1720
22 swift                    0x000000010eb2684c swift::CompilerInstance::parseAndTypeCheckMainFile(swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 444
23 swift                    0x000000010eb2542c swift::CompilerInstance::parseAndCheckTypes(swift::CompilerInstance::ImplicitImports const&) + 636
24 swift                    0x000000010eb24d59 swift::CompilerInstance::performSema() + 473
25 swift                    0x000000010df87532 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1426
26 swift                    0x000000010df85f2a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2954
27 swift                    0x000000010df40bfd main + 2317
28 libdyld.dylib            0x00007fff5bf36015 start + 1
29 libdyld.dylib            0x000000000000000c start + 2752290808
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-06-21-a.xctoolchain/usr/bin/swift -frontend -c -primary-file sr8240.swift -target x86_64-apple-darwin17.6.0 -enable-objc-interop -module-name sr8240 -o /var/folders/3k/4q7m7bkn2k750rpr0jm8s9fr0000gn/T/sr8240-8a00aa.o 
1.  While type-checking extension of Box<Repr> at sr8240.swift:13:1
2.  While type-checking 'init(rawEnumValue:)' at sr8240.swift:14:5
3.  While validating 'init(rawEnumValue:)' at sr8240.swift:14:5
4.  While resolving type Representation.RawEnum at [sr8240.swift:14:24 - line:14:39] RangeText="Representation.R"
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

@huonw
Copy link
Mannequin

huonw mannequin commented Jul 18, 2018

#18004

@huonw
Copy link
Mannequin

huonw mannequin commented Jul 18, 2018

c12bb46

@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
@AnthonyLatsis AnthonyLatsis added type checker Area → compiler: Semantic analysis TypeResolver assertion failure Bug → crash: An assertion failure labels Dec 12, 2023
@AnthonyLatsis AnthonyLatsis added swift 4.2 types Feature: types labels Dec 12, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure 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 swift 4.2 type checker Area → compiler: Semantic analysis TypeResolver types Feature: types
Projects
None yet
Development

No branches or pull requests

3 participants