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 upDistinguish fn item types to allow reification from nothing to fn pointers. #31710
Conversation
eddyb
added
the
S-waiting-on-crater
label
Feb 16, 2016
rust-highfive
assigned
arielb1
Feb 16, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
nikomatsakis
and unassigned
arielb1
Feb 16, 2016
This comment has been minimized.
This comment has been minimized.
|
Triggering a crater run. |
This comment has been minimized.
This comment has been minimized.
|
Crater run results: https://gist.github.com/nikomatsakis/0902ea970301a841231e One regression ( |
eddyb
force-pushed the
eddyb:reify
branch
6 times, most recently
from
12fa405
to
dd04d6a
Feb 17, 2016
This comment has been minimized.
This comment has been minimized.
|
|
eddyb
force-pushed the
eddyb:reify
branch
4 times, most recently
from
e9fe0fc
to
8d806be
Feb 18, 2016
This comment has been minimized.
This comment has been minimized.
|
The regression should be handled by the unify-coerce logic, however I wish I could enable the full extent of it without triggering LLVM asserts |
This comment has been minimized.
This comment has been minimized.
|
Turns out that using The problem in question starts with My code was mistakenly assigning What usually happens is I've come up with this testcase, which should trigger the same sequence of events, but does not: fn main() {
let mut x = unsafe {std::mem::zeroed()};
let mut y = &[1, 2, 3][x];
y = &vec![];
x = ..;
}It errors with "type mismatch resolving cc @rust-lang/compiler Even though my PR appears to work now, I dread leaving an obligation-dropping bug around. |
eddyb
force-pushed the
eddyb:reify
branch
from
8d806be
to
33ad2f7
Feb 23, 2016
This comment has been minimized.
This comment has been minimized.
|
Found the culprit: it's this let resolved_t = match unresolved_type_action {
UnresolvedTypeAction::Error => {
structurally_resolved_type(fcx, sp, t)
}
UnresolvedTypeAction::Ignore => {
// We can continue even when the type cannot be resolved
// (i.e. it is an inference variable) because `Ty::builtin_deref`
// and `try_overloaded_deref` both simply return `None`
// in such a case without producing spurious errors.
fcx.resolve_type_vars_if_possible(t)
}
};
Usually that's not an issue because a failed coercion is fatal, so at worst you get an ICE after a legitimate error. But I had code which tried coercions and continued in a different manner, resulting in projection obligations successfully selected but then their effects completely rolled back and thus The fix is very simple: replace that line with However, I would like a permanent solution, that doesn't allow access to |
eddyb
force-pushed the
eddyb:reify
branch
2 times, most recently
from
307dabf
to
4d44144
Feb 23, 2016
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Tests appear to pass, can I get another crater run? If we see any regressions caused by the scheme I chose, we'll have to tone it down, perhaps limit it to two function item types (although I really like this scheme, especially now that I've plucked the bugs out and it seems to "just work"). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@eddyb the crater run seems to have results now, maybe it just wasn't done before: https://gist.github.com/nikomatsakis/54fbfe9a0d09b8f51cc6
|
eddyb
referenced this pull request
Mar 1, 2016
Merged
Lint unused labels and types with `fn new() -> Self` and no `Default` impl #730
This comment has been minimized.
This comment has been minimized.
|
@eddyb so we were talking about this in the @rust-lang/lang meeting -- if we want to abide by our usual policies, we may want to think about a compatibility mode for transmute where we permit transmutes from a (zero-sized) fn to a ptr but issue a "forward compatibility" lint warning about phasing this change out. I wish there was something more ergonomic than |
eddyb
force-pushed the
eddyb:reify
branch
from
01f814a
to
93b45e4
Mar 9, 2016
eddyb
force-pushed the
eddyb:reify
branch
from
93b45e4
to
3855fa9
Mar 9, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
arielb1
added
the
relnotes
label
Mar 9, 2016
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 9, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 10, 2016
This comment has been minimized.
This comment has been minimized.
bors
merged commit 3855fa9
into
rust-lang:master
Mar 10, 2016
This was referenced Mar 10, 2016
eddyb
deleted the
eddyb:reify
branch
Mar 10, 2016
nikomatsakis
removed
the
S-waiting-on-crater
label
Mar 10, 2016
alexcrichton
referenced this pull request
Mar 16, 2016
Closed
compilation of unicode_segmentation crate hangs on nightly #32278
SSheldon
added a commit
to SSheldon/rust-objc
that referenced
this pull request
Mar 20, 2016
SSheldon
added a commit
to SSheldon/rust-objc-exception
that referenced
this pull request
Mar 20, 2016
This comment has been minimized.
This comment has been minimized.
|
FYI, special casing the transmute from functions did not prevent all regressions. I had some code that started segfaulting in 1.9.0, fixed by SSheldon/rust-objc-foundation@f918819. Basically, it boils down to looking like this: #[link(name = "objc", kind = "dylib")]
extern {
fn objc_msgSend();
}
unsafe fn msg_send<T>(t: T) {
let f: unsafe extern fn() = objc_msgSend;
let f: unsafe extern fn(T) = ::std::mem::transmute(f);
f(t)
}
fn hello() {
println!("hello");
}
fn main() {
unsafe {
msg_send(hello);
}
}That's a case where what used to be a function pointer silently becomes a 0-sized type. Anyways, fixed now, hopefully no one else is writing code like this! But figured I'd make it known in case anyone else runs into something similar. |
eddyb commentedFeb 16, 2016
Type-checking and translation of zero-sized function item types (fixes #19925).
The first commit is a rebase of #26284, except for files that have moved since.
This is a [breaking-change], due to:
size_of::<u8>&size_of::<i8>'s types differ despite their identical signature.The first two cases are handled in most cases with the new coerce-unify logic,
which will combine incompatible function item types into function pointers,
at the outer-most level of if-else chains, match arms and array literals.
The last case is specially handled during type-checking such that transmutes
from a function item type to a pointer or integer type will continue to work for
another release cycle, but are being linted against. To get rid of warnings and
ensure your code will continue to compile, cast to a pointer before transmuting.