Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS interop object literal constructors with extension types fail to compile when serializing codegen with sharding enabled #57008

Closed
srujzs opened this issue Oct 31, 2024 · 0 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop

Comments

@srujzs
Copy link
Contributor

srujzs commented Oct 31, 2024

import 'dart:js_interop';

extension type ObjectLiteral._(JSObject _) implements JSObject {
  external factory ObjectLiteral({int foo});
}

void main() {
  ObjectLiteral(foo: 0);
}

This should emit code that looks like {foo: 0}. We should visit the StaticInvocation in dart2js, and emit an HForeignCode in SSA. This exists today:

bool isObjectLiteralConstructor = node is ir.Procedure &&
and works when run directly. However, as part of its sequential phases, dart2js may serialize the codegen it produced. The code that does this sees the generated procedure for the above factory and mistakenly assumes it's a top-level interop procedure because it's external. Therefore, it results in a JS fragment like #.ObjectLiteral|constructor#(#) because it directly uses the name, which is invalid JS code, and therefore results in a crash.

The solution is to just skip the generated procedure.

One thing that still isn't clear though is why we don't need to do this for all the other generated procedures for interop extension type members. I believe it's because we replace all the invocations of such procedures in js_util_optimizer.dart whereas we defer the lowering for object literal constructors until later in dart2js. This may allow dart2js to tree-shake away those procedures early since there is no code referring to them anymore. Experimentally, that looks to be the case.

cc @rakudrama @stereotype441 @natebiggs

@srujzs srujzs added web-js-interop Issues that impact all js interop area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Oct 31, 2024
@srujzs srujzs self-assigned this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

1 participant