Skip to content

Commit 3736a28

Browse files
srawlinsCommit Queue
authored andcommitted
dartdev: flip AOT flag for analysis-server-based commands
Work towards #50498 Work towards #53576 Change-Id: Idc34d6e1f0b0107391d26d0b531329fbc9645a00 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435445 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Siva Annamalai <[email protected]>
1 parent 36087ec commit 3736a28

File tree

7 files changed

+96
-2
lines changed

7 files changed

+96
-2
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,31 @@ constraint][language version] lower bound to 3.9 or greater (`sdk: '^3.9.0'`).
1616

1717
#### Analyzer
1818

19+
- The [dart command-line tool][] commands that use the analysis server now run
20+
the AOT-compiled analysis server snapshot. These include `dart analyze`,
21+
`dart fix`, and `dart language-server`.
22+
23+
There is no functional difference when using the AOT-compiled analysis server
24+
snapshot. But various tests indicate that there is a significant speedup in
25+
the time to analyze a project.
26+
27+
In case of an incompatibility with the AOT-compiled snapshot, a
28+
`--no-use-aot-snapshot` flag may be passed to these commands. (Please file an
29+
issue with the appropriate project if you find that you need to use this
30+
flag! It will be removed in the future.) This flag directs the tool to revert
31+
to the old behavior, using the JIT-compiled analysis server snapshot. To
32+
direct the Dart Code plugin for VS Code to pass this flag, use the
33+
[`dart.analyzerAdditionalArgs`][vs-code-args] setting. To direct the Dart
34+
IntelliJ plugin to pass this flag, use the `dart.server.additional.arguments`
35+
registry property, similar to [these steps][intellij-args].
36+
1937
- Add the [`switch_on_type`][] lint rule.
2038
- Add the [`unnecessary_unawaited`][] lint rule.
2139
- Add an assist to convert a field formal parameter to a normal parameter.
2240

41+
[dart command-line tool]: https://dart.dev/tools/dart-tool
42+
[vs-code-args]: https://dartcode.org/docs/settings/#dartanalyzeradditionalargs
43+
[intellij-args]: https://github.com/dart-lang/sdk/blob/main/pkg/analysis_server/doc/tutorial/instrumentation.md#intellij-idea-and-android-studio
2344
[`switch_on_type`]: http://dart.dev/lints/switch_on_type
2445
[`unnecessary_unawaited`]: http://dart.dev/lints/unnecessary_unawaited
2546

pkg/dartdev/lib/src/commands/analyze.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class AnalyzeCommand extends DartdevCommand {
9393
..addFlag(
9494
useAotSnapshotFlag,
9595
help: 'Use the AOT analysis server snapshot',
96+
defaultsTo: true,
9697
hide: true,
9798
)
9899
..addExperimentalFlags();
@@ -124,7 +125,7 @@ class AnalyzeCommand extends DartdevCommand {
124125
}
125126
}
126127

127-
/// Errors in analysis_options and pubspec.yaml will be reported first
128+
/// Errors in analysis_options.yaml and pubspec.yaml will be reported first
128129
/// and a note that they might be the cause of other errors.
129130
final List<AnalysisError> priorityErrors = <AnalysisError>[];
130131
final List<AnalysisError> errors = <AnalysisError>[];

pkg/dartdev/lib/src/commands/fix.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed
6464
..addFlag(
6565
useAotSnapshotFlag,
6666
help: 'Use the AOT analysis server snapshot',
67+
defaultsTo: true,
6768
hide: true,
6869
)
6970
..addExperimentalFlags(verbose: verbose);

pkg/dartdev/lib/src/commands/language_server.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ For more information about the server's capabilities and configuration, see:
3636
includeHelpFlag: false,
3737
defaultToLsp: true,
3838
)..addFlag(useAotSnapshotFlag,
39-
help: 'Use the AOT analysis server snapshot', hide: true);
39+
help: 'Use the AOT analysis server snapshot',
40+
defaultsTo: true,
41+
hide: true);
4042
}
4143

4244
@override
@@ -61,6 +63,8 @@ For more information about the server's capabilities and configuration, see:
6163
useExecProcess: true,
6264
);
6365
} else {
66+
args = [...args];
67+
args.remove('--no-$useAotSnapshotFlag');
6468
VmInteropHandler.run(
6569
sdk.analysisServerSnapshot,
6670
args,

pkg/dartdev/test/commands/analyze_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,30 @@ warning - analysis_options.yaml:1:10 - The include file 'package:lints/recommend
826826
});
827827
});
828828
});
829+
830+
group('AOT snapshot', () {
831+
test('--use-aot-snapshot', () async {
832+
p = project(mainSrc: 'int get foo => 1;\n');
833+
834+
var result =
835+
await p.runAnalyze(['--use-aot-snapshot'], workingDir: p.dirPath);
836+
837+
expect(result.exitCode, 0);
838+
expect(result.stderr, isEmpty);
839+
expect(result.stdout, contains('No issues found!'));
840+
});
841+
842+
test('--no-use-aot-snapshot', () async {
843+
p = project(mainSrc: 'int get foo => 1;\n');
844+
845+
var result =
846+
await p.runAnalyze(['--no-use-aot-snapshot'], workingDir: p.dirPath);
847+
848+
expect(result.exitCode, 0);
849+
expect(result.stderr, isEmpty);
850+
expect(result.stdout, contains('No issues found!'));
851+
});
852+
});
829853
}
830854

831855
class TestLogger implements Logger {

pkg/dartdev/test/commands/fix_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,41 @@ linter:
627627
'2 fixes made in 1 file.',
628628
]));
629629
});
630+
631+
group('AOT mode', () {
632+
test('--use-aot-snapshot', () async {
633+
p = project(
634+
mainSrc: 'String a() => "";',
635+
analysisOptions: '''
636+
linter:
637+
rules:
638+
- prefer_single_quotes
639+
''',
640+
);
641+
var result = await p!.runFix(['--use-aot-snapshot', '--dry-run', '.'],
642+
workingDir: p!.dirPath);
643+
expect(result.exitCode, 0);
644+
expect(result.stderr, isEmpty);
645+
expect(result.stdout, contains('1 proposed fix in 1 file.'));
646+
});
647+
648+
test('--no-use-aot-snapshot', () async {
649+
p = project(
650+
mainSrc: 'String a() => "";',
651+
analysisOptions: '''
652+
linter:
653+
rules:
654+
- prefer_single_quotes
655+
''',
656+
);
657+
var result = await p!.runFix(
658+
['--no-use-aot-snapshot', '--dry-run', '.'],
659+
workingDir: p!.dirPath);
660+
expect(result.exitCode, 0);
661+
expect(result.stderr, isEmpty);
662+
expect(result.stdout, contains('1 proposed fix in 1 file.'));
663+
});
664+
});
630665
});
631666

632667
group('regression', () {

pkg/dartdev/test/commands/language_server_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ void defineLanguageServerTests() {
7373
return runWithLsp(['language-server', '--protocol=lsp']);
7474
});
7575

76+
test('--use-aot-snapshot', () async {
77+
return runWithLsp(['language-server', '--use-aot-snapshot']);
78+
});
79+
80+
test('--no-use-aot-snapshot', () async {
81+
return runWithLsp(['language-server', '--no-use-aot-snapshot']);
82+
});
83+
7684
test('protocol analyzer', () async {
7785
project = utils.project();
7886

0 commit comments

Comments
 (0)