mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
Use default FeatureSet for a file in its unlinked unit key hash.
BUG=https://github.com/dart-lang/sdk/issues/40609 Change-Id: I4f333c802d1ba086354701aa41a75dadca8099a2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135500 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
e34299101c
commit
fa74c546b1
3 changed files with 37 additions and 21 deletions
|
@ -108,6 +108,14 @@ class FileState {
|
|||
*/
|
||||
final bool isInExternalSummaries;
|
||||
|
||||
/**
|
||||
* The default [FeatureSet] for the file path and URI.
|
||||
*
|
||||
* The actual language version, and the feature set, of the file might be
|
||||
* different, if `@dart` is specified in the file header.
|
||||
*/
|
||||
final FeatureSet _featureSet;
|
||||
|
||||
bool _exists;
|
||||
String _content;
|
||||
String _contentHash;
|
||||
|
@ -139,14 +147,15 @@ class FileState {
|
|||
*/
|
||||
bool hasErrorOrWarning = false;
|
||||
|
||||
FileState._(this._fsState, this.path, this.uri, this.source)
|
||||
FileState._(this._fsState, this.path, this.uri, this.source, this._featureSet)
|
||||
: isInExternalSummaries = false;
|
||||
|
||||
FileState._external(this._fsState, this.uri)
|
||||
: isInExternalSummaries = true,
|
||||
path = null,
|
||||
source = null,
|
||||
_exists = true {
|
||||
_exists = true,
|
||||
_featureSet = null {
|
||||
_apiSignature = Uint8List(16);
|
||||
_libraryCycle = LibraryCycle.external();
|
||||
}
|
||||
|
@ -368,8 +377,7 @@ class FileState {
|
|||
return _parse(errorListener);
|
||||
});
|
||||
} catch (_) {
|
||||
AnalysisOptionsImpl analysisOptions = _fsState._analysisOptions;
|
||||
return _createEmptyCompilationUnit(analysisOptions.contextFeatures);
|
||||
return _createEmptyCompilationUnit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -405,6 +413,7 @@ class FileState {
|
|||
{
|
||||
var signature = ApiSignature();
|
||||
signature.addUint32List(_fsState._unlinkedSalt);
|
||||
signature.addFeatureSet(_featureSet);
|
||||
signature.addString(_contentHash);
|
||||
signature.addBool(_exists);
|
||||
contentSignature = signature.toByteList();
|
||||
|
@ -522,10 +531,10 @@ class FileState {
|
|||
@override
|
||||
String toString() => path ?? '<unresolved>';
|
||||
|
||||
CompilationUnit _createEmptyCompilationUnit(FeatureSet featureSet) {
|
||||
CompilationUnit _createEmptyCompilationUnit() {
|
||||
var token = Token.eof(0);
|
||||
return astFactory.compilationUnit(
|
||||
beginToken: token, endToken: token, featureSet: featureSet)
|
||||
beginToken: token, endToken: token, featureSet: _featureSet)
|
||||
..lineInfo = LineInfo(const <int>[0]);
|
||||
}
|
||||
|
||||
|
@ -568,14 +577,13 @@ class FileState {
|
|||
|
||||
CompilationUnit _parse(AnalysisErrorListener errorListener) {
|
||||
AnalysisOptionsImpl analysisOptions = _fsState._analysisOptions;
|
||||
var featureSet = _fsState.featureSetProvider.getFeatureSet(path, uri);
|
||||
if (source == null) {
|
||||
return _createEmptyCompilationUnit(featureSet);
|
||||
return _createEmptyCompilationUnit();
|
||||
}
|
||||
|
||||
CharSequenceReader reader = CharSequenceReader(content);
|
||||
Scanner scanner = Scanner(source, reader, errorListener)
|
||||
..configureFeatures(featureSet);
|
||||
..configureFeatures(_featureSet);
|
||||
Token token = PerformanceStatistics.scan.makeCurrentWhile(() {
|
||||
return scanner.tokenize(reportScannerErrors: false);
|
||||
});
|
||||
|
@ -819,7 +827,8 @@ class FileSystemState {
|
|||
*/
|
||||
FileState get unresolvedFile {
|
||||
if (_unresolvedFile == null) {
|
||||
_unresolvedFile = FileState._(this, null, null, null);
|
||||
var featureSet = FeatureSet.fromEnableFlags([]);
|
||||
_unresolvedFile = FileState._(this, null, null, null, featureSet);
|
||||
_unresolvedFile.refresh();
|
||||
}
|
||||
return _unresolvedFile;
|
||||
|
@ -847,7 +856,8 @@ class FileSystemState {
|
|||
}
|
||||
// Create a new file.
|
||||
FileSource uriSource = FileSource(resource, uri);
|
||||
file = FileState._(this, path, uri, uriSource);
|
||||
FeatureSet featureSet = featureSetProvider.getFeatureSet(path, uri);
|
||||
file = FileState._(this, path, uri, uriSource, featureSet);
|
||||
_uriToFile[uri] = file;
|
||||
_addFileWithPath(path, file);
|
||||
_pathToCanonicalFile[path] = file;
|
||||
|
@ -888,7 +898,8 @@ class FileSystemState {
|
|||
String path = uriSource.fullName;
|
||||
File resource = _resourceProvider.getFile(path);
|
||||
FileSource source = FileSource(resource, uri);
|
||||
file = FileState._(this, path, uri, source);
|
||||
FeatureSet featureSet = featureSetProvider.getFeatureSet(path, uri);
|
||||
file = FileState._(this, path, uri, source, featureSet);
|
||||
_uriToFile[uri] = file;
|
||||
_addFileWithPath(path, file);
|
||||
file.refresh(allowCached: true);
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
// 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/dart/analysis/features.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/dart/ast/token.dart';
|
||||
import 'package:analyzer/src/summary/api_signature.dart';
|
||||
|
||||
|
@ -61,12 +59,6 @@ class _UnitApiSignatureComputer {
|
|||
addToken(node.rightBracket);
|
||||
}
|
||||
|
||||
void addFeatureSet(FeatureSet featureSet) {
|
||||
for (var feature in ExperimentStatus.knownFeatures.values) {
|
||||
signature.addBool(featureSet.isEnabled(feature));
|
||||
}
|
||||
}
|
||||
|
||||
void addFunctionBodyModifiers(FunctionBody node) {
|
||||
signature.addBool(node.isSynchronous);
|
||||
signature.addBool(node.isGenerator);
|
||||
|
@ -127,7 +119,7 @@ class _UnitApiSignatureComputer {
|
|||
}
|
||||
|
||||
void compute(CompilationUnit unit) {
|
||||
addFeatureSet(unit.featureSet);
|
||||
signature.addFeatureSet(unit.featureSet);
|
||||
|
||||
signature.addInt(unit.directives.length);
|
||||
unit.directives.forEach(addNode);
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
|
||||
|
@ -87,6 +89,17 @@ class ApiSignature {
|
|||
_offset += 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect a [FeatureSet].
|
||||
*/
|
||||
void addFeatureSet(FeatureSet featureSet) {
|
||||
var knownFeatures = ExperimentStatus.knownFeatures;
|
||||
addInt(knownFeatures.length);
|
||||
for (var feature in knownFeatures.values) {
|
||||
addBool(featureSet.isEnabled(feature));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect a 32-bit unsigned integer value.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue