Skip to content

Commit

Permalink
Macro. Prepare for reporting resolved macro generated files. Step Lib…
Browse files Browse the repository at this point in the history
…ertyGlobal#1.

Change-Id: Ib84e1aeef508cbfdd5b02d5c4c13420c5aa4daff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344421
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Jan 3, 2024
1 parent d2b5f5f commit 70783e5
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 81 deletions.
67 changes: 24 additions & 43 deletions pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:analyzer/src/context/packages.dart';
import 'package:analyzer/src/dart/analysis/analysis_options_map.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
import 'package:analyzer/src/dart/analysis/driver_event.dart' as events;
import 'package:analyzer/src/dart/analysis/feature_set_provider.dart';
import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
import 'package:analyzer/src/dart/analysis/file_state.dart';
Expand Down Expand Up @@ -1115,9 +1116,8 @@ class AnalysisDriver implements AnalysisDriverGeneric {
if (_errorsRequestedFiles.isNotEmpty) {
var path = _errorsRequestedFiles.keys.first;
var completers = _errorsRequestedFiles.remove(path)!;
var result = await _computeErrors(
path: path,
);
var analysisResult = await _computeAnalysisResult(path, withUnit: false);
var result = analysisResult.errorsResult!;
for (var completer in completers) {
completer.complete(result);
}
Expand Down Expand Up @@ -1340,7 +1340,15 @@ class AnalysisDriver implements AnalysisDriverGeneric {
if (!withUnit) {
var bytes = _byteStore.get(key);
if (bytes != null) {
return _getAnalysisResultFromBytes(file, signature, bytes);
final unit = AnalysisDriverResolvedUnit.fromBuffer(bytes);
final errors = _getErrorsFromSerialized(file, unit.errors);
_updateHasErrorOrWarningFlag(file, errors);
final index = unit.index!;
final errorsResult = _createErrorsResultImpl(
file: file,
errors: errors,
);
return AnalysisResult.errors(signature, errorsResult, index);
}
}

Expand All @@ -1349,6 +1357,12 @@ class AnalysisDriver implements AnalysisDriverGeneric {
_logger.writeln('Work in $name');
try {
testView?.numOfAnalyzedLibraries++;
_resultController.add(
events.ComputeAnalysis(
file: file,
library: library,
),
);

if (!_hasLibraryByUri('dart:core')) {
return _newMissingDartLibraryResult(file, 'dart:core');
Expand Down Expand Up @@ -1446,13 +1460,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
});
}

Future<SomeErrorsResult> _computeErrors({
required String path,
}) async {
var analysisResult = await _computeAnalysisResult(path, withUnit: false);
return analysisResult.errorsResult!;
}

Future<AnalysisDriverUnitIndex> _computeIndex(String path) async {
var analysisResult = await _computeAnalysisResult(path, withUnit: false);
return analysisResult._index!;
Expand All @@ -1476,6 +1483,12 @@ class AnalysisDriver implements AnalysisDriverGeneric {
performance: OperationPerformanceImpl('<root>'),
);

_resultController.add(
events.ComputeResolvedLibrary(
library: library,
),
);

var analysisOptions = libraryContext.analysisContext
.getAnalysisOptionsForFile(library.file.resource);

Expand Down Expand Up @@ -1689,38 +1702,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
_saltForUnlinked = buffer.toUint32List();
}

/// Load the [AnalysisResult] for the given [file] from the [bytes]. Set
/// optional [content] and [resolvedUnit].
AnalysisResult _getAnalysisResultFromBytes(
FileState file,
String signature,
Uint8List bytes, {
String? content,
CompilationUnit? resolvedUnit,
List<AnalysisError>? errors,
}) {
var unit = AnalysisDriverResolvedUnit.fromBuffer(bytes);
errors ??= _getErrorsFromSerialized(file, unit.errors);
_updateHasErrorOrWarningFlag(file, errors);
var index = unit.index!;
if (content != null && resolvedUnit != null) {
var resolvedUnitResult = ResolvedUnitResultImpl(
session: currentSession,
fileState: file,
content: content,
unit: resolvedUnit,
errors: errors,
);
return AnalysisResult.unit(signature, resolvedUnitResult, index);
} else {
var errorsResult = _createErrorsResultImpl(
file: file,
errors: errors,
);
return AnalysisResult.errors(signature, errorsResult, index);
}
}

/// Return [AnalysisError]s for the given [serialized] errors.
List<AnalysisError> _getErrorsFromSerialized(
FileState file, List<AnalysisDriverUnitError> serialized) {
Expand Down
27 changes: 27 additions & 0 deletions pkg/analyzer/lib/src/dart/analysis/driver_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/analysis/file_state.dart';

/// An event that happened inside the [AnalysisDriver].
sealed class AnalysisDriverEvent {}

final class ComputeAnalysis extends AnalysisDriverEvent {
final FileState file;
final LibraryFileKind library;

ComputeAnalysis({
required this.file,
required this.library,
});
}

final class ComputeResolvedLibrary extends AnalysisDriverEvent {
final LibraryFileKind library;

ComputeResolvedLibrary({
required this.library,
});
}
Loading

0 comments on commit 70783e5

Please sign in to comment.