Semantic
Type members
Classlikes
Utility definition used for better error-reporting of argument errors
Utility definition used for better error-reporting of argument errors
Cache used in fixed point computation
Cache used in fixed point computation
The analysis computes the least fixed point for the cache (see doc for
ExprValueCache
).
For the fixed point computation to terminate, we need to make sure that the domain of the cache, i.e. the key pair (Ref, Tree) is finite. As the code is finite, we only need to carefully design the abstract domain to be finitary.
We also need to make sure that the computing function (i.e. the abstract
interpreter) is monotone. Error handling breaks monotonicity of the
abstract interpreter, because when an error happens, we always return
the bottom value Hot
for an expression. It is not a threat for
termination because when an error happens, we stop the fixed point
computation at the end of the iteration where the error happens. Care
must be paid to tests of errors, monotonicity will be broken if we simply
ignore the test errors (See TryReporter
).
Note: It's tempting to use location of trees as key. That should be avoided as a template may have the same location as its single statement body. Macros may also create incorrect locations.
An object with unknown initialization status
An object with unknown initialization status
A function value
A function value
The abstract object which stores value about its fields and immediate outers.
The abstract object which stores value about its fields and immediate outers.
Semantically it suffices to store the outer for klass
. We cache other outers
for performance reasons.
Note: Object is NOT a value.
A value which represents a set of addresses
A value which represents a set of addresses
It comes from if
expressions.
A reference to the object under initialization pointed by this
A reference to the object under initialization pointed by this
A TryReporter cannot be simply thrown away
A TryReporter cannot be simply thrown away
Either abort
should be called or the errors be reported.
If errors are ignored and abort
is not called, the monotonicity of the
computation function is not guaranteed, thus termination of fixed-point
computation becomes a problem.
Abstract values
Abstract values
Value = Hot | Cold | Warm | ThisRef | Fun | RefSet
Cold
┌──────► ▲ ◄────┐ ◄────┐
│ │ │ │
│ │ │ │
| │ │ │
| │ │ │
ThisRef Warm Fun RefSet │ ▲ ▲ ▲ │ │ │ │ | │ │ │ ▲ │ │ │ │ │ │ │ └─────────┴───────┴───────┘ Hot
The diagram above does not reflect relationship between RefSet
and other values. RefSet
represents a set of values which could
be ThisRef
, Warm
or Fun
. The following ordering applies for
RefSet:
R_a ⊑ R_b if R_a ⊆ R_b
V ⊑ R if V ∈ R
An object with all fields initialized but reaches objects under initialization
An object with all fields initialized but reaches objects under initialization
We need to restrict nesting levels of outer
to finitize the domain.
Value members
Concrete methods
Handles the evaluation of different expressions
Handles the evaluation of different expressions
Note: Recursive call should go to eval
instead of cases
.
Check that path in path-dependent types are initialized
Check that path in path-dependent types are initialized
This is intended to avoid type soundness issues in Dotty.
Evaluate an expression with the given value for this
in a given class klass
Evaluate an expression with the given value for this
in a given class klass
Note that klass
might be a super class of the object referred by thisV
.
The parameter klass
is needed for this
resolution. Consider the following code:
class A { A.this class B extends A { A.this } }
As can be seen above, the meaning of the expression A.this
depends on where
it is located.
This method only handles cache logic and delegates the work to cases
.
The parameter cacheResult
is used to reduce the size of the cache.
Initialize part of an abstract object in klass
of the inheritance chain
Initialize part of an abstract object in klass
of the inheritance chain
Compute the outer value that correspond to tref.prefix
Compute the outer value that correspond to tref.prefix
Extensions
Extensions
Whether the object is fully assigned
Whether the object is fully assigned
It means all fields and outers are set. For performance, we don't check outers here, because Scala semantics ensure that they are always set before any user code in the constructor.
Note that isFullyFilled = true
does not mean we can use the
object freely, as its fields or outers may still reach uninitialized
objects.
Update field value of the abstract object
Update field value of the abstract object
Invariant: fields are immutable and only set once
Try early promotion of warm objects
Try early promotion of warm objects
Promotion is expensive and should only be performed for small classes.
-
for each concrete method
m
of the warm object: call the method and promote the result -
for each concrete field
f
of the warm object: promote the field value
If the object contains nested classes as members, the checker simply reports a warning to avoid expensive checks.