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 6 pull requests #101233

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
137f20c
rebased: convert rustc_monomorphize errors to SessionDiagnostic
CleanCut Aug 18, 2022
40f4473
replace some usages of [Span]FatalError with error-specific types
CleanCut Aug 23, 2022
33cbbc2
remove stray comment
CleanCut Aug 23, 2022
e914247
bless the change in note/help order due to migrating to SessionDiagno…
CleanCut Aug 24, 2022
30c7506
allow non-monomorphize modules to access hard-coded error message thr…
CleanCut Aug 24, 2022
6cdfdd0
adjust to new error value
CleanCut Aug 24, 2022
82d609c
have LangItemError derive everything LangItem does
CleanCut Aug 24, 2022
706452e
translations(rustc_session): migrate the file cgu_reuse_tracker
beowolx Aug 19, 2022
d5262a9
translations(rustc_session): migrate 80% of the file parse.rs
beowolx Aug 22, 2022
2c77f3e
translations(rustc_session): migrate check_expected_reuse
beowolx Aug 24, 2022
a19139f
remove unnecessary comment
CleanCut Aug 26, 2022
845d567
revert src/tools/cargo submodule to where it ought to be from where w…
CleanCut Aug 26, 2022
6099d17
rustdoc: Resugar async fn return type in `clean`, not `html`
aDotInTheVoid Aug 30, 2022
6c585fc
Clean up render_assoc_items_inner a bit
GuillaumeGomez Aug 30, 2022
86f8c4e
ADD - InvalidSymbolName to migrate symbol-name({}) error to new diagn…
JhonnyBillM Aug 27, 2022
359002b
ADD - migrate InvalidTraitItem and AltInvalidTraitItem errors
JhonnyBillM Aug 21, 2022
bd83bbc
UPDATE - accept String instead of unused 'str
JhonnyBillM Aug 21, 2022
8f5fada
ADD - migrate InvalidDefPath to new diagnostics infra
JhonnyBillM Aug 21, 2022
ef2f6ab
ADD - diagnostics lints to symbol_mangling module
JhonnyBillM Aug 21, 2022
3ee6946
UPDATE - to support diag introduced in PR #100765
JhonnyBillM Aug 21, 2022
8588374
Use in-page links for sanitizer docs.
ehuss Aug 30, 2022
900cda2
Print only blanket implementations on reference primitive type
GuillaumeGomez Aug 30, 2022
477b7ba
Add regression test for implementations displayed on reference primit…
GuillaumeGomez Aug 30, 2022
fcc90f2
Rollup merge of #90946 - GuillaumeGomez:def-id-remove-weird-case, r=M…
GuillaumeGomez Aug 31, 2022
ac7705f
Rollup merge of #100730 - CleanCut:diagnostics-rustc_monomorphize, r=…
GuillaumeGomez Aug 31, 2022
d8f2acf
Rollup merge of #100753 - LuisCardosoOliveira:translation-migrate-ses…
GuillaumeGomez Aug 31, 2022
7e11c11
Rollup merge of #100831 - JhonnyBillM:migrate-symbol-mangling-to-diag…
GuillaumeGomez Aug 31, 2022
72e33a3
Rollup merge of #101204 - aDotInTheVoid:async-resugar-in-clean, r=Gui…
GuillaumeGomez Aug 31, 2022
39b083c
Rollup merge of #101216 - ehuss:sanitizer-links, r=JohnTitor
GuillaumeGomez Aug 31, 2022
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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3905,8 +3905,10 @@ name = "rustc_monomorphize"
version = "0.0.0"
dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc_macros",
"rustc_middle",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -4154,7 +4156,9 @@ dependencies = [
"punycode",
"rustc-demangle",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
"rustc_macros",
"rustc_middle",
"rustc_session",
"rustc_span",
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,11 @@ pub(crate) fn codegen_panic_inner<'tcx>(
args: &[Value],
span: Span,
) {
let def_id =
fx.tcx.lang_items().require(lang_item).unwrap_or_else(|s| fx.tcx.sess.span_fatal(span, &s));
let def_id = fx
.tcx
.lang_items()
.require(lang_item)
.unwrap_or_else(|e| fx.tcx.sess.span_fatal(span, e.to_string()));

let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
let symbol_name = fx.tcx.symbol_name(instance).name;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
}
});

sess.cgu_reuse_tracker.check_expected_reuse(sess.diagnostic());
sess.cgu_reuse_tracker.check_expected_reuse(sess);

sess.abort_if_errors();

Expand Down
26 changes: 26 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/monomorphize.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
monomorphize_recursion_limit =
reached the recursion limit while instantiating `{$shrunk}`
.note = `{$def_path_str}` defined here

monomorphize_written_to_path = the full type name has been written to '{$path}'

monomorphize_type_length_limit = reached the type-length limit while instantiating `{$shrunk}`

monomorphize_consider_type_length_limit =
consider adding a `#![type_length_limit="{$type_length}"]` attribute to your crate

monomorphize_fatal_error = {$error_message}

monomorphize_unknown_partition_strategy = unknown partitioning strategy

monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined

monomorphize_unused_generic_params = item has unused generic parameters

monomorphize_large_assignments =
moving {$size} bytes
.label = value moved from here
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

monomorphize_requires_lang_item =
requires `{$lang_item}` lang_item
16 changes: 16 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/session.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
session_incorrect_cgu_reuse_type =
CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be {$at_least ->
[one] {"at least "}
*[other] {""}
}`{$expected_reuse}`

session_cgu_not_recorded =
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded`

session_feature_gate_error = {$explain}

session_feature_diagnostic_for_issue =
see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information

session_feature_diagnostic_help =
add `#![feature({$feature})]` to the crate attributes to enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
symbol_mangling_invalid_symbol_name = symbol-name({$mangled_formatted})

symbol_mangling_invalid_trait_item = demangling({$demangling_formatted})

symbol_mangling_alt_invalid_trait_item = demangling-alt({$alt_demangling_formatted})

symbol_mangling_invalid_def_path = def-path({$def_path})
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ fluent_messages! {
const_eval => "../locales/en-US/const_eval.ftl",
driver => "../locales/en-US/driver.ftl",
expand => "../locales/en-US/expand.ftl",
session => "../locales/en-US/session.ftl",
interface => "../locales/en-US/interface.ftl",
infer => "../locales/en-US/infer.ftl",
lint => "../locales/en-US/lint.ftl",
monomorphize => "../locales/en-US/monomorphize.ftl",
parser => "../locales/en-US/parser.ftl",
passes => "../locales/en-US/passes.ftl",
plugin_impl => "../locales/en-US/plugin_impl.ftl",
Expand All @@ -52,6 +54,7 @@ fluent_messages! {
ty_utils => "../locales/en-US/ty_utils.ftl",
typeck => "../locales/en-US/typeck.ftl",
mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
}

pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_hir/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::LangItem;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
pub struct LangItemError(pub LangItem);

impl ToString for LangItemError {
fn to_string(&self) -> String {
format!("requires `{}` lang_item", self.0.name())
}
}
7 changes: 4 additions & 3 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! * Functions called by the compiler itself.

use crate::def_id::DefId;
use crate::errors::LangItemError;
use crate::{MethodKind, Target};

use rustc_ast as ast;
Expand Down Expand Up @@ -115,9 +116,9 @@ macro_rules! language_item_table {

/// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
/// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
/// returns an error message as a string.
pub fn require(&self, it: LangItem) -> Result<DefId, String> {
self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
/// returns an error encapsulating the `LangItem`.
pub fn require(&self, it: LangItem) -> Result<DefId, LangItemError> {
self.items[it as usize].ok_or_else(|| LangItemError(it))
}

/// Returns the [`DefId`]s of all lang items in a group.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod def;
pub mod def_path_hash_map;
pub mod definitions;
pub mod diagnostic_items;
pub mod errors;
pub use rustc_span::def_id;
mod hir;
pub mod hir_id;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns the `DefId` for a given `LangItem`.
/// If not found, fatally aborts compilation.
pub fn require_lang_item(self, lang_item: LangItem, span: Option<Span>) -> DefId {
self.lang_items().require(lang_item).unwrap_or_else(|msg| {
self.lang_items().require(lang_item).unwrap_or_else(|err| {
if let Some(span) = span {
self.sess.span_fatal(span, &msg)
self.sess.span_fatal(span, err.to_string())
} else {
self.sess.fatal(&msg)
self.sess.fatal(err.to_string())
}
})
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_monomorphize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ edition = "2021"
doctest = false

[dependencies]
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
smallvec = { version = "1.8.1", features = [ "union", "may_dangle" ] }
tracing = "0.1"
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
Expand Down
67 changes: 39 additions & 28 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ use std::iter;
use std::ops::Range;
use std::path::PathBuf;

use crate::errors::{LargeAssignmentsLint, RecursionLimit, RequiresLangItem, TypeLengthLimit};

#[derive(PartialEq)]
pub enum MonoItemCollectionMode {
Eager,
Expand Down Expand Up @@ -604,17 +606,24 @@ fn check_recursion_limit<'tcx>(
// more than the recursion limit is assumed to be causing an
// infinite expansion.
if !recursion_limit.value_within_limit(adjusted_recursion_depth) {
let def_span = tcx.def_span(def_id);
let def_path_str = tcx.def_path_str(def_id);
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance, 32, 32);
let error = format!("reached the recursion limit while instantiating `{}`", shrunk);
let mut err = tcx.sess.struct_span_fatal(span, &error);
err.span_note(
tcx.def_span(def_id),
&format!("`{}` defined here", tcx.def_path_str(def_id)),
);
if let Some(path) = written_to_path {
err.note(&format!("the full type name has been written to '{}'", path.display()));
}
err.emit()
let mut path = PathBuf::new();
let was_written = if written_to_path.is_some() {
path = written_to_path.unwrap();
Some(())
} else {
None
};
tcx.sess.emit_fatal(RecursionLimit {
span,
shrunk,
def_span,
def_path_str,
was_written,
path,
});
}

recursion_depths.insert(def_id, recursion_depth + 1);
Expand Down Expand Up @@ -642,16 +651,15 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
// Bail out in these cases to avoid that bad user experience.
if !tcx.type_length_limit().value_within_limit(type_length) {
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance, 32, 32);
let msg = format!("reached the type-length limit while instantiating `{}`", shrunk);
let mut diag = tcx.sess.struct_span_fatal(tcx.def_span(instance.def_id()), &msg);
if let Some(path) = written_to_path {
diag.note(&format!("the full type name has been written to '{}'", path.display()));
}
diag.help(&format!(
"consider adding a `#![type_length_limit=\"{}\"]` attribute to your crate",
type_length
));
diag.emit()
let span = tcx.def_span(instance.def_id());
let mut path = PathBuf::new();
let was_written = if written_to_path.is_some() {
path = written_to_path.unwrap();
Some(())
} else {
None
};
tcx.sess.emit_fatal(TypeLengthLimit { span, shrunk, was_written, path, type_length });
}
}

Expand Down Expand Up @@ -914,17 +922,16 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
// but correct span? This would make the lint at least accept crate-level lint attributes.
return;
};
self.tcx.struct_span_lint_hir(
self.tcx.emit_spanned_lint(
LARGE_ASSIGNMENTS,
lint_root,
source_info.span,
|lint| {
let mut err = lint.build(&format!("moving {} bytes", layout.size.bytes()));
err.span_label(source_info.span, "value moved from here");
err.note(&format!(r#"The current maximum size is {}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`"#, limit.bytes()));
err.emit();
LargeAssignmentsLint {
span: source_info.span,
size: layout.size.bytes(),
limit: limit.bytes(),
},
);
)
}
}
}
Expand Down Expand Up @@ -1321,7 +1328,11 @@ impl<'v> RootCollector<'_, 'v> {

let start_def_id = match self.tcx.lang_items().require(LangItem::Start) {
Ok(s) => s,
Err(err) => self.tcx.sess.fatal(&err),
Err(lang_item_err) => {
self.tcx
.sess
.emit_fatal(RequiresLangItem { lang_item: lang_item_err.0.name().to_string() });
}
};
let main_ret_ty = self.tcx.fn_sig(main_def_id).output();

Expand Down
84 changes: 84 additions & 0 deletions compiler/rustc_monomorphize/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use std::path::PathBuf;

use rustc_errors::ErrorGuaranteed;
use rustc_macros::{LintDiagnostic, SessionDiagnostic};
use rustc_session::SessionDiagnostic;
use rustc_span::Span;

#[derive(SessionDiagnostic)]
#[diag(monomorphize::recursion_limit)]
pub struct RecursionLimit {
#[primary_span]
pub span: Span,
pub shrunk: String,
#[note]
pub def_span: Span,
pub def_path_str: String,
#[note(monomorphize::written_to_path)]
pub was_written: Option<()>,
pub path: PathBuf,
}

#[derive(SessionDiagnostic)]
#[diag(monomorphize::type_length_limit)]
#[help(monomorphize::consider_type_length_limit)]
pub struct TypeLengthLimit {
#[primary_span]
pub span: Span,
pub shrunk: String,
#[note(monomorphize::written_to_path)]
pub was_written: Option<()>,
pub path: PathBuf,
pub type_length: usize,
}

#[derive(SessionDiagnostic)]
#[diag(monomorphize::requires_lang_item)]
pub struct RequiresLangItem {
pub lang_item: String,
}

pub struct UnusedGenericParams {
pub span: Span,
pub param_spans: Vec<Span>,
pub param_names: Vec<String>,
}

impl SessionDiagnostic<'_> for UnusedGenericParams {
fn into_diagnostic(
self,
sess: &'_ rustc_session::parse::ParseSess,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
let mut diag = sess.struct_err(rustc_errors::fluent::monomorphize::unused_generic_params);
diag.set_span(self.span);
for (span, name) in self.param_spans.into_iter().zip(self.param_names) {
// FIXME: I can figure out how to do a label with a fluent string with a fixed message,
// or a label with a dynamic value in a hard-coded string, but I haven't figured out
// how to combine the two. 😢
diag.span_label(span, format!("generic parameter `{}` is unused", name));
}
diag
}
}

#[derive(LintDiagnostic)]
#[diag(monomorphize::large_assignments)]
#[note]
pub struct LargeAssignmentsLint {
#[label]
pub span: Span,
pub size: u64,
pub limit: u64,
}

#[derive(SessionDiagnostic)]
#[diag(monomorphize::unknown_partition_strategy)]
pub struct UnknownPartitionStrategy;

#[derive(SessionDiagnostic)]
#[diag(monomorphize::symbol_already_defined)]
pub struct SymbolAlreadyDefined {
#[primary_span]
pub span: Option<Span>,
pub symbol: String,
}
3 changes: 3 additions & 0 deletions compiler/rustc_monomorphize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![feature(let_else)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

#[macro_use]
extern crate tracing;
Expand All @@ -16,6 +18,7 @@ use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, Ty, TyCtxt};

mod collector;
mod errors;
mod partitioning;
mod polymorphize;
mod util;
Expand Down
Loading