Skip to content

Commit

Permalink
[dart2js] Skip interop extension type object literal constructors dur…
Browse files Browse the repository at this point in the history
…ing 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 <srujzs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
  • Loading branch information
srujzs authored and Commit Queue committed Nov 1, 2024
1 parent c17dd35 commit 2973f37
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/compiler/lib/src/ssa/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,16 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
ir.Node target = definition.node;
if (target is ir.Procedure) {
if (target.isExternal) {
// Skip interop extension type object literal constructors as
// that's handled within `visitStaticInvocation`.
// TODO(54968): We should handle the lowering for object literal
// constructors in the interop transformer somehow instead and
// avoid assuming all such members are object literal constructors
// or otherwise paying the cost to verify by indexing extension
// types.
final isObjectLiteralConstructor = target.isExtensionTypeMember &&
target.function.namedParameters.isNotEmpty;
if (isObjectLiteralConstructor) return null;
_buildExternalFunctionNode(targetElement as FunctionEntity,
_ensureDefaultArgumentValues(target.function));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2024, 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 'dart:js_interop';

extension type ObjectLiteral._(JSObject _) implements JSObject {
external factory ObjectLiteral({int foo});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2024, 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 'def.dart';

void main() {
ObjectLiteral(foo: 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, 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 for https://github.com/dart-lang/sdk/issues/57008: Test that
# we skip generated procedures for object literal constructors when we serialize
# the codegen. All invocations of such procedures are transformed.
dependencies:
main: def

0 comments on commit 2973f37

Please sign in to comment.