You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[front_end] Fix bootstrapping of message generation.
The dart formatter depends on `package:analyzer`, which depends on the
code generated diagnostic message file
`pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart`. This
means that if the code generator for this file tries to format it
using the formatter's programmatic API (the `DartFormatter` class),
there will be a bootstrapping problem, because the code generator will
include the generated file in its transitive imports.
To avoid this, `generate_messages.dart` is changed so that it first
writes out an unformatted file, and then uses the `DartFormat` class
(from `package:analyzer_utilities`) to do the formatting. The
`DartFormat` class runs `dart format` as a subprocess, so it doesn't
depend have to import `package:analyzer`.
In addition to fixing the bootstrapping problem, this has two side
benefits:
- By avoiding the import of `package:analyzer`, it makes the code
generator run much faster. I see approximately a 4x speedup.
- Previously, if formatting failed due to a syntax error in the
generated code, it no output would be generated, making the bug
difficult to diagnose. Now, if the generated code contains a syntax
error, the unformatted file is left on disk.
A previous fix for the bootstrapping problem
`generate_messages_failsafe.dart`, didn't have these advantages. It is
removed since it's no longer needed.
The test `generated_files_up_to_date_git_test.dart` is updated so that
it does the formatting using the `DartFormatter` class. This isn't a
problem for bootstrapping, because this test is only required to work
properly when the code is in a fully generated state.
Note that the code generator can also be invoked indirectly through
the `pkg/front_end/tool/cfe.dart` tool. This, unfortunately, still has
the bootstrapping problem, so a hint message is added to `cfe.dart` to
encourage the user to run `generate_messages.dart` directly.
Change-Id: I6a6a6964fec4259a4462c6ec5204fea2dcd28314
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447920
Commit-Queue: Paul Berry <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
0 commit comments