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 5 pull requests #74054

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn to_llvm_relocation_model(relocation_model: RelocModel) -> llvm::RelocModel {
}
}

fn to_llvm_code_model(code_model: Option<CodeModel>) -> llvm::CodeModel {
pub(crate) fn to_llvm_code_model(code_model: Option<CodeModel>) -> llvm::CodeModel {
match code_model {
Some(CodeModel::Tiny) => llvm::CodeModel::Tiny,
Some(CodeModel::Small) => llvm::CodeModel::Small,
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::attributes;
use crate::back::write::to_llvm_code_model;
use crate::callee::get_fn;
use crate::coverageinfo;
use crate::debuginfo;
Expand Down Expand Up @@ -181,6 +182,13 @@ pub unsafe fn create_module(
}
}

// Linking object files with different code models is undefined behavior
// because the compiler would have to generate additional code (to span
// longer jumps) if a larger code model is used with a smaller one.
//
// See https://reviews.llvm.org/D52322 and https://reviews.llvm.org/D52323.
llvm::LLVMRustSetModuleCodeModel(llmod, to_llvm_code_model(sess.code_model()));

// If skipping the PLT is enabled, we need to add some module metadata
// to ensure intrinsic calls don't use it.
if !sess.needs_plt() {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,7 @@ extern "C" {
pub fn LLVMRustUnsetComdat(V: &Value);
pub fn LLVMRustSetModulePICLevel(M: &Module);
pub fn LLVMRustSetModulePIELevel(M: &Module);
pub fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);
pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ declare_features! (
/// Allows capturing variables in scope using format_args!
(active, format_args_capture, "1.46.0", Some(67984), None),

/// Lazily evaluate constants. This allows constants to depend on type parameters.
(active, lazy_normalization_consts, "1.46.0", Some(72219), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand All @@ -586,5 +589,6 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::raw_dylib,
sym::const_trait_impl,
sym::const_trait_bound_opt_out,
sym::lazy_normalization_consts,
sym::specialization,
];
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// we still evaluate them eagerly.
#[inline]
pub fn lazy_normalization(self) -> bool {
self.features().const_generics
self.features().const_generics || self.features().lazy_normalization_consts
}

#[inline]
Expand Down
35 changes: 18 additions & 17 deletions src/librustc_middle/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,27 @@ pub trait PrettyPrinter<'tcx>:
// where there is no explicit `extern crate`, we just prepend
// the crate name.
match self.tcx().extern_crate(def_id) {
Some(&ExternCrate {
src: ExternCrateSource::Extern(def_id),
dependency_of: LOCAL_CRATE,
span,
..
}) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
(ExternCrateSource::Path, LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
},
None => {
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(terr) = self.eq_opaque_type_and_type(
mir_output_ty,
normalized_output_ty,
self.mir_def_id.to_def_id(),
self.mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
Expand All @@ -145,7 +145,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(err) = self.eq_opaque_type_and_type(
mir_output_ty,
user_provided_output_ty,
self.mir_def_id.to_def_id(),
self.mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// When you have `let x: impl Foo = ...` in a closure,
// the resulting inferend values are stored with the
// def-id of the base function.
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id.to_def_id());
let parent_def_id =
self.tcx().closure_base_def_id(self.mir_def_id.to_def_id()).expect_local();
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
} else {
return Err(terr);
Expand Down Expand Up @@ -1208,7 +1209,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&mut self,
revealed_ty: Ty<'tcx>,
anon_ty: Ty<'tcx>,
anon_owner_def_id: DefId,
anon_owner_def_id: LocalDefId,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
Expand Down Expand Up @@ -1238,8 +1239,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let tcx = infcx.tcx;
let param_env = self.param_env;
let body = self.body;
let concrete_opaque_types =
&tcx.typeck_tables_of(anon_owner_def_id.expect_local()).concrete_opaque_types;
let concrete_opaque_types = &tcx.typeck_tables_of(anon_owner_def_id).concrete_opaque_types;
let mut opaque_type_values = Vec::new();

debug!("eq_opaque_type_and_type: mir_def_id={:?}", self.mir_def_id);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ pub fn const_eval_raw_provider<'tcx>(
}

v
} else if def_id.is_local() {
} else if let Some(def_id) = def_id.as_local() {
// constant defined in this crate, we can figure out a lint level!
match tcx.def_kind(def_id) {
match tcx.def_kind(def_id.to_def_id()) {
// constants never produce a hard error at the definition site. Anything else is
// a backwards compatibility hazard (and will break old versions of winapi for
// sure)
Expand All @@ -346,7 +346,7 @@ pub fn const_eval_raw_provider<'tcx>(
// validation thus preventing such a hard error from being a backwards
// compatibility hazard
DefKind::Const | DefKind::AssocConst => {
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = tcx.hir().as_local_hir_id(def_id);
err.report_as_lint(
tcx.at(tcx.def_span(def_id)),
"any use of this value will cause an error",
Expand All @@ -369,7 +369,7 @@ pub fn const_eval_raw_provider<'tcx>(
err.report_as_lint(
tcx.at(span),
"reaching this expression at runtime will panic or abort",
tcx.hir().as_local_hir_id(def_id.expect_local()),
tcx.hir().as_local_hir_id(def_id),
Some(err.span),
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/check_consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod validation;
pub struct ConstCx<'mir, 'tcx> {
pub body: &'mir mir::Body<'tcx>,
pub tcx: TyCtxt<'tcx>,
pub def_id: DefId,
pub def_id: LocalDefId,
pub param_env: ty::ParamEnv<'tcx>,
pub const_kind: Option<hir::ConstContext>,
}
Expand All @@ -40,7 +40,7 @@ impl ConstCx<'mir, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
) -> Self {
let const_kind = tcx.hir().body_const_context(def_id);
ConstCx { body, tcx, def_id: def_id.to_def_id(), param_env, const_kind }
ConstCx { body, tcx, def_id: def_id, param_env, const_kind }
}

/// Returns the kind of const context this `Item` represents (`const`, `static`, etc.).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ pub fn check_live_drops(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &mir::Body<
return;
}

let ccx = ConstCx {
body,
tcx,
def_id: def_id.to_def_id(),
const_kind,
param_env: tcx.param_env(def_id),
};
let ccx = ConstCx { body, tcx, def_id, const_kind, param_env: tcx.param_env(def_id) };

let mut visitor = CheckLiveDrops { ccx: &ccx, qualifs: Qualifs::default() };

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Qualif for CustomEq {
// because that component may be part of an enum variant (e.g.,
// `Option::<NonStructuralMatchTy>::Some`), in which case some values of this type may be
// structural-match (`Option::None`).
let id = cx.tcx.hir().local_def_id_to_hir_id(cx.def_id.as_local().unwrap());
let id = cx.tcx.hir().local_def_id_to_hir_id(cx.def_id);
traits::search_for_structural_match_violation(id, cx.body.span, cx.tcx, ty).is_some()
}

Expand Down
18 changes: 9 additions & 9 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Qualifs<'mir, 'tcx> {
// without breaking stable code?
MaybeMutBorrowedLocals::mut_borrows_only(tcx, &body, param_env)
.unsound_ignore_borrow_on_drop()
.into_engine(tcx, &body, def_id)
.into_engine(tcx, &body, def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
Expand All @@ -83,7 +83,7 @@ impl Qualifs<'mir, 'tcx> {
let ConstCx { tcx, body, def_id, .. } = *ccx;

FlowSensitiveAnalysis::new(NeedsDrop, ccx)
.into_engine(tcx, &body, def_id)
.into_engine(tcx, &body, def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
Expand All @@ -110,7 +110,7 @@ impl Qualifs<'mir, 'tcx> {
let ConstCx { tcx, body, def_id, .. } = *ccx;

FlowSensitiveAnalysis::new(HasMutInterior, ccx)
.into_engine(tcx, &body, def_id)
.into_engine(tcx, &body, def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Qualifs<'mir, 'tcx> {

hir::ConstContext::Const | hir::ConstContext::Static(_) => {
let mut cursor = FlowSensitiveAnalysis::new(CustomEq, ccx)
.into_engine(ccx.tcx, &ccx.body, ccx.def_id)
.into_engine(ccx.tcx, &ccx.body, ccx.def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&ccx.body);

Expand Down Expand Up @@ -195,13 +195,13 @@ impl Validator<'mir, 'tcx> {
let ConstCx { tcx, body, def_id, const_kind, .. } = *self.ccx;

let use_min_const_fn_checks = (const_kind == Some(hir::ConstContext::ConstFn)
&& crate::const_eval::is_min_const_fn(tcx, def_id))
&& crate::const_eval::is_min_const_fn(tcx, def_id.to_def_id()))
&& !tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you;

if use_min_const_fn_checks {
// Enforce `min_const_fn` for stable `const fn`s.
use crate::transform::qualify_min_const_fn::is_min_const_fn;
if let Err((span, err)) = is_min_const_fn(tcx, def_id, &body) {
if let Err((span, err)) = is_min_const_fn(tcx, def_id.to_def_id(), &body) {
error_min_const_fn_violation(tcx, span, err);
return;
}
Expand All @@ -212,10 +212,10 @@ impl Validator<'mir, 'tcx> {
// Ensure that the end result is `Sync` in a non-thread local `static`.
let should_check_for_sync = const_kind
== Some(hir::ConstContext::Static(hir::Mutability::Not))
&& !tcx.is_thread_local_static(def_id);
&& !tcx.is_thread_local_static(def_id.to_def_id());

if should_check_for_sync {
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = tcx.hir().as_local_hir_id(def_id);
check_return_ty_is_sync(tcx, &body, hir_id);
}
}
Expand Down Expand Up @@ -535,7 +535,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
// `#[allow_internal_unstable]`.
use crate::transform::qualify_min_const_fn::lib_feature_allowed;
if !self.span.allows_unstable(feature)
&& !lib_feature_allowed(self.tcx, self.def_id, feature)
&& !lib_feature_allowed(self.tcx, self.def_id.to_def_id(), feature)
{
self.check_op(ops::FnCallUnstable(def_id, feature));
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ pub fn run_passes(
}

fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
let const_kind = tcx.hir().body_const_context(def_id.expect_local());
let def_id = def_id.expect_local();
let const_kind = tcx.hir().body_const_context(def_id);

// No need to const-check a non-const `fn`.
if const_kind.is_none() {
Expand All @@ -214,7 +215,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
// cannot yet be stolen), because `mir_validated()`, which steals
// from `mir_const(), forces this query to execute before
// performing the steal.
let body = &tcx.mir_const(def_id).borrow();
let body = &tcx.mir_const(def_id.to_def_id()).borrow();

if body.return_ty().references_error() {
tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors");
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
return;
}

let def_id = src.def_id();
let def_id = src.def_id().expect_local();

let mut rpo = traversal::reverse_postorder(body);
let ccx = ConstCx::new(tcx, def_id.expect_local(), body);
let ccx = ConstCx::new(tcx, def_id, body);
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);

let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);

let promoted = promote_candidates(def_id, body, tcx, temps, promotable_candidates);
let promoted =
promote_candidates(def_id.to_def_id(), body, tcx, temps, promotable_candidates);
self.promoted_fragments.set(promoted);
}
}
Expand Down Expand Up @@ -724,7 +725,7 @@ impl<'tcx> Validator<'_, 'tcx> {
ty::FnDef(def_id, _) => {
is_const_fn(self.tcx, def_id)
|| is_unstable_const_fn(self.tcx, def_id).is_some()
|| is_lang_panic_fn(self.tcx, self.def_id)
|| is_lang_panic_fn(self.tcx, self.def_id.to_def_id())
}
_ => false,
};
Expand Down
Loading