Skip to content
Merged
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
395 changes: 4 additions & 391 deletions compiler/rustc_codegen_gcc/src/back/lto.rs

Large diffs are not rendered by default.

46 changes: 28 additions & 18 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};

use back::lto::{ThinBuffer, ThinData};
use gccjit::{CType, Context, OptimizationLevel};
#[cfg(feature = "master")]
use gccjit::{TargetInfo, Version};
Expand All @@ -87,7 +86,9 @@ use rustc_codegen_ssa::back::write::{
};
use rustc_codegen_ssa::base::codegen_crate;
use rustc_codegen_ssa::target_features::cfg_target_feature;
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, WriteBackendMethods};
use rustc_codegen_ssa::traits::{
CodegenBackend, ExtraBackendMethods, ThinBufferMethods, WriteBackendMethods,
};
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, TargetConfig};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::profiling::SelfProfilerRef;
Expand Down Expand Up @@ -177,8 +178,6 @@ pub struct GccCodegenBackend {
lto_supported: Arc<AtomicBool>,
}

static LTO_SUPPORTED: AtomicBool = AtomicBool::new(false);

fn load_libgccjit_if_needed(libgccjit_target_lib_file: &Path) {
if gccjit::is_loaded() {
// Do not load a libgccjit second time.
Expand Down Expand Up @@ -251,7 +250,6 @@ impl CodegenBackend for GccCodegenBackend {
#[cfg(feature = "master")]
{
let lto_supported = gccjit::is_lto_supported();
LTO_SUPPORTED.store(lto_supported, Ordering::SeqCst);
self.lto_supported.store(lto_supported, Ordering::SeqCst);

gccjit::set_global_personality_function_name(b"rust_eh_personality\0");
Expand Down Expand Up @@ -281,6 +279,10 @@ impl CodegenBackend for GccCodegenBackend {
}
}

fn thin_lto_supported(&self) -> bool {
false
}

fn provide(&self, providers: &mut Providers) {
providers.queries.global_backend_features =
|tcx, ()| gcc_util::global_gcc_features(tcx.sess)
Expand Down Expand Up @@ -421,11 +423,19 @@ unsafe impl Send for SyncContext {}
// FIXME(antoyo): that shouldn't be Sync. Parallel compilation is currently disabled with "CodegenBackend::supports_parallel()".
unsafe impl Sync for SyncContext {}

pub struct ThinBuffer;

impl ThinBufferMethods for ThinBuffer {
fn data(&self) -> &[u8] {
&[]
}
}

impl WriteBackendMethods for GccCodegenBackend {
type Module = GccContext;
type TargetMachine = ();
type ModuleBuffer = ModuleBuffer;
type ThinData = ThinData;
type ThinData = ();
type ThinBuffer = ThinBuffer;

fn run_and_optimize_fat_lto(
Expand All @@ -442,16 +452,16 @@ impl WriteBackendMethods for GccCodegenBackend {
}

fn run_thin_lto(
cgcx: &CodegenContext,
prof: &SelfProfilerRef,
dcx: DiagCtxtHandle<'_>,
_cgcx: &CodegenContext,
_prof: &SelfProfilerRef,
_dcx: DiagCtxtHandle<'_>,
// FIXME(bjorn3): Limit LTO exports to these symbols
_exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
modules: Vec<(String, Self::ThinBuffer)>,
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
_each_linked_rlib_for_lto: &[PathBuf],
_modules: Vec<(String, Self::ThinBuffer)>,
_cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>) {
back::lto::run_thin(cgcx, prof, dcx, each_linked_rlib_for_lto, modules, cached_modules)
unreachable!()
}

fn print_pass_timings(&self) {
Expand All @@ -473,13 +483,13 @@ impl WriteBackendMethods for GccCodegenBackend {
}

fn optimize_thin(
cgcx: &CodegenContext,
_cgcx: &CodegenContext,
_prof: &SelfProfilerRef,
_shared_emitter: &SharedEmitter,
_tm_factory: TargetMachineFactoryFn<Self>,
thin: ThinModule<Self>,
_thin: ThinModule<Self>,
) -> ModuleCodegen<Self::Module> {
back::lto::optimize_thin_module(thin, cgcx)
unreachable!()
}

fn codegen(
Expand All @@ -492,8 +502,8 @@ impl WriteBackendMethods for GccCodegenBackend {
back::write::codegen(cgcx, prof, shared_emitter, module, config)
}

fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
back::lto::prepare_thin(module)
fn prepare_thin(_module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
unreachable!()
}

fn serialize_module(_module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer) {
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ pub trait CodegenBackend {
vec![]
}

/// Is ThinLTO supported by this backend?
fn thin_lto_supported(&self) -> bool {
true
}

/// Value printed by `--print=backend-has-zstd`.
///
/// Used by compiletest to determine whether tests involving zstd compression
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se

codegen_backend.init(&sess);
sess.replaced_intrinsics = FxHashSet::from_iter(codegen_backend.replaced_intrinsics());
sess.thin_lto_supported = codegen_backend.thin_lto_supported();

let cfg = parse_cfg(sess.dcx(), config.crate_cfg);
let mut cfg = config::build_configuration(&sess, cfg);
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ impl LintStore {
})
}

/// Returns all lint group names, including deprecated/aliased groups
pub fn get_all_group_names(&self) -> impl Iterator<Item = &'static str> {
self.lint_groups.keys().copied()
}

pub fn register_early_pass(
&mut self,
pass: impl Fn() -> EarlyLintPassObject + 'static + sync::DynSend + sync::DynSync,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_macros/src/diagnostics/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const ALLOWED_CAPITALIZED_WORDS: &[&str] = &[
"NaNs",
"OK",
"Rust",
"ThinLTO",
"Unicode",
"VS",
// tidy-alphabetical-end
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,7 @@ pub(crate) struct UnexpectedBuiltinCfg {
pub(crate) cfg_name: Symbol,
pub(crate) controlled_by: &'static str,
}

#[derive(Diagnostic)]
#[diag("ThinLTO is not supported by the codegen backend")]
pub(crate) struct ThinLtoNotSupportedByBackend;
13 changes: 13 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ pub struct Session {
/// The names of intrinsics that the current codegen backend replaces
/// with its own implementations.
pub replaced_intrinsics: FxHashSet<Symbol>,

/// Does the codegen backend support ThinLTO?
pub thin_lto_supported: bool,
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -606,10 +609,19 @@ impl Session {
}
config::LtoCli::Thin => {
// The user explicitly asked for ThinLTO
if !self.thin_lto_supported {
// Backend doesn't support ThinLTO, disable LTO.
self.dcx().emit_warn(errors::ThinLtoNotSupportedByBackend);
return config::Lto::No;
}
return config::Lto::Thin;
}
}

if !self.thin_lto_supported {
return config::Lto::No;
}

// Ok at this point the target doesn't require anything and the user
// hasn't asked for anything. Our next decision is whether or not
// we enable "auto" ThinLTO where we use multiple codegen units and
Expand Down Expand Up @@ -1088,6 +1100,7 @@ pub fn build_session(
host_filesearch,
invocation_temp,
replaced_intrinsics: FxHashSet::default(), // filled by `run_compiler`
thin_lto_supported: true, // filled by `run_compiler`
};

validate_commandline_args_with_session_available(&sess);
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_trait_selection/src/traits/query/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,14 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> {
// `tcx.normalize_canonicalized_projection` may normalize to a type that
// still has unevaluated consts, so keep normalizing here if that's the case.
// Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer
// of type and we need to continue folding it to reveal the TAIT behind it.
// of type/const and we need to continue folding it to reveal the TAIT behind it
// or further normalize nested unevaluated consts.
if res != term.to_term(tcx)
&& (res.as_type().map_or(false, |t| t.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION))
|| term.kind(tcx) == ty::AliasTermKind::FreeTy)
&& (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
|| matches!(
term.kind(tcx),
ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst
))
{
res.try_fold_with(self)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn check(cx: &LateContext<'_>) {
{
let mut rustc_groups = FxHashSet::default();
let mut clippy_groups = FxHashSet::default();
for (group, ..) in unerased_lint_store(cx.tcx.sess).get_lint_groups() {
for group in unerased_lint_store(cx.tcx.sess).get_all_group_names() {
match group.split_once("::") {
None => {
rustc_groups.insert(group);
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2978,7 +2978,6 @@ ui/unboxed-closures/issue-18652.rs
ui/unboxed-closures/issue-18661.rs
ui/unboxed-closures/issue-30906.rs
ui/unboxed-closures/issue-53448.rs
ui/underscore-imports/issue-110164.rs
ui/uniform-paths/auxiliary/issue-53691.rs
ui/uniform-paths/issue-53691.rs
ui/uninhabited/issue-107505.rs
Expand Down
32 changes: 1 addition & 31 deletions tests/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ See:
- [`std::box::Boxed`](https://doc.rust-lang.org/std/boxed/struct.Box.html)
- [Tracking issue for `box_patterns` feature #29641](https://github.com/rust-lang/rust/issues/29641)

## `tests/ui/btreemap/`: B-Tree Maps

Tests focused on `BTreeMap` collections and their compiler interactions. E.g. collection patterns, iterator behavior, and trait implementations specific to `BTreeMap`. See [`std::collections::BTreeMap`](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html).

## `tests/ui/builtin-superkinds/`: Built-in Trait Hierarchy Tests

Tests for built-in trait hierarchy (Send, Sync, Sized, etc.) and their supertrait relationships. E.g. auto traits and marker trait constraints.
Expand Down Expand Up @@ -262,12 +258,10 @@ This directory only contains one highly specific test. Other coinduction tests c

## `tests/ui/collections`

These tests exercise the `collections` library.
These tests exercise the `collections` library. For example, `BTreeMap` and `HashMap`.

See [`std::collections`](https://doc.rust-lang.org/std/collections/index.html)

**FIXME**: consider merge with `tests/ui/btreemap` and `tests/ui/hashmap`

## `tests/ui/command/`: `std::process::Command`

This directory is actually for the standard library [`std::process::Command`](https://doc.rust-lang.org/std/process/struct.Command.html) type, where some tests are too difficult or inconvenient to write as unit tests or integration tests within the standard library itself.
Expand Down Expand Up @@ -518,10 +512,6 @@ The `dyn` keyword is used to highlight that calls to methods on the associated T

See [`dyn` keyword](https://doc.rust-lang.org/std/keyword.dyn.html).

## `tests/ui/dynamically-sized-types`: Dynamically Sized Types

**FIXME**: should be coalesced with `tests/ui/dst`.

## `tests/ui/editions/`: Rust edition-specific peculiarities

These tests run in specific Rust editions, such as Rust 2015 or Rust 2018, and check errors and functionality related to specific now-deprecated idioms and features.
Expand Down Expand Up @@ -688,10 +678,6 @@ Tests on range patterns where one of the bounds is not a direct value.

**FIXME**: Overlaps with `ui/range`. `impossible_range.rs` is particularly suspected to be a duplicate test.

## `tests/ui/hashmap/`

Tests for the standard library collection [`std::collections::HashMap`](https://doc.rust-lang.org/std/collections/struct.HashMap.html).

## `tests/ui/higher-ranked/`

Tests for higher-ranked trait bounds.
Expand All @@ -701,10 +687,6 @@ See:
- [Higher-ranked trait bounds | rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/traits/hrtb.html)
- [Higher-ranked trait bounds | Nomicon](https://doc.rust-lang.org/nomicon/hrtb.html)

## `tests/ui/higher-ranked-trait-bounds`

**FIXME**: move to `tests/ui/higher-ranked/trait-bounds`

## `tests/ui/hygiene/`

This seems to have been originally intended for "hygienic macros" - macros which work in all contexts, independent of what surrounds them. However, this category has grown into a mish-mash of many tests that may belong in the other directories.
Expand Down Expand Up @@ -927,12 +909,6 @@ See [Tracking issue for allowing overlapping implementations for marker trait #2

Broad category of tests on `match` constructs.

## `tests/ui/meta/`: Tests for compiletest itself

These tests check the function of the UI test suite at large and Compiletest in itself.

**FIXME**: This should absolutely be merged with `tests/ui/compiletest-self-test/`.

## `tests/ui/methods/`

A broad category for anything related to methods and method resolution.
Expand Down Expand Up @@ -1530,12 +1506,6 @@ See [RFC 0132 Unified Function Call Syntax](https://github.com/rust-lang/rfcs/bl

See [Tracking issue for Fn traits (`unboxed_closures` & `fn_traits` feature)](https://github.com/rust-lang/rust/issues/29625).

## `tests/ui/underscore-imports/`

See [Underscore imports | Reference](https://doc.rust-lang.org/reference/items/use-declarations.html#underscore-imports).

**FIXME**: should become a subdirectory of `tests/ui/imports/`.

## `tests/ui/underscore-lifetime/`: `'_` elided lifetime

Exercises [anonymous elided lifetimes](https://doc.rust-lang.org/reference/lifetime-elision.html).
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
error[E0161]: cannot move a value of type `str`
--> $DIR/dst-index.rs:31:5
--> $DIR/dst-index-fail.rs:31:5
|
LL | S[0];
| ^^^^ the size of `str` cannot be statically determined

error[E0161]: cannot move a value of type `dyn Debug`
--> $DIR/dst-index.rs:34:5
--> $DIR/dst-index-fail.rs:34:5
|
LL | T[0];
| ^^^^ the size of `dyn Debug` cannot be statically determined

error[E0507]: cannot move out of index of `S`
--> $DIR/dst-index.rs:31:5
--> $DIR/dst-index-fail.rs:31:5
|
LL | S[0];
| ^^^^ move occurs because value has type `str`, which does not implement the `Copy` trait

error[E0507]: cannot move out of index of `T`
--> $DIR/dst-index.rs:34:5
--> $DIR/dst-index-fail.rs:34:5
|
LL | T[0];
| ^^^^ move occurs because value has type `dyn Debug`, which does not implement the `Copy` trait
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions tests/ui/generic-const-items/type-const-nested-assoc-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ check-pass

#![feature(generic_const_items, min_generic_const_args)]
#![allow(incomplete_features)]

type const CT<T: ?Sized>: usize = { <T as Trait>::N };

trait Trait {
type const N: usize;
}

impl<T: ?Sized> Trait for T {
type const N:usize = 0;
}

fn f(_x: [(); CT::<()>]) {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// https://github.com/rust-lang/rust/issues/60218
// Regression test for #60218
//
// Regression test for https://github.com/rust-lang/rust/issues/60218
// This was reported to cause ICEs.

use std::iter::Map;
Expand Down
Loading
Loading