lcnr
    • 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
      • Invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • 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
    • Engagement control
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control 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
Invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
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
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
## paperclip-core breakage The following example fails to pass coherence with the new solver due to an interaction of two separate design decisions. ```rust struct W<T: ?Sized>(T); trait NoImpl {} trait Unconstrained { type Assoc; } impl<T: Unconstrained<Assoc = U>, U: NoImpl> Unconstrained for W<T> { type Assoc = U; } trait Overlap {} impl<T: Unconstrained<Assoc = ()>> Overlap for T {} impl<U> Overlap for W<U> {} ``` ### Nested goals are evaluated eagerly In the new solver evaluating a goal does not return nested goals. We instead handle them eagerly and recompute the whole goal later if any nested goal remains ambiguous. This is different from the old implementation where evaluation *selects* a unique candidate and then pushes all nested obligations to the caller. ### `normalizes-to` is a function When proving that an associated item normalizes to a given term, we do so in two steps. We first normalize the associated item, returning the normalized-to term, and then equate that term with the expected term. This is implemented by always replacing the expected term with an unconstrained inference variable when evaluating a `NormalizesTo` goal: [source](https://github.com/rust-lang/rust/blob/ee03c286cfdca26fa5b2a4ee40957625d2c826ff/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs#L38-L59). ## A walkthrough of the concrete regression The old solver errors when proving `W<?t>: Future<Assoc = ()>` while the new solver stalls with ambiguity. In the old solver, we prove `Projection(<W<?0> as Unconstrained>::Assoc, ())`, this first normalizes `<W<?0> as Unconstrained>::Assoc` to `?1`, returning the nested goals `[Projection(<?0 as Unconstrained>::Assoc, ?1), Trait(?1: NoImpl)]`. We then equate `?1` with `()`, and attempt to prove the nested goals. Proving `(): NoImpl` then errors. In the new solver, we prove `Projection(<W<?0> as Unconstrained>::Assoc, ())`, this first normalizes `<W<?0> as Unconstrained>::Assoc` to `?1`. Normalization tries to eagerly prove `[Projection(<?0 as Unconstrained>::Assoc, ?1), Trait(?1: NoImpl)]`. These goals are still ambiguous at this point. Normalization therefore returns `?1` as the normalized-to term and discards the nested goals, forcing the certainty to `Maybe`. We then unify `?1` with `()`. However, we never get to prove `?1: NoImpl` as attempting the normalization again still does not use the term. As a simplified proof tree: - `Projection(<W<?0> as Unconstrained>::Assoc, ())` - `NormalizesTo(<W<?0> as Unconstrained>::Assoc, ?1)` replace expected term with unconstrained infer - `Trait(?1: NoImpl)` ~> ambig - `Eq(?1, ())` - `NormalizesTo(<W<?0> as Unconstrained>::Assoc, ?2)` we would replace expected term with a new unconstrained infer ~> still ambig ## Why is the new behavior desirable ### Nested goals are evaluated eagerly Always returning nested goals is clearly undesirable. We need to evaluate nested goals anyways if there are multiple candidates for which matching the impl header succeeds. Having to reevaluate these nested goals later on causes duplicate work. This is the case with the old solver. Returning nested goals likely also causes issues if we ever decide to get better at merging candidates. This is currently not an issue as we only prefer trivial candidates over others and never merge them. If we already have to evaluate nested goals sometimes, it seems easier to just attempt to do it whenever possible. We previously avoided to return nested goals at all to reduce complexity by only supporting eager evaluation. ### `normalizes-to` is a function This both improves performance by allowing us to cache normalization once for each alias, reusing it for each expected term. More importantly, it's a very easy way to prevent the expected term from impacting normalization, cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/22 ## Can users avoid this regression My vibe is that the above pattern cannot be expressed with the new solver. This breakage is a fundamental restriction to the kinds of pattern which can be expressed. If we have a where-bound `T: Trait<Assoc = U>`, there's no way to have the expected associated type interact with the nested goals of the normalization/trait goal. I am unable to prove it, but I believe there to be no good way to fix `paperclip-core` without removing one of the impls. ## Can we avoid this issue in the new solver ### Pushing knowledge about the expected term into `normalizes-to` The idea here would be when creating a new inference var for `U` in `<?t as Unconstrained>::Assoc = ?u` we put `<?t as Unconstrained>::Assoc normalizes-to ?u` in the environment if `?u` is created inside of a query and not constrained by an input of it. We discard this info if any of the inference variables involved in the alias get constrained. We add this info to `QueryInput` of all queries whose goal references all involved inference variables. With this, `Projection(<W<?0> as Unconstrained>::Assoc, ())` would compute `NormalizesTo(<W<?0> as Unconstrained>::Assoc, ?1)` which adds `<?0 as Unconstrained>::Assoc normalizes-to ?1` to the environment. We then unify `?1` with `()`. When recomputing `NormalizesTo(<W<?0> as Unconstrained>::Assoc, ?1)` we now have `<?0 as Unconstrained>::Assoc normalizes-to ()` in the environment, which we keep around as only the expected term, but not the alias, has changed. When now trying to normalize `<?0 as Unconstrained>::Assoc` inside of this nested goal, we immediately return `()` instead of using a nested `AliasRelate` goal. This is non-trivial, likely has issues with region uniquification and probably has a significant perf impact. ### Propagate nested goals out of `normalizes-to` Put the nested goals of `NormalizesTo` into its `Response` and then handle them inside of the `AliasRelate` call. Implemented in https://github.com/rust-lang/rust/pull/122687.

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 verison 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