Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 library dart2js.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'backend_strategy.dart'; | 10 import 'backend_strategy.dart'; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 /// Creates the resolver task. | 280 /// Creates the resolver task. |
| 281 /// | 281 /// |
| 282 /// Override this to mock the resolver for testing. | 282 /// Override this to mock the resolver for testing. |
| 283 ResolverTask createResolverTask() { | 283 ResolverTask createResolverTask() { |
| 284 return new ResolverTask(resolution, backend.constantCompilerTask, measurer); | 284 return new ResolverTask(resolution, backend.constantCompilerTask, measurer); |
| 285 } | 285 } |
| 286 | 286 |
| 287 ResolutionWorldBuilder get resolutionWorldBuilder => | 287 ResolutionWorldBuilder get resolutionWorldBuilder => |
| 288 enqueuer.resolution.worldBuilder; | 288 enqueuer.resolution.worldBuilder; |
| 289 CodegenWorldBuilder get codegenWorldBuilder { | 289 CodegenWorldBuilder get codegenWorldBuilder { |
| 290 assert(invariant(NO_LOCATION_SPANNABLE, _codegenWorldBuilder != null, | 290 assert( |
| 291 message: "CodegenWorldBuilder has not been created yet.")); | 291 _codegenWorldBuilder != null, |
| 292 failedAt(NO_LOCATION_SPANNABLE, | |
| 293 "CodegenWorldBuilder has not been created yet.")); | |
| 292 return _codegenWorldBuilder; | 294 return _codegenWorldBuilder; |
| 293 } | 295 } |
| 294 | 296 |
| 295 bool get analyzeAll => options.analyzeAll || compileAll; | 297 bool get analyzeAll => options.analyzeAll || compileAll; |
| 296 | 298 |
| 297 bool get compileAll => false; | 299 bool get compileAll => false; |
| 298 | 300 |
| 299 bool get disableTypeInference => | 301 bool get disableTypeInference => |
| 300 options.disableTypeInference || compilationFailed; | 302 options.disableTypeInference || compilationFailed; |
| 301 | 303 |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1371 _compiler.resolver.checkClass(element); | 1373 _compiler.resolver.checkClass(element); |
| 1372 } | 1374 } |
| 1373 } | 1375 } |
| 1374 | 1376 |
| 1375 @override | 1377 @override |
| 1376 void registerCompileTimeError(Element element, DiagnosticMessage message) => | 1378 void registerCompileTimeError(Element element, DiagnosticMessage message) => |
| 1377 _compiler.registerCompileTimeError(element, message); | 1379 _compiler.registerCompileTimeError(element, message); |
| 1378 | 1380 |
| 1379 @override | 1381 @override |
| 1380 bool hasResolvedAst(ExecutableElement element) { | 1382 bool hasResolvedAst(ExecutableElement element) { |
| 1381 assert(invariant(element, element.isDeclaration, | 1383 assert(element.isDeclaration, |
| 1382 message: "Element $element must be the declaration.")); | 1384 failedAt(element, "Element $element must be the declaration.")); |
| 1383 if (_compiler.serialization.isDeserialized(element)) { | 1385 if (_compiler.serialization.isDeserialized(element)) { |
| 1384 return _compiler.serialization.hasResolvedAst(element); | 1386 return _compiler.serialization.hasResolvedAst(element); |
| 1385 } | 1387 } |
| 1386 return hasBeenResolved(element.memberContext.declaration) && | 1388 return hasBeenResolved(element.memberContext.declaration) && |
| 1387 element.hasResolvedAst; | 1389 element.hasResolvedAst; |
| 1388 } | 1390 } |
| 1389 | 1391 |
| 1390 @override | 1392 @override |
| 1391 ResolvedAst getResolvedAst(ExecutableElement element) { | 1393 ResolvedAst getResolvedAst(ExecutableElement element) { |
| 1392 assert(invariant(element, element.isDeclaration, | 1394 assert(element.isDeclaration, |
| 1393 message: "Element $element must be the declaration.")); | 1395 failedAt(element, "Element $element must be the declaration.")); |
| 1394 assert(invariant(element, hasResolvedAst(element), | 1396 assert(hasResolvedAst(element), |
| 1395 message: "ResolvedAst not available for $element.")); | 1397 failedAt(element, "ResolvedAst not available for $element.")); |
| 1396 if (_compiler.serialization.isDeserialized(element)) { | 1398 if (_compiler.serialization.isDeserialized(element)) { |
| 1397 return _compiler.serialization.getResolvedAst(element); | 1399 return _compiler.serialization.getResolvedAst(element); |
| 1398 } | 1400 } |
| 1399 return element.resolvedAst; | 1401 return element.resolvedAst; |
| 1400 } | 1402 } |
| 1401 | 1403 |
| 1402 @override | 1404 @override |
| 1403 ResolvedAst computeResolvedAst(Element element) { | 1405 ResolvedAst computeResolvedAst(Element element) { |
| 1404 ensureResolved(element); | 1406 ensureResolved(element); |
| 1405 return getResolvedAst(element); | 1407 return getResolvedAst(element); |
| 1406 } | 1408 } |
| 1407 | 1409 |
| 1408 @override | 1410 @override |
| 1409 bool hasResolutionImpact(Element element) { | 1411 bool hasResolutionImpact(Element element) { |
| 1410 assert(invariant(element, element.isDeclaration, | 1412 assert(element.isDeclaration, |
| 1411 message: "Element $element must be the declaration.")); | 1413 failedAt(element, "Element $element must be the declaration.")); |
| 1412 if (_compiler.serialization.isDeserialized(element)) { | 1414 if (_compiler.serialization.isDeserialized(element)) { |
| 1413 return _compiler.serialization.hasResolutionImpact(element); | 1415 return _compiler.serialization.hasResolutionImpact(element); |
| 1414 } | 1416 } |
| 1415 return _resolutionImpactCache.containsKey(element); | 1417 return _resolutionImpactCache.containsKey(element); |
| 1416 } | 1418 } |
| 1417 | 1419 |
| 1418 @override | 1420 @override |
| 1419 ResolutionImpact getResolutionImpact(Element element) { | 1421 ResolutionImpact getResolutionImpact(Element element) { |
| 1420 assert(invariant(element, element.isDeclaration, | 1422 assert(element.isDeclaration, |
| 1421 message: "Element $element must be the declaration.")); | 1423 failedAt(element, "Element $element must be the declaration.")); |
| 1422 ResolutionImpact resolutionImpact; | 1424 ResolutionImpact resolutionImpact; |
| 1423 if (_compiler.serialization.isDeserialized(element)) { | 1425 if (_compiler.serialization.isDeserialized(element)) { |
| 1424 resolutionImpact = _compiler.serialization.getResolutionImpact(element); | 1426 resolutionImpact = _compiler.serialization.getResolutionImpact(element); |
| 1425 } else { | 1427 } else { |
| 1426 resolutionImpact = _resolutionImpactCache[element]; | 1428 resolutionImpact = _resolutionImpactCache[element]; |
| 1427 } | 1429 } |
| 1428 assert(invariant(element, resolutionImpact != null, | 1430 assert(resolutionImpact != null, |
| 1429 message: "ResolutionImpact not available for $element.")); | 1431 failedAt(element, "ResolutionImpact not available for $element.")); |
| 1430 return resolutionImpact; | 1432 return resolutionImpact; |
| 1431 } | 1433 } |
| 1432 | 1434 |
| 1433 @override | 1435 @override |
| 1434 WorldImpact getWorldImpact(Element element) { | 1436 WorldImpact getWorldImpact(Element element) { |
| 1435 assert(invariant(element, element.isDeclaration, | 1437 assert(element.isDeclaration, |
| 1436 message: "Element $element must be the declaration.")); | 1438 failedAt(element, "Element $element must be the declaration.")); |
| 1437 WorldImpact worldImpact = _worldImpactCache[element]; | 1439 WorldImpact worldImpact = _worldImpactCache[element]; |
| 1438 assert(invariant(element, worldImpact != null, | 1440 assert(worldImpact != null, |
| 1439 message: "WorldImpact not computed for $element.")); | 1441 failedAt(element, "WorldImpact not computed for $element.")); |
| 1440 return worldImpact; | 1442 return worldImpact; |
| 1441 } | 1443 } |
| 1442 | 1444 |
| 1443 @override | 1445 @override |
| 1444 WorldImpact computeWorldImpact(Element element) { | 1446 WorldImpact computeWorldImpact(Element element) { |
| 1445 return _compiler.selfTask.measureSubtask("Resolution.computeWorldImpact", | 1447 return _compiler.selfTask.measureSubtask("Resolution.computeWorldImpact", |
| 1446 () { | 1448 () { |
| 1447 assert(invariant( | 1449 assert( |
| 1448 element, | |
| 1449 element.impliesType || | 1450 element.impliesType || |
| 1450 element.isField || | 1451 element.isField || |
| 1451 element.isFunction || | 1452 element.isFunction || |
| 1452 element.isConstructor || | 1453 element.isConstructor || |
| 1453 element.isGetter || | 1454 element.isGetter || |
| 1454 element.isSetter, | 1455 element.isSetter, |
| 1455 message: 'Unexpected element kind: ${element.kind}')); | 1456 failedAt(element, 'Unexpected element kind: ${element.kind}')); |
| 1456 assert(invariant(element, element is AnalyzableElement, | 1457 // `true ==` prevents analyzer type inference from strengthening element |
| 1457 message: 'Element $element is not analyzable.')); | 1458 // to AnalyzableElement which incompatible with some down-cast to ElementX |
| 1458 assert(invariant(element, element.isDeclaration, | 1459 // uses. |
|
Johnni Winther
2017/05/24 08:24:52
Seems like we should file a bug for this.
sra1
2017/05/24 17:38:54
Done.
| |
| 1459 message: "Element $element must be the declaration.")); | 1460 assert(true == element is AnalyzableElement, |
| 1461 failedAt(element, 'Element $element is not analyzable.')); | |
| 1462 assert(element.isDeclaration, | |
| 1463 failedAt(element, "Element $element must be the declaration.")); | |
| 1460 return _worldImpactCache.putIfAbsent(element, () { | 1464 return _worldImpactCache.putIfAbsent(element, () { |
| 1461 assert(_compiler.parser != null); | 1465 assert(_compiler.parser != null); |
| 1462 Node tree = _compiler.parser.parse(element); | 1466 Node tree = _compiler.parser.parse(element); |
| 1463 assert(invariant(element, !element.isSynthesized || tree == null)); | 1467 assert(!element.isSynthesized || tree == null, failedAt(element)); |
| 1464 ResolutionImpact resolutionImpact = _compiler.resolver.resolve(element); | 1468 ResolutionImpact resolutionImpact = _compiler.resolver.resolve(element); |
| 1465 | 1469 |
| 1466 if (_compiler.serialization.supportSerialization || | 1470 if (_compiler.serialization.supportSerialization || |
| 1467 retainCachesForTesting) { | 1471 retainCachesForTesting) { |
| 1468 // [ResolutionImpact] is currently only used by serialization. The | 1472 // [ResolutionImpact] is currently only used by serialization. The |
| 1469 // enqueuer uses the [WorldImpact] which is always cached. | 1473 // enqueuer uses the [WorldImpact] which is always cached. |
| 1470 // TODO(johnniwinther): Align these use cases better; maybe only | 1474 // TODO(johnniwinther): Align these use cases better; maybe only |
| 1471 // cache [ResolutionImpact] and let the enqueuer transform it into | 1475 // cache [ResolutionImpact] and let the enqueuer transform it into |
| 1472 // a [WorldImpact]. | 1476 // a [WorldImpact]. |
| 1473 _resolutionImpactCache[element] = resolutionImpact; | 1477 _resolutionImpactCache[element] = resolutionImpact; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1487 WorldImpact transformResolutionImpact( | 1491 WorldImpact transformResolutionImpact( |
| 1488 Element element, ResolutionImpact resolutionImpact) { | 1492 Element element, ResolutionImpact resolutionImpact) { |
| 1489 WorldImpact worldImpact = _compiler.backend.impactTransformer | 1493 WorldImpact worldImpact = _compiler.backend.impactTransformer |
| 1490 .transformResolutionImpact(resolutionImpact); | 1494 .transformResolutionImpact(resolutionImpact); |
| 1491 _worldImpactCache[element] = worldImpact; | 1495 _worldImpactCache[element] = worldImpact; |
| 1492 return worldImpact; | 1496 return worldImpact; |
| 1493 } | 1497 } |
| 1494 | 1498 |
| 1495 @override | 1499 @override |
| 1496 void uncacheWorldImpact(Element element) { | 1500 void uncacheWorldImpact(Element element) { |
| 1497 assert(invariant(element, element.isDeclaration, | 1501 assert(element.isDeclaration, |
| 1498 message: "Element $element must be the declaration.")); | 1502 failedAt(element, "Element $element must be the declaration.")); |
| 1499 if (retainCachesForTesting) return; | 1503 if (retainCachesForTesting) return; |
| 1500 if (_compiler.serialization.isDeserialized(element)) return; | 1504 if (_compiler.serialization.isDeserialized(element)) return; |
| 1501 assert(invariant(element, _worldImpactCache[element] != null, | 1505 assert(_worldImpactCache[element] != null, |
| 1502 message: "WorldImpact not computed for $element.")); | 1506 failedAt(element, "WorldImpact not computed for $element.")); |
| 1503 _worldImpactCache[element] = const WorldImpact(); | 1507 _worldImpactCache[element] = const WorldImpact(); |
| 1504 _resolutionImpactCache.remove(element); | 1508 _resolutionImpactCache.remove(element); |
| 1505 } | 1509 } |
| 1506 | 1510 |
| 1507 @override | 1511 @override |
| 1508 void emptyCache() { | 1512 void emptyCache() { |
| 1509 if (retainCachesForTesting) return; | 1513 if (retainCachesForTesting) return; |
| 1510 for (Element element in _worldImpactCache.keys) { | 1514 for (Element element in _worldImpactCache.keys) { |
| 1511 _worldImpactCache[element] = const WorldImpact(); | 1515 _worldImpactCache[element] = const WorldImpact(); |
| 1512 } | 1516 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1575 _ElementScanner(this.scanner); | 1579 _ElementScanner(this.scanner); |
| 1576 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 1580 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 1577 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 1581 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 1578 } | 1582 } |
| 1579 | 1583 |
| 1580 class _EmptyEnvironment implements Environment { | 1584 class _EmptyEnvironment implements Environment { |
| 1581 const _EmptyEnvironment(); | 1585 const _EmptyEnvironment(); |
| 1582 | 1586 |
| 1583 String valueOf(String key) => null; | 1587 String valueOf(String key) => null; |
| 1584 } | 1588 } |
| OLD | NEW |