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
swiftc -version
docker.io/swiftlang/swift:nightly-main-bionic
Swift version 5.4-dev (LLVM 7459512566cf7f4, Swift 8b5869ce6217b1f)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
Votes
0
Component/s
Labels
Bug
Assignee
None
Priority
Medium
md5: 24d6e67a34f3fdc16dabfde09f778d00
Issue Description:
Consider this code:
@inline(never)
func doIt() -> Int {
var sum = 0
for x in [(1, "hello"),
(2, "hello"),
(3, "hello"),
(4, "hello"),
(5, "hello"),
(6, "hello"),
] {
sum += x.0
}
return sum
}
print(doIt())
Clearly, this code just prints 21 (1 + 2 + 3 + 4 + 5 + 6). For correctness, it doesn't actually need to build the whole array.
The compiler agrees with me: The end of the doIt function in assembly is just
movl $21, %eax
addq $176, %rsp
popq %rbx
retq
which is cool. It literally puts a 21 into EAX. Good job.
Alas, it spits out a bunch more code that doesn't do anything:
So I think that the optimiser doesn't actually quite understand that taking out whole arrays is fine because creating and destroying an array doesn't do any side effects that anybody could legally observe in Swift.
Environment
Additional Detail from JIRA
md5: 24d6e67a34f3fdc16dabfde09f778d00
Issue Description:
Consider this code:
Clearly, this code just prints 21 (1 + 2 + 3 + 4 + 5 + 6). For correctness, it doesn't actually need to build the whole array.
The compiler agrees with me: The end of the
doIt
function in assembly is justwhich is cool. It literally puts a 21 into EAX. Good job.
Alas, it spits out a bunch more code that doesn't do anything:
So I think that the optimiser doesn't actually quite understand that taking out whole arrays is fine because creating and destroying an array doesn't do any side effects that anybody could legally observe in Swift.
Repro:
The text was updated successfully, but these errors were encountered: