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

Side by Side Diff: lib/src/codegen/js_module_item_order.dart

Issue 1749213006: use Source.isInSystemLibrary (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: format Created 4 years, 9 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
« no previous file with comments | « no previous file | lib/src/compiler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'dart:collection' show HashMap; 5 import 'dart:collection' show HashMap;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 9
10 import '../compiler.dart' show corelibOrder; 10 import '../compiler.dart' show corelibOrder;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 205 }
206 } 206 }
207 207
208 bool libraryIsLoaded(LibraryElement library) { 208 bool libraryIsLoaded(LibraryElement library) {
209 assert(library != _currentLibrary); 209 assert(library != _currentLibrary);
210 210
211 // DynamicElementImpl has no library. 211 // DynamicElementImpl has no library.
212 if (library == null) return true; 212 if (library == null) return true;
213 213
214 // The SDK is a special case: we optimize the order to prevent laziness. 214 // The SDK is a special case: we optimize the order to prevent laziness.
215 if (_isDartUri(library)) { 215 if (library.source.isInSystemLibrary) {
216 // SDK is loaded before non-SDK libraries 216 // SDK is loaded before non-SDK libraries
217 if (!_isDartUri(_currentLibrary)) return true; 217 if (!_currentLibrary.source.isInSystemLibrary) return true;
218 218
219 // Compute the order of both SDK libraries. If unknown, assume it's after. 219 // Compute the order of both SDK libraries. If unknown, assume it's after.
220 var order = corelibOrder.indexOf(library.source.uri); 220 var order = corelibOrder.indexOf(library.source.uri);
221 if (order == -1) order = corelibOrder.length; 221 if (order == -1) order = corelibOrder.length;
222 222
223 var currentOrder = corelibOrder.indexOf(_currentLibrary.source.uri); 223 var currentOrder = corelibOrder.indexOf(_currentLibrary.source.uri);
224 if (currentOrder == -1) currentOrder = corelibOrder.length; 224 if (currentOrder == -1) currentOrder = corelibOrder.length;
225 225
226 // If the dart:* library we are currently compiling is loaded after the 226 // If the dart:* library we are currently compiling is loaded after the
227 // class's library, then we know the class is available. 227 // class's library, then we know the class is available.
228 if (order != currentOrder) return currentOrder > order; 228 if (order != currentOrder) return currentOrder > order;
229 229
230 // If we don't know the order of the class's library or the current 230 // If we don't know the order of the class's library or the current
231 // library, do the normal cycle check. (Not all SDK libs are cycles.) 231 // library, do the normal cycle check. (Not all SDK libs are cycles.)
232 } 232 }
233 233
234 return !_inLibraryCycle(library); 234 return !_inLibraryCycle(library);
235 } 235 }
236 236
237 /// Returns true if [library] depends on the [currentLibrary] via some 237 /// Returns true if [library] depends on the [currentLibrary] via some
238 /// transitive import. 238 /// transitive import.
239 bool _inLibraryCycle(LibraryElement library) { 239 bool _inLibraryCycle(LibraryElement library) {
240 // SDK libs don't depend on things outside the SDK. 240 // SDK libs don't depend on things outside the SDK.
241 // (We can reach this via the recursive call below.) 241 // (We can reach this via the recursive call below.)
242 if (_isDartUri(library) && !_isDartUri(_currentLibrary)) return false; 242 if (library.source.isInSystemLibrary &&
243 !_currentLibrary.source.isInSystemLibrary) return false;
243 244
244 var result = _libraryCycleMemo[library]; 245 var result = _libraryCycleMemo[library];
245 if (result != null) return result; 246 if (result != null) return result;
246 247
247 result = library == _currentLibrary; 248 result = library == _currentLibrary;
248 _libraryCycleMemo[library] = result; 249 _libraryCycleMemo[library] = result;
249 for (var e in library.imports) { 250 for (var e in library.imports) {
250 if (result) break; 251 if (result) break;
251 result = _inLibraryCycle(e.importedLibrary); 252 result = _inLibraryCycle(e.importedLibrary);
252 } 253 }
253 for (var e in library.exports) { 254 for (var e in library.exports) {
254 if (result) break; 255 if (result) break;
255 result = _inLibraryCycle(e.exportedLibrary); 256 result = _inLibraryCycle(e.exportedLibrary);
256 } 257 }
257 return _libraryCycleMemo[library] = result; 258 return _libraryCycleMemo[library] = result;
258 } 259 }
259
260 /// Returns whether this is a library imported with 'dart:' URI.
261 ///
262 /// This is similar to [LibraryElement.isInSdk], but checking the URI instead
263 /// of the library naming convention, because the URI is reliable.
264 static bool _isDartUri(LibraryElement e) => e.source.uri.scheme == 'dart';
265 } 260 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698