Rust Async Working Group
      • 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

      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
    • 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 Note Insights 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

    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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: WG-async open discussion 2023-09-28 tags: WG-async, open-discussion, minutes date: 2023-09-28 discussion: https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async/topic/Open.20discussion.202023-09-28 url: https://hackmd.io/JWIp_2rJRgmfn5axJUbsVg --- # Open discussion: September 2023 This is the doc for open discussion within wg-async about various design questions and other topics. Please feel free to propose a topic below. On the day of the meeting, we'll do a quick poll to sort the topics by interest and then go through them one by one. If you have a brief (under 5 min) introduction prepared for the group, we'll take that into account as we prioritize the topics. ###### tags: `open-discussion` Attendance: TC, tmandry, Zach Mitchell, eholk, yosh, vincenzo Leave discussion topics below. https://blog.yoshuawuyts.com/linearity-and-control/ --- ## Purpose of `linear fn` tmandry: Why do we need to mark functions, and not just arguments / type parameters, as `linear`? yosh: I'm trying to page this back in. In general like, I'm pretty convinced this interpretation of linearity is *not* what we want, so I've not really thought about it much since writing the second post. yosh: I believe the main reason is that futures are weird. An `async fn` is not just a function, it's also a type containing the actual computation's state machine. So when we say `linear async fn`, that not only governs the arguments passed into the function - but also the function itself. yosh: `Fn{,Once,Mut}` have a very similar property: if we take a closure as an argument somewhere, then we have to know somehow whether that closure is trying to uphold the linearity guarantees or not. And functions can be passed as closures, we need a notation for functions too. yosh: We have this problem in reverse for `unsafe fn`. Where if you have an `unsafe fn`, you can't actually pass it as a closure anywhere because we don't have `UnsafeFn` traits. tmandry: You want closure values to be linear if they capture linear types. yosh: Yes. tmandry: It feels different from `async` and `try` effects though in that it doesn't affect the control flow of the function (e.g. `map`). TC: Do free functions need to be marked `linear`? yosh: If we ever want to pass it as a function argument ```rust fn foo(f: impl Fn) {} unsafe fn bar() {} foo(bar); fn foo(f: impl UnsafeFn) {} fn bar() {} foo(bar); fn foo(f: impl LinearFn) {} fn bar() {} foo(bar); ``` TC: But we can pass a `Fn` somewhere that expects an `UnsafeFn`, etc. yosh: Yes. --- ## Destructor arguments tmandry: One of the benefits I've had in mind for linear types is that it would allow explicit destructors that take arguments, e.g. a context that's needed for destruction. So maybe not all linear types should be `Drop`? yosh: I think that's a valid thing to want, and that sort of touches on the two different interpretations of linearity: 1. Linear types as a type-system version of `#[must_use]` 2. Linear types as "Drop is guaranteed to be called" yosh: Being able to pass arguments into the destructor works really well with the first variant. But that interpretation of linearity has the downside that it leads to pretty different usage patterns than what we're used to in Rust today. Feedback on Niko's earlier post on linearity showed that, where things like closures run into a lot of issues. yosh: Instead what I hope we might be able to do is take the "will Drop" interpretation of linearity, and over time give it more capabilities. Maybe using context/capabilities we can find a way to pass arguments into destructors? eholk: I kind of like that linear types make destructors a convention or design pattern, like constructors are in Rust, rather than necessarily something special. tmandry: I think 2 is the thing I've been calling `?Leak`/`!Leak` in my head. Skeptical of being able to use contexts/capabilities for destructor args because it's saying you *couldn't* destruct the value without the context... hm, might work?... but I'm not sure. yosh: I think 2 is way more valuable than being able to pass arguments into the destructor. --- ## Linear Drop and owned references eholk: The proposal to have the linear version of `drop` take `self` probably won't work for pinned data (admittedly, drop is wrong for pinned data already), because a `self` arg is semantically *moved* from the callers frame into the `drop` function's frame. I've seen a few people discuss something like `&owned T` references, which it seems like will be necessary here. yosh: do you have a link to discussions about `&owned T`? I haven't heard of that before I think? eholk: No, but here's a quick example of how `&owned` would work: ```rust fn consume(x: &owned Box<i32>) { mem::drop(*x); } fn main() { let x = Box::new(42); consume(&owned x); println!("{}", x); // error: use of moved value } ``` Basically, `&owned` passes the obligation/right to drop the value pointed to by the reference, so it is considered moved after passing it somewhere else, even though the value stays in the same place in memory. yosh: oh, so it's like _logical move_ (ownership has changed) vs _physical move_ (the address has changed)? eholk: Exactly! yosh: innnnnnterestingggggg - I'll need a bit to process this I think haha yosh: ohhhh, could this be used for like `alloca` etc? I believe it's called "box constructors" or something? Or in-place box. Ha, I forget. Placement new! tmandry: I could see it working for `Pin`. `Pin<&owned T>`. yosh: `Pin` is must not move --- ## Why is it not possible to write scoped async blocks? zmitchell: Just for my understanding, I'm not clear on the first example in the post e.g. that it's not possible to write something like scoped threads. What is the safety concern that's preventing it? yosh: Gankra's post linked at the start covers this in-depth. But the tldr is that when you call a regular function, nothing else can happen concurrently with it on the same thread. You call a function, and it runs until it returns. That's a way to hold onto references without relying on destructors. yosh: Async functions don't run when called, they run when `.await`ed. Meaning we have space in between where you could have a reference and `mem::forget` it, which will throw the system off. We need a way to guarantee nothing else can be done with the references while they're being held in the closure, and we don't have a great way of doing that in async Rust right now. Does that... make sense? zmitchell: Yes, thanks

    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