Skip to content

Commit cdac44e

Browse files
committed
Auto merge of #143762 - tgross35:rollup-n9t27c6, r=tgross35
Rollup of 7 pull requests Successful merges: - #140136 (Add an aarch64-msvc build running on ARM64 Windows) - #143642 (stdarch subtree update) - #143707 (Fix `--skip-std-check-if-no-download-rustc`) - #143722 (Make some "safe" llvm ops actually sound) - #143728 (Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name`) - #143742 (Rework borrowing suggestions to use `Expr` instead of just `Span`) - #143744 (Properly track the depth when expanding free alias types) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2a023bf + 3a1bb04 commit cdac44e

File tree

63 files changed

+816
-773
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+816
-773
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ jobs:
152152
- name: show the current environment
153153
run: src/ci/scripts/dump-environment.sh
154154

155+
- name: install rust
156+
run: src/ci/scripts/install-rust.sh
157+
155158
- name: install awscli
156159
run: src/ci/scripts/install-awscli.sh
157160

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ fn create_msvc_imps(
11821182
.filter_map(|val| {
11831183
// Exclude some symbols that we know are not Rust symbols.
11841184
let name = llvm::get_value_name(val);
1185-
if ignored(name) { None } else { Some((val, name)) }
1185+
if ignored(&name) { None } else { Some((val, name)) }
11861186
})
11871187
.map(move |(val, name)| {
11881188
let mut imp_name = prefix.as_bytes().to_vec();

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn generate_enzyme_call<'ll>(
306306
// add outer_fn name to ad_name to make it unique, in case users apply autodiff to multiple
307307
// functions. Unwrap will only panic, if LLVM gave us an invalid string.
308308
let name = llvm::get_value_name(outer_fn);
309-
let outer_fn_name = std::str::from_utf8(name).unwrap();
309+
let outer_fn_name = std::str::from_utf8(&name).unwrap();
310310
ad_name.push_str(outer_fn_name);
311311

312312
// Let us assume the user wrote the following function square:

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'ll> CodegenCx<'ll, '_> {
429429
// specific rules on what can be cast. So instead of adding a new way to
430430
// generate static initializers that match the static's type, we picked
431431
// the easier option and retroactively change the type of the static item itself.
432-
let name = llvm::get_value_name(g).to_vec();
432+
let name = llvm::get_value_name(g);
433433
llvm::set_value_name(g, b"");
434434

435435
let linkage = llvm::get_linkage(g);

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
211211
// function.
212212
// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
213213
pub(crate) fn SetUniqueComdat(llmod: &Module, val: &Value) {
214-
let name_buf = get_value_name(val).to_vec();
214+
let name_buf = get_value_name(val);
215215
let name =
216216
CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap();
217217
set_comdat(llmod, val, &name);
@@ -319,12 +319,14 @@ pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value {
319319
}
320320
}
321321

322-
/// Safe wrapper for `LLVMGetValueName2` into a byte slice
323-
pub(crate) fn get_value_name(value: &Value) -> &[u8] {
322+
/// Safe wrapper for `LLVMGetValueName2`
323+
/// Needs to allocate the value, because `set_value_name` will invalidate
324+
/// the pointer.
325+
pub(crate) fn get_value_name(value: &Value) -> Vec<u8> {
324326
unsafe {
325327
let mut len = 0;
326328
let data = LLVMGetValueName2(value, &mut len);
327-
std::slice::from_raw_parts(data.cast(), len)
329+
std::slice::from_raw_parts(data.cast(), len).to_vec()
328330
}
329331
}
330332

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11651165
self.push_suggestion(CodeSuggestion {
11661166
substitutions,
11671167
msg: self.subdiagnostic_message_to_diagnostic_message(msg),
1168-
style: SuggestionStyle::ShowCode,
1168+
style: SuggestionStyle::ShowAlways,
11691169
applicability,
11701170
});
11711171
self

compiler/rustc_middle/src/ty/util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,11 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> {
10521052
}
10531053

10541054
self.depth += 1;
1055-
ensure_sufficient_stack(|| {
1055+
let ty = ensure_sufficient_stack(|| {
10561056
self.tcx.type_of(alias.def_id).instantiate(self.tcx, alias.args).fold_with(self)
1057-
})
1057+
});
1058+
self.depth -= 1;
1059+
ty
10581060
}
10591061

10601062
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {

compiler/rustc_resolve/src/ident.rs

Lines changed: 143 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::{Ident, Span, kw, sym};
1313
use tracing::{debug, instrument};
1414

1515
use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
16-
use crate::imports::Import;
16+
use crate::imports::{Import, NameResolution};
1717
use crate::late::{ConstantHasGenerics, NoConstantGenericsReason, PathSource, Rib, RibKind};
1818
use crate::macros::{MacroRulesScope, sub_namespace_match};
1919
use crate::{
@@ -37,7 +37,7 @@ impl From<UsePrelude> for bool {
3737
}
3838
}
3939

40-
#[derive(Debug, PartialEq)]
40+
#[derive(Debug, PartialEq, Clone, Copy)]
4141
enum Shadowing {
4242
Restricted,
4343
Unrestricted,
@@ -879,53 +879,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
879879
.into_iter()
880880
.find_map(|binding| if binding == ignore_binding { None } else { binding });
881881

882-
if let Some(Finalize { path_span, report_private, used, root_span, .. }) = finalize {
883-
let Some(binding) = binding else {
884-
return Err((Determined, Weak::No));
885-
};
886-
887-
if !self.is_accessible_from(binding.vis, parent_scope.module) {
888-
if report_private {
889-
self.privacy_errors.push(PrivacyError {
890-
ident,
891-
binding,
892-
dedup_span: path_span,
893-
outermost_res: None,
894-
parent_scope: *parent_scope,
895-
single_nested: path_span != root_span,
896-
});
897-
} else {
898-
return Err((Determined, Weak::No));
899-
}
900-
}
901-
902-
// Forbid expanded shadowing to avoid time travel.
903-
if let Some(shadowed_glob) = resolution.shadowed_glob
904-
&& shadowing == Shadowing::Restricted
905-
&& binding.expansion != LocalExpnId::ROOT
906-
&& binding.res() != shadowed_glob.res()
907-
{
908-
self.ambiguity_errors.push(AmbiguityError {
909-
kind: AmbiguityKind::GlobVsExpanded,
910-
ident,
911-
b1: binding,
912-
b2: shadowed_glob,
913-
warning: false,
914-
misc1: AmbiguityErrorMisc::None,
915-
misc2: AmbiguityErrorMisc::None,
916-
});
917-
}
918-
919-
if shadowing == Shadowing::Unrestricted
920-
&& binding.expansion != LocalExpnId::ROOT
921-
&& let NameBindingKind::Import { import, .. } = binding.kind
922-
&& matches!(import.kind, ImportKind::MacroExport)
923-
{
924-
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
925-
}
926-
927-
self.record_use(ident, binding, used);
928-
return Ok(binding);
882+
if let Some(finalize) = finalize {
883+
return self.finalize_module_binding(
884+
ident,
885+
binding,
886+
resolution.shadowed_glob,
887+
parent_scope,
888+
finalize,
889+
shadowing,
890+
);
929891
}
930892

931893
let check_usable = |this: &mut Self, binding: NameBinding<'ra>| {
@@ -944,75 +906,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
944906

945907
// Check if one of single imports can still define the name,
946908
// if it can then our result is not determined and can be invalidated.
947-
for single_import in &resolution.single_imports {
948-
if ignore_import == Some(*single_import) {
949-
// This branch handles a cycle in single imports.
950-
//
951-
// For example:
952-
// ```
953-
// use a::b;
954-
// use b as a;
955-
// ```
956-
// 1. Record `use a::b` as the `ignore_import` and attempt to locate `a` in the
957-
// current module.
958-
// 2. Encounter the import `use b as a`, which is a `single_import` for `a`,
959-
// and try to find `b` in the current module.
960-
// 3. Re-encounter the `use a::b` import since it's a `single_import` of `b`.
961-
// This leads to entering this branch.
962-
continue;
963-
}
964-
if !self.is_accessible_from(single_import.vis, parent_scope.module) {
965-
continue;
966-
}
967-
if let Some(ignored) = ignore_binding
968-
&& let NameBindingKind::Import { import, .. } = ignored.kind
969-
&& import == *single_import
970-
{
971-
// Ignore not just the binding itself, but if it has a shadowed_glob,
972-
// ignore that, too, because this loop is supposed to only process
973-
// named imports.
974-
continue;
975-
}
976-
977-
let Some(module) = single_import.imported_module.get() else {
978-
return Err((Undetermined, Weak::No));
979-
};
980-
let ImportKind::Single { source, target, target_bindings, .. } = &single_import.kind
981-
else {
982-
unreachable!();
983-
};
984-
if source != target {
985-
// This branch allows the binding to be defined or updated later if the target name
986-
// can hide the source.
987-
if target_bindings.iter().all(|binding| binding.get().is_none()) {
988-
// None of the target bindings are available, so we can't determine
989-
// if this binding is correct or not.
990-
// See more details in #124840
991-
return Err((Undetermined, Weak::No));
992-
} else if target_bindings[ns].get().is_none() && binding.is_some() {
993-
// `binding.is_some()` avoids the condition where the binding
994-
// truly doesn't exist in this namespace and should return `Err(Determined)`.
995-
return Err((Undetermined, Weak::No));
996-
}
997-
}
998-
999-
match self.resolve_ident_in_module(
1000-
module,
1001-
*source,
1002-
ns,
1003-
&single_import.parent_scope,
1004-
None,
1005-
ignore_binding,
1006-
ignore_import,
1007-
) {
1008-
Err((Determined, _)) => continue,
1009-
Ok(binding)
1010-
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
1011-
{
1012-
continue;
1013-
}
1014-
Ok(_) | Err((Undetermined, _)) => return Err((Undetermined, Weak::No)),
1015-
}
909+
if self.single_import_can_define_name(
910+
&resolution,
911+
binding,
912+
ns,
913+
ignore_import,
914+
ignore_binding,
915+
parent_scope,
916+
) {
917+
return Err((Undetermined, Weak::No));
1016918
}
1017919

1018920
// So we have a resolution that's from a glob import. This resolution is determined
@@ -1101,6 +1003,129 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11011003
Err((Determined, Weak::No))
11021004
}
11031005

1006+
fn finalize_module_binding(
1007+
&mut self,
1008+
ident: Ident,
1009+
binding: Option<NameBinding<'ra>>,
1010+
shadowed_glob: Option<NameBinding<'ra>>,
1011+
parent_scope: &ParentScope<'ra>,
1012+
finalize: Finalize,
1013+
shadowing: Shadowing,
1014+
) -> Result<NameBinding<'ra>, (Determinacy, Weak)> {
1015+
let Finalize { path_span, report_private, used, root_span, .. } = finalize;
1016+
1017+
let Some(binding) = binding else {
1018+
return Err((Determined, Weak::No));
1019+
};
1020+
1021+
if !self.is_accessible_from(binding.vis, parent_scope.module) {
1022+
if report_private {
1023+
self.privacy_errors.push(PrivacyError {
1024+
ident,
1025+
binding,
1026+
dedup_span: path_span,
1027+
outermost_res: None,
1028+
parent_scope: *parent_scope,
1029+
single_nested: path_span != root_span,
1030+
});
1031+
} else {
1032+
return Err((Determined, Weak::No));
1033+
}
1034+
}
1035+
1036+
// Forbid expanded shadowing to avoid time travel.
1037+
if let Some(shadowed_glob) = shadowed_glob
1038+
&& shadowing == Shadowing::Restricted
1039+
&& binding.expansion != LocalExpnId::ROOT
1040+
&& binding.res() != shadowed_glob.res()
1041+
{
1042+
self.ambiguity_errors.push(AmbiguityError {
1043+
kind: AmbiguityKind::GlobVsExpanded,
1044+
ident,
1045+
b1: binding,
1046+
b2: shadowed_glob,
1047+
warning: false,
1048+
misc1: AmbiguityErrorMisc::None,
1049+
misc2: AmbiguityErrorMisc::None,
1050+
});
1051+
}
1052+
1053+
if shadowing == Shadowing::Unrestricted
1054+
&& binding.expansion != LocalExpnId::ROOT
1055+
&& let NameBindingKind::Import { import, .. } = binding.kind
1056+
&& matches!(import.kind, ImportKind::MacroExport)
1057+
{
1058+
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
1059+
}
1060+
1061+
self.record_use(ident, binding, used);
1062+
return Ok(binding);
1063+
}
1064+
1065+
// Checks if a single import can define the `Ident` corresponding to `binding`.
1066+
// This is used to check whether we can definitively accept a glob as a resolution.
1067+
fn single_import_can_define_name(
1068+
&mut self,
1069+
resolution: &NameResolution<'ra>,
1070+
binding: Option<NameBinding<'ra>>,
1071+
ns: Namespace,
1072+
ignore_import: Option<Import<'ra>>,
1073+
ignore_binding: Option<NameBinding<'ra>>,
1074+
parent_scope: &ParentScope<'ra>,
1075+
) -> bool {
1076+
for single_import in &resolution.single_imports {
1077+
if ignore_import == Some(*single_import) {
1078+
continue;
1079+
}
1080+
if !self.is_accessible_from(single_import.vis, parent_scope.module) {
1081+
continue;
1082+
}
1083+
if let Some(ignored) = ignore_binding
1084+
&& let NameBindingKind::Import { import, .. } = ignored.kind
1085+
&& import == *single_import
1086+
{
1087+
continue;
1088+
}
1089+
1090+
let Some(module) = single_import.imported_module.get() else {
1091+
return true;
1092+
};
1093+
let ImportKind::Single { source, target, target_bindings, .. } = &single_import.kind
1094+
else {
1095+
unreachable!();
1096+
};
1097+
if source != target {
1098+
if target_bindings.iter().all(|binding| binding.get().is_none()) {
1099+
return true;
1100+
} else if target_bindings[ns].get().is_none() && binding.is_some() {
1101+
return true;
1102+
}
1103+
}
1104+
1105+
match self.resolve_ident_in_module(
1106+
module,
1107+
*source,
1108+
ns,
1109+
&single_import.parent_scope,
1110+
None,
1111+
ignore_binding,
1112+
ignore_import,
1113+
) {
1114+
Err((Determined, _)) => continue,
1115+
Ok(binding)
1116+
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
1117+
{
1118+
continue;
1119+
}
1120+
Ok(_) | Err((Undetermined, _)) => {
1121+
return true;
1122+
}
1123+
}
1124+
}
1125+
1126+
false
1127+
}
1128+
11041129
/// Validate a local resolution (from ribs).
11051130
#[instrument(level = "debug", skip(self, all_ribs))]
11061131
fn validate_res_from_ribs(

0 commit comments

Comments
 (0)