Add --print-json=...
flag
#860
Labels
major-change
A proposal to make a major change to rustc
T-compiler
Add this label so rfcbot knows to poll the compiler team
Proposal
Summary
Add an unstable
--print-json={print_requests...}
compiler flag which allows combining multiple print requests and outputs machine-consumable JSON lines, one line for each print request, which are more friendly for tooling.Example output (format illustrative, exact shape/format subject to further experimentation)
Prior discussions:
Motivation: make (multiple) print request output more tool-friendly
Presently,
rustc --print=print_request_1,print_request_2
will simply concatenate the output of both print requests with no clear delimitation. For instance, cargo has to resort to using a___
crate name hack to delimit output between e.g.--print=split-debuginfo
and--print=cfg
for the samerustc
invocation (as cargo wants to avoid incurring multiplerustc
invocation overhead).Properly outputting multiple JSON lines will clearly delimit output between multiple print requests and thus allow cargo to not need this hack (for newer
rustc
versions that has--print-json
).JSON lines are also more tooling friendly, as tools can use e.g.
serde_json
to derive deserializers for print request output, instead of having to invent/implement adhoc parsers for different print requests that outputs slightly different formats (where we don't have clearly stated stability guarantees re. their output formats or content).Stability guarantees and the lack thereof
The message container "shape"
The "skeleton" message container shape of
{"message-type": "print", "id": "$print-request-name", "value": /* form-differs-per-print-request */ }
would be guaranteed stable.This is subject to further bikeshedding/design/experimentation.
Shape of individual print requests
The stability of the shape of the
value
(of the message container above; i.e. print request output) is delegated to individual print requests.Unstable print requests
Given multiple print requests (e.g.
--print-json=p1,p2
),-Z unstable-options
will be required if any print requests are unstable (usual print request stability apply).Valid values / output of individual print requests
Delegated to individual print requests.
Alternative:
--error-format=json
+--print=...
?I have considered using existing
--error-format=json
+--print=...
to encode--print-json=...
. However, the flag iserror-format
, which IMO is confusing because print requests are arguably not error messages.Path to stabilization
This will need to go through some experimentation to determine if the output shape is tool-friendly and iron out possible quirks.
A proposal for stabilization of this flag will need to go through usual compiler FCP progress.
Special attention should be paid to figuring out and documenting the stability guarantees surrounding the output shape/format of this flag, and its interactions with individual print request stability guarantees.
Unresolved questions
Mentors or Reviewers
@bjorn3, @Urgau or compiler
cc @weihanglo and @epage as we discussed what cargo needs regarding print requests.
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
The text was updated successfully, but these errors were encountered: