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 17 pull requests #76944

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
68 commits
Select commit Hold shift click to select a range
f8376b5
shim: monomorphic `FnPtrShim`s during construction
davidtwco Aug 9, 2020
a06edda
Fix segfault if pthread_getattr_np fails
tavianator Sep 9, 2020
a684153
Only call pthread_attr_destroy() after getattr_np() succeeds on all l…
tavianator Sep 9, 2020
80ce7fa
miri: correctly deal with `ConstKind::Bound`
lcnr Sep 10, 2020
ae85bbb
do not ICE on `ty::Bound` in Layout::compute
lcnr Sep 11, 2020
8f27e3c
Make some methods of `Pin` unstable const
CDirkx Sep 12, 2020
e5447a2
Fix #76432
simonvandel Sep 13, 2020
9c5d0c1
MIR pass to remove unneeded drops on types not needing drop
simonvandel Sep 13, 2020
9d47ecf
Suggestion from review
simonvandel Sep 14, 2020
94dae60
simplfy condition in ItemLowerer::with_trait_impl_ref()
matthiaskrgr Sep 16, 2020
b7c8bea
Fix wording in mir doc
pickfire Sep 17, 2020
f4a7149
Don't compile regex at every function call.
hbina Sep 17, 2020
b479139
Remove intrinsics::arith_offset use from libarena
est31 Sep 17, 2020
4fe6ca3
Replace const_generics feature gate with min_const_generics
est31 Sep 17, 2020
ebdea01
Remove redundant #![feature(...)] 's from compiler/
est31 Sep 17, 2020
5f58e00
fix array_windows docs
lcnr Sep 17, 2020
2793672
use `array_windows` instead of `windows` in the compiler
lcnr Sep 17, 2020
f193593
array pattern
lcnr Sep 17, 2020
012974d
use strip_prefix over starts_with and manual slicing based on pattern…
matthiaskrgr Sep 17, 2020
764d307
docs `array` -> `slice`
lcnr Sep 17, 2020
1dd3df6
black_box: silence unused_mut warning when building with cfg(miri)
RalfJung Sep 17, 2020
1ccfcb6
Set BUILD_TRIPLE via build script
Mark-Simulacrum Sep 6, 2020
ccdb48a
Remove support for different src directory
Mark-Simulacrum Sep 7, 2020
f0392c2
Discover Rust toolchain without Python
Mark-Simulacrum Sep 7, 2020
aac7d9e
Provide bootstrap tools with RUSTC in environment
Mark-Simulacrum Sep 10, 2020
afed561
Specify output directory for bootstrap tests
Mark-Simulacrum Sep 10, 2020
e3c6e46
Make some methods of `Pin<&mut T>` unstable const
CDirkx Sep 18, 2020
083f1d7
Validate constants during `const_eval_raw`
oli-obk Jul 30, 2020
2d7ac72
Stop using the `const_eval` query for initializers of statics
oli-obk Jul 31, 2020
6d3c7bb
Update codegen tests
oli-obk Jul 31, 2020
4397d66
Document `op_to_const`'s purpose
oli-obk Aug 10, 2020
b1bd34d
`turn_into_const` is infallible
oli-obk Aug 10, 2020
48f366f
Replace `and_then` `map_err` `and_then` chain with a match
oli-obk Aug 10, 2020
a6c60bb
Clarify a statement in UB test
oli-obk Aug 10, 2020
dd9702a
Do not call the `const_eval` query in mir interpretation except for c…
oli-obk Aug 10, 2020
40c2087
We can make const eval sound, it's just super expensive
oli-obk Aug 10, 2020
69a6be7
Rename const eval queries to reflect the validation changes
oli-obk Aug 10, 2020
888afd5
Unify the names of const eval queries and their return types
oli-obk Aug 20, 2020
90708c1
Fix rebase fallout and make the test work with debug info
oli-obk Aug 21, 2020
182ed85
Address review comments
oli-obk Sep 7, 2020
c3c8c98
Rustfmt
oli-obk Sep 9, 2020
ef04e68
Update compile-fail tests
oli-obk Sep 9, 2020
c5889e4
Update incremental tests
oli-obk Sep 9, 2020
b8e6883
Reflect the "do not call this query directly" mentality in its name
oli-obk Sep 19, 2020
673935f
Get LocalDefId from source instead of passing in
simonvandel Sep 19, 2020
30dd6cf
The optimization should also apply for DropAndReplace
simonvandel Sep 19, 2020
804f673
cleanup cfg after optimization
simonvandel Sep 19, 2020
4d1ef03
cleanup promotion const_kind checks
RalfJung Sep 6, 2020
7febd5a
fix doc comment
RalfJung Sep 7, 2020
7b99c8e
never promote non-const operations; revert STATIC promotion change
RalfJung Sep 9, 2020
9216eb8
fix some comments
RalfJung Sep 9, 2020
bb11ffc
Rollup merge of #74949 - oli-obk:validate_const_eval_raw, r=RalfJung
Dylan-DPC Sep 19, 2020
9d6d856
Rollup merge of #75346 - davidtwco:issue-69925-polymorphic-instancede…
Dylan-DPC Sep 19, 2020
71e3be0
Rollup merge of #76411 - RalfJung:promote-in-const-fn, r=ecstatic-morse
Dylan-DPC Sep 19, 2020
2f985d8
Rollup merge of #76521 - tavianator:fix-pthread-getattr-destroy, r=Am…
Dylan-DPC Sep 19, 2020
fd2251e
Rollup merge of #76544 - Mark-Simulacrum:less-python, r=alexcrichton
Dylan-DPC Sep 19, 2020
4846b1f
Rollup merge of #76581 - lcnr:bound-too-generic, r=eddyb
Dylan-DPC Sep 19, 2020
1f187ac
Rollup merge of #76655 - CDirkx:const-pin, r=ecstatic-morse
Dylan-DPC Sep 19, 2020
6a50cfa
Rollup merge of #76659 - simonvandel:76432, r=oli-obk
Dylan-DPC Sep 19, 2020
f334470
Rollup merge of #76673 - simonvandel:remove-unneeded-drops, r=oli-obk
Dylan-DPC Sep 19, 2020
6928c39
Rollup merge of #76809 - matthiaskrgr:simplify_cond, r=varkor
Dylan-DPC Sep 19, 2020
bd65273
Rollup merge of #76815 - pickfire:patch-6, r=jonas-schievink
Dylan-DPC Sep 19, 2020
daba283
Rollup merge of #76818 - hbina:dont_compile_regex_all_the_time, r=ecs…
Dylan-DPC Sep 19, 2020
16532d5
Rollup merge of #76821 - est31:remove_redundant_nightly_features, r=o…
Dylan-DPC Sep 19, 2020
57a51a5
Rollup merge of #76823 - RalfJung:black-box-warn, r=joshtriplett
Dylan-DPC Sep 19, 2020
5824de0
Rollup merge of #76825 - lcnr:array-windows-apply, r=varkor
Dylan-DPC Sep 19, 2020
0a99fbb
Rollup merge of #76827 - lcnr:array_windows-docs, r=jonas-schievink
Dylan-DPC Sep 19, 2020
1fad825
Rollup merge of #76828 - matthiaskrgr:clippy_manual_strip, r=lcnr
Dylan-DPC Sep 19, 2020
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
53 changes: 25 additions & 28 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 62,6 @@ pub enum InstanceDef<'tcx> {
/// `<fn() as FnTrait>::call_*` (generated `FnTrait` implementation for `fn()` pointers).
///
/// `DefId` is `FnTrait::call_*`.
///
/// NB: the (`fn` pointer) type must currently be monomorphic to avoid double substitution
/// problems with the MIR shim bodies. `Instance::resolve` enforces this.
// FIXME(#69925) support polymorphic MIR shim bodies properly instead.
FnPtrShim(DefId, Ty<'tcx>),

/// Dynamic dispatch to `<dyn Trait as Trait>::fn`.
Expand All @@ -87,10 83,6 @@ pub enum InstanceDef<'tcx> {
/// The `DefId` is for `core::ptr::drop_in_place`.
/// The `Option<Ty<'tcx>>` is either `Some(T)`, or `None` for empty drop
/// glue.
///
/// NB: the type must currently be monomorphic to avoid double substitution
/// problems with the MIR shim bodies. `Instance::resolve` enforces this.
// FIXME(#69925) support polymorphic MIR shim bodies properly instead.
DropGlue(DefId, Option<Ty<'tcx>>),

/// Compiler-generated `<T as Clone>::clone` implementation.
Expand All @@ -99,10 91,6 @@ pub enum InstanceDef<'tcx> {
/// Additionally, arrays, tuples, and closures get a `Clone` shim even if they aren't `Copy`.
///
/// The `DefId` is for `Clone::clone`, the `Ty` is the type `T` with the builtin `Clone` impl.
///
/// NB: the type must currently be monomorphic to avoid double substitution
/// problems with the MIR shim bodies. `Instance::resolve` enforces this.
// FIXME(#69925) support polymorphic MIR shim bodies properly instead.
CloneShim(DefId, Ty<'tcx>),
}

Expand Down Expand Up @@ -243,6 231,27 @@ impl<'tcx> InstanceDef<'tcx> {
_ => false,
}
}

/// Returns `true` when the MIR body associated with this instance should be monomorphized
/// by its users (e.g. codegen or miri) by substituting the `substs` from `Instance` (see
/// `Instance::substs_for_mir_body`).
///
/// Otherwise, returns `false` only for some kinds of shims where the construction of the MIR
/// body should perform necessary substitutions.
pub fn has_polymorphic_mir_body(&self) -> bool {
match *self {
InstanceDef::CloneShim(..)
| InstanceDef::FnPtrShim(..)
| InstanceDef::DropGlue(_, Some(_)) => false,
InstanceDef::ClosureOnceShim { .. }
| InstanceDef::DropGlue(..)
| InstanceDef::Item(_)
| InstanceDef::Intrinsic(..)
| InstanceDef::ReifyShim(..)
| InstanceDef::Virtual(..)
| InstanceDef::VtableShim(..) => true,
}
}
}

impl<'tcx> fmt::Display for Instance<'tcx> {
Expand Down Expand Up @@ -440,30 449,18 @@ impl<'tcx> Instance<'tcx> {
Instance { def, substs }
}

/// FIXME(#69925) Depending on the kind of `InstanceDef`, the MIR body associated with an
/// Depending on the kind of `InstanceDef`, the MIR body associated with an
/// instance is expressed in terms of the generic parameters of `self.def_id()`, and in other
/// cases the MIR body is expressed in terms of the types found in the substitution array.
/// In the former case, we want to substitute those generic types and replace them with the
/// values from the substs when monomorphizing the function body. But in the latter case, we
/// don't want to do that substitution, since it has already been done effectively.
///
/// This function returns `Some(substs)` in the former case and None otherwise -- i.e., if
/// This function returns `Some(substs)` in the former case and `None` otherwise -- i.e., if
/// this function returns `None`, then the MIR body does not require substitution during
/// monomorphization.
/// codegen.
pub fn substs_for_mir_body(&self) -> Option<SubstsRef<'tcx>> {
match self.def {
InstanceDef::CloneShim(..)
| InstanceDef::DropGlue(_, Some(_)) => None,
InstanceDef::ClosureOnceShim { .. }
| InstanceDef::DropGlue(..)
// FIXME(#69925): `FnPtrShim` should be in the other branch.
| InstanceDef::FnPtrShim(..)
| InstanceDef::Item(_)
| InstanceDef::Intrinsic(..)
| InstanceDef::ReifyShim(..)
| InstanceDef::Virtual(..)
| InstanceDef::VtableShim(..) => Some(self.substs),
}
if self.def.has_polymorphic_mir_body() { Some(self.substs) } else { None }
}

/// Returns a new `Instance` where generic parameters in `instance.substs` are replaced by
Expand Down
60 changes: 31 additions & 29 deletions compiler/rustc_mir/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
let mut result = match instance {
ty::InstanceDef::Item(..) => bug!("item {:?} passed to make_shim", instance),
ty::InstanceDef::VtableShim(def_id) => {
build_call_shim(tcx, instance, Some(Adjustment::Deref), CallKind::Direct(def_id), None)
build_call_shim(tcx, instance, Some(Adjustment::Deref), CallKind::Direct(def_id))
}
ty::InstanceDef::FnPtrShim(def_id, ty) => {
let trait_ = tcx.trait_of_item(def_id).unwrap();
Expand All @@ -42,24 42,16 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
Some(ty::ClosureKind::FnMut | ty::ClosureKind::Fn) => Adjustment::Deref,
None => bug!("fn pointer {:?} is not an fn", ty),
};
// HACK: we need the "real" argument types for the MIR,
// but because our substs are (Self, Args), where Args
// is a tuple, we must include the *concrete* argument
// types in the MIR. They will be substituted again with
// the param-substs, but because they are concrete, this
// will not do any harm.
let sig = tcx.erase_late_bound_regions(&ty.fn_sig(tcx));
let arg_tys = sig.inputs();

build_call_shim(tcx, instance, Some(adjustment), CallKind::Indirect(ty), Some(arg_tys))

build_call_shim(tcx, instance, Some(adjustment), CallKind::Indirect(ty))
}
// We are generating a call back to our def-id, which the
// codegen backend knows to turn to an actual call, be it
// a virtual call, or a direct call to a function for which
// indirect calls must be codegen'd differently than direct ones
// (such as `#[track_caller]`).
ty::InstanceDef::ReifyShim(def_id) => {
build_call_shim(tcx, instance, None, CallKind::Direct(def_id), None)
build_call_shim(tcx, instance, None, CallKind::Direct(def_id))
}
ty::InstanceDef::ClosureOnceShim { call_once: _ } => {
let fn_mut = tcx.require_lang_item(LangItem::FnMut, None);
Expand All @@ -70,13 62,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
.unwrap()
.def_id;

build_call_shim(
tcx,
instance,
Some(Adjustment::RefMut),
CallKind::Direct(call_mut),
None,
)
build_call_shim(tcx, instance, Some(Adjustment::RefMut), CallKind::Direct(call_mut))
}
ty::InstanceDef::DropGlue(def_id, ty) => build_drop_shim(tcx, def_id, ty),
ty::InstanceDef::CloneShim(def_id, ty) => build_clone_shim(tcx, def_id, ty),
Expand Down Expand Up @@ -641,29 627,45 @@ impl CloneShimBuilder<'tcx> {
}
}

/// Builds a "call" shim for `instance`. The shim calls the
/// function specified by `call_kind`, first adjusting its first
/// argument according to `rcvr_adjustment`.
///
/// If `untuple_args` is a vec of types, the second argument of the
/// function will be untupled as these types.
/// Builds a "call" shim for `instance`. The shim calls the function specified by `call_kind`,
/// first adjusting its first argument according to `rcvr_adjustment`.
fn build_call_shim<'tcx>(
tcx: TyCtxt<'tcx>,
instance: ty::InstanceDef<'tcx>,
rcvr_adjustment: Option<Adjustment>,
call_kind: CallKind<'tcx>,
untuple_args: Option<&[Ty<'tcx>]>,
) -> Body<'tcx> {
debug!(
"build_call_shim(instance={:?}, rcvr_adjustment={:?}, \
call_kind={:?}, untuple_args={:?})",
instance, rcvr_adjustment, call_kind, untuple_args
"build_call_shim(instance={:?}, rcvr_adjustment={:?}, call_kind={:?})",
instance, rcvr_adjustment, call_kind
);

// `FnPtrShim` contains the fn pointer type that a call shim is being built for - this is used
// to substitute into the signature of the shim. It is not necessary for users of this
// MIR body to perform further substitutions (see `InstanceDef::has_polymorphic_mir_body`).
let (sig_substs, untuple_args) = if let ty::InstanceDef::FnPtrShim(_, ty) = instance {
let sig = tcx.erase_late_bound_regions(&ty.fn_sig(tcx));

let untuple_args = sig.inputs();

// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
let arg_tup = tcx.mk_tup(untuple_args.iter());
let sig_substs = tcx.mk_substs_trait(ty, &[ty::subst::GenericArg::from(arg_tup)]);

(Some(sig_substs), Some(untuple_args))
} else {
(None, None)
};

let def_id = instance.def_id();
let sig = tcx.fn_sig(def_id);
let mut sig = tcx.erase_late_bound_regions(&sig);

assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
if let Some(sig_substs) = sig_substs {
sig = sig.subst(tcx, sig_substs);
}

if let CallKind::Indirect(fnty) = call_kind {
// `sig` determines our local decls, and thus the callee type in the `Call` terminator. This
// can only be an `FnDef` or `FnPtr`, but currently will be `Self` since the types come from
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
// MIR for `std::ops::Fn::call` before AddMovesForPackedDrops

fn std::ops::Fn::call(_1: *const fn(), _2: Args) -> <Self as FnOnce<Args>>::Output {
let mut _0: <Self as std::ops::FnOnce<Args>>::Output; // return place in scope 0 at $SRC_DIR/core/src/ops/function.rs:LL:COL
fn std::ops::Fn::call(_1: *const fn(), _2: ()) -> <fn() as FnOnce<()>>::Output {
let mut _0: <fn() as std::ops::FnOnce<()>>::Output; // return place in scope 0 at $SRC_DIR/core/src/ops/function.rs:LL:COL

bb0: {
_0 = move (*_1)() -> bb1; // scope 0 at $SRC_DIR/core/src/ops/function.rs:LL:COL
Expand Down