Rust Lang 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

      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
    # Design Meeting 2022-05-25: keyword generics Link to doc: https://hackmd.io/Aw2L3VmPQsm0ANC_XMughQ Process: Raise your hand in Zoom while you're reading ✋ # Discussion Notes - Question to answer: do sets of effects need to be ordered? - maybe another way to phrase the above: Do the effects need to capture structure - is maybe-async in maybe-async too limited, or is it sufficiently expressive to still be useful? - its utility *might* be limited to higher-order routines, like the `Option::map` example. - can the return type of a function vary depending on keyword generic? (potentially by feeding the effect into a type-constructor for the return type)? - Question: what should we do with `try`-stacking? What if we return an `Option<Result>` or `Result<Result<T>>`. How should effects apply to those? ### Carried vs Uncarried effects scott: "carried" effects end up getting embedded into a return type that end up getting processed later, versus "uncarried" effects that just have an immediate meaning for the execution of the function, but no implications for the return type. josh: also: Is "try" one effect, or is it something that varies depending on which type the "try" is operating on (e.g. Option vs Result) scott: in any case, the potential difference in meaning of "async try" vs "try async" seems worrisome. felix: definitely seems like "try" poses all sorts of issues, since it seems like it might "stack" (e.g. `Result<Result<T, E>, E>` or `Result<Option<T>, E>`) josh: There's lot of open questions, and we should be clear about what would block stabilization of a feature vs what would block even starting the experimental work here. Mark: Hesitant to introduce syntax into substantial parts of std even if hidden from rustdoc, that's a major step. # Questions / Discussion Topics Queue ### Carried vs Uncarried effects Scott: One thing I've noticed is that things tend to work differently for what I've called "carried" effects (like `try` and `async`, where it needs to wrap things in a different type and the behaviour can be "delayed" in a sense -- you can `?` or `.await` later) and "uncarried" effects (like `const` and `unsafe`, where there's no monomorphization difference that would be needed and you can't `.safe` later). Are we certain that we can handle these the same way? For example, ordering isn't meaningful for `const unsafe` or `unsafe const`, but `async try` vs `try async` are materially different, so does the order of the effect generics choose between these or something, for carried effects? oli: In the MVP we opt to require `?` and `.await` at the immediate site. There is no delay. Quoting from the doc: > any await inside a maybe-async function must be on a function call to another maybe-async function: Scott: Does that imply that combining effects just isn't supported, since `.await?` has delayed the `?` part? Scott: (Musing) Oh, "The interesting part here is that you can also just call this function in runtime code, thus sharing the implementation." also applies to `unsafe` in a way: A safe function is one "sharing the implementation" with its unsafe equivalent. Scott: I'll also note that it's unclear to me that returning `impl TheEffectTrait` is always correct. For example, https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.try_find explicitly doesn't do that, since it wants people to be able to call combinators on the result, not just `?`. Scott: So overall this proposal seems clearly good for uncarried effects, but I'm scared about the implications for carried things. oli: all this work will be exploratory, I expect us to get a better picture of it once we have an explicit syntax to work with ## Josh: Should it be `effect A`/`effect true`, or should it be specifically `effect async` or perhaps `async true`? oli: For now we're going with just a single bool There may be desire to decouple them later, but there may also be interest to couple them (a function that is either async and const or neither) Josh: If we intend to offer both coupled and decoupled in the future, it seems like `bar::<effect true>` is not forwards-compatible with that, in addition to not being self-documenting for what it's actually doing. We could have multiple generic parameters here, but having each one take a set of keywords seems better. oli: yea, boolean flags are not great, this is like with function arguments. So we should indeed look into some typestrong thing here. ## Josh: I don't think we can defer the ambiguity of calling a maybe-async function from an async function; we can't force people to immediately use `.await`, even over an edition boundary, because they may want to use the future in some other way (e.g. `.instrument().await`, `join`). I think we need to sort out the right syntax for this first. oli: right, this is not in the doc, but we'd like to basically use inference to go back from the await. This should be doable via generics on a trait (basically `MaybeFuture<effect E>`) Josh: So if it infers to async it uses async, and if it doesn't it uses sync? That seems error-prone; forget an await and your code compiles using a sync call (and even works, except for being suboptimal). That has all the same problems as "automatic await", which is part of why several of us rejected automatic await. oli: Yea, this is a concern, it may be trivial to lint though? Or we require async in async and you need to opt out. Josh: I think settling this question needs to be a substantial part of the next step in getting this even prototyped. oli: we can just require the explicit syntax for calling maybe-async from async at the beginning Josh: As in `func::<effect true>` or however that ends up being spelled? oli: yes :+1: oli: we mainly want to figure out how such a less explicit thing could work and what the problems are, we have no good plan here yet, beyond "make it more convenient". This can all live under an even less stable feature gate if we decide to even start working on it. Josh: Given that this feature itself exists to make it more convenient, we definitely need to figure out at least some of what the endgame looks like, to know if we get convenience all the way through. (Notable alternatives: having separate names/functions for async and sync, and just having ways to share types between sync and async) ## Josh: Is there a way we could re-export a maybe-async name as a definitely-async or definitely-sync name? oli: maybe via explicit opaque types? `opaque type Foo: async Fn() = some_fn` ## Mark: I don't think it makes sense to discuss now, but syntax here seems immensely important. Scattering all of std's docs for example with `effect X, ...` is terrible. :+1: Yosh: that makes sense! The primary focus so far has been to define a "desugared" variant of keyword generics: which is relatively close to how we think it would be represented in the compiler. But we haven't yet spent any time really thinking about whether and how more ergonomic syntax could be provided. Mark: One of the reasons I note this is that -- per Josh's question above -- syntax will be pretty fundamental to early stage experimentation, I expect. (And I at least would be against landing code into std even hidden from rustdoc with `effect X` or similar proposed syntaxes; maintainability to newcomers is important too). ## Mark: select/specialization - my mental model is that async at least is pretty tied to "other bits" (e.g., a particular runtime's timer API, or epoll registration, etc.). Do we actually expect to be able to make code with the same interface compatible with both models with the same user interface? I'm also thinking about e.g. reqwest's blocking API, which IIRC has some differences around pipelining (access to response body and headers separately? I forget details). But in general: do we expect this to be "enough"? Yosh: We do! - Most of the differences on implementation can be divided into two categories: 1. Implementation of IO primitives, which live in something I refer to as "leaf futures". 2. Capabilities provided by the async model: e.g. ad-hoc concurrency, and ad-hoc cancellation of computation. In the `async-h1` HTTP parser/serializer library the internals are almost entirely sequential: we expect that under this model we should be able to rewrite it to be "maybe async". The only open question I see is how to handle timeouts, but there are a few schemes. As for the leaf futures: the `async-std` library has sufficiently proven that the existing functionality exposed by the stdlib can be ported to async code with no API changes modulo missing language features (async versions of traits, closures, drop, etc.). We want the proposal to make it possible to be to write "maybe async" versions of `TcpStream`, `File`, etc. ## Mark: user-defined generics -- not needed? The async/const here make sense, but I'm not sure how to extend that to fallibility. We do have plans for yeet/try blocks, but if I want (for example) panic fallibility generics or allocation fallibility generics, those seem like they need to fit into this model. I'm not sure they fit will into the contexts proposal from Tyler (and others), given the need to vary return types and such. oli: user-defined and "add more" are two somewhat separate topics. We do want a few more language effects if this pans out for const and async, but it's entirely unclear what it would even mean for a user to define a new effect. One concrete-ish example: I may also want multiple of the same effect (particularly try), e.g., `Result<Result<T>>` or `Result<T>` or `T`, with panics in different places as an alternative (for example). ## Felix: Terminology: "Effect"? Or "Evaluation Context"? pnkfelix: I'm still trying to tease apart whether this is really an effect system (which I usually think of as specifying constraints on the function body, e.g. "can read region R" or "can write region R" or "can throw an exception", or a way to thread down information about the context oli: we use "effect" because it's similar and people tell us it's effects, but mostly it's being generic over $something as we want to avoid writing the same code twice with minor adjustments. Yosh: I don't think we're particularly committed to any specific terminology either; I'd be happy to change words to different words if folks find that clearer. ## Josh: How would you write shared types between sync and async, if the types need to have slightly different semantics beyond just the functions called? Josh: For instance, an async Thing may need to have a file descriptor marked as non-blocking, while a sync Thing may need to have a file descriptor marked as blocking?

    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