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 7 pull requests #126950

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8cfd4b1
Unify the precedence level for PREC_POSTFIX and PREC_PAREN
dtolnay Jun 24, 2024
273447c
Rename the 2 unambiguous precedence levels to PREC_UNAMBIGUOUS
dtolnay Jun 24, 2024
572ae3b
rustc_data_structures: Use portable AtomicU64 on 32-bit SPARC
glaubitz Jun 24, 2024
dc8ac3e
rustc_llvm: Link against libatomic on 32-bit SPARC
glaubitz Jun 24, 2024
8f7175c
bootstrap: Link against libatomic on 32-bit SPARC
glaubitz Jun 24, 2024
a194f42
rustc_target: Rewrite sparc_unknown_linux_gnu spec to use TargetOptions
glaubitz Jun 24, 2024
e57bbb3
rustc_target: Build sparc_unknown_linux_gnu with -mcpu=v9 and -m32
glaubitz Jun 24, 2024
c2f1072
Tweak `FlatPat::new` to avoid a temporarily-invalid state
Zalathar Jun 25, 2024
2e017f4
set `on-broken-pipe` in `prepare_cargo_tool`
onur-ozkan Jun 25, 2024
604caa0
De-duplicate all consecutive native libs regardless of their options
Urgau Jun 25, 2024
c7b579a
Add missing slash in const_eval_select doc comment
cyrgani Jun 25, 2024
d30d85f
Delegation: ast lowering refactor
Bryanskiy Jun 25, 2024
e8cd125
Rollup merge of #126893 - dtolnay:prec, r=compiler-errors
compiler-errors Jun 25, 2024
296e0b8
Rollup merge of #126907 - glaubitz:sparc-fixes, r=nagisa
compiler-errors Jun 25, 2024
a9a4777
Rollup merge of #126932 - Zalathar:flat-pat, r=Nadrieril
compiler-errors Jun 25, 2024
f0339ac
Rollup merge of #126934 - onur-ozkan:broken-build-cache, r=Kobzol
compiler-errors Jun 25, 2024
095645c
Rollup merge of #126943 - Urgau:dedup-all, r=petrochenkov
compiler-errors Jun 25, 2024
985b3a3
Rollup merge of #126946 - cyrgani:patch-1, r=compiler-errors
compiler-errors Jun 25, 2024
6d0bb34
Rollup merge of #126947 - Bryanskiy:delegation-lowering-refactoring, …
compiler-errors Jun 25, 2024
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
45 changes: 21 additions & 24 deletions compiler/rustc_ast/src/util/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ pub const PREC_JUMP: i8 = -30;
pub const PREC_RANGE: i8 = -10;
// The range 2..=14 is reserved for AssocOp binary operator precedences.
pub const PREC_PREFIX: i8 = 50;
pub const PREC_POSTFIX: i8 = 60;
pub const PREC_PAREN: i8 = 99;
pub const PREC_UNAMBIGUOUS: i8 = 60;
pub const PREC_FORCE_PAREN: i8 = 100;

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -325,37 +324,35 @@ impl ExprPrecedence {
| ExprPrecedence::Let
| ExprPrecedence::Unary => PREC_PREFIX,

// Unary, postfix
ExprPrecedence::Await
// Never need parens
ExprPrecedence::Array
| ExprPrecedence::Await
| ExprPrecedence::Block
| ExprPrecedence::Call
| ExprPrecedence::MethodCall
| ExprPrecedence::ConstBlock
| ExprPrecedence::Field
| ExprPrecedence::ForLoop
| ExprPrecedence::FormatArgs
| ExprPrecedence::Gen
| ExprPrecedence::If
| ExprPrecedence::Index
| ExprPrecedence::Try
| ExprPrecedence::InlineAsm
| ExprPrecedence::Lit
| ExprPrecedence::Loop
| ExprPrecedence::Mac
| ExprPrecedence::FormatArgs
| ExprPrecedence::Match
| ExprPrecedence::MethodCall
| ExprPrecedence::OffsetOf
| ExprPrecedence::PostfixMatch => PREC_POSTFIX,

// Never need parens
ExprPrecedence::Array
| ExprPrecedence::Paren
| ExprPrecedence::Path
| ExprPrecedence::PostfixMatch
| ExprPrecedence::Repeat
| ExprPrecedence::Struct
| ExprPrecedence::Try
| ExprPrecedence::TryBlock
| ExprPrecedence::Tup
| ExprPrecedence::Lit
| ExprPrecedence::Path
| ExprPrecedence::Paren
| ExprPrecedence::If
| ExprPrecedence::While
| ExprPrecedence::ForLoop
| ExprPrecedence::Loop
| ExprPrecedence::Match
| ExprPrecedence::ConstBlock
| ExprPrecedence::Block
| ExprPrecedence::TryBlock
| ExprPrecedence::Gen
| ExprPrecedence::Struct
| ExprPrecedence::Err => PREC_PAREN,
| ExprPrecedence::Err => PREC_UNAMBIGUOUS,
}
}
}
Expand Down
107 changes: 49 additions & 58 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
let Ok(sig_id) = sig_id else {
return false;
};
if let Some(local_sig_id) = sig_id.as_local() {
self.has_self(sig_id, span)
}

