Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 1861: Extern types #43467
Comments
aturon
added
B-RFC-approved
T-lang
labels
Jul 25, 2017
aturon
changed the title
Tracking issue for RFC 1861: Extern tyupes
Tracking issue for RFC 1861: Extern types
Jul 25, 2017
This comment has been minimized.
This comment has been minimized.
|
This is not explicitly mentioned in the RFC, but I'm assuming different instances of extern {
type A;
type B;
}
fn convert_ref(r: &A) -> &B { r } |
This comment has been minimized.
This comment has been minimized.
|
@jethrogb That's certainly the intention, yes. |
This comment has been minimized.
This comment has been minimized.
|
Relatedly, is deciding whether we want to call it EDIT: rust-lang/rfcs#2071 is also relevant here w.r.t. the connotations of |
This comment has been minimized.
This comment has been minimized.
|
Can we get a bullet for the panic vs DynSized debate? |
fitzgen
referenced this issue
Jul 25, 2017
Open
Tracking rustc bugs/features/RFCs that affect bindgen #849
jimblandy
referenced this issue
Jul 26, 2017
Open
Poor error message for type definitions in `extern` blocks #43495
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 27, 2017
This comment has been minimized.
This comment has been minimized.
|
I've started working on this, and I have a working simple initial version (no generics, no DynSized). I've however noticed a slight usability issue. In FFI code, it's frequent for raw pointers to be initialized to null using Despite being unsized, extern types are used through thin pointers, so it should be possible to use It is still possible to cast an integer to an extern type pointer, but this is not as nice as just using the function designed for this. Also this can never be done in a generic context. extern {
type foo;
}
fn null_foo() -> *const foo {
0usize as *const foo
}Really we'd want is a new trait to distinguish types which use thin pointers. It would be implemented automatically for all sized types and extern types. Then the cast above would succeed whenever the type is bounded by this trait. Eg, the function fn null<T: ?Sized + Thin>() -> *const T {
0usize as *const T
}However there's a risk of more and more such traits creeping up, such as |
This comment has been minimized.
This comment has been minimized.
|
I think we can add extern types now and live with |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin yeah, it's definitely a minor concern for now. I do think this problem of not having a trait bound to express "this type may be unsized be must have a thin pointer" might crop up in other places though. |
This comment has been minimized.
This comment has been minimized.
|
Oh yeah, I agree we should solve that eventually too. I’m only saying we might not need to solve all of it before we ship any of it. |
This comment has been minimized.
This comment has been minimized.
|
I've pushed an initial implementation in #44295 |
bors
added a commit
that referenced
this issue
Sep 4, 2017
crumblingstatue
referenced this issue
Sep 7, 2017
Open
[1.0] Commit to supporting a specific Rust version #148
bors
added a commit
that referenced
this issue
Sep 10, 2017
bors
added a commit
that referenced
this issue
Sep 13, 2017
bors
added a commit
that referenced
this issue
Oct 1, 2017
bors
added a commit
that referenced
this issue
Oct 28, 2017
This comment has been minimized.
This comment has been minimized.
While it is possible for Sync, Send, UnwindSafe and RefUnwindSafe, doing Should Or is it possible to declare an extern type is safe-by-default, which opt-out instead of opt-in? extern {
#[unsafe_impl_all_auto_traits_by_default]
type Foo;
}
impl !Send for Foo {} |
This comment has been minimized.
This comment has been minimized.
|
@kennytm What's the usecase? The semantics of |
This comment has been minimized.
This comment has been minimized.
|
@eddyb Use case: Trying to see if it's possible to make CStr a thin DST. I don't see anything related to a cell in #44295? It is reported to LLVM as an |
This comment has been minimized.
This comment has been minimized.
|
@kennytm So with |
bors
added a commit
that referenced
this issue
Nov 16, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Nov 17, 2018
bors
added a commit
that referenced
this issue
Nov 17, 2018
bors
added a commit
that referenced
this issue
Nov 18, 2018
sdroege
referenced this issue
Dec 7, 2018
Merged
Remove confusing comment about ideally using `!` for `c_void` #56594
This comment has been minimized.
This comment has been minimized.
|
Comments from jethrogb and Ericson2314 mention that LLVM uses a special Rust1.33.0-nightly 2019-01-04 f381a96 extern {
type nuffin_t;
fn myalloc() -> *mut nuffin_t;
fn myfree(_: *mut nuffin_t);
}%"::nuffin_t" = type {}
declare %"::nuffin_t"* @myalloc() unnamed_addr #0
declare void @myfree(%"::nuffin_t"*) unnamed_addr #0Cclang version 8.0.0 (trunk 350447) struct nuffin_t;
struct nuffin_t *myalloc();
void myfree(struct nuffin_t*);%struct.nuffin_t = type opaque
declare dso_local void @myfree(%struct.nuffin_t*) #1
declare dso_local %struct.nuffin_t* @myalloc(...) #1 |
This comment has been minimized.
This comment has been minimized.
|
Good catch! |
Centril
added a commit
to Centril/rust
that referenced
this issue
Jan 17, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Jan 17, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Jan 17, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Jan 18, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Jan 18, 2019
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Jan 18, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Jan 18, 2019
hellow554
referenced this issue
Jan 24, 2019
Closed
Taking a reference to a static with an extern type ICEs #57876
This comment has been minimized.
This comment has been minimized.
|
@shepmaster I independently came across that (well, @RalfJung pointed it out) and I opened #58271 last week, which I'm not sure how to fix. If what I did is different from But also, note that |
This comment has been minimized.
This comment has been minimized.
raphaelcohn
commented
Mar 6, 2019
|
I've been trying to use I've come across an issue where I'd like to define a method which involves casting from various raw pointers, come of which are Sized and some of which are Is there any way to use the type system to differentiate |
This comment has been minimized.
This comment has been minimized.
|
@raphaelcohn I believe the plan is to add a |
This comment has been minimized.
This comment has been minimized.
|
@alexreg yeah so that's the opposite of what @raphaelcohn wants I think :) |
This comment has been minimized.
This comment has been minimized.
|
rust-lang/rfcs#2580 is another proposal in somewhat the same space as |
This comment has been minimized.
This comment has been minimized.
|
@jethrogb It's exactly what he wants, the way I read it. Or maybe he needs both. Regardless, negative bounds for auto traits exist, so e.g. |
This comment has been minimized.
This comment has been minimized.
|
@alexreg You could write |
This comment has been minimized.
This comment has been minimized.
raphaelcohn
commented
Mar 7, 2019
|
@alexreg, @jethrogb @SimonSapin @kennytm Thank you all. |
This comment has been minimized.
This comment has been minimized.
|
Indeed, the RFC also proposes a trait alias |
This comment has been minimized.
This comment has been minimized.
|
@kennytm It's not? Well, it needs to be! |
This comment has been minimized.
This comment has been minimized.
|
For the record, I think we need |
This comment has been minimized.
This comment has been minimized.
raphaelcohn
commented
Mar 8, 2019
|
And anything that lets me safely coerce a slice to an |
aturon commentedJul 25, 2017
•
edited by RalfJung
This is a tracking issue for RFC 1861 "Extern types".
Steps:
Unresolved questions:
Should we allow generic lifetime and type parameters on extern types?
If so, how do they effect the type in terms of variance?
In std's source, it is mentioned that LLVM expects
i8*for C'svoid*.We'd need to continue to hack this for the two
c_voids in std and libc.But perhaps this should be done across-the-board for all extern types?
Somebody should check what Clang does. Also see #59095.