-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Hi all,
Currently testing your building simulation example in a recent swift version:
swift --version
Swift version 6.2-dev (LLVM 9f6c3d784782c34, Swift 55189bae8e55169)
Target: x86_64-unknown-linux-gnuAnd it seems that the latest dev version of Swift doesnt like the blackHole concept:
swift build
Building for debugging...
/..../Sources/main.swift:205:5: error: main actor-isolated var 'blackHole' can not be mutated from a nonisolated context
200 | }
201 |
202 | var blackHole: Any?
| `- note: mutation of this var is only permitted within the actor
203 | @inline(never)
204 | func dontLetTheCompilerOptimizeThisAway<T>(_ x: T) {
| `- note: add '@MainActor' to make global function 'dontLetTheCompilerOptimizeThisAway' part of global actor 'MainActor'
205 | blackHole = x
| `- error: main actor-isolated var 'blackHole' can not be mutated from a nonisolated context
206 | }
207 |
Adding MainActor indeed fixes the issue:
var blackHole: Any?
@inline(never)
@MainActor
func dontLetTheCompilerOptimizeThisAway<T>(_ x: T) {
blackHole = x
}swift run
Building for debugging...
[1/1] Write swift-version--1BA0962812E73E12.txt
Build of product 'hello' complete! (0.11s)
trials: 100
timesteps: 20
average forward only time: 4.501960000000002e-06 seconds
average forward and back (gradient) time: 0.00023504620999999993 seconds
Metadata
Metadata
Assignees
Labels
No labels