swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
66.86k stars 10.3k forks source link

Parameter Pack + Closure Interop leads to reflection context crashes. #74301

Open chiragramani opened 4 weeks ago

chiragramani commented 4 weeks ago

Description

Parameter Pack + Closure Interop leads to reflection context crashes.

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libswiftRemoteMirror.dylib             0x104dcf260 swift::reflection::ReflectionContext<swift::External<swift::WithObjCInterop<swift::RuntimeTarget<8u>>>>::getClosureContextInfo(unsigned long long, swift::reflection::ClosureContextInfo const&, swift::remote::TypeInfoProvider*) + 480
1   libswiftRemoteMirror.dylib             0x104dafcb8 swift::reflection::ReflectionContext<swift::External<swift::WithObjCInterop<swift::RuntimeTarget<8u>>>>::getInstanceTypeInfo(unsigned long long, swift::remote::TypeInfoProvider*) + 376
2   libswiftRemoteMirror.dylib             0x104dafacc swift_reflection_infoForInstance + 32
3   Symbolication                          0x1003f0118 -[VMUObjectIdentifier _classInfoForMemory:length:atOffset:remoteAddress:] + 768
4   Symbolication                          0x1003f049c -[VMUObjectIdentifier classInfoForMemory:length:remoteAddress:] + 84
5   Symbolication                          0x100397f40 __39-[VMUTaskMemoryScanner _fixupBlockIsas]_block_invoke_2 + 112
6   Symbolication                          0x10039d81c __47-[VMUTaskMemoryScanner _withOrderedNodeMapper:]_block_invoke + 2996

Reproduction

import Foundation

var boxed: [() -> Any] = []

func box<each T: Equatable>(_ items: repeat each T) {
    func provide<Y: Equatable>(
        element: Y
    ) {
        boxed.append({ element })
    }
    repeat provide(element: each items)
}

func setup_repro() {
    box("1", "2", "3")
}

setup_repro()
  1. Tap on Memory Graph assistant in Xcode.
  2. Leak agent crashes.

Expected behavior

Leak agent shouldn't crash.

Environment

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)

Additional information

No response

slavapestov commented 3 weeks ago

This was possibly already fixed by https://github.com/apple/swift/pull/73200. CC @mikeash

kavon commented 3 weeks ago

Is this related to https://github.com/apple/swift/issues/73181 ?

chiragramani commented 3 weeks ago

Is this related to #73181 ?

Oh, yes, they're related. I overlooked linking them together earlier.