Stop recording annotations (in the VM and dart2wasm). The visitor will stop visiting as soon as it is in an expression that is in the annotations list. The tests have been migrated so that their constants occur in the executable code instead of annotations. One test has been kept to see that the annotations no longer are recorded: TEST=pkg/vm/testcases/transformations/record_use/instance_method.dart A new test has been added to ensure we're also recording constants nested inside other constants. TEST=pkg/vm/testcases/transformations/record_use/nested_instance_constant.dart Closes: https://github.com/dart-lang/native/issues/2977 Change-Id: I5d814c8500b510628025ab2daeb115e782dd423a Cq-Include-Trybots: luci.dart.try:dart2wasm-asserts-linux-chrome-try,dart2wasm-asserts-minified-linux-d8-try,dart2wasm-linux-chrome-try,dart2wasm-linux-d8-try,dart2wasm-linux-firefox-try,dart2wasm-linux-jscm-chrome-try,dart2wasm-linux-optimized-jsc-try,pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try,dart2js-canary-linux-try,dart2js-hostasserts-linux-d8-try,dart2js-linux-chrome-try,dart2js-linux-firefox-try,dart2js-mac-chrome-try,dart2js-mac-safari-try,dart2js-minified-csp-linux-chrome-try,dart2js-minified-linux-d8-try,dart2js-unit-linux-x64-release-try,dart2js-win-chrome-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478440 Commit-Queue: Johnni Winther <johnniwinther@google.com> Auto-Submit: Daco Harkes <dacoharkes@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
1.5 KiB
Recorded Uses
Tree-shaking can cause APIs and resources to be removed from programs. We developed a mechanism in dart2js to help developers understand what resources are still in use after an application is optimized.
Status
(experimental, in progress)
Currently we have a mechanism that only supports tracking static member
functions. It is not rich enough to track the use of resource classes or
constants, like IconData in flutter applications. That would be an ideal
expansion in the future.
How it works
Developers can annotate top-level functions or methods with RecordUse from
package:record_use. This annotation signals to dart2js that the annotated
member is a resource that needs to be tracked.
Example:
import 'package:record_use/record_use.dart';
@RecordUse()
void myTopLevelMethod() {
// ... resource usage ...
}
When providing dart2js with the experimental --write-resources flag, the
compiler will emit a .resources.json file. This file lists whether any
top-level methods annotated with the special pragma was invoked in the program.
It will also include some additional static information, like the source
location of the call, or even which parameters where provided (if the parameters
are constant).
Only calls in reachable code (executable code) are tracked. Calls appearing within metadata (annotations) are ignored.
Example output
Example outputs can be found in pkg/vm/testcases/transformations/record_use/, and can be read with
package:record_use.