Skip to content

Commit 65fbcc5

Browse files
committed
Swift: CFG test for for-try-await
1 parent abe3a81 commit 65fbcc5

File tree

2 files changed

+189
-33
lines changed

2 files changed

+189
-33
lines changed

swift/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 173 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,44 +1458,26 @@ cfg.swift:
14581458
# 141| case ...
14591459
#-----| -> =~ ...
14601460

1461-
# 141| $match
1462-
#-----| -> ... ~=(_:_:) ...
1463-
1464-
# 141| ... ~=(_:_:) ...
1465-
#-----| -> =~ ...
1466-
14671461
# 141| 0
1468-
#-----| -> $match
1462+
#-----| -> =~ ...
14691463

14701464
# 141| =~ ...
1471-
#-----| -> ~=(_:_:)
1465+
#-----| -> 0
14721466

14731467
# 141| =~ ...
14741468
#-----| no-match -> =~ ...
14751469
#-----| match -> true
14761470

1477-
# 141| ~=(_:_:)
1478-
#-----| -> 0
1479-
1480-
# 141| $match
1481-
#-----| -> ... ~=(_:_:) ...
1482-
1483-
# 141| ... ~=(_:_:) ...
1484-
#-----| -> =~ ...
1485-
14861471
# 141| 1
1487-
#-----| -> $match
1472+
#-----| -> =~ ...
14881473

14891474
# 141| =~ ...
1490-
#-----| -> ~=(_:_:)
1475+
#-----| -> 1
14911476

14921477
# 141| =~ ...
14931478
#-----| match -> true
14941479
#-----| no-match -> case ...
14951480

1496-
# 141| ~=(_:_:)
1497-
#-----| -> 1
1498-
14991481
# 142| return ...
15001482
#-----| return -> exit patterns(x:) (normal)
15011483

@@ -1505,24 +1487,15 @@ cfg.swift:
15051487
# 144| case ...
15061488
#-----| -> =~ ... where ...
15071489

1508-
# 144| $match
1509-
#-----| -> ... ~=(_:_:) ...
1510-
1511-
# 144| ... ~=(_:_:) ...
1512-
#-----| -> =~ ...
1513-
15141490
# 144| =~ ...
15151491
#-----| match, no-match -> ... .&&(_:_:) ...
15161492
#-----| no-match -> case ...
15171493

15181494
# 144| x
1519-
#-----| -> $match
1520-
1521-
# 144| ~=(_:_:)
1522-
#-----| -> x
1495+
#-----| -> =~ ...
15231496

15241497
# 144| =~ ... where ...
1525-
#-----| -> ~=(_:_:)
1498+
#-----| -> x
15261499

15271500
# 144| ... .&&(_:_:) ...
15281501

@@ -5992,3 +5965,170 @@ cfg.swift:
59925965

59935966
# 519| x
59945967
#-----| -> (Int) ...
5968+
5969+
# 522| enter testAsyncFor()
5970+
#-----| -> testAsyncFor()
5971+
5972+
# 522| exit testAsyncFor()
5973+
5974+
# 522| exit testAsyncFor() (normal)
5975+
#-----| -> exit testAsyncFor()
5976+
5977+
# 522| testAsyncFor()
5978+
#-----| -> stream
5979+
5980+
# 523| var ... = ...
5981+
#-----| -> stream
5982+
5983+
# 523| stream
5984+
#-----| match -> AsyncStream<Element>.init(_:bufferingPolicy:_:)
5985+
5986+
# 523| AsyncStream<Element>.init(_:bufferingPolicy:_:)
5987+
#-----| -> AsyncStream<Int>.Type
5988+
5989+
# 523| AsyncStream<Int>.Type
5990+
#-----| -> Int.Type
5991+
5992+
# 523| call to AsyncStream<Element>.init(_:bufferingPolicy:_:)
5993+
#-----| -> var ... = ...
5994+
5995+
# 523| Int.Type
5996+
#-----| -> .self
5997+
5998+
# 523| .self
5999+
#-----| -> .bufferingNewest
6000+
6001+
# 523| AsyncStream<Int>.Continuation.BufferingPolicy.Type
6002+
#-----| -> 5
6003+
6004+
# 523| .bufferingNewest
6005+
#-----| -> AsyncStream<Int>.Continuation.BufferingPolicy.Type
6006+
6007+
# 523| call to ...
6008+
#-----| -> { ... }
6009+
6010+
# 523| 5
6011+
#-----| -> call to ...
6012+
6013+
# 523| enter { ... }
6014+
#-----| -> { ... }
6015+
6016+
# 523| exit { ... }
6017+
6018+
# 523| exit { ... } (normal)
6019+
#-----| -> exit { ... }
6020+
6021+
# 523| { ... }
6022+
#-----| -> continuation
6023+
6024+
# 523| { ... }
6025+
#-----| -> call to AsyncStream<Element>.init(_:bufferingPolicy:_:)
6026+
6027+
# 524| continuation
6028+
#-----| -> .detached(priority:operation:)
6029+
6030+
# 525| Task<(), Never>.Type
6031+
#-----| -> default priority
6032+
6033+
# 525| return
6034+
#-----| return -> exit { ... } (normal)
6035+
6036+
# 525| .detached(priority:operation:)
6037+
#-----| -> Task<(), Never>.Type
6038+
6039+
# 525| call to detached(priority:operation:)
6040+
#-----| -> return
6041+
6042+
# 525| default priority
6043+
#-----| -> { ... }
6044+
6045+
# 525| enter { ... }
6046+
#-----| -> { ... }
6047+
6048+
# 525| exit { ... }
6049+
6050+
# 525| exit { ... } (normal)
6051+
#-----| -> exit { ... }
6052+
6053+
# 525| { ... }
6054+
#-----| -> ....(_:_:)
6055+
6056+
# 525| { ... }
6057+
#-----| -> call to detached(priority:operation:)
6058+
6059+
# 526| for ... in ... { ... }
6060+
#-----| non-empty -> i
6061+
#-----| empty -> .finish()
6062+
6063+
# 526| i
6064+
#-----| match -> .yield(_:)
6065+
6066+
# 526| 1
6067+
#-----| -> 100
6068+
6069+
# 526| ... ....(_:_:) ...
6070+
#-----| -> for ... in ... { ... }
6071+
6072+
# 526| ....(_:_:)
6073+
#-----| -> Int.Type
6074+
6075+
# 526| Int.Type
6076+
#-----| -> 1
6077+
6078+
# 526| 100
6079+
#-----| -> ... ....(_:_:) ...
6080+
6081+
# 527| continuation
6082+
#-----| -> i
6083+
6084+
# 527| .yield(_:)
6085+
#-----| -> continuation
6086+
6087+
# 527| call to yield(_:)
6088+
#-----| -> for ... in ... { ... }
6089+
6090+
# 527| i
6091+
#-----| -> call to yield(_:)
6092+
6093+
# 529| continuation
6094+
#-----| -> call to finish()
6095+
6096+
# 529| .finish()
6097+
#-----| -> continuation
6098+
6099+
# 529| call to finish()
6100+
#-----| -> exit { ... } (normal)
6101+
6102+
# 533| for ... in ... { ... }
6103+
#-----| empty -> exit testAsyncFor() (normal)
6104+
#-----| non-empty -> i
6105+
6106+
# 533| i
6107+
#-----| match -> print(_:separator:terminator:)
6108+
6109+
# 533| stream
6110+
#-----| -> for ... in ... { ... }
6111+
6112+
# 534| print(_:separator:terminator:)
6113+
#-----| -> i
6114+
6115+
# 534| call to print(_:separator:terminator:)
6116+
#-----| -> for ... in ... { ... }
6117+
6118+
# 534| default separator
6119+
#-----| -> default terminator
6120+
6121+
# 534| default terminator
6122+
#-----| -> call to print(_:separator:terminator:)
6123+
6124+
# 534| (Any) ...
6125+
#-----| -> [...]
6126+
6127+
# 534| [...]
6128+
#-----| -> [...]
6129+
6130+
# 534| [...]
6131+
#-----| -> default separator
6132+
6133+
# 534| i
6134+
#-----| -> (Any) ...

swift/ql/test/library-tests/controlflow/graph/cfg.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,19 @@ func testAvailable() -> Int {
518518

519519
return x
520520
}
521+
522+
func testAsyncFor () async {
523+
var stream = AsyncStream(Int.self, bufferingPolicy: .bufferingNewest(5), {
524+
continuation in
525+
Task.detached {
526+
for i in 1...100 {
527+
continuation.yield(i)
528+
}
529+
continuation.finish()
530+
}
531+
})
532+
533+
for try await i in stream {
534+
print(i)
535+
}
536+
}

0 commit comments

Comments
 (0)