A field/function annotated with this pragma must be guaranteed to not return `null` at runtime. Make use of this non-nullable annotation in the VM's type propagator. Annotates the "_TypedListView._typedData" field to ensure the VM knows it returns a non-nullable _TypedListView. Furthermore annotates methods on the integer implementation. Those particular methods are recognized methods with a "dynamic" return type. This caused the type propagator to use CompileType::Dynamic() as result type. Since a previous CL started to only utilize the annotated type if it is better than "dynamic" more integer operations got handled in-line, though with null-checks. Annotating those methods to return non-null improves the in-line handling of integer operations. This improves dart-aot On arm7hf: SHA256: +5%, SHA: +6%, JsonObjectRoundTrip: +7%, ... On arm8: SHA1: +28%, MD5: +25%, SHA256: +15%, TypedData.Int16ListViewBench: +18.5%, StringInterpolation: +18%, ... Issue https://github.com/dart-lang/sdk/issues/31954 Issue https://github.com/dart-lang/sdk/issues/35154 Change-Id: Ia4263a37241a36c9dc35e8a48893297effa6f4b2 Reviewed-on: https://dart-review.googlesource.com/c/84421 Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
2.5 KiB
@pragma annotations recognized by the compiler.
Annotations for return types and field types.
The VM is not able to see across method calls (apart from inlining) and therefore does not know anything about the return'ed values of calls, except for the interface type of the signature.
To improve this we have two types of additional information sources the VM utilizes to gain knowledge about return types:
-
inferred types (stored in kernel metadata): these are computed by global transformations (e.g. TFA) and are only available in AOT mode
-
@pragma annotations: these are recognized in JIT and AOT mode
This return type information is mainly used in the VM's type propagator.
Since those annotations side-step the normal type system, they are unsafe and we therefore restrict those annotations to only have an affect inside dart: libraries.
@pragma("vm:exact-result-type", ) annotation
Tells the VM about the exact result type (i.e. the exact class-id) of a function or a field load.
There are two limitations on this pragma:
-
The Dart object returned by the method at runtime must have exactly the type specified in the annotation (not a subtype).
-
The exact return type declared in the pragma must be a subtype of the interface type declared in the method signature. Note that this restriction is not enforced automatically by the compiler.
If those limitations are violated, undefined behavior may result.
Note that since null is an instance of the Null type, which is a subtype of any other, exactness of the annotated result type implies that the result must be non-null.
Syntax
class A {}
class B extends A {}
// Reference to type via type literal
@pragma("vm:exact-result-type", B)
A foo() native "foo_impl";
// Reference to type via path
@pragma("vm:exact-result-type", "dart:core#_Smi");
int foo() native "foo_impl";
class C {
// Reference to type via type literal
@pragma('vm:exact-result-type', B)
final B bValue;
// Reference to type via path
@pragma('vm:exact-result-type', "dart:core#_Smi")
final int intValue;
}
@pragma("vm:non-nullable-result-type") annotation
Tells the VM that the method/field cannot return null.
There is one limitation on this pragma:
- The Dart object returned by the method at runtime must not return
null.
If this limitation is violated, undefined behavior may result.
Syntax
@pragma("vm:non-nullable-result-type")
A foo() native "foo_impl";
class C {
@pragma('vm:non-nullable-result-type");
final int value;
}