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
Strengthen language around @assume_effects :consistent (#58254)
The current language of `:consistent` for assume_effects is problematic,
because it explicitly promises something false: That you're allowed to
mark a method as `:consistent` even in the face of redefinitions.
To understand this problem a bit better, we need to think about the
primary use case of the `:consistent` annotation: To perform constant
propagation evaluation of fuctions with constant arguments. However,
since constant evaluation only runs in a single world (unlike the
abstract interpreter, which symbolically runs in multiple worlds and
keeps track of which world range its result is valid for), we run into a
bit of a problem. In principle, for full correctness and under the
current definition of consistentcy, we can only claim that we know the
result for a single world age (the one that we ran in). This is
problematic, because it would force us to re-infer the function for
every new world age.
In practice however, ignoring `@assume_effects` for the moment, we have
a stronger guarantee. When inference sets the :consistent effect bit, it
guarantees consistentcy across the entire computed min_world:max_world
range. If there is a redefinition, the world range will be terminated,
even if it is `:consistent` both before and after and even if the
redefinition would not otherwise affect inference's computed
information. This is useful, because it lets us conclude that the
information derived from concrete evluation is valid for the entire
min_world:max_world range of the corresponding code instance.
Coming back to `@assume_effects` we run into a problem however, because
we have no way to provide the required edges to inference. In practice
inference will probably be able to figure it out, but this is
insufficient as a semantic guarantee. After some discussion within the
compiler team, we came to the conclusion that the best resolution was to
change the documented semantics of `@assume_effects :consistent` to
require consistent-cy across the entire defined world range of the
method, not just world-age-by-world-age. This is a significantly
stronger guarantee, but appears necessary for semantic correctness. In
the future we may want to consider `:consistent` annotations for
particular if blocks, which would not require the same restrictions
(because it would still rely on inference to add appropriate edges for
redefinitions).
Closes#46156
0 commit comments