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

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

Issue 1170813008: fixes detection of SDK libraries (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: format Created 5 years, 6 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
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 import 'package:analyzer/src/generated/ast.dart'; 6 import 'package:analyzer/src/generated/ast.dart';
7 import 'package:analyzer/src/generated/element.dart'; 7 import 'package:analyzer/src/generated/element.dart';
8 import 'package:dev_compiler/src/dependency_graph.dart' show corelibOrder; 8 import 'package:dev_compiler/src/dependency_graph.dart' show corelibOrder;
9 9
10 typedef void ModuleItemEmitter(AstNode item); 10 typedef void ModuleItemEmitter(AstNode item);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // TODO(jmesserly): if we want to log what triggered laziness, this is 175 // TODO(jmesserly): if we want to log what triggered laziness, this is
176 // the place to do so. 176 // the place to do so.
177 _loaded[current] = false; 177 _loaded[current] = false;
178 } 178 }
179 } 179 }
180 180
181 bool libraryIsLoaded(LibraryElement library) { 181 bool libraryIsLoaded(LibraryElement library) {
182 assert(library != _currentLibrary); 182 assert(library != _currentLibrary);
183 183
184 // The SDK is a special case: we optimize the order to prevent laziness. 184 // The SDK is a special case: we optimize the order to prevent laziness.
185 if (library.isInSdk) { 185 if (_isDartUri(library)) {
186 // SDK is loaded before non-SDK libraries 186 // SDK is loaded before non-SDK libraries
187 if (!_currentLibrary.isInSdk) return true; 187 if (!_isDartUri(_currentLibrary)) return true;
188 188
189 // Compute the order of both SDK libraries. If unknown, assume it's after. 189 // Compute the order of both SDK libraries. If unknown, assume it's after.
190 var order = corelibOrder.indexOf(library.name); 190 var order = corelibOrder.indexOf(library.name);
191 if (order == -1) order = corelibOrder.length; 191 if (order == -1) order = corelibOrder.length;
192 192
193 var currentOrder = corelibOrder.indexOf(_currentLibrary.name); 193 var currentOrder = corelibOrder.indexOf(_currentLibrary.name);
194 if (currentOrder == -1) currentOrder = corelibOrder.length; 194 if (currentOrder == -1) currentOrder = corelibOrder.length;
195 195
196 // If the dart:* library we are currently compiling is loaded after the 196 // If the dart:* library we are currently compiling is loaded after the
197 // class's library, then we know the class is available. 197 // class's library, then we know the class is available.
198 if (order != currentOrder) return currentOrder > order; 198 if (order != currentOrder) return currentOrder > order;
199 199
200 // If we don't know the order of the class's library or the current 200 // If we don't know the order of the class's library or the current
201 // library, do the normal cycle check. (Not all SDK libs are cycles.) 201 // library, do the normal cycle check. (Not all SDK libs are cycles.)
202 } 202 }
203 203
204 return !_inLibraryCycle(library); 204 return !_inLibraryCycle(library);
205 } 205 }
206 206
207 /// Returns true if [library] depends on the [currentLibrary] via some 207 /// Returns true if [library] depends on the [currentLibrary] via some
208 /// transitive import. 208 /// transitive import.
209 bool _inLibraryCycle(LibraryElement library) { 209 bool _inLibraryCycle(LibraryElement library) {
210 // SDK libs don't depend on things outside the SDK. 210 // SDK libs don't depend on things outside the SDK.
211 // (We can reach this via the recursive call below.) 211 // (We can reach this via the recursive call below.)
212 if (library.isInSdk && !_currentLibrary.isInSdk) return false; 212 if (_isDartUri(library) && !_isDartUri(_currentLibrary)) return false;
213 213
214 var result = _libraryCycleMemo[library]; 214 var result = _libraryCycleMemo[library];
215 if (result != null) return result; 215 if (result != null) return result;
216 216
217 result = library == _currentLibrary; 217 result = library == _currentLibrary;
218 _libraryCycleMemo[library] = result; 218 _libraryCycleMemo[library] = result;
219 for (var e in library.imports) { 219 for (var e in library.imports) {
220 if (result) break; 220 if (result) break;
221 result = _inLibraryCycle(e.importedLibrary); 221 result = _inLibraryCycle(e.importedLibrary);
222 } 222 }
223 for (var e in library.exports) { 223 for (var e in library.exports) {
224 if (result) break; 224 if (result) break;
225 result = _inLibraryCycle(e.exportedLibrary); 225 result = _inLibraryCycle(e.exportedLibrary);
226 } 226 }
227 return _libraryCycleMemo[library] = result; 227 return _libraryCycleMemo[library] = result;
228 } 228 }
229
230 /// Returns whether this is a library imported with 'dart:' URI.
231 ///
232 /// This is similar to [LibraryElement.isInSdk], but checking the URI instead
233 /// of the library naming convention, because the URI is reliable.
234 static bool _isDartUri(LibraryElement e) => e.source.uri.scheme == 'dart';
vsm 2015/06/10 16:41:15 Do you want to assert e.isInSdk == _isDartUri(e)?
Jennifer Messerly 2015/06/10 16:46:04 We can't assert it, because user can name their li
229 } 235 }
OLDNEW
« lib/devc.dart ('K') | « lib/src/codegen/js_codegen.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698