-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for raw
stabilization (raw::TraitObject
)
#27751
Comments
|
I have used One case, in the bytes crate, I use The insight is that, pretty often, implementations of Another case I had was building a somewhat involved tree structure, there would be many pointers to the same trait object. The goal was to get an entire node of the tree to fit in a cache line and duplicating the vtable ptr prevented this. So, in this case, I saved the vtable pointer only once and "reconstructed" the trait object on demand. |
also, use the right caching logic for type_moves_by_default (this was broken by @jroesch). ``` before: 593.10user 5.21system 7:51.41elapsed 126%CPU (0avgtext+0avgdata 1150016maxresident)k after: 567.03user 4.00system 7:28.23elapsed 127%CPU (0avgtext+0avgdata 1133112maxresident)k ``` A nice 4.5% improvement. For reference, on the last run LLVM takes 429.267s, which is 75% - hopefully this can be reduced. I think the regression since #27751 is because of the wf patch - need to investigate it through. r? @nikomatsakis
I have a possible use case for stabilizing Mostly I'm looking to exploit the (pointer, length) representation matching up with iovec, and thereby allowing a nice ergonomics win for calls using iovecs. |
🔔 This issue is now entering its cycle-long final comment period 🔔 Specifically, the libs team is considering deprecating @kamalmarhubi we specifically don't want to stabilize the layout of slices to be used in places like that, hence the deprecation! |
Was |
Yes, and we neither want to stabilize it nor deprecate it yet, this module will stick around for that reason. |
A bit more detail from the discussion at the meeting: That said, it'd be good to use this issue to track usecases for the raw representation, and see whether we can find other ways of accommodating them. |
I figured as much. Maybe specialization and conditional compilation will let me be bad in the way I want to be there... :-) Thanks for the ping! |
The libs team discussed this during triage yesterday and the decision was to deprecate |
@alexcrichton is that the whole module, or just
|
reluctant +1 - I kind of liked the |
@kamalmarhubi just the |
It looks like fat raw pointers can be cast to thin raw pointers to access the "data" part:
These together could replace |
I don’t know if this was always the case, but I’ve just found out that casting a raw pointer from a fn data_pointer(object: &SomeTrait) -> *const () {
let ptr: *const SomeTrait = object;
ptr as *const ()
} |
@SimonSapin You're also able to make that function generic over a EDIT: I mean this: fn data_pointer<T: ?Sized>(r: &T) -> *const u8 {
r as *const T as *const u8
} |
@eddyb Yes, correct. In fact Servo does this, with a trait bound, to allow both trait objects and concrete types that implement that trait. |
I think that's always been the case. It's a footgun because you can lose
the fat part of a fat pointer while casting. I'm not sure if it's specified
which thin part you end up with.
…On Fri, Oct 13, 2017 at 10:08 PM, Simon Sapin ***@***.***> wrote:
@eddyb <https://github.com/eddyb> Yes, correct. In fact Servo does this,
with a trait bound, to allow both trait objects and concrete types that
implement that trait.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#27751 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n2s4TUOqik2U8-LrlasX4P3hdthfks5sr8NZgaJpZM4FqbX->
.
|
What do you mean, which thin part? I don’t think it would make sense for this cast to extract a vtable pointer or a slice length when casting to an arbitrary pointer to a statically-sized type. |
I agree and I don't see it changing. But as long as the actual repr is
unstable I'm not sure the result of this cast would be officially set in
stone.
…On Fri, Oct 13, 2017 at 10:48 PM, Simon Sapin ***@***.***> wrote:
What do you mean, which thin part? I don’t think it would make sense for
this cast to extract a vtable pointer or a slice length when casting to an
arbitrary pointer to a statically-sized type.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#27751 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n5enzkTPDk-CPQCuJSHXjSl0tDmUks5sr8yLgaJpZM4FqbX->
.
|
Even if the repr changes it has to include at least a data pointer, doesn’t it? |
The reference says it is a "pointer-to-pointer cast" but doesn't say what that means. Sounds OK though? |
@durka The casts are properly defined and there's even fat-to-fat casts which check the metadata and whatnot - they might be described in an RFC, or not at all, but that's orthogonal. |
https://doc.rust-lang.org/nightly/nomicon/casts.html says:
and
Maybe it’s time to fix that TODO and define this more precisely? |
rust-lang/rfcs#2580 proposes deprecating this. |
Deprecation PR: #84207 |
As an unstable feature, this can be removed a couple release cycles after the deprecation warning has been in place. |
Opened a removal pr at #86833. |
The
std::raw
module exports some representation details for the purposes of transmuting and taking things apart. Stabilizing these means pinning down the representation details forever.One possibility is to instead provide various conversions, rather than asking people to use
transmute
, when we're sure the conversions will always be possible. Methods likefrom_raw_parts
are already doing this.The
TraitObject
case in particular is unsettled due to the potential for upcasting in the future.cc @carllerche
CURRENT STATUS AS OF 2016-08-18: Discussed in @rust-lang/lang meeting. The situation is this. We expect that this will be insufficient in the future, particularly if/when we support trait objects like Trait1+Trait2 (which would require 2 vtables). We could stabilize it, since it would remain correct for all existing objects, but it'd be a shame. In contrast, the various "custom DST" proposals would allow for a much more flexible way of extracting and creating this data (sort of like from_raw_parts), so we think we'd prefer to explore that route. (from #27751 (comment))
The text was updated successfully, but these errors were encountered: