OpaqueReturnTypeOf swiftui

Inside swiftui.swiftinterface I find:

public struct DefaultNavigationViewStyle : SwiftUI.NavigationViewStyle {
  public init()
  public func _body(configuration: SwiftUI._NavigationViewStyleConfiguration) -> some SwiftUI.View
  public typealias _Body = @_opaqueReturnTypeOf("$s7SwiftUI26DefaultNavigationViewStyleV5_body13configurationQrAA01_deF13ConfigurationV_tF", 0) 🦸

Now I don't see _Body in the documentation, but how do I decypher this?

Especially the :superhero:

(Edit: Somehow Discourse makes them look different, but they're the same character in the Editor)

The s7Swift... string is the mangled name. You can pass it to swift-demangle to get the demangled name.

I knew that part... The attribute and the emoticon not though.

You can see what the attribute does here: https://github.com/apple/swift/blob/master/lib/Sema/TypeCheckType.cpp#L2055 (resolves the opaque type decl and returns the type) I am not sure about the emoji though!

1 Like

If I recall correctly someone on Slack told me (maybe @harlanhaskins) that the emoji was @Joe_Groff's idea.


The emoji is meaningless; an arbitrary identifier can be used there, and the parser will ignore it. It's just there for the attribute to have something to grammatically hang on to. The information needed is entirely in the attribute itself. The string argument indicates which declaration's opaque type is being referenced using the declaration's mangled name, and the integer argument indicates which independent element of the opaque type is being referenced; it's currently always zero, but in the future we may generalize the feature so you can have multiple some Protocol types in an opaque return, and this index will indicate which of them is being referenced.