-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
ICE: Intrinsics cannot be used as bare functions #15694
Comments
This is the one thing preventing removal of the I recently started implementing RFC 5 and realized that the substance of it isn't very important, and I'm not sure I even like the resulting design because it ends up with more special cases. All we really need is to fix this issue. I'm poking at it casually but if somebody else wants to tackle it, great. |
Oh, actually, just fixing this isn't quite enough to remove the transmute wrapper. We also need |
@brson There is no |
ICEs on the current nightly with a much longer error message ("can't monomorphize a ...."): $ rustc --verbose --version
rustc 0.13.0-nightly (c6c786671 2015-01-04 00:50:59 +0000)
binary: rustc
commit-hash: c6c786671d692d7b13c2e5c68a53001327b4b125
commit-date: 2015-01-04 00:50:59 +0000
host: x86_64-apple-darwin
release: 0.13.0-nightly $ env RUST_BACKTRACE=1 rustc foo.rs
foo.rs:3:9: 3:12 warning: unused variable: `foo`, #[warn(unused_variables)] on by default
foo.rs:3 let foo: unsafe extern "rust-intrinsic" fn(int) -> uint = mem::transmute;
^~~
error: internal compiler error: can't monomorphize a NodeForeignItem(ForeignItem { ident: "transmute"(66)#0, attrs: [Spanned { node: Attribute_ { id: AttrId(1031), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// Unsafely transforms a value of one type into a value of another type., CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1032), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(///, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1033), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// Both types must have the same size and alignment, and this guarantee, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1034), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// is enforced at compile-time., CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1035), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(///, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1036), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// # Examples, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1037), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(///, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1038), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// ```rust, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1039), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// use std::mem;, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1040), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(///, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1041), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// let v: &[u8] = unsafe { mem::transmute("L") };, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1042), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// assert!(v == [76u8]);, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1043), style: AttrOuter, value: Spanned { node: MetaNameValue(doc, Spanned { node: LitStr(/// ```, CookedStr), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: true }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, Spanned { node: Attribute_ { id: AttrId(1044), style: AttrOuter, value: Spanned { node: MetaWord(stable), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, is_sugared_doc: false }, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }], node: ForeignItemFn(FnDecl { inputs: [Arg { ty: Ty { id: 23, node: TyPath(Path { span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) }, global: false, segments: [PathSegment { identifier: "T"(215)#0, parameters: AngleBracketedParameters(AngleBracketedParameterData { lifetimes: [], types: [], bindings: [] }) }] }, 24), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, pat: Pat { id: 22, node: PatIdent(BindByValue(MutImmutable), Spanned { node: "e"(827)#0, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, None), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, id: 21 }], output: Return(Ty { id: 25, node: TyPath(Path { span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) }, global: false, segments: [PathSegment { identifier: "U"(785)#0, parameters: AngleBracketedParameters(AngleBracketedParameterData { lifetimes: [], types: [], bindings: [] }) }] }, 26), span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }), variadic: false }, Generics { lifetimes: [], ty_params: [TyParam { ident: "T"(215)#0, id: 27, bounds: [], default: None, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }, TyParam { ident: "U"(785)#0, id: 28, bounds: [], default: None, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) } }], where_clause: WhereClause { id: 29, predicates: [] } }), id: 20, span: Span { lo: BytePos(0), hi: BytePos(0), expn_id: ExpnId(4294967295) }, vis: Public })
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:182
stack backtrace:
1: 0x10cec1a85 - sys::backtrace::write::h99bbbbef588b9184Klt
2: 0x10cee6f1f - failure::on_fail::h8b1c6fd57e4213d95nz
3: 0x10ce4b95a - rt::unwind::begin_unwind_inner::hfd8d974c1cdeb74f35y
4: 0x10ab49b17 - rt::unwind::begin_unwind::h5235829026449479069
5: 0x10ab4a488 - diagnostic::Handler::bug::h72cca12a0dd401ceDLF
6: 0x10a160778 - session::Session::bug::h97e7302b0910d3e2lrq
7: 0x1096fd619 - trans::monomorphize::monomorphic_fn::h38e56ba386e94ac9Snd
8: 0x109748977 - trans::callee::trans_fn_ref_with_substs::h6a01a4be71e1beb1ewg
9: 0x109745577 - trans::callee::trans_fn_ref::hf307be0be67e1605Ykg
10: 0x10976b91a - trans::expr::trans_def::h1d52728ad739099eWKi
11: 0x109754c83 - trans::expr::trans_unadjusted::hb2acbb87da4fa8eb7ii
12: 0x10970f440 - trans::expr::trans_into::h0995e46f3b8447c0Owh
13: 0x10981364f - trans::_match::mk_binding_alloca::h14553518544565681418
14: 0x10970e7d2 - trans::base::init_local::hba63ae135471a61cB1s
15: 0x10970fc90 - trans::controlflow::trans_block::h7b1e02bd6913eed7Q1d
16: 0x1097d9914 - trans::base::trans_closure::h602c945d09839558sSt
17: 0x1096fb4cb - trans::base::trans_fn::h122108ebc597d915Z2t
18: 0x1096f6b26 - trans::base::trans_item::h542c93e65da12cf3Qpu
19: 0x1097e1118 - trans::base::trans_crate::hd65661651c173516blv
20: 0x109598a0e - driver::phase_4_translate_to_llvm::hc36550ced8732ffcvFa
21: 0x10957a8c1 - driver::compile_input::h3940b6305f304e80wba
22: 0x109641853 - thunk::F.Invoke<A, R>::invoke::h10598202800189765697
23: 0x10963e9b0 - rt::unwind::try::try_fn::h2354011666368721707
24: 0x10cf4f409 - rust_try_inner
25: 0x10cf4f3f6 - rust_try
26: 0x10963f0f6 - thunk::F.Invoke<A, R>::invoke::h10531483554991743553
27: 0x10ced2ed4 - sys::thread::thread_start::h156b750c645e6d54M8v
28: 0x7fff8f8de2fc - _pthread_body
29: 0x7fff8f8de279 - _pthread_body |
triage: still reproduces with slightly updated code: use std::mem;
fn main() {
let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = mem::transmute;
} |
Is it worth allowing intrinsics to be used as bare functions at all? I mean, they aren't actually functions in reality, they expand to some specific code inline. I don't think it's worth the implementation complexity to handle it. I'd much rather make it a hard error during type checking than support the use case. I've not heard of anybody encountering this ICE in real code, which makes it seem unlikely that this is feature people expect to have. At the very least we can relax the restriction if I turn out to be wrong and this is something people do want. |
The error is now different:
|
Triage: #![feature(intrinsics)]
use std::mem;
fn main() {
let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = mem::transmute;
} gets the following error
with |
Still reproduces with |
Triage. AFAICT this ICE depends on the unstable Triaging as P-medium until either 1. someone provides argument that the |
(also, I agree with @Aatch that we should make this a proper error. I do not see much motivation for trying to support this via e.g. generated shim code.) |
cc @rust-lang/wg-diagnostics if anyone wants to grab an ICE -> error conversion |
…e, r=estebank Emit error on intrinsic to fn ptr casts I'm not sure if a type error is the best way of doing this but it seemed like a relatively correct place to do it, and I expect this is a pretty rare case to hit anyway. Fixes rust-lang#15694
…e, r=estebank Emit error on intrinsic to fn ptr casts I'm not sure if a type error is the best way of doing this but it seemed like a relatively correct place to do it, and I expect this is a pretty rare case to hit anyway. Fixes rust-lang#15694
…eykril feat: add assist for applying De Morgan's law to `Iterator::all` and `Iterator::any` This PR adds an assist for transforming expressions of the form `!iter.any(|x| predicate(x))` into `iter.all(|x| !predicate(x))` and vice versa. [IteratorDeMorgans.webm](https://github.com/rust-lang/rust-analyzer/assets/52933714/aad1a299-6620-432b-9106-aafd2a7fa9f5) Closes rust-lang#15694
The text was updated successfully, but these errors were encountered: