Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: pkg/compiler/lib/src/dart_backend/backend.dart

Issue 1397043002: Introduce BackendImpact to separate enqueueing from data. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart_backend; 5 part of dart_backend;
6 6
7 // TODO(ahe): This class is simply wrong. This backend should use 7 // TODO(ahe): This class is simply wrong. This backend should use
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, 8 // elements when it can, not AST nodes. Perhaps a [Map<Element,
9 // TreeElements>] is what is needed. 9 // TreeElements>] is what is needed.
10 class ElementAst { 10 class ElementAst {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 enqueuer.addToWorkList(getNameFunction); 256 enqueuer.addToWorkList(getNameFunction);
257 } 257 }
258 } 258 }
259 } 259 }
260 260
261 @override 261 @override
262 void registerInstantiatedType(InterfaceType type, 262 void registerInstantiatedType(InterfaceType type,
263 Enqueuer enqueuer, 263 Enqueuer enqueuer,
264 Registry registry, 264 Registry registry,
265 {bool mirrorUsage: false}) { 265 {bool mirrorUsage: false}) {
266 registerPlatformMembers(type,
267 registerGetter: registry.registerDynamicGetter,
268 registerSetter: registry.registerDynamicSetter,
269 registerInvocation: registry.registerDynamicInvocation);
270 super.registerInstantiatedType(
271 type, enqueuer, registry, mirrorUsage: mirrorUsage);
272 }
273
274 /// Register dynamic access of members of [type] that implement members
275 /// of types defined in the platform libraries.
276 void registerPlatformMembers(
277 InterfaceType type,
278 {void registerGetter(UniverseSelector selector),
279 void registerSetter(UniverseSelector selector),
280 void registerInvocation(UniverseSelector selector)}) {
281
266 // Without patching, dart2dart has no way of performing sound tree-shaking 282 // Without patching, dart2dart has no way of performing sound tree-shaking
267 // in face external functions. Therefore we employ another scheme: 283 // in face external functions. Therefore we employ another scheme:
268 // 284 //
269 // Based on the assumption that the platform code only relies on the 285 // Based on the assumption that the platform code only relies on the
270 // interfaces of it's own classes, we can approximate the semantics of 286 // interfaces of it's own classes, we can approximate the semantics of
271 // external functions by eagerly registering dynamic invocation of instance 287 // external functions by eagerly registering dynamic invocation of instance
272 // members defined the platform interfaces. 288 // members defined the platform interfaces.
273 // 289 //
274 // Since we only need to generate code for non-platform classes we can 290 // Since we only need to generate code for non-platform classes we can
275 // restrict this registration to platform interfaces implemented by 291 // restrict this registration to platform interfaces implemented by
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // Register selectors for all instance methods since these might 323 // Register selectors for all instance methods since these might
308 // be called on user classes from within the platform 324 // be called on user classes from within the platform
309 // implementation. 325 // implementation.
310 superclass.forEachLocalMember((MemberElement element) { 326 superclass.forEachLocalMember((MemberElement element) {
311 if (element.isConstructor || element.isStatic) return; 327 if (element.isConstructor || element.isStatic) return;
312 328
313 FunctionElement function = element.asFunctionElement(); 329 FunctionElement function = element.asFunctionElement();
314 element.computeType(resolution); 330 element.computeType(resolution);
315 Selector selector = new Selector.fromElement(element); 331 Selector selector = new Selector.fromElement(element);
316 if (selector.isGetter) { 332 if (selector.isGetter) {
317 registry.registerDynamicGetter( 333 registerGetter(
318 new UniverseSelector(selector, null)); 334 new UniverseSelector(selector, null));
319 } else if (selector.isSetter) { 335 } else if (selector.isSetter) {
320 registry.registerDynamicSetter( 336 registerSetter(
321 new UniverseSelector(selector, null)); 337 new UniverseSelector(selector, null));
322 } else { 338 } else {
323 registry.registerDynamicInvocation( 339 registerInvocation(
324 new UniverseSelector(selector, null)); 340 new UniverseSelector(selector, null));
325 } 341 }
326 }); 342 });
327 } 343 }
328 } 344 }
329 } 345 }
330 } 346 }
331 super.registerInstantiatedType(
332 type, enqueuer, registry, mirrorUsage: mirrorUsage);
333 } 347 }
334 348
335 @override 349 @override
336 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { 350 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) {
337 // TODO(sigurdm): Implement deferred loading for dart2dart. 351 // TODO(sigurdm): Implement deferred loading for dart2dart.
338 reporter.reportWarningMessage( 352 reporter.reportWarningMessage(
339 node, MessageKind.DEFERRED_LIBRARY_DART_2_DART); 353 node, MessageKind.DEFERRED_LIBRARY_DART_2_DART);
340 return false; 354 return false;
341 } 355 }
342 } 356 }
343 357
344 class DartResolutionCallbacks extends ResolutionCallbacks { 358 class DartResolutionCallbacks extends ResolutionCallbacks {
345 final DartBackend backend; 359 final DartBackend backend;
346 360
347 DartResolutionCallbacks(this.backend); 361 DartResolutionCallbacks(this.backend);
348 362
349 @override 363 @override
350 WorldImpact transformImpact(ResolutionWorldImpact worldImpact) { 364 WorldImpact transformImpact(ResolutionWorldImpact worldImpact) {
351 TransformedWorldImpact transformed = 365 TransformedWorldImpact transformed =
352 new TransformedWorldImpact(worldImpact); 366 new TransformedWorldImpact(worldImpact);
353 for (DartType typeLiteral in worldImpact.typeLiterals) { 367 for (DartType typeLiteral in worldImpact.typeLiterals) {
354 onTypeLiteral(typeLiteral, transformed); 368 if (typeLiteral.isInterfaceType) {
369 backend.usedTypeLiterals.add(typeLiteral.element);
370 }
355 } 371 }
356 for (InterfaceType instantiatedType in worldImpact.instantiatedTypes) { 372 for (InterfaceType instantiatedType in worldImpact.instantiatedTypes) {
357 // TODO(johnniwinther): Remove this when dependency tracking is done on 373 // TODO(johnniwinther): Remove this when dependency tracking is done on
358 // the world impact itself. 374 // the world impact itself.
359 transformed.registerInstantiation(instantiatedType); 375 transformed.registerInstantiatedType(instantiatedType);
360 backend.registerInstantiatedType( 376 backend.registerPlatformMembers(instantiatedType,
361 instantiatedType, backend.compiler.enqueuer.resolution, transformed); 377 registerGetter: transformed.registerDynamicGetter,
378 registerSetter: transformed.registerDynamicSetter,
379 registerInvocation: transformed.registerDynamicInvocation);
362 } 380 }
363 return transformed; 381 return transformed;
364 } 382 }
365
366 @override
367 void onTypeLiteral(DartType type, Registry registry) {
368 if (type.isInterfaceType) {
369 backend.usedTypeLiterals.add(type.element);
370 }
371 }
372 } 383 }
373 384
374 class EmitterUnparser extends Unparser { 385 class EmitterUnparser extends Unparser {
375 final Map<Node, String> renames; 386 final Map<Node, String> renames;
376 387
377 EmitterUnparser(this.renames, {bool minify, bool stripTypes}) 388 EmitterUnparser(this.renames, {bool minify, bool stripTypes})
378 : super(minify: minify, stripTypes: stripTypes); 389 : super(minify: minify, stripTypes: stripTypes);
379 390
380 visit(Node node) { 391 visit(Node node) {
381 if (node != null && renames.containsKey(node)) { 392 if (node != null && renames.containsKey(node)) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 556 }
546 557
547 // TODO(johnniwinther): Remove this when values are computed from the 558 // TODO(johnniwinther): Remove this when values are computed from the
548 // expressions. 559 // expressions.
549 @override 560 @override
550 void copyConstantValues(DartConstantTask task) { 561 void copyConstantValues(DartConstantTask task) {
551 constantCompiler.constantValueMap.addAll( 562 constantCompiler.constantValueMap.addAll(
552 task.constantCompiler.constantValueMap); 563 task.constantCompiler.constantValueMap);
553 } 564 }
554 } 565 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/inferrer/simple_types_inferrer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698