You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/NNNN-opt-in-reflection-metadata.md
+8-1Lines changed: 8 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,6 +130,7 @@ If the presence of reflection metadata is mandatory, the requirement on Reflecta
130
130
Since Reflection metadata might be used by the debugger, we propose to always keep that metadata if full emission of debugging information isenabled (`-gdwarf-types` or `-g` flags).
131
131
132
132
### Changes in flags
133
+
133
134
To handle behavior change between Swift pre-6 and 6, we can introduce a new upcoming feature, which will allow to enable Opt-In mode explicitly for pre-6 Swift with `-enable-upcoming-feature OptInReflection` and will set this mode by defaultin Swift 6.
134
135
135
136
A new flag `-enable-full-reflection-metadata` will also have to be introduced to allow developers to enable reflection in full if they desire in Swift 6 and later.
@@ -154,6 +155,7 @@ For Swift 6, flags `-disable-reflection-metadata` and `-emit-reflection-for-debu
154
155
Introducing a new flag to control the feature will allow us to safely roll it out and avoid breakages of the existing code. For those modules that get compiled with fully enabled metadata, nothing will change (all symbols will stay present). For modules that have the metadata disabled, but are consumers of reflectable API, the compiler will emit the error enforcing the guarantee.
155
156
156
157
### Casts implementation
158
+
157
159
Casting might be a good way to improve the feature's ergonomics because currently there is no way to check if reflection is available at runtime. (`Mirror.children.count` doesn't really help because it doesn't distinguish between the absence of reflection metadata and the absence of fields on a type)
158
160
159
161
To implement this feature, we propose to introduce a new runtime function `swift_reflectableCast`, and emit a call to it instead of `swift_dynamicCast`during IRGen if Reflectable is a target type.
@@ -195,4 +197,9 @@ Dead Code Elimination and linker optimisations were also considered as a way to
195
197
The optimiser could use a conformance to a `Reflectable` protocolas a hint about what reflection metadata should be preserved.
196
198
However, turned out it was quite challenging to statically determine all usages of Reflection metadata even with hints.
197
199
198
-
It was also considered to use an attribute `@reflectable` on nominal type declaration to express the requirement to have reflection metadata, however, a lot of logic had to be re-implemented outside of type-checker to ensure all guarantees are fulfilled.
200
+
It was also considered to use an attribute `@reflectable` on nominal type declaration to express the requirement to have reflection metadata, however, a lot of logic had to be re-implemented outside of type-checker to ensure all guarantees are fulfilled.
201
+
202
+
203
+
## Acknowledgments
204
+
205
+
Thanks to [Joe Groff](https://github.com/jckarter) for various useful pieces of advice, general help along the journey, and for suggesting several useful features like Reflectable casts!
0 commit comments