Skip to content

Commit

Permalink
Auto merge of #118248 - compiler-errors:rollup-tye3vgj, r=compiler-er…
Browse files Browse the repository at this point in the history
…rors

Rollup of 7 pull requests

Successful merges:

 - #118187 (Recompile LLVM when it changes in the git sources)
 - #118210 (intercrate ambiguity causes: ignore candidates which don't apply)
 - #118215 (Add common trait for crate definitions)
 - #118238 (memcpy assumptions: update GCC link)
 - #118243 (EvalCtxt::commit_if_ok don't inherit nested goals)
 - #118245 (Add `Span` to `TraitBoundModifier`)
 - #118246 (Remove a hack for effects)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 24, 2023
2 parents 4fd68eb + 592ee12 commit 42ae1a7
Show file tree
Hide file tree
Showing 42 changed files with 485 additions and 155 deletions.
7 changes: 3 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub enum TraitBoundModifier {
Maybe,

/// `~const Trait`
MaybeConst,
MaybeConst(Span),

/// `~const !Trait`
//
Expand All @@ -317,8 +317,7 @@ pub enum TraitBoundModifier {
impl TraitBoundModifier {
pub fn to_constness(self) -> Const {
match self {
// FIXME(effects) span
Self::MaybeConst => Const::Yes(DUMMY_SP),
Self::MaybeConst(span) => Const::Yes(span),
_ => Const::No,
}
}
Expand Down Expand Up @@ -3155,7 +3154,7 @@ mod size_asserts {
static_assert_size!(ForeignItem, 96);
static_assert_size!(ForeignItemKind, 24);
static_assert_size!(GenericArg, 24);
static_assert_size!(GenericBound, 56);
static_assert_size!(GenericBound, 64);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 136);
static_assert_size!(Item, 136);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
GenericBound::Trait(
ty,
modifier @ (TraitBoundModifier::None
| TraitBoundModifier::MaybeConst
| TraitBoundModifier::MaybeConst(_)
| TraitBoundModifier::Negative),
) => {
Some(this.lower_poly_trait_ref(ty, itctx, modifier.to_constness()))
Expand Down Expand Up @@ -2227,7 +2227,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_trait_bound_modifier(&mut self, f: TraitBoundModifier) -> hir::TraitBoundModifier {
match f {
TraitBoundModifier::None => hir::TraitBoundModifier::None,
TraitBoundModifier::MaybeConst => hir::TraitBoundModifier::MaybeConst,
TraitBoundModifier::MaybeConst(_) => hir::TraitBoundModifier::MaybeConst,

TraitBoundModifier::Negative => {
if self.tcx.features().negative_bounds {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
(BoundKind::TraitObject, TraitBoundModifier::Maybe) => {
self.err_handler().emit_err(errors::OptionalTraitObject { span: poly.span });
}
(_, TraitBoundModifier::MaybeConst)
(_, &TraitBoundModifier::MaybeConst(span))
if let Some(reason) = &self.disallow_tilde_const =>
{
let reason = match reason {
Expand All @@ -1224,8 +1224,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
DisallowTildeConstContext::Item => errors::TildeConstReason::Item,
};
self.err_handler()
.emit_err(errors::TildeConstDisallowed { span: bound.span(), reason });
self.err_handler().emit_err(errors::TildeConstDisallowed { span, reason });
}
(_, TraitBoundModifier::MaybeConstMaybe) => {
self.err_handler().emit_err(errors::OptionalConstExclusive {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ impl<'a> State<'a> {
TraitBoundModifier::Maybe => {
self.word("?");
}
TraitBoundModifier::MaybeConst => {
TraitBoundModifier::MaybeConst(_) => {
self.word_space("~const");
}
TraitBoundModifier::MaybeConstNegative => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind,
use rustc_ast::{attr, token, util::literal};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};
use thin_vec::{thin_vec, ThinVec};

impl<'a> ExtCtxt<'a> {
Expand Down Expand Up @@ -135,7 +135,7 @@ impl<'a> ExtCtxt<'a> {
ast::GenericBound::Trait(
self.poly_trait_ref(path.span, path),
if is_const {
ast::TraitBoundModifier::MaybeConst
ast::TraitBoundModifier::MaybeConst(DUMMY_SP)
} else {
ast::TraitBoundModifier::None
},
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
};

if let ty::FnDef(did, callee_args) = *ty.kind() {
if let ty::FnDef(did, _) = *ty.kind() {
let fn_sig = ty.fn_sig(tcx);

// HACK: whenever we get a FnDef in a non-const context, enforce effects to get the
// default `host = true` to avoid inference errors later.
if tcx.hir().body_const_context(self.body_id).is_none() {
self.enforce_context_effects(expr.hir_id, qpath.span(), did, callee_args);
}
if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic
&& tcx.item_name(did) == sym::transmute
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl BoundModifiers {
(BoundPolarity::Positive, None) => TraitBoundModifier::None,
(BoundPolarity::Negative(_), None) => TraitBoundModifier::Negative,
(BoundPolarity::Maybe(_), None) => TraitBoundModifier::Maybe,
(BoundPolarity::Positive, Some(_)) => TraitBoundModifier::MaybeConst,
(BoundPolarity::Positive, Some(sp)) => TraitBoundModifier::MaybeConst(sp),
(BoundPolarity::Negative(_), Some(_)) => TraitBoundModifier::MaybeConstNegative,
(BoundPolarity::Maybe(_), Some(_)) => TraitBoundModifier::MaybeConstMaybe,
}
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_smir/src/rustc_internal/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use stable_mir::mir::alloc::AllocId;
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
use stable_mir::ty::{
AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
ExistentialTraitRef, FloatTy, GenericArgKind, GenericArgs, IntTy, Region, RigidTy, TraitRef,
Ty, UintTy,
ExistentialTraitRef, FloatTy, GenericArgKind, GenericArgs, IntTy, Region, RigidTy, Span,
TraitRef, Ty, UintTy,
};
use stable_mir::{CrateItem, DefId};

Expand Down Expand Up @@ -279,6 +279,14 @@ impl<'tcx> RustcInternal<'tcx> for AdtDef {
}
}

impl<'tcx> RustcInternal<'tcx> for Span {
type T = rustc_span::Span;

fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
tables[*self]
}
}

impl<'tcx, T> RustcInternal<'tcx> for &T
where
T: RustcInternal<'tcx>,
Expand Down
37 changes: 32 additions & 5 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rustc_hir::def::DefKind;
use rustc_middle::mir;
use rustc_middle::mir::interpret::{alloc_range, AllocId};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
use rustc_middle::ty::{self, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, Variance};
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_target::abi::FieldIdx;
Expand All @@ -28,7 +29,7 @@ use stable_mir::ty::{
EarlyParamRegion, FloatTy, FnDef, GenericArgs, GenericParamDef, IntTy, LineInfo, Movability,
RigidTy, Span, TyKind, UintTy,
};
use stable_mir::{self, opaque, Context, CrateItem, Error, Filename, ItemKind};
use stable_mir::{self, opaque, Context, Crate, CrateItem, Error, Filename, ItemKind, Symbol};
use std::cell::RefCell;
use tracing::debug;

Expand Down Expand Up @@ -61,9 +62,18 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
crates
}

fn name_of_def_id(&self, def_id: stable_mir::DefId) -> String {
fn def_name(&self, def_id: stable_mir::DefId, trimmed: bool) -> Symbol {
let tables = self.0.borrow();
tables.tcx.def_path_str(tables[def_id])
if trimmed {
with_forced_trimmed_paths!(tables.tcx.def_path_str(tables[def_id]))
} else {
with_no_trimmed_paths!(tables.tcx.def_path_str(tables[def_id]))
}
}

fn krate(&self, def_id: stable_mir::DefId) -> Crate {
let tables = self.0.borrow();
smir_crate(tables.tcx, tables[def_id].krate)
}

fn span_to_string(&self, span: stable_mir::ty::Span) -> String {
Expand Down Expand Up @@ -240,12 +250,29 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.create_def_id(def_id)
}

fn instance_mangled_name(&self, def: InstanceDef) -> String {
fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol {
let tables = self.0.borrow_mut();
let instance = tables.instances[def];
let instance = tables.instances[instance];
tables.tcx.symbol_name(instance).name.to_string()
}

/// Retrieve the instance name for diagnostic messages.
///
/// This will return the specialized name, e.g., `Vec<char>::new`.
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol {
let tables = self.0.borrow_mut();
let instance = tables.instances[def];
if trimmed {
with_forced_trimmed_paths!(
tables.tcx.def_path_str_with_args(instance.def_id(), instance.args)
)
} else {
with_no_trimmed_paths!(
tables.tcx.def_path_str_with_args(instance.def_id(), instance.args)
)
}
}

fn mono_instance(&self, item: stable_mir::CrateItem) -> stable_mir::mir::mono::Instance {
let mut tables = self.0.borrow_mut();
let def_id = tables[item.0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::EvalCtxt;
use super::{EvalCtxt, NestedGoals};
use crate::solve::inspect;
use rustc_middle::traits::query::NoSolution;

Expand All @@ -14,7 +14,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
predefined_opaques_in_body: self.predefined_opaques_in_body,
max_input_universe: self.max_input_universe,
search_graph: self.search_graph,
nested_goals: self.nested_goals.clone(),
nested_goals: NestedGoals::new(),
tainted: self.tainted,
inspect: self.inspect.new_probe(),
};
Expand All @@ -32,7 +32,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
tainted,
inspect,
} = nested_ecx;
self.nested_goals = nested_goals;
self.nested_goals.extend(nested_goals);
self.tainted = tainted;
self.inspect.integrate_snapshot(inspect);
} else {
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ pub(super) struct NestedGoals<'tcx> {
pub(super) goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
}

impl NestedGoals<'_> {
impl<'tcx> NestedGoals<'tcx> {
pub(super) fn new() -> Self {
Self { normalizes_to_hack_goal: None, goals: Vec::new() }
}

pub(super) fn is_empty(&self) -> bool {
self.normalizes_to_hack_goal.is_none() && self.goals.is_empty()
}

pub(super) fn extend(&mut self, other: NestedGoals<'tcx>) {
assert_eq!(other.normalizes_to_hack_goal, None);
self.goals.extend(other.goals)
}
}

#[derive(PartialEq, Eq, Debug, Hash, HashStable, Clone, Copy)]
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_trait_selection/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
}
}

// FIXME(@lcnr): If the normalization of the alias adds an inference constraint which
// causes a previously added goal to fail, then we treat the alias as rigid.
//
// These feels like a potential issue, I should look into writing some tests here
// and then probably changing `commit_if_ok` to not inherit the parent goals.
match self.commit_if_ok(|this| {
let normalized_ty = this.next_ty_infer();
let normalizes_to_goal = Goal::new(
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a> {
let mut ambiguity_cause = None;
for cand in goal.candidates() {
// FIXME: boiiii, using string comparisions here sure is scuffed.
if let inspect::ProbeKind::MiscCandidate { name: "coherence unknowable", result: _ } =
cand.kind()
if let inspect::ProbeKind::MiscCandidate {
name: "coherence unknowable",
result: Ok(_),
} = cand.kind()
{
let lazily_normalize_ty = |ty: Ty<'tcx>| {
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(infcx);
Expand Down
69 changes: 69 additions & 0 deletions compiler/stable_mir/src/crate_def.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//! Module that define a common trait for things that represent a crate definition,
//! such as, a function, a trait, an enum, and any other definitions.

use crate::ty::Span;
use crate::{with, Crate, Symbol};

/// A unique identification number for each item accessible for the current compilation unit.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct DefId(pub(crate) usize);

/// A trait for retrieving information about a particular definition.
///
/// Implementors must provide the implementation of `def_id` which will be used to retrieve
/// information about a crate's definition.
pub trait CrateDef {
/// Retrieve the unique identifier for the current definition.
fn def_id(&self) -> DefId;

/// Return the fully qualified name of the current definition.
fn name(&self) -> Symbol {
let def_id = self.def_id();
with(|cx| cx.def_name(def_id, false))
}

/// Return a trimmed name of this definition.
///
/// This can be used to print more user friendly diagnostic messages.
///
/// If a symbol name can only be imported from one place for a type, and as
/// long as it was not glob-imported anywhere in the current crate, we trim its
/// path and print only the name.
///
/// For example, this function may shorten `std::vec::Vec` to just `Vec`,
/// as long as there is no other `Vec` importable anywhere.
fn trimmed_name(&self) -> Symbol {
let def_id = self.def_id();
with(|cx| cx.def_name(def_id, true))
}

/// Return information about the crate where this definition is declared.
///
/// This will return the crate number and its name.
fn krate(&self) -> Crate {
let def_id = self.def_id();
with(|cx| cx.krate(def_id))
}

/// Return the span of this definition.
fn span(&self) -> Span {
let def_id = self.def_id();
with(|cx| cx.span_of_an_item(def_id))
}
}

macro_rules! crate_def {
( $(#[$attr:meta])*
$vis:vis $name:ident $(;)?
) => {
$(#[$attr])*
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
$vis struct $name(pub DefId);

impl CrateDef for $name {
fn def_id(&self) -> DefId {
self.0
}
}
};
}
Loading

0 comments on commit 42ae1a7

Please sign in to comment.