Skip to content

Stop using rustc_private libraries #364

@fw-immunant

Description

@fw-immunant

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 Make approach from c2rust-ast-builder/src/builder.rs requires the ability to construct AST nodes from scratch. This works perfectly with syn but is somewhat at odds with the approach from ra_ap_syntax, which exposes a limited interface in ra_ap_syntax::ast::make but with which it's much harder to build constructs like extern blocks--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. syn treats comments as whitespace, which makes them substantially harder to preserve compared to ra_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions