| 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 | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| (...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 } | 1953 } |
| 1954 } | 1954 } |
| 1955 } | 1955 } |
| 1956 | 1956 |
| 1957 // TODO(johnniwinther): Move [ResolverTask] here. | 1957 // TODO(johnniwinther): Move [ResolverTask] here. |
| 1958 class _CompilerResolution implements Resolution { | 1958 class _CompilerResolution implements Resolution { |
| 1959 final Compiler compiler; | 1959 final Compiler compiler; |
| 1960 final Map<Element, ResolutionImpact> _resolutionImpactCache = | 1960 final Map<Element, ResolutionImpact> _resolutionImpactCache = |
| 1961 <Element, ResolutionImpact>{}; | 1961 <Element, ResolutionImpact>{}; |
| 1962 final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{}; | 1962 final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{}; |
| 1963 bool retainCaches = false; | 1963 bool retainCachesForTesting = false; |
| 1964 | 1964 |
| 1965 _CompilerResolution(this.compiler); | 1965 _CompilerResolution(this.compiler); |
| 1966 | 1966 |
| 1967 @override | 1967 @override |
| 1968 DiagnosticReporter get reporter => compiler.reporter; | 1968 DiagnosticReporter get reporter => compiler.reporter; |
| 1969 | 1969 |
| 1970 @override | 1970 @override |
| 1971 Parsing get parsing => compiler.parsing; | 1971 Parsing get parsing => compiler.parsing; |
| 1972 | 1972 |
| 1973 @override | 1973 @override |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 } | 2025 } |
| 2026 | 2026 |
| 2027 @override | 2027 @override |
| 2028 WorldImpact computeWorldImpact(Element element) { | 2028 WorldImpact computeWorldImpact(Element element) { |
| 2029 return _worldImpactCache.putIfAbsent(element, () { | 2029 return _worldImpactCache.putIfAbsent(element, () { |
| 2030 assert(compiler.parser != null); | 2030 assert(compiler.parser != null); |
| 2031 Node tree = compiler.parser.parse(element); | 2031 Node tree = compiler.parser.parse(element); |
| 2032 assert(invariant(element, !element.isSynthesized || tree == null)); | 2032 assert(invariant(element, !element.isSynthesized || tree == null)); |
| 2033 ResolutionImpact resolutionImpact = | 2033 ResolutionImpact resolutionImpact = |
| 2034 compiler.resolver.resolve(element); | 2034 compiler.resolver.resolve(element); |
| 2035 if (compiler.serialization.supportSerialization || retainCaches) { | 2035 if (compiler.serialization.supportSerialization || retainCachesForTesting)
{ |
| 2036 // [ResolutionImpact] is currently only used by serialization. The | 2036 // [ResolutionImpact] is currently only used by serialization. The |
| 2037 // enqueuer uses the [WorldImpact] which is always cached. | 2037 // enqueuer uses the [WorldImpact] which is always cached. |
| 2038 // TODO(johnniwinther): Align these use cases better; maybe only | 2038 // TODO(johnniwinther): Align these use cases better; maybe only |
| 2039 // cache [ResolutionImpact] and let the enqueuer transform it into | 2039 // cache [ResolutionImpact] and let the enqueuer transform it into |
| 2040 // a [WorldImpact]. | 2040 // a [WorldImpact]. |
| 2041 _resolutionImpactCache[element] = resolutionImpact; | 2041 _resolutionImpactCache[element] = resolutionImpact; |
| 2042 } | 2042 } |
| 2043 if (tree != null && !compiler.options.analyzeSignaturesOnly) { | 2043 if (tree != null && !compiler.options.analyzeSignaturesOnly) { |
| 2044 // TODO(het): don't do this if suppressWarnings is on, currently we have | 2044 // TODO(het): don't do this if suppressWarnings is on, currently we have |
| 2045 // to do it because the typechecker also sets types | 2045 // to do it because the typechecker also sets types |
| 2046 // Only analyze nodes with a corresponding [TreeElements]. | 2046 // Only analyze nodes with a corresponding [TreeElements]. |
| 2047 compiler.checker.check(element); | 2047 compiler.checker.check(element); |
| 2048 } | 2048 } |
| 2049 WorldImpact worldImpact = | 2049 WorldImpact worldImpact = |
| 2050 compiler.backend.impactTransformer.transformResolutionImpact( | 2050 compiler.backend.impactTransformer.transformResolutionImpact( |
| 2051 resolutionImpact); | 2051 resolutionImpact); |
| 2052 return worldImpact; | 2052 return worldImpact; |
| 2053 }); | 2053 }); |
| 2054 } | 2054 } |
| 2055 | 2055 |
| 2056 @override | 2056 @override |
| 2057 void uncacheWorldImpact(Element element) { | 2057 void uncacheWorldImpact(Element element) { |
| 2058 if (retainCaches) return; | 2058 if (retainCachesForTesting) return; |
| 2059 if (compiler.serialization.isDeserialized(element)) return; | 2059 if (compiler.serialization.isDeserialized(element)) return; |
| 2060 assert(invariant(element, _worldImpactCache[element] != null, | 2060 assert(invariant(element, _worldImpactCache[element] != null, |
| 2061 message: "WorldImpact not computed for $element.")); | 2061 message: "WorldImpact not computed for $element.")); |
| 2062 _worldImpactCache[element] = const WorldImpact(); | 2062 _worldImpactCache[element] = const WorldImpact(); |
| 2063 _resolutionImpactCache.remove(element); | 2063 _resolutionImpactCache.remove(element); |
| 2064 } | 2064 } |
| 2065 | 2065 |
| 2066 @override | 2066 @override |
| 2067 void emptyCache() { | 2067 void emptyCache() { |
| 2068 if (retainCaches) return; | 2068 if (retainCachesForTesting) return; |
| 2069 for (Element element in _worldImpactCache.keys) { | 2069 for (Element element in _worldImpactCache.keys) { |
| 2070 _worldImpactCache[element] = const WorldImpact(); | 2070 _worldImpactCache[element] = const WorldImpact(); |
| 2071 } | 2071 } |
| 2072 _resolutionImpactCache.clear(); | 2072 _resolutionImpactCache.clear(); |
| 2073 } | 2073 } |
| 2074 | 2074 |
| 2075 @override | 2075 @override |
| 2076 bool hasBeenResolved(Element element) { | 2076 bool hasBeenResolved(Element element) { |
| 2077 return _worldImpactCache.containsKey(element); | 2077 return _worldImpactCache.containsKey(element); |
| 2078 } | 2078 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2165 _ElementScanner(this.scanner); | 2165 _ElementScanner(this.scanner); |
| 2166 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2166 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2167 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2167 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2168 } | 2168 } |
| 2169 | 2169 |
| 2170 class _EmptyEnvironment implements Environment { | 2170 class _EmptyEnvironment implements Environment { |
| 2171 const _EmptyEnvironment(); | 2171 const _EmptyEnvironment(); |
| 2172 | 2172 |
| 2173 String valueOf(String key) => null; | 2173 String valueOf(String key) => null; |
| 2174 } | 2174 } |
| OLD | NEW |