Skip to content

Commit 273fe8e

Browse files
jensjohaCommit Queue
authored andcommitted
[analyzer] Stable analysis tool has more options
The CL adds options to disable comments, disable warnings and disable lints. It also makes the cfe "compile_files_in_folders" tool ignore these settings. Disabling comments, for instance, looks to give a change of: * instructions:u between -6.79% and -7.99%. * msec task-clock:u between -6.72% and -11.21%. * seconds time elapsed between -6.71 and -11.21%. depending on what other options are given (disabling lints and/or warnings too) and whether GC is "disabled" or not. See below for details. Similarly disabling lints (the 14 lints I've otherwise enabled) (although less combinations tested) seems to change the cost between -2.11% and -3.33%, and disabling warnings seems to change the cost between -7.60% and -13.28%. In total either enabling both lints, warnings and comments vs neither (disabling all three) change the cost -16.29% and -21.86%. Comparing a CFE compile with an analyzer "compile" with all three disabled shows that analyzer is still about twice as slow. Details: ``` $ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --no-gc --silent --iterations=10 --gcs=3 --snapshot=pkg/analyzer/tool/stable_analysis.aot --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-comments" --arguments="/tmp/extracted_compile_dart_compile" Will now run 10+3 iterations with 2 snapshots. .........|.........|...... .......................... Comparing snapshot #1 (stable_analysis.aot) with snapshot #2 (stable_analysis.aot --no-comments) msec task-clock:u: -7.0360% +/- 2.2215% (-716.15 +/- 226.12) (10178.40 -> 9462.25) page-faults:u: -9.3094% +/- 0.0553% (-16061.70 +/- 95.37) (172531.70 -> 156470.00) cycles:u: -6.9440% +/- 2.2933% (-2972501432.70 +/- 981663660.71) (42806647619.00 -> 39834146186.30) instructions:u: -6.7931% +/- 0.0048% (-3440120947.40 +/- 2430899.72) (50641327831.60 -> 47201206884.20) seconds time elapsed: -7.0392% +/- 2.2165% (-0.72 +/- 0.23) (10.18 -> 9.47) seconds user: -6.9201% +/- 2.3274% (-0.68 +/- 0.23) (9.83 -> 9.15) seconds sys: -10.2590% +/- 9.2097% (-0.04 +/- 0.03) (0.35 -> 0.31) Comparing GC runtimes: Combined GC time: -9.6583% +/- 1.7022% (-321.00 +/- 56.57) (3323.57 -> 3002.57) Will now run 10+0 iterations with 2 snapshots. Running with extra vm arguments: --new_gen_semi_initial_size=10000 --new_gen_semi_max_size=20000 .........|.........| .................... Comparing snapshot #1 (stable_analysis.aot) with snapshot #2 (stable_analysis.aot --no-comments) msec task-clock:u: -7.1224% +/- 0.3630% (-1605.67 +/- 81.82) (22543.93 -> 20938.26) page-faults:u: -3.1600% +/- 0.0002% (-46716.10 +/- 2.42) (1478356.30 -> 1431640.20) cycles:u: -7.7156% +/- 0.3679% (-6694485059.90 +/- 319209763.53) (86765022635.00 -> 80070537575.10) instructions:u: -7.6201% +/- 0.0010% (-2695561907.00 +/- 362989.96) (35374252528.80 -> 32678690621.80) branch-misses:u: -10.2389% +/- 3.5180% (-11334840.10 +/- 3894561.73) (110703356.00 -> 99368515.90) seconds time elapsed: -7.1089% +/- 0.3612% (-1.60 +/- 0.08) (22.56 -> 20.95) seconds user: -7.4913% +/- 0.4934% (-1.51 +/- 0.10) (20.13 -> 18.62) seconds sys: -4.0502% +/- 3.7179% (-0.10 +/- 0.09) (2.42 -> 2.32) $ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --no-gc --silent --iterations=10 --gcs=3 --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-lints" --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-comments" --sarguments="--no-lints" --arguments="/tmp/extracted_compile_dart_compile" Will now run 10+3 iterations with 2 snapshots. .........|.........|...... .......................... Comparing snapshot #1 (stable_analysis.aot --no-lints) with snapshot #2 (stable_analysis.aot --no-comments --no-lints) msec task-clock:u: -9.2019% +/- 0.6621% (-910.34 +/- 65.50) (9892.93 -> 8982.59) page-faults:u: -6.2397% +/- 0.0494% (-10547.20 +/- 83.52) (169032.60 -> 158485.40) cycles:u: -9.3403% +/- 0.6697% (-3887793187.50 +/- 278762348.75) (41623774318.80 -> 37735981131.30) instructions:u: -7.0416% +/- 0.0016% (-3514960850.70 +/- 810910.06) (49917064106.10 -> 46402103255.40) branch-misses:u: -8.4057% +/- 2.6353% (-13819038.80 +/- 4332417.14) (164399864.10 -> 150580825.30) seconds time elapsed: -9.2035% +/- 0.6675% (-0.91 +/- 0.07) (9.90 -> 8.99) seconds user: -9.4766% +/- 0.7713% (-0.91 +/- 0.07) (9.55 -> 8.65) Comparing GC runtimes: Combined GC time: -11.4370% +/- 1.6980% (-378.03 +/- 56.13) (3305.37 -> 2927.33) Will now run 10+0 iterations with 2 snapshots. Running with extra vm arguments: --new_gen_semi_initial_size=10000 --new_gen_semi_max_size=20000 .........|.........| .................... Comparing snapshot #1 (stable_analysis.aot --no-lints) with snapshot #2 (stable_analysis.aot --no-comments --no-lints) msec task-clock:u: -7.2817% +/- 0.4008% (-1593.44 +/- 87.70) (21882.89 -> 20289.45) page-faults:u: -3.1244% +/- 0.0002% (-45240.50 +/- 2.27) (1447974.10 -> 1402733.60) cycles:u: -7.9326% +/- 0.4361% (-6672136018.70 +/- 366778719.10) (84110098071.20 -> 77437962052.50) instructions:u: -7.4881% +/- 0.0026% (-2595260910.30 +/- 917003.73) (34658689885.60 -> 32063428975.30) branch-misses:u: -10.1639% +/- 3.2225% (-11069908.60 +/- 3509791.31) (108913984.10 -> 97844075.50) seconds time elapsed: -7.2712% +/- 0.4031% (-1.59 +/- 0.09) (21.90 -> 20.31) seconds user: -7.8503% +/- 0.5967% (-1.53 +/- 0.12) (19.53 -> 18.00) seconds sys: -2.5633% +/- 2.0326% (-0.06 +/- 0.05) (2.35 -> 2.29) $ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --no-gc --silent --iterations=10 --gcs=3 --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-lints" --sarguments="--no-warnings" --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-comments" --sarguments="--no-lints" --sarguments="--no-warnings" --arguments="/tmp/extracted_compile_dart_compile" Will now run 10+3 iterations with 2 snapshots. .........|.........|...... .......................... Comparing snapshot #1 (stable_analysis.aot --no-lints --no-warnings) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -11.2175% +/- 0.9595% (-1057.47 +/- 90.45) (9427.00 -> 8369.53) page-faults:u: -2.9365% +/- 0.0303% (-4905.10 +/- 50.64) (167041.70 -> 162136.60) cycles:u: -11.5567% +/- 0.9943% (-4574393094.20 +/- 393550033.60) (39582014249.70 -> 35007621155.50) instructions:u: -7.9922% +/- 0.0016% (-3682331457.40 +/- 758149.87) (46074246049.70 -> 42391914592.30) branch-misses:u: -12.5973% +/- 3.8892% (-20502429.90 +/- 6329690.96) (162752151.40 -> 142249721.50) seconds time elapsed: -11.2137% +/- 0.9574% (-1.06 +/- 0.09) (9.43 -> 8.37) seconds user: -11.8730% +/- 1.0637% (-1.08 +/- 0.10) (9.10 -> 8.02) Comparing GC runtimes: Combined GC time: -11.6525% +/- 0.5882% (-393.43 +/- 19.86) (3376.40 -> 2982.97) Will now run 10+0 iterations with 2 snapshots. Running with extra vm arguments: --new_gen_semi_initial_size=10000 --new_gen_semi_max_size=20000 .........|.........| .................... Comparing snapshot #1 (stable_analysis.aot --no-lints --no-warnings) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -6.7208% +/- 0.3612% (-1266.45 +/- 68.07) (18843.65 -> 17577.20) page-faults:u: -3.1649% +/- 0.0001% (-42088.20 +/- 1.96) (1329861.40 -> 1287773.20) cycles:u: -7.3160% +/- 0.4054% (-5241354807.90 +/- 290412282.62) (71642843105.80 -> 66401488297.90) instructions:u: -7.5935% +/- 0.0044% (-2296152115.10 +/- 1343905.59) (30238373990.20 -> 27942221875.10) branch-misses:u: -9.1132% +/- 3.9645% (-8608099.00 +/- 3744717.48) (94457321.20 -> 85849222.20) seconds time elapsed: -6.7108% +/- 0.3627% (-1.27 +/- 0.07) (18.86 -> 17.59) seconds user: -7.0670% +/- 0.5908% (-1.18 +/- 0.10) (16.67 -> 15.49) seconds sys: -4.0702% +/- 2.9649% (-0.09 +/- 0.06) (2.18 -> 2.09) $ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --no-gc --silent --iterations=10 --gcs=3 --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-warnings" --sarguments="--no-comments" --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-comments" --sarguments="--no-lints" --sarguments="--no-warnings" --arguments="/tmp/extracted_compile_dart_compile" Will now run 10+3 iterations with 2 snapshots. .........|.........|...... .......................... Comparing snapshot #1 (stable_analysis.aot --no-warnings --no-comments) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -3.3341% +/- 0.7377% (-289.51 +/- 64.06) (8683.35 -> 8393.84) page-faults:u: -0.7417% +/- 0.0323% (-1211.60 +/- 52.80) (163349.30 -> 162137.70) cycles:u: -3.4347% +/- 0.7601% (-1248867985.60 +/- 276375749.53) (36360602643.40 -> 35111734657.80) instructions:u: -2.6297% +/- 0.0028% (-1144935784.80 +/- 1231115.23) (43538078747.80 -> 42393142963.00) branch-misses:u: -5.2678% +/- 3.3805% (-7994928.30 +/- 5130484.66) (151768514.80 -> 143773586.50) seconds time elapsed: -3.3345% +/- 0.7360% (-0.29 +/- 0.06) (8.69 -> 8.40) seconds user: -3.2817% +/- 0.7542% (-0.27 +/- 0.06) (8.35 -> 8.07) Comparing GC runtimes: No change in combined time. Will now run 10+0 iterations with 2 snapshots. Running with extra vm arguments: --new_gen_semi_initial_size=10000 --new_gen_semi_max_size=20000 .........|.........| .................... Comparing snapshot #1 (stable_analysis.aot --no-warnings --no-comments) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -2.9476% +/- 0.7598% (-533.40 +/- 137.48) (18095.98 -> 17562.59) page-faults:u: -2.1956% +/- 0.0002% (-28908.80 +/- 2.72) (1316679.70 -> 1287770.90) cycles:u: -3.0434% +/- 0.8290% (-2084711292.10 +/- 567884399.15) (68499834949.50 -> 66415123657.40) instructions:u: -2.1172% +/- 0.0036% (-604406330.20 +/- 1031078.80) (28547212878.80 -> 27942806548.60) seconds time elapsed: -2.9501% +/- 0.7589% (-0.53 +/- 0.14) (18.11 -> 17.58) seconds user: -2.7506% +/- 0.9446% (-0.44 +/- 0.15) (15.93 -> 15.49) seconds sys: -4.3950% +/- 4.3370% (-0.10 +/- 0.09) (2.17 -> 2.07) $ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --no-gc --silent --iterations=10 --gcs=3 --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-lints" --sarguments="--no-comments" --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-comments" --sarguments="--no-lints" --sarguments="--no-warnings" --arguments="/tmp/extracted_compile_dart_compile" Will now run 10+3 iterations with 2 snapshots. .........|.........|...... .......................... Comparing snapshot #1 (stable_analysis.aot --no-lints --no-comments) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -7.6122% +/- 0.8005% (-689.89 +/- 72.54) (9062.94 -> 8373.04) page-faults:u: 2.3362% +/- 0.0384% (3701.00 +/- 60.83) (158421.00 -> 162122.00) cycles:u: -7.9589% +/- 0.8252% (-3031048897.60 +/- 314287122.04) (38083925666.10 -> 35052876768.50) instructions:u: -8.6432% +/- 0.0022% (-4010719175.80 +/- 1020253.35) (46402911564.20 -> 42392192388.40) branch-misses:u: -8.5667% +/- 3.3681% (-13392276.60 +/- 5265305.94) (156329178.70 -> 142936902.10) seconds time elapsed: -7.6092% +/- 0.7960% (-0.69 +/- 0.07) (9.07 -> 8.38) seconds user: -8.1069% +/- 0.8987% (-0.71 +/- 0.08) (8.74 -> 8.03) Comparing GC runtimes: Combined GC time: 1.4218% +/- 0.6146% (41.57 +/- 17.97) (2923.60 -> 2965.17) Will now run 10+0 iterations with 2 snapshots. Running with extra vm arguments: --new_gen_semi_initial_size=10000 --new_gen_semi_max_size=20000 .........|.........| .................... Comparing snapshot #1 (stable_analysis.aot --no-lints --no-comments) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -13.2776% +/- 0.5461% (-2683.53 +/- 110.37) (20211.00 -> 17527.47) page-faults:u: -8.1957% +/- 0.0002% (-114963.50 +/- 2.25) (1402734.60 -> 1287771.10) cycles:u: -14.0568% +/- 0.5875% (-10861686217.90 +/- 453928594.78) (77270029416.60 -> 66408343198.70) instructions:u: -12.8518% +/- 0.0039% (-4120716309.30 +/- 1253748.99) (32063315038.40 -> 27942598729.10) branch-misses:u: -12.3483% +/- 4.9528% (-11819842.80 +/- 4740787.92) (95720172.60 -> 83900329.80) seconds time elapsed: -13.2848% +/- 0.5501% (-2.69 +/- 0.11) (20.23 -> 17.54) seconds user: -14.2010% +/- 0.8556% (-2.56 +/- 0.15) (18.00 -> 15.45) seconds sys: -5.7485% +/- 4.1202% (-0.13 +/- 0.09) (2.21 -> 2.08) $ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --no-gc --silent --iterations=10 --gcs=3 --snapshot=pkg/analyzer/tool/stable_analysis.aot --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-comments" --sarguments="--no-lints" --sarguments="--no-warnings" --arguments="/tmp/extracted_compile_dart_compile" Will now run 10+3 iterations with 2 snapshots. .........|.........|...... .......................... Comparing snapshot #1 (stable_analysis.aot) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -17.0699% +/- 1.2566% (-1725.94 +/- 127.06) (10111.01 -> 8385.07) page-faults:u: -6.0303% +/- 0.0647% (-10406.40 +/- 111.60) (172567.50 -> 162161.10) cycles:u: -17.5229% +/- 1.3093% (-7452390822.40 +/- 556837791.41) (42529351599.20 -> 35076960776.80) instructions:u: -16.2915% +/- 0.0045% (-8250492166.60 +/- 2298292.70) (50642836187.30 -> 42392344020.70) branch-misses:u: -19.3893% +/- 5.0813% (-33703814.20 +/- 8832662.68) (173826494.90 -> 140122680.70) seconds time elapsed: -17.0646% +/- 1.2597% (-1.73 +/- 0.13) (10.12 -> 8.39) seconds user: -17.4043% +/- 1.3249% (-1.70 +/- 0.13) (9.77 -> 8.07) Comparing GC runtimes: Combined GC time: -9.6474% +/- 0.9303% (-317.80 +/- 30.65) (3294.17 -> 2976.37) Will now run 10+0 iterations with 2 snapshots. Running with extra vm arguments: --new_gen_semi_initial_size=10000 --new_gen_semi_max_size=20000 .........|.........| .................... Comparing snapshot #1 (stable_analysis.aot) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: -21.8650% +/- 0.3146% (-4909.91 +/- 70.64) (22455.59 -> 17545.68) page-faults:u: -12.8916% +/- 0.0001% (-190583.50 +/- 2.05) (1478355.30 -> 1287771.80) cycles:u: -23.1639% +/- 0.3324% (-20039621139.90 +/- 287545199.62) (86512110232.60 -> 66472489092.70) instructions:u: -21.0110% +/- 0.0045% (-7432530108.60 +/- 1594640.89) (35374475273.60 -> 27941945165.00) branch-misses:u: -20.4131% +/- 3.4484% (-21659250.80 +/- 3658856.19) (106104443.40 -> 84445192.60) seconds time elapsed: -21.8550% +/- 0.3165% (-4.91 +/- 0.07) (22.47 -> 17.56) seconds user: -22.9392% +/- 0.6813% (-4.61 +/- 0.14) (20.12 -> 15.50) seconds sys: -12.6236% +/- 4.3772% (-0.30 +/- 0.10) (2.34 -> 2.04) $ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --no-gc --silent --iterations=10 --gcs=3 --snapshot=pkg/front_end/tool/compile_files_in_folders.aot --snapshot=pkg/analyzer/tool/stable_analysis.aot --sarguments="--no-comments" --sarguments="--no-lints" --sarguments="--no-warnings" --arguments="/tmp/extracted_compile_dart_compile" Will now run 10+3 iterations with 2 snapshots. .........|.........|...... .......................... Comparing snapshot #1 (compile_files_in_folders.aot) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: 93.7631% +/- 1.7382% (4059.93 +/- 75.26) (4329.99 -> 8389.92) page-faults:u: 74.1975% +/- 0.0433% (69060.90 +/- 40.33) (93077.10 -> 162138.00) cycles:u: 95.0345% +/- 1.8170% (17109768118.30 +/- 327129529.20) (18003745305.70 -> 35113513424.00) instructions:u: 100.4940% +/- 0.0028% (21248236334.70 +/- 598466.90) (21143775631.70 -> 42392011966.40) branch-misses:u: 98.0546% +/- 7.7754% (70722114.60 +/- 5607995.68) (72125240.20 -> 142847354.80) seconds time elapsed: 93.7448% +/- 1.7272% (4.06 +/- 0.07) (4.33 -> 8.39) seconds user: 94.6406% +/- 1.9931% (3.93 +/- 0.08) (4.15 -> 8.08) seconds sys: 74.2391% +/- 13.9753% (0.13 +/- 0.03) (0.18 -> 0.32) Comparing GC runtimes: Combined GC time: 100.8652% +/- 2.6849% (1496.13 +/- 39.82) (1483.30 -> 2979.43) Will now run 10+0 iterations with 2 snapshots. Running with extra vm arguments: --new_gen_semi_initial_size=10000 --new_gen_semi_max_size=20000 .........|.........| .................... Comparing snapshot #1 (compile_files_in_folders.aot) with snapshot #2 (stable_analysis.aot --no-comments --no-lints --no-warnings) msec task-clock:u: 304.8456% +/- 1.7471% (13210.70 +/- 75.71) (4333.57 -> 17544.27) page-faults:u: 199.1590% +/- 0.0010% (857307.10 +/- 4.13) (430463.60 -> 1287770.70) cycles:u: 339.8369% +/- 2.0802% (51368129498.20 +/- 314431857.77) (15115522915.20 -> 66483652413.40) instructions:u: 121.8106% +/- 0.0124% (15344104830.80 +/- 1564723.39) (12596695878.50 -> 27940800709.30) branch-misses:u: 72.0768% +/- 6.0455% (35926587.50 +/- 3013368.88) (49844848.90 -> 85771436.40) seconds time elapsed: 304.7994% +/- 1.7436% (13.22 +/- 0.08) (4.34 -> 17.56) seconds user: 336.2468% +/- 1.5576% (11.94 +/- 0.06) (3.55 -> 15.49) seconds sys: 165.8816% +/- 7.6178% (1.28 +/- 0.06) (0.77 -> 2.05) ``` Change-Id: I048a6031e3d6bb56896fa28077b5e7ddf9add810 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452783 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent a82aa2f commit 273fe8e

File tree

3 files changed

+89
-14
lines changed

3 files changed

+89
-14
lines changed

pkg/analyzer/lib/src/dart/scanner/scanner.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:analyzer/src/dart/analysis/experiments.dart';
1717
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
1818
import 'package:analyzer/src/dart/scanner/reader.dart';
1919
import 'package:analyzer/src/error/codes.dart';
20+
import 'package:meta/meta.dart';
2021
import 'package:pub_semver/pub_semver.dart';
2122

2223
export 'package:analyzer/src/dart/error/syntactic_errors.dart';
@@ -32,6 +33,11 @@ export 'package:analyzer/src/dart/error/syntactic_errors.dart';
3233
class Scanner {
3334
static final Uint8List _lineStartsZero = Uint8List(0);
3435

36+
/// Allows to - by default - either preserve or not preserve comments while
37+
/// testing.
38+
@visibleForTesting
39+
static bool preserveCommentsDefaultForTesting = true;
40+
3541
final Source source;
3642

3743
/// The text to be scanned.
@@ -50,7 +56,7 @@ class Scanner {
5056
late final FeatureSet _featureSetForOverriding;
5157

5258
/// The flag specifying whether documentation comments should be parsed.
53-
bool _preserveComments = true;
59+
bool _preserveComments = preserveCommentsDefaultForTesting;
5460
List<int>? _lineStarts;
5561
late final Token firstToken;
5662

pkg/analyzer/tool/stable_analysis.dart

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,51 @@
55
import 'dart:io';
66

77
import 'package:analyzer/error/error.dart';
8+
import 'package:analyzer/src/clients/build_resolvers/build_resolvers.dart';
89
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
910
import 'package:analyzer/src/dart/analysis/driver.dart';
1011
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
1112
import 'package:analyzer/src/dart/analysis/file_state.dart';
1213
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
14+
import 'package:analyzer/src/dart/scanner/scanner.dart';
15+
import 'package:analyzer/src/lint/registry.dart' as linter;
1316
import 'package:linter/src/rules.dart' as linter;
1417

1518
void main(List<String> args) {
1619
String? dirPath;
17-
bool registerLints = true;
20+
bool silent = false;
21+
bool lints = true;
22+
bool warnings = true;
23+
bool comments = true;
1824
bool dumpPerformanceNumbers = false;
25+
// Hardcoded for now, but could be interesting to try them one at a time and
26+
// see what the cost of each individual lint is.
27+
Set<String> wantedLints = {
28+
"collection_methods_unrelated_type",
29+
"curly_braces_in_flow_control_structures",
30+
"depend_on_referenced_packages",
31+
"prefer_adjacent_string_concatenation",
32+
"unawaited_futures",
33+
"avoid_void_async",
34+
"recursive_getters",
35+
"avoid_empty_else",
36+
"empty_statements",
37+
"valid_regexps",
38+
"lines_longer_than_80_chars",
39+
"unrelated_type_equality_checks",
40+
"annotate_overrides",
41+
"always_declare_return_types",
42+
};
1943

2044
for (String arg in args) {
21-
if (arg == "--no-lints") {
22-
registerLints = false;
45+
if (arg == "--silent") {
46+
silent = true;
47+
} else if (arg == "--no-lints") {
48+
lints = false;
49+
} else if (arg == "--no-warnings") {
50+
warnings = false;
51+
} else if (arg == "--no-comments") {
52+
comments = false;
2353
} else if (arg == "--dump-performance") {
2454
dumpPerformanceNumbers = true;
2555
} else if (!arg.startsWith("--") && dirPath == null) {
@@ -28,11 +58,8 @@ void main(List<String> args) {
2858
throw "Unknown argument: $arg";
2959
}
3060
}
31-
32-
if (registerLints) {
33-
linter.registerLintRules();
34-
}
3561
if (dirPath == null) throw "Needs a directory to work on.";
62+
if (dirPath.endsWith("/")) dirPath = dirPath.substring(0, dirPath.length - 1);
3663
Directory dir = Directory(dirPath);
3764
List<String> filesToAnalyze = [];
3865
for (FileSystemEntity entity in dir.listSync(
@@ -44,6 +71,13 @@ void main(List<String> args) {
4471
}
4572
}
4673

74+
if (lints) {
75+
linter.registerLintRules();
76+
}
77+
78+
// ignore: invalid_use_of_visible_for_testing_member
79+
Scanner.preserveCommentsDefaultForTesting = comments;
80+
4781
// Creating the Scheduler here, and not starting it, means it's not going to
4882
// get started. It's good for stability :).
4983
// To make sure the 'start' method is overwritten below.
@@ -54,6 +88,20 @@ void main(List<String> args) {
5488
AnalysisContextCollectionImpl collection = AnalysisContextCollectionImpl(
5589
includedPaths: [dir.path],
5690
scheduler: scheduler,
91+
updateAnalysisOptions4: ({required AnalysisOptionsImpl analysisOptions}) {
92+
analysisOptions.warning = warnings;
93+
analysisOptions.lint = lints;
94+
if (lints) {
95+
int added = 0;
96+
for (var rule in linter.Registry.ruleRegistry.rules) {
97+
if (wantedLints.contains(rule.name)) {
98+
analysisOptions.lintRules.add(rule);
99+
added++;
100+
}
101+
}
102+
if (!silent) print("Enabled $added lints");
103+
}
104+
},
57105
);
58106
DriverBasedAnalysisContext context = collection.contexts[0];
59107
AnalysisDriver analysisDriver = context.driver;
@@ -76,7 +124,7 @@ void main(List<String> args) {
76124
for (var unit in library.units) {
77125
for (var diagnostic in unit.diagnostics) {
78126
if (diagnostic.diagnosticCode.type == DiagnosticType.TODO) continue;
79-
print(diagnostic);
127+
if (!silent) print(diagnostic);
80128
}
81129
}
82130
}

pkg/front_end/tool/compile_files_in_folders.dart

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,39 @@ import '../test/utils/io_utils.dart' show computeRepoDirUri;
2020

2121
final Uri repoDir = computeRepoDirUri();
2222

23-
Future<void> main(List<String> args) async {
23+
Future<void> main(List<String> argsOrg) async {
24+
bool silent = false;
25+
List<String> args = [];
26+
for (String arg in argsOrg) {
27+
if (arg == "--silent") {
28+
silent = true;
29+
} else if (arg.startsWith("--")) {
30+
// Ignore other non-path arguments for better compatibility with the
31+
// stable analysis tool (and thus comparison with the analyzer).
32+
continue;
33+
} else {
34+
args.add(arg);
35+
}
36+
}
2437
Stopwatch stopwatch = new Stopwatch()..start();
25-
await run(args);
26-
print("Finished in ${stopwatch.elapsed}");
38+
await run(args, silent);
39+
if (!silent) {
40+
print("Finished in ${stopwatch.elapsed}");
41+
}
2742
}
2843

29-
Future<void> run(List<String> args) async {
44+
Future<void> run(List<String> args, bool silent) async {
3045
api.CompilerOptions compilerOptions = getOptions();
3146

3247
ProcessedOptions options = new ProcessedOptions(options: compilerOptions);
3348

3449
Set<Uri> libUris = {};
3550
Set<Uri> packageConfigUris = {};
3651
for (String arg in args) {
52+
if (!arg.endsWith("/")) {
53+
// Assume directory.
54+
arg = "$arg/";
55+
}
3756
Uri dir = Uri.base.resolveUri(new Uri.file(arg));
3857
libUris.add(dir);
3958
while (!File.fromUri(
@@ -71,7 +90,9 @@ Future<void> run(List<String> args) async {
7190
new CompilerContext(options),
7291
);
7392
IncrementalCompilerResult result = await compiler.computeDelta();
74-
print("Got ${result.component.libraries.length} libraries.");
93+
if (!silent) {
94+
print("Got ${result.component.libraries.length} libraries.");
95+
}
7596
}
7697

7798
api.CompilerOptions getOptions() {

0 commit comments

Comments
 (0)