rust/src/librustc_trans
bors dce604a8fe Auto merge of #44295 - plietar:extern-types, r=arielb1
Implement RFC 1861: Extern types

A few notes :

- Type parameters are not supported. This was an unresolved question from the RFC. It is not clear how useful this feature is, and how variance should be treated. This can be added in a future PR.

- `size_of_val` / `align_of_val` can be called with extern types, and respectively return 0 and 1. This differs from the RFC, which specified that they should panic, but after discussion with @eddyb on IRC this seems like a better solution.
If/when a `DynSized` trait is added, this will be disallowed statically.

- Auto traits are not implemented by default, since the contents of extern types is unknown. This means extern types are `!Sync`, `!Send` and `!Freeze`. This seems like the correct behaviour to me.
Manual `unsafe impl Sync for Foo` is still possible.

- This PR allows extern type to be used as the tail of a struct, as described by the RFC :
```rust
extern {
    type OpaqueTail;
}

#[repr(C)]
struct FfiStruct {
    data: u8,
    more_data: u32,
    tail: OpaqueTail,
}
```

However this is undesirable, as the alignment of `tail` is unknown (the current PR assumes an alignment of 1). Unfortunately we can't prevent it in the general case as the tail could be a type parameter :
```rust
#[repr(C)]
struct FfiStruct<T: ?Sized> {
    data: u8,
    more_data: u32,
    tail: T,
}
```

Adding a `DynSized` trait would solve this as well, by requiring tail fields to be bound by it.

- Despite being unsized, pointers to extern types are thin and can be casted from/to integers. However it is not possible to write a `null<T>() -> *const T` function which works with extern types, as I've explained here : https://github.com/rust-lang/rust/issues/43467#issuecomment-321678621

- Trait objects cannot be built from extern types. I intend to support it eventually, although how this interacts with `DynSized`/`size_of_val` is still unclear.

- The definition of `c_void` is unmodified
2017-10-28 13:34:12 +00:00
..
back
debuginfo
mir
abi.rs
adt.rs
allocator.rs
asm.rs
assert_module_sources.rs
attributes.rs
base.rs
build.rs
builder.rs
cabi_aarch64.rs
cabi_arm.rs
cabi_asmjs.rs
cabi_hexagon.rs
cabi_mips64.rs
cabi_mips.rs
cabi_msp430.rs
cabi_nvptx64.rs
cabi_nvptx.rs
cabi_powerpc64.rs
cabi_powerpc.rs
cabi_s390x.rs
cabi_sparc64.rs
cabi_sparc.rs
cabi_x86_64.rs
cabi_x86_win64.rs
cabi_x86.rs
callee.rs
Cargo.toml
common.rs
consts.rs
context.rs
declare.rs
diagnostics.rs
glue.rs
intrinsic.rs
lib.rs
llvm_util.rs
machine.rs
metadata.rs
meth.rs
partitioning.rs
README.md
symbol_names_test.rs
time_graph.rs
trans_item.rs
tvec.rs
type_.rs
type_of.rs
value.rs

NB: This crate is part of the Rust compiler. For an overview of the compiler as a whole, see the README.md file found in librustc.

The trans crate contains the code to convert from MIR into LLVM IR, and then from LLVM IR into machine code. In general it contains code that runs towards the end of the compilation process.