Skip to content

Rollup of 11 pull requests #141739

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

Merged
merged 34 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8bed646
Enable review queue tracking
Kobzol May 22, 2025
19fd098
float: Disable `total_cmp` sNaN tests for `f16`
tgross35 May 28, 2025
0527f02
Add `eslint` as part of tidy run
GuillaumeGomez May 28, 2025
9e5dd51
Remove checks that are run with `tidy`
GuillaumeGomez May 28, 2025
c593c01
Remove codegen_unit from MiscCodegenMethods
bjorn3 Dec 13, 2024
5b0ab2c
The personality function is a Function, not a Value
bjorn3 Dec 13, 2024
a4cb1c7
Reduce amount of types that need to be PartialEq
bjorn3 Dec 13, 2024
0fd257d
Remove a couple of uses of interior mutability around statics
bjorn3 Dec 13, 2024
0809b41
Move supports_parallel from CodegenBackend to ExtraBackendMethods
bjorn3 Jan 9, 2025
669e2ea
Make predefine methods take &mut self
bjorn3 Jan 9, 2025
d7c0bde
Remove methods from StaticCodegenMethods that are not called in cg_ss…
bjorn3 Jan 9, 2025
f0707fa
Mark all optimize methods and the codegen method as safe
bjorn3 Jan 9, 2025
865c7b9
Remove unused arg_memory_ty method
bjorn3 Nov 7, 2024
b2858f3
Add `loongarch64` with `d` feature to `f32::midpoint` fast path
heiher May 24, 2025
367a877
avoid some usages of `&mut P<T>` in AST visitors
fee1-dead May 27, 2025
059bc38
Provide secrets to try builds with new bors
Kobzol May 29, 2025
8e5d579
Fix false documentation
JonathanBrouwer May 29, 2025
8c8d2c2
creader: Remove extraenous String::clone
osiewicz May 29, 2025
0d9f25b
resolve target-libdir directly from rustc
onur-ozkan May 29, 2025
f0f661d
Install eslint in host-x86_64 Dockerfile
GuillaumeGomez May 29, 2025
b1723fc
Centralize the eslint version between tidy and docker
GuillaumeGomez May 29, 2025
a5f3b1e
Make `std/src/num` mirror `core/src/num`
tgross35 Feb 25, 2025
8645ef7
Fix npm install error
GuillaumeGomez May 29, 2025
be64109
Rollup merge of #137574 - tgross35:std-float-reorganization, r=workin…
GuillaumeGomez May 29, 2025
08bbf24
Rollup merge of #141384 - Kobzol:enable-review-prefs, r=jieyouxu
GuillaumeGomez May 29, 2025
161cf3e
Rollup merge of #141448 - bjorn3:codegen_refactors, r=WaffleLapkin
GuillaumeGomez May 29, 2025
2b08e4d
Rollup merge of #141636 - fee1-dead-contrib:push-ntqvvxwuvrvx, r=petr…
GuillaumeGomez May 29, 2025
cb7efc0
Rollup merge of #141676 - tgross35:f16-disable-total-cmp, r=workingju…
GuillaumeGomez May 29, 2025
a547af9
Rollup merge of #141705 - GuillaumeGomez:eslint-tidy, r=Kobzol
GuillaumeGomez May 29, 2025
8c708a4
Rollup merge of #141715 - heiher:loong64-f32-midpoint, r=the8472
GuillaumeGomez May 29, 2025
5f6f23a
Rollup merge of #141723 - Kobzol:new-bors-try, r=marcoieni
GuillaumeGomez May 29, 2025
710fa11
Rollup merge of #141728 - JonathanBrouwer:fix-docs, r=compiler-errors
GuillaumeGomez May 29, 2025
aaa9159
Rollup merge of #141729 - onur-ozkan:fix-141722, r=jieyouxu
GuillaumeGomez May 29, 2025
18646a8
Rollup merge of #141732 - osiewicz:creader-remove-extraenous-string-c…
GuillaumeGomez May 29, 2025
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
Prev Previous commit
Next Next commit
Mark all optimize methods and the codegen method as safe
There is no safety contract and I don't think any of them can actually
cause UB in more ways than passing malicious source code to rustc can.
While LtoModuleCodegen::optimize says that the returned ModuleCodegen
points into the LTO module, the LTO module has already been dropped by
the time this function returns, so if the returned ModuleCodegen indeed
points into the LTO module, we would have seen crashes on every LTO
compilation, which we don't. As such the comment is outdated.
  • Loading branch information
bjorn3 committed May 28, 2025
commit f0707fad319777ed5da4b6eb1eb908cb44ab8c18
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl WriteBackendMethods for GccCodegenBackend {
unimplemented!()
}

unsafe fn optimize(
fn optimize(
_cgcx: &CodegenContext<Self>,
_dcx: DiagCtxtHandle<'_>,
module: &mut ModuleCodegen<Self::Module>,
Expand All @@ -409,14 +409,14 @@ impl WriteBackendMethods for GccCodegenBackend {
Ok(())
}

unsafe fn optimize_thin(
fn optimize_thin(
cgcx: &CodegenContext<Self>,
thin: ThinModule<Self>,
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
back::lto::optimize_thin_module(thin, cgcx)
}

unsafe fn codegen(
fn codegen(
cgcx: &CodegenContext<Self>,
dcx: DiagCtxtHandle<'_>,
module: ModuleCodegen<Self::Module>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ impl Drop for ThinBuffer {
}
}

pub(crate) unsafe fn optimize_thin_module(
pub(crate) fn optimize_thin_module(
thin_module: ThinModule<LlvmCodegenBackend>,
cgcx: &CodegenContext<LlvmCodegenBackend>,
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ pub(crate) unsafe fn llvm_optimize(
}

// Unsafe due to LLVM calls.
pub(crate) unsafe fn optimize(
pub(crate) fn optimize(
cgcx: &CodegenContext<LlvmCodegenBackend>,
dcx: DiagCtxtHandle<'_>,
module: &mut ModuleCodegen<ModuleLlvm>,
Expand Down Expand Up @@ -815,7 +815,7 @@ pub(crate) fn link(
Ok(modules.remove(0))
}

pub(crate) unsafe fn codegen(
pub(crate) fn codegen(
cgcx: &CodegenContext<LlvmCodegenBackend>,
dcx: DiagCtxtHandle<'_>,
module: ModuleCodegen<ModuleLlvm>,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ impl WriteBackendMethods for LlvmCodegenBackend {
) -> Result<(Vec<LtoModuleCodegen<Self>>, Vec<WorkProduct>), FatalError> {
back::lto::run_thin(cgcx, modules, cached_modules)
}
unsafe fn optimize(
fn optimize(
cgcx: &CodegenContext<Self>,
dcx: DiagCtxtHandle<'_>,
module: &mut ModuleCodegen<Self::Module>,
config: &ModuleConfig,
) -> Result<(), FatalError> {
unsafe { back::write::optimize(cgcx, dcx, module, config) }
back::write::optimize(cgcx, dcx, module, config)
}
fn optimize_fat(
cgcx: &CodegenContext<Self>,
Expand All @@ -205,19 +205,19 @@ impl WriteBackendMethods for LlvmCodegenBackend {
let dcx = dcx.handle();
back::lto::run_pass_manager(cgcx, dcx, module, false)
}
unsafe fn optimize_thin(
fn optimize_thin(
cgcx: &CodegenContext<Self>,
thin: ThinModule<Self>,
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
unsafe { back::lto::optimize_thin_module(thin, cgcx) }
back::lto::optimize_thin_module(thin, cgcx)
}
unsafe fn codegen(
fn codegen(
cgcx: &CodegenContext<Self>,
dcx: DiagCtxtHandle<'_>,
module: ModuleCodegen<Self::Module>,
config: &ModuleConfig,
) -> Result<CompiledModule, FatalError> {
unsafe { back::write::codegen(cgcx, dcx, module, config) }
back::write::codegen(cgcx, dcx, module, config)
}
fn prepare_thin(
module: ModuleCodegen<Self::Module>,
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_codegen_ssa/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
}

/// Optimize this module within the given codegen context.
///
/// This function is unsafe as it'll return a `ModuleCodegen` still
/// points to LLVM data structures owned by this `LtoModuleCodegen`.
/// It's intended that the module returned is immediately code generated and
/// dropped, and then this LTO module is dropped.
pub unsafe fn optimize(
pub fn optimize(
self,
cgcx: &CodegenContext<B>,
) -> Result<ModuleCodegen<B::Module>, FatalError> {
Expand All @@ -70,7 +65,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
B::optimize_fat(cgcx, &mut module)?;
Ok(module)
}
LtoModuleCodegen::Thin(thin) => unsafe { B::optimize_thin(cgcx, thin) },
LtoModuleCodegen::Thin(thin) => B::optimize_thin(cgcx, thin),
}
}

Expand All @@ -85,7 +80,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
}

/// Run autodiff on Fat LTO module
pub unsafe fn autodiff(
pub fn autodiff(
self,
cgcx: &CodegenContext<B>,
diff_fncs: Vec<AutoDiffItem>,
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
B::run_fat_lto(cgcx, needs_fat_lto, import_only_modules).unwrap_or_else(|e| e.raise());
if cgcx.lto == Lto::Fat && !autodiff.is_empty() {
let config = cgcx.config(ModuleKind::Regular);
module =
unsafe { module.autodiff(cgcx, autodiff, config).unwrap_or_else(|e| e.raise()) };
module = module.autodiff(cgcx, autodiff, config).unwrap_or_else(|e| e.raise());
}
// We are adding a single work item, so the cost doesn't matter.
vec![(WorkItem::LTO(module), 0)]
Expand Down Expand Up @@ -887,9 +886,7 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
let dcx = cgcx.create_dcx();
let dcx = dcx.handle();

unsafe {
B::optimize(cgcx, dcx, &mut module, module_config)?;
}
B::optimize(cgcx, dcx, &mut module, module_config)?;

// After we've done the initial round of optimizations we need to
// decide whether to synchronously codegen this module or ship it
Expand Down Expand Up @@ -1020,7 +1017,7 @@ fn execute_lto_work_item<B: ExtraBackendMethods>(
module: lto::LtoModuleCodegen<B>,
module_config: &ModuleConfig,
) -> Result<WorkItemResult<B>, FatalError> {
let module = unsafe { module.optimize(cgcx)? };
let module = module.optimize(cgcx)?;
finish_intra_module_work(cgcx, module, module_config)
}

Expand All @@ -1036,7 +1033,7 @@ fn finish_intra_module_work<B: ExtraBackendMethods>(
|| module.kind == ModuleKind::Metadata
|| module.kind == ModuleKind::Allocator
{
let module = unsafe { B::codegen(cgcx, dcx, module, module_config)? };
let module = B::codegen(cgcx, dcx, module, module_config)?;
Ok(WorkItemResult::Finished(module))
} else {
Ok(WorkItemResult::NeedsLink(module))
Expand Down Expand Up @@ -1725,9 +1722,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
let dcx = cgcx.create_dcx();
let dcx = dcx.handle();
let module = B::run_link(&cgcx, dcx, needs_link).map_err(|_| ())?;
let module = unsafe {
B::codegen(&cgcx, dcx, module, cgcx.config(ModuleKind::Regular)).map_err(|_| ())?
};
let module =
B::codegen(&cgcx, dcx, module, cgcx.config(ModuleKind::Regular)).map_err(|_| ())?;
compiled_modules.push(module);
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_ssa/src/traits/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
use crate::back::write::{CodegenContext, FatLtoInput, ModuleConfig};
use crate::{CompiledModule, ModuleCodegen};

pub trait WriteBackendMethods: 'static + Sized + Clone {
pub trait WriteBackendMethods: Clone + 'static {
type Module: Send + Sync;
type TargetMachine;
type TargetMachineError;
Expand Down Expand Up @@ -37,7 +37,7 @@ pub trait WriteBackendMethods: 'static + Sized + Clone {
) -> Result<(Vec<LtoModuleCodegen<Self>>, Vec<WorkProduct>), FatalError>;
fn print_pass_timings(&self);
fn print_statistics(&self);
unsafe fn optimize(
fn optimize(
cgcx: &CodegenContext<Self>,
dcx: DiagCtxtHandle<'_>,
module: &mut ModuleCodegen<Self::Module>,
Expand All @@ -47,11 +47,11 @@ pub trait WriteBackendMethods: 'static + Sized + Clone {
cgcx: &CodegenContext<Self>,
llmod: &mut ModuleCodegen<Self::Module>,
) -> Result<(), FatalError>;
unsafe fn optimize_thin(
fn optimize_thin(
cgcx: &CodegenContext<Self>,
thin: ThinModule<Self>,
) -> Result<ModuleCodegen<Self::Module>, FatalError>;
unsafe fn codegen(
fn codegen(
cgcx: &CodegenContext<Self>,
dcx: DiagCtxtHandle<'_>,
module: ModuleCodegen<Self::Module>,
Expand Down