Skip to content

Commit 2973f37

Browse files
srujzsCommit Queue
authored andcommitted
[dart2js] Skip interop extension type object literal constructors during serialization
Fixes #57008 dart2js was mistakenly assuming the generated procedures for these constructors are top-level external interop members and accidentally generating invalid code. We should skip serializing these procedures. This should be safe since any invocation of these procedures are transformed in visitStaticInvocation. Change-Id: If11c718bea8447b60de00b73f328a3cdd5544bda Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393001 Auto-Submit: Srujan Gaddam <[email protected]> Commit-Queue: Srujan Gaddam <[email protected]> Reviewed-by: Nate Biggs <[email protected]>
1 parent c17dd35 commit 2973f37

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

pkg/compiler/lib/src/ssa/builder.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,16 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
440440
ir.Node target = definition.node;
441441
if (target is ir.Procedure) {
442442
if (target.isExternal) {
443+
// Skip interop extension type object literal constructors as
444+
// that's handled within `visitStaticInvocation`.
445+
// TODO(54968): We should handle the lowering for object literal
446+
// constructors in the interop transformer somehow instead and
447+
// avoid assuming all such members are object literal constructors
448+
// or otherwise paying the cost to verify by indexing extension
449+
// types.
450+
final isObjectLiteralConstructor = target.isExtensionTypeMember &&
451+
target.function.namedParameters.isNotEmpty;
452+
if (isObjectLiteralConstructor) return null;
443453
_buildExternalFunctionNode(targetElement as FunctionEntity,
444454
_ensureDefaultArgumentValues(target.function));
445455
} else {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:js_interop';
6+
7+
extension type ObjectLiteral._(JSObject _) implements JSObject {
8+
external factory ObjectLiteral({int foo});
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'def.dart';
6+
7+
void main() {
8+
ObjectLiteral(foo: 0);
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
#
5+
# Regression test for https://github.com/dart-lang/sdk/issues/57008: Test that
6+
# we skip generated procedures for object literal constructors when we serialize
7+
# the codegen. All invocations of such procedures are transformed.
8+
dependencies:
9+
main: def

0 commit comments

Comments
 (0)