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 | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| (...skipping 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1950 const <DiagnosticMessage>[], | 1950 const <DiagnosticMessage>[], |
| 1951 api.Diagnostic.HINT); | 1951 api.Diagnostic.HINT); |
| 1952 }); | 1952 }); |
| 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 = | |
| 1961 <Element, ResolutionImpact>{}; | |
| 1960 final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{}; | 1962 final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{}; |
| 1961 | 1963 |
| 1962 _CompilerResolution(this.compiler); | 1964 _CompilerResolution(this.compiler); |
| 1963 | 1965 |
| 1964 @override | 1966 @override |
| 1965 DiagnosticReporter get reporter => compiler.reporter; | 1967 DiagnosticReporter get reporter => compiler.reporter; |
| 1966 | 1968 |
| 1967 @override | 1969 @override |
| 1968 Parsing get parsing => compiler.parsing; | 1970 Parsing get parsing => compiler.parsing; |
| 1969 | 1971 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1994 FunctionSignature resolveSignature(FunctionElement function) { | 1996 FunctionSignature resolveSignature(FunctionElement function) { |
| 1995 return compiler.resolver.resolveSignature(function); | 1997 return compiler.resolver.resolveSignature(function); |
| 1996 } | 1998 } |
| 1997 | 1999 |
| 1998 @override | 2000 @override |
| 1999 DartType resolveTypeAnnotation(Element element, TypeAnnotation node) { | 2001 DartType resolveTypeAnnotation(Element element, TypeAnnotation node) { |
| 2000 return compiler.resolver.resolveTypeAnnotation(element, node); | 2002 return compiler.resolver.resolveTypeAnnotation(element, node); |
| 2001 } | 2003 } |
| 2002 | 2004 |
| 2003 @override | 2005 @override |
| 2006 ResolutionImpact getResolutionImpact(Element element) { | |
| 2007 ResolutionImpact resolutionImpact = _resolutionImpactCache[element]; | |
| 2008 assert(invariant(element, resolutionImpact != null, | |
| 2009 message: "ResolutionImpact not available for $element.")); | |
| 2010 return resolutionImpact; | |
| 2011 } | |
| 2012 | |
| 2013 @override | |
| 2004 WorldImpact getWorldImpact(Element element) { | 2014 WorldImpact getWorldImpact(Element element) { |
| 2005 WorldImpact worldImpact = _worldImpactCache[element]; | 2015 WorldImpact worldImpact = _worldImpactCache[element]; |
| 2006 assert(invariant(element, worldImpact != null, | 2016 assert(invariant(element, worldImpact != null, |
| 2007 message: "WorldImpact not computed for $element.")); | 2017 message: "WorldImpact not computed for $element.")); |
| 2008 return worldImpact; | 2018 return worldImpact; |
| 2009 } | 2019 } |
| 2010 | 2020 |
| 2011 @override | 2021 @override |
| 2012 WorldImpact computeWorldImpact(Element element) { | 2022 WorldImpact computeWorldImpact(Element element) { |
| 2013 return _worldImpactCache.putIfAbsent(element, () { | 2023 return _worldImpactCache.putIfAbsent(element, () { |
| 2014 assert(compiler.parser != null); | 2024 assert(compiler.parser != null); |
| 2015 Node tree = compiler.parser.parse(element); | 2025 Node tree = compiler.parser.parse(element); |
| 2016 assert(invariant(element, !element.isSynthesized || tree == null)); | 2026 assert(invariant(element, !element.isSynthesized || tree == null)); |
| 2017 ResolutionImpact resolutionImpact = | 2027 ResolutionImpact resolutionImpact = |
| 2018 compiler.resolver.resolve(element); | 2028 compiler.resolver.resolve(element); |
| 2029 if (compiler.serialization.supportSerialization) { | |
|
Siggi Cherem (dart-lang)
2016/03/30 20:29:39
why do we only cache when serialization is enabled
Johnni Winther
2016/03/31 07:50:41
We always the the WorldImpact, which is the one us
| |
| 2030 _resolutionImpactCache[element] = resolutionImpact; | |
| 2031 } | |
| 2019 if (tree != null && !compiler.options.analyzeSignaturesOnly) { | 2032 if (tree != null && !compiler.options.analyzeSignaturesOnly) { |
| 2020 // TODO(het): don't do this if suppressWarnings is on, currently we have | 2033 // TODO(het): don't do this if suppressWarnings is on, currently we have |
| 2021 // to do it because the typechecker also sets types | 2034 // to do it because the typechecker also sets types |
| 2022 // Only analyze nodes with a corresponding [TreeElements]. | 2035 // Only analyze nodes with a corresponding [TreeElements]. |
| 2023 compiler.checker.check(element); | 2036 compiler.checker.check(element); |
| 2024 } | 2037 } |
| 2025 WorldImpact worldImpact = | 2038 WorldImpact worldImpact = |
| 2026 compiler.backend.impactTransformer.transformResolutionImpact( | 2039 compiler.backend.impactTransformer.transformResolutionImpact( |
| 2027 resolutionImpact); | 2040 resolutionImpact); |
| 2028 return worldImpact; | 2041 return worldImpact; |
| 2029 }); | 2042 }); |
| 2030 } | 2043 } |
| 2031 | 2044 |
| 2032 @override | 2045 @override |
| 2033 void uncacheWorldImpact(Element element) { | 2046 void uncacheWorldImpact(Element element) { |
| 2034 if (compiler.serialization.isDeserialized(element)) return; | 2047 if (compiler.serialization.isDeserialized(element)) return; |
| 2035 assert(invariant(element, _worldImpactCache[element] != null, | 2048 assert(invariant(element, _worldImpactCache[element] != null, |
| 2036 message: "WorldImpact not computed for $element.")); | 2049 message: "WorldImpact not computed for $element.")); |
| 2037 _worldImpactCache[element] = const WorldImpact(); | 2050 _worldImpactCache[element] = const WorldImpact(); |
| 2051 _resolutionImpactCache.remove(element); | |
| 2038 } | 2052 } |
| 2039 | 2053 |
| 2040 @override | 2054 @override |
| 2041 void emptyCache() { | 2055 void emptyCache() { |
| 2042 for (Element element in _worldImpactCache.keys) { | 2056 for (Element element in _worldImpactCache.keys) { |
| 2043 _worldImpactCache[element] = const WorldImpact(); | 2057 _worldImpactCache[element] = const WorldImpact(); |
| 2044 } | 2058 } |
| 2059 _resolutionImpactCache.clear(); | |
| 2045 } | 2060 } |
| 2046 | 2061 |
| 2047 @override | 2062 @override |
| 2048 bool hasBeenResolved(Element element) { | 2063 bool hasBeenResolved(Element element) { |
| 2049 return _worldImpactCache.containsKey(element); | 2064 return _worldImpactCache.containsKey(element); |
| 2050 } | 2065 } |
| 2051 | 2066 |
| 2052 @override | 2067 @override |
| 2053 ResolutionWorkItem createWorkItem( | 2068 ResolutionWorkItem createWorkItem( |
| 2054 Element element, ItemCompilationContext compilationContext) { | 2069 Element element, ItemCompilationContext compilationContext) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2137 _ElementScanner(this.scanner); | 2152 _ElementScanner(this.scanner); |
| 2138 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2153 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2139 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2154 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2140 } | 2155 } |
| 2141 | 2156 |
| 2142 class _EmptyEnvironment implements Environment { | 2157 class _EmptyEnvironment implements Environment { |
| 2143 const _EmptyEnvironment(); | 2158 const _EmptyEnvironment(); |
| 2144 | 2159 |
| 2145 String valueOf(String key) => null; | 2160 String valueOf(String key) => null; |
| 2146 } | 2161 } |
| OLD | NEW |