Skip to content

Commit 5323cbc

Browse files
committed
Auto merge of #149163 - matthiaskrgr:rollup-4tjqj8v, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #149043 ( rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution) - #149134 (std: sys: net: uefi: Implement read_vectored) - #149135 (Constify `residual_into_try_type`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5f7653d + ea8ca21 commit 5323cbc

File tree

13 files changed

+189
-23
lines changed

13 files changed

+189
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,6 +3336,7 @@ dependencies = [
33363336
"libc",
33373337
"object 0.37.3",
33383338
"regex",
3339+
"rustdoc-json-types",
33393340
"serde_json",
33403341
"similar",
33413342
"wasmparser 0.236.1",

library/core/src/ops/try_trait.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,14 @@ pub const trait Residual<O>: Sized {
371371
/// but importantly not on the contextual type the way it would be if
372372
/// we called `<_ as FromResidual>::from_residual(r)` directly.
373373
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
374+
#[rustc_const_unstable(feature = "const_try_residual", issue = "91285")]
374375
// needs to be `pub` to avoid `private type` errors
375376
#[expect(unreachable_pub)]
376377
#[inline] // FIXME: force would be nice, but fails -- see #148915
377378
#[lang = "into_try_type"]
378-
pub fn residual_into_try_type<R: Residual<O>, O>(r: R) -> <R as Residual<O>>::TryType {
379+
pub const fn residual_into_try_type<R: [const] Residual<O>, O>(
380+
r: R,
381+
) -> <R as Residual<O>>::TryType {
379382
FromResidual::from_residual(r)
380383
}
381384

library/std/src/sys/net/connection/uefi/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ impl TcpStream {
6969
}
7070

7171
pub fn read_vectored(&self, buf: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
72-
// FIXME: UEFI does support vectored read, so implement that.
73-
crate::io::default_read_vectored(|b| self.read(b), buf)
72+
self.inner.read_vectored(buf, self.read_timeout()?)
7473
}
7574

7675
pub fn is_read_vectored(&self) -> bool {
77-
false
76+
true
7877
}
7978

8079
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {

library/std/src/sys/net/connection/uefi/tcp.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::tcp4;
2-
use crate::io::{self, IoSlice};
2+
use crate::io::{self, IoSlice, IoSliceMut};
33
use crate::net::SocketAddr;
44
use crate::ptr::NonNull;
55
use crate::sys::{helpers, unsupported};
@@ -44,6 +44,16 @@ impl Tcp {
4444
}
4545
}
4646

47+
pub(crate) fn read_vectored(
48+
&self,
49+
buf: &mut [IoSliceMut<'_>],
50+
timeout: Option<Duration>,
51+
) -> io::Result<usize> {
52+
match self {
53+
Self::V4(client) => client.read_vectored(buf, timeout),
54+
}
55+
}
56+
4757
pub(crate) fn ttl(&self) -> io::Result<u32> {
4858
match self {
4959
Self::V4(client) => client.get_mode_data().map(|x| x.time_to_live.into()),

library/std/src/sys/net/connection/uefi/tcp4.rs

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use r_efi::efi::{self, Status};
22
use r_efi::protocols::tcp4;
33

4-
use crate::io::{self, IoSlice};
4+
use crate::io::{self, IoSlice, IoSliceMut};
55
use crate::net::SocketAddrV4;
66
use crate::ptr::NonNull;
77
use crate::sync::atomic::{AtomicBool, Ordering};
@@ -193,30 +193,74 @@ impl Tcp4 {
193193
}
194194

195195
pub(crate) fn read(&self, buf: &mut [u8], timeout: Option<Duration>) -> io::Result<usize> {
196-
let evt = unsafe { self.create_evt() }?;
197-
let completion_token =
198-
tcp4::CompletionToken { event: evt.as_ptr(), status: Status::SUCCESS };
199196
let data_len = u32::try_from(buf.len()).unwrap_or(u32::MAX);
200197

201198
let fragment = tcp4::FragmentData {
202199
fragment_length: data_len,
203200
fragment_buffer: buf.as_mut_ptr().cast::<crate::ffi::c_void>(),
204201
};
205-
let mut tx_data = tcp4::ReceiveData {
202+
let mut rx_data = tcp4::ReceiveData {
206203
urgent_flag: r_efi::efi::Boolean::FALSE,
207204
data_length: data_len,
208205
fragment_count: 1,
209206
fragment_table: [fragment],
210207
};
211208

212-
let protocol = self.protocol.as_ptr();
213-
let mut token = tcp4::IoToken {
214-
completion_token,
215-
packet: tcp4::IoTokenPacket {
216-
rx_data: (&raw mut tx_data).cast::<tcp4::ReceiveData<0>>(),
217-
},
209+
self.read_inner((&raw mut rx_data).cast(), timeout).map(|_| data_len as usize)
210+
}
211+
212+
pub(crate) fn read_vectored(
213+
&self,
214+
buf: &[IoSliceMut<'_>],
215+
timeout: Option<Duration>,
216+
) -> io::Result<usize> {
217+
let mut data_length = 0u32;
218+
let mut fragment_count = 0u32;
219+
220+
// Calculate how many IoSlice in buf can be transmitted.
221+
for i in buf {
222+
// IoSlice length is always <= u32::MAX in UEFI.
223+
match data_length.checked_add(u32::try_from(i.len()).expect("value is stored as a u32"))
224+
{
225+
Some(x) => data_length = x,
226+
None => break,
227+
}
228+
fragment_count += 1;
229+
}
230+
231+
let rx_data_size = size_of::<tcp4::ReceiveData<0>>()
232+
+ size_of::<tcp4::FragmentData>() * (fragment_count as usize);
233+
let mut rx_data = helpers::UefiBox::<tcp4::ReceiveData>::new(rx_data_size)?;
234+
rx_data.write(tcp4::ReceiveData {
235+
urgent_flag: r_efi::efi::Boolean::FALSE,
236+
data_length,
237+
fragment_count,
238+
fragment_table: [],
239+
});
240+
unsafe {
241+
// SAFETY: IoSlice and FragmentData are guaranteed to have same layout.
242+
crate::ptr::copy_nonoverlapping(
243+
buf.as_ptr().cast(),
244+
(*rx_data.as_mut_ptr()).fragment_table.as_mut_ptr(),
245+
fragment_count as usize,
246+
);
218247
};
219248

249+
self.read_inner(rx_data.as_mut_ptr(), timeout).map(|_| data_length as usize)
250+
}
251+
252+
pub(crate) fn read_inner(
253+
&self,
254+
rx_data: *mut tcp4::ReceiveData,
255+
timeout: Option<Duration>,
256+
) -> io::Result<()> {
257+
let evt = unsafe { self.create_evt() }?;
258+
let completion_token =
259+
tcp4::CompletionToken { event: evt.as_ptr(), status: Status::SUCCESS };
260+
261+
let protocol = self.protocol.as_ptr();
262+
let mut token = tcp4::IoToken { completion_token, packet: tcp4::IoTokenPacket { rx_data } };
263+
220264
let r = unsafe { ((*protocol).receive)(protocol, &mut token) };
221265
if r.is_error() {
222266
return Err(io::Error::from_raw_os_error(r.as_usize()));
@@ -227,7 +271,7 @@ impl Tcp4 {
227271
if completion_token.status.is_error() {
228272
Err(io::Error::from_raw_os_error(completion_token.status.as_usize()))
229273
} else {
230-
Ok(data_len as usize)
274+
Ok(())
231275
}
232276
}
233277

src/librustdoc/json/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
302302
ExternalLocation::Remote(s) => Some(s.clone()),
303303
_ => None,
304304
},
305+
path: self
306+
.tcx
307+
.used_crate_source(*crate_num)
308+
.paths()
309+
.next()
310+
.expect("crate should have at least 1 path")
311+
.clone(),
305312
},
306313
)
307314
})
@@ -339,20 +346,21 @@ mod size_asserts {
339346
// tidy-alphabetical-start
340347
static_assert_size!(AssocItemConstraint, 112);
341348
static_assert_size!(Crate, 184);
342-
static_assert_size!(ExternalCrate, 48);
343349
static_assert_size!(FunctionPointer, 168);
344350
static_assert_size!(GenericArg, 80);
345351
static_assert_size!(GenericArgs, 104);
346352
static_assert_size!(GenericBound, 72);
347353
static_assert_size!(GenericParamDef, 136);
348354
static_assert_size!(Impl, 304);
349-
// `Item` contains a `PathBuf`, which is different sizes on different OSes.
350-
static_assert_size!(Item, 528 + size_of::<std::path::PathBuf>());
351355
static_assert_size!(ItemSummary, 32);
352356
static_assert_size!(PolyTrait, 64);
353357
static_assert_size!(PreciseCapturingArg, 32);
354358
static_assert_size!(TargetFeature, 80);
355359
static_assert_size!(Type, 80);
356360
static_assert_size!(WherePredicate, 160);
357361
// tidy-alphabetical-end
362+
363+
// These contains a `PathBuf`, which is different sizes on different OSes.
364+
static_assert_size!(Item, 528 + size_of::<std::path::PathBuf>());
365+
static_assert_size!(ExternalCrate, 48 + size_of::<std::path::PathBuf>());
358366
}

src/rustdoc-json-types/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
3737
// will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line
3838
// are deliberately not in a doc comment, because they need not be in public docs.)
3939
//
40-
// Latest feature: Add `ItemKind::Attribute`.
41-
pub const FORMAT_VERSION: u32 = 56;
40+
// Latest feature: Add `ExternCrate::path`.
41+
pub const FORMAT_VERSION: u32 = 57;
4242

4343
/// The root of the emitted JSON blob.
4444
///
@@ -135,6 +135,12 @@ pub struct ExternalCrate {
135135
pub name: String,
136136
/// The root URL at which the crate's documentation lives.
137137
pub html_root_url: Option<String>,
138+
139+
/// A path from where this crate was loaded.
140+
///
141+
/// This will typically be a `.rlib` or `.rmeta`. It can be used to determine which crate
142+
/// this was in terms of whatever build-system invoked rustc.
143+
pub path: PathBuf,
138144
}
139145

140146
/// Information about an external (not defined in the local crate) [`Item`].

src/tools/run-make-support/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ wasmparser = { version = "0.236", default-features = false, features = ["std", "
2222

2323
# Shared with bootstrap and compiletest
2424
build_helper = { path = "../../build_helper" }
25+
# Shared with rustdoc
26+
rustdoc-json-types = { path = "../../rustdoc-json-types" }
2527

2628
[lib]
2729
crate-type = ["lib", "dylib"]

src/tools/run-make-support/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub mod rfs {
3434
}
3535

3636
// Re-exports of third-party library crates.
37-
pub use {bstr, gimli, libc, object, regex, serde_json, similar, wasmparser};
37+
pub use {bstr, gimli, libc, object, regex, rustdoc_json_types, serde_json, similar, wasmparser};
3838

3939
// Helpers for building names of output artifacts that are potentially target-specific.
4040
pub use crate::artifact_names::{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![no_std]
2+
3+
pub struct S;
4+
5+
pub use trans_dep::S as TransDep;

0 commit comments

Comments
 (0)