Skip to content

Commit

Permalink
Version 3.6.0-330.0.dev
Browse files Browse the repository at this point in the history
Merge 085deb8 into dev
  • Loading branch information
Dart CI committed Oct 8, 2024
2 parents 3c47264 + 085deb8 commit 7b965fb
Show file tree
Hide file tree
Showing 45 changed files with 1,211 additions and 694 deletions.
1 change: 1 addition & 0 deletions pkg/analysis_server/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ lib/src/handler/legacy/edit_get_fixes.dart
lib/src/handler/legacy/edit_get_postfix_completion.dart
lib/src/handler/legacy/edit_get_refactoring.dart
lib/src/handler/legacy/edit_get_statement_completion.dart
lib/src/handler/legacy/edit_import_elements.dart
lib/src/handler/legacy/edit_is_postfix_completion_applicable.dart
lib/src/handler/legacy/edit_list_postfix_completion_templates.dart
lib/src/handler/legacy/edit_organize_directives.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class ImportElementsComputer {
}

bool _hasElement(String prefix, String name) {
var scope = libraryResult.libraryElement.scope;
var scope = libraryResult.libraryElement.definingCompilationUnit.scope;

if (prefix.isNotEmpty) {
var prefixElement = scope.lookup(prefix).getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class EditImportElementsHandler extends LegacyHandler {
sendResponse(Response.importElementsInvalidFile(request));
return;
}
var libraryUnit = result.libraryElement.definingCompilationUnit;
if (libraryUnit != result.unit.declaredElement) {
var libraryUnit = result.libraryElement2.firstFragment;
if (libraryUnit != result.libraryFragment) {
// The file in the request is a part of a library. We need to pass the
// defining compilation unit to the computer, not the part.
result = await server.getResolvedUnit(libraryUnit.source.fullName);
Expand Down
2 changes: 2 additions & 0 deletions pkg/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use `CompilationUnitElement.libraryImportPrefixes` instead.
* Deprecated `LibraryElement.parts`,
use `CompilationUnitElement.parts` instead.
* Deprecated `LibraryElement.scope`,
use `CompilationUnitElement.scope` instead.

## 6.9.0
* `NormalFormalParameter` now implements `AnnotatedNode`.
Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ abstract class CompilationUnitElement implements UriReferencedElement {
/// The parts included by this unit.
List<PartElement> get parts;

/// The scope used to resolve names within this compilation unit.
///
/// It includes all of the elements that are declared in the library, and all
/// of the elements imported into this unit or parent units.
Scope get scope;

@override
AnalysisSession get session;

Expand Down Expand Up @@ -2094,6 +2100,7 @@ abstract class LibraryOrAugmentationElement implements Element {
///
/// It consists of elements that are either declared in the library, or
/// imported into it.
@Deprecated('Use CompilationUnitElement.scope')
Scope get scope;

@override
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class LibraryAnalyzer {
ResolutionVisitor(
unitElement: unitElement,
errorListener: errorListener,
nameScope: _libraryElement.scope,
nameScope: unitElement.scope,
strictInference: _analysisOptions.strictInference,
strictCasts: _analysisOptions.strictCasts,
elementWalker: ElementWalker.forCompilationUnit(
Expand All @@ -174,7 +174,7 @@ class LibraryAnalyzer {
// TODO(scheglov): We don't need to do this for the whole unit.
parsedUnit.accept(ScopeResolverVisitor(
_libraryElement, file.source, _typeProvider, errorListener,
nameScope: _libraryElement.scope));
nameScope: unitElement.scope));

FlowAnalysisHelper flowAnalysisHelper = FlowAnalysisHelper(
_testingData != null, _libraryElement.featureSet,
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6396,6 +6396,7 @@ abstract class LibraryOrAugmentationElementImpl extends ElementImpl
return definingCompilationUnit.libraryImportPrefixes;
}

@Deprecated('Use CompilationUnitElement.scope')
@override
LibraryFragmentScope get scope {
return definingCompilationUnit.scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {

@reflectiveTest
class LibraryElementTest_scope extends PubPackageResolutionTest {
@deprecated
test_lookup() async {
await assertNoErrorsInCode(r'''
int foo = 0;
Expand All @@ -194,6 +195,7 @@ int foo = 0;
);
}

@deprecated
test_lookup_extension_unnamed() async {
await assertNoErrorsInCode(r'''
extension on int {}
Expand All @@ -206,6 +208,7 @@ extension on int {}
);
}

@deprecated
test_lookup_implicitCoreImport() async {
await assertNoErrorsInCode('');

Expand All @@ -217,6 +220,7 @@ extension on int {}
);
}

@deprecated
test_lookup_notFound() async {
await assertNoErrorsInCode('');

Expand All @@ -231,6 +235,7 @@ extension on int {}
);
}

@deprecated
test_lookup_prefersLocal() async {
await assertNoErrorsInCode(r'''
// ignore:unused_import
Expand All @@ -252,6 +257,7 @@ int sin() => 3;
);
}

@deprecated
test_lookup_prefix() async {
await assertNoErrorsInCode(r'''
// ignore:unused_import
Expand All @@ -266,6 +272,7 @@ import 'dart:math' as math;
);
}

@deprecated
test_lookup_respectsCombinator_hide() async {
await assertNoErrorsInCode(r'''
// ignore:unused_import
Expand All @@ -289,6 +296,7 @@ import 'dart:math' hide sin;
);
}

@deprecated
test_lookup_respectsCombinator_show() async {
await assertNoErrorsInCode(r'''
// ignore:unused_import
Expand Down
2 changes: 2 additions & 0 deletions pkg/dev_compiler/lib/ddc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'dart:isolate';
import 'package:bazel_worker/bazel_worker.dart';
import 'package:kernel/ast.dart' show clearDummyTreeNodesParentPointer;

import 'src/command/arguments.dart';
import 'src/command/result.dart';
import 'src/compiler/shared_command.dart';
import 'src/kernel/command.dart';
import 'src/kernel/expression_compiler_worker.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/dev_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

// The dev_compiler does not have a publishable public API, instead this is
// intended for other consumers within the Dart SDK.
export 'src/command/options.dart' show Options;
export 'src/compiler/module_builder.dart'
show ModuleFormat, parseModuleFormat, libraryUriToJsIdentifier;
export 'src/compiler/shared_command.dart' show SharedCompilerOptions;
export 'src/kernel/command.dart' show jsProgramToCode;
export 'src/kernel/compiler.dart' show Compiler, ProgramCompiler;
export 'src/kernel/compiler_new.dart' show LibraryBundleCompiler;
Expand Down
147 changes: 147 additions & 0 deletions pkg/dev_compiler/lib/src/command/arguments.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// 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 'dart:io';

/// Stores the result of preprocessing `dartdevc` command line arguments.
///
/// `dartdevc` preprocesses arguments to support some features that
/// `package:args` does not handle (training `@` to reference arguments in a
/// file).
///
/// [isBatch]/[isWorker] mode are preprocessed because they can combine
/// argument lists from the initial invocation and from batch/worker jobs.
class ParsedArguments {
/// The user's arguments to the compiler for this compilation.
final List<String> rest;

/// Whether to run in `--batch` mode, e.g the Dart SDK and Language tests.
///
/// Similar to [isWorker] but with a different protocol.
/// See also [isBatchOrWorker].
final bool isBatch;

/// Whether to run in `--experimental-expression-compiler` mode.
///
/// This is a special mode that is optimized for only compiling expressions.
///
/// All dependencies must come from precompiled dill files, and those must
/// be explicitly invalidated as needed between expression compile requests.
/// Invalidation of dill is performed using [updateDeps] from the client (i.e.
/// debugger) and should be done every time a dill file changes, for example,
/// on hot reload or rebuild.
final bool isExpressionCompiler;

/// Whether to run in `--bazel_worker` mode, e.g. for Bazel builds.
///
/// Similar to [isBatch] but with a different protocol.
/// See also [isBatchOrWorker].
final bool isWorker;

/// Whether to re-use the last compiler result when in a worker.
///
/// This is useful if we are repeatedly compiling things in the same context,
/// e.g. in a debugger REPL.
final bool reuseResult;

/// Whether to use the incremental compiler for compiling.
///
/// Note that this only makes sense when also reusing results.
final bool useIncrementalCompiler;

ParsedArguments._(
this.rest, {
this.isBatch = false,
this.isWorker = false,
this.reuseResult = false,
this.useIncrementalCompiler = false,
this.isExpressionCompiler = false,
});

/// Preprocess arguments to determine whether DDK is used in batch mode or as a
/// persistent worker.
///
/// When used in batch mode, we expect a `--batch` parameter.
///
/// When used as a persistent bazel worker, the `--persistent_worker` might be
/// present, and an argument of the form `@path/to/file` might be provided. The
/// latter needs to be replaced by reading all the contents of the
/// file and expanding them into the resulting argument list.
factory ParsedArguments.from(List<String> args) {
if (args.isEmpty) return ParsedArguments._(args);

var newArgs = <String>[];
var isWorker = false;
var isBatch = false;
var reuseResult = false;
var useIncrementalCompiler = false;
var isExpressionCompiler = false;

Iterable<String> argsToParse = args;

// Expand `@path/to/file`
if (args.last.startsWith('@')) {
var extra = _readLines(args.last.substring(1));
argsToParse = args.take(args.length - 1).followedBy(extra);
}

for (var arg in argsToParse) {
if (arg == '--persistent_worker') {
isWorker = true;
} else if (arg == '--batch') {
isBatch = true;
} else if (arg == '--reuse-compiler-result') {
reuseResult = true;
} else if (arg == '--use-incremental-compiler') {
useIncrementalCompiler = true;
} else if (arg == '--experimental-expression-compiler') {
isExpressionCompiler = true;
} else {
newArgs.add(arg);
}
}
return ParsedArguments._(newArgs,
isWorker: isWorker,
isBatch: isBatch,
reuseResult: reuseResult,
useIncrementalCompiler: useIncrementalCompiler,
isExpressionCompiler: isExpressionCompiler);
}

/// Whether the compiler is running in [isBatch] or [isWorker] mode.
///
/// Both modes are generally equivalent from the compiler's perspective,
/// the main difference is that they use distinct protocols to communicate
/// jobs to the compiler.
bool get isBatchOrWorker => isBatch || isWorker;

/// Merge [args] and return the new parsed arguments.
///
/// Typically used when [isBatchOrWorker] is set to merge the compilation's
/// arguments with any global ones that were provided when the worker started.
ParsedArguments merge(List<String> arguments) {
// Parse the arguments again so `--kernel` can be passed. This provides
// added safety that we are really compiling in Kernel mode, if somehow the
// worker was not initialized correctly.
var newArgs = ParsedArguments.from(arguments);
if (newArgs.isBatchOrWorker) {
throw ArgumentError('cannot change batch or worker mode after startup.');
}
return ParsedArguments._(rest.toList()..addAll(newArgs.rest),
isWorker: isWorker,
isBatch: isBatch,
reuseResult: reuseResult || newArgs.reuseResult,
useIncrementalCompiler:
useIncrementalCompiler || newArgs.useIncrementalCompiler);
}
}

/// Return all lines in a file found at [path].
Iterable<String> _readLines(String path) {
try {
return File(path).readAsLinesSync().where((String line) => line.isNotEmpty);
} on FileSystemException catch (e) {
throw Exception('Failed to read $path: $e');
}
}
Loading

0 comments on commit 7b965fb

Please sign in to comment.