Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1133513003: Cache flushing implementation for the task model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.src.context.context; 5 library analyzer.src.context.context;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/cancelable_future.dart'; 10 import 'package:analyzer/src/cancelable_future.dart';
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 /** 175 /**
176 * A factory to override how [LibraryResolver] is created. 176 * A factory to override how [LibraryResolver] is created.
177 */ 177 */
178 LibraryResolverFactory libraryResolverFactory; 178 LibraryResolverFactory libraryResolverFactory;
179 179
180 /** 180 /**
181 * Initialize a newly created analysis context. 181 * Initialize a newly created analysis context.
182 */ 182 */
183 AnalysisContextImpl() { 183 AnalysisContextImpl() {
184 _privatePartition = new cache.UniversalCachePartition(this, 184 _privatePartition = new cache.UniversalCachePartition(this);
185 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE,
186 new ContextRetentionPolicy(this));
187 _cache = createCacheFromSourceFactory(null); 185 _cache = createCacheFromSourceFactory(null);
188 _taskManager = AnalysisEngine.instance.taskManager; 186 _taskManager = AnalysisEngine.instance.taskManager;
189 _driver = new AnalysisDriver(_taskManager, this); 187 _driver = new AnalysisDriver(_taskManager, this);
190 _onSourcesChangedController = 188 _onSourcesChangedController =
191 new StreamController<SourcesChangedEvent>.broadcast(); 189 new StreamController<SourcesChangedEvent>.broadcast();
192 } 190 }
193 191
194 @override 192 @override
195 AnalysisOptions get analysisOptions => _options; 193 AnalysisOptions get analysisOptions => _options;
196 194
197 @override 195 @override
198 void set analysisOptions(AnalysisOptions options) { 196 void set analysisOptions(AnalysisOptions options) {
199 bool needsRecompute = this._options.analyzeFunctionBodiesPredicate != 197 bool needsRecompute = this._options.analyzeFunctionBodiesPredicate !=
200 options.analyzeFunctionBodiesPredicate || 198 options.analyzeFunctionBodiesPredicate ||
201 this._options.generateImplicitErrors != 199 this._options.generateImplicitErrors !=
202 options.generateImplicitErrors || 200 options.generateImplicitErrors ||
203 this._options.generateSdkErrors != options.generateSdkErrors || 201 this._options.generateSdkErrors != options.generateSdkErrors ||
204 this._options.dart2jsHint != options.dart2jsHint || 202 this._options.dart2jsHint != options.dart2jsHint ||
205 (this._options.hint && !options.hint) || 203 (this._options.hint && !options.hint) ||
206 this._options.preserveComments != options.preserveComments || 204 this._options.preserveComments != options.preserveComments ||
207 this._options.enableNullAwareOperators != 205 this._options.enableNullAwareOperators !=
208 options.enableNullAwareOperators || 206 options.enableNullAwareOperators ||
209 this._options.enableStrictCallChecks != options.enableStrictCallChecks; 207 this._options.enableStrictCallChecks != options.enableStrictCallChecks;
210 int cacheSize = options.cacheSize; 208 int cacheSize = options.cacheSize;
211 if (this._options.cacheSize != cacheSize) { 209 if (this._options.cacheSize != cacheSize) {
212 this._options.cacheSize = cacheSize; 210 this._options.cacheSize = cacheSize;
213 _privatePartition.maxCacheSize = cacheSize;
214 } 211 }
215 this._options.analyzeFunctionBodiesPredicate = 212 this._options.analyzeFunctionBodiesPredicate =
216 options.analyzeFunctionBodiesPredicate; 213 options.analyzeFunctionBodiesPredicate;
217 this._options.generateImplicitErrors = options.generateImplicitErrors; 214 this._options.generateImplicitErrors = options.generateImplicitErrors;
218 this._options.generateSdkErrors = options.generateSdkErrors; 215 this._options.generateSdkErrors = options.generateSdkErrors;
219 this._options.dart2jsHint = options.dart2jsHint; 216 this._options.dart2jsHint = options.dart2jsHint;
220 this._options.enableNullAwareOperators = options.enableNullAwareOperators; 217 this._options.enableNullAwareOperators = options.enableNullAwareOperators;
221 this._options.enableStrictCallChecks = options.enableStrictCallChecks; 218 this._options.enableStrictCallChecks = options.enableStrictCallChecks;
222 this._options.hint = options.hint; 219 this._options.hint = options.hint;
223 this._options.incremental = options.incremental; 220 this._options.incremental = options.incremental;
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 buffer.write(" "); 1926 buffer.write(" ");
1930 buffer.writeln(source.fullName); 1927 buffer.writeln(source.fullName);
1931 } 1928 }
1932 _logInformation(buffer.toString()); 1929 _logInformation(buffer.toString());
1933 } 1930 }
1934 return changedTargets.length > 0; 1931 return changedTargets.length > 0;
1935 } 1932 }
1936 } 1933 }
1937 1934
1938 /** 1935 /**
1939 * A retention policy used by an analysis context.
1940 */
1941 class ContextRetentionPolicy implements cache.CacheRetentionPolicy {
1942 /**
1943 * The context associated with this policy.
1944 */
1945 final AnalysisContextImpl context;
1946
1947 /**
1948 * Initialize a newly created policy to be associated with the given
1949 * [context].
1950 */
1951 ContextRetentionPolicy(this.context);
1952
1953 @override
1954 RetentionPriority getAstPriority(
1955 AnalysisTarget target, cache.CacheEntry entry) {
1956 int priorityCount = context._priorityOrder.length;
1957 for (int i = 0; i < priorityCount; i++) {
1958 if (target == context._priorityOrder[i]) {
1959 return RetentionPriority.HIGH;
1960 }
1961 }
1962 if (_astIsNeeded(entry)) {
1963 return RetentionPriority.MEDIUM;
1964 }
1965 return RetentionPriority.LOW;
1966 }
1967
1968 bool _astIsNeeded(cache.CacheEntry entry) =>
1969 entry.isInvalid(BUILD_FUNCTION_TYPE_ALIASES_ERRORS) ||
1970 entry.isInvalid(BUILD_LIBRARY_ERRORS) ||
1971 entry.isInvalid(CONSTRUCTORS_ERRORS) ||
1972 entry.isInvalid(HINTS) ||
1973 //entry.isInvalid(LINTS) ||
1974 entry.isInvalid(RESOLVE_REFERENCES_ERRORS) ||
1975 entry.isInvalid(RESOLVE_TYPE_NAMES_ERRORS) ||
1976 entry.isInvalid(VERIFY_ERRORS);
1977 }
1978
1979 /**
1980 * An object that manages the partitions that can be shared between analysis 1936 * An object that manages the partitions that can be shared between analysis
1981 * contexts. 1937 * contexts.
1982 */ 1938 */
1983 class PartitionManager { 1939 class PartitionManager {
1984 /** 1940 /**
1985 * The default cache size for a Dart SDK partition.
1986 */
1987 static int _DEFAULT_SDK_CACHE_SIZE = 256;
1988
1989 /**
1990 * A table mapping SDK's to the partitions used for those SDK's. 1941 * A table mapping SDK's to the partitions used for those SDK's.
1991 */ 1942 */
1992 HashMap<DartSdk, cache.SdkCachePartition> _sdkPartitions = 1943 HashMap<DartSdk, cache.SdkCachePartition> _sdkPartitions =
1993 new HashMap<DartSdk, cache.SdkCachePartition>(); 1944 new HashMap<DartSdk, cache.SdkCachePartition>();
1994 1945
1995 /** 1946 /**
1996 * Clear any cached data being maintained by this manager. 1947 * Clear any cached data being maintained by this manager.
1997 */ 1948 */
1998 void clearCache() { 1949 void clearCache() {
1999 _sdkPartitions.clear(); 1950 _sdkPartitions.clear();
2000 } 1951 }
2001 1952
2002 /** 1953 /**
2003 * Return the partition being used for the given [sdk], creating the partition 1954 * Return the partition being used for the given [sdk], creating the partition
2004 * if necessary. 1955 * if necessary.
2005 */ 1956 */
2006 cache.SdkCachePartition forSdk(DartSdk sdk) { 1957 cache.SdkCachePartition forSdk(DartSdk sdk) {
2007 // Call sdk.context now, because when it creates a new 1958 // Call sdk.context now, because when it creates a new
2008 // InternalAnalysisContext instance, it calls forSdk() again, so creates an 1959 // InternalAnalysisContext instance, it calls forSdk() again, so creates an
2009 // SdkCachePartition instance. 1960 // SdkCachePartition instance.
2010 // So, if we initialize context after "partition == null", we end up 1961 // So, if we initialize context after "partition == null", we end up
2011 // with two SdkCachePartition instances. 1962 // with two SdkCachePartition instances.
2012 InternalAnalysisContext sdkContext = sdk.context; 1963 InternalAnalysisContext sdkContext = sdk.context;
2013 // Check cache for an existing partition. 1964 // Check cache for an existing partition.
2014 cache.SdkCachePartition partition = _sdkPartitions[sdk]; 1965 cache.SdkCachePartition partition = _sdkPartitions[sdk];
2015 if (partition == null) { 1966 if (partition == null) {
2016 partition = 1967 partition = new cache.SdkCachePartition(sdkContext);
2017 new cache.SdkCachePartition(sdkContext, _DEFAULT_SDK_CACHE_SIZE);
2018 _sdkPartitions[sdk] = partition; 1968 _sdkPartitions[sdk] = partition;
2019 } 1969 }
2020 return partition; 1970 return partition;
2021 } 1971 }
2022 } 1972 }
2023 1973
2024 /** 1974 /**
2025 * Representation of a pending computation which is based on the results of 1975 * Representation of a pending computation which is based on the results of
2026 * analysis that may or may not have been completed. 1976 * analysis that may or may not have been completed.
2027 */ 1977 */
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 PendingFuture pendingFuture = 2091 PendingFuture pendingFuture =
2142 new PendingFuture<T>(_context, target, computeValue); 2092 new PendingFuture<T>(_context, target, computeValue);
2143 if (!pendingFuture.evaluate(entry)) { 2093 if (!pendingFuture.evaluate(entry)) {
2144 _context._pendingFutureTargets 2094 _context._pendingFutureTargets
2145 .putIfAbsent(target, () => <PendingFuture>[]) 2095 .putIfAbsent(target, () => <PendingFuture>[])
2146 .add(pendingFuture); 2096 .add(pendingFuture);
2147 } 2097 }
2148 return pendingFuture.future; 2098 return pendingFuture.future;
2149 } 2099 }
2150 } 2100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698