Skip to content

Unbound memory growth when using existential with primary associated type in SwiftUI view #64974

Open
@mbrandonw

Description

@mbrandonw

Description

I filed this bug in Feedback (FB12101395) as currently I've only been able to reproduce it in SwiftUI, but it does seem like a Swift bug in general.

Run the following code in a simulator, tap the “Go” button, and notice that the application freezes:

import SwiftUI

struct ContentView: View {
  var body: some View {
    NavigationStack {
      NavigationLink("Go") {
        DemoView()
      }
    }
  }
}

protocol Foo<A> {
  associatedtype A
}
struct Bar: Foo {
  typealias A = Int
}

struct DemoView: View {
  let foo: any Foo<Int> = Bar()
  var body: some View {
    EmptyView()
  }
}

If you open the Debug Navigator in Xcode you will notice that the memory keeps growing.

This happens in Xcode 14.2+Swift 5.7 as well as Xcode 14.3+Swift 5.8.

Steps to reproduce

Run the above in a SwiftUI application.

Expected behavior

Tapping the "Go" button should drill down to the destination.

Environment

  • swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
    • This also happens in Swift 5.7
  • Xcode 14.3, Build version 14E222b
    • This also happens in Xcode 14.2
  • iOS 16+

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.constrained existentialsFeature → existentials: constrained existentials such as 'any Collection<Int>'existentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valueshangBug: Execution is not seen to haltswift 5.8

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions