Rust Types Team
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • 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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Help
Menu
Options
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # projection normalizes-to mismatch previous doc: https://hackmd.io/noGGefTfQ0eCARFb3D0tJw ```rust fn next<T: Iterator<Item = U>, U>(t: &mut T) -> Option<U> { t.next() } fn foo<T: Iterator>(t: &mut T) { let _: Option<T::Item> = next(t); // `next` here uses `T::Item` for `U` so // `normalizes-to` doesn't work. } ``` `Projection` in the environment is treated solely as `normalizes-to`. We use `Projection` bounds to normalize without checking whether the `term` is equal to the associated type. As a goal, `Projection` can be fulfilled using `alias-eq`. This means that `Projection` as an assumption is stronger than what we need to prove when it's used as a requirement. ## possible solutions I believe the only way to solve this in a reasonable timeframe is by actually splitting `Projection` goals and `NormalizesTo`. The question is: how do we prove `Projection` goals in this case: ### `Projection` tries `normalizes-to` and uses `eq` if it fails This is the behavior of the old solver. It's a bit of a mess for multiple reasons: - if `normalizes-to` is ambiguous, we have to detect whether the inference var is still unconstrained or not. If the inference var is still unconstrained, we must not bubble up any inference constraints as we may later want to fall back to `eq`. - unclear how to implement `eq`. Calling `eq` would just end up at `alias-relate`. At this point the next alternative may be better ### `Projection` directly equates the types well, this causes a fun issue :sparkles: ```rust // compile-flags: -Ztrait-solver=next // check-pass fn foo(i: isize) -> isize { i + 1 } fn apply<A, F>(f: F, v: A) -> A where F: FnOnce(A) -> A { f(v) } pub fn main() { let f = |i| foo(i); assert_eq!(apply(f, 2), 3); } ``` a minimized version: ```rust trait Trait { type Assoc; } impl<T> Trait for T { type Assoc = T; } fn impls_trait<T: Trait<Assoc = T>>() -> T { todo!() } fn main() { let _: u32 = impls_trait::<_>(); //~^ ERROR type mismatch resolving `<_ as Trait>::Assoc == _` //~^ NOTE cyclic type of infinite size } ``` `impls_trait<?0>` requires proving `Projection(<?0 as Trait>::Assoc, ?0)`, equating the projection and the inference variable results in an occurs check failure. This requires some changes to generalization. Another issue which is more frequent due to `Projection` now simply equating types: ```rust trait Trait<'a> { type Assoc; } fn foo<'a, T: Trait<'a, Assoc = U>, U>() {} fn main() { foo::<_, _>(); } ``` This test now triggers the "unstable query result" warning. We start with `Projection(<?0 as Trait<&'1>::Assoc, ?2)`, this returns `YES: ?1 = <?0 as Trait<&'1>::Assoc`, reproving `Projection(<?0 as Trait<&'1>::Assoc, <?0 as Trait<&'1>::Assoc)` requires `Projection(<?0 as Trait<&'1>::Assoc, <?0 as Trait<&'2>::Assoc)` due to uniquification, which is ambiguous. ### generalization uwu Generalization is generally broken when [dealing with aliases](https://github.com/rust-lang/trait-system-refactor-initiative/issues/8) and higher ranked types[^1]. The issues with with generalizating aliases can mostly be summarized as: generalizing an inference variable to an alias is pretty much always wrong as it does not consider the option to first normalize the alias instead. It is also broken if the projection contains bound variables, which we should delay until later. #### A minimal fix Inside of the generalizer, stop generalizing projections, replace them with inference variables. When relating an inference variable with a projection directly, generalize, if there is an occurs check failure, emit a `NormalizesTo` goal instead. This is not a great fix: - the occurs check failure may be in a nested projection `?x == Alias<<?x as ToUnit>::Assoc`. We would be able to constrain `?x` to `Alias<()>` here. - it means that subtyping for projections is still incorrect [^1]: &nbsp; `for<'a> fn(&'a ()) <: ?0` sets `?0` to `for<'a> fn(&'a ())` even though it could also be `fn(&'whatever ())`. ### notes from 2023-10-23 Adding to [this issue](https://github.com/rust-lang/trait-system-refactor-initiative/issues/8) ```rust for<'a> fn(<<?x as OtherTrait>::Assoc as Trait<'a>>::Assoc) eq ?x ``` `?x` could be set to `for<'a> fn(<T as Trait<'a>>::Assoc)` which would then pass the occurs check and equate successfully. We must not replace `<<?x as OtherTrait>::Assoc as Trait<'a>>::Assoc` with an inference variable as that variable is unable to name `'a`. how Niko expects the "theoretically perfect" rules to look is that you can normalize at any point, kind of like this... ``` ?X does not occur in Y ---------------------- Env |- ?X = Y : C[?X := Y] Y normalizes-to Y' Env |- ?X = Y' : C ---------------------- Env |- ?X = Y : C ---------------------- Env |- T normalizes-to T impl { type Alias = T } ---------------------- Env |- Alias[P*] normalizes-to T Env |- Pi normalizes-to Qi ---------------------- Env |- Ty[P0..Pn] normalizes-to Ty[P0...Qi...Pn] ``` In cases where normalization fails, we could make the solver return "P = Q if P = Q", which effectively means "ambiguous normalization". When proving a binder, if the returned goals include `'a`, then we can return that the binder must be equal. Ideally we show that the "best" path through those rules above is to always normalize as much as we can (sound/complete)

    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