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-9430] Compiler crash: capturing result of type(of: self) in convenience initializer #51894

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

Comments

@rintaro
Copy link
Mannequin

rintaro mannequin commented Dec 7, 2018

Previous ID SR-9430
Radar rdar://46982573
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, CompilerCrash, SILGen
Assignee @slavapestov
Priority Medium

md5: d7f2c4f62a3b3bb10db4541d78284887

Issue Description:

class C {
  required init() {}
  convenience init(x: Int) {
    let dynamicSelf = type(of: self)
    _ = { dynamicSelf.init() } 
    self.init()
  }
}

Results:

SIL verification failed: applied argument types do not match suffix of function type's inputs: PAI->getArguments()[i]->getType() == substConv.getSILArgumentType(appliedArgStartIdx + i)
Verifying instruction:
   %1 = argument of bb0 : $@thick C.Type          // users: %10, %5, %7, %7
   %1 = argument of bb0 : $@thick C.Type          // users: %10, %5, %7, %7
     // function_ref closure #​1 in C.init(x:)
  %6 = function_ref @$s4test1CC1xACSi_tcfcACXDycfU_ : $@convention(thin) (@thick @dynamic_self C.Type) -> @owned C // user: %7
->   %7 = partial_apply [callee_guaranteed] %6(%1) : $@convention(thin) (@thick @dynamic_self C.Type) -> @owned C // type-defs: %1; user: %8
     strong_release %7 : $@callee_guaranteed () -> @owned C // id: %8
In function:
// C.__allocating_init(x:)
sil hidden @$s4test1CC1xACSi_tcfC : $@convention(method) (Int, @thick C.Type) -> @owned C {
// %0                                             // user: %3
// %1                                             // users: %10, %5, %7, %7
bb0(%0 : $Int, %1 : $@thick C.Type):
  %2 = alloc_stack $C, let, name "self"           // users: %11, %4, %13, %14
  debug_value %0 : $Int, let, name "x", argno 1   // id: %3
  %4 = load %2 : $*C
  debug_value %1 : $@thick C.Type, let, name "dynamicSelf" // id: %5
  // function_ref closure #​1 in C.init(x:)
  %6 = function_ref @$s4test1CC1xACSi_tcfcACXDycfU_ : $@convention(thin) (@thick @dynamic_self C.Type) -> @owned C // user: %7
  %7 = partial_apply [callee_guaranteed] %6(%1) : $@convention(thin) (@thick @dynamic_self C.Type) -> @owned C // type-defs: %1; user: %8
  strong_release %7 : $@callee_guaranteed () -> @owned C // id: %8
  // function_ref C.__allocating_init()
  %9 = function_ref @$s4test1CCACycfC : $@convention(method) (@thick C.Type) -> @owned C // user: %10
  %10 = apply %9(%1) : $@convention(method) (@thick C.Type) -> @owned C // users: %12, %15, %11
  store %10 to %2 : $*C                           // id: %11
  strong_retain %10 : $C                          // id: %12
  destroy_addr %2 : $*C                           // id: %13
  dealloc_stack %2 : $*C                          // id: %14
  return %10 : $C                                 // id: %15
} // end sil function '$s4test1CC1xACSi_tcfC'

Stack dump:
0.  Program arguments: /Users/rintaro/Repositories/swift-oss/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -interpret test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name test 
1.  While verifying SIL function "@$s4test1CC1xACSi_tcfC".
 for 'init(x:)' (at test.swift:4:15)
0  swift                    0x000000010b0738c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010b072898 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010b073ee2 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff67ac5b3d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000110c18bc6 _sigtramp + 2836738214
5  libsystem_c.dylib        0x00007fff679831c9 abort + 127
6  swift                    0x000000010801fdb9 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 633
7  swift                    0x000000010802dad1 swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::SILInstruction*) + 43825
8  swift                    0x0000000108021b1c (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 1196
9  swift                    0x000000010801c107 swift::SILFunction::verify(bool) const + 7095
10 swift                    0x000000010801f193 swift::SILModule::verify() const + 211
11 swift                    0x0000000107a00848 swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 232
12 swift                    0x000000010717a28d performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 11181
13 swift                    0x0000000107176672 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
14 swift                    0x000000010712843e main + 686
15 libdyld.dylib            0x00007fff678daed9 start + 1
Abort trap: 6
@belkadan
Copy link
Contributor

belkadan commented Dec 7, 2018

cc @slavapestov, @jckarter

@jckarter
Copy link
Member

jckarter commented Dec 7, 2018

Looks like a @dynamic_self mismatch.

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

No branches or pull requests

4 participants