You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is related to #1 but not identical. When adding a defaulted type parameter to a stable type, for example changing:
structVec<T>{…}
To:
structVec<T,A:Alloc = Global>{…}
We would like to experiment with this change on Rust Nightly before it affects users one the Stable channel. That is, we would like to keep the type parameter unstable. Ideally, even the existence of this type parameter should not affect the stable channel at all.
As far as I understand this is not possible today. Ways forward include:
Extend the stability mechanism in the language to support unstable type parameters. This itself would likely take significant time to design and implement.
Accept that the existence of the new type parameter is instantly stable as soon as it lands, and hope that the trait that constraints this parameter being unstable is enough to avoid locking is into some API detail that we might want to change later. In this case Compat of adding parameters to stable types #1 needs to be resolved before adding the parameter.
Avoid adding type parameters at all to stable types. Define new types instead. This would mean that e.g. &mut NewVec<T, Global> could not be passed where &mut Vec<T> is expected.
A fourth option would be another Alloc trait, which is unstable and will only be implemented for unstable types. This will then be replaced as soon as either 1. becomes possible or when allocator_api becomes stable. With this we could also test other options for the alloc trait without breaking the current allocator api every time.
Taking a step back, the only stable type that implements Alloc is System. There is nothing that says that System should implement Alloc. The only thing currently documented is that it implements GlobalAlloc. And Global is what implements Alloc, and, practically speaking, it wraps System. So it doesn't seem to actually be useful for System to implement Alloc.
`Global` uses the `#[global_allocator]` and `System` the system allocator but this doesn't matter here. Removing `Alloc` for `System` is maybe the most simple option. The implementation cannot be used on stable anyway.
On May 3, 2019, 12:41, at 12:41, Mike Hommey ***@***.***> wrote:
Taking a step back, the only stable type that implements `Alloc` is
`System`. There is nothing that says that `System` should implement
`Alloc`. The only thing currently documented is that it implements
`GlobalAlloc`. And `Global` is what implements `Alloc`, and,
practically speaking, it wraps `System`. So it doesn't seem to actually
be useful for `System` to implement `Alloc`.
So how about we remove the `Alloc` impl for `System`?
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#2 (comment)
I think unstable params on stable types is good thing to have in general: I think a lot of Rust code ought be more polymorphic (in ways we haven't even thought of yet!) and this is the best way to unblock experimentation on that front.
Now I don't want to hold up Box<T, A> much longer, either, so how hard would this be?
Reacted by Avi Dessauer, Eira Fransham, Solomon Ucko and Tim Diekmann
@TimDiekmann I assume you mean that this commit “solves” this issue on the premise that since there is a bound on the type parameter with an unstable trait that has no impl with stable types, then users on Stable cannot write Box<T, Foo> for any Foo.
Does this satisfy the criteria that the parameter addition has no observable effect for users on Stable? I’m not sure. For example, what about Box<T, _>? (With a literal underscore.)
Oh, the literal underscore is a good point. But, as far as I can see, this case should be safe. There will definitely a second parameter but a user on Stable cannot make any assumptions about it, as he cannot implement the trait. (Even typing Box<T, System> would be relatively safe, but Alloc should be removed from System anyway. If a nightly user really needs this, he may implement it in a newtype struct). With Box<T, _> it would even be possible to change the second parameter bound or default without breaking anything.
Just to be clear, you’re arguing that the visible effects of this type parameter on Stable are benign enough that we should accept them as insta-stable. This is not the same as there being no such effect. The former would require some @rust-lang/libs buy-in before landing at all.
Reacted by John Ericson, Tim Diekmann and Scott J Maddox
Yeah I want something that's seamless enough that teams / WGs don't need to synchronize, so this and other parameter experiments can take place entirely in parallel.
implement another Box (maybe in alloc::alloc::boxed) gated behind a feature flag and test around with this box. The new box should be compatible with the old box, so at a later point it could replace it.
I'm pretty sure new issues will occure as soon as we push the box upstream.
On May 4, 2020, 04:37, at 04:37, Avi Dessauer ***@***.***> wrote:
I'm still interested in rust-lang/rust#65083,
but I would need guidance on blocking type inference.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#2 (comment)
rust-lang/rust#58457 would have removed AllocRef for System. This is also an option to prevent users from specifying an allocator. However this does not prevent writing
I think rust-lang/rust#72314 is ready to merge now, which adds support for unstable type parameters. That is, type parameters with defaults can be marked unstable, which means an explicit type argument will only be permitted if the corresponding feature flag is enabled. However, as a note of warning to API implementers: a non-default type can still be inferred for an unstable type parameter. (This appears to be necessary to prevent code breaking when a type parameter is stabilised.) That means that you must be careful not to allow the type parameter to be inferred outside of library code, e.g. by having custom constructors for the non-default type parameter, at least until the type parameter is stabilised. I think that this is the most reasonable design, but let me know if you have any concerns. It may be helpful for those interested to take a look at the tests on rust-lang/rust#72314 to check it matches their intuition. If there are no concerns, I'll approve it in a few days.
Reacted by Tim Diekmann, Avi Dessauer, Jon Gjengset and Wodann
you must be careful not to allow the type parameter to be inferred outside of library code, e.g. by having custom constructors for the non-default type parameter
If I understand correctly, this means, that a stable API must not make any assumption about the unstable type parameter. For example we must not stabilize Vec::new_in before stabilizing the type parameter. If we'd do this, we may pass an allocator without a feature gate and alter the defaulted type parameter.
Now that I think about it, it seems harder to accidentally allow this than I thought. The sort of example I had in mind was the following.
// Library code.pubstructSomeType<#[unstable(feature = "test_feature")]T = ()>(T);// User code.SomeType(0u8)// Works, even though a non-default is not specified, because the default is inferred.
There could be a similar problem if existing methods are extended to support different type parameters, but that's not going to happen, in which case @TimDiekmann's comment is the main point to keep in mind: if you stabilise any method that allows the default to be changed (even implicitly, e.g. taking a type that can be inferred as non-default), you've effectively stabilised the type parameter itself (even if the user can't mention it explicitly). I think due to the way the APIs are designed, this won't be a problem in practice, though.
It's now possible to add stability annotations on generic parameters as seen in rust-lang/rust#77187. Many thanks for @Avi-D-coder to make this possible. Also thank you for @varkor for reviewing the changes and @exrook to catch this up, so it's merged now!
Reacted by Jon Gjengset, Avi Dessauer, Wodann and Amit Haramaty
Activity
TimDiekmann commentedon May 3, 2019
glandium commentedon May 3, 2019
I tested this for
Box<T, A>just right now, and it doesn't actually work:Just compiles without an error.
So either this needs to be fixed first, or we have to limit the changes to only expose unstable methods, which would make it less useful.
TimDiekmann commentedon May 3, 2019
Oh damn, I think I tested it with
Box::<(), Global>and forgot thatGlobalitself isn't stable either... I'm sorry for the confusion...TimDiekmann commentedon May 3, 2019
A fourth option would be another
Alloctrait, which is unstable and will only be implemented for unstable types. This will then be replaced as soon as either 1. becomes possible or whenallocator_apibecomes stable. With this we could also test other options for the alloc trait without breaking the current allocator api every time.glandium commentedon May 3, 2019
Taking a step back, the only stable type that implements
AllocisSystem. There is nothing that says thatSystemshould implementAlloc. The only thing currently documented is that it implementsGlobalAlloc. AndGlobalis what implementsAlloc, and, practically speaking, it wrapsSystem. So it doesn't seem to actually be useful forSystemto implementAlloc.So how about we remove the
Allocimpl forSystem?TimDiekmann commentedon May 3, 2019
Ericson2314 commentedon May 3, 2019
I think unstable params on stable types is good thing to have in general: I think a lot of Rust code ought be more polymorphic (in ways we haven't even thought of yet!) and this is the best way to unblock experimentation on that front.
Now I don't want to hold up
Box<T, A>much longer, either, so how hard would this be?TimDiekmann commentedon May 3, 2019
With glandium/rust@4395ce1 this issue should be solved. @SimonSapin?
Absolutely! Probably an issue should be filed in rust repo, if there isn't one yet.
SimonSapin commentedon May 3, 2019
@TimDiekmann I assume you mean that this commit “solves” this issue on the premise that since there is a bound on the type parameter with an unstable trait that has no impl with stable types, then users on Stable cannot write
Box<T, Foo>for anyFoo.Does this satisfy the criteria that the parameter addition has no observable effect for users on Stable? I’m not sure. For example, what about
Box<T, _>? (With a literal underscore.)TimDiekmann commentedon May 3, 2019
Oh, the literal underscore is a good point. But, as far as I can see, this case should be safe. There will definitely a second parameter but a user on Stable cannot make any assumptions about it, as he cannot implement the trait. (Even typing
Box<T, System>would be relatively safe, butAllocshould be removed fromSystemanyway. If a nightly user really needs this, he may implement it in a newtype struct). WithBox<T, _>it would even be possible to change the second parameter bound or default without breaking anything.SimonSapin commentedon May 3, 2019
Just to be clear, you’re arguing that the visible effects of this type parameter on Stable are benign enough that we should accept them as insta-stable. This is not the same as there being no such effect. The former would require some @rust-lang/libs buy-in before landing at all.
Ericson2314 commentedon May 3, 2019
Yeah I want something that's seamless enough that teams / WGs don't need to synchronize, so this and other parameter experiments can take place entirely in parallel.
Remove the impl Alloc for System
18 remaining items
Avi-D-coder commentedon Nov 12, 2019
@varkor
#[may_dangle]does not show up either.SimonSapin commentedon Nov 12, 2019
Another aspect to consider is how adding a defaulted type parameter affects inference: rust-lang/rust#50822 (comment)
TimDiekmann commentedon May 4, 2020
This issue is now exactly one year old.
This pretty much failed. I don't think we should focus on this anymore.
I'd say we do two things in parallel to push this further:
Boxto solve Compat of adding parameters to stable types #1Box(maybe inalloc::alloc::boxed) gated behind a feature flag and test around with this box. The new box should be compatible with the old box, so at a later point it could replace it.I'm pretty sure new issues will occure as soon as we push the box upstream.
Avi-D-coder commentedon May 4, 2020
I'm still interested in rust-lang/rust#65083, but I would need guidance on blocking type inference.
TimDiekmann commentedon May 4, 2020
Amanieu commentedon May 4, 2020
If we can't get unstable type parameters then we will just have to introduce the allocator parameter as insta-stable, like a trait impl.
TimDiekmann commentedon May 4, 2020
rust-lang/rust#58457 would have removed
AllocRefforSystem. This is also an option to prevent users from specifying an allocator. However this does not prevent writingBut this is fine to me.
varkor commentedon Jul 20, 2020
I think rust-lang/rust#72314 is ready to merge now, which adds support for unstable type parameters. That is, type parameters with defaults can be marked unstable, which means an explicit type argument will only be permitted if the corresponding feature flag is enabled. However, as a note of warning to API implementers: a non-default type can still be inferred for an unstable type parameter. (This appears to be necessary to prevent code breaking when a type parameter is stabilised.) That means that you must be careful not to allow the type parameter to be inferred outside of library code, e.g. by having custom constructors for the non-default type parameter, at least until the type parameter is stabilised. I think that this is the most reasonable design, but let me know if you have any concerns. It may be helpful for those interested to take a look at the tests on rust-lang/rust#72314 to check it matches their intuition. If there are no concerns, I'll approve it in a few days.
Wodann commentedon Jul 22, 2020
That seems like a reasonable trade-off between reviewer responsibility and compiler detectability to me. Nice work @Avi-D-coder and @varkor!
SimonSapin commentedon Jul 22, 2020
I don’t understand this part, could you say more?
TimDiekmann commentedon Jul 22, 2020
If I understand correctly, this means, that a stable API must not make any assumption about the unstable type parameter. For example we must not stabilize
Vec::new_inbefore stabilizing the type parameter. If we'd do this, we may pass an allocator without a feature gate and alter the defaulted type parameter.varkor commentedon Jul 22, 2020
Now that I think about it, it seems harder to accidentally allow this than I thought. The sort of example I had in mind was the following.
There could be a similar problem if existing methods are extended to support different type parameters, but that's not going to happen, in which case @TimDiekmann's comment is the main point to keep in mind: if you stabilise any method that allows the default to be changed (even implicitly, e.g. taking a type that can be inferred as non-default), you've effectively stabilised the type parameter itself (even if the user can't mention it explicitly). I think due to the way the APIs are designed, this won't be a problem in practice, though.
Auto merge of rust-lang#77118 - exrook:stability-generic-parameters-2…
TimDiekmann commentedon Sep 27, 2020
It's now possible to add stability annotations on generic parameters as seen in rust-lang/rust#77187. Many thanks for @Avi-D-coder to make this possible. Also thank you for @varkor for reviewing the changes and @exrook to catch this up, so it's merged now!