-
Notifications
You must be signed in to change notification settings - Fork 294
Stop using rustc_private libraries #364
Description
The rustc_private libraries (rustc, rustc_target, syntax, etc., as used in c2rust-ast-builder and elsewhere in c2rust) couple the version of the compiler used to build c2rust to the versions of these crates upon which c2rust depends. As a result, we require users to use a quite old nightly to build c2rust.
This keeps us on an old rustc and impedes development velocity. We should instead use an AST library that lives on crates.io and does not lock us to a specific rustc version.
The major options here are the AST provided by rust-analyzer (on crates.io as ra_ap_syntax) and the AST implementation in syn.
Both are capable of production-quality Rust parsing, but we have more specific needs:
- The
Makeapproach fromc2rust-ast-builder/src/builder.rsrequires the ability to construct AST nodes from scratch. This works perfectly withsynbut is somewhat at odds with the approach fromra_ap_syntax, which exposes a limited interface inra_ap_syntax::ast::makebut with which it's much harder to build constructs likeexternblocks--generally the API is intended for immutable access to an AST over a static string, not for building an AST dynamically. - We want to preserve comments so that programmer intent is carried along to facilitate further manual porting/refactoring of code translated by c2rust.
syntreats comments as whitespace, which makes them substantially harder to preserve compared tora_ap_syntax, which has a token kind for them.
The current plan (to enable cleanups and facilitate continued development) is to first port the transpiler from libsyntax/etc. to some versioned Rust AST crate, porting the refactoring tool later. In any event, we probably want to end up with the same AST library for both the transpiler and the rewriter if at all possible. Because the rewriter also considers it critical to preserve even non-doc comments, I think (short of patching syn) that rust-analyzer's libs are the only way to go.
I'm working on this port right now and will hopefully have a PR up soon.