HackMD
    • 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
    # Polonius notes ## 1. Make it work ### Correctness 1. With [PR #64749](https://github.com/rust-lang/rust/pull/64749) the single remaining rustc UI test failure was fixed (and also re-enabled a liveness optimization in rustc) apart from a couple OOMs. 2. Tests succeed except for said OOMs: - `ui/numbers-arithmetic/saturating-float-casts.rs` is materializing 10 948 x 136 664 outlives constraints (15GB+; i.e. materializing placeholder region subsets at all points of the CFG) [here](https://github.com/rust-lang/rust/blob/8301de16dafc81a3b5d94aa0707ad83bdb56a599/src/librustc_mir/borrow_check/nll/type_check/mod.rs#L229-L233). (The NLL MIR dump is 200MB+, the .dot files are 15MB+ and fail to generate a png on my machine, as I was trying to check these regions' SCCs) - since then, another similar OOM-ing test was added: `ui/wrapping-int-combinations.rs` (it's possible new ones have been added since I last checked) These are similar to the cases we had during NLL dev: where some tests with lots of `assert_eq!` were slow, and faster when switching to regular `assert!`. (I think we talked about this materializing as being the "`Location::All` hack" which we could/would remove, but didn't since it's technically correct ? or maybe I'm confusing with the similar situation with NLLs) Note that a lot of those are actually equal origins, and that the "equality variant" could help here, by storing them in a dedicated relation (though this can be done for the Naive/DatafrogOpt variants, but don't map as cleanly) though we'd need to make sure the datalog rules themselves don't end up materializing the same huge number of tuples when computing the subsets TC. 3. Not all Polonius errors actually show up as rustc errors (examples in the UI test suite and `rand` when killing loans on `Call`s only; 7 of the run-pass tests which pass in rustc fail if we assert that there should be no Polonius errors): ``` [run-pass (polonius)] run-pass/array-slice-vec/check-static-mut-slices.rs [run-pass (polonius)] run-pass/array-slice-vec/check-static-slice.rs [run-pass (polonius)] run-pass/consts/const-vec-of-fns.rs [run-pass (polonius)] run-pass/drop/dynamic-drop-async.rs [run-pass (polonius)] run-pass/generator/addassign-yield.rs [run-pass (polonius)] run-pass/generator/issue-52398.rs [run-pass (polonius)] run-pass/generator/static-generators.rs ``` There were more cases like this in the ui tests, but run-pass was easier to capture at the time. I've started looking at a couple cases and they seemed related to statics, maybe they all are ? 4. Ensuring correctness and non-regressions, by enabling the polonius compare mode on CI. Current blockers: * the previously mentioned OOMs on materializing placeholder region subsets at all points of the CFG * performance ? need to quantify the slowdown to see whether it's a blocker (last I checked it was slower but not particularly bad) ### Completeness 1. illegal subset relations (more details in [this blogpost](http://smallcultfollowing.com/babysteps/blog/2019/01/17/polonius-and-region-errors/)) - Placeholder loans technique implemented, which is not described in the blogpost (but prototyped in [a branch whose main logic is here](https://github.com/lqd/borrow-check/blob/174980ab299110feddae2217573dbe02e6535bcf/polonius-engine/src/output/naive.rs#L196-L216)) in both `Naive` and `Datafrogopt`, simple tests seem to work but not yet reviewed or in a PR - Some open questions in the [dedicated zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/placeholder.20loans), e.g. about rustc integration (how to emit these placeholder loans facts, but also would we "just" need to change `RegionInferenceContext::check_universal_regions` to instead look at the Polonius errors when in `-Zpolonius` mode). - Possible concern about the impact on `LocationInsensitive`, and thus `Hybrid`, variants - Once the ["context PR #134"](https://github.com/rust-lang/polonius/pull/134) is finalized, a placeholder loans PR can be opened (with book updates describing the facts and rules), but tests might be hard to write until rustc is modified to emit those facts so that we can reuse the existing tests 2. are there still NLL optimizations disabled in Polonius mode ? (there was one such disabled optimization about computing liveness, but was removed in [PR #64749](https://github.com/rust-lang/rust/pull/64749)) 3. Higher-rank subtyping, and relation to Chalk, so a lot of overlap with wg-traits. The problem is described in more detail in [this blog post](http://smallcultfollowing.com/babysteps/blog/2019/01/21/hereditary-harrop-region-constraints/), but most of the solutions design work and plan to fix are not yet written down (but some explorations have been done already IIRC) 4. Move/initialization analysis - possibly almost complete on the Polonius side with [PR #135](https://github.com/rust-lang/polonius/pull/135) ### Precision The "flow-sensitive equality" variant which better distinguishes instantaneous data flow from persistent data flow: - even if this endeavour also started to avoid tracking subsets along the CFG, it seems a TC of the `equal` origins must also be done. So the variant seems similar to the `Naive` variant operationally (but in practice is a bit worse in the current implementation, but that can be improved) - [dedicated zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/equality.20regions) (where most recently I was "live-zuliping" the analysis of a test failure which lead to me to the need for the TC) - WIP implementation [in this branch](https://github.com/lqd/borrow-check/blob/variant_prototype2/polonius-engine/src/output/prototype.rs), still not 100% correct: 2 failures on rustc tests, for code which should apparently fail to compile but passes (more details in the thread, [around here](https://rust-lang.zulipchat.com/#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/equality.20regions/near/177823183)) --- ## II. Make it good ### 1. refactoring: - finalizing naming/terminology: some of that has already been done, but still needs to be done in the relation names, the parser, etc (for the previous renaming of, say, `regions` to `origins`, but also we were looking for more representative relation names, like renaming the `requires` relation to `contains` or similar). - code organization: * in polonius itself, eg unit tests written as-is won't really scale (and we need to figure out our relation with rustc's tests, as those are not checked in the Polonius CI when we do PRs) * fact generation in rustc is a bit ad-hoc and spaghetti (understandably so, but we can probably make it clearer) -> [issue #117](https://github.com/rust-lang/polonius/issues/117) is a proposal about this * passing data between rustc and polonius, eliminating clones, sharing data between Polonius steps (and not just partial resuts between the locinsensitive and regular analysis, but also input data: no need to create Relations multiple times) * the more analyses polonius does, the less a single type of errors makes sense in the communication between rustc and polonius -> the ["context PR"](https://github.com/rust-lang/polonius/pull/134) proposal helps with the previous two points (but does not fix some of the cloning of `AllFacts` since rustc does not give ownership of the facts yet) * taking better control of allocation, which is related to both code organization and performance (and datafrog) ### 2. Misc - leapjoins/datafrog: encode WF-ness of leapjoins in the API if possible, loosen the requirements so we can have leapjoins that only filter - a plan for testing (maybe also better architecture/tools for writing tests): testing is still better done in rustc, which is unfortunate/hard. Do we copy all of rustc's tests, how do we synchronize facts ? - is the optimized variant still necessary ? (what about the location insensitive one ?) - docs: beginnings of the book have been merged; it's built on CI and hosted on GH pages [here](https://rust-lang.github.io/polonius/) -> there's a [WIP doc PR](https://github.com/rust-lang/polonius/pull/126) which is almost ready to go: only a question remains about the expected terminology of universal regions (and then renaming CFG "nodes" back to "points") - more videos ? - issues for new contributors / quest issues / etc - try to make tests faster to compile (might require moving away from lalrpop) to follow-up on [PR #128](https://github.com/rust-lang/polonius/pull/128) which did this for the regular `polonius-bin` - upstreaming some tools into datafrog: basic tracing "provenance" information, rule transformations and datalog-to-datafrog skeleton generator (at the moment located in [an external repo](https://github.com/lqd/datapond)) --- ## III. Make it fast - pushing the filtering as early as possible: on loans, regions, subsets. Different prototypes have been done, in the liveness and borrowcking phases, (on both limiting tracking only loans which could end up in errors, and on the ones pre-filtered by `LocationInsensitive`) and are only waiting on more progress on the completeness front to be turned into PRs - datafrog leapjoins (and the WF-ness question) - maybe the more precise "equality variant" has different performance characteristics (static equality in particular is among the fastest, while flow-sensitive equality seems similar to the Naive one) - CFG compression (but heavy filtering seems to have even more of a performance boost; maybe combining both would be interesting, as it seems sensible to have a specialized data structure to compute some analyses, maybe arielb's iterated dominance frontier but I'm not sure yet I agree/understand it makes sense for liveness per se) - benchmarking effort: Albin has lots of benchmarks and data but imprecise as timing the polonius binary and not polonius-engine itself or rustc; lokalmatador was working on instrumenting rustc with measureme/-Z self-profile but deleted their github account so this WIP work is lost - Comment: I have been considering reimplementing roughly the same analysis again as an execution mode of polonius-cli. Would that make sense? E.g. `polonius --benchmark-to-tsv=results.tsv folder` would take a folder of inputs by crate (i.e. `folder/clap/nll-facts/` and so on) and produce a TSV with the results per function and crate. The advantage to what I have now is more precision (and also the ability to time the different steps), and the ability to do analysis on outputs as well, including intermediate ones. -- Albin - out of the 2 datasets I have access to, here are some stats about interesting crates/functions to look at: [first batch](https://gist.github.com/lqd/51344ae68afb576d4d8ee48ac47a536e#file-first-txt), [second batch](https://gist.github.com/lqd/51344ae68afb576d4d8ee48ac47a536e#file-second-txt) - also, while this benchmarking will help inform and improve polonius and rustc's fact generation, it will not yet provide information on the parts of NLLs which could be replaced by Polonius - the liveness work ended up regenerating clap which made it 2x faster, maybe we can add the old version if it's a better benchmark ? (then again, this better performance is because of rustc improvements and bugfixes, so the new data is definitely more realistic towards what one would experience using polonius on the same piece of code) - is it possible/easy to compare liveness via polonius vs the existing liveness computations ? can we measure NLL borrowck with just "polonius liveness" ? would that data be useful ? - optimizing datafrog itself: can we use subsumptive tabling (and DTs, so this is related to "datapond") ? sorting networks w/ SIMD ? integer compression and intersection (surely via SIMD as well) ? specific hash joins or bitmap structures, for relations known to be "small" (a bounded max number of tuples really), or where the query structure can allow it (more notes about these possible the specialized `Relation`s can be found in a [dedicated zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/notes.20on.20datafrog)) ? parallelizing the 3 joins/steps per iteration of the semi-naive evaluation ?

    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