Skip to content

Rollup of 7 pull requests #118716

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0899efe
[DO NOT MERGE] update target feature following LLVM API change
krasimirgg Dec 4, 2023
43baf5d
[DO NOT MERGE] update target feature following LLVM API change
krasimirgg Dec 4, 2023
4ac3274
adapt llvm_util for the rename
krasimirgg Dec 6, 2023
0104620
update llvm version
krasimirgg Dec 6, 2023
5d3a294
Only check principal trait ref for object safety
compiler-errors Dec 6, 2023
281b65a
Add method to get type of an Rvalue in StableMIR
celinval Dec 6, 2023
e16ebdb
Simplify StaticDef to Instance conversion
celinval Dec 6, 2023
77d7e44
Update compiler/stable_mir/src/mir/body.rs
celinval Dec 7, 2023
4616b9f
Add sanity check to `BinOp::ty()`
celinval Dec 7, 2023
ec0110b
coverage: Merge refined spans in a separate final pass
Zalathar Dec 7, 2023
9089d28
coverage: Inline `push_refined_span`
Zalathar Dec 7, 2023
9a43215
coverage: Simplify code that pushes to `refined_spans`
Zalathar Dec 7, 2023
c0be10c
Ping GuillaumeGomez for changes in rustc_codegen_gcc
GuillaumeGomez Dec 7, 2023
cf1cecc
fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use
oksbsb Dec 7, 2023
399cd6c
targets: remove not-added {i386,i486}-unknown-linux-gnu
davidtwco Dec 7, 2023
78aedc7
Rollup merge of #118610 - krasimirgg:llvm-18-dec, r=nikic
matthiaskrgr Dec 7, 2023
309487a
Rollup merge of #118686 - compiler-errors:object-safety, r=lcnr
matthiaskrgr Dec 7, 2023
69f13c2
Rollup merge of #118688 - celinval:smir-rvalue-ty, r=compiler-errors
matthiaskrgr Dec 7, 2023
b64b2d5
Rollup merge of #118695 - Zalathar:push-refined, r=davidtwco
matthiaskrgr Dec 7, 2023
2079ccb
Rollup merge of #118707 - GuillaumeGomez:ping-cg_gcc, r=antoyo
matthiaskrgr Dec 7, 2023
e97a3fa
Rollup merge of #118709 - oksbsb:fix-job-server, r=petrochenkov
matthiaskrgr Dec 7, 2023
be7630e
Rollup merge of #118712 - davidtwco:targets-remove-i386-i486, r=compi…
matthiaskrgr Dec 7, 2023
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 compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> LLVMFeature<'a> {
"sve2-bitperm",
TargetFeatureFoldStrength::EnableOnly("neon"),
),
// The unaligned-scalar-mem feature was renamed to fast-unaligned-access.
("riscv32" | "riscv64", "fast-unaligned-access") if get_version().0 <= 17 => {
LLVMFeature::new("unaligned-scalar-mem")
}
(_, s) => LLVMFeature::new(s),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ const RISCV_ALLOWED_FEATURES: &[(&str, Stability)] = &[
("d", Unstable(sym::riscv_target_feature)),
("e", Unstable(sym::riscv_target_feature)),
("f", Unstable(sym::riscv_target_feature)),
("fast-unaligned-access", Unstable(sym::riscv_target_feature)),
("m", Stable),
("relax", Unstable(sym::riscv_target_feature)),
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature)),
("v", Unstable(sym::riscv_target_feature)),
("zba", Stable),
("zbb", Stable),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/jobserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn default_client() -> Client {

static GLOBAL_CLIENT_CHECKED: OnceLock<Client> = OnceLock::new();

pub fn check(report_warning: impl FnOnce(&'static str)) {
pub fn initialize_checked(report_warning: impl FnOnce(&'static str)) {
let client_checked = match &*GLOBAL_CLIENT {
Ok(client) => client.clone(),
Err(e) => {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
// Set parallel mode before thread pool creation, which will create `Lock`s.
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);

// Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread
let early_handler = EarlyErrorHandler::new(config.opts.error_format);
early_handler.initialize_checked_jobserver();

util::run_in_thread_pool_with_globals(
config.opts.edition,
config.opts.unstable_opts.threads,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use std::sync::Arc;

fn mk_session(matches: getopts::Matches) -> (Session, Cfg) {
let mut early_handler = EarlyErrorHandler::new(ErrorOutputType::default());
early_handler.initialize_checked_jobserver();

let registry = registry::Registry::new(&[]);
let sessopts = build_session_options(&mut early_handler, &matches);
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
Expand Down
87 changes: 37 additions & 50 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ impl CoverageSpan {
}
}

pub fn merge_from(&mut self, mut other: CoverageSpan) {
debug_assert!(self.is_mergeable(&other));
pub fn merge_from(&mut self, other: &Self) {
debug_assert!(self.is_mergeable(other));
self.span = self.span.to(other.span);
self.merged_spans.append(&mut other.merged_spans);
self.merged_spans.extend_from_slice(&other.merged_spans);
}

pub fn cutoff_statements_at(&mut self, cutoff_pos: BytePos) {
Expand Down Expand Up @@ -267,15 +267,15 @@ impl<'a> CoverageSpansGenerator<'a> {
if curr.is_mergeable(prev) {
debug!(" same bcb (and neither is a closure), merge with prev={prev:?}");
let prev = self.take_prev();
self.curr_mut().merge_from(prev);
self.curr_mut().merge_from(&prev);
self.maybe_push_macro_name_span();
// Note that curr.span may now differ from curr_original_span
} else if prev.span.hi() <= curr.span.lo() {
debug!(
" different bcbs and disjoint spans, so keep curr for next iter, and add prev={prev:?}",
);
let prev = self.take_prev();
self.push_refined_span(prev);
self.refined_spans.push(prev);
self.maybe_push_macro_name_span();
} else if prev.is_closure {
// drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
Expand Down Expand Up @@ -322,11 +322,10 @@ impl<'a> CoverageSpansGenerator<'a> {
let prev = self.take_prev();
debug!(" AT END, adding last prev={prev:?}");

// Take `pending_dups` so that we can drain it while calling self methods.
// It is never used as a field after this point.
for dup in std::mem::take(&mut self.pending_dups) {
// Drain any remaining dups into the output.
for dup in self.pending_dups.drain(..) {
debug!(" ...adding at least one pending dup={:?}", dup);
self.push_refined_span(dup);
self.refined_spans.push(dup);
}

// Async functions wrap a closure that implements the body to be executed. The enclosing
Expand All @@ -343,28 +342,27 @@ impl<'a> CoverageSpansGenerator<'a> {
};

if !body_ends_with_closure {
self.push_refined_span(prev);
self.refined_spans.push(prev);
}

// Do one last merge pass, to simplify the output.
self.refined_spans.dedup_by(|b, a| {
if a.is_mergeable(b) {
debug!(?a, ?b, "merging list-adjacent refined spans");
a.merge_from(b);
true
} else {
false
}
});

// Remove `CoverageSpan`s derived from closures, originally added to ensure the coverage
// regions for the current function leave room for the closure's own coverage regions
// (injected separately, from the closure's own MIR).
self.refined_spans.retain(|covspan| !covspan.is_closure);
self.refined_spans
}

fn push_refined_span(&mut self, covspan: CoverageSpan) {
if let Some(last) = self.refined_spans.last_mut()
&& last.is_mergeable(&covspan)
{
// Instead of pushing the new span, merge it with the last refined span.
debug!(?last, ?covspan, "merging new refined span with last refined span");
last.merge_from(covspan);
} else {
self.refined_spans.push(covspan);
}
}

/// If `curr` is part of a new macro expansion, carve out and push a separate
/// span that ends just after the macro name and its subsequent `!`.
fn maybe_push_macro_name_span(&mut self) {
Expand Down Expand Up @@ -397,7 +395,7 @@ impl<'a> CoverageSpansGenerator<'a> {
" and curr starts a new macro expansion, so add a new span just for \
the macro `{visible_macro}!`, new span={macro_name_cov:?}",
);
self.push_refined_span(macro_name_cov);
self.refined_spans.push(macro_name_cov);
}

fn curr(&self) -> &CoverageSpan {
Expand Down Expand Up @@ -454,19 +452,14 @@ impl<'a> CoverageSpansGenerator<'a> {
previous iteration, or prev started a new disjoint span"
);
if last_dup.span.hi() <= self.curr().span.lo() {
// Temporarily steal `pending_dups` into a local, so that we can
// drain it while calling other self methods.
let mut pending_dups = std::mem::take(&mut self.pending_dups);
for dup in pending_dups.drain(..) {
for dup in self.pending_dups.drain(..) {
debug!(" ...adding at least one pending={:?}", dup);
self.push_refined_span(dup);
self.refined_spans.push(dup);
}
// The list of dups is now empty, but we can recycle its capacity.
assert!(pending_dups.is_empty() && self.pending_dups.is_empty());
self.pending_dups = pending_dups;
} else {
self.pending_dups.clear();
}
assert!(self.pending_dups.is_empty());
}

/// Advance `prev` to `curr` (if any), and `curr` to the next `CoverageSpan` in sorted order.
Expand Down Expand Up @@ -513,22 +506,18 @@ impl<'a> CoverageSpansGenerator<'a> {
let has_pre_closure_span = prev.span.lo() < right_cutoff;
let has_post_closure_span = prev.span.hi() > right_cutoff;

// Temporarily steal `pending_dups` into a local, so that we can
// mutate and/or drain it while calling other self methods.
let mut pending_dups = std::mem::take(&mut self.pending_dups);

if has_pre_closure_span {
let mut pre_closure = self.prev().clone();
pre_closure.span = pre_closure.span.with_hi(left_cutoff);
debug!(" prev overlaps a closure. Adding span for pre_closure={:?}", pre_closure);
if !pending_dups.is_empty() {
for mut dup in pending_dups.iter().cloned() {
dup.span = dup.span.with_hi(left_cutoff);
debug!(" ...and at least one pre_closure dup={:?}", dup);
self.push_refined_span(dup);
}

for mut dup in self.pending_dups.iter().cloned() {
dup.span = dup.span.with_hi(left_cutoff);
debug!(" ...and at least one pre_closure dup={:?}", dup);
self.refined_spans.push(dup);
}
self.push_refined_span(pre_closure);

self.refined_spans.push(pre_closure);
}

if has_post_closure_span {
Expand All @@ -537,19 +526,17 @@ impl<'a> CoverageSpansGenerator<'a> {
// about how the `CoverageSpan`s are ordered.)
self.prev_mut().span = self.prev().span.with_lo(right_cutoff);
debug!(" Mutated prev.span to start after the closure. prev={:?}", self.prev());
for dup in pending_dups.iter_mut() {

for dup in &mut self.pending_dups {
debug!(" ...and at least one overlapping dup={:?}", dup);
dup.span = dup.span.with_lo(right_cutoff);
}

let closure_covspan = self.take_curr(); // Prevent this curr from becoming prev.
self.push_refined_span(closure_covspan); // since self.prev() was already updated
self.refined_spans.push(closure_covspan); // since self.prev() was already updated
} else {
pending_dups.clear();
self.pending_dups.clear();
}

// Restore the modified post-closure spans, or the empty vector's capacity.
assert!(self.pending_dups.is_empty());
self.pending_dups = pending_dups;
}

/// Called if `curr.span` equals `prev_original_span` (and potentially equal to all
Expand Down Expand Up @@ -645,7 +632,7 @@ impl<'a> CoverageSpansGenerator<'a> {
} else {
debug!(" ... adding modified prev={:?}", self.prev());
let prev = self.take_prev();
self.push_refined_span(prev);
self.refined_spans.push(prev);
}
} else {
// with `pending_dups`, `prev` cannot have any statements that don't overlap
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,17 +1474,6 @@ pub fn build_session(
let asm_arch =
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };

// Check jobserver before getting `jobserver::client`.
jobserver::check(|err| {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
parse_sess
.span_diagnostic
.struct_warn(err)
.note("the build environment is likely misconfigured")
.emit()
});

let sess = Session {
target: target_cfg,
host,
Expand Down Expand Up @@ -1792,6 +1781,18 @@ impl EarlyErrorHandler {
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
self.handler.struct_warn(msg).emit()
}

pub fn initialize_checked_jobserver(&self) {
// initialize jobserver before getting `jobserver::client` and `build_session`.
jobserver::initialize_checked(|err| {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
self.handler
.struct_warn(err)
.note("the build environment is likely misconfigured")
.emit()
});
}
}

fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
Expand Down
18 changes: 16 additions & 2 deletions compiler/rustc_smir/src/rustc_smir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.tcx.mk_ty_from_kind(internal_kind).stable(&mut *tables)
}

#[allow(rustc::usage_of_qualified_ty)]
fn new_box_ty(&self, ty: stable_mir::ty::Ty) -> stable_mir::ty::Ty {
let mut tables = self.0.borrow_mut();
let inner = ty.internal(&mut *tables);
ty::Ty::new_box(tables.tcx, inner).stable(&mut *tables)
}

fn def_ty(&self, item: stable_mir::DefId) -> stable_mir::ty::Ty {
let mut tables = self.0.borrow_mut();
tables.tcx.type_of(item.internal(&mut *tables)).instantiate_identity().stable(&mut *tables)
Expand All @@ -276,6 +283,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.types[ty].kind().stable(&mut *tables)
}

fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> stable_mir::ty::Ty {
let mut tables = self.0.borrow_mut();
let internal_kind = ty.internal(&mut *tables);
let internal_ty = tables.tcx.mk_ty_from_kind(internal_kind);
internal_ty.discriminant_ty(tables.tcx).stable(&mut *tables)
}

fn instance_body(&self, def: InstanceDef) -> Option<Body> {
let mut tables = self.0.borrow_mut();
let instance = tables.instances[def];
Expand Down Expand Up @@ -308,9 +322,9 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
matches!(instance.def, ty::InstanceDef::DropGlue(_, None))
}

fn mono_instance(&self, item: stable_mir::CrateItem) -> stable_mir::mir::mono::Instance {
fn mono_instance(&self, def_id: stable_mir::DefId) -> stable_mir::mir::mono::Instance {
let mut tables = self.0.borrow_mut();
let def_id = tables[item.0];
let def_id = tables[def_id];
Instance::mono(tables.tcx, def_id).stable(&mut *tables)
}

Expand Down

This file was deleted.

This file was deleted.

17 changes: 7 additions & 10 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,18 +761,15 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let defer_to_coercion = self.tcx().features().object_safe_for_dispatch;

if !defer_to_coercion {
let cause = self.cause(traits::WellFormed(None));
let component_traits = data.auto_traits().chain(data.principal_def_id());
let tcx = self.tcx();
self.out.extend(component_traits.map(|did| {
traits::Obligation::with_depth(
tcx,
cause.clone(),
if let Some(principal) = data.principal_def_id() {
self.out.push(traits::Obligation::with_depth(
self.tcx(),
self.cause(traits::WellFormed(None)),
depth,
param_env,
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(did)),
)
}));
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(principal)),
));
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion compiler/stable_mir/src/compiler_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub trait Context {
/// Create a new type from the given kind.
fn new_rigid_ty(&self, kind: RigidTy) -> Ty;

/// Create a new box type, `Box<T>`, for the given inner type `T`.
fn new_box_ty(&self, ty: Ty) -> Ty;

/// Returns the type of given crate item.
fn def_ty(&self, item: DefId) -> Ty;

Expand All @@ -102,6 +105,9 @@ pub trait Context {
/// Obtain the representation of a type.
fn ty_kind(&self, ty: Ty) -> TyKind;

// Get the discriminant Ty for this Ty if there's one.
fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty;

/// Get the body of an Instance which is already monomorphized.
fn instance_body(&self, instance: InstanceDef) -> Option<Body>;

Expand All @@ -119,7 +125,7 @@ pub trait Context {

/// Convert a non-generic crate item into an instance.
/// This function will panic if the item is generic.
fn mono_instance(&self, item: CrateItem) -> Instance;
fn mono_instance(&self, def_id: DefId) -> Instance;

/// Item requires monomorphization.
fn requires_monomorphization(&self, def_id: DefId) -> bool;
Expand Down
Loading