Skip to content

Commit cf3815e

Browse files
Rollup merge of rust-lang#41920 - arielb1:inline-drop, r=eddyb
remove the #[inline] attribute from drop_in_place Apparently LLVM has exponential code growth while inlining landing pads if that attribute is present. Fixes rust-lang#41696. beta-nominating because regression. r? @eddyb
2 parents f7c39ac + b0c80a9 commit cf3815e

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/libcore/ptr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub use intrinsics::write_bytes;
5656
/// invalid pointers, types, and double drops.
5757
#[stable(feature = "drop_in_place", since = "1.8.0")]
5858
#[lang="drop_in_place"]
59-
#[inline]
6059
#[allow(unconditional_recursion)]
6160
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
6261
// Code here does not matter - this is replaced by the

src/librustc_trans/common.rs

+6
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ pub fn requests_inline<'a, 'tcx>(
537537
if is_inline_instance(tcx, instance) {
538538
return true
539539
}
540+
if let ty::InstanceDef::DropGlue(..) = instance.def {
541+
// Drop glue wants to be instantiated at every translation
542+
// unit, but without an #[inline] hint. We should make this
543+
// available to normal end-users.
544+
return true
545+
}
540546
attr::requests_inline(&instance.def.attrs(tcx)[..])
541547
}
542548

src/test/run-pass/issue-41696.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// this used to cause exponential code-size blowup during LLVM passes.
12+
13+
#![feature(test)]
14+
15+
extern crate test;
16+
17+
struct MayUnwind;
18+
19+
impl Drop for MayUnwind {
20+
fn drop(&mut self) {
21+
if test::black_box(false) {
22+
panic!()
23+
}
24+
}
25+
}
26+
27+
struct DS<U> {
28+
may_unwind: MayUnwind,
29+
name: String,
30+
next: U,
31+
}
32+
33+
fn add<U>(ds: DS<U>, name: String) -> DS<DS<U>> {
34+
DS {
35+
may_unwind: MayUnwind,
36+
name: "?".to_owned(),
37+
next: ds,
38+
}
39+
}
40+
41+
fn main() {
42+
let deserializers = DS { may_unwind: MayUnwind, name: "?".to_owned(), next: () };
43+
let deserializers = add(deserializers, "?".to_owned());
44+
let deserializers = add(deserializers, "?".to_owned());
45+
let deserializers = add(deserializers, "?".to_owned());
46+
let deserializers = add(deserializers, "?".to_owned());
47+
let deserializers = add(deserializers, "?".to_owned());
48+
let deserializers = add(deserializers, "?".to_owned());
49+
let deserializers = add(deserializers, "?".to_owned()); // 0.7s
50+
let deserializers = add(deserializers, "?".to_owned()); // 1.3s
51+
let deserializers = add(deserializers, "?".to_owned()); // 2.4s
52+
let deserializers = add(deserializers, "?".to_owned()); // 6.7s
53+
let deserializers = add(deserializers, "?".to_owned()); // 26.0s
54+
let deserializers = add(deserializers, "?".to_owned()); // 114.0s
55+
let deserializers = add(deserializers, "?".to_owned()); // 228.0s
56+
let deserializers = add(deserializers, "?".to_owned()); // 400.0s
57+
let deserializers = add(deserializers, "?".to_owned()); // 800.0s
58+
let deserializers = add(deserializers, "?".to_owned()); // 1600.0s
59+
let deserializers = add(deserializers, "?".to_owned()); // 3200.0s
60+
}

0 commit comments

Comments
 (0)