Skip to content

Commit

Permalink
Auto merge of #127831 - tgross35:rollup-c0j9n7b, r=tgross35
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #124033 (Sync ar_archive_writer to LLVM 18.1.3)
 - #126699 (Delegation: support coercion for target expression)
 - #126762 (Deny keyword lifetimes pre-expansion)
 - #126967 (Promote the `wasm32-wasip2` target to Tier 2)
 - #127390 (Migrate `raw-dylib-inline-cross-dylib` and `raw-dylib-custom-dlltool` `run-make` tests to rmake)
 - #127501 (Invert infer `error_reporting` mod struture)
 - #127816 (Update method name to reflect changes to its internals)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 16, 2024
2 parents 032be6f + 7d534dd commit 7d356eb
Show file tree
Hide file tree
Showing 87 changed files with 1,429 additions and 338 deletions.
172 changes: 166 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ checksum = "d67af77d68a931ecd5cbd8a3b5987d63a1d1d1278f7f6a60ae33db485cdebb69"

[[package]]
name = "ar_archive_writer"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c269894b6fe5e9d7ada0cf69b5bf847ff35bc25fc271f08e1d080fce80339a"
checksum = "f8412a2d690663356cba5a2532f3ed55d1e8090743bc6695b88403b27df67733"
dependencies = [
"object 0.32.2",
"object 0.35.0",
]

[[package]]
Expand Down Expand Up @@ -1682,6 +1682,7 @@ dependencies = [
"compiler_builtins",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
"serde",
]

[[package]]
Expand Down Expand Up @@ -1891,6 +1892,12 @@ dependencies = [
"syn 2.0.67",
]

[[package]]
name = "id-arena"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"

[[package]]
name = "ident_case"
version = "1.0.1"
Expand Down Expand Up @@ -2120,6 +2127,12 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"

[[package]]
name = "lexopt"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"

[[package]]
name = "libc"
version = "0.2.155"
Expand Down Expand Up @@ -2634,7 +2647,7 @@ dependencies = [
"indexmap",
"memchr",
"ruzstd 0.5.0",
"wasmparser",
"wasmparser 0.118.2",
]

[[package]]
Expand All @@ -2648,6 +2661,15 @@ dependencies = [
"ruzstd 0.6.0",
]

[[package]]
name = "object"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e"
dependencies = [
"memchr",
]

[[package]]
name = "object"
version = "0.36.0"
Expand Down Expand Up @@ -3436,7 +3458,7 @@ dependencies = [
"object 0.34.0",
"regex",
"similar",
"wasmparser",
"wasmparser 0.118.2",
]

[[package]]
Expand Down Expand Up @@ -3823,7 +3845,7 @@ dependencies = [
"thin-vec",
"thorin-dwp",
"tracing",
"wasm-encoder",
"wasm-encoder 0.200.0",
"windows",
]

Expand Down Expand Up @@ -5267,6 +5289,15 @@ dependencies = [
"color-eyre",
]

[[package]]
name = "spdx"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc"
dependencies = [
"smallvec",
]

[[package]]
name = "spdx-expression"
version = "0.5.2"
Expand Down Expand Up @@ -6315,6 +6346,28 @@ version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"

[[package]]
name = "wasm-component-ld"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "314d932d5e84c9678751b85498b1482b2f32f185744e449d3ce0b1d400376dad"
dependencies = [
"anyhow",
"clap",
"lexopt",
"tempfile",
"wasmparser 0.210.0",
"wat",
"wit-component",
]

[[package]]
name = "wasm-component-ld-wrapper"
version = "0.1.0"
dependencies = [
"wasm-component-ld",
]

[[package]]
name = "wasm-encoder"
version = "0.200.0"
Expand All @@ -6324,6 +6377,40 @@ dependencies = [
"leb128",
]

[[package]]
name = "wasm-encoder"
version = "0.210.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e3764d9d6edabd8c9e16195e177be0d20f6ab942ad18af52860f12f82bc59a"
dependencies = [
"leb128",
]

[[package]]
name = "wasm-encoder"
version = "0.211.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e7d931a1120ef357f32b74547646b6fa68ea25e377772b72874b131a9ed70d4"
dependencies = [
"leb128",
]

[[package]]
name = "wasm-metadata"
version = "0.210.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "012729d1294907fcb0866f08460ab95426a6d0b176a599619b84cac7653452b4"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder 0.210.0",
"wasmparser 0.210.0",
]

[[package]]
name = "wasmparser"
version = "0.118.2"
Expand All @@ -6334,6 +6421,42 @@ dependencies = [
"semver",
]

[[package]]
name = "wasmparser"
version = "0.210.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7bbcd21e7581619d9f6ca00f8c4f08f1cacfe58bf63f83af57cd0476f1026f5"
dependencies = [
"ahash",
"bitflags 2.5.0",
"hashbrown",
"indexmap",
"semver",
"serde",
]

[[package]]
name = "wast"
version = "211.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b25506dd82d00da6b14a87436b3d52b1d264083fa79cdb72a0d1b04a8595ccaa"
dependencies = [
"bumpalo",
"leb128",
"memchr",
"unicode-width",
"wasm-encoder 0.211.1",
]

[[package]]
name = "wat"
version = "1.211.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb716ca6c86eecac2d82541ffc39860118fc0af9309c4f2670637bea2e1bdd7d"
dependencies = [
"wast",
]

[[package]]
name = "winapi"
version = "0.3.9"
Expand Down Expand Up @@ -6561,6 +6684,43 @@ dependencies = [
"memchr",
]

[[package]]
name = "wit-component"
version = "0.210.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a450bdb5d032acf1fa0865451fa0c6f50e62f2d31eaa8dba967c2e2d068694a4"
dependencies = [
"anyhow",
"bitflags 2.5.0",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder 0.210.0",
"wasm-metadata",
"wasmparser 0.210.0",
"wit-parser",
]

[[package]]
name = "wit-parser"
version = "0.210.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a965cbd439af19a4b44a54a97ab8957d86f02d01320efc9e31c1d3605c6710"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"wasmparser 0.210.0",
]

[[package]]
name = "writeable"
version = "0.5.5"
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ members = [
"src/tools/opt-dist",
"src/tools/coverage-dump",
"src/tools/rustc-perf-wrapper",
"src/tools/wasm-component-ld",
]

exclude = [
Expand Down Expand Up @@ -104,6 +105,9 @@ rustc-demangle.debug = 0
[profile.release.package.lld-wrapper]
debug = 0
strip = true
[profile.release.package.wasm-component-ld-wrapper]
debug = 0
strip = true

[patch.crates-io]
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
Expand Down
84 changes: 69 additions & 15 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

use crate::{ImplTraitPosition, ResolverAstLoweringExt};

use super::{ImplTraitContext, LoweringContext, ParamMode};
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};

use ast::visit::Visitor;
use hir::def::{DefKind, PartialRes, Res};
Expand Down Expand Up @@ -259,8 +259,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self_param_id: pat_node_id,
};
self_resolver.visit_block(block);
let block = this.lower_block(block, false);
this.mk_expr(hir::ExprKind::Block(block, None), block.span)
this.lower_target_expr(&block)
} else {
let pat_hir_id = this.lower_node_id(pat_node_id);
this.generate_arg(pat_hir_id, span)
Expand All @@ -273,26 +272,81 @@ impl<'hir> LoweringContext<'_, 'hir> {
})
}

// Generates fully qualified call for the resulting body.
// FIXME(fn_delegation): Alternatives for target expression lowering:
// https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2197170600.
fn lower_target_expr(&mut self, block: &Block) -> hir::Expr<'hir> {
if block.stmts.len() == 1
&& let StmtKind::Expr(expr) = &block.stmts[0].kind
{
return self.lower_expr_mut(expr);
}

let block = self.lower_block(block, false);
self.mk_expr(hir::ExprKind::Block(block, None), block.span)
}

// Generates expression for the resulting body. If possible, `MethodCall` is used
// to allow autoref/autoderef for target expression. For example in:
//
// trait Trait : Sized {
// fn by_value(self) -> i32 { 1 }
// fn by_mut_ref(&mut self) -> i32 { 2 }
// fn by_ref(&self) -> i32 { 3 }
// }
//
// struct NewType(SomeType);
// impl Trait for NewType {
// reuse Trait::* { self.0 }
// }
//
// `self.0` will automatically coerce.
fn finalize_body_lowering(
&mut self,
delegation: &Delegation,
args: Vec<hir::Expr<'hir>>,
span: Span,
) -> hir::Expr<'hir> {
let path = self.lower_qpath(
delegation.id,
&delegation.qself,
&delegation.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);

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 has_generic_args =
delegation.path.segments.iter().rev().skip(1).any(|segment| segment.args.is_some());

let call = if self
.get_resolution_id(delegation.id, span)
.and_then(|def_id| Ok(self.has_self(def_id, span)))
.unwrap_or_default()
&& delegation.qself.is_none()
&& !has_generic_args
{
let ast_segment = delegation.path.segments.last().unwrap();
let segment = self.lower_path_segment(
delegation.path.span,
ast_segment,
ParamMode::Optional,
ParenthesizedGenericArgs::Err,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
let segment = self.arena.alloc(segment);

self.arena.alloc(hir::Expr {
hir_id: self.next_id(),
kind: hir::ExprKind::MethodCall(segment, &args[0], &args[1..], span),
span,
})
} else {
let path = self.lower_qpath(
delegation.id,
&delegation.qself,
&delegation.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);

let callee_path = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(path), span));
self.arena.alloc(self.mk_expr(hir::ExprKind::Call(callee_path, args), span))
};
let block = self.arena.alloc(hir::Block {
stmts: &[],
expr: Some(call),
Expand Down
Loading

0 comments on commit 7d356eb

Please sign in to comment.