Skip to content

Commit a556b6c

Browse files
committed
Extensions can't declare conformance to Reflectable and transitive conformance is allowed
1 parent 1402adf commit a556b6c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

proposals/NNNN-opt-in-reflection-metadata.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ If the presence of reflection metadata is mandatory, the requirement on Reflecta
127127

128128
## Detailed design
129129

130+
To decide when to emit reflection metadata IRGen will check the conformance of a type to the `Reflectable` protocol and if the type conforms, IRGen will emit reflection.
131+
132+
Conformance to Reflectable should be only allowed at type declarations level, to avoid confusing behavior, when a developer adds conformance on an imported from another module type that doesn't have reflection enabled.
133+
134+
Transitive conformance to Reflectable should be allowed to give API authors an opportunity to hide reflection logic from APIs users as implementation details.
135+
136+
```swift
137+
// Library
138+
public protocol Foo: Reflectable {}
139+
public func consume<T: Foo>(_ t: T) {}
140+
141+
// User
142+
struct Bar: Foo {} // Reflection is emitted
143+
consume(Bar())
144+
```
145+
130146
Since Reflection metadata might be used by the debugger, we propose to always keep that metadata if full emission of debugging information is enabled (`-gdwarf-types` or `-g` flags).
131147

132148
### Changes in flags

0 commit comments

Comments
 (0)