Files
sdk/tests/dartdevc/js_interop_non_external_lib.dart
T
MarkZ f6028e821a Reland "[ddc] Overhauling DDC's generic class representation."
This is a reland of commit e7658520bb

Fixes in the reland + context:
Type parameters emitted in implicit type checks on covariant mixin forwarding stubs may reference type arguments in anonymous classes. We reduce this to their mixin's implementing subclass to avoid generating RTI rules for anonymous classes.

Previous implementations would 'translate' type parameters to that of their mixed in type, but that strategy fails if the implementing subtype  shuffles the order of type arguments relative to its mixed in type (demonstrated in the test - though not actually relevant in the Flutter break).

Original change's description:
> [ddc] Overhauling DDC's generic class representation.
>
> Prior to this change, DDC represented generic classes as closures over type parameters (with type arguments provided at runtime), which tightly coupled generic class definitions with their types and concrete instantiation.
>
> This rewrite decouples this representation, letting us 1) bind type information late and 2) separate generic class definitions from their instantiation.
>
> Notable changes:
> - Generic classes are now declared at top level (rather than within in closures).
> - RTIs are now passed to generic class constructors at runtime (except for JS Interop classes). Only the instantiated class's RTI is required (and it's retained up the type hierarchy).
> - Type signature resolvers are now lambdas that accept a type environment RTI at runtime. While signatures are still attached early, their instances' RTIs are now needed at runtime.
> - Generic classes, constructors, and factories are now evaluated in a 'Class' type environment.
> - An `RtiTypeEnvironment` is introduced to represent lookups on an RTI type environment bound to a parameter. These are used when evaluating type signatures and at constructor/factory bodies.
> - Type recipes now emit Class type parameters with names - but continue to emit method type parameters with de Bruijn indices. This is because indices aren't stable across subtypes.
> - Certain debugger functions now require instances (e.g.,`getClassMetadata`).
> - Adds a special flag for non-external JS interop factory constructors to emit 'true' types (versus 'any').
>
> Change-Id: I7cbeaaf666dd4f9bd5e3ef22a1163a659fc0ee48
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365863
> Reviewed-by: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Kallen Tu <kallentu@google.com>
> Reviewed-by: Nicholas Shahan <nshahan@google.com>
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Commit-Queue: Mark Zhou <markzipan@google.com>

Change-Id: I9b6f69b7150631f28442675c4230e093e3b821d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379511
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-08-13 18:15:38 +00:00

62 lines
1.5 KiB
Dart

// Copyright (c) 2022, 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.
// Define a JS class in a different library to test that name resolution works
// for non-external factories and static methods. Also uses class type
// parameters to make sure we generate a generic class.
@JS()
library js_interop_non_external_lib;
import 'package:expect/expect.dart';
import 'package:js/js.dart';
late List topLevelList;
void topLevelListAppend(item) {
topLevelList.add(item);
}
@JS('JSClass')
class OtherJSClass<T extends num> {
external OtherJSClass.cons(T t);
factory OtherJSClass(T t) {
// Do a simple test using T.
Expect.type<T>(t);
Expect.notType<T>('');
field = 'unnamed';
topLevelList = <T>[t];
return OtherJSClass.cons(t);
}
factory OtherJSClass.named(T t) {
// Do a simple test using T.
Expect.type<T>(t);
Expect.notType<T>('');
field = 'named';
topLevelList = <T>[t];
return OtherJSClass.cons(t);
}
factory OtherJSClass.redirecting(T t) = OtherJSClass;
static String field = '';
static String get getSet {
return field;
}
static set getSet(String val) {
field = val;
}
static String method() => field;
static T genericMethod<T extends num>(T t) {
// Do a simple test using T.
Expect.type<T>(t);
Expect.notType<T>('');
return t;
}
}