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

Compiler crash with pack expansion #67322

Closed
xAlien95 opened this issue Jul 14, 2023 · 1 comment · Fixed by #67565
Closed

Compiler crash with pack expansion #67322

xAlien95 opened this issue Jul 14, 2023 · 1 comment · Fixed by #67565
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 in itself crash Bug: A crash, i.e., an abnormal termination of software demangling Area → compiler: The `libswiftDemangling` library generics Feature: generic declarations and types swift 5.9 variadic generics Feature → generics: Variadic generics

Comments

@xAlien95
Copy link
Contributor

Description
The following code is causing a compiler crash, with the error message Incorrect reconstructed type for $ss7KeyPathCyxqd__Gqd__Qp_tD (Full output/stack dump).

extension Array {
  func sorted<each Value: Comparable>(by keyPath: repeat KeyPath<Element, each Value>) -> Self {
    return sorted { a, b in
      var ordered = true, equal = true

      func process<T: Comparable>(_ keyPath: KeyPath<Element, T>) {
        let l = a[keyPath: keyPath], r = b[keyPath: keyPath]
        if equal {
          if l != r { equal = false }
          if l > r { ordered = false }
        }
      }

      repeat process(each keyPath)

      return ordered
    }
  }
}

Steps to reproduce
Build the script with the latest Swift development snapshot.

Expected behavior
The compiler shouldn't crash.

Environment

  • Swift compiler version info: swift-DEVELOPMENT-SNAPSHOT-2023-07-10-a.xctoolchain, Apple Swift version 5.9-dev (LLVM 677d82daa6d87d2, Swift 291fe21d5020234)
  • Xcode version info: Xcode 14.2, Build version 14C18
  • Deployment target: macOS 12.6.7 (21G651)
@xAlien95 xAlien95 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jul 14, 2023
@xAlien95
Copy link
Contributor Author

It's actually a regression: it compiles successfully and works as intended with swift-DEVELOPMENT-SNAPSHOT-2023-07-07-a.xctoolchain.

slavapestov added a commit to slavapestov/swift that referenced this issue Jul 27, 2023
…ype() implementations

The old behavior was only correct when building substituted types,
ie, if createTupleType() was never called with a pack expansion type.

This was the case in the runtime's MetadataLookup which applies
substitutions to an interface type to ultimately construct metadata
for a fully-concrete type, but not in the ASTDemangler, where we
actually build interface types.

Since TypeDecoder doesn't have any way to query the kind of type
it just built, let's just instead make this decision inside the
implementation of the type builder concept.

Fixes apple#67322.
slavapestov added a commit to slavapestov/swift that referenced this issue Jul 27, 2023
…ype() implementations

The old behavior was only correct when building substituted types,
ie, if createTupleType() was never called with a pack expansion type.

This was the case in the runtime's MetadataLookup which applies
substitutions to an interface type to ultimately construct metadata
for a fully-concrete type, but not in the ASTDemangler, where we
actually build interface types.

Since TypeDecoder doesn't have any way to query the kind of type
it just built, let's just instead make this decision inside the
implementation of the type builder concept.

Fixes apple#67322.
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself generics Feature: generic declarations and types variadic generics Feature → generics: Variadic generics swift 5.9 crash Bug: A crash, i.e., an abnormal termination of software assertion failure Bug → crash: An assertion failure demangling Area → compiler: The `libswiftDemangling` library and removed triage needed This issue needs more specific labels labels Jul 28, 2023
slavapestov added a commit to slavapestov/swift that referenced this issue Aug 15, 2023
…ype() implementations

The old behavior was only correct when building substituted types,
ie, if createTupleType() was never called with a pack expansion type.

This was the case in the runtime's MetadataLookup which applies
substitutions to an interface type to ultimately construct metadata
for a fully-concrete type, but not in the ASTDemangler, where we
actually build interface types.

Since TypeDecoder doesn't have any way to query the kind of type
it just built, let's just instead make this decision inside the
implementation of the type builder concept.

Fixes apple#67322.
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 demangling Area → compiler: The `libswiftDemangling` library generics Feature: generic declarations and types swift 5.9 variadic generics Feature → generics: Variadic generics
Projects
None yet
3 participants