Skip to content

Commit 6fe0633

Browse files
committed
Add @effects(releasenone) documentation.
1 parent 5ce5252 commit 6fe0633

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/HighLevelSILOptimizations.rst

+44
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,50 @@ readonly
341341
eliminated, but cannot be reordered or folded in a way that would
342342
move calls to the readnone function across side effects.
343343

344+
releasenone
345+
346+
function has side effects, it can read or write global state, or state
347+
reachable from its arguments. It can however be assumed that no externally
348+
visible release has happened (i.e it is allowed for a ``releasenone``
349+
function to allocate and destruct an object in its implementation as long as
350+
this is does not cause an release of an object visible outside of the
351+
implementation).
352+
353+
Examples
354+
::
355+
class SomeObject {
356+
final var x: Int = 3
357+
}
358+
var global = SomeObject()
359+
360+
class SomeOtherObject {
361+
var x: Int = 2
362+
deinit {
363+
global = SomeObject()
364+
}
365+
}
366+
367+
@effects(releasenone)
368+
func validReleaseNoneFunction(x: Int) -> Int {
369+
global.x = 5
370+
return x + 2
371+
}
372+
373+
@effects(releasenone)
374+
func validReleaseNoneFunction(x: Int) -> Int {
375+
var notExternallyVisibleObject = SomeObject()
376+
return x + notExternallyVisibleObject.x
377+
}
378+
379+
func notAReleaseNoneFunction(x: Int, y: SomeObject) -> Int {
380+
return x + y.x
381+
}
382+
383+
func notAReleaseNoneFunction(x: Int) -> Int {
384+
var releaseExternallyVisible = SomeOtherObject()
385+
return x + releaseExternallyVisible.x
386+
}
387+
344388
readwrite
345389

346390
function has side effects and the optimizer can't assume anything.

0 commit comments

Comments
 (0)