Skip to content

Commit 02fe07b

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] new-rti: Set Array instance type
TBR=fishythefish@google.com Change-Id: I6268ae5c67ef0e3632e6c46cc7f17a72b2ca4964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108020 Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Stephen Adams <sra@google.com>
1 parent bae5bde commit 02fe07b

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,10 +3059,15 @@ class KernelSsaGraphBuilder extends ir.Visitor {
30593059
return object;
30603060
}
30613061
if (options.experimentNewRti) {
3062-
// TODO(sra): For new-rti, construct Rti object. [type] could be `List<T>`
3063-
// or `JSArray<T>`.
3062+
// [type] could be `List<T>`, so ensure it is `JSArray<T>`.
3063+
InterfaceType arrayType =
3064+
InterfaceType(_commonElements.jsArrayClass, type.typeArguments);
3065+
HInstruction rti =
3066+
_typeBuilder.analyzeTypeArgumentNewRti(arrayType, sourceElement);
30643067

3065-
// For now, fall through.
3068+
// TODO(15489): Register at codegen.
3069+
registry?.registerInstantiation(type);
3070+
return _callSetRuntimeTypeInfo(rti, object, sourceInformation);
30663071
}
30673072
List<HInstruction> arguments = <HInstruction>[];
30683073
for (DartType argument in type.typeArguments) {
@@ -4046,6 +4051,8 @@ class KernelSsaGraphBuilder extends ir.Visitor {
40464051
_handleJsInterceptorConstant(invocation);
40474052
} else if (name == 'getInterceptor') {
40484053
_handleForeignGetInterceptor(invocation);
4054+
} else if (name == 'getJSArrayInteropRti') {
4055+
_handleForeignGetJSArrayInteropRti(invocation);
40494056
} else if (name == 'JS_STRING_CONCAT') {
40504057
_handleJsStringConcat(invocation);
40514058
} else if (name == '_createInvocationMirror') {
@@ -4608,6 +4615,24 @@ class KernelSsaGraphBuilder extends ir.Visitor {
46084615
stack.add(instruction);
46094616
}
46104617

4618+
void _handleForeignGetJSArrayInteropRti(ir.StaticInvocation invocation) {
4619+
if (_unexpectedForeignArguments(invocation,
4620+
minPositional: 0, maxPositional: 0) ||
4621+
!options.experimentNewRti) {
4622+
// Result expected on stack.
4623+
stack.add(graph.addConstantNull(closedWorld));
4624+
return;
4625+
}
4626+
// TODO(sra): Introduce 'any' type.
4627+
InterfaceType interopType =
4628+
InterfaceType(_commonElements.jsArrayClass, [DynamicType()]);
4629+
SourceInformation sourceInformation =
4630+
_sourceInformationBuilder.buildCall(invocation, invocation);
4631+
HInstruction rti = HLoadType(interopType, _abstractValueDomain.dynamicType)
4632+
..sourceInformation = sourceInformation;
4633+
push(rti);
4634+
}
4635+
46114636
void _handleForeignJs(ir.StaticInvocation invocation) {
46124637
if (_unexpectedForeignArguments(invocation,
46134638
minPositional: 2, maxPositional: null, typeArgumentCount: 1)) {

sdk/lib/_internal/js_runtime/lib/foreign_helper.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ external JS_INTERCEPTOR_CONSTANT(Type type);
207207
/// Calls are replaced with the [HInterceptor] SSA instruction.
208208
external getInterceptor(object);
209209

210+
/// Returns the Rti object for the type for JavaScript arrays via JS-interop.
211+
///
212+
/// Calls are replaced with a [HLoadType] SSA instruction.
213+
external Object getJSArrayInteropRti();
214+
210215
/// Returns the object corresponding to Namer.staticStateHolder.
211216
external JS_GET_STATIC_STATE();
212217

sdk/lib/_internal/js_runtime/lib/rti.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ library rti;
88
import 'dart:_foreign_helper'
99
show
1010
getInterceptor,
11+
getJSArrayInteropRti,
1112
JS,
1213
JS_BUILTIN,
1314
JS_EMBEDDED_GLOBAL,
@@ -271,8 +272,7 @@ Rti instanceType(object) {
271272
// FWIW, the legacy rti has this problem too. Perhaps JSArrays should use a
272273
// program-local `symbol` for the type field.
273274
if (rti != null) return _castToRti(rti);
274-
// TODO(sra): Use JS_GET_NAME to access the recipe.
275-
throw UnimplementedError('return JSArray<any>');
275+
return _castToRti(getJSArrayInteropRti());
276276
}
277277

278278
var interceptor = getInterceptor(object);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2019, 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+
// dart2jsOptions=--experiment-new-rti --no-minify
6+
7+
import "package:expect/expect.dart";
8+
import "dart:_foreign_helper" show JS;
9+
10+
main() {
11+
Expect.equals('JSArray<int>', <int>[].runtimeType.toString());
12+
13+
// TODO(35084): An 'any' type would make JS-interop easier to use.
14+
Expect.equals('JSArray<dynamic>', JS('', '[]').runtimeType.toString());
15+
}

0 commit comments

Comments
 (0)