Skip to content

Commit

Permalink
Auto merge of rust-lang#102061 - notriddle:rollup-kwu9vp8, r=notriddle
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

Successful merges:

 - rust-lang#100250 (Manually cleanup token stream when macro expansion aborts.)
 - rust-lang#101014 (Fix -Zmeta-stats ICE by giving `FileEncoder` file read permissions)
 - rust-lang#101958 (Improve error for when query is unsupported by crate)
 - rust-lang#101976 (MirPhase: clarify that linting is not a semantic change)
 - rust-lang#102001 (Use LLVM C-API to build atomic cmpxchg and fence)
 - rust-lang#102008 (Add GUI test for notable traits element position)
 - rust-lang#102013 (Simplify rpitit handling on lower_fn_decl)
 - rust-lang#102021 (some post-valtree cleanup)
 - rust-lang#102027 (rustdoc: remove `docblock` class from `item-decl`)
 - rust-lang#102034 (rustdoc: remove no-op CSS `h1-6 { border-bottom-color }`)
 - rust-lang#102038 (Make the `normalize-overflow` rustdoc test actually do something)
 - rust-lang#102053 (:arrow_up: rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 20, 2022
2 parents cd8cc91 + 25f5483 commit 432abd8
Show file tree
Hide file tree
Showing 131 changed files with 1,984 additions and 1,016 deletions.
60 changes: 15 additions & 45 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,10 @@ enum FnDeclKind {
}

impl FnDeclKind {
fn impl_trait_return_allowed(&self, tcx: TyCtxt<'_>) -> bool {
fn impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {
match self {
FnDeclKind::Fn | FnDeclKind::Inherent => true,
FnDeclKind::Impl if tcx.features().return_position_impl_trait_in_trait => true,
_ => false,
}
}

fn impl_trait_in_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {
match self {
FnDeclKind::Trait if tcx.features().return_position_impl_trait_in_trait => true,
_ => false,
}
Expand Down Expand Up @@ -1698,9 +1692,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}));

let output = if let Some((ret_id, span)) = make_ret_async {
match kind {
FnDeclKind::Trait => {
if !kind.impl_trait_in_trait_allowed(self.tcx) {
if !kind.impl_trait_allowed(self.tcx) {
match kind {
FnDeclKind::Trait | FnDeclKind::Impl => {
self.tcx
.sess
.create_feature_err(
Expand All @@ -1709,51 +1703,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
.emit();
}
self.lower_async_fn_ret_ty(
&decl.output,
fn_node_id.expect("`make_ret_async` but no `fn_def_id`"),
ret_id,
true,
)
}
_ => {
if !kind.impl_trait_return_allowed(self.tcx) {
if kind == FnDeclKind::Impl {
self.tcx
.sess
.create_feature_err(
TraitFnAsync { fn_span, span },
sym::return_position_impl_trait_in_trait,
)
.emit();
} else {
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
}
_ => {
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
}
self.lower_async_fn_ret_ty(
&decl.output,
fn_node_id.expect("`make_ret_async` but no `fn_def_id`"),
ret_id,
false,
)
}
}

self.lower_async_fn_ret_ty(
&decl.output,
fn_node_id.expect("`make_ret_async` but no `fn_def_id`"),
ret_id,
matches!(kind, FnDeclKind::Trait),
)
} else {
match decl.output {
FnRetTy::Ty(ref ty) => {
let mut context = match fn_node_id {
Some(fn_node_id) if kind.impl_trait_return_allowed(self.tcx) => {
let fn_def_id = self.local_def_id(fn_node_id);
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
in_trait: false,
}
}
Some(fn_node_id) if kind.impl_trait_in_trait_allowed(self.tcx) => {
Some(fn_node_id) if kind.impl_trait_allowed(self.tcx) => {
let fn_def_id = self.local_def_id(fn_node_id);
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
in_trait: true,
in_trait: matches!(kind, FnDeclKind::Trait),
}
}
_ => ImplTraitContext::Disallowed(match kind {
Expand Down
64 changes: 36 additions & 28 deletions compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_ast::visit::Visitor;
use rustc_ast::NodeId;
use rustc_ast::{mut_visit, visit};
use rustc_ast::{Attribute, HasAttrs, HasTokens};
use rustc_errors::PResult;
use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_expand::config::StripUnconfigured;
use rustc_expand::configure;
Expand Down Expand Up @@ -144,33 +145,34 @@ impl CfgEval<'_, '_> {
// the location of `#[cfg]` and `#[cfg_attr]` in the token stream. The tokenization
// process is lossless, so this process is invisible to proc-macros.

let parse_annotatable_with: fn(&mut Parser<'_>) -> _ = match annotatable {
Annotatable::Item(_) => {
|parser| Annotatable::Item(parser.parse_item(ForceCollect::Yes).unwrap().unwrap())
}
Annotatable::TraitItem(_) => |parser| {
Annotatable::TraitItem(
parser.parse_trait_item(ForceCollect::Yes).unwrap().unwrap().unwrap(),
)
},
Annotatable::ImplItem(_) => |parser| {
Annotatable::ImplItem(
parser.parse_impl_item(ForceCollect::Yes).unwrap().unwrap().unwrap(),
)
},
Annotatable::ForeignItem(_) => |parser| {
Annotatable::ForeignItem(
parser.parse_foreign_item(ForceCollect::Yes).unwrap().unwrap().unwrap(),
)
},
Annotatable::Stmt(_) => |parser| {
Annotatable::Stmt(P(parser.parse_stmt(ForceCollect::Yes).unwrap().unwrap()))
},
Annotatable::Expr(_) => {
|parser| Annotatable::Expr(parser.parse_expr_force_collect().unwrap())
}
_ => unreachable!(),
};
let parse_annotatable_with: for<'a> fn(&mut Parser<'a>) -> PResult<'a, _> =
match annotatable {
Annotatable::Item(_) => {
|parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap()))
}
Annotatable::TraitItem(_) => |parser| {
Ok(Annotatable::TraitItem(
parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(),
))
},
Annotatable::ImplItem(_) => |parser| {
Ok(Annotatable::ImplItem(
parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(),
))
},
Annotatable::ForeignItem(_) => |parser| {
Ok(Annotatable::ForeignItem(
parser.parse_foreign_item(ForceCollect::Yes)?.unwrap().unwrap(),
))
},
Annotatable::Stmt(_) => |parser| {
Ok(Annotatable::Stmt(P(parser.parse_stmt(ForceCollect::Yes)?.unwrap())))
},
Annotatable::Expr(_) => {
|parser| Ok(Annotatable::Expr(parser.parse_expr_force_collect()?))
}
_ => unreachable!(),
};

// 'Flatten' all nonterminals (i.e. `TokenKind::Interpolated`)
// to `None`-delimited groups containing the corresponding tokens. This
Expand All @@ -193,7 +195,13 @@ impl CfgEval<'_, '_> {
let mut parser =
rustc_parse::stream_to_parser(&self.cfg.sess.parse_sess, orig_tokens, None);
parser.capture_cfg = true;
annotatable = parse_annotatable_with(&mut parser);
match parse_annotatable_with(&mut parser) {
Ok(a) => annotatable = a,
Err(mut err) => {
err.emit();
return Some(annotatable);
}
}

// Now that we have our re-parsed `AttrTokenStream`, recursively configuring
// our attribute target will correctly the tokens as well.
Expand Down
26 changes: 16 additions & 10 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::attributes;
use crate::common::Funclet;
use crate::context::CodegenCx;
use crate::llvm::{self, BasicBlock, False};
use crate::llvm::{AtomicOrdering, AtomicRmwBinOp, SynchronizationScope};
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock};
use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
use cstr::cstr;
use libc::{c_char, c_uint};
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, TypeKind};
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind};
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::*;
Expand Down Expand Up @@ -1042,15 +1041,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
) -> &'ll Value {
let weak = if weak { llvm::True } else { llvm::False };
unsafe {
llvm::LLVMRustBuildAtomicCmpXchg(
let value = llvm::LLVMBuildAtomicCmpXchg(
self.llbuilder,
dst,
cmp,
src,
AtomicOrdering::from_generic(order),
AtomicOrdering::from_generic(failure_order),
weak,
)
llvm::False, // SingleThreaded
);
llvm::LLVMSetWeak(value, weak);
value
}
}
fn atomic_rmw(
Expand All @@ -1067,21 +1068,26 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
dst,
src,
AtomicOrdering::from_generic(order),
False,
llvm::False, // SingleThreaded
)
}
}

fn atomic_fence(
&mut self,
order: rustc_codegen_ssa::common::AtomicOrdering,
scope: rustc_codegen_ssa::common::SynchronizationScope,
scope: SynchronizationScope,
) {
let single_threaded = match scope {
SynchronizationScope::SingleThread => llvm::True,
SynchronizationScope::CrossThread => llvm::False,
};
unsafe {
llvm::LLVMRustBuildAtomicFence(
llvm::LLVMBuildFence(
self.llbuilder,
AtomicOrdering::from_generic(order),
SynchronizationScope::from_generic(scope),
single_threaded,
UNNAMED,
);
}
}
Expand Down
36 changes: 9 additions & 27 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,27 +400,6 @@ impl AtomicOrdering {
}
}

/// LLVMRustSynchronizationScope
#[derive(Copy, Clone)]
#[repr(C)]
pub enum SynchronizationScope {
SingleThread,
CrossThread,
}

impl SynchronizationScope {
pub fn from_generic(sc: rustc_codegen_ssa::common::SynchronizationScope) -> Self {
match sc {
rustc_codegen_ssa::common::SynchronizationScope::SingleThread => {
SynchronizationScope::SingleThread
}
rustc_codegen_ssa::common::SynchronizationScope::CrossThread => {
SynchronizationScope::CrossThread
}
}
}
}

/// LLVMRustFileType
#[derive(Copy, Clone)]
#[repr(C)]
Expand Down Expand Up @@ -1782,16 +1761,18 @@ extern "C" {
Order: AtomicOrdering,
) -> &'a Value;

pub fn LLVMRustBuildAtomicCmpXchg<'a>(
pub fn LLVMBuildAtomicCmpXchg<'a>(
B: &Builder<'a>,
LHS: &'a Value,
CMP: &'a Value,
RHS: &'a Value,
Order: AtomicOrdering,
FailureOrder: AtomicOrdering,
Weak: Bool,
SingleThreaded: Bool,
) -> &'a Value;

pub fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);

pub fn LLVMBuildAtomicRMW<'a>(
B: &Builder<'a>,
Op: AtomicRmwBinOp,
Expand All @@ -1801,11 +1782,12 @@ extern "C" {
SingleThreaded: Bool,
) -> &'a Value;

pub fn LLVMRustBuildAtomicFence(
B: &Builder<'_>,
pub fn LLVMBuildFence<'a>(
B: &Builder<'a>,
Order: AtomicOrdering,
Scope: SynchronizationScope,
);
SingleThreaded: Bool,
Name: *const c_char,
) -> &'a Value;

/// Writes a module to the specified path. Returns 0 on success.
pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/const_eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
val: mir::ConstantKind<'tcx>,
) -> InterpResult<'tcx, mir::DestructuredMirConstant<'tcx>> {
) -> InterpResult<'tcx, mir::DestructuredConstant<'tcx>> {
trace!("destructure_mir_constant: {:?}", val);
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
let op = ecx.mir_const_to_op(&val, None)?;
let op = ecx.const_to_op(&val, None)?;

// We go to `usize` as we cannot allocate anything bigger anyway.
let (field_count, variant, down) = match val.ty().kind() {
Expand All @@ -129,7 +129,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
.collect::<InterpResult<'tcx, Vec<_>>>()?;
let fields = tcx.arena.alloc_from_iter(fields_iter);

Ok(mir::DestructuredMirConstant { variant, fields })
Ok(mir::DestructuredConstant { variant, fields })
}

#[instrument(skip(tcx), level = "debug")]
Expand All @@ -139,7 +139,7 @@ pub(crate) fn deref_mir_constant<'tcx>(
val: mir::ConstantKind<'tcx>,
) -> mir::ConstantKind<'tcx> {
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
let op = ecx.mir_const_to_op(&val, None).unwrap();
let op = ecx.const_to_op(&val, None).unwrap();
let mplace = ecx.deref_operand(&op).unwrap();
if let Some(alloc_id) = mplace.ptr.provenance {
assert_eq!(
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.stack_mut().push(frame);

// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
for const_ in &body.required_consts {
let span = const_.span;
let const_ =
self.subst_from_current_frame_and_normalize_erasing_regions(const_.literal)?;
self.mir_const_to_op(&const_, None).map_err(|err| {
for ct in &body.required_consts {
let span = ct.span;
let ct = self.subst_from_current_frame_and_normalize_erasing_regions(ct.literal)?;
self.const_to_op(&ct, None).map_err(|err| {
// If there was an error, set the span of the current frame to this constant.
// Avoiding doing this when evaluation succeeds.
self.frame_mut().loc = Err(span);
Expand Down
Loading

0 comments on commit 432abd8

Please sign in to comment.