public class MoveAnalysis extends Object implements wybs.lang.Build.Stage<WyilFile>
Responsible for determining when a value of a dynamically sized data type can be "moved" or must be "copied". Moving is preferable preferable (when permitted) because the original reference can be used without copying the underlying data. The following provides a useful example:
function g(int[] xs, int i) -> (int[] ys):
xs[j] = f(xs)
return xs
Here, in the invocation f(xs) the array xs cannot
be moved since it is live afterwards. Instead, we must clone xs
at this point. However, the subsequent use of xs in the
return statement does not require a clone and can be moved
(since xs is no longer live).
The following illustrates another situation where temporary moves or "borrows" are permitted:
function get(int[] xs, int i, int j) -> (int r):
int sum = xs[i]
sum = sum + xs[j]
return sum
Clearly, there is not need to clone xs when it is used in the
initialiser for sum. This is because the use is temporary and
does not modify xs. We say that xs is not
consumed.| Constructor and Description |
|---|
MoveAnalysis(wybs.lang.Build.Task builder) |
Copyright © 2017. All rights reserved.