The various Dart compilers and compilation modes have different optimizations. This can lead to differences in the recorded API usage between compilers.
The following compiler optimizations can influence the recorded API usage:
dart compile exe might tree-shake a call, while dart2js might not.late variable initialization.package:record_useThe package:record_use library records API usage by analyzing the compiled output of a program. This means that the recorded API usage can vary depending on the compiler and compilation mode that is used. To ensure more accurate and consistent recording, consider the following recommendations:
@mustBeConst annotation: When designing APIs that are intended for analysis by package:record_use, consider using the @mustBeConst annotation on parameters. This annotation forces call sites to provide obviously constant arguments, which compilers are more likely to treat consistently across different optimization levels.package:record_use reports, consider adding a warning mechanism within the tool's analysis (e.g., in a “link hook”). This warning would trigger if any API calls are found with non-constant arguments, dynamic calls, or tear-offs. These constructs can lead to inconsistent reporting across compilers due to varying optimization strategies.