Skip to content

Commit

Permalink
[cp] Cherry-pick 8ee2b8b to stable.
Browse files Browse the repository at this point in the history
This cherry-picks a fix for a dart2js crash onto the stable channel.

For more information see #52216

=== original commit message ===
[dart2js] Convert recordTypes after closureData

Bug #51899

Change-Id: Id9108e6cf13aee409b127fe6cd007bef8f0fe609
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298460
Reviewed-by: Sigmund Cherem <[email protected]>
Reviewed-by: Mayank Patke <[email protected]>
Commit-Queue: Stephen Adams <[email protected]>
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302801
Commit-Queue: Sigmund Cherem <[email protected]>
  • Loading branch information
sigmundch authored and Commit Queue committed May 12, 2023
1 parent 2f11564 commit 2794288
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pkg/compiler/lib/src/js_model/js_world_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,13 @@ class JClosedWorldBuilder {
ClosureData closureData;
RecordData recordData;

final recordTypes = Set<RecordType>.from(
map.toBackendTypeSet(closedWorld.instantiatedRecordTypes));

if (_options.disableRtiOptimization) {
rtiNeed = TrivialRuntimeTypesNeed(_elementMap.elementEnvironment);
closureData = _closureDataBuilder.createClosureEntities(
this,
map.toBackendMemberMap(closureModels, identity),
const TrivialClosureRtiNeed(),
callMethods);
recordData = _recordDataBuilder.createRecordData(this, recordTypes);
} else {
RuntimeTypesNeedImpl kernelRtiNeed =
closedWorld.rtiNeed as RuntimeTypesNeedImpl;
Expand Down Expand Up @@ -184,8 +180,6 @@ class JClosedWorldBuilder {
localFunctionsNodesNeedingSignature),
callMethods);

recordData = _recordDataBuilder.createRecordData(this, recordTypes);

List<FunctionEntity> callMethodsNeedingSignature = <FunctionEntity>[];
for (ir.LocalFunction node in localFunctionsNodesNeedingSignature) {
callMethodsNeedingSignature
Expand All @@ -204,7 +198,9 @@ class JClosedWorldBuilder {
}

(map as JsToFrontendMapImpl)._registerClosureData(closureData);
//(map as JsToFrontendMapImpl)._registerRecordData(recordData);
final recordTypes = Set<RecordType>.from(
map.toBackendTypeSet(closedWorld.instantiatedRecordTypes));
recordData = _recordDataBuilder.createRecordData(this, recordTypes);

BackendUsage backendUsage =
_convertBackendUsage(map, closedWorld.backendUsage as BackendUsageImpl);
Expand Down Expand Up @@ -584,7 +580,9 @@ class JsToFrontendMapImpl extends JsToFrontendMap {
if (typeVariable is KLocalTypeVariable) {
if (_closureData == null) {
failedAt(
typeVariable, "Local function type variables are not supported.");
typeVariable,
'ClosureData needs to be registered before converting type variable'
' $typeVariable');
}
ClosureRepresentationInfo info =
_closureData!.getClosureInfo(typeVariable.typeDeclaration.node);
Expand Down
15 changes: 15 additions & 0 deletions tests/web/regress/issue/51899_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

// This test uses a record with a static type dependent on a local function type
// variable.

import 'package:expect/expect.dart';

void main() {
Object? foo<T>(T value) => (0, value);
// ^ static type is (int, T)

Expect.isTrue(foo<Pattern>('hi') is (int, String));
}

0 comments on commit 2794288

Please sign in to comment.