Skip to content

Commit

Permalink
Auto merge of rust-lang#131540 - matthiaskrgr:rollup-elbgu1w, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#131464 (Update wasm-component-ld to 0.5.10)
 - rust-lang#131476 (coverage: Include the highest counter ID seen in `.cov-map` dumps)
 - rust-lang#131497 (Add myself to bootstrap review rotation)
 - rust-lang#131498 (Consider outermost const-anon in `non_local_def` lint)
 - rust-lang#131512 (Fixing rustDoc for LayoutError.)
 - rust-lang#131529 (rustdoc-json-types: fix typo in comment)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 11, 2024
2 parents ce697f9 + d590d21 commit 484c8e7
Show file tree
Hide file tree
Showing 99 changed files with 515 additions and 61 deletions.
48 changes: 24 additions & 24 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5804,16 +5804,16 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"

[[package]]
name = "wasm-component-ld"
version = "0.5.9"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde17bc96539700198e12516230c76095cc215c84ef39ad206e1af3f84243e0f"
checksum = "4d4aa6bd7fbe7cffbed29fe3e236fda74419def1bdef6f80f989ec51137edf44"
dependencies = [
"anyhow",
"clap",
"lexopt",
"tempfile",
"wasi-preview1-component-adapter-provider",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
"wat",
"wit-component",
"wit-parser",
Expand All @@ -5837,28 +5837,28 @@ dependencies = [

[[package]]
name = "wasm-encoder"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22b896fa8ceb71091ace9bcb81e853f54043183a1c9667cf93422c40252ffa0a"
checksum = "e2b1b95711b3ad655656a341e301cc64e33cbee94de9a99a1c5a2ab88efab79d"
dependencies = [
"leb128",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
]

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

[[package]]
Expand All @@ -5873,9 +5873,9 @@ dependencies = [

[[package]]
name = "wasmparser"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09e46c7fceceaa72b2dd1a8a137ea7fd8f93dfaa69806010a709918e496c5dc"
checksum = "324b4e56d24439495b88cd81439dad5e97f3c7b1eedc3c7e10455ed1e045e9a2"
dependencies = [
"ahash",
"bitflags 2.6.0",
Expand All @@ -5887,22 +5887,22 @@ dependencies = [

[[package]]
name = "wast"
version = "218.0.0"
version = "219.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a53cd1f0fa505df97557e36a58bddb8296e2fcdcd089529545ebfdb18a1b9d7"
checksum = "06880ecb25662bc21db6a83f4fcc27c41f71fbcba4f1980b650c88ada92728e1"
dependencies = [
"bumpalo",
"leb128",
"memchr",
"unicode-width",
"wasm-encoder 0.218.0",
"wasm-encoder 0.219.0",
]

[[package]]
name = "wat"
version = "1.218.0"
version = "1.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f87f8e14e776762e07927c27c2054d2cf678aab9aae2d431a79b3e31e4dd391"
checksum = "11e56dbf9fc89111b0d97c91e683d7895b1a6e5633a729f2ccad2303724005b6"
dependencies = [
"wast",
]
Expand Down Expand Up @@ -6179,9 +6179,9 @@ dependencies = [

[[package]]
name = "wit-component"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa53aa7e6bf2b3e8ccaffbcc963fbdb672a603dc0af393a481b6cec24c266406"
checksum = "99a76111c20444a814019de20499d30940ecd219b9512ee296f034a5edb18a2d"
dependencies = [
"anyhow",
"bitflags 2.6.0",
Expand All @@ -6190,17 +6190,17 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"wasm-encoder 0.218.0",
"wasm-encoder 0.219.0",
"wasm-metadata",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
"wit-parser",
]

[[package]]
name = "wit-parser"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d3d1066ab761b115f97fef2b191090faabcb0f37b555b758d3caf42d4ed9e55"
checksum = "23102e180c0c464f36e293d31a27b524e3ece930d7b5527d2f33f9d2c963de64"
dependencies = [
"anyhow",
"id-arena",
Expand All @@ -6211,7 +6211,7 @@ dependencies = [
"serde_derive",
"serde_json",
"unicode-xid",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
]

[[package]]
Expand Down
90 changes: 59 additions & 31 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
// If that's the case this means that this impl block declaration
// is using local items and so we don't lint on it.

// We also ignore anon-const in item by including the anon-const
// parent as well.
let parent_parent = if parent_def_kind == DefKind::Const
&& parent_opt_item_name == Some(kw::Underscore)
{
Some(cx.tcx.parent(parent))
} else {
None
};

// 1. We collect all the `hir::Path` from the `Self` type and `Trait` ref
// of the `impl` definition
let mut collector = PathCollector { paths: Vec::new() };
Expand All @@ -148,13 +138,33 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
|p| matches!(p.res, Res::Def(def_kind, _) if def_kind != DefKind::TyParam),
);

// 2. We check if any of path reference a "local" parent and if that the case
// we bail out as asked by T-lang, even though this isn't correct from a
// type-system point of view, as inference exists and could still leak the impl.
// 1.9. We retrieve the parent def id of the impl item, ...
//
// ... modulo const-anons items, for enhanced compatibility with the ecosystem
// as that pattern is common with `serde`, `bevy`, ...
//
// For this example we want the `DefId` parent of the outermost const-anon items.
// ```
// const _: () = { // the parent of this const-anon
// const _: () = {
// impl Foo {}
// };
// };
// ```
let outermost_impl_parent = peel_parent_while(cx.tcx, parent, |tcx, did| {
tcx.def_kind(did) == DefKind::Const
&& tcx.opt_item_name(did) == Some(kw::Underscore)
});

// 2. We check if any of the paths reference a the `impl`-parent.
//
// If that the case we bail out, as was asked by T-lang, even though this isn't
// correct from a type-system point of view, as inference exists and one-impl-rule
// make its so that we could still leak the impl.
if collector
.paths
.iter()
.any(|path| path_has_local_parent(path, cx, parent, parent_parent))
.any(|path| path_has_local_parent(path, cx, parent, outermost_impl_parent))
{
return;
}
Expand Down Expand Up @@ -253,8 +263,8 @@ impl<'tcx> Visitor<'tcx> for PathCollector<'tcx> {
}
}

/// Given a path and a parent impl def id, this checks if the if parent resolution
/// def id correspond to the def id of the parent impl definition.
/// Given a path, this checks if the if the parent resolution def id corresponds to
/// the def id of the parent impl definition (the direct one and the outermost one).
///
/// Given this path, we will look at the path (and ignore any generic args):
///
Expand All @@ -267,32 +277,50 @@ fn path_has_local_parent(
path: &Path<'_>,
cx: &LateContext<'_>,
impl_parent: DefId,
impl_parent_parent: Option<DefId>,
outermost_impl_parent: Option<DefId>,
) -> bool {
path.res
.opt_def_id()
.is_some_and(|did| did_has_local_parent(did, cx.tcx, impl_parent, impl_parent_parent))
.is_some_and(|did| did_has_local_parent(did, cx.tcx, impl_parent, outermost_impl_parent))
}

/// Given a def id and a parent impl def id, this checks if the parent
/// def id (modulo modules) correspond to the def id of the parent impl definition.
/// Given a def id this checks if the parent def id (modulo modules) correspond to
/// the def id of the parent impl definition (the direct one and the outermost one).
#[inline]
fn did_has_local_parent(
did: DefId,
tcx: TyCtxt<'_>,
impl_parent: DefId,
impl_parent_parent: Option<DefId>,
outermost_impl_parent: Option<DefId>,
) -> bool {
did.is_local()
&& if let Some(did_parent) = tcx.opt_parent(did) {
did_parent == impl_parent
|| Some(did_parent) == impl_parent_parent
|| !did_parent.is_crate_root()
&& tcx.def_kind(did_parent) == DefKind::Mod
&& did_has_local_parent(did_parent, tcx, impl_parent, impl_parent_parent)
} else {
false
}
if !did.is_local() {
return false;
}

let Some(parent_did) = tcx.opt_parent(did) else {
return false;
};

peel_parent_while(tcx, parent_did, |tcx, did| tcx.def_kind(did) == DefKind::Mod)
.map(|parent_did| parent_did == impl_parent || Some(parent_did) == outermost_impl_parent)
.unwrap_or(false)
}

/// Given a `DefId` checks if it satisfies `f` if it does check with it's parent and continue
/// until it doesn't satisfies `f` and return the last `DefId` checked.
///
/// In other word this method return the first `DefId` that doesn't satisfies `f`.
#[inline]
fn peel_parent_while(
tcx: TyCtxt<'_>,
mut did: DefId,
mut f: impl FnMut(TyCtxt<'_>, DefId) -> bool,
) -> Option<DefId> {
while !did.is_crate_root() && f(tcx, did) {
did = tcx.opt_parent(did).filter(|parent_did| parent_did.is_local())?;
}

Some(did)
}

/// Return for a given `Path` the span until the last args
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ impl Layout {
)]
pub type LayoutErr = LayoutError;

/// The parameters given to `Layout::from_size_align`
/// The `LayoutError` is returned when the parameters given
/// to `Layout::from_size_align`
/// or some other `Layout` constructor
/// do not satisfy its documented constraints.
#[stable(feature = "alloc_layout_error", since = "1.50.0")]
Expand Down
2 changes: 1 addition & 1 deletion src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ pub struct FunctionHeader {
/// on unwinding for more info.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Abi {
// We only have a concrete listing here for stable ABI's because their are so many
// We only have a concrete listing here for stable ABI's because there are so many
// See rustc_ast_passes::feature_gate::PostExpansionVisitor::check_abi for the list
/// The default ABI, but that can also be written explicitly with `extern "Rust"`.
Rust,
Expand Down
42 changes: 42 additions & 0 deletions src/tools/coverage-dump/src/covfun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ pub(crate) fn dump_covfun_mappings(
expression_resolver.push_operands(lhs, rhs);
}

let mut max_counter = None;
for i in 0..num_files {
let num_mappings = parser.read_uleb128_u32()?;
println!("Number of file {i} mappings: {num_mappings}");

for _ in 0..num_mappings {
let (kind, region) = parser.read_mapping_kind_and_region()?;
println!("- {kind:?} at {region:?}");
kind.for_each_term(|term| {
if let CovTerm::Counter(n) = term {
max_counter = max_counter.max(Some(n));
}
});

match kind {
// Also print expression mappings in resolved form.
Expand All @@ -83,6 +89,16 @@ pub(crate) fn dump_covfun_mappings(
}

parser.ensure_empty()?;

// Printing the highest counter ID seen in the functions mappings makes
// it easier to determine whether a change to coverage instrumentation
// has increased or decreased the number of physical counters needed.
// (It's possible for the generated code to have more counters that
// aren't used by any mappings, but that should hopefully be rare.)
println!("Highest counter ID seen: {}", match max_counter {
Some(id) => format!("c{id}"),
None => "(none)".to_owned(),
});
println!();
}
Ok(())
Expand Down Expand Up @@ -271,6 +287,32 @@ enum MappingKind {
},
}

impl MappingKind {
fn for_each_term(&self, mut callback: impl FnMut(CovTerm)) {
match *self {
Self::Code(term) => callback(term),
Self::Gap(term) => callback(term),
Self::Expansion(_id) => {}
Self::Skip => {}
Self::Branch { r#true, r#false } => {
callback(r#true);
callback(r#false);
}
Self::MCDCBranch {
r#true,
r#false,
condition_id: _,
true_next_id: _,
false_next_id: _,
} => {
callback(r#true);
callback(r#false);
}
Self::MCDCDecision { bitmap_idx: _, conditions_num: _ } => {}
}
}
}

struct MappingRegion {
/// Offset of this region's start line, relative to the *start line* of
/// the *previous mapping* (or 0). Line numbers are 1-based.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/wasm-component-ld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ name = "wasm-component-ld"
path = "src/main.rs"

[dependencies]
wasm-component-ld = "0.5.9"
wasm-component-ld = "0.5.10"
2 changes: 2 additions & 0 deletions tests/coverage/abort.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Number of file 0 mappings: 13
- Code(Expression(9, Add)) at (prev + 1, 9) to (start + 0, 23)
= (c1 + c2)
- Code(Counter(3)) at (prev + 2, 5) to (start + 1, 2)
Highest counter ID seen: c5

Function name: abort::might_abort
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 03, 01, 01, 14, 05, 02, 09, 01, 24, 02, 02, 0c, 03, 02]
Expand All @@ -46,4 +47,5 @@ Number of file 0 mappings: 3
- Code(Counter(1)) at (prev + 2, 9) to (start + 1, 36)
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 3, 2)
= (c0 - c1)
Highest counter ID seen: c1

1 change: 1 addition & 0 deletions tests/coverage/assert-ne.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Number of file 0 mappings: 4
- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 19)
= (c0 - c1)
- Code(Counter(2)) at (prev + 3, 5) to (start + 1, 2)
Highest counter ID seen: c2

2 changes: 2 additions & 0 deletions tests/coverage/assert.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Number of file 0 mappings: 9
- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 0, 23)
= (c1 + (c2 + c3))
- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2)
Highest counter ID seen: c4

Function name: assert::might_fail_assert
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 04, 01, 02, 0f, 02, 02, 25, 00, 3d, 05, 01, 01, 00, 02]
Expand All @@ -37,4 +38,5 @@ Number of file 0 mappings: 3
- Code(Expression(0, Sub)) at (prev + 2, 37) to (start + 0, 61)
= (c0 - c1)
- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c1

Loading

0 comments on commit 484c8e7

Please sign in to comment.