Skip to content

Commit

Permalink
[dart2js] Bailout tracing of record fields when record is bailed out
Browse files Browse the repository at this point in the history
Fixes: dart-lang#52968
Change-Id: Ie59d4c0f903089622bc260d471bc136fa91eacde
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315020
Reviewed-by: Sigmund Cherem <[email protected]>
Commit-Queue: Mayank Patke <[email protected]>
  • Loading branch information
fishythefish authored and Commit Queue committed Jul 19, 2023
1 parent 5494c1c commit b336f39
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pkg/compiler/lib/src/inferrer/node_tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,24 @@ abstract class TracerVisitor implements TypeInformationVisitor {

void analyzeStoredIntoRecord(RecordTypeInformation record) {
inferrer.analyzeRecordAndEnqueue(record);

record.flowsInto.forEach((TypeInformation flow) {
flow.users.forEach((TypeInformation user) {
if (user is RecordFieldAccessTypeInformation) {
final getterIndex =
record.recordShape.indexOfGetterName(user.getterName);
if (user.receiver == flow &&
getterIndex >= 0 &&
getterIndex < record.fieldTypes.length &&
record.fieldTypes[getterIndex] == currentUser) {
addNewEscapeInformation(user);
if (record.bailedOut) {
bailout('Stored in a record that bailed out');
} else {
record.flowsInto.forEach((TypeInformation flow) {
flow.users.forEach((TypeInformation user) {
if (user is RecordFieldAccessTypeInformation) {
final getterIndex =
record.recordShape.indexOfGetterName(user.getterName);
if (user.receiver == flow &&
getterIndex >= 0 &&
getterIndex < record.fieldTypes.length &&
record.fieldTypes[getterIndex] == currentUser) {
addNewEscapeInformation(user);
}
}
}
});
});
});
}
}

/// Checks whether this is a call to a list adding method. The definition of
Expand Down
26 changes: 26 additions & 0 deletions tests/web/regress/issue/52968_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, 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';

void main() {
final validator = createValidator([
(validate: isNotEmpty, message: 'Value is required'),
]);
Expect.isEmpty(validator('foo'));
Expect.isNotEmpty(validator(null));
}

typedef FieldValidator<T> = List<String> Function(T? value);
typedef Validator<T> = bool Function(T? value);
FieldValidator<T> createValidator<T>(
List<({Validator<T> validate, String message})> validators) =>
(T? value) {
return validators
.where((validator) => !validator.validate(value))
.map((validator) => validator.message)
.toList();
};

bool isNotEmpty(String? value) => value != null && value.isNotEmpty;

0 comments on commit b336f39

Please sign in to comment.