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