[record_use] Fix dart2js crash

If uses are not being recorded, don't perform any work in the compiler.

TEST=manually tested that the compiler doesn't crash anymore

If uses are being recorded, keep the source information. (This could
be costly for memory. We should consider introducing a more involved
`RecordUseSourceInformationStrategy`, but that will add complexity.)

TEST=pkg/compiler/test/record_use/record_use_test.dart

Closes: https://github.com/dart-lang/sdk/issues/63131

Change-Id: Ib93a8a85a9b4d7c64cae7e8ac306ff4df0145db8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493403
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
This commit is contained in:
Daco Harkes
2026-04-08 13:52:40 -07:00
committed by Commit Queue
parent 8b6c67a4ba
commit 295f0b1e23
3 changed files with 5 additions and 1 deletions
@@ -679,6 +679,7 @@ class AnnotationsDataImpl implements AnnotationsData {
@override
bool shouldRecordMethodUses(FunctionEntity member) {
if (!_options.writeRecordedUses) return false;
EnumSet<PragmaAnnotation>? annotations = memberPragmaAnnotations[member];
if (annotations != null) {
if (annotations.contains(PragmaAnnotation.recordUse)) {
@@ -690,6 +691,7 @@ class AnnotationsDataImpl implements AnnotationsData {
@override
bool shouldRecordConstInstances(ClassEntity clazz) {
if (!_options.writeRecordedUses) return false;
EnumSet<PragmaAnnotation>? set = classPragmaAnnotations[clazz];
return set != null && set.contains(PragmaAnnotation.recordUse);
}
@@ -108,7 +108,7 @@ class JsBackendStrategy {
JsBackendStrategy(this._compiler) {
bool generateSourceMap = _compiler.options.generateSourceMap;
if (!generateSourceMap) {
if (!generateSourceMap && !_compiler.options.writeRecordedUses) {
sourceInformationStrategy = const JavaScriptSourceInformationStrategy();
} else {
sourceInformationStrategy = OnlineKernelSourceInformationStrategy();
@@ -20,6 +20,8 @@ const List<String> compilerOptions = [
Flags.testMode,
Flags.disableInlining,
Flags.disableTypeInference,
// https://github.com/dart-lang/sdk/issues/63131
Flags.noSourceMaps,
];
/// Run `dart --define=updateExpectations=true pkg/compiler/test/record_use/record_use_test.dart`