Skip to content

Commit 7c64e31

Browse files
author
Dart CI
committed
Version 3.4.0-247.0.dev
Merge 1b5368f into dev
2 parents 91dc69b + 1b5368f commit 7c64e31

File tree

29 files changed

+829
-113
lines changed

29 files changed

+829
-113
lines changed

.github/workflows/scorecards-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
steps:
2525
- name: "Checkout code"
26-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
26+
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
2727
with:
2828
persist-credentials: false
2929

.github/workflows/third-party-deps-scan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
contents: read
2222
steps:
2323
- name: "Checkout code"
24-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
24+
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
2525
with:
2626
persist-credentials: false
2727
- name: "setup python"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
6+
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
7+
import 'package:analyzer/dart/analysis/results.dart';
8+
import 'package:analyzer/file_system/overlay_file_system.dart';
9+
import 'package:analyzer/file_system/physical_file_system.dart';
10+
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
11+
import 'package:analyzer/src/util/performance/operation_performance.dart';
12+
13+
import 'sliding_statistics.dart';
14+
15+
/// A tool to see the current performance of code completion at an interesting
16+
/// location. To see details, run it with `--observe:5000` and then use
17+
/// DevTools CPU profiler.
18+
///
19+
/// Currently this is not a tool to track performance, it does not record it
20+
/// anywhere.
21+
///
22+
/// Update the marked code as necessary to construct a case for checking
23+
/// performance. The code below is just one example that we saw to have
24+
/// significant cost.
25+
///
26+
/// Don't forget to update [flutterPackagePath].
27+
Future<void> main() async {
28+
await _runForever(
29+
path: '$flutterPackagePath/lib/test.dart',
30+
markedCode: r'''
31+
import 'package:flutter/widgets.dart';
32+
Widget x = ^;
33+
''',
34+
);
35+
}
36+
37+
const String flutterEnvironmentPath =
38+
'/Users/scheglov/dart/flutter_elements/environment';
39+
40+
/// This should be the path of the `package:flutter` in a local checkout.
41+
/// You don't have to use [flutterEnvironmentPath] from above.
42+
const String flutterPackagePath = '$flutterEnvironmentPath/packages/flutter';
43+
44+
Future<void> _runForever({
45+
required String path,
46+
required String markedCode,
47+
}) async {
48+
final offset = markedCode.indexOf('^');
49+
if (offset == -1) {
50+
throw ArgumentError('No ^ marker');
51+
}
52+
53+
final rawCode =
54+
markedCode.substring(0, offset) + markedCode.substring(offset + 1);
55+
if (rawCode.contains('^')) {
56+
throw ArgumentError('Duplicate ^ marker');
57+
}
58+
59+
final resourceProvider = OverlayResourceProvider(
60+
PhysicalResourceProvider.INSTANCE,
61+
);
62+
63+
resourceProvider.setOverlay(
64+
path,
65+
content: rawCode,
66+
modificationStamp: -1,
67+
);
68+
69+
var collection = AnalysisContextCollectionImpl(
70+
resourceProvider: resourceProvider,
71+
includedPaths: [path],
72+
sdkPath: '/Users/scheglov/Applications/dart-sdk',
73+
);
74+
var analysisContext = collection.contextFor(path);
75+
var analysisSession = analysisContext.currentSession;
76+
var unitResult = await analysisSession.getResolvedUnit(path);
77+
unitResult as ResolvedUnitResult;
78+
79+
var dartRequest = DartCompletionRequest.forResolvedUnit(
80+
resolvedUnit: unitResult,
81+
offset: offset,
82+
);
83+
84+
final statistics = SlidingStatistics(100);
85+
while (true) {
86+
var timer = Stopwatch()..start();
87+
var budget = CompletionBudget(Duration(seconds: 30));
88+
List<CompletionSuggestionBuilder> suggestions = [];
89+
for (var i = 0; i < 10; i++) {
90+
suggestions = await DartCompletionManager(
91+
budget: budget,
92+
notImportedSuggestions: NotImportedSuggestions(),
93+
).computeSuggestions(
94+
dartRequest,
95+
OperationPerformanceImpl('<root>'),
96+
useFilter: false,
97+
);
98+
}
99+
100+
final responseTime = timer.elapsedMilliseconds;
101+
statistics.add(responseTime);
102+
if (statistics.isReady) {
103+
print(
104+
'[${DateTime.now().millisecondsSinceEpoch}]'
105+
'[time: $responseTime ms][mean: ${statistics.mean.toStringAsFixed(1)}]'
106+
'[stdDev: ${statistics.standardDeviation.toStringAsFixed(3)}]'
107+
'[min: ${statistics.min.toStringAsFixed(1)}]'
108+
'[max: ${statistics.max.toStringAsFixed(1)}]',
109+
);
110+
} else {
111+
print('[time: $responseTime ms][suggestions: ${suggestions.length}]');
112+
}
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'dart:math';
6+
import 'dart:typed_data';
7+
8+
class SlidingStatistics {
9+
final Uint32List _values;
10+
int _index = 0;
11+
bool _isReady = false;
12+
13+
SlidingStatistics(int length) : _values = Uint32List(length);
14+
15+
bool get isReady => _isReady;
16+
17+
int get max {
18+
var result = 0;
19+
for (final value in _values) {
20+
if (value > result) {
21+
result = value;
22+
}
23+
}
24+
return result;
25+
}
26+
27+
double get mean {
28+
assert(isReady);
29+
var sum = 0.0;
30+
for (final value in _values) {
31+
sum += value;
32+
}
33+
return sum / _values.length;
34+
}
35+
36+
int get min {
37+
var result = 1 << 20;
38+
for (final value in _values) {
39+
if (value < result) {
40+
result = value;
41+
}
42+
}
43+
return result;
44+
}
45+
46+
double get standardDeviation {
47+
assert(isReady);
48+
final mean = this.mean;
49+
var sum = 0.0;
50+
for (final value in _values) {
51+
final diff = value - mean;
52+
sum += diff * diff;
53+
}
54+
return sqrt(sum / _values.length);
55+
}
56+
57+
void add(int value) {
58+
_values[_index] = value;
59+
_index++;
60+
if (_index == _values.length) {
61+
_isReady = true;
62+
}
63+
_index %= _values.length;
64+
}
65+
}

pkg/analyzer/lib/src/dart/analysis/driver.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import 'package:meta/meta.dart';
9595
// TODO(scheglov): Clean up the list of implicitly analyzed files.
9696
class AnalysisDriver {
9797
/// The version of data format, should be incremented on every format change.
98-
static const int DATA_VERSION = 351;
98+
static const int DATA_VERSION = 353;
9999

100100
/// The number of exception contexts allowed to write. Once this field is
101101
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/element/display_string_builder.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class ElementDisplayStringBuilder {
7171
}
7272

7373
void writeConstructorElement(ConstructorElement element) {
74+
if (element.isAugmentation) {
75+
_write('augment ');
76+
}
77+
7478
_writeType(element.returnType);
7579
_write(' ');
7680

@@ -88,25 +92,17 @@ class ElementDisplayStringBuilder {
8892
}
8993

9094
void writeEnumElement(EnumElement element) {
95+
if (element.isAugmentation) {
96+
_write('augment ');
97+
}
98+
9199
_write('enum ');
92100
_write(element.displayName);
93101
_writeTypeParameters(element.typeParameters);
94102
_writeTypesIfNotEmpty(' with ', element.mixins);
95103
_writeTypesIfNotEmpty(' implements ', element.interfaces);
96104
}
97105

98-
// void writePropertyAccessor(PropertyAccessorElement element) {
99-
// var variable = element.variable2;
100-
// if (variable == null) {
101-
// // builder.;
102-
// }
103-
//
104-
// writeExecutableElement(
105-
// element,
106-
// (element.isGetter ? 'get ' : 'set ') + variable2.displayName,
107-
// );
108-
// }
109-
110106
void writeExecutableElement(ExecutableElement element, String name) {
111107
if (element.isAugmentation) {
112108
_write('augment ');
@@ -135,6 +131,10 @@ class ElementDisplayStringBuilder {
135131
}
136132

137133
void writeExtensionElement(ExtensionElement element) {
134+
if (element.isAugmentation) {
135+
_write('augment ');
136+
}
137+
138138
_write('extension');
139139
if (element.displayName.isNotEmpty) {
140140
_write(' ');

pkg/analyzer/lib/src/summary2/bundle_reader.dart

+7
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,13 @@ class TopLevelVariableElementLinkedData
25662566
);
25672567
element.macroDiagnostics = reader.readMacroDiagnostics();
25682568
element.type = reader.readRequiredType();
2569+
2570+
final augmentationTarget = reader.readElement();
2571+
if (augmentationTarget is TopLevelVariableElementImpl) {
2572+
augmentationTarget.augmentation = element;
2573+
element.augmentationTarget = augmentationTarget;
2574+
}
2575+
25692576
if (element is ConstTopLevelVariableElementImpl) {
25702577
var initializer = reader._readOptionalExpression();
25712578
if (initializer != null) {

pkg/analyzer/lib/src/summary2/bundle_writer.dart

+6
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ class BundleWriter {
636636
_resolutionSink._writeAnnotationList(element.metadata);
637637
_resolutionSink.writeMacroDiagnostics(element.macroDiagnostics);
638638
_resolutionSink.writeType(element.type);
639+
640+
_resolutionSink.writeElement(element.augmentationTarget);
641+
if (element.isAugmentation) {
642+
_propertyAugmentations.add(element);
643+
}
644+
639645
_resolutionSink._writeOptionalNode(element.constantInitializer);
640646
}
641647

pkg/analyzer/lib/src/summary2/element_builder.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
11911191
}
11921192

11931193
element.hasInitializer = variable.initializer != null;
1194+
element.isAugmentation = node.augmentKeyword != null;
11941195
element.isConst = node.variables.isConst;
11951196
element.isExternal = node.externalKeyword != null;
11961197
element.isFinal = node.variables.isFinal;

pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:io';
66

77
import 'package:analyzer/file_system/file_system.dart';
88
import 'package:analyzer/file_system/memory_file_system.dart';
9+
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
910
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
1011
import 'package:path/path.dart' as path;
1112
import 'package:path/path.dart';
@@ -146,11 +147,28 @@ mixin ResourceProviderMixin {
146147
return newFile(path, content);
147148
}
148149

150+
File newPackageConfigJsonFileFromBuilder(
151+
String directoryPath,
152+
PackageConfigFileBuilder builder,
153+
) {
154+
final content = builder.toContent(toUriStr: toUriStr);
155+
return newPackageConfigJsonFile(directoryPath, content);
156+
}
157+
149158
File newPubspecYamlFile(String directoryPath, String content) {
150159
String path = join(directoryPath, file_paths.pubspecYaml);
151160
return newFile(path, content);
152161
}
153162

163+
void newSinglePackageConfigJsonFile({
164+
required String packagePath,
165+
required String name,
166+
}) {
167+
final builder = PackageConfigFileBuilder()
168+
..add(name: name, rootPath: packagePath);
169+
newPackageConfigJsonFileFromBuilder(packagePath, builder);
170+
}
171+
154172
Uri toUri(String path) {
155173
path = convertPath(path);
156174
return resourceProvider.pathContext.toUri(path);

0 commit comments

Comments
 (0)