| 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 | 1964 |
| 1964 _CompilerResolution(this.compiler); | 1965 _CompilerResolution(this.compiler); |
| 1965 | 1966 |
| 1966 @override | 1967 @override |
| 1967 DiagnosticReporter get reporter => compiler.reporter; | 1968 DiagnosticReporter get reporter => compiler.reporter; |
| 1968 | 1969 |
| 1969 @override | 1970 @override |
| 1970 Parsing get parsing => compiler.parsing; | 1971 Parsing get parsing => compiler.parsing; |
| 1971 | 1972 |
| 1972 @override | 1973 @override |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1996 FunctionSignature resolveSignature(FunctionElement function) { | 1997 FunctionSignature resolveSignature(FunctionElement function) { |
| 1997 return compiler.resolver.resolveSignature(function); | 1998 return compiler.resolver.resolveSignature(function); |
| 1998 } | 1999 } |
| 1999 | 2000 |
| 2000 @override | 2001 @override |
| 2001 DartType resolveTypeAnnotation(Element element, TypeAnnotation node) { | 2002 DartType resolveTypeAnnotation(Element element, TypeAnnotation node) { |
| 2002 return compiler.resolver.resolveTypeAnnotation(element, node); | 2003 return compiler.resolver.resolveTypeAnnotation(element, node); |
| 2003 } | 2004 } |
| 2004 | 2005 |
| 2005 @override | 2006 @override |
| 2007 bool hasResolutionImpact(Element element) { |
| 2008 return _resolutionImpactCache.containsKey(element); |
| 2009 } |
| 2010 |
| 2011 @override |
| 2006 ResolutionImpact getResolutionImpact(Element element) { | 2012 ResolutionImpact getResolutionImpact(Element element) { |
| 2007 ResolutionImpact resolutionImpact = _resolutionImpactCache[element]; | 2013 ResolutionImpact resolutionImpact = _resolutionImpactCache[element]; |
| 2008 assert(invariant(element, resolutionImpact != null, | 2014 assert(invariant(element, resolutionImpact != null, |
| 2009 message: "ResolutionImpact not available for $element.")); | 2015 message: "ResolutionImpact not available for $element.")); |
| 2010 return resolutionImpact; | 2016 return resolutionImpact; |
| 2011 } | 2017 } |
| 2012 | 2018 |
| 2013 @override | 2019 @override |
| 2014 WorldImpact getWorldImpact(Element element) { | 2020 WorldImpact getWorldImpact(Element element) { |
| 2015 WorldImpact worldImpact = _worldImpactCache[element]; | 2021 WorldImpact worldImpact = _worldImpactCache[element]; |
| 2016 assert(invariant(element, worldImpact != null, | 2022 assert(invariant(element, worldImpact != null, |
| 2017 message: "WorldImpact not computed for $element.")); | 2023 message: "WorldImpact not computed for $element.")); |
| 2018 return worldImpact; | 2024 return worldImpact; |
| 2019 } | 2025 } |
| 2020 | 2026 |
| 2021 @override | 2027 @override |
| 2022 WorldImpact computeWorldImpact(Element element) { | 2028 WorldImpact computeWorldImpact(Element element) { |
| 2023 return _worldImpactCache.putIfAbsent(element, () { | 2029 return _worldImpactCache.putIfAbsent(element, () { |
| 2024 assert(compiler.parser != null); | 2030 assert(compiler.parser != null); |
| 2025 Node tree = compiler.parser.parse(element); | 2031 Node tree = compiler.parser.parse(element); |
| 2026 assert(invariant(element, !element.isSynthesized || tree == null)); | 2032 assert(invariant(element, !element.isSynthesized || tree == null)); |
| 2027 ResolutionImpact resolutionImpact = | 2033 ResolutionImpact resolutionImpact = |
| 2028 compiler.resolver.resolve(element); | 2034 compiler.resolver.resolve(element); |
| 2029 if (compiler.serialization.supportSerialization) { | 2035 if (compiler.serialization.supportSerialization || retainCaches) { |
| 2030 // [ResolutionImpact] is currently only used by serialization. The | 2036 // [ResolutionImpact] is currently only used by serialization. The |
| 2031 // enqueuer uses the [WorldImpact] which is always cached. | 2037 // enqueuer uses the [WorldImpact] which is always cached. |
| 2032 // TODO(johnniwinther): Align these use cases better; maybe only | 2038 // TODO(johnniwinther): Align these use cases better; maybe only |
| 2033 // cache [ResolutionImpact] and let the enqueuer transform it into | 2039 // cache [ResolutionImpact] and let the enqueuer transform it into |
| 2034 // a [WorldImpact]. | 2040 // a [WorldImpact]. |
| 2035 _resolutionImpactCache[element] = resolutionImpact; | 2041 _resolutionImpactCache[element] = resolutionImpact; |
| 2036 } | 2042 } |
| 2037 if (tree != null && !compiler.options.analyzeSignaturesOnly) { | 2043 if (tree != null && !compiler.options.analyzeSignaturesOnly) { |
| 2038 // 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 |
| 2039 // to do it because the typechecker also sets types | 2045 // to do it because the typechecker also sets types |
| 2040 // Only analyze nodes with a corresponding [TreeElements]. | 2046 // Only analyze nodes with a corresponding [TreeElements]. |
| 2041 compiler.checker.check(element); | 2047 compiler.checker.check(element); |
| 2042 } | 2048 } |
| 2043 WorldImpact worldImpact = | 2049 WorldImpact worldImpact = |
| 2044 compiler.backend.impactTransformer.transformResolutionImpact( | 2050 compiler.backend.impactTransformer.transformResolutionImpact( |
| 2045 resolutionImpact); | 2051 resolutionImpact); |
| 2046 return worldImpact; | 2052 return worldImpact; |
| 2047 }); | 2053 }); |
| 2048 } | 2054 } |
| 2049 | 2055 |
| 2050 @override | 2056 @override |
| 2051 void uncacheWorldImpact(Element element) { | 2057 void uncacheWorldImpact(Element element) { |
| 2058 if (retainCaches) return; |
| 2052 if (compiler.serialization.isDeserialized(element)) return; | 2059 if (compiler.serialization.isDeserialized(element)) return; |
| 2053 assert(invariant(element, _worldImpactCache[element] != null, | 2060 assert(invariant(element, _worldImpactCache[element] != null, |
| 2054 message: "WorldImpact not computed for $element.")); | 2061 message: "WorldImpact not computed for $element.")); |
| 2055 _worldImpactCache[element] = const WorldImpact(); | 2062 _worldImpactCache[element] = const WorldImpact(); |
| 2056 _resolutionImpactCache.remove(element); | 2063 _resolutionImpactCache.remove(element); |
| 2057 } | 2064 } |
| 2058 | 2065 |
| 2059 @override | 2066 @override |
| 2060 void emptyCache() { | 2067 void emptyCache() { |
| 2068 if (retainCaches) return; |
| 2061 for (Element element in _worldImpactCache.keys) { | 2069 for (Element element in _worldImpactCache.keys) { |
| 2062 _worldImpactCache[element] = const WorldImpact(); | 2070 _worldImpactCache[element] = const WorldImpact(); |
| 2063 } | 2071 } |
| 2064 _resolutionImpactCache.clear(); | 2072 _resolutionImpactCache.clear(); |
| 2065 } | 2073 } |
| 2066 | 2074 |
| 2067 @override | 2075 @override |
| 2068 bool hasBeenResolved(Element element) { | 2076 bool hasBeenResolved(Element element) { |
| 2069 return _worldImpactCache.containsKey(element); | 2077 return _worldImpactCache.containsKey(element); |
| 2070 } | 2078 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2157 _ElementScanner(this.scanner); | 2165 _ElementScanner(this.scanner); |
| 2158 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2166 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2159 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2167 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2160 } | 2168 } |
| 2161 | 2169 |
| 2162 class _EmptyEnvironment implements Environment { | 2170 class _EmptyEnvironment implements Environment { |
| 2163 const _EmptyEnvironment(); | 2171 const _EmptyEnvironment(); |
| 2164 | 2172 |
| 2165 String valueOf(String key) => null; | 2173 String valueOf(String key) => null; |
| 2166 } | 2174 } |
| OLD | NEW |