Skip to content
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

Rollup of 10 pull requests #65702

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
88b5e94
Make <*const/mut T>::offset_from `const fn`
oli-obk Aug 20, 2019
4a51801
Use dedicated method for getting the type size
oli-obk Oct 18, 2019
94a6d4b
Adjust const eval code to reflect `offset_from` docs
oli-obk Oct 18, 2019
1c9d889
Review nit
oli-obk Oct 18, 2019
3956c48
Ignore a test on musl because its ui output differs
oli-obk Oct 18, 2019
bf83ecf
Update ui output
oli-obk Oct 19, 2019
1e2b711
fix WASI sleep impl
newpavlov Oct 20, 2019
c290293
Derive `Rustc{En,De}codable` for `TokenStream`.
nnethercote Oct 15, 2019
8774484
Add option to disable keyboard shortcuts in docs
GuillaumeGomez Oct 21, 2019
3f1af90
Code cleanups following up on #65576.
sunfishcode Oct 22, 2019
40f92b3
refactor maybe_append
yjhmelody Oct 22, 2019
a239c8d
Add test for issue-41366
JohnTitor Oct 22, 2019
dd0f98b
Add test for issue-51431
JohnTitor Oct 22, 2019
93fab98
Add test for issue-52437
JohnTitor Oct 22, 2019
768965a
bring back some Debug instances for Miri
RalfJung Oct 22, 2019
fc5b485
add comments
RalfJung Oct 22, 2019
7a85c43
Add test for issue-63496
JohnTitor Oct 22, 2019
74db3e8
rustc_metadata: use a table for super_predicates.
eddyb Oct 18, 2019
66a0253
self-profiling: Remove module names from some event-ids in codegen ba…
michaelwoerister Oct 22, 2019
7a80a11
rustc_metadata: use a table for fn_sig.
eddyb Oct 18, 2019
371cc39
rustc_metadata: use a table for impl_trait_ref.
eddyb Oct 18, 2019
16397a9
Rollup merge of #63810 - oli-obk:const_offset_from, r=RalfJung,nikic
JohnTitor Oct 22, 2019
1d2e145
Rollup merge of #65583 - eddyb:more-query-like-cross-crate-tables, r=…
JohnTitor Oct 22, 2019
294269c
Rollup merge of #65617 - newpavlov:patch-2, r=alexcrichton
JohnTitor Oct 22, 2019
304ce88
Rollup merge of #65641 - nnethercote:derive-TokenStream-Encodable-Dec…
JohnTitor Oct 22, 2019
21af776
Rollup merge of #65656 - GuillaumeGomez:option-disable-shortcut, r=Dy…
JohnTitor Oct 22, 2019
d53ba64
Rollup merge of #65681 - sunfishcode:followup, r=Centril
JohnTitor Oct 22, 2019
00e963d
Rollup merge of #65686 - yjhmelody:yjhmelody-patch-1, r=Centril
JohnTitor Oct 22, 2019
d703346
Rollup merge of #65688 - JohnTitor:add-some-tests, r=Dylan-DPC
JohnTitor Oct 22, 2019
2fb3e40
Rollup merge of #65689 - RalfJung:miri-debug, r=Centril
JohnTitor Oct 22, 2019
d63e1a8
Rollup merge of #65695 - michaelwoerister:fix-self-profiling-work-ite…
JohnTitor Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,10 @@ extern "rust-intrinsic" {
/// Emits a `!nontemporal` store according to LLVM (see their docs).
/// Probably will never become stable.
pub fn nontemporal_store<T>(ptr: *mut T, val: T);

/// See documentation of `<*const T>::offset_from` for details.
#[cfg(not(bootstrap))]
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
}

// Some functions are defined here because they accidentally got made
Expand Down
18 changes: 17 additions & 1 deletion src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,22 @@ impl<T: ?Sized> *const T {
/// }
/// ```
#[unstable(feature = "ptr_offset_from", issue = "41079")]
#[cfg(not(bootstrap))]
#[rustc_const_unstable(feature = "const_ptr_offset_from")]
#[inline]
pub const unsafe fn offset_from(self, origin: *const T) -> isize where T: Sized {
let pointee_size = mem::size_of::<T>();
let ok = 0 < pointee_size && pointee_size <= isize::max_value() as usize;
// assert that the pointee size is valid in a const eval compatible way
// FIXME: do this with a real assert at some point
[()][(!ok) as usize];
intrinsics::ptr_offset_from(self, origin)
}

#[unstable(feature = "ptr_offset_from", issue = "41079")]
#[inline]
#[cfg(bootstrap)]
/// bootstrap
pub unsafe fn offset_from(self, origin: *const T) -> isize where T: Sized {
let pointee_size = mem::size_of::<T>();
assert!(0 < pointee_size && pointee_size <= isize::max_value() as usize);
Expand Down Expand Up @@ -2013,8 +2028,9 @@ impl<T: ?Sized> *mut T {
/// }
/// ```
#[unstable(feature = "ptr_offset_from", issue = "41079")]
#[rustc_const_unstable(feature = "const_ptr_offset_from")]
#[inline]
pub unsafe fn offset_from(self, origin: *const T) -> isize where T: Sized {
pub const unsafe fn offset_from(self, origin: *const T) -> isize where T: Sized {
(self as *const T).offset_from(origin)
}

Expand Down
19 changes: 18 additions & 1 deletion src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rustc::mir::interpret::GlobalId;
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
use rustc::hir;
use syntax::ast::{self, FloatTy};
use rustc_target::abi::HasDataLayout;

use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
use rustc_codegen_ssa::traits::*;
Expand Down Expand Up @@ -694,6 +695,23 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
return;
}

"ptr_offset_from" => {
let ty = substs.type_at(0);
let pointee_size = self.size_of(ty);

// This is the same sequence that Clang emits for pointer subtraction.
// It can be neither `nsw` nor `nuw` because the input is treated as
// unsigned but then the output is treated as signed, so neither works.
let a = args[0].immediate();
let b = args[1].immediate();
let a = self.ptrtoint(a, self.type_isize());
let b = self.ptrtoint(b, self.type_isize());
let d = self.sub(a, b);
let pointee_size = self.const_usize(pointee_size.bytes());
// this is where the signed magic happens (notice the `s` in `exactsdiv`)
self.exactsdiv(d, pointee_size)
}

_ => bug!("unknown intrinsic '{}'", name),
};

Expand Down Expand Up @@ -1224,7 +1242,6 @@ fn generic_simd_intrinsic(
// The `fn simd_bitmask(vector) -> unsigned integer` intrinsic takes a
// vector mask and returns an unsigned integer containing the most
// significant bit (MSB) of each lane.
use rustc_target::abi::HasDataLayout;

// If the vector has less than 8 lanes, an u8 is returned with zeroed
// trailing bits.
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
needs_thin_lto: Vec<(String, B::ThinBuffer)>,
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>
) -> Vec<(WorkItem<B>, u64)> {
let _prof_timer = cgcx.prof.generic_activity("codegen_run_lto");
let _prof_timer = cgcx.prof.generic_activity("codegen_generate_lto_work");

let (lto_modules, copy_jobs) = if !needs_fat_lto.is_empty() {
assert!(needs_thin_lto.is_empty());
Expand Down Expand Up @@ -674,11 +674,11 @@ impl<B: WriteBackendMethods> WorkItem<B> {
}
}

pub fn name(&self) -> String {
fn profiling_event_id(&self) -> &'static str {
match *self {
WorkItem::Optimize(ref m) => format!("optimize: {}", m.name),
WorkItem::CopyPostLtoArtifacts(ref m) => format!("copy post LTO artifacts: {}", m.name),
WorkItem::LTO(ref m) => format!("lto: {}", m.name()),
WorkItem::Optimize(_) => "codegen_module_optimize",
WorkItem::CopyPostLtoArtifacts(_) => "codegen_copy_artifacts_from_incr_cache",
WorkItem::LTO(_) => "codegen_module_perform_lto",
}
}
}
Expand Down Expand Up @@ -1587,7 +1587,7 @@ fn spawn_work<B: ExtraBackendMethods>(
// as a diagnostic was already sent off to the main thread - just
// surface that there was an error in this worker.
bomb.result = {
let _prof_timer = cgcx.prof.generic_activity(&work.name());
let _prof_timer = cgcx.prof.generic_activity(work.profiling_event_id());
execute_work_item(&cgcx, work).ok()
};
});
Expand Down
37 changes: 24 additions & 13 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
rust_main_def_id: DefId,
use_start_lang_item: bool,
) {
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
// depending on whether the target needs `argc` and `argv` to be passed in.
let llfty = if cx.sess().target.target.options.main_needs_argc_argv {
cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int())
} else {
Expand Down Expand Up @@ -440,19 +442,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'

bx.insert_reference_to_gdb_debug_scripts_section_global();

let (arg_argc, arg_argv) = if cx.sess().target.target.options.main_needs_argc_argv {
// Params from native main() used as args for rust start function
let param_argc = bx.get_param(0);
let param_argv = bx.get_param(1);
let arg_argc = bx.intcast(param_argc, cx.type_isize(), true);
let arg_argv = param_argv;
(arg_argc, arg_argv)
} else {
// The Rust start function doesn't need argc and argv, so just pass zeros.
let arg_argc = bx.const_int(cx.type_int(), 0);
let arg_argv = bx.const_null(cx.type_ptr_to(cx.type_i8p()));
(arg_argc, arg_argv)
};
let (arg_argc, arg_argv) = get_argc_argv(cx, &mut bx);

let (start_fn, args) = if use_start_lang_item {
let start_def_id = cx.tcx().require_lang_item(StartFnLangItem, None);
Expand All @@ -477,6 +467,27 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
}
}

/// Obtain the `argc` and `argv` values to pass to the rust start function.
fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx,
bx: &mut Bx
) -> (Bx::Value, Bx::Value)
{
if cx.sess().target.target.options.main_needs_argc_argv {
// Params from native `main()` used as args for rust start function
let param_argc = bx.get_param(0);
let param_argv = bx.get_param(1);
let arg_argc = bx.intcast(param_argc, cx.type_isize(), true);
let arg_argv = param_argv;
(arg_argc, arg_argv)
} else {
// The Rust start function doesn't need `argc` and `argv`, so just pass zeros.
let arg_argc = bx.const_int(cx.type_int(), 0);
let arg_argv = bx.const_null(cx.type_ptr_to(cx.type_i8p()));
(arg_argc, arg_argv)
}
}

pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;

pub fn codegen_crate<B: ExtraBackendMethods>(
Expand Down
31 changes: 8 additions & 23 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<'tcx> EntryKind<'tcx> {
EntryKind::Mod(_) => DefKind::Mod,
EntryKind::Variant(_) => DefKind::Variant,
EntryKind::Trait(_) => DefKind::Trait,
EntryKind::TraitAlias(_) => DefKind::TraitAlias,
EntryKind::TraitAlias => DefKind::TraitAlias,
EntryKind::Enum(..) => DefKind::Enum,
EntryKind::MacroDef(_) => DefKind::Macro(MacroKind::Bang),
EntryKind::ForeignType => DefKind::ForeignTy,
Expand All @@ -458,7 +458,7 @@ impl<'tcx> EntryKind<'tcx> {
EntryKind::Impl(_) |
EntryKind::Field |
EntryKind::Generator(_) |
EntryKind::Closure(_) => return None,
EntryKind::Closure => return None,
})
}
}
Expand Down Expand Up @@ -575,7 +575,7 @@ impl<'a, 'tcx> CrateMetadata {
data.is_marker,
self.def_path_table.def_path_hash(item_id))
},
EntryKind::TraitAlias(_) => {
EntryKind::TraitAlias => {
ty::TraitDef::new(self.local_def_id(item_id),
hir::Unsafety::Normal,
false,
Expand Down Expand Up @@ -680,13 +680,7 @@ impl<'a, 'tcx> CrateMetadata {
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> {
let super_predicates = match self.kind(item_id) {
EntryKind::Trait(data) => data.decode(self).super_predicates,
EntryKind::TraitAlias(data) => data.decode(self).super_predicates,
_ => bug!("def-index does not refer to trait or trait alias"),
};

super_predicates.decode((self, tcx))
self.root.per_def.super_predicates.get(self, item_id).unwrap().decode((self, tcx))
}

crate fn get_generics(&self, item_id: DefIndex, sess: &Session) -> ty::Generics {
Expand Down Expand Up @@ -717,7 +711,7 @@ impl<'a, 'tcx> CrateMetadata {
}
}

fn get_impl_data(&self, id: DefIndex) -> ImplData<'tcx> {
fn get_impl_data(&self, id: DefIndex) -> ImplData {
match self.kind(id) {
EntryKind::Impl(data) => data.decode(self),
_ => bug!(),
Expand All @@ -744,7 +738,7 @@ impl<'a, 'tcx> CrateMetadata {
}

crate fn get_impl_trait(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option<ty::TraitRef<'tcx>> {
self.get_impl_data(id).trait_ref.map(|tr| tr.decode((self, tcx)))
self.root.per_def.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
}

/// Iterates over all the stability attributes in the given crate.
Expand Down Expand Up @@ -1118,7 +1112,7 @@ impl<'a, 'tcx> CrateMetadata {
def_key.parent.and_then(|parent_index| {
match self.kind(parent_index) {
EntryKind::Trait(_) |
EntryKind::TraitAlias(_) => Some(self.local_def_id(parent_index)),
EntryKind::TraitAlias => Some(self.local_def_id(parent_index)),
_ => None,
}
})
Expand Down Expand Up @@ -1245,16 +1239,7 @@ impl<'a, 'tcx> CrateMetadata {
}

crate fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
let sig = match self.kind(id) {
EntryKind::Fn(data) |
EntryKind::ForeignFn(data) => data.decode(self).sig,
EntryKind::Method(data) => data.decode(self).fn_data.sig,
EntryKind::Variant(data) |
EntryKind::Struct(data, _) => data.decode(self).ctor_sig.unwrap(),
EntryKind::Closure(data) => data.decode(self).sig,
_ => bug!(),
};
sig.decode((self, tcx))
self.root.per_def.fn_sig.get(self, id).unwrap().decode((self, tcx))
}

#[inline]
Expand Down
Loading