fn has_self(&self, def_id: DefId, span: Span) -> bool {
if let Some(local_sig_id) = def_id.as_local() {
// The value may be missing due to recursive delegation.
// Error will be emmited later during HIR ty lowering.
self.resolver.delegation_fn_sigs.get(&local_sig_id).map_or(false, |sig| sig.has_self)
} else {
match self.tcx.def_kind(sig_id) {
match self.tcx.def_kind(def_id) {
DefKind::Fn => false,
DefKind::AssocFn => self.tcx.associated_item(sig_id).fn_has_self_parameter,
DefKind::AssocFn => self.tcx.associated_item(def_id).fn_has_self_parameter,
_ => span_bug!(span, "unexpected DefKind for delegation item"),
}
}
Expand Down Expand Up @@ -107,12 +111,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
span: Span,
) -> Result<DefId, ErrorGuaranteed> {
let sig_id = if self.is_in_trait_impl { item_id } else { path_id };
let sig_id =
self.resolver.get_partial_res(sig_id).and_then(|r| r.expect_full_res().opt_def_id());
sig_id.ok_or_else(|| {
self.tcx
.dcx()
.span_delayed_bug(span, "LoweringContext: couldn't resolve delegation item")
self.get_resolution_id(sig_id, span)
}

fn get_resolution_id(&self, node_id: NodeId, span: Span) -> Result<DefId, ErrorGuaranteed> {
let def_id =
self.resolver.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
def_id.ok_or_else(|| {
self.tcx.dcx().span_delayed_bug(
span,
format!("LoweringContext: couldn't resolve node {:?} in delegation item", node_id),
)
})
}

Expand All @@ -122,7 +131,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
predicates: &[],
has_where_clause_predicates: false,
where_clause_span: span,
span: span,
span,
})
}

Expand Down Expand Up @@ -222,12 +231,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}));

let path = self.arena.alloc(hir::Path { span, res: Res::Local(param_id), segments });

hir::Expr {
hir_id: self.next_id(),
kind: hir::ExprKind::Path(hir::QPath::Resolved(None, path)),
span,
}
self.mk_expr(hir::ExprKind::Path(hir::QPath::Resolved(None, path)), span)
}

fn lower_delegation_body(
Expand All @@ -236,19 +240,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
param_count: usize,
span: Span,
) -> BodyId {
let path = self.lower_qpath(
delegation.id,
&delegation.qself,
&delegation.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
let block = delegation.body.as_deref();

self.lower_body(|this| {
let mut parameters: Vec<hir::Param<'_>> = Vec::new();
let mut args: Vec<hir::Expr<'hir>> = Vec::new();
let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count);
let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count);

for idx in 0..param_count {
let (param, pat_node_id) = this.generate_param(span);
Expand All @@ -264,55 +260,49 @@ impl<'hir> LoweringContext<'_, 'hir> {
};
self_resolver.visit_block(block);
let block = this.lower_block(block, false);
hir::Expr {
hir_id: this.next_id(),
kind: hir::ExprKind::Block(block, None),
span: block.span,
}
this.mk_expr(hir::ExprKind::Block(block, None), block.span)
} else {
let pat_hir_id = this.lower_node_id(pat_node_id);
this.generate_arg(pat_hir_id, span)
};
args.push(arg);
}

let args = self.arena.alloc_from_iter(args);
let final_expr = this.generate_call(path, args);
let final_expr = this.finalize_body_lowering(delegation, args, span);
(this.arena.alloc_from_iter(parameters), final_expr)
})
}

fn generate_call(
// Generates fully qualified call for the resulting body.
fn finalize_body_lowering(
&mut self,
path: hir::QPath<'hir>,
args: &'hir [hir::Expr<'hir>],
delegation: &Delegation,
args: Vec<hir::Expr<'hir>>,
span: Span,
) -> hir::Expr<'hir> {
let callee = self.arena.alloc(hir::Expr {
hir_id: self.next_id(),
kind: hir::ExprKind::Path(path),
span: path.span(),
});
let path = self.lower_qpath(
delegation.id,
&delegation.qself,
&delegation.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);

let expr = self.arena.alloc(hir::Expr {
hir_id: self.next_id(),
kind: hir::ExprKind::Call(callee, args),
span: path.span(),
});
let args = self.arena.alloc_from_iter(args);
let path_expr = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(path), span));
let call = self.arena.alloc(self.mk_expr(hir::ExprKind::Call(path_expr, args), span));

let block = self.arena.alloc(hir::Block {
stmts: &[],
expr: Some(expr),
expr: Some(call),
hir_id: self.next_id(),
rules: hir::BlockCheckMode::DefaultBlock,
span: path.span(),
span,
targeted_by_break: false,
});

hir::Expr {
hir_id: self.next_id(),
kind: hir::ExprKind::Block(block, None),
span: path.span(),
}
self.mk_expr(hir::ExprKind::Block(block, None), span)
}

fn generate_delegation_error(
Expand All @@ -333,11 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let header = self.generate_header_error();
let sig = hir::FnSig { decl, header, span };

let body_id = self.lower_body(|this| {
let expr =
hir::Expr { hir_id: this.next_id(), kind: hir::ExprKind::Err(err), span: span };
(&[], expr)
});
let body_id = self.lower_body(|this| (&[], this.mk_expr(hir::ExprKind::Err(err), span)));
DelegationResults { generics, body_id, sig }
}

Expand All @@ -349,6 +335,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
abi: abi::Abi::Rust,
}
}

#[inline]
fn mk_expr(&mut self, kind: hir::ExprKind<'hir>, span: Span) -> hir::Expr<'hir> {
hir::Expr { hir_id: self.next_id(), kind, span }
}
}

struct SelfResolver<'a> {
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<'a> State<'a> {
fn print_expr_call(&mut self, func: &ast::Expr, args: &[P<ast::Expr>], fixup: FixupContext) {
let prec = match func.kind {
ast::ExprKind::Field(..) => parser::PREC_FORCE_PAREN,
_ => parser::PREC_POSTFIX,
_ => parser::PREC_UNAMBIGUOUS,
};

// Independent of parenthesization related to precedence, we must
Expand Down Expand Up @@ -257,7 +257,7 @@ impl<'a> State<'a> {
// boundaries, `$receiver.method()` can be parsed back as a statement
// containing an expression if and only if `$receiver` can be parsed as
// a statement containing an expression.
self.print_expr_maybe_paren(receiver, parser::PREC_POSTFIX, fixup);
self.print_expr_maybe_paren(receiver, parser::PREC_UNAMBIGUOUS, fixup);

self.word(".");
self.print_ident(segment.ident);
Expand Down Expand Up @@ -489,7 +489,7 @@ impl<'a> State<'a> {
self.space();
}
MatchKind::Postfix => {
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
self.print_expr_maybe_paren(expr, parser::PREC_UNAMBIGUOUS, fixup);
self.word_nbsp(".match");
}
}
Expand Down Expand Up @@ -549,7 +549,7 @@ impl<'a> State<'a> {
self.print_block_with_attrs(blk, attrs);
}
ast::ExprKind::Await(expr, _) => {
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
self.print_expr_maybe_paren(expr, parser::PREC_UNAMBIGUOUS, fixup);
self.word(".await");
}
ast::ExprKind::Assign(lhs, rhs, _) => {
Expand All @@ -568,14 +568,14 @@ impl<'a> State<'a> {
self.print_expr_maybe_paren(rhs, prec, fixup.subsequent_subexpression());
}
ast::ExprKind::Field(expr, ident) => {
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
self.print_expr_maybe_paren(expr, parser::PREC_UNAMBIGUOUS, fixup);
self.word(".");
self.print_ident(*ident);
}
ast::ExprKind::Index(expr, index, _) => {
self.print_expr_maybe_paren(
expr,
parser::PREC_POSTFIX,
parser::PREC_UNAMBIGUOUS,
fixup.leftmost_subexpression(),
);
self.word("[");
Expand Down Expand Up @@ -713,7 +713,7 @@ impl<'a> State<'a> {
}
}
ast::ExprKind::Try(e) => {
self.print_expr_maybe_paren(e, parser::PREC_POSTFIX, fixup);
self.print_expr_maybe_paren(e, parser::PREC_UNAMBIGUOUS, fixup);
self.word("?")
}
ast::ExprKind::TryBlock(blk) => {
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,11 +1490,6 @@ fn print_native_static_libs(
let mut lib_args: Vec<_> = all_native_libs
.iter()
.filter(|l| relevant_lib(sess, l))
// Deduplication of successive repeated libraries, see rust-lang/rust#113209
//
// note: we don't use PartialEq/Eq because NativeLib transitively depends on local
// elements like spans, which we don't care about and would make the deduplication impossible
.dedup_by(|l1, l2| l1.name == l2.name && l1.kind == l2.kind && l1.verbatim == l2.verbatim)
.filter_map(|lib| {
let name = lib.name;
match lib.kind {
Expand All @@ -1521,6 +1516,8 @@ fn print_native_static_libs(
| NativeLibKind::RawDylib => None,
}
})
// deduplication of consecutive repeated libraries, see rust-lang/rust#113209
.dedup()
.collect();
for path in all_rust_dylibs {
// FIXME deduplicate with add_dynamic_crate
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ libc = "0.2"
memmap2 = "0.2.1"
# tidy-alphabetical-end

[target.'cfg(any(target_arch = "powerpc", target_arch = "mips"))'.dependencies]
[target.'cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))'.dependencies]
portable-atomic = "1.5.1"

[features]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_data_structures/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ cfg_match! {
[crate::owned_slice::OwnedSlice]
);

// PowerPC and MIPS platforms with 32-bit pointers do not
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
// have AtomicU64 type.
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc", target_arch = "sparc")))]
already_sync!(
[std::sync::atomic::AtomicU64]
);

#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
already_sync!(
[portable_atomic::AtomicU64]
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ cfg_match! {

pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32};

// PowerPC and MIPS platforms with 32-bit pointers do not
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
// have AtomicU64 type.
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc")))]
pub use std::sync::atomic::AtomicU64;

#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
pub use portable_atomic::AtomicU64;

pub use std::sync::Arc as Lrc;
Expand Down
Loading
Loading