Commit 89a7663
authored
[AutoDiff] Initial support for differentiation of throwing functions (#82653)
This adds initial support for differentiation of functions that may produce `Error` result.
Essentially we wrap the pullback into `Optional` and emit a diamond-shape control flow pattern depending on whether the pullback value is available or not. VJP emission was modified to accommodate for this. In addition to this, some additional tricks are required as `try_apply` result is not available in the instruction parent block, it is available in normal successor basic block.
As a result we can now:
- differentiate an active `try_apply` result (that would be produced from `do ... try .. catch` constructions)
- `try_apply` when error result is unreachable (usually `try!` and similar source code constructs)
- Support (some) throwing functions with builtin differentiation operators. stdlib change will follow. Though we cannot support typed throws here (yet)
- Correctly propagate error types during currying around differentiable functions as well as type-checking for `@derivative(of:)` attribute, so we can register custom derivatives for functions producing error result
- Added custom derivative for `Optional.??` operator (note that support here is not yet complete as we cannot differentiate through autoclosures, so `x ?? y` works only if `y` is not active, e.g. a constant value).
Some fixes here and there1 parent b7a07db commit 89a7663
File tree
14 files changed
+725
-74
lines changed- include/swift/SILOptimizer/Differentiation
- lib
- AST
- SILGen
- SILOptimizer/Differentiation
- Sema
- stdlib/public/Differentiation
- test/AutoDiff
- SILGen
- SILOptimizer
- compiler_crashers_fixed
- validation-test
14 files changed
+725
-74
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
280 | 288 | | |
281 | 289 | | |
282 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2920 | 2920 | | |
2921 | 2921 | | |
2922 | 2922 | | |
| 2923 | + | |
2923 | 2924 | | |
2924 | 2925 | | |
2925 | 2926 | | |
| |||
2929 | 2930 | | |
2930 | 2931 | | |
2931 | 2932 | | |
| 2933 | + | |
2932 | 2934 | | |
2933 | 2935 | | |
2934 | 2936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1190 | 1190 | | |
1191 | 1191 | | |
1192 | 1192 | | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
1199 | 1196 | | |
1200 | 1197 | | |
1201 | 1198 | | |
| |||
1213 | 1210 | | |
1214 | 1211 | | |
1215 | 1212 | | |
1216 | | - | |
| 1213 | + | |
| 1214 | + | |
1217 | 1215 | | |
1218 | 1216 | | |
1219 | 1217 | | |
| |||
1240 | 1238 | | |
1241 | 1239 | | |
1242 | 1240 | | |
1243 | | - | |
1244 | | - | |
| 1241 | + | |
| 1242 | + | |
1245 | 1243 | | |
1246 | 1244 | | |
1247 | 1245 | | |
| |||
1253 | 1251 | | |
1254 | 1252 | | |
1255 | 1253 | | |
1256 | | - | |
1257 | | - | |
| 1254 | + | |
| 1255 | + | |
1258 | 1256 | | |
1259 | 1257 | | |
1260 | 1258 | | |
| |||
1323 | 1321 | | |
1324 | 1322 | | |
1325 | 1323 | | |
1326 | | - | |
1327 | | - | |
| 1324 | + | |
| 1325 | + | |
1328 | 1326 | | |
1329 | 1327 | | |
1330 | 1328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| |||
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| 189 | + | |
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
| |||
313 | 315 | | |
314 | 316 | | |
315 | 317 | | |
316 | | - | |
317 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
318 | 322 | | |
319 | | - | |
| 323 | + | |
320 | 324 | | |
321 | 325 | | |
322 | 326 | | |
| |||
0 commit comments