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 8 pull requests #90416

Merged
merged 20 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
23d033e
Added const versions of common numeric operations
AlexApps99 Oct 21, 2021
361c978
Added docs to internal_macro const
AlexApps99 Oct 20, 2021
29a4e4a
Fix incorrect doc link
Veykril Oct 28, 2021
991a296
Make `core::slice::from_raw_parts[_mut]` const
WaffleLapkin Oct 28, 2021
04cb196
don't mutably borrow inner infcx in all of ConstInferUnifier::consts
b-naber Oct 29, 2021
a39c50b
add test
b-naber Oct 29, 2021
87fbf3c
ignore type flags insertion in default_anon_const_substs if error occ…
b-naber Oct 29, 2021
60bf2f1
Add a few query descriptions
wesleywiser Oct 29, 2021
0c70831
Unify titles in rustdoc book doc attributes chapter
GuillaumeGomez Oct 28, 2021
878ac10
Use proper issue number for `feature(const_slice_from_raw_parts)`
WaffleLapkin Oct 29, 2021
afaa54a
Apply changes proposed in the review
WaffleLapkin Oct 29, 2021
b6851ba
Remove unnecessary `macro_use`s in rustdoc
jyn514 Oct 30, 2021
20bb932
Rollup merge of #89876 - AlexApps99:const_ops, r=oli-obk
matthiaskrgr Oct 30, 2021
86087f9
Rollup merge of #90371 - Veykril:patch-2, r=jyn514
matthiaskrgr Oct 30, 2021
a213740
Rollup merge of #90374 - GuillaumeGomez:unify-rustdoc-book-titles, r=…
matthiaskrgr Oct 30, 2021
b531364
Rollup merge of #90377 - WaffleLapkin:const_slice_from_raw_parts, r=o…
matthiaskrgr Oct 30, 2021
88e0bea
Rollup merge of #90395 - b-naber:const-expr-type-relation, r=oli-obk
matthiaskrgr Oct 30, 2021
d99dc7a
Rollup merge of #90396 - b-naber:type_flags_ices_default_anon_consts,…
matthiaskrgr Oct 30, 2021
f9111e0
Rollup merge of #90402 - wesleywiser:query_descriptions, r=oli-obk
matthiaskrgr Oct 30, 2021
19b5b0f
Rollup merge of #90412 - jyn514:macro-use, r=camelid
matthiaskrgr Oct 30, 2021
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
29 changes: 20 additions & 9 deletions compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
}

#[tracing::instrument(level = "debug", skip(self))]
fn tys(&mut self, t: Ty<'tcx>, _t: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
debug_assert_eq!(t, _t);
debug!("ConstInferUnifier: t={:?}", t);
Expand Down Expand Up @@ -941,6 +942,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
}
}

#[tracing::instrument(level = "debug", skip(self))]
fn consts(
&mut self,
c: &'tcx ty::Const<'tcx>,
Expand All @@ -951,29 +953,38 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {

match c.val {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
let mut inner = self.infcx.inner.borrow_mut();
let variable_table = &mut inner.const_unification_table();

// Check if the current unification would end up
// unifying `target_vid` with a const which contains
// an inference variable which is unioned with `target_vid`.
//
// Not doing so can easily result in stack overflows.
if variable_table.unioned(self.target_vid, vid) {
if self
.infcx
.inner
.borrow_mut()
.const_unification_table()
.unioned(self.target_vid, vid)
{
return Err(TypeError::CyclicConst(c));
}

let var_value = variable_table.probe_value(vid);
let var_value =
self.infcx.inner.borrow_mut().const_unification_table().probe_value(vid);
match var_value.val {
ConstVariableValue::Known { value: u } => self.consts(u, u),
ConstVariableValue::Unknown { universe } => {
if self.for_universe.can_name(universe) {
Ok(c)
} else {
let new_var_id = variable_table.new_key(ConstVarValue {
origin: var_value.origin,
val: ConstVariableValue::Unknown { universe: self.for_universe },
});
let new_var_id =
self.infcx.inner.borrow_mut().const_unification_table().new_key(
ConstVarValue {
origin: var_value.origin,
val: ConstVariableValue::Unknown {
universe: self.for_universe,
},
},
);
Ok(self.tcx().mk_const_var(new_var_id, c.ty))
}
}
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,13 @@ rustc_queries! {
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
}

/// The signature of functions.
/// Computes the signature of the function.
query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
separate_provide_extern
}

/// Performs lint checking for the module.
query lint_mod(key: LocalDefId) -> () {
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
}
Expand All @@ -702,6 +703,7 @@ rustc_queries! {
desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
}

/// Checks for uses of unstable APIs in the module.
query check_mod_unstable_api_usage(key: LocalDefId) -> () {
desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
}
Expand Down Expand Up @@ -928,6 +930,7 @@ rustc_queries! {
desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
}

/// Generates a MIR body for the shim.
query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
storage(ArenaCacheSelector<'tcx>)
desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
Expand All @@ -946,11 +949,13 @@ rustc_queries! {
separate_provide_extern
}

/// Gets the span for the definition.
query def_span(def_id: DefId) -> Span {
desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}

/// Gets the span for the identifier of the definition.
query def_ident_span(def_id: DefId) -> Option<Span> {
desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
separate_provide_extern
Expand Down Expand Up @@ -1466,6 +1471,8 @@ rustc_queries! {
desc { "fetching what a dependency looks like" }
separate_provide_extern
}

/// Gets the name of the crate.
query crate_name(_: CrateNum) -> Symbol {
eval_always
desc { "fetching what a crate is named" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ impl CheckAttrVisitor<'tcx> {
"not a `use` item",
);
}
err.note("read https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#docno_inlinedocinline for more information")
err.note("read https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#inline-and-no_inline for more information")
.emit();
},
);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> Subst
// Getting this wrong can lead to ICE and unsoundness, so we assert it here.
for arg in substs.iter() {
let allowed_flags = ty::TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE;
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE
| ty::TypeFlags::HAS_ERROR;
assert!(!arg.has_type_flags(!allowed_flags));
}
substs
Expand Down
71 changes: 71 additions & 0 deletions library/core/src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ macro_rules! forward_ref_unop {
forward_ref_unop!(impl $imp, $method for $t,
#[stable(feature = "rust1", since = "1.0.0")]);
};
(impl const $imp:ident, $method:ident for $t:ty) => {
forward_ref_unop!(impl const $imp, $method for $t,
#[stable(feature = "rust1", since = "1.0.0")]);
};
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
(impl const $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
#[$attr]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const $imp for &$t {
type Output = <$t as $imp>::Output;

#[inline]
fn $method(self) -> <$t as $imp>::Output {
$imp::$method(*self)
}
}
};
(impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
#[$attr]
impl $imp for &$t {
Expand All @@ -25,6 +42,45 @@ macro_rules! forward_ref_binop {
forward_ref_binop!(impl $imp, $method for $t, $u,
#[stable(feature = "rust1", since = "1.0.0")]);
};
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
forward_ref_binop!(impl const $imp, $method for $t, $u,
#[stable(feature = "rust1", since = "1.0.0")]);
};
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
#[$attr]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl<'a> const $imp<$u> for &'a $t {
type Output = <$t as $imp<$u>>::Output;

#[inline]
fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
$imp::$method(*self, other)
}
}

#[$attr]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const $imp<&$u> for $t {
type Output = <$t as $imp<$u>>::Output;

#[inline]
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
$imp::$method(self, *other)
}
}

#[$attr]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const $imp<&$u> for &$t {
type Output = <$t as $imp<$u>>::Output;

#[inline]
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
$imp::$method(*self, *other)
}
}
};
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
#[$attr]
impl<'a> $imp<$u> for &'a $t {
Expand Down Expand Up @@ -65,6 +121,21 @@ macro_rules! forward_ref_op_assign {
forward_ref_op_assign!(impl $imp, $method for $t, $u,
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
};
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
forward_ref_op_assign!(impl const $imp, $method for $t, $u,
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
};
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
#[$attr]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const $imp<&$u> for $t {
#[inline]
fn $method(&mut self, other: &$u) {
$imp::$method(self, *other);
}
}
};
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
#[$attr]
impl $imp<&$u> for $t {
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
#![feature(const_caller_location)]
#![feature(const_cell_into_inner)]
#![feature(const_discriminant)]
#![cfg_attr(not(bootstrap), feature(const_eval_select))]
#![feature(const_float_bits_conv)]
#![feature(const_float_classify)]
#![feature(const_fmt_arguments_new)]
Expand All @@ -117,6 +118,7 @@
#![feature(const_maybe_uninit_as_ptr)]
#![feature(const_maybe_uninit_assume_init)]
#![feature(const_num_from_num)]
#![feature(const_ops)]
#![feature(const_option)]
#![feature(const_pin)]
#![feature(const_replace)]
Expand Down
21 changes: 14 additions & 7 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ macro_rules! nonzero_integers {
}

#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOr for $Ty {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitOr for $Ty {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
Expand All @@ -103,7 +104,8 @@ macro_rules! nonzero_integers {
}

#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOr<$Int> for $Ty {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitOr<$Int> for $Ty {
type Output = Self;
#[inline]
fn bitor(self, rhs: $Int) -> Self::Output {
Expand All @@ -115,7 +117,8 @@ macro_rules! nonzero_integers {
}

#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOr<$Ty> for $Int {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitOr<$Ty> for $Int {
type Output = $Ty;
#[inline]
fn bitor(self, rhs: $Ty) -> Self::Output {
Expand All @@ -127,15 +130,17 @@ macro_rules! nonzero_integers {
}

#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOrAssign for $Ty {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitOrAssign for $Ty {
#[inline]
fn bitor_assign(&mut self, rhs: Self) {
*self = *self | rhs;
}
}

#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOrAssign<$Int> for $Ty {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitOrAssign<$Int> for $Ty {
#[inline]
fn bitor_assign(&mut self, rhs: $Int) {
*self = *self | rhs;
Expand Down Expand Up @@ -257,7 +262,8 @@ macro_rules! nonzero_integers_div {
( $( $Ty: ident($Int: ty); )+ ) => {
$(
#[stable(feature = "nonzero_div", since = "1.51.0")]
impl Div<$Ty> for $Int {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Div<$Ty> for $Int {
type Output = $Int;
/// This operation rounds towards zero,
/// truncating any fractional part of the exact result, and cannot panic.
Expand All @@ -270,7 +276,8 @@ macro_rules! nonzero_integers_div {
}

#[stable(feature = "nonzero_div", since = "1.51.0")]
impl Rem<$Ty> for $Int {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Rem<$Ty> for $Int {
type Output = $Int;
/// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
#[inline]
Expand Down
Loading