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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2987303002: Fix for truncated unlinked summaries in ByteStore. (Closed)
Patch Set: Created 3 years, 4 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 | pkg/analyzer/test/src/dart/analysis/file_state_test.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 bool _exists; 110 bool _exists;
111 List<int> _contentBytes; 111 List<int> _contentBytes;
112 String _content; 112 String _content;
113 String _contentHash; 113 String _contentHash;
114 LineInfo _lineInfo; 114 LineInfo _lineInfo;
115 Set<String> _definedTopLevelNames; 115 Set<String> _definedTopLevelNames;
116 Set<String> _definedClassMemberNames; 116 Set<String> _definedClassMemberNames;
117 Set<String> _referencedNames; 117 Set<String> _referencedNames;
118 Set<String> _subtypedNames; 118 Set<String> _subtypedNames;
119 String _unlinkedKey;
119 UnlinkedUnit _unlinked; 120 UnlinkedUnit _unlinked;
120 List<int> _apiSignature; 121 List<int> _apiSignature;
121 122
122 List<FileState> _importedFiles; 123 List<FileState> _importedFiles;
123 List<FileState> _exportedFiles; 124 List<FileState> _exportedFiles;
124 List<FileState> _partedFiles; 125 List<FileState> _partedFiles;
125 List<NameFilter> _exportFilters; 126 List<NameFilter> _exportFilters;
126 127
127 Set<FileState> _directReferencedFiles = new Set<FileState>(); 128 Set<FileState> _directReferencedFiles = new Set<FileState>();
128 Set<FileState> _transitiveFiles; 129 Set<FileState> _transitiveFiles;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 * The external names referenced by the file. 276 * The external names referenced by the file.
276 */ 277 */
277 Set<String> get referencedNames => _referencedNames; 278 Set<String> get referencedNames => _referencedNames;
278 279
279 /** 280 /**
280 * The names which are used in `extends`, `with` or `implements` clauses in 281 * The names which are used in `extends`, `with` or `implements` clauses in
281 * the file. Import prefixes and type arguments are not included. 282 * the file. Import prefixes and type arguments are not included.
282 */ 283 */
283 Set<String> get subtypedNames => _subtypedNames; 284 Set<String> get subtypedNames => _subtypedNames;
284 285
286 @visibleForTesting
287 FileStateTestView get test => new FileStateTestView(this);
288
285 /** 289 /**
286 * Return public top-level declarations declared in the file. The keys to the 290 * Return public top-level declarations declared in the file. The keys to the
287 * map are names of declarations. 291 * map are names of declarations.
288 */ 292 */
289 Map<String, TopLevelDeclaration> get topLevelDeclarations { 293 Map<String, TopLevelDeclaration> get topLevelDeclarations {
290 if (_topLevelDeclarations == null) { 294 if (_topLevelDeclarations == null) {
291 _topLevelDeclarations = <String, TopLevelDeclaration>{}; 295 _topLevelDeclarations = <String, TopLevelDeclaration>{};
292 296
293 void addDeclaration(TopLevelDeclarationKind kind, String name) { 297 void addDeclaration(TopLevelDeclarationKind kind, String name) {
294 if (!name.startsWith('_')) { 298 if (!name.startsWith('_')) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 421 }
418 422
419 // Compute the content hash. 423 // Compute the content hash.
420 List<int> contentBytes = UTF8.encode(_content); 424 List<int> contentBytes = UTF8.encode(_content);
421 { 425 {
422 List<int> hashBytes = md5.convert(contentBytes).bytes; 426 List<int> hashBytes = md5.convert(contentBytes).bytes;
423 _contentHash = hex.encode(hashBytes); 427 _contentHash = hex.encode(hashBytes);
424 } 428 }
425 429
426 // Prepare the unlinked bundle key. 430 // Prepare the unlinked bundle key.
427 String unlinkedKey;
428 { 431 {
429 ApiSignature signature = new ApiSignature(); 432 ApiSignature signature = new ApiSignature();
430 signature.addUint32List(_fsState._salt); 433 signature.addUint32List(_fsState._salt);
431 signature.addInt(contentBytes.length); 434 signature.addInt(contentBytes.length);
432 signature.addString(_contentHash); 435 signature.addString(_contentHash);
433 unlinkedKey = '${signature.toHex()}.unlinked'; 436 _unlinkedKey = '${signature.toHex()}.unlinked';
434 } 437 }
435 438
436 // Prepare bytes of the unlinked bundle - existing or new. 439 // Prepare bytes of the unlinked bundle - existing or new.
437 List<int> bytes; 440 List<int> bytes;
438 { 441 {
439 bytes = _fsState._byteStore.get(unlinkedKey); 442 bytes = _fsState._byteStore.get(_unlinkedKey);
440 if (bytes == null) { 443 if (bytes == null || bytes.isEmpty) {
441 CompilationUnit unit = parse(AnalysisErrorListener.NULL_LISTENER); 444 CompilationUnit unit = parse(AnalysisErrorListener.NULL_LISTENER);
442 _fsState._logger.run('Create unlinked for $path', () { 445 _fsState._logger.run('Create unlinked for $path', () {
443 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); 446 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit);
444 DefinedNames definedNames = computeDefinedNames(unit); 447 DefinedNames definedNames = computeDefinedNames(unit);
445 List<String> referencedNames = computeReferencedNames(unit).toList(); 448 List<String> referencedNames = computeReferencedNames(unit).toList();
446 List<String> subtypedNames = computeSubtypedNames(unit).toList(); 449 List<String> subtypedNames = computeSubtypedNames(unit).toList();
447 bytes = new AnalysisDriverUnlinkedUnitBuilder( 450 bytes = new AnalysisDriverUnlinkedUnitBuilder(
448 unit: unlinkedUnit, 451 unit: unlinkedUnit,
449 definedTopLevelNames: definedNames.topLevelNames.toList(), 452 definedTopLevelNames: definedNames.topLevelNames.toList(),
450 definedClassMemberNames: 453 definedClassMemberNames:
451 definedNames.classMemberNames.toList(), 454 definedNames.classMemberNames.toList(),
452 referencedNames: referencedNames, 455 referencedNames: referencedNames,
453 subtypedNames: subtypedNames) 456 subtypedNames: subtypedNames)
454 .toBuffer(); 457 .toBuffer();
455 _fsState._byteStore.put(unlinkedKey, bytes); 458 _fsState._byteStore.put(_unlinkedKey, bytes);
456 }); 459 });
457 } 460 }
458 } 461 }
459 462
460 // Read the unlinked bundle. 463 // Read the unlinked bundle.
461 var driverUnlinkedUnit = new AnalysisDriverUnlinkedUnit.fromBuffer(bytes); 464 var driverUnlinkedUnit = new AnalysisDriverUnlinkedUnit.fromBuffer(bytes);
462 _definedTopLevelNames = driverUnlinkedUnit.definedTopLevelNames.toSet(); 465 _definedTopLevelNames = driverUnlinkedUnit.definedTopLevelNames.toSet();
463 _definedClassMemberNames = 466 _definedClassMemberNames =
464 driverUnlinkedUnit.definedClassMemberNames.toSet(); 467 driverUnlinkedUnit.definedClassMemberNames.toSet();
465 _referencedNames = driverUnlinkedUnit.referencedNames.toSet(); 468 _referencedNames = driverUnlinkedUnit.referencedNames.toSet();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 } 637 }
635 for (int i = 0; i < a.length; i++) { 638 for (int i = 0; i < a.length; i++) {
636 if (a[i] != b[i]) { 639 if (a[i] != b[i]) {
637 return false; 640 return false;
638 } 641 }
639 } 642 }
640 return true; 643 return true;
641 } 644 }
642 } 645 }
643 646
647 @visibleForTesting
648 class FileStateTestView {
649 final FileState file;
650
651 FileStateTestView(this.file);
652
653 String get unlinkedKey => file._unlinkedKey;
654 }
655
644 /** 656 /**
645 * Information about known file system state. 657 * Information about known file system state.
646 */ 658 */
647 class FileSystemState { 659 class FileSystemState {
648 final PerformanceLog _logger; 660 final PerformanceLog _logger;
649 final ResourceProvider _resourceProvider; 661 final ResourceProvider _resourceProvider;
650 final ByteStore _byteStore; 662 final ByteStore _byteStore;
651 final FileContentOverlay _contentOverlay; 663 final FileContentOverlay _contentOverlay;
652 final SourceFactory _sourceFactory; 664 final SourceFactory _sourceFactory;
653 final AnalysisOptions _analysisOptions; 665 final AnalysisOptions _analysisOptions;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 943
932 /** 944 /**
933 * Information about changes to the known file set. 945 * Information about changes to the known file set.
934 */ 946 */
935 class KnownFilesSetChange { 947 class KnownFilesSetChange {
936 final Set<String> added; 948 final Set<String> added;
937 final Set<String> removed; 949 final Set<String> removed;
938 950
939 KnownFilesSetChange(this.added, this.removed); 951 KnownFilesSetChange(this.added, this.removed);
940 } 952 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698