Skip to content

Commit

Permalink
Version 2.14.0-370.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'b13dc22338bee08f38029de3afb5c21a2569bd58' into 'dev'
  • Loading branch information
Dart CI committed Jul 30, 2021
2 parents 2e22cdf + b13dc22 commit 406d207
Show file tree
Hide file tree
Showing 32 changed files with 404 additions and 153 deletions.
10 changes: 5 additions & 5 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6237,14 +6237,14 @@ const MessageCode messageJsInteropEnclosingClassJSAnnotationContext =
message: r"""This is the enclosing class.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeJsInteropExternalExtensionMemberNotOnJSClass =
messageJsInteropExternalExtensionMemberNotOnJSClass;
const Code<Null> codeJsInteropExternalExtensionMemberOnTypeInvalid =
messageJsInteropExternalExtensionMemberOnTypeInvalid;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageJsInteropExternalExtensionMemberNotOnJSClass =
const MessageCode("JsInteropExternalExtensionMemberNotOnJSClass",
const MessageCode messageJsInteropExternalExtensionMemberOnTypeInvalid =
const MessageCode("JsInteropExternalExtensionMemberOnTypeInvalid",
message:
r"""JS interop class required for 'external' extension members.""",
r"""JS interop or Native class required for 'external' extension members.""",
tip:
r"""Try adding a JS interop annotation to the on type class of the extension.""");

Expand Down
29 changes: 21 additions & 8 deletions pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
messageJsInteropAnonymousFactoryPositionalParameters,
messageJsInteropEnclosingClassJSAnnotation,
messageJsInteropEnclosingClassJSAnnotationContext,
messageJsInteropExternalExtensionMemberNotOnJSClass,
messageJsInteropExternalExtensionMemberOnTypeInvalid,
messageJsInteropExternalMemberNotJSAnnotated,
messageJsInteropIndexNotSupported,
messageJsInteropNamedParameters,
Expand Down Expand Up @@ -282,13 +282,14 @@ class JsInteropChecks extends RecursiveVisitor {
/// [member] is `external` and not an allowed `external` usage.
void _checkDisallowedExternal(Member member) {
if (member.isExternal) {
// TODO(rileyporter): Allow extension members on some Native classes.
if (member.isExtensionMember) {
_diagnosticsReporter.report(
messageJsInteropExternalExtensionMemberNotOnJSClass,
member.fileOffset,
member.name.text.length,
member.fileUri);
if (!_isNativeExtensionMember(member)) {
_diagnosticsReporter.report(
messageJsInteropExternalExtensionMemberOnTypeInvalid,
member.fileOffset,
member.name.text.length,
member.fileUri);
}
} else if (!hasJSInteropAnnotation(member) &&
!_isAllowedExternalUsage(member)) {
// Member could be JS annotated and not considered a JS interop member
Expand Down Expand Up @@ -338,6 +339,18 @@ class JsInteropChecks extends RecursiveVisitor {
/// Returns whether given extension [member] is in an extension that is on a
/// JS interop class.
bool _isJSExtensionMember(Member member) {
return _checkExtensionMember(member, hasJSInteropAnnotation);
}

/// Returns whether given extension [member] is in an extension on a Native
/// class.
bool _isNativeExtensionMember(Member member) {
return _checkExtensionMember(member, _nativeClasses.containsValue);
}

/// Returns whether given extension [member] is on a class that passses the
/// given [validateExtensionClass].
bool _checkExtensionMember(Member member, Function validateExtensionClass) {
assert(member.isExtensionMember);
if (_libraryExtensionsIndex == null) {
_libraryExtensionsIndex = {};
Expand All @@ -347,6 +360,6 @@ class JsInteropChecks extends RecursiveVisitor {
}

var onType = _libraryExtensionsIndex![member.reference]!.onType;
return onType is InterfaceType && hasJSInteropAnnotation(onType.classNode);
return onType is InterfaceType && validateExtensionClass(onType.classNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AnalysisOptionsGenerator extends YamlCompletionGenerator {
AnalyzerOptions.chromeOsManifestChecks: EmptyProducer(),
}),
AnalyzerOptions.plugins: EmptyProducer(),
AnalyzerOptions.propagateLinterExceptions: EmptyProducer(),
AnalyzerOptions.strong_mode: MapProducer({
AnalyzerOptions.declarationCasts: EmptyProducer(),
AnalyzerOptions.implicitCasts: EmptyProducer(),
Expand Down
6 changes: 5 additions & 1 deletion pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:analyzer/src/context/source.dart';
import 'package:analyzer/src/dart/analysis/file_state.dart';
import 'package:analyzer/src/dart/analysis/testing_data.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/constant/compute.dart';
import 'package:analyzer/src/dart/constant/constant_verifier.dart';
import 'package:analyzer/src/dart/constant/evaluation.dart';
Expand Down Expand Up @@ -351,7 +352,10 @@ class LibraryAnalyzer {
}

// Run lints that handle specific node types.
unit.accept(LinterVisitor(nodeRegistry));
unit.accept(LinterVisitor(
nodeRegistry,
LinterExceptionHandler(_analysisOptions.propagateLinterExceptions)
.logException));
}

void _computeVerifyErrors(FileState file, CompilationUnit unit) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,12 @@ class DeferredLibraryReferenceDetector extends RecursiveAstVisitor<void> {
///
/// Clients may not extend, implement or mix-in this class.
class LinterExceptionHandler {
/// Indicates whether linter exceptions should be propagated to the caller (by
/// re-throwing them)
final bool propagateLinterExceptions;

LinterExceptionHandler(this.propagateLinterExceptions);

/// A method that can be passed to the `LinterVisitor` constructor to handle
/// exceptions that occur during linting.
void logException(
Expand All @@ -1326,6 +1332,9 @@ class LinterExceptionHandler {
// TODO(39284): should this exception be silent?
AnalysisEngine.instance.instrumentationService.logException(
SilentException(buffer.toString(), exception, stackTrace));
if (propagateLinterExceptions) {
throw exception;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ class LibraryAnalyzer {
}

// Run lints that handle specific node types.
unit.accept(LinterVisitor(nodeRegistry));
unit.accept(LinterVisitor(
nodeRegistry,
LinterExceptionHandler(_analysisOptions.propagateLinterExceptions)
.logException));
}

void _computeVerifyErrors(FileState file, CompilationUnit unit) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/generated/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class AnalysisOptionsImpl implements AnalysisOptions {
/// This option is experimental and subject to change.
bool implicitDynamic = true;

/// Indicates whether linter exceptions should be propagated to the caller (by
/// re-throwing them)
bool propagateLinterExceptions = false;

/// A flag indicating whether inference failures are allowed, off by default.
///
/// This option is experimental and subject to change.
Expand Down Expand Up @@ -319,6 +323,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
if (options is AnalysisOptionsImpl) {
implicitCasts = options.implicitCasts;
implicitDynamic = options.implicitDynamic;
propagateLinterExceptions = options.propagateLinterExceptions;
strictInference = options.strictInference;
strictRawTypes = options.strictRawTypes;
}
Expand Down Expand Up @@ -382,6 +387,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
// Append boolean flags.
buffer.addBool(implicitCasts);
buffer.addBool(implicitDynamic);
buffer.addBool(propagateLinterExceptions);
buffer.addBool(strictInference);
buffer.addBool(strictRawTypes);
buffer.addBool(useFastaParser);
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/lint/linter_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LinterVisitor extends RecursiveAstVisitor<void> {

LinterVisitor(this.registry, [LintRuleExceptionHandler? exceptionHandler])
: exceptionHandler =
exceptionHandler ?? LinterExceptionHandler().logException;
exceptionHandler ?? LinterExceptionHandler(true).logException;

@override
void visitAdjacentStrings(AdjacentStrings node) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/task/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class AnalyzerOptions {
/// Ways to say `include`.
static const List<String> includeSynonyms = ['include', 'true'];

static const String propagateLinterExceptions = 'propagate-linter-exceptions';

/// Ways to say `true` or `false`.
static const List<String> trueOrFalse = ['true', 'false'];

Expand All @@ -163,6 +165,7 @@ class AnalyzerOptions {
language,
optionalChecks,
plugins,
propagateLinterExceptions,
strong_mode,
];

Expand Down Expand Up @@ -805,6 +808,9 @@ class _OptionsProcessor {
if (feature == AnalyzerOptions.implicitDynamic) {
options.implicitDynamic = boolValue;
}
if (feature == AnalyzerOptions.propagateLinterExceptions) {
options.propagateLinterExceptions = boolValue;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/analyzer/test/src/dart/analysis/context_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ environment:
);
expect(actual.implicitCasts, expected.implicitCasts);
expect(actual.implicitDynamic, expected.implicitDynamic);
expect(
actual.propagateLinterExceptions, expected.propagateLinterExceptions);
expect(actual.strictInference, expected.strictInference);
expect(actual.strictRawTypes, expected.strictRawTypes);
}
Expand Down
23 changes: 15 additions & 8 deletions pkg/dev_compiler/lib/src/kernel/asset_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ import 'package:pedantic/pedantic.dart';
/// A wrapper around asset server that redirects file read requests
/// to http get requests to the asset server.
class AssetFileSystem implements FileSystem {
FileSystem original;
final FileSystem original;
final String server;
final String port;
final RetryTimeoutClient client;

AssetFileSystem(this.original, this.server, this.port);
AssetFileSystem(this.original, this.server, this.port)
: client = RetryTimeoutClient(
HttpClient()
..maxConnectionsPerHost = 200
..connectionTimeout = const Duration(seconds: 30)
..idleTimeout = const Duration(seconds: 30),
retries: 4);

/// Convert the uri to a server uri.
Uri _resourceUri(Uri uri) => Uri.parse('http://$server:$port/${uri.path}');
Expand All @@ -34,6 +41,10 @@ class AssetFileSystem implements FileSystem {
// Pass the uri to the asset server in the debugger.
return AssetFileSystemEntity(this, _resourceUri(uri));
}

void close() {
client?.close(force: true);
}
}

class AssetFileSystemEntity implements FileSystemEntity {
Expand Down Expand Up @@ -85,20 +96,16 @@ class AssetFileSystemEntity implements FileSystemEntity {
});
}

/// Execute the [body] with the new http client.
/// Execute the [body] with the http client created in [fileSystem].
///
/// Throws a [FileSystemException] on failure,
/// and cleans up the client on return or error.
Future<T> _runWithClient<T>(
Future<T> Function(RetryTimeoutClient httpClient) body) async {
RetryTimeoutClient httpClient;
try {
httpClient = RetryTimeoutClient(HttpClient(), retries: 5);
return await body(httpClient);
return await body(fileSystem.client);
} on Exception catch (e, s) {
throw FileSystemException(uri, '$e:$s');
} finally {
httpClient?.close(force: true);
}
}

Expand Down
21 changes: 16 additions & 5 deletions pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,30 @@ class ExpressionCompilerWorker {
/// receive port corresponding to [sendPort].
static Future<void> createAndStart(List<String> args,
{SendPort sendPort}) async {
ExpressionCompilerWorker worker;
if (sendPort != null) {
var receivePort = ReceivePort();
sendPort.send(receivePort.sendPort);
try {
var worker = await createFromArgs(args,
worker = await createFromArgs(args,
requestStream: receivePort.cast<Map<String, dynamic>>(),
sendResponse: sendPort.send);
await worker.start();
await worker.run();
} catch (e, s) {
sendPort
.send({'exception': '$e', 'stackTrace': '$s', 'succeeded': false});
rethrow;
} finally {
receivePort.close();
worker?.close();
}
} else {
var worker = await createFromArgs(args);
await worker.start();
try {
worker = await createFromArgs(args);
await worker.run();
} finally {
worker?.close();
}
}
}

Expand Down Expand Up @@ -243,7 +249,7 @@ class ExpressionCompilerWorker {
///
/// Completes when the [requestStream] closes and we finish handling the
/// requests.
Future<void> start() async {
Future<void> run() async {
await for (var request in requestStream) {
try {
var command = request['command'] as String;
Expand Down Expand Up @@ -275,6 +281,11 @@ class ExpressionCompilerWorker {
_processedOptions.ticker.logMs('Stopped expression compiler worker.');
}

void close() {
var fileSystem = _processedOptions?.fileSystem;
if (fileSystem != null && fileSystem is AssetFileSystem) fileSystem.close();
}

/// Handles a `CompileExpression` request.
Future<Map<String, dynamic>> _compileExpression(
CompileExpressionRequest request) async {
Expand Down
Loading

0 comments on commit 406d207

Please sign in to comment.