Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proc_macro/bridge: stop using a remote object handle for proc_macro Ident and Literal #98189

Merged
merged 5 commits into from
Jul 19, 2022

Commits on Jul 18, 2022

  1. proc_macro: use fxhash within the proc_macro crate

    Unfortunately, as it is difficult to depend on crates from within proc_macro,
    this is done by vendoring a copy of the hasher as a module rather than
    depending on the rustc_hash crate.
    
    This probably doesn't have a substantial impact up-front, however will be more
    relevant once symbols are interned within the proc_macro client.
    mystor committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    17e9687 View commit details
    Browse the repository at this point in the history
  2. proc_macro: Specialize Punct::to_string

    This was removed in a previous part, however it should be specialized for
    to_string performance and consistency.
    mystor committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    e0dce6e View commit details
    Browse the repository at this point in the history
  3. proc_macro: stop using a remote object handle for Ident

    Doing this for all unicode identifiers would require a dependency on
    `unicode-normalization` and `rustc_lexer`, which is currently not
    possible for `proc_macro` due to it being built concurrently with `std`
    and `core`. Instead, ASCII identifiers are validated locally, and an RPC
    message is used to validate unicode identifiers when needed.
    
    String values are interned on the both the server and client when
    deserializing, to avoid unnecessary copies and keep Ident cheap to copy and
    move. This appears to be important for performance.
    
    The client-side interner is based roughly on the one from rustc_span, and uses
    an arena inspired by rustc_arena.
    
    RPC messages passing symbols always include the full value. This could
    potentially be optimized in the future if it is revealed to be a
    performance bottleneck.
    
    Despite now having a relevant implementaion of Display for Ident, ToString is
    still specialized, as it is a hot-path for this object.
    
    The symbol infrastructure will also be used for literals in the next
    part.
    mystor committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    491fccf View commit details
    Browse the repository at this point in the history
  4. proc_macro: stop using a remote object handle for Literal

    This builds on the symbol infrastructure built for `Ident` to replicate
    the `LitKind` and `Lit` structures in rustc within the `proc_macro`
    client, allowing literals to be fully created and interacted with from
    the client thread. Only parsing and subspan operations still require
    sync RPC.
    mystor committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    b34c79f View commit details
    Browse the repository at this point in the history
  5. proc_macro: Move subspan to be a method on Span in the bridge

    This method is still only used for Literal::subspan, however the
    implementation only depends on the Span component, so it is simpler and
    more efficient for now to pass down only the information that is needed.
    In the future, if more information about the Literal is required in the
    implementation (e.g. to validate that spans line up as expected with
    source text), that extra information can be added back with extra
    arguments.
    mystor committed Jul 18, 2022
    Configuration menu
    Copy the full SHA
    c4acac6 View commit details
    Browse the repository at this point in the history