Skip to content

Commit 315216e

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] Avoid collision with getInterceptor.
getInterceptor now always goes via HInterceptor, ensuring the back end knows to generate the unspecialized interceptor. We no longer generate the unspecialized interceptor as *shadowing* the js_runtime definition. In small programs where interceptors are not used except via js_runtime.getInterceptor, the program would fail on the value returned by the dummy body, since it was not shadowed. This gets rid of the two definitions of getInterceptor (issue 9180). Change-Id: Ibfa73f26d7d432273d5e755e2165ab6c2d48ad4f Reviewed-on: https://dart-review.googlesource.com/68002 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]>
1 parent f02d4d4 commit 315216e

File tree

8 files changed

+41
-38
lines changed

8 files changed

+41
-38
lines changed

pkg/compiler/lib/src/common_elements.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,6 @@ class CommonElements {
707707
member.library == interceptorsLibrary;
708708
}
709709

710-
FunctionEntity _getInterceptorMethod;
711-
FunctionEntity get getInterceptorMethod =>
712-
_getInterceptorMethod ??= _findInterceptorsFunction('getInterceptor');
713-
714710
FunctionEntity _getNativeInterceptorMethod;
715711
FunctionEntity get getNativeInterceptorMethod =>
716712
_getNativeInterceptorMethod ??=

pkg/compiler/lib/src/js_backend/backend.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,6 @@ class JavaScriptBackend {
843843
// [ElementEnvironment.getMemberMetadata] in [AnnotationProcessor].
844844
void processAnnotations(
845845
JClosedWorld closedWorld, InferredDataBuilder inferredDataBuilder) {
846-
// These methods are overwritten with generated versions.
847-
inlineCache.markAsNonInlinable(
848-
closedWorld.commonElements.getInterceptorMethod,
849-
insideLoop: true);
850846
for (MemberEntity entity in closedWorld.processedMembers) {
851847
_processMemberAnnotations(closedWorld, inferredDataBuilder, entity);
852848
}

pkg/compiler/lib/src/js_backend/minify_namer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class MinifyNamer extends Namer
166166
r'BoundClosure',
167167
r'Closure',
168168
r'StateError$',
169-
r'getInterceptor',
169+
r'getInterceptor$',
170170
r'max',
171171
r'$mul',
172172
r'Map',

pkg/compiler/lib/src/js_backend/namer.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,20 +1481,19 @@ class Namer {
14811481
return names.join();
14821482
}
14831483

1484-
/// Property name used for `getInterceptor` or one of its specializations.
1484+
/// Property name used for a specialization of `getInterceptor`.
1485+
///
1486+
/// js_runtime contains a top-level `getInterceptor` method. The
1487+
/// specializations have the same name, but with a suffix to avoid name
1488+
/// collisions.
14851489
jsAst.Name nameForGetInterceptor(Iterable<ClassEntity> classes) {
1486-
FunctionEntity getInterceptor = _commonElements.getInterceptorMethod;
1487-
if (classes.contains(_commonElements.jsInterceptorClass)) {
1488-
// If the base Interceptor class is in the set of intercepted classes, we
1489-
// need to go through the generic getInterceptorMethod, since any subclass
1490-
// of the base Interceptor could match.
1491-
// The unspecialized getInterceptor method can also be accessed through
1492-
// its element, so we treat this as a user-space global instead of an
1493-
// internal global.
1494-
return _disambiguateGlobalMember(getInterceptor);
1495-
}
1496-
String suffix = suffixForGetInterceptor(classes);
1497-
return _disambiguateInternalGlobal("${getInterceptor.name}\$$suffix");
1490+
// If the base Interceptor class is in the set of intercepted classes, we
1491+
// need to go through the generic getInterceptor method (any subclass of the
1492+
// base Interceptor could match), which is encoded as an empty suffix.
1493+
String suffix = classes.contains(_commonElements.jsInterceptorClass)
1494+
? ''
1495+
: suffixForGetInterceptor(classes);
1496+
return _disambiguateInternalGlobal('getInterceptor\$$suffix');
14981497
}
14991498

15001499
/// Property name used for the one-shot interceptor method for the given

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,6 +3596,8 @@ class KernelSsaGraphBuilder extends ir.Visitor
35963596
stack.add(graph.addConstantNull(closedWorld));
35973597
} else if (name == 'JS_INTERCEPTOR_CONSTANT') {
35983598
handleJsInterceptorConstant(invocation);
3599+
} else if (name == 'getInterceptor') {
3600+
handleForeignGetInterceptor(invocation);
35993601
} else if (name == 'JS_STRING_CONCAT') {
36003602
handleJsStringConcat(invocation);
36013603
} else if (name == '_createInvocationMirror') {
@@ -4024,6 +4026,25 @@ class KernelSsaGraphBuilder extends ir.Visitor
40244026
stack.add(graph.addConstantNull(closedWorld));
40254027
}
40264028

4029+
void handleForeignGetInterceptor(ir.StaticInvocation invocation) {
4030+
// Single argument is the intercepted object.
4031+
if (_unexpectedForeignArguments(invocation,
4032+
minPositional: 1, maxPositional: 1)) {
4033+
// Result expected on stack.
4034+
stack.add(graph.addConstantNull(closedWorld));
4035+
return;
4036+
}
4037+
ir.Expression argument = invocation.arguments.positional.single;
4038+
argument.accept(this);
4039+
HInstruction argumentInstruction = pop();
4040+
4041+
SourceInformation sourceInformation =
4042+
_sourceInformationBuilder.buildCall(invocation, invocation);
4043+
HInstruction instruction =
4044+
_interceptorFor(argumentInstruction, sourceInformation);
4045+
stack.add(instruction);
4046+
}
4047+
40274048
void handleForeignJs(ir.StaticInvocation invocation) {
40284049
if (_unexpectedForeignArguments(invocation,
40294050
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
@@ -211,6 +211,11 @@ external void JS_SET_STATIC_STATE(staticState);
211211
*/
212212
external JS_INTERCEPTOR_CONSTANT(Type type);
213213

214+
/// Returns the interceptor for [object].
215+
///
216+
/// Calls are replaced with the [HInterceptor] SSA instruction.
217+
external getInterceptor(object);
218+
214219
/**
215220
* Returns the object corresponding to Namer.staticStateHolder.
216221
*/

sdk/lib/_internal/js_runtime/lib/interceptors.dart

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import 'dart:_js_helper'
4545

4646
import 'dart:_foreign_helper'
4747
show
48+
getInterceptor,
4849
JS,
4950
JS_EFFECT,
5051
JS_EMBEDDED_GLOBAL,
@@ -70,22 +71,6 @@ _symbolMapToStringMap(Map<Symbol, dynamic> map) {
7071
return result;
7172
}
7273

73-
/**
74-
* Get the interceptor for [object]. Called by the compiler when it needs
75-
* to emit a call to an intercepted method, that is a method that is
76-
* defined in an interceptor class.
77-
*/
78-
@NoInline()
79-
getInterceptor(object) {
80-
// This is a magic method: the compiler does specialization of it
81-
// depending on the uses of intercepted methods and instantiated
82-
// primitive types.
83-
84-
// The [JS] call prevents the type analyzer from making assumptions about the
85-
// return type.
86-
return JS('', 'void 0');
87-
}
88-
8974
getDispatchProperty(object) {
9075
return JS(
9176
'', '#[#]', object, JS_EMBEDDED_GLOBAL('String', DISPATCH_PROPERTY_NAME));

sdk/lib/_internal/js_runtime/lib/js_helper.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import 'dart:async' show Completer, DeferredLoadException, Future;
3030
import 'dart:_foreign_helper'
3131
show
3232
DART_CLOSURE_TO_JS,
33+
getInterceptor,
3334
JS,
3435
JS_BUILTIN,
3536
JS_CONST,

0 commit comments

Comments
 (0)