From 2794288cf8f28968eeca4158d40cfc3453483729 Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Fri, 12 May 2023 15:52:10 +0000 Subject: [PATCH] [cp] Cherry-pick 8ee2b8b36b2dc872bb64abbd7887b9cbcaf3cb6f to stable. This cherry-picks a fix for a dart2js crash onto the stable channel. For more information see https://github.com/dart-lang/sdk/issues/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 Reviewed-by: Mayank Patke Commit-Queue: Stephen Adams Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302801 Commit-Queue: Sigmund Cherem --- .../lib/src/js_model/js_world_builder.dart | 14 ++++++-------- tests/web/regress/issue/51899_test.dart | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 tests/web/regress/issue/51899_test.dart diff --git a/pkg/compiler/lib/src/js_model/js_world_builder.dart b/pkg/compiler/lib/src/js_model/js_world_builder.dart index 4034ea6f5e75..21bea521e11b 100644 --- a/pkg/compiler/lib/src/js_model/js_world_builder.dart +++ b/pkg/compiler/lib/src/js_model/js_world_builder.dart @@ -146,9 +146,6 @@ class JClosedWorldBuilder { ClosureData closureData; RecordData recordData; - final recordTypes = Set.from( - map.toBackendTypeSet(closedWorld.instantiatedRecordTypes)); - if (_options.disableRtiOptimization) { rtiNeed = TrivialRuntimeTypesNeed(_elementMap.elementEnvironment); closureData = _closureDataBuilder.createClosureEntities( @@ -156,7 +153,6 @@ class JClosedWorldBuilder { map.toBackendMemberMap(closureModels, identity), const TrivialClosureRtiNeed(), callMethods); - recordData = _recordDataBuilder.createRecordData(this, recordTypes); } else { RuntimeTypesNeedImpl kernelRtiNeed = closedWorld.rtiNeed as RuntimeTypesNeedImpl; @@ -184,8 +180,6 @@ class JClosedWorldBuilder { localFunctionsNodesNeedingSignature), callMethods); - recordData = _recordDataBuilder.createRecordData(this, recordTypes); - List callMethodsNeedingSignature = []; for (ir.LocalFunction node in localFunctionsNodesNeedingSignature) { callMethodsNeedingSignature @@ -204,7 +198,9 @@ class JClosedWorldBuilder { } (map as JsToFrontendMapImpl)._registerClosureData(closureData); - //(map as JsToFrontendMapImpl)._registerRecordData(recordData); + final recordTypes = Set.from( + map.toBackendTypeSet(closedWorld.instantiatedRecordTypes)); + recordData = _recordDataBuilder.createRecordData(this, recordTypes); BackendUsage backendUsage = _convertBackendUsage(map, closedWorld.backendUsage as BackendUsageImpl); @@ -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); diff --git a/tests/web/regress/issue/51899_test.dart b/tests/web/regress/issue/51899_test.dart new file mode 100644 index 000000000000..1be389685d27 --- /dev/null +++ b/tests/web/regress/issue/51899_test.dart @@ -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 value) => (0, value); + // ^ static type is (int, T) + + Expect.isTrue(foo('hi') is (int, String)); +}