1
Fork 0

Auto merge of #114308 - matthiaskrgr:rollup-m64bkm7, r=matthiaskrgr

Rollup of 7 pull requests

Successful merges:

 - #109318 (Make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent with `Mutex` and `RwLock`)
 - #113701 (Re-export core::ffi::FromBytesUntilNulError in std::ffi)
 - #113804 (Resolve correct archive version name in `opt-dist`)
 - #114165 (Add missing rvalues to smir)
 - #114182 (clean up after 113312)
 - #114193 (Update lexer emoji diagnostics to Unicode 15.0)
 - #114200 (Detect trait upcasting through struct tail unsizing in new solver select)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-07-31 23:30:28 +00:00
commit 706a4d9a4e
24 changed files with 228 additions and 134 deletions

View file

@ -16,7 +16,11 @@ Rust lexer used by rustc. No stability guarantees are provided.
# Note that this crate purposefully does not depend on other rustc crates
[dependencies]
unicode-xid = "0.2.0"
unic-emoji-char = "0.9.0"
[dependencies.unicode-properties]
version = "0.1.0"
default-features = false
features = ["emoji"]
[dev-dependencies]
expect-test = "1.4.0"

View file

@ -34,6 +34,7 @@ pub use crate::cursor::Cursor;
use self::LiteralKind::*;
use self::TokenKind::*;
use crate::cursor::EOF_CHAR;
use unicode_properties::UnicodeEmoji;
/// Parsed token.
/// It doesn't contain information about data that has been parsed,
@ -428,9 +429,7 @@ impl Cursor<'_> {
Literal { kind, suffix_start }
}
// Identifier starting with an emoji. Only lexed for graceful error recovery.
c if !c.is_ascii() && unic_emoji_char::is_emoji(c) => {
self.fake_ident_or_unknown_prefix()
}
c if !c.is_ascii() && c.is_emoji_char() => self.fake_ident_or_unknown_prefix(),
_ => Unknown,
};
let res = Token::new(token_kind, self.pos_within_token());
@ -514,9 +513,7 @@ impl Cursor<'_> {
// we see a prefix here, it is definitely an unknown prefix.
match self.first() {
'#' | '"' | '\'' => UnknownPrefix,
c if !c.is_ascii() && unic_emoji_char::is_emoji(c) => {
self.fake_ident_or_unknown_prefix()
}
c if !c.is_ascii() && c.is_emoji_char() => self.fake_ident_or_unknown_prefix(),
_ => Ident,
}
}
@ -525,7 +522,7 @@ impl Cursor<'_> {
// Start is already eaten, eat the rest of identifier.
self.eat_while(|c| {
unicode_xid::UnicodeXID::is_xid_continue(c)
|| (!c.is_ascii() && unic_emoji_char::is_emoji(c))
|| (!c.is_ascii() && c.is_emoji_char())
|| c == '\u{200d}'
});
// Known prefixes must have been handled earlier. So if

View file

@ -132,7 +132,7 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
use mir::Rvalue::*;
match self {
Use(op) => stable_mir::mir::Rvalue::Use(op.stable(tables)),
Repeat(_, _) => todo!(),
Repeat(op, len) => stable_mir::mir::Rvalue::Repeat(op.stable(tables), opaque(len)),
Ref(region, kind, place) => stable_mir::mir::Rvalue::Ref(
opaque(region),
kind.stable(tables),
@ -145,7 +145,11 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
stable_mir::mir::Rvalue::AddressOf(mutability.stable(tables), place.stable(tables))
}
Len(place) => stable_mir::mir::Rvalue::Len(place.stable(tables)),
Cast(_, _, _) => todo!(),
Cast(cast_kind, op, ty) => stable_mir::mir::Rvalue::Cast(
cast_kind.stable(tables),
op.stable(tables),
tables.intern_ty(*ty),
),
BinaryOp(bin_op, ops) => stable_mir::mir::Rvalue::BinaryOp(
bin_op.stable(tables),
ops.0.stable(tables),
@ -163,8 +167,13 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
stable_mir::mir::Rvalue::UnaryOp(un_op.stable(tables), op.stable(tables))
}
Discriminant(place) => stable_mir::mir::Rvalue::Discriminant(place.stable(tables)),
Aggregate(_, _) => todo!(),
ShallowInitBox(_, _) => todo!(),
Aggregate(agg_kind, operands) => {
let operands = operands.iter().map(|op| op.stable(tables)).collect();
stable_mir::mir::Rvalue::Aggregate(agg_kind.stable(tables), operands)
}
ShallowInitBox(op, ty) => {
stable_mir::mir::Rvalue::ShallowInitBox(op.stable(tables), tables.intern_ty(*ty))
}
CopyForDeref(place) => stable_mir::mir::Rvalue::CopyForDeref(place.stable(tables)),
}
}
@ -478,6 +487,40 @@ impl<'tcx> Stable<'tcx> for mir::UnOp {
}
}
impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
type T = stable_mir::mir::AggregateKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
match self {
mir::AggregateKind::Array(ty) => {
stable_mir::mir::AggregateKind::Array(tables.intern_ty(*ty))
}
mir::AggregateKind::Tuple => stable_mir::mir::AggregateKind::Tuple,
mir::AggregateKind::Adt(def_id, var_idx, generic_arg, user_ty_index, field_idx) => {
stable_mir::mir::AggregateKind::Adt(
rustc_internal::adt_def(*def_id),
var_idx.index(),
generic_arg.stable(tables),
user_ty_index.map(|idx| idx.index()),
field_idx.map(|idx| idx.index()),
)
}
mir::AggregateKind::Closure(def_id, generic_arg) => {
stable_mir::mir::AggregateKind::Closure(
rustc_internal::closure_def(*def_id),
generic_arg.stable(tables),
)
}
mir::AggregateKind::Generator(def_id, generic_arg, movability) => {
stable_mir::mir::AggregateKind::Generator(
rustc_internal::generator_def(*def_id),
generic_arg.stable(tables),
movability.stable(tables),
)
}
}
}
}
impl<'tcx> Stable<'tcx> for rustc_hir::GeneratorKind {
type T = stable_mir::mir::GeneratorKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {

View file

@ -1,4 +1,6 @@
use crate::stable_mir::ty::Region;
use crate::stable_mir::ty::{
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
};
use crate::stable_mir::{self, ty::Ty};
#[derive(Clone, Debug)]
@ -137,7 +139,6 @@ pub enum Statement {
Nop,
}
// FIXME this is incomplete
#[derive(Clone, Debug)]
pub enum Rvalue {
/// Creates a pointer with the indicated mutability to the place.
@ -146,6 +147,16 @@ pub enum Rvalue {
/// `&raw v` or `addr_of!(v)`.
AddressOf(Mutability, Place),
/// Creates an aggregate value, like a tuple or struct.
///
/// This is needed because dataflow analysis needs to distinguish
/// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo`
/// has a destructor.
///
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After
/// generator lowering, `Generator` aggregate kinds are disallowed too.
Aggregate(AggregateKind, Vec<Operand>),
/// * `Offset` has the same semantics as [`offset`](pointer::offset), except that the second
/// parameter may be a `usize` as well.
/// * The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats,
@ -198,6 +209,16 @@ pub enum Rvalue {
/// Creates a reference to the place.
Ref(Region, BorrowKind, Place),
/// Creates an array where each element is the value of the operand.
///
/// This is the cause of a bug in the case where the repetition count is zero because the value
/// is not dropped, see [#74836].
///
/// Corresponds to source code like `[x; 32]`.
///
/// [#74836]: https://github.com/rust-lang/rust/issues/74836
Repeat(Operand, Const),
/// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
///
/// This is different from a normal transmute because dataflow analysis will treat the box as
@ -232,6 +253,15 @@ pub enum Rvalue {
Use(Operand),
}
#[derive(Clone, Debug)]
pub enum AggregateKind {
Array(Ty),
Tuple,
Adt(AdtDef, VariantIdx, GenericArgs, Option<UserTypeAnnotationIndex>, Option<FieldIdx>),
Closure(ClosureDef, GenericArgs),
Generator(GeneratorDef, GenericArgs, Movability),
}
#[derive(Clone, Debug)]
pub enum Operand {
Copy(Place),
@ -247,6 +277,11 @@ pub struct Place {
type FieldIdx = usize;
/// The source-order index of a variant in a type.
type VariantIdx = usize;
type UserTypeAnnotationIndex = usize;
#[derive(Clone, Debug)]
pub struct SwitchTarget {
pub value: u128,

View file

@ -10,7 +10,7 @@ impl Ty {
}
}
type Const = Opaque;
pub(crate) type Const = Opaque;
pub(crate) type Region = Opaque;
type Span = Opaque;

View file

@ -100,10 +100,18 @@ impl<'tcx> InferCtxtSelectExt<'tcx> for InferCtxt<'tcx> {
rematch_impl(self, goal, def_id, nested_obligations)
}
// If an unsize goal is ambiguous, then we can manually rematch it to make
// selection progress for coercion during HIR typeck. If it is *not* ambiguous,
// but is `BuiltinImplSource::Misc`, it may have nested `Unsize` goals,
// and we need to rematch those to detect tuple unsizing and trait upcasting.
// FIXME: This will be wrong if we have param-env or where-clause bounds
// with the unsize goal -- we may need to mark those with different impl
// sources.
(Certainty::Maybe(_), CandidateSource::BuiltinImpl(src))
| (Certainty::Yes, CandidateSource::BuiltinImpl(src @ BuiltinImplSource::Misc))
if self.tcx.lang_items().unsize_trait() == Some(goal.predicate.def_id()) =>
{
rematch_unsize(self, goal, nested_obligations, src)
rematch_unsize(self, goal, nested_obligations, src, certainty)
}
// Technically some builtin impls have nested obligations, but if
@ -217,6 +225,7 @@ fn rematch_unsize<'tcx>(
goal: Goal<'tcx, ty::TraitPredicate<'tcx>>,
mut nested: Vec<PredicateObligation<'tcx>>,
source: BuiltinImplSource,
certainty: Certainty,
) -> SelectionResult<'tcx, Selection<'tcx>> {
let tcx = infcx.tcx;
let a_ty = structurally_normalize(goal.predicate.self_ty(), infcx, goal.param_env, &mut nested);
@ -227,6 +236,12 @@ fn rematch_unsize<'tcx>(
&mut nested,
);
match (a_ty.kind(), b_ty.kind()) {
// Stall any ambiguous upcasting goals, since we can't rematch those
(ty::Dynamic(_, _, ty::Dyn), ty::Dynamic(_, _, ty::Dyn)) => match certainty {
Certainty::Yes => Ok(Some(ImplSource::Builtin(source, nested))),
_ => Ok(None),
},
// `T` -> `dyn Trait` upcasting
(_, &ty::Dynamic(data, region, ty::Dyn)) => {
// Check that the type implements all of the predicates of the def-id.
// (i.e. the principal, all of the associated types match, and any auto traits)
@ -354,10 +369,10 @@ fn rematch_unsize<'tcx>(
);
Ok(Some(ImplSource::Builtin(source, nested)))
}
// FIXME: We *could* ICE here if either:
// 1. the certainty is `Certainty::Yes`,
// 2. we're in codegen (which should mean `Certainty::Yes`).
_ => Ok(None),
_ => {
assert_ne!(certainty, Certainty::Yes);
Ok(None)
}
}
}