Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #123396

Merged
merged 15 commits into from
Apr 3, 2024
Merged

Rollup of 5 pull requests #123396

merged 15 commits into from
Apr 3, 2024

Commits on Mar 23, 2024

  1. Configuration menu
    Copy the full SHA
    67b9d7d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    038e7c6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f2cff5e View commit details
    Browse the repository at this point in the history

Commits on Mar 29, 2024

  1. Add Context::ext

    jkarneges committed Mar 29, 2024
    Configuration menu
    Copy the full SHA
    c6ac3b0 View commit details
    Browse the repository at this point in the history
  2. rustfmt

    jkarneges committed Mar 29, 2024
    Configuration menu
    Copy the full SHA
    13838a5 View commit details
    Browse the repository at this point in the history
  3. update tests

    jkarneges committed Mar 29, 2024
    Configuration menu
    Copy the full SHA
    4f82731 View commit details
    Browse the repository at this point in the history

Commits on Apr 2, 2024

  1. t plit astconv's error report code in check functions to mod errors.

    Move some error report codes to mod `astconv/errors.rs`
    surechen committed Apr 2, 2024
    Configuration menu
    Copy the full SHA
    1012218 View commit details
    Browse the repository at this point in the history
  2. Improve bootstrap comments

    Rewrote a comment I found hard to understand, added some more.
    Noratrieb committed Apr 2, 2024
    Configuration menu
    Copy the full SHA
    a072103 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0fcdf34 View commit details
    Browse the repository at this point in the history
  4. set tracking issue

    jkarneges committed Apr 2, 2024
    Configuration menu
    Copy the full SHA
    036085d View commit details
    Browse the repository at this point in the history

Commits on Apr 3, 2024

  1. Rollup merge of rust-lang#122865 - surechen:refactor_astconv_error_re…

    …port_20240321, r=lcnr
    
    Split hir ty lowerer's error reporting code in check functions to mod errors.
    
    Move some error report codes to mod `astconv/errors.rs`
    
    r? `@lcnr`
    jhpratt committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    0697ee9 View commit details
    Browse the repository at this point in the history
  2. Rollup merge of rust-lang#122935 - RalfJung:with-exposed-provenance, …

    …r=Amanieu
    
    rename ptr::from_exposed_addr -> ptr::with_exposed_provenance
    
    As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066).
    
    The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".)
    
    The new name nicely matches `ptr::without_provenance`.
    jhpratt committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    e9ef8e1 View commit details
    Browse the repository at this point in the history
  3. Rollup merge of rust-lang#123182 - jhpratt:fix-decodable-derive, r=da…

    …vidtwco
    
    Avoid expanding to unstable internal method
    
    Fixes rust-lang#123156
    
    Rather than expanding to `std::rt::begin_panic`, the expansion is now to `unreachable!()`. The resulting behavior is identical. A test that previously triggered the same error as rust-lang#123156 has been added to ensure it does not regress.
    
    r? compiler
    jhpratt committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    e41d7e7 View commit details
    Browse the repository at this point in the history
  4. Rollup merge of rust-lang#123203 - jkarneges:context-ext, r=Amanieu

    Add `Context::ext`
    
    This change enables `Context` to carry arbitrary extension data via a single `&mut dyn Any` field.
    
    ```rust
    #![feature(context_ext)]
    
    impl Context {
        fn ext(&mut self) -> &mut dyn Any;
    }
    
    impl ContextBuilder {
        fn ext(self, data: &'a mut dyn Any) -> Self;
    
        fn from(cx: &'a mut Context<'_>) -> Self;
        fn waker(self, waker: &'a Waker) -> Self;
    }
    ```
    
    Basic usage:
    
    ```rust
    struct MyExtensionData {
        executor_name: String,
    }
    
    let mut ext = MyExtensionData {
        executor_name: "foo".to_string(),
    };
    
    let mut cx = ContextBuilder::from_waker(&waker).ext(&mut ext).build();
    
    if let Some(ext) = cx.ext().downcast_mut::<MyExtensionData>() {
        println!("{}", ext.executor_name);
    }
    ```
    
    Currently, `Context` only carries a `Waker`, but there is interest in having it carry other kinds of data. Examples include [LocalWaker](rust-lang#118959), [a reactor interface](rust-lang/libs-team#347), and [multiple arbitrary values by type](https://docs.rs/context-rs/latest/context_rs/). There is also a general practice in the ecosystem of sharing data between executors and futures via thread-locals or globals that would arguably be better shared via `Context`, if it were possible.
    
    The `ext` field would provide a low friction (to stabilization) solution to enable experimentation. It would enable experimenting with what kinds of data we want to carry as well as with what data structures we may want to use to carry such data.
    
    Dedicated fields for specific kinds of data could still be added directly on `Context` when we have sufficient experience or understanding about the problem they are solving, such as with `LocalWaker`. The `ext` field would be for data for which we don't have such experience or understanding, and that could be graduated to dedicated fields once proven.
    
    Both the provider and consumer of the extension data must be aware of the concrete type behind the `Any`. This means it is not possible for the field to carry an abstract interface. However, the field can carry a concrete type which in turn carries an interface. There are different ways one can imagine an interface-carrying concrete type to work, hence the benefit of being able to experiment with such data structures.
    
    ## Passing interfaces
    
    Interfaces can be placed in a concrete type, such as a struct, and then that type can be casted to `Any`. However, one gotcha is `Any` cannot contain non-static references. This means one cannot simply do:
    
    ```rust
    struct Extensions<'a> {
        interface1: &'a mut dyn Trait1,
        interface2: &'a mut dyn Trait2,
    }
    
    let mut ext = Extensions {
        interface1: &mut impl1,
        interface2: &mut impl2,
    };
    
    let ext: &mut dyn Any = &mut ext;
    ```
    
    To work around this without boxing, unsafe code can be used to create a safe projection using accessors. For example:
    
    ```rust
    pub struct Extensions {
        interface1: *mut dyn Trait1,
        interface2: *mut dyn Trait2,
    }
    
    impl Extensions {
        pub fn new<'a>(
            interface1: &'a mut (dyn Trait1 + 'static),
            interface2: &'a mut (dyn Trait2 + 'static),
            scratch: &'a mut MaybeUninit<Self>,
        ) -> &'a mut Self {
            scratch.write(Self {
                interface1,
                interface2,
            })
        }
    
        pub fn interface1(&mut self) -> &mut dyn Trait1 {
            unsafe { self.interface1.as_mut().unwrap() }
        }
    
        pub fn interface2(&mut self) -> &mut dyn Trait2 {
            unsafe { self.interface2.as_mut().unwrap() }
        }
    }
    
    let mut scratch = MaybeUninit::uninit();
    let ext: &mut Extensions = Extensions::new(&mut impl1, &mut impl2, &mut scratch);
    
    // ext can now be casted to `&mut dyn Any` and back, and used safely
    let ext: &mut dyn Any = ext;
    ```
    
    ## Context inheritance
    
    Sometimes when futures poll other futures they want to provide their own `Waker` which requires creating their own `Context`. Unfortunately, polling sub-futures with a fresh `Context` means any properties on the original `Context` won't get propagated along to the sub-futures. To help with this, some additional methods are added to `ContextBuilder`.
    
    Here's how to derive a new `Context` from another, overriding only the `Waker`:
    
    ```rust
    let mut cx = ContextBuilder::from(parent_cx).waker(&new_waker).build();
    ```
    jhpratt committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    9c1c0bf View commit details
    Browse the repository at this point in the history
  5. Rollup merge of rust-lang#123380 - Nilstrieb:bomments, r=clubby789

    Improve bootstrap comments
    
    Rewrote a comment I found hard to understand, added some more.
    jhpratt committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    f756095 View commit details
    Browse the repository at this point in the history