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 7 pull requests #113647

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5465748
Permit pre-evaluated constants in simd_shuffle
oli-obk Jul 10, 2023
5710fca
update ancient note
tshepang Jul 12, 2023
5842a3f
add support of available_parallelism for target hermit
stlankes Jul 3, 2023
50c7344
define hermit_abi as public depedenceny
stlankes Jul 3, 2023
e1777f9
fix usage of Timespec om the target hermit
stlankes Jul 3, 2023
8666ade
use latest version of hermit-abi
stlankes Jul 4, 2023
518648d
Structurally normalize in selection
compiler-errors Jul 7, 2023
df3f45d
avoid ambiguous word
tshepang Jul 12, 2023
0b5c683
Add machine-applicable suggestion for `unused_qualifications` lint
jieyouxu Jun 17, 2023
ff25ebc
add str, slice, and array to smir types
ericmarkmartin Jul 12, 2023
a167e66
move const definition
ericmarkmartin Jul 13, 2023
9d071b3
Make `nodejs` control the default for RustdocJs tests instead of a ha…
jyn514 Jul 13, 2023
835984c
Rollup merge of #112525 - hermitcore:devel, r=m-ou-se
matthiaskrgr Jul 13, 2023
3f539cd
Rollup merge of #112729 - jieyouxu:unused-qualifications-suggestion, …
matthiaskrgr Jul 13, 2023
83fb198
Rollup merge of #113529 - oli-obk:simd_shuffle_evaluated, r=wesleywiser
matthiaskrgr Jul 13, 2023
c9ef99b
Rollup merge of #113618 - tshepang:patch-1, r=jyn514
matthiaskrgr Jul 13, 2023
2a8ec6e
Rollup merge of #113625 - compiler-errors:structurally-norm-in-select…
matthiaskrgr Jul 13, 2023
a8ad867
Rollup merge of #113639 - ericmarkmartin:more-smir-types, r=oli-obk
matthiaskrgr Jul 13, 2023
6801648
Rollup merge of #113640 - jyn514:nodejs-defaults, r=GuillaumeGomez
matthiaskrgr Jul 13, 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
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1529,9 +1529,9 @@ dependencies = [

[[package]]
name = "hermit-abi"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-alloc",
Expand Down Expand Up @@ -1864,7 +1864,7 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi 0.3.1",
"hermit-abi 0.3.2",
"libc",
"windows-sys 0.48.0",
]
Expand All @@ -1881,7 +1881,7 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb"
dependencies = [
"hermit-abi 0.3.1",
"hermit-abi 0.3.2",
"rustix 0.38.2",
"windows-sys 0.48.0",
]
Expand Down Expand Up @@ -2396,7 +2396,7 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi 0.3.1",
"hermit-abi 0.3.2",
"libc",
]

Expand Down Expand Up @@ -4819,7 +4819,7 @@ dependencies = [
"dlmalloc",
"fortanix-sgx-abi",
"hashbrown 0.14.0",
"hermit-abi 0.3.1",
"hermit-abi 0.3.2",
"libc",
"miniz_oxide",
"object",
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_codegen_ssa/src/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
) -> Result<Option<ty::ValTree<'tcx>>, ErrorHandled> {
let uv = match constant.literal {
mir::ConstantKind::Unevaluated(uv, _) => uv.shrink(),
mir::ConstantKind::Ty(c) => match c.kind() {
// A constant that came from a const generic but was then used as an argument to old-style
// simd_shuffle (passing as argument instead of as a generic param).
rustc_type_ir::ConstKind::Value(valtree) => return Ok(Some(valtree)),
other => span_bug!(constant.span, "{other:#?}"),
},
// We should never encounter `ConstantKind::Val` unless MIR opts (like const prop) evaluate
// a constant and write that value back into `Operand`s. This could happen, but is unlikely.
// Also: all users of `simd_shuffle` are on unstable and already need to take a lot of care
// around intrinsics. For an issue to happen here, it would require a macro expanding to a
// `simd_shuffle` call without wrapping the constant argument in a `const {}` block, but
// the user pass through arbitrary expressions.
// FIXME(oli-obk): replace the magic const generic argument of `simd_shuffle` with a real
// const generic.
other => span_bug!(constant.span, "{other:#?}"),
};
let uv = self.monomorphize(uv);
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,14 @@ pub trait LintContext: Sized {
db.span_note(glob_reexport_span, format!("the name `{}` in the {} namespace is supposed to be publicly re-exported here", name, namespace));
db.span_note(private_item_span, "but the private item here shadows it".to_owned());
}
BuiltinLintDiagnostics::UnusedQualifications { path_span, unqualified_path } => {
db.span_suggestion_verbose(
path_span,
"replace it with the unqualified path",
unqualified_path,
Applicability::MachineApplicable
);
}
}
// Rewrap `db`, and pass control to the user.
decorate(db)
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,12 @@ pub enum BuiltinLintDiagnostics {
/// The local binding that shadows the glob reexport.
private_item_span: Span,
},
UnusedQualifications {
/// The span of the unnecessarily-qualified path.
path_span: Span,
/// The replacement unqualified path.
unqualified_path: Ident,
},
}

/// Lints that are buffered up early on in the `Session` before the
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3917,11 +3917,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
};
if res == unqualified_result {
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
self.r.lint_buffer.buffer_lint(
self.r.lint_buffer.buffer_lint_with_diagnostic(
lint,
finalize.node_id,
finalize.path_span,
"unnecessary qualification",
lint::BuiltinLintDiagnostics::UnusedQualifications {
path_span: finalize.path_span,
unqualified_path: path.last().unwrap().ident
}
)
}
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ impl<'tcx> Tables<'tcx> {
},
ty::Adt(_, _) => todo!(),
ty::Foreign(_) => todo!(),
ty::Str => todo!(),
ty::Array(_, _) => todo!(),
ty::Slice(_) => todo!(),
ty::Str => TyKind::RigidTy(RigidTy::Str),
ty::Array(ty, constant) => {
TyKind::RigidTy(RigidTy::Array(self.intern_ty(*ty), opaque(constant)))
}
ty::Slice(ty) => TyKind::RigidTy(RigidTy::Slice(self.intern_ty(*ty))),
ty::RawPtr(_) => todo!(),
ty::Ref(_, _, _) => todo!(),
ty::FnDef(_, _) => todo!(),
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::with;
use crate::rustc_internal::Opaque;

type Const = Opaque;

#[derive(Copy, Clone, Debug)]
pub struct Ty(pub usize);
Expand All @@ -21,6 +24,9 @@ pub enum RigidTy {
Int(IntTy),
Uint(UintTy),
Float(FloatTy),
Str,
Array(Ty, Const),
Slice(Ty),
Tuple(Vec<Ty>),
}

Expand Down
63 changes: 46 additions & 17 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ use rustc_hir::def_id::DefId;
use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
use rustc_infer::traits::util::supertraits;
use rustc_infer::traits::{
Obligation, PolyTraitObligation, PredicateObligation, Selection, SelectionResult,
Obligation, PolyTraitObligation, PredicateObligation, Selection, SelectionResult, TraitEngine,
};
use rustc_middle::traits::solve::{CanonicalInput, Certainty, Goal};
use rustc_middle::traits::{
ImplSource, ImplSourceObjectData, ImplSourceTraitUpcastingData, ImplSourceUserDefinedData,
ObligationCause, SelectionError,
};
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::DUMMY_SP;

use crate::solve::assembly::{BuiltinImplSource, Candidate, CandidateSource};
use crate::solve::eval_ctxt::{EvalCtxt, GenerateProofTree};
use crate::solve::inspect::ProofTreeBuilder;
use crate::solve::search_graph::OverflowHandler;
use crate::traits::vtable::{count_own_vtable_entries, prepare_vtable_segments, VtblSegment};
use crate::traits::StructurallyNormalizeExt;
use crate::traits::TraitEngineExt;

pub trait InferCtxtSelectExt<'tcx> {
fn select_in_new_trait_solver(
Expand Down Expand Up @@ -220,25 +222,33 @@ fn rematch_object<'tcx>(
goal: Goal<'tcx, ty::TraitPredicate<'tcx>>,
mut nested: Vec<PredicateObligation<'tcx>>,
) -> SelectionResult<'tcx, Selection<'tcx>> {
let self_ty = goal.predicate.self_ty();
let ty::Dynamic(data, _, source_kind) = *self_ty.kind()
let a_ty = structurally_normalize(goal.predicate.self_ty(), infcx, goal.param_env, &mut nested);
let ty::Dynamic(data, _, source_kind) = *a_ty.kind()
else {
bug!()
};
let source_trait_ref = data.principal().unwrap().with_self_ty(infcx.tcx, self_ty);

let (is_upcasting, target_trait_ref_unnormalized) = if Some(goal.predicate.def_id())
== infcx.tcx.lang_items().unsize_trait()
{
assert_eq!(source_kind, ty::Dyn, "cannot upcast dyn*");
if let ty::Dynamic(data, _, ty::Dyn) = goal.predicate.trait_ref.substs.type_at(1).kind() {
(true, data.principal().unwrap().with_self_ty(infcx.tcx, self_ty))
let source_trait_ref = data.principal().unwrap().with_self_ty(infcx.tcx, a_ty);

let (is_upcasting, target_trait_ref_unnormalized) =
if Some(goal.predicate.def_id()) == infcx.tcx.lang_items().unsize_trait() {
assert_eq!(source_kind, ty::Dyn, "cannot upcast dyn*");
let b_ty = structurally_normalize(
goal.predicate.trait_ref.substs.type_at(1),
infcx,
goal.param_env,
&mut nested,
);
if let ty::Dynamic(data, _, ty::Dyn) = *b_ty.kind() {
// FIXME: We also need to ensure that the source lifetime outlives the
// target lifetime. This doesn't matter for codegen, though, and only
// *really* matters if the goal's certainty is ambiguous.
(true, data.principal().unwrap().with_self_ty(infcx.tcx, a_ty))
} else {
bug!()
}
} else {
bug!()
}
} else {
(false, ty::Binder::dummy(goal.predicate.trait_ref))
};
(false, ty::Binder::dummy(goal.predicate.trait_ref))
};

let mut target_trait_ref = None;
for candidate_trait_ref in supertraits(infcx.tcx, source_trait_ref) {
Expand Down Expand Up @@ -305,3 +315,22 @@ fn rematch_object<'tcx>(
ImplSource::Object(ImplSourceObjectData { vtable_base, nested })
}))
}

fn structurally_normalize<'tcx>(
ty: Ty<'tcx>,
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
nested: &mut Vec<PredicateObligation<'tcx>>,
) -> Ty<'tcx> {
if matches!(ty.kind(), ty::Alias(..)) {
let mut engine = <dyn TraitEngine<'tcx>>::new(infcx);
let normalized_ty = infcx
.at(&ObligationCause::dummy(), param_env)
.structurally_normalize(ty, &mut *engine)
.expect("normalization shouldn't fail if we got to here");
nested.extend(engine.pending_obligations());
normalized_ty
} else {
ty
}
}
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }
fortanix-sgx-abi = { version = "0.5.0", features = ['rustc-dep-of-std'], public = true }

[target.'cfg(target_os = "hermit")'.dependencies]
hermit-abi = { version = "0.3.0", features = ['rustc-dep-of-std'] }
hermit-abi = { version = "0.3.2", features = ['rustc-dep-of-std'], public = true }

[target.wasm32-wasi.dependencies]
wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ use super::map::{map_try_reserve_error, RandomState};
/// ```
///
/// The easiest way to use `HashSet` with a custom type is to derive
/// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`], this will in the
/// future be implied by [`Eq`].
/// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`],
/// which is required if [`Eq`] is derived.
///
/// ```
/// use std::collections::HashSet;
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/sys/hermit/thread.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(dead_code)]

use super::unsupported;
use crate::ffi::CStr;
use crate::io;
use crate::mem;
Expand Down Expand Up @@ -99,7 +98,7 @@ impl Thread {
}

pub fn available_parallelism() -> io::Result<NonZeroUsize> {
unsupported()
unsafe { Ok(NonZeroUsize::new_unchecked(abi::get_processor_count())) }
}

pub mod guard {
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/hermit/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Timespec {
}

fn checked_add_duration(&self, other: &Duration) -> Option<Timespec> {
let mut secs = self.tv_sec.checked_add_unsigned(other.as_secs())?;
let mut secs = self.t.tv_sec.checked_add_unsigned(other.as_secs())?;

// Nano calculations can't overflow because nanos are <1B which fit
// in a u32.
Expand All @@ -53,7 +53,7 @@ impl Timespec {
}

fn checked_sub_duration(&self, other: &Duration) -> Option<Timespec> {
let mut secs = self.tv_sec.checked_sub_unsigned(other.as_secs())?;
let mut secs = self.t.tv_sec.checked_sub_unsigned(other.as_secs())?;

// Similar to above, nanos can't overflow.
let mut nsec = self.t.tv_nsec as i32 - other.subsec_nanos() as i32;
Expand Down
Loading