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-9429] Compiler crash: passing Self.self in initializer in protocol extension #51893

Closed
rintaro mannequin opened this issue Dec 7, 2018 · 3 comments
Closed

[SR-9429] Compiler crash: passing Self.self in initializer in protocol extension #51893

rintaro mannequin opened this issue Dec 7, 2018 · 3 comments
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 regression SILGen Area → compiler: The SIL generation stage swift 5.0

Comments

@rintaro
Copy link
Mannequin

rintaro mannequin commented Dec 7, 2018

Previous ID SR-9429
Radar None
Original Reporter @rintaro
Type Bug
Status Resolved
Resolution Done
Environment

master as of 12/07/2018

94b167d

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.0Regression, CompilerCrash, SILGen
Assignee @slavapestov
Priority Medium

md5: c17eb3385b3a7727af36c09b3a082ee8

Issue Description:

protocol _P {
  init()
}

extension _P {
  init<T>(_fn:(Self.Type)->T){
    _ = _fn(Self.self)
    self.init()
  }
}

class C : _P {
  required init() {}
  convenience init(x: Int) {
    self.init(_fn: { _ in fatalError() })
  }
}

Results:

Assertion failed: (argType == parent->getParent()->mapTypeIntoContext( SGF.getSILType(parameterInfo)) && "argument does not have same type as specified by parameter info"), function visitType, file /Users/rintaro/Repositories/swift-oss/swift/lib/SILGen/SILGenProlog.cpp, line 110.
Stack dump:
0.  Program arguments: ../build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -emit-ir test.swift 
1.  While silgen emitConstructor SIL function "@$s4test1CC1xACSi_tcfC".
 for 'init(x:)' (at test.swift:14:15)
2.  While silgen closureexpr SIL function "@$s4test1CC1xACSi_tcfcs5NeverOACXDmXEfU_".
 for expression at [test.swift:15:20 - line:15:40] RangeText="{ _ in fatalError() "
0  swift                    0x000000010cc788c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010cc77898 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010cc78ee2 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff67ac5b3d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000117bb2938 _sigtramp + 2953760280
5  libsystem_c.dylib        0x00007fff679831c9 abort + 127
6  libsystem_c.dylib        0x00007fff6794b868 basename_r + 0
7  swift                    0x000000010973001e (anonymous namespace)::EmitBBArguments::visitType(swift::CanType, bool) + 766
8  swift                    0x000000010973011b swift::CanTypeVisitor<(anonymous namespace)::EmitBBArguments, swift::Lowering::ManagedValue>::visit(swift::CanType) + 91
9  swift                    0x000000010972fce9 (anonymous namespace)::ArgumentInitHelper::makeArgument(swift::Type, bool, swift::SILBasicBlock*, swift::SILLocation) + 137
10 swift                    0x000000010972f56d (anonymous namespace)::ArgumentInitHelper::emitParam(swift::ParamDecl*) + 797
11 swift                    0x000000010972ee2b swift::Lowering::SILGenFunction::emitProlog(swift::ParameterList*, swift::ParamDecl*, swift::Type, swift::DeclContext*, bool) + 187
12 swift                    0x000000010972e1c3 swift::Lowering::SILGenFunction::emitProlog(swift::AnyFunctionRef, swift::ParameterList*, swift::ParamDecl*, swift::Type, bool) + 99
13 swift                    0x00000001096e763e swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 126
14 swift                    0x0000000109656dd6 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 278
15 swift                    0x00000001096dbc88 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 40
16 swift                    0x00000001096ceba0 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 112
17 swift                    0x00000001096c3a39 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
18 swift                    0x000000010963ddc4 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 452
19 swift                    0x00000001096aa677 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 343
20 swift                    0x000000010963df52 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 114
21 swift                    0x00000001096765f4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3924
22 swift                    0x000000010966f969 (anonymous namespace)::ArgEmitter::emitTopLevel(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 5881
23 swift                    0x0000000109681cb7 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 1047
24 swift                    0x00000001096813bc (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1756
25 swift                    0x0000000109666466 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3030
26 swift                    0x0000000109665790 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 2016
27 swift                    0x00000001096ceb80 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 80
28 swift                    0x00000001096c3a39 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
29 swift                    0x00000001096d9f37 (anonymous namespace)::RValueEmitter::visitRebindSelfInConstructorExpr(swift::RebindSelfInConstructorExpr*, swift::Lowering::SGFContext) + 343
30 swift                    0x00000001096d070b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 7131
31 swift                    0x00000001096c3f9e swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1198
32 swift                    0x000000010973320c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 8652
33 swift                    0x0000000109731035 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
34 swift                    0x000000010969e790 swift::Lowering::SILGenFunction::emitValueConstructor(swift::ConstructorDecl*) + 6816
35 swift                    0x000000010965c7f3 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*)::$_3::operator()() const::'lambda'(swift::SILFunction*)::operator()(swift::SILFunction*) const + 259
36 swift                    0x0000000109656970 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*)::$_3::operator()() const + 304
37 swift                    0x0000000109656130 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 368
38 swift                    0x000000010973bbe4 (anonymous namespace)::SILGenType::emitType() + 276
39 swift                    0x000000010973bac9 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
40 swift                    0x000000010965a8c6 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 806
41 swift                    0x000000010965b823 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 371
42 swift                    0x000000010965bd30 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&) + 16
43 swift                    0x0000000108d7eabf performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 9183
44 swift                    0x0000000108d7b672 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
45 swift                    0x0000000108d2d43e main + 686
46 libdyld.dylib            0x00007fff678daed9 start + 1
47 libdyld.dylib            0x0000000000000004 start + 2557628716
Abort trap: 6

Doesn't crash if class C is final.

@belkadan
Copy link
Contributor

belkadan commented Dec 7, 2018

@slavapestov, does Self work in this position? I thought that we didn't count this as a covariant self because it's not literally in return position.

@slavapestov
Copy link
Member

It's in a protocol extension, so Self is just a normal generic parameter, so it should work.

@slavapestov
Copy link
Member

#21817

@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 regression SILGen Area → compiler: The SIL generation stage swift 5.0
Projects
None yet
Development

No branches or pull requests

3 participants