Commit 3ccda34
committed
Revert "[move-only] Ensure that we treat captured escaping closure arguments as such even if the closure doesn't actually escape"
This reverts commit 224674c.
Originally, I made this change since we were going to follow the AST in a strict
way in terms of what closures are considered escaping or not from a diagnostics
perspective. Upon further investigation I found that we actually do something
different for inout escaping semantics and by treating the AST as the one point
of truth, we are being inconsistent with the rest of the compiler. As an
example, the following code is considered by the compiler to not be an invalid
escaping use of an inout implying that we do not consider the closure to be
escaping:
```
func f(_ x: inout Int) {
let g = {
_ = x
}
}
```
in contrast, a var is always considered to be an escape:
```
func f(_ x: inout Int) {
var g = {
_ = x
}
}
test2.swift:3:13: error: escaping closure captures 'inout' parameter 'x'
var g = {
^
test2.swift:2:10: note: parameter 'x' is declared 'inout'
func f(_ x: inout Int) {
^
test2.swift:4:11: note: captured here
_ = x
^
```
Of course, if we store the let into memory, we get the error one would expect:
```
var global: () -> () = {}
func f(_ x: inout Int) {
let g = {
_ = x
}
global = g
}
test2.swift:4:11: error: escaping closure captures 'inout' parameter 'x'
let g = {
^
test2.swift:3:10: note: parameter 'x' is declared 'inout'
func f(_ x: inout Int) {
^
test2.swift:5:7: note: captured here
_ = x
^
```
By reverting to the old behavior where allocbox to stack ran early, noncopyable
types now have the same sort of semantics: let closures that capture a
noncopyable type that do not on the face of it escape are considered
non-escaping, while if the closure is ever stored into memory (e.x.: store into
a global, into a local var) or escapes, we get the appropriate escaping
diagnostics. E.x.:
```
public struct E : ~Copyable {}
public func borrowVal(_ e: borrowing E) {}
public func consumeVal(_ e: consuming E) {}
func f1() {
var e = E()
// Mutable borrowing use of e. We can consume e as long as we reinit at end
// of function. We don't here, so we get an error.
let c1: () -> () = {
borrowVal(e)
consumeVal(e)
}
// Mutable borrowing use of e. We can consume e as long as we reinit at end
// of function. We do do that here, so no error.
let c2: () -> () = {
borrowVal(e)
consumeVal(e)
e = E()
}
}
```1 parent 3865b5d commit 3ccda34
File tree
3 files changed
+14
-60
lines changed- include/swift/SILOptimizer/PassManager
- lib/SILOptimizer
- PassManager
- Transforms
3 files changed
+14
-60
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | 115 | | |
119 | 116 | | |
120 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | 172 | | |
178 | 173 | | |
179 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | 90 | | |
104 | 91 | | |
105 | 92 | | |
| |||
314 | 301 | | |
315 | 302 | | |
316 | 303 | | |
317 | | - | |
| 304 | + | |
318 | 305 | | |
319 | 306 | | |
320 | 307 | | |
| |||
324 | 311 | | |
325 | 312 | | |
326 | 313 | | |
327 | | - | |
328 | | - | |
| 314 | + | |
329 | 315 | | |
330 | 316 | | |
331 | 317 | | |
| |||
337 | 323 | | |
338 | 324 | | |
339 | 325 | | |
340 | | - | |
341 | | - | |
342 | 326 | | |
343 | 327 | | |
344 | | - | |
| 328 | + | |
| 329 | + | |
345 | 330 | | |
346 | 331 | | |
347 | 332 | | |
| |||
385 | 370 | | |
386 | 371 | | |
387 | 372 | | |
388 | | - | |
| 373 | + | |
389 | 374 | | |
390 | 375 | | |
391 | 376 | | |
| |||
409 | 394 | | |
410 | 395 | | |
411 | 396 | | |
412 | | - | |
413 | | - | |
| 397 | + | |
414 | 398 | | |
415 | 399 | | |
416 | 400 | | |
| |||
429 | 413 | | |
430 | 414 | | |
431 | 415 | | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | 416 | | |
442 | | - | |
| 417 | + | |
443 | 418 | | |
444 | 419 | | |
445 | 420 | | |
| |||
452 | 427 | | |
453 | 428 | | |
454 | 429 | | |
455 | | - | |
| 430 | + | |
456 | 431 | | |
457 | 432 | | |
458 | 433 | | |
| |||
475 | 450 | | |
476 | 451 | | |
477 | 452 | | |
478 | | - | |
479 | | - | |
| 453 | + | |
480 | 454 | | |
481 | 455 | | |
482 | 456 | | |
483 | 457 | | |
484 | | - | |
| 458 | + | |
| 459 | + | |
485 | 460 | | |
486 | 461 | | |
487 | 462 | | |
| |||
1246 | 1221 | | |
1247 | 1222 | | |
1248 | 1223 | | |
1249 | | - | |
1250 | | - | |
1251 | 1224 | | |
1252 | 1225 | | |
1253 | 1226 | | |
| |||
1256 | 1229 | | |
1257 | 1230 | | |
1258 | 1231 | | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | 1232 | | |
1266 | 1233 | | |
1267 | 1234 | | |
1268 | | - | |
| 1235 | + | |
1269 | 1236 | | |
1270 | 1237 | | |
1271 | 1238 | | |
| |||
1284 | 1251 | | |
1285 | 1252 | | |
1286 | 1253 | | |
1287 | | - | |
1288 | 1254 | | |
1289 | 1255 | | |
1290 | 1256 | | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
| 1257 | + | |
1296 | 1258 | | |
0 commit comments