Skip to content

Labeled tuple with KeyPath expression as functions #71882

@kateinoigakukun

Description

@kateinoigakukun

Description

No response

Reproduction

// $ swift-frontend -frontend -emit-silgen check.swift
struct S {}

struct A {
  var m: (S, S)
}

func takeKeyPathAsClosure(_: (A) -> (x: S, y: S)) {}

func check() {
  takeKeyPathAsClosure(\A.m)
}

Stack dump

SIL verification failed: keypath value type should match value type of keypath pattern
  (x: S, y: S)
  (S, S)
Verifying instruction:
->   %0 = keypath $KeyPath<A, (x: S, y: S)>, (root $A; stored_property #A.m : $(S, S)) // user: %1
     %1 = move_value [lexical] [var_decl] %0 : $KeyPath<A, (x: S, y: S)> // users: %10, %3
In function:
// check()
sil hidden [ossa] @$s5checkAAyyF : $@convention(thin) () -> () {
bb0:
  %0 = keypath $KeyPath<A, (x: S, y: S)>, (root $A; stored_property #A.m : $(S, S)) // user: %1
  %1 = move_value [lexical] [var_decl] %0 : $KeyPath<A, (x: S, y: S)> // users: %10, %3
  // function_ref implicit closure #1 in check()
  %2 = function_ref @$s5checkAAyyFAA1SV1x_AC1ytAA1AVcfu_ : $@convention(thin) (A, @guaranteed KeyPath<A, (x: S, y: S)>) -> (S, S) // user: %4
  %3 = copy_value %1 : $KeyPath<A, (x: S, y: S)>  // user: %4
  %4 = partial_apply [callee_guaranteed] %2(%3) : $@convention(thin) (A, @guaranteed KeyPath<A, (x: S, y: S)>) -> (S, S) // users: %9, %5
  %5 = convert_escape_to_noescape [not_guaranteed] %4 : $@callee_guaranteed (A) -> (S, S) to $@noescape @callee_guaranteed (A) -> (S, S) // users: %8, %7
  // function_ref takeKeyPathAsClosure(_:)
  %6 = function_ref @$s5check20takeKeyPathAsClosureyyAA1SV1x_AD1ytAA1AVXEF : $@convention(thin) (@guaranteed @noescape @callee_guaranteed (A) -> (S, S)) -> () // user: %7
  %7 = apply %6(%5) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed (A) -> (S, S)) -> ()
  destroy_value %5 : $@noescape @callee_guaranteed (A) -> (S, S) // id: %8
  destroy_value %4 : $@callee_guaranteed (A) -> (S, S) // id: %9
  destroy_value %1 : $KeyPath<A, (x: S, y: S)>    // id: %10
  %11 = tuple ()                                  // user: %12
  return %11 : $()                                // id: %12
} // end sil function '$s5checkAAyyF'

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend -frontend -emit-silgen check.swift
1.      Swift version 5.11-dev (LLVM 87ace14daa2139a, Swift 8bb684628593220)
2.      Compiling with the current language version
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for module check)
4.      While silgen emitFunction SIL function "@$s5checkAAyyF".
 for 'check()' (at check.swift:18:1)
5.      While verifying SIL function "@$s5checkAAyyF".
 for 'check()' (at check.swift:18:1)
 #0 0x0000562f02f6f947 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x79d5947)
 #1 0x0000562f02f6d64e llvm::sys::RunSignalHandlers() (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x79d364e)
 #2 0x0000562f02f6ffbf SignalHandler(int) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x79d5fbf)
 #3 0x00007fe11ba90420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fe119f6300b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fe119f42859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7
 #6 0x0000562efd54afd3 (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1fb0fd3)
 #7 0x0000562efd560042 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1fc6042)
 #8 0x0000562efd54fa40 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1fb5a40)
 #9 0x0000562efd54e1a9 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1fb41a9)
#10 0x0000562efd546672 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1fac672)
#11 0x0000562efc9e1a4e swift::Lowering::SILGenModule::postEmitFunction(swift::SILDeclRef, swift::SILFunction*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1447a4e)
#12 0x0000562efc9e1151 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1447151)
#13 0x0000562efc9e22b2 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x14482b2)
#14 0x0000562efc9df553 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x1445553)
#15 0x0000562efc9e562f swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x144b62f)
#16 0x0000562efcad7994 swift::SimpleRequest<swift::ASTLoweringRequest, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x153d994)
#17 0x0000562efc9eb5b8 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x14515b8)
#18 0x0000562efc9e60b2 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0x144c0b2)
#19 0x0000562efc26e357 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0xcd4357)
#20 0x0000562efc284999 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0xcea999)
#21 0x0000562efc271d75 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0xcd7d75)
#22 0x0000562efc2703ed swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0xcd63ed)
#23 0x0000562efc067df7 swift::mainEntry(int, char const**) (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0xacddf7)
#24 0x00007fe119f44083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3
#25 0x0000562efc0660de _start (/home/katei/ghq/work.katei.dev/swiftwasm-source/build/Packaging/dist-toolchain/swift-wasm-DEVELOPMENT-SNAPSHOT/usr/bin/swift-frontend+0xacc0de)

Expected behavior

Should be compile error

Environment

Swift version 5.11-dev (LLVM 87ace14daa2139a, Swift 8bb6846)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwarekey pathsFeature: key paths (both native and Objective-C)triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions