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 #99825

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
645a883
Update mentions to `rustc_metadata::rmeta::Lazy`
JohnTitor Jul 27, 2022
e849f9b
doc/rustc: describe the uefi target platforms
dvdhrm Jul 26, 2022
9d118c5
Fix settings display on small screen size
GuillaumeGomez Jul 27, 2022
1564305
Add GUI test for settings in small device
GuillaumeGomez Jul 27, 2022
0eb28ab
Allow using stable os::fd::raw items through unstable os::wasi module
bstrie Jul 27, 2022
bc4a1de
Initial (incomplete) implementation of transmutability trait.
jswrenn Jul 3, 2021
18751a7
safe transmute: gracefully handle const params of wrong types
jswrenn Jul 20, 2022
8c5c291
safe transmute: test when `ASSUME` params are passed indirectly
jswrenn Jul 20, 2022
0fa70c3
safe transmute: revise `Hash`, `PartialEq` impls on `VariantDef`, `Fi…
jswrenn Jul 20, 2022
c0d0ce9
safe transmute: tweak tracing
jswrenn Jul 21, 2022
4a15157
safe transmute: don't mark user impls as unambiguous
jswrenn Jul 21, 2022
402644f
safe transmute: test to ensure that trait is correctly feature-gated
jswrenn Jul 21, 2022
21d1ab4
safe transmute: add `rustc_on_unimplemented` to `BikeshedIntrinsicFrom`
jswrenn Jul 21, 2022
b78c3da
safe transmute: reference tracking issue
jswrenn Jul 21, 2022
2268603
safe transmute: tweak `Nfa::union` to consume params by value
jswrenn Jul 21, 2022
aee5f31
safe transmute: lowercase tracing levels
jswrenn Jul 21, 2022
8aca883
rustdoc: remove Clean trait impl for ty::Term
notriddle Jul 27, 2022
3ea9916
rustdoc: remove Clean trait impl for hir::Term
notriddle Jul 27, 2022
2f03cbd
rustdoc: remove Clean trait impl for ty::GenericParamDef
notriddle Jul 27, 2022
fef95da
Rollup merge of #92268 - jswrenn:transmute, r=oli-obk
GuillaumeGomez Jul 27, 2022
46e21aa
Rollup merge of #99723 - bstrie:wasifd, r=yaahc
GuillaumeGomez Jul 27, 2022
24f6d02
Rollup merge of #99760 - dvdhrm:rw/uefiplat, r=ehuss
GuillaumeGomez Jul 27, 2022
e81f2f9
Rollup merge of #99803 - JohnTitor:update-lazy-docs, r=compiler-errors
GuillaumeGomez Jul 27, 2022
151ba52
Rollup merge of #99810 - GuillaumeGomez:fix-settings-slider-small-wid…
GuillaumeGomez Jul 27, 2022
6c23495
Rollup merge of #99817 - notriddle:notriddle/clean-trait-removal, r=G…
GuillaumeGomez Jul 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4553,6 +4553,7 @@ dependencies = [
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_transmute",
"smallvec",
"tracing",
]
Expand All @@ -4577,6 +4578,20 @@ dependencies = [
"tracing",
]

[[package]]
name = "rustc_transmute"
version = "0.1.0"
dependencies = [
"itertools",
"rustc_data_structures",
"rustc_infer",
"rustc_macros",
"rustc_middle",
"rustc_span",
"rustc_target",
"tracing",
]

[[package]]
name = "rustc_ty_utils"
version = "0.0.0"
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ language_item_table! {
CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1);
DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1);

// language items relating to transmutability
TransmuteTrait, sym::transmute_trait, transmute_trait, Target::Trait, GenericRequirement::Exact(6);

Add(Op), sym::add, add_trait, Target::Trait, GenericRequirement::Exact(1);
Sub(Op), sym::sub, sub_trait, Target::Trait, GenericRequirement::Exact(1);
Mul(Op), sym::mul, mul_trait, Target::Trait, GenericRequirement::Exact(1);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub(crate) struct CrateMetadata {

// --- Some data pre-decoded from the metadata blob, usually for performance ---
/// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
/// lifetime is only used behind `Lazy`, and therefore acts like a
/// lifetime is only used behind `LazyValue`, `LazyArray`, or `LazyTable`, and therefore acts like a
/// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
/// is being used to decode those values.
root: CrateRoot,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_V
///
/// Metadata is effective a tree, encoded in post-order,
/// and with the root's position written next to the header.
/// That means every single `Lazy` points to some previous
/// That means every single `LazyValue` points to some previous
/// location in the metadata and is part of a larger node.
///
/// The first `Lazy` in a node is encoded as the backwards
/// The first `LazyValue` in a node is encoded as the backwards
/// distance from the position where the containing node
/// starts and where the `Lazy` points to, while the rest
/// use the forward distance from the previous `Lazy`.
/// starts and where the `LazyValue` points to, while the rest
/// use the forward distance from the previous `LazyValue`.
/// Distances start at 1, as 0-byte nodes are invalid.
/// Also invalid are nodes being referred in a different
/// order than they were encoded in.
Expand All @@ -94,12 +94,12 @@ impl<T> LazyValue<T> {

/// A list of lazily-decoded values.
///
/// Unlike `Lazy<Vec<T>>`, the length is encoded next to the
/// Unlike `LazyValue<Vec<T>>`, the length is encoded next to the
/// position, not at the position, which means that the length
/// doesn't need to be known before encoding all the elements.
///
/// If the length is 0, no position is encoded, but otherwise,
/// the encoding is that of `Lazy`, with the distinction that
/// the encoding is that of `LazyArray`, with the distinction that
/// the minimal distance the length of the sequence, i.e.
/// it's assumed there's no 0-byte element in the sequence.
struct LazyArray<T> {
Expand Down Expand Up @@ -167,17 +167,17 @@ impl<I, T> Clone for LazyTable<I, T> {
}
}

/// Encoding / decoding state for `Lazy`.
/// Encoding / decoding state for `Lazy`s (`LazyValue`, `LazyArray`, and `LazyTable`).
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum LazyState {
/// Outside of a metadata node.
NoNode,

/// Inside a metadata node, and before any `Lazy`.
/// Inside a metadata node, and before any `Lazy`s.
/// The position is that of the node itself.
NodeStart(NonZeroUsize),

/// Inside a metadata node, with a previous `Lazy`.
/// Inside a metadata node, with a previous `Lazy`s.
/// The position is where that previous `Lazy` would start.
Previous(NonZeroUsize),
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fixed_size_enum! {
}
}

// We directly encode `DefPathHash` because a `Lazy` would encur a 25% cost.
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
impl FixedSizeEncoding for Option<DefPathHash> {
type ByteArray = [u8; 16];

Expand All @@ -159,7 +159,7 @@ impl FixedSizeEncoding for Option<DefPathHash> {
}
}

// We directly encode RawDefId because using a `Lazy` would incur a 50% overhead in the worst case.
// We directly encode RawDefId because using a `LazyValue` would incur a 50% overhead in the worst case.
impl FixedSizeEncoding for Option<RawDefId> {
type ByteArray = [u8; 8];

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ pub enum SelectionCandidate<'tcx> {
/// `false` if there are no *further* obligations.
has_nested: bool,
},

/// Implementation of transmutability trait.
TransmutabilityCandidate,

ParamCandidate(ty::PolyTraitPredicate<'tcx>),
ImplCandidate(DefId),
AutoImplCandidate(DefId),
Expand Down
91 changes: 90 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub use subst::*;
pub use vtable::*;

use std::fmt::Debug;
use std::hash::Hash;
use std::hash::{Hash, Hasher};
use std::ops::ControlFlow;
use std::{fmt, str};

Expand Down Expand Up @@ -1724,6 +1724,59 @@ impl VariantDef {
}
}

impl PartialEq for VariantDef {
#[inline]
fn eq(&self, other: &Self) -> bool {
// There should be only one `VariantDef` for each `def_id`, therefore
// it is fine to implement `PartialEq` only based on `def_id`.
//
// Below, we exhaustively destructure `self` and `other` so that if the
// definition of `VariantDef` changes, a compile-error will be produced,
// reminding us to revisit this assumption.

let Self {
def_id: lhs_def_id,
ctor_def_id: _,
name: _,
discr: _,
fields: _,
ctor_kind: _,
flags: _,
} = &self;

let Self {
def_id: rhs_def_id,
ctor_def_id: _,
name: _,
discr: _,
fields: _,
ctor_kind: _,
flags: _,
} = other;

lhs_def_id == rhs_def_id
}
}

impl Eq for VariantDef {}

impl Hash for VariantDef {
#[inline]
fn hash<H: Hasher>(&self, s: &mut H) {
// There should be only one `VariantDef` for each `def_id`, therefore
// it is fine to implement `Hash` only based on `def_id`.
//
// Below, we exhaustively destructure `self` so that if the definition
// of `VariantDef` changes, a compile-error will be produced, reminding
// us to revisit this assumption.

let Self { def_id, ctor_def_id: _, name: _, discr: _, fields: _, ctor_kind: _, flags: _ } =
&self;

def_id.hash(s)
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
pub enum VariantDiscr {
/// Explicit value for this variant, i.e., `X = 123`.
Expand All @@ -1744,6 +1797,42 @@ pub struct FieldDef {
pub vis: Visibility,
}

impl PartialEq for FieldDef {
#[inline]
fn eq(&self, other: &Self) -> bool {
// There should be only one `FieldDef` for each `did`, therefore it is
// fine to implement `PartialEq` only based on `did`.
//
// Below, we exhaustively destructure `self` so that if the definition
// of `FieldDef` changes, a compile-error will be produced, reminding
// us to revisit this assumption.

let Self { did: lhs_did, name: _, vis: _ } = &self;

let Self { did: rhs_did, name: _, vis: _ } = other;

lhs_did == rhs_did
}
}

impl Eq for FieldDef {}

impl Hash for FieldDef {
#[inline]
fn hash<H: Hasher>(&self, s: &mut H) {
// There should be only one `FieldDef` for each `did`, therefore it is
// fine to implement `Hash` only based on `did`.
//
// Below, we exhaustively destructure `self` so that if the definition
// of `FieldDef` changes, a compile-error will be produced, reminding
// us to revisit this assumption.

let Self { did, name: _, vis: _ } = &self;

did.hash(s)
}
}

bitflags! {
#[derive(TyEncodable, TyDecodable, Default, HashStable)]
pub struct ReprFlags: u8 {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ symbols! {
trait_alias,
trait_upcasting,
transmute,
transmute_trait,
transparent,
transparent_enums,
transparent_unions,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ impl fmt::Debug for Align {

impl Align {
pub const ONE: Align = Align { pow2: 0 };
pub const MAX: Align = Align { pow2: 29 };

#[inline]
pub fn from_bits(bits: u64) -> Result<Align, String> {
Expand Down Expand Up @@ -540,7 +541,7 @@ impl Align {
if bytes != 1 {
return Err(not_power_of_2(align));
}
if pow2 > 29 {
if pow2 > Self::MAX.pow2 {
return Err(too_large(align));
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ rustc_query_system = { path = "../rustc_query_system" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_transmute = { path = "../rustc_transmute", features = ["rustc"] }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.assemble_candidates_for_unsizing(obligation, &mut candidates);
} else if lang_items.destruct_trait() == Some(def_id) {
self.assemble_const_destruct_candidates(obligation, &mut candidates);
} else if lang_items.transmute_trait() == Some(def_id) {
// User-defined transmutability impls are permitted.
self.assemble_candidates_from_impls(obligation, &mut candidates);
self.assemble_candidates_for_transmutability(obligation, &mut candidates);
} else {
if lang_items.clone_trait() == Some(def_id) {
// Same builtin conditions as `Copy`, i.e., every type which has builtin support
Expand Down Expand Up @@ -873,6 +877,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
};
}

#[tracing::instrument(level = "debug", skip(self, obligation, candidates))]
fn assemble_candidates_for_transmutability(
&mut self,
obligation: &TraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) {
if obligation.has_param_types_or_consts() {
return;
}

if obligation.has_infer_types_or_consts() {
candidates.ambiguous = true;
return;
}

candidates.vec.push(TransmutabilityCandidate);
}

#[tracing::instrument(level = "debug", skip(self, obligation, candidates))]
fn assemble_candidates_for_trait_alias(
&mut self,
Expand Down
52 changes: 52 additions & 0 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplSource::Builtin(data)
}

TransmutabilityCandidate => {
let data = self.confirm_transmutability_candidate(obligation)?;
ImplSource::Builtin(data)
}

ParamCandidate(param) => {
let obligations =
self.confirm_param_candidate(obligation, param.map_bound(|t| t.trait_ref));
Expand Down Expand Up @@ -267,6 +272,53 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplSourceBuiltinData { nested: obligations }
}

fn confirm_transmutability_candidate(
&mut self,
obligation: &TraitObligation<'tcx>,
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
debug!(?obligation, "confirm_transmutability_candidate");

let predicate = obligation.predicate;

let type_at = |i| predicate.map_bound(|p| p.trait_ref.substs.type_at(i));
let bool_at = |i| {
predicate
.skip_binder()
.trait_ref
.substs
.const_at(i)
.try_eval_bool(self.tcx(), obligation.param_env)
.unwrap_or(true)
};

let src_and_dst = predicate.map_bound(|p| rustc_transmute::Types {
src: p.trait_ref.substs.type_at(1),
dst: p.trait_ref.substs.type_at(0),
});

let scope = type_at(2).skip_binder();

let assume = rustc_transmute::Assume {
alignment: bool_at(3),
lifetimes: bool_at(4),
validity: bool_at(5),
visibility: bool_at(6),
};

let cause = obligation.cause.clone();

let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx);

let maybe_transmutable = transmute_env.is_transmutable(cause, src_and_dst, scope, assume);

use rustc_transmute::Answer;

match maybe_transmutable {
Answer::Yes => Ok(ImplSourceBuiltinData { nested: vec![] }),
_ => Err(Unimplemented),
}
}

/// This handles the case where an `auto trait Foo` impl is being used.
/// The idea is that the impl applies to `X : Foo` if the following conditions are met:
///
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);
}

// FIXME(@jswrenn): this should probably be more sophisticated
(TransmutabilityCandidate, _) | (_, TransmutabilityCandidate) => false,

// (*)
(
BuiltinCandidate { has_nested: false }
Expand Down