Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `raw` stabilization (`raw::TraitObject`) #27751
Comments
aturon
added
T-lang
T-libs
B-unstable
labels
Aug 12, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
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. |
Ms2ger
referenced this issue
Aug 16, 2015
Open
Tracking: Unstable Rust feature gates used by Servo #5286
arielb1
referenced this issue
Aug 17, 2015
Merged
make trait matching smarter with projections #27866
added a commit
that referenced
this issue
Aug 18, 2015
Havvy
referenced this issue
Sep 21, 2015
Closed
[Rustonomicon] Show how to convert a trait object into concrete type #28571
This comment has been minimized.
This comment has been minimized.
|
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. |
kamalmarhubi
referenced this issue
Mar 5, 2016
Closed
RFC: Use byte slices directly in place of IoVec #263
alexcrichton
added
the
I-nominated
label
Mar 9, 2016
This comment has been minimized.
This comment has been minimized.
|
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! |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Mar 11, 2016
This comment has been minimized.
This comment has been minimized.
|
Was |
This comment has been minimized.
This comment has been minimized.
|
Yes, and we neither want to stabilize it nor deprecate it yet, this module will stick around for that reason. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
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! |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage yesterday and the decision was to deprecate |
added a commit
to alexcrichton/rust
that referenced
this issue
Apr 7, 2016
alexcrichton
referenced this issue
Apr 7, 2016
Merged
std: Stabilize APIs for the 1.9 release #32804
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton is that the whole module, or just
|
This comment has been minimized.
This comment has been minimized.
|
reluctant +1 - I kind of liked the |
added a commit
to alexcrichton/rust
that referenced
this issue
Apr 7, 2016
This comment has been minimized.
This comment has been minimized.
|
@kamalmarhubi just the |
This comment has been minimized.
This comment has been minimized.
|
It looks like fat raw pointers can be cast to thin raw pointers to access the "data" part:
These together could replace |
added a commit
to Manishearth/rust
that referenced
this issue
Apr 8, 2016
added a commit
to alexcrichton/rust
that referenced
this issue
Apr 8, 2016
added a commit
to alexcrichton/rust
that referenced
this issue
Apr 12, 2016
alexcrichton
removed
the
final-comment-period
label
Apr 13, 2016
This comment has been minimized.
This comment has been minimized.
|
If #34785 is merged, the |
nrc
added
the
I-nominated
label
Aug 17, 2016
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/libs So was this feature deprecated? Should this issue be closed or a label changed or something? |
This comment has been minimized.
This comment has been minimized.
|
@nrc currently this covers |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton is there a plan for |
nrc
changed the title
Tracking issue for `raw` stabilization
Tracking issue for `raw` stabilization (`raw::ThreadObject`)
Aug 18, 2016
This comment has been minimized.
This comment has been minimized.
|
I believe not currently, no. I think we may have vaguely been waiting on the lang team to say whether it's cool or not to stabilize such a structure? |
This comment has been minimized.
This comment has been minimized.
|
To make my previous comment more explicit: I think a couple functions in the spirit of |
This comment has been minimized.
This comment has been minimized.
|
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 |
nikomatsakis
removed
the
I-nominated
label
Aug 18, 2016
This comment has been minimized.
This comment has been minimized.
Are these written down? Could you link to them? |
This comment has been minimized.
This comment has been minimized.
aturon
changed the title
Tracking issue for `raw` stabilization (`raw::ThreadObject`)
Tracking issue for `raw` stabilization (`raw::TraitObject`)
Aug 18, 2016
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
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 ()
} |
This comment has been minimized.
This comment has been minimized.
|
@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
} |
This comment has been minimized.
This comment has been minimized.
|
@eddyb Yes, correct. In fact Servo does this, with a trait bound, to allow both trait objects and concrete types that implement that trait. |
This comment has been minimized.
This comment has been minimized.
|
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->
.
|
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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->
.
|
This comment has been minimized.
This comment has been minimized.
|
Even if the repr changes it has to include at least a data pointer, doesn’t it? |
This comment has been minimized.
This comment has been minimized.
|
The reference says it is a "pointer-to-pointer cast" but doesn't say what that means. Sounds OK though? |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
https://doc.rust-lang.org/nightly/nomicon/casts.html says:
and
Maybe it’s time to fix that TODO and define this more precisely? |
ozkriff
referenced this issue
May 17, 2018
Open
Запрос статьи про DST, str, [], толстые указатели и т.п. #292
gnzlbg
referenced this issue
Oct 11, 2018
Closed
Representation of Rust references (`&T`, `&mut T`) and raw pointers (`*const T, `*mut T`) #16
This comment has been minimized.
This comment has been minimized.
|
rust-lang/rfcs#2580 proposes deprecating this. |
aturon commentedAug 12, 2015
•
edited by nikomatsakis
The
std::rawmodule 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_partsare already doing this.The
TraitObjectcase 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))