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

[Source compatibility suite] penny-bot failing to build with main branch #71423

Closed
justice-adams-apple opened this issue Feb 6, 2024 · 9 comments · Fixed by #71737
Closed
Assignees
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 itself crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions key paths Feature: key paths (both native and Objective-C) SILGen Area → compiler: The SIL generation stage source compatibility suite Flag: An issue that surfaced in the source compatibility suite swift 6.0 verifier

Comments

@justice-adams-apple
Copy link
Contributor

Description

The penny-bot project is failing to build with the main branch on macOS. The error seen in the log is

error: compile command failed due to signal 6 (use -v to see invocation)

SIL verification failed: keypath value type should match value type of keypath pattern
  any CodingKey
  URICoderCodingKey
Verifying instruction:
->   %8 = keypath $KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey>, (root $URIValueFromNodeDecoder.CodingStackEntry; stored_property #URIValueFromNodeDecoder.CodingStackEntry.key : $URICoderCodingKey) // user: %9
     %9 = move_value [lexical] [var_decl] %8 : $KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey> // users: %15, %11
In function:
// URIValueFromNodeDecoder.codingPath.getter
sil hidden [ossa] @$s14OpenAPIRuntime23URIValueFromNodeDecoderC10codingPathSays9CodingKey_pGvg : $@convention(method) (@guaranteed URIValueFromNodeDecoder) -> @owned Array<any CodingKey> {
// %0 "self"                                      // users: %2, %1
bb0(%0 : @guaranteed $URIValueFromNodeDecoder):
  debug_value %0 : $URIValueFromNodeDecoder, let, name "self", argno 1, implicit // id: %1
  %2 = ref_element_addr %0 : $URIValueFromNodeDecoder, #URIValueFromNodeDecoder.codingStack // user: %3
  %3 = begin_access [read] [dynamic] %2 : $*Array<URIValueFromNodeDecoder.CodingStackEntry> // users: %5, %4
  %4 = load [copy] %3 : $*Array<URIValueFromNodeDecoder.CodingStackEntry> // user: %7
  end_access %3 : $*Array<URIValueFromNodeDecoder.CodingStackEntry> // id: %5
  %6 = alloc_stack $Array<URIValueFromNodeDecoder.CodingStackEntry> // users: %23, %22, %18, %7
  store %4 to [init] %6 : $*Array<URIValueFromNodeDecoder.CodingStackEntry> // id: %7
  %8 = keypath $KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey>, (root $URIValueFromNodeDecoder.CodingStackEntry; stored_property #URIValueFromNodeDecoder.CodingStackEntry.key : $URICoderCodingKey) // user: %9
  %9 = move_value [lexical] [var_decl] %8 : $KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey> // users: %15, %11
  // function_ref implicit closure #1 in URIValueFromNodeDecoder.codingPath.getter
  %10 = function_ref @$s14OpenAPIRuntime23URIValueFromNodeDecoderC10codingPathSays9CodingKey_pGvgsAE_pAC0I10StackEntry33_BFEE7B52A740E8A5D915E2907E6B5D0CLLVcfu_ : $@convention(thin) @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0, @guaranteed KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey>) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <URIValueFromNodeDecoder.CodingStackEntry, Never, any CodingKey> // user: %12
  %11 = copy_value %9 : $KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey> // user: %12
  %12 = partial_apply [callee_guaranteed] %10(%11) : $@convention(thin) @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0, @guaranteed KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey>) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <URIValueFromNodeDecoder.CodingStackEntry, Never, any CodingKey> // users: %14, %13
  %13 = convert_escape_to_noescape [not_guaranteed] %12 : $@callee_guaranteed @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <URIValueFromNodeDecoder.CodingStackEntry, Never, any CodingKey> to $@noescape @callee_guaranteed @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <URIValueFromNodeDecoder.CodingStackEntry, Never, any CodingKey> // users: %21, %18
  destroy_value %12 : $@callee_guaranteed @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <URIValueFromNodeDecoder.CodingStackEntry, Never, any CodingKey> // id: %14
  destroy_value %9 : $KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey> // id: %15
  // function_ref Collection.map<A, B>(_:)
  %16 = function_ref @$sSlsE3mapySayqd__Gqd__7ElementQzqd_0_YKXEqd_0_YKs5ErrorRd_0_r0_lF : $@convention(method) <Ï„_0_0 where Ï„_0_0 : Collection><Ï„_1_0, Ï„_1_1 where Ï„_1_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <Ï„_0_0.Element, Ï„_1_1, Ï„_1_0>, @in_guaranteed Ï„_0_0) -> (@owned Array<Ï„_1_0>, @error_indirect Ï„_1_1) // user: %18
  %17 = alloc_stack $Never                        // users: %20, %18
  try_apply %16<[URIValueFromNodeDecoder.CodingStackEntry], any CodingKey, Never>(%17, %13, %6) : $@convention(method) <Ï„_0_0 where Ï„_0_0 : Collection><Ï„_1_0, Ï„_1_1 where Ï„_1_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <Ï„_0_0.Element, Ï„_1_1, Ï„_1_0>, @in_guaranteed Ï„_0_0) -> (@owned Array<Ï„_1_0>, @error_indirect Ï„_1_1), normal bb1, error bb2 // id: %18

// %19                                            // user: %24
bb1(%19 : @owned $Array<any CodingKey>):          // Preds: bb0
  dealloc_stack %17 : $*Never                     // id: %20
  destroy_value %13 : $@noescape @callee_guaranteed @substituted <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0) -> (@out Ï„_0_2, @error_indirect Ï„_0_1) for <URIValueFromNodeDecoder.CodingStackEntry, Never, any CodingKey> // id: %21
  destroy_addr %6 : $*Array<URIValueFromNodeDecoder.CodingStackEntry> // id: %22
  dealloc_stack %6 : $*Array<URIValueFromNodeDecoder.CodingStackEntry> // id: %23
  return %19 : $Array<any CodingKey>              // id: %24

bb2:                                              // Preds: bb0
  unreachable                                     // id: %25
} // end sil function '$s14OpenAPIRuntime23URIValueFromNodeDecoderC10codingPathSays9CodingKey_pGvg'

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: <ommited>
1.	Apple Swift version 5.11-dev (LLVM 69fa38fd6c00774, Swift 2fa1022a912a1c0)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module OpenAPIRuntime)
4.	While silgen emitFunction SIL function "@$s14OpenAPIRuntime23URIValueFromNodeDecoderC10codingPathSays9CodingKey_pGvg".
 for getter for codingPath (at /Users/ec2-user/jenkins/workspace/swift-main-source-compat-suite/swift-source-compat-suite/project_cache/penny-bot/.build/checkouts/swift-openapi-runtime/Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder.swift:304:9)
5.	While verifying SIL function "@$s14OpenAPIRuntime23URIValueFromNodeDecoderC10codingPathSays9CodingKey_pGvg".
 for getter for codingPath (at /Users/ec2-user/jenkins/workspace/swift-main-source-compat-suite/swift-source-compat-suite/project_cache/penny-bot/.build/checkouts/swift-openapi-runtime/Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder.swift:304:9)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010bc02f48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1  swift-frontend           0x000000010bc010e8 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x000000010bc035ae SignalHandler(int) + 270
3  libsystem_platform.dylib 0x00007ff809e205ed _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603370415127088
5  libsystem_c.dylib        0x00007ff809d19b45 abort + 123
6  swift-frontend           0x00000001068e5748 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 1288
7  swift-frontend           0x00000001068fb3aa swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 70202
8  swift-frontend           0x00000001068ea0c2 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 18
9  swift-frontend           0x00000001068e8aee (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 12030
10 swift-frontend           0x00000001068e1513 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 227
11 swift-frontend           0x0000000105ed44c0 swift::Lowering::SILGenModule::postEmitFunction(swift::SILDeclRef, swift::SILFunction*) + 240
12 swift-frontend           0x0000000105ed3cf6 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6742
13 swift-frontend           0x0000000105ed4a64 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 228
14 swift-frontend           0x0000000105ed227e swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 190
15 swift-frontend           0x0000000105ffcdff SILGenExtension::visitFuncDecl(swift::FuncDecl*) + 143
16 swift-frontend           0x00000001070de0ca swift::AbstractStorageDecl::visitEmittedAccessors(llvm::function_ref<void (swift::AccessorDecl*)>) const + 90
17 swift-frontend           0x0000000105ed6bc2 swift::Lowering::SILGenModule::visitEmittedAccessors(swift::AbstractStorageDecl*, llvm::function_ref<void (swift::AccessorDecl*)>) + 50
18 swift-frontend           0x0000000105ffcc37 SILGenExtension::visitVarDecl(swift::VarDecl*) + 263
19 swift-frontend           0x0000000105ff89b7 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 103
20 swift-frontend           0x0000000105ff8945 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 21
21 swift-frontend           0x0000000105ed7753 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1315
22 swift-frontend           0x0000000105fe2643 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 115
23 swift-frontend           0x0000000105edd84e llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 382
24 swift-frontend           0x0000000105ed7f71 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 161
25 swift-frontend           0x000000010581f450 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2272
26 swift-frontend           0x000000010583204f withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 143
27 swift-frontend           0x0000000105821ae3 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 931
28 swift-frontend           0x0000000105820922 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3122
29 swift-frontend           0x0000000105641a12 swift::mainEntry(int, char const**) + 2530
30 dyld                     0x00007ff809a9941f start + 1903

Reproduction

swift build --disable-sandbox --package-path penny-bot --verbose --configuration release -Xswiftc -swift-version -Xswiftc 5

Expected behavior

Expected to build

Environment

Apple Swift version 5.11-dev (LLVM 69fa38fd6c00774, Swift 2fa1022)
Target: x86_64-apple-macosx13.0

Additional information

https://ci.swift.org/view/Dashboard/job/swift-main-source-compat-suite/672

@justice-adams-apple justice-adams-apple added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 6, 2024
@justice-adams-apple
Copy link
Contributor Author

Possible related: #39612 ?

@justice-adams-apple justice-adams-apple added the source compatibility suite Flag: An issue that surfaced in the source compatibility suite label Feb 6, 2024
@justice-adams-apple justice-adams-apple changed the title [Source compatibility suite] penny-bot failing to build with main branch on macOS [Source compatibility suite] penny-bot failing to build with main branch Feb 6, 2024
@justice-adams-apple
Copy link
Contributor Author

@rjmccall
Copy link
Contributor

rjmccall commented Feb 7, 2024

The SIL verifier is crashing right out of SILGen. I don’t see any recent changes to either the verifier or SILGen here, but there was a very recent change to KeyPath type checking in #36912 which added covariance in the keypath-literal-to-function path.

The verifier is pointing at a keypath instruction of type $KeyPath<URIValueFromNodeDecoder.CodingStackEntry, any CodingKey>. This type is just the lowered type of the KeyPathExpr, and KeyPath is invariant to type lowering, so this is exactly the type-checked type of the expression. The path is apparently just URIValueFromNodeDecoder.CodingStackEntry.key, which is declared here:

https://github.com/apple/swift-openapi-runtime/blob/76951d77a0609599d2dc233e7e40808a74767c6a/Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder.swift#L129

private struct CodingStackEntry {
   var key: URICoderCodingKey
   var element: URIDecodedNode
}

URICoderCodingKey is declared here:

https://github.com/apple/swift-openapi-runtime/blob/76951d77a0609599d2dc233e7e40808a74767c6a/Sources/OpenAPIRuntime/URICoder/Common/URICodeCodingKey.swift#L18

Note the extension here:

extension URICoderCodingKey: CodingKey {

Okay, so the key path leads to a value of type URICoderCodingKey, but we're somehow getting a KeyPath type whose value type is any CodingKey, which is a supertype. The function that's failing to verify is $s14OpenAPIRuntime23URIValueFromNodeDecoderC10codingPathSays9CodingKey_pGvg, which demangles to OpenAPIRuntime.URIValueFromNodeDecoder.codingPath.getter : [Swift.CodingKey]. That is declared here:

https://github.com/apple/swift-openapi-runtime/blob/76951d77a0609599d2dc233e7e40808a74767c6a/Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder.swift#L304

var codingPath: [any CodingKey] { codingStack.map(\.key) }

So yeah, we are indeed back-propagating a contextual type into the type of the KeyPathExpr. It seems likely that Freddy's patch is the culprit here.

@xedin
Copy link
Contributor

xedin commented Feb 7, 2024

@Jumhyn do you have time to look into this?

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself SILGen Area → compiler: The SIL generation stage verifier crash Bug: A crash, i.e., an abnormal termination of software assertion failure Bug → crash: An assertion failure key paths Feature: key paths (both native and Objective-C) expressions Feature: expressions swift 6.0 and removed triage needed This issue needs more specific labels labels Feb 7, 2024
justice-adams-apple added a commit to swiftlang/swift-source-compat-suite that referenced this issue Feb 7, 2024
@xedin
Copy link
Contributor

xedin commented Feb 12, 2024

Reduction:

protocol CodingKey {}

struct URICoderCodingKey : CodingKey {
}

struct CodingStackEntry {
   var key: URICoderCodingKey
}

struct Test {
  var codingStack: [CodingStackEntry]
  var codingPath: [any CodingKey] { codingStack.map(\.key) }
}

@Jumhyn
Copy link
Member

Jumhyn commented Feb 13, 2024

Oop, missed this. Yeah I can take a look!

@Jumhyn Jumhyn self-assigned this Feb 13, 2024
@Jumhyn
Copy link
Member

Jumhyn commented Feb 14, 2024

@xedin any idea why the source compat run on the PR wouldn't have caught this?

@xedin
Copy link
Contributor

xedin commented Feb 14, 2024

I think this project was added after the run of source compat suite on that PR.

@Jumhyn
Copy link
Member

Jumhyn commented Feb 19, 2024

Finally had a chance to look at this: proposed fix is here

xedin added a commit to xedin/swift-source-compat-suite that referenced this issue Feb 27, 2024
[The issue](swiftlang/swift#71423) has been
fixed and the project is currently UPASS'ing in main configuration.
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 itself crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions key paths Feature: key paths (both native and Objective-C) SILGen Area → compiler: The SIL generation stage source compatibility suite Flag: An issue that surfaced in the source compatibility suite swift 6.0 verifier
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants