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 4 pull requests #66948

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c2c4dc1
rustc: combine Instance::fn_sig_noadjust and Instance::fn_sig.
eddyb Oct 28, 2019
6159505
rustc_mir: don't hardcode InstanceDef::VtableShim behavior to Adjustm…
eddyb Oct 28, 2019
4e15e2e
rustc_codegen_ssa: use &'tcx mir::Body<'tcx> instead of &'a ... for t…
eddyb Oct 29, 2019
473f908
rustc_codegen_ssa: make codegen_instance a simple wrapper for codegen…
eddyb Oct 29, 2019
45e7c94
rustc_codegen_ssa: clean up lifetimes on TerminatorCodegenHelper's me…
eddyb Oct 29, 2019
6c8fb6e
rustc_codegen_ssa: remove define_fn and define_internal_fn.
eddyb Oct 29, 2019
e370753
rustc_codegen_ssa: take a FnAbi instead of a FnSig in declare_fn.
eddyb Oct 29, 2019
6de254d
rustc_codegen_llvm: move NoReturn attribute to apply_attrs_llfn.
eddyb Oct 29, 2019
d57c15f
rustc_codegen_ssa: use FnAbi::of_instance wherever possible.
eddyb Oct 29, 2019
6862a84
rustc: use ReifyShim for reifying Virtual call instances.
eddyb Oct 29, 2019
880f905
rustc: compute FnAbi's for virtual calls through FnAbi::of_instance.
eddyb Oct 29, 2019
49bed20
rustc: rename FnAbi::new to FnAbi::of_fn_ptr.
eddyb Oct 29, 2019
0e70c4d
rustc: take a PolyFnSig instead of an FnSig in FnAbi::of_fn_ptr.
eddyb Oct 29, 2019
8be241f
rustc_codegen_llvm: rewrite debuginfo::get_function_signature to use …
eddyb Oct 29, 2019
30edd33
rustc_codegen_llvm: take an Instance in attributes::from_fn_attrs.
eddyb Nov 27, 2019
5bdcde2
rustc_codegen_llvm: privatize as much of attributes::* as possible.
eddyb Nov 27, 2019
4140720
rustc_target: add abi::call::Conv::Rust distinct from Conv::C.
eddyb Nov 27, 2019
3315d70
rustc: move Instance::fn_sig to ty::layout and privatize it.
eddyb Nov 27, 2019
0232114
rustc: add docs to FnAbi::{of_fn_ptr,of_instance} and InstanceDef::Vi…
eddyb Nov 27, 2019
3e7a5a4
handle diverging functions forwarding their return place
RalfJung Nov 27, 2019
2869aba
comment
RalfJung Nov 27, 2019
a9dca3b
rustbuild: fix cross-compile install
infinity0 Nov 28, 2019
0533249
rustbuild: don't clobber RUSTFLAGS, append to it
infinity0 Nov 28, 2019
c703ff2
Conditional compilation for sanitizers
tmiasko Oct 22, 2019
67a049d
Rollup merge of #65947 - eddyb:fn-abi, r=oli-obk,nagisa
RalfJung Dec 2, 2019
7a75bbf
Rollup merge of #66245 - tmiasko:cfg-sanitize, r=oli-obk
RalfJung Dec 2, 2019
92c6187
Rollup merge of #66827 - RalfJung:miri-missing-ret-place, r=oli-obk
RalfJung Dec 2, 2019
60c42a3
Rollup merge of #66834 - infinity0:master, r=Mark-Simulacrum
RalfJung Dec 2, 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
12 changes: 7 additions & 5 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,9 @@ def build_bootstrap(self):
env["LIBRARY_PATH"] = os.path.join(self.bin_root(), "lib") + \
(os.pathsep + env["LIBRARY_PATH"]) \
if "LIBRARY_PATH" in env else ""
env["RUSTFLAGS"] = "-Cdebuginfo=2 "
# preserve existing RUSTFLAGS
env.setdefault("RUSTFLAGS", "")
env["RUSTFLAGS"] += " -Cdebuginfo=2"

build_section = "target.{}".format(self.build_triple())
target_features = []
Expand All @@ -652,13 +654,13 @@ def build_bootstrap(self):
elif self.get_toml("crt-static", build_section) == "false":
target_features += ["-crt-static"]
if target_features:
env["RUSTFLAGS"] += "-C target-feature=" + (",".join(target_features)) + " "
env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features))
target_linker = self.get_toml("linker", build_section)
if target_linker is not None:
env["RUSTFLAGS"] += "-C linker=" + target_linker + " "
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes "
env["RUSTFLAGS"] += " -C linker=" + target_linker
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
if self.get_toml("deny-warnings", "rust") != "false":
env["RUSTFLAGS"] += "-Dwarnings "
env["RUSTFLAGS"] += " -Dwarnings"

env["PATH"] = os.path.join(self.bin_root(), "bin") + \
os.pathsep + env["PATH"]
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ install!((self, builder, _config),
};
Rustc, "src/librustc", true, only_hosts: true, {
builder.ensure(dist::Rustc {
compiler: self.compiler,
compiler: builder.compiler(builder.top_stage, self.target),
});
install_rustc(builder, self.compiler.stage, self.target);
};
Expand Down
36 changes: 36 additions & 0 deletions src/doc/unstable-book/src/language-features/cfg-sanitize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# `cfg_sanitize`

The tracking issue for this feature is: [#39699]

[#39699]: https://github.com/rust-lang/rust/issues/39699

------------------------

The `cfg_sanitize` feature makes it possible to execute different code
depending on whether a particular sanitizer is enabled or not.

## Examples

``` rust
#![feature(cfg_sanitize)]

#[cfg(sanitize = "thread")]
fn a() {
// ...
}

#[cfg(not(sanitize = "thread"))]
fn a() {
// ...
}

fn b() {
if cfg!(sanitize = "leak") {
// ...
} else {
// ...
}
}

```

15 changes: 15 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ pub enum Sanitizer {
Thread,
}

impl fmt::Display for Sanitizer {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Sanitizer::Address => "address".fmt(f),
Sanitizer::Leak => "leak".fmt(f),
Sanitizer::Memory => "memory".fmt(f),
Sanitizer::Thread => "thread".fmt(f),
}
}
}

impl FromStr for Sanitizer {
type Err = ();
fn from_str(s: &str) -> Result<Sanitizer, ()> {
Expand Down Expand Up @@ -1580,6 +1591,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
}
}
}
if let Some(s) = &sess.opts.debugging_opts.sanitizer {
let symbol = Symbol::intern(&s.to_string());
ret.insert((sym::sanitize, Some(symbol)));
}
if sess.opts.debug_assertions {
ret.insert((Symbol::intern("debug_assertions"), None));
}
Expand Down
106 changes: 26 additions & 80 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::hir::CodegenFnAttrFlags;
use crate::hir::Unsafety;
use crate::hir::def::Namespace;
use crate::hir::def_id::DefId;
use crate::ty::{self, Ty, PolyFnSig, TypeFoldable, SubstsRef, TyCtxt};
use crate::ty::{self, Ty, TypeFoldable, SubstsRef, TyCtxt};
use crate::ty::print::{FmtPrinter, Printer};
use crate::traits;
use crate::middle::lang_items::DropInPlaceFnLangItem;
use rustc_target::spec::abi::Abi;
use rustc_macros::HashStable;

use std::fmt;
use std::iter;

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
#[derive(HashStable, Lift)]
Expand All @@ -29,17 +27,26 @@ pub enum InstanceDef<'tcx> {

/// `fn()` pointer where the function itself cannot be turned into a pointer.
///
/// One example in the compiler today is functions annotated with `#[track_caller]`, which
/// must have their implicit caller location argument populated for a call. Because this is a
/// required part of the function's ABI but can't be tracked as a property of the function
/// pointer, we create a single "caller location" at the site where the function is reified.
/// One example is `<dyn Trait as Trait>::fn`, where the shim contains
/// a virtual call, which codegen supports only via a direct call to the
/// `<dyn Trait as Trait>::fn` instance (an `InstanceDef::Virtual`).
///
/// Another example is functions annotated with `#[track_caller]`, which
/// must have their implicit caller location argument populated for a call.
/// Because this is a required part of the function's ABI but can't be tracked
/// as a property of the function pointer, we use a single "caller location"
/// (the definition of the function itself).
ReifyShim(DefId),

/// `<fn() as FnTrait>::call_*`
/// `DefId` is `FnTrait::call_*`.
FnPtrShim(DefId, Ty<'tcx>),

/// `<dyn Trait as Trait>::fn`
/// `<dyn Trait as Trait>::fn`, "direct calls" of which are implicitly
/// codegen'd as virtual calls.
///
/// NB: if this is reified to a `fn` pointer, a `ReifyShim` is used
/// (see `ReifyShim` above for more details on that).
Virtual(DefId, usize),

/// `<[mut closure] as FnOnce>::call_once`
Expand All @@ -61,70 +68,6 @@ impl<'tcx> Instance<'tcx> {
&ty,
)
}

fn fn_sig_noadjust(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
let ty = self.ty(tcx);
match ty.kind {
ty::FnDef(..) |
// Shims currently have type FnPtr. Not sure this should remain.
ty::FnPtr(_) => ty.fn_sig(tcx),
ty::Closure(def_id, substs) => {
let sig = substs.as_closure().sig(def_id, tcx);

let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
sig.map_bound(|sig| tcx.mk_fn_sig(
iter::once(*env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
sig.output(),
sig.c_variadic,
sig.unsafety,
sig.abi
))
}
ty::Generator(def_id, substs, _) => {
let sig = substs.as_generator().poly_sig(def_id, tcx);

let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);

let pin_did = tcx.lang_items().pin_type().unwrap();
let pin_adt_ref = tcx.adt_def(pin_did);
let pin_substs = tcx.intern_substs(&[env_ty.into()]);
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);

sig.map_bound(|sig| {
let state_did = tcx.lang_items().gen_state().unwrap();
let state_adt_ref = tcx.adt_def(state_did);
let state_substs = tcx.intern_substs(&[
sig.yield_ty.into(),
sig.return_ty.into(),
]);
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);

tcx.mk_fn_sig(iter::once(env_ty),
ret_ty,
false,
Unsafety::Normal,
Abi::Rust
)
})
}
_ => bug!("unexpected type {:?} in Instance::fn_sig_noadjust", ty)
}
}

pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
let mut fn_sig = self.fn_sig_noadjust(tcx);
if let InstanceDef::VtableShim(..) = self.def {
// Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
fn_sig = fn_sig.map_bound(|mut fn_sig| {
let mut inputs_and_output = fn_sig.inputs_and_output.to_vec();
inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
fn_sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
fn_sig
});
}
fn_sig
}
}

impl<'tcx> InstanceDef<'tcx> {
Expand Down Expand Up @@ -196,7 +139,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
write!(f, " - intrinsic")
}
InstanceDef::Virtual(_, num) => {
write!(f, " - shim(#{})", num)
write!(f, " - virtual#{}", num)
}
InstanceDef::FnPtrShim(_, ty) => {
write!(f, " - shim({:?})", ty)
Expand Down Expand Up @@ -311,20 +254,23 @@ impl<'tcx> Instance<'tcx> {
substs: SubstsRef<'tcx>,
) -> Option<Instance<'tcx>> {
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
Instance::resolve(tcx, param_env, def_id, substs).map(|resolved| {
Instance::resolve(tcx, param_env, def_id, substs).map(|mut resolved| {
let has_track_caller = |def| tcx.codegen_fn_attrs(def).flags
.contains(CodegenFnAttrFlags::TRACK_CALLER);

match resolved.def {
InstanceDef::Item(def_id) if has_track_caller(def_id) => {
debug!(" => fn pointer created for function with #[track_caller]");
Instance {
def: InstanceDef::ReifyShim(def_id),
substs,
}
},
_ => resolved,
resolved.def = InstanceDef::ReifyShim(def_id);
}
InstanceDef::Virtual(def_id, _) => {
debug!(" => fn pointer created for virtual call");
resolved.def = InstanceDef::ReifyShim(def_id);
}
_ => {}
}

resolved
})
}

Expand Down
Loading