[dart2js] Fix bug in impact data serialization.

Change-Id: I1e4915624b609aafa9392fc651f5935bf658a71b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244184
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Auto-Submit: Joshua Litt <joshualitt@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Joshua Litt 2022-05-10 03:34:13 +00:00 committed by Commit Bot
parent f5f26c9c61
commit 2783cca57d
4 changed files with 59 additions and 0 deletions

View file

@ -1131,6 +1131,7 @@ class ImpactData {
source.readListOrNull(() => source.readIntegerValue())?.toSet();
_runtimeTypeUses =
source.readListOrNull(() => _RuntimeTypeUse.fromDataSource(source));
_forInData = source.readListOrNull(() => _ForInData.fromDataSource(source));
// TODO(johnniwinther): Remove these when CFE provides constants.
_constructorNodes =
@ -1216,6 +1217,8 @@ class ImpactData {
sink.writeList(_intLiterals, sink.writeIntegerValue, allowNull: true);
sink.writeList(_runtimeTypeUses, (_RuntimeTypeUse o) => o.toDataSink(sink),
allowNull: true);
sink.writeList(_forInData, (_ForInData o) => o.toDataSink(sink),
allowNull: true);
sink.writeMemberNodes(_constructorNodes, allowNull: true);
sink.writeMemberNodes(_fieldNodes, allowNull: true);
@ -2115,6 +2118,8 @@ class _RuntimeTypeUse {
}
class _ForInData {
static const String tag = '_ForInData';
final ir.DartType iterableType;
final ir.DartType iteratorType;
final ClassRelation iteratorClassRelation;
@ -2122,4 +2127,24 @@ class _ForInData {
_ForInData(this.iterableType, this.iteratorType, this.iteratorClassRelation,
{this.isAsync});
factory _ForInData.fromDataSource(DataSourceReader source) {
source.begin(tag);
ir.DartType iterableType = source.readDartTypeNode();
ir.DartType iteratorType = source.readDartTypeNode();
ClassRelation iteratorClassRelation = source.readEnum(ClassRelation.values);
bool isAsync = source.readBool();
source.end(tag);
return _ForInData(iterableType, iteratorType, iteratorClassRelation,
isAsync: isAsync);
}
void toDataSink(DataSinkWriter sink) {
sink.begin(tag);
sink.writeDartTypeNode(iteratorType);
sink.writeDartTypeNode(iteratorType);
sink.writeEnum(iteratorClassRelation);
sink.writeBool(isAsync);
sink.end(tag);
}
}

View file

@ -0,0 +1,16 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
int totalCases = 1;
int runCases() {
int cases = 0;
const foos = [1, 2, 3];
for (final foo in foos) {
if (cases == 0) cases++;
print(foo);
}
return cases;
}

View file

@ -0,0 +1,10 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
import 'def.dart';
main() {
Expect.equals(runCases(), totalCases);
}

View file

@ -0,0 +1,8 @@
# Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
#
# Regression test: integral numbers should be treated as int and not double
# after serialization across modules.
dependencies:
main: [def, expect]