Aleksey Kladov
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Batch vs Server architecture for stripped down RLS ## Links Part of an ongoing conversation about reconciling RLS and rust-analyzer. See the [master document](https://hackmd.io/9qrJYdSLTK2MWG4-pbmpWw) which indexes all the various hackmds. ## Goals Bring critical functionality, which needs precision, from RLS to rust-analyzer: * correct error highlighting * find usages/rename Notes: * There will be a flag to choose between "native" and "save-analysis based" implementations of these features * find usages and rename are *rare* features, not every changes triggers them * both approaches are temporary crutches, until rust-analyzer-like analysis infrastructure matures and we'll be able to *just* run every analysis precisely in an IDE setting ## Approaches ### Stripped down RLS server (filled-in my @matklad, may contain major misunderstandings) #### Implementation Strategy First phase: in rust-analyzer, we add ability to spawn RLS process and forward some requests to it. Second phase: we strip down code in RLS by: * replacing save-analysis with using compiler's in-memory data structures * removing code responsible for features other than find usages and rename * removing code responsible for passing file diffs (?) nikomatsakis: I'm not sure that it's really a goal to replace save-analysis. That seems like a lot of work which kind of duplicates the effort of building up the analogous structures in rust-analyzer. At the same time, I wouldn't call it *not* a goal. Regarding file diffs, there's a real question there: maybe it's easy enough for rust-analyzer to feed in "open files and diffs" to the "backend RLS" server, which then avoids the problem of forcing "find all usages" to require files be saved? (Can an LSP implementation even force the editor to save files? Would that be something we would have to do in the plugin?) #### Benefits * stable interface, not something ad-hoc we have to experiment with * ability to stay resident means that repeated uses will be faster * you could still wait to start it (and potentially ask it to quit after some time) to control memory usage * closer to the existing RLS (basically it would be kind of stripped down) * can maybe literally start *as* the existing RLS? * we can remove save-analysis altogether, as nobody is happy with it in its current form (but some people think that some data formant *like* save-analysis is nice to have eventually) * the approach looks like it moves in the general direction of the end-state we want to see #### Drawbacks * we still maintain significant chunks of RLS, in particular: * code that marries single-crate world of rustc with multi-crate world of Cargo * code that links to cargo and re-does build logic * we still have `#[feature(rustc_private)]` in the build, meaning that we tie build process to the build process of rustc itself * replacing save-analysis with in-memory data structures is work * overall complexity seems higher, since we need to juggle persistent processes, instead of shelling out to batch processes * hard to support non-cargo build systems ### "CLI" tool for batch analysis of save-analysis files #### Implementation Strategy No code is shared with RLS server. We re-use existing libraries for reading save-analysis data (rls-analysis, rls-span, etc). No changes to rustc or cargo. For error highlighitng, rust-analyzer runs `cargo check --message-format=json`. For find-usages, rust-analyzer runs `RUSTFLAGS=-Zsave-analysis cargo check`, then reads save-anlysis data. User can override these command-line invocations. We require that client saves all modified documents before issuing these requests. nikomatsakis: What happens when user is not using nightly? Then `-Zsave-analysis` isn't available. nikomatsakis: The LSP server itself can't require the client to save all modified documents, right? So this would require all editor plugins to be aware of these changes? #### Benefits * no changes to rls/rustc/cargo are required, all bits are already in place * we don't have to maintain RLS tool anymore (but we might want for some time, to smooth out the transition) * no component uses `#[feature(rustc_private)]`, no component blocks rustc's CI, everything builds with `cargo build` * supports all cargo builds out of the box * supports other build system with some effort * guaranteed correct build environment, by construction (as we shell out to the build system) #### Drawbacks * we need to find a way to use `-Zsave-anlysis` on stable without stabilizing save-analysis. @matklad thinks that just setting `RUST_BOOTSTRAP=1` from rust-analyzer is fine (and can explain it), but this would be a controversial issue, and we might need to invent something more official. A straw-man would be `tools_unstable` for non-language features that exist on stable, can't affect the build in any way, will change with next releases and are targeted for tools which explicitly track revision of compiler. * nikomatsakis: Just setting RUST_BOOTSTRAP=1 would also allow access to feature gates... I guess that this would only be used for the "find all usages" command, though. * nikomatsakis: There is a "de facto" dependency between rust-analyzer and the version of rustc in use (i.e., if we change the save-analysis format, it would break rust-analyzer). Unless rust-analyzer is distributed (and versioned) with rustup, this seems like it will be error-prone and difficult to manage. (But we could well distribute rust-analyzer with rustup) * matklad: there's already a "de facto" dependency. rust-ananlzyer analysis std library from source, and so it has to support nightly features even for stable toolchain. It also hard-codes the set of crates in sysroot (including private ones) and their dependencies. The same applies to IntelliJ Rust. * not instant performance: the time is that of `cargo check` plus serializing/deserializing save analysis. * this is explicitly throw away code. By itself, it's not a part of the end-game solution. * will require editor plugins to be updated to force save before executing those commands (and then, once we have things working, to stop requiring that) ### "CLI" tools distributed with rustup #### Implementation strategy Similar to above, except that the tools are executables distributed with rustup as part of distributing the "RLS". They encapsulate the use of save-analysis, simply spitting back results to rust-analyzer in some unspecified format. This is very similar to forwarding requests to the RLS, except it doesn't require maintaining multiple processes, but also comes with the latency and other down-sides of running batch commands. (Internally, these tools could "shell out" to cargo to gather the save-analysis data.) #### Benefits * relative to having rust-analyzer directly consume save-analysis, this encapsulates the knowledge of save-analysis into a distinct tool #### Drawbacks * this is a new tool with new options; we can specify that it may not continue to exist, but people could come to rely on it * not sure if there are possible mitigations here * not instant performance: the time is that of `cargo check` plus serializing/deserializing save analysis. * this is explicitly throw away code. By itself, it's not a part of the end-game solution. * will require editor plugins to be updated to force save before executing those commands (and then, once we have things working, to stop requiring that)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully