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

Capture precise paths in THIR and MIR #33

Closed
wants to merge 164 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
0b3c9d8
unix: Extend UnixStream and UnixDatagram to send and receive file des…
LinkTed Aug 21, 2020
6fa7c3f
Split net.rs into multiple files
LinkTed Aug 22, 2020
6f82ddf
Add AncillaryError
LinkTed Aug 22, 2020
e6984ee
Add UCred struct
LinkTed Aug 23, 2020
8783b06
Move `add_to_ancillary_data` and `AncillaryDataIter` to ancillary.rs
LinkTed Aug 23, 2020
8784ffb
Using `read_unaligned` instead of `memcpy`.
LinkTed Aug 25, 2020
e108405
Replace `TryFrom` of `AncillaryData` with a private method.
LinkTed Aug 25, 2020
3dfab6f
Add integer overflow check
LinkTed Aug 25, 2020
b82f29d
Remove `Clone` trait bound in `add_to_ancillary_data`
LinkTed Aug 25, 2020
4c929a0
Remove lifetime annotation in `messages` function
LinkTed Aug 25, 2020
1f3195a
Remove inner function in `bind`, `connect` and `send_to`
LinkTed Aug 25, 2020
6ed9bfa
Use `fill` instead of `memset`
LinkTed Aug 27, 2020
07ed6af
Remove unnecessary path
LinkTed Aug 27, 2020
53791b3
Move conditional compilation to the upper module and sort the target …
LinkTed Aug 28, 2020
1869141
Reduce impl trait by using macro in `raw_fd.rs`
LinkTed Aug 28, 2020
46764d4
Add doc(cfg(...))
LinkTed Aug 29, 2020
a91fd73
Add doc comments
LinkTed Aug 29, 2020
19c5fdd
Rename `test.rs` to `tests.rs`
LinkTed Sep 1, 2020
686964f
Add `set_passcred` and `passcred` methods to `UnixStream` and `UnixDa…
LinkTed Sep 7, 2020
eeea5c2
Change API to unsafe and add doc comments
LinkTed Sep 12, 2020
1902711
Change name of struct to SocketCred
LinkTed Sep 16, 2020
5964d59
Change standard types to libc types
LinkTed Sep 16, 2020
d0b133c
Remove unsupported target_os for SocketCred
LinkTed Sep 17, 2020
e61148f
Cast boolean into int directly in function set_passcred
LinkTed Sep 17, 2020
cc085e9
Replace `assert` with `unreachable`
LinkTed Sep 18, 2020
db902bc
Add the code of the tracking issue
LinkTed Sep 19, 2020
7b476d8
Remove `target_os`, which does not have `MSG_CMSG_CLOEXEC` constant i…
LinkTed Sep 20, 2020
1f6d7dc
Remove `target_os`, which does not have `cmsghdr` struct in `libc`
LinkTed Sep 20, 2020
d30508f
Remove `target_os`, which does not have `SO_PASSCRED` constant in `libc`
LinkTed Sep 20, 2020
e0cedba
Fix cfg condition for test
LinkTed Sep 20, 2020
c2a1b50
Add conditional compilation for import
LinkTed Sep 20, 2020
b01ce2c
Fix `MSG_CMSG_CLOEXEC` for macos
LinkTed Sep 22, 2020
31e6e38
Fix `SO_PASSCRED` for macos
LinkTed Sep 22, 2020
0fcb834
Fix unused import for `IoSliceMut` for macos
LinkTed Sep 22, 2020
889c927
Remove `SocketCred` for `emscripten`
LinkTed Sep 22, 2020
ce167f8
Fix type mismatching for different OSes.
LinkTed Sep 25, 2020
6b0c3df
Remove unnecessary trailing semicolon
LinkTed Sep 26, 2020
e9bf699
Remove `passcred` for `emscripten`
LinkTed Sep 26, 2020
1ae54e5
Change imports for `cfg(doc)`
LinkTed Sep 27, 2020
d0069a0
Fix imports for MacOs
LinkTed Oct 2, 2020
a817647
Add fake definitions for Windows
LinkTed Oct 4, 2020
fc65f6a
Fix import errors for `#[cfg(doc)]` target
LinkTed Oct 4, 2020
7b596f2
Fix `libc` is ambiguous for Windows
LinkTed Oct 5, 2020
64facfe
Fix unresolved link to `SocketAncillary`
LinkTed Oct 6, 2020
d8c75d9
Fix unresolved imports for `recv_vectored_with_ancillary_from`, `sen…
LinkTed Oct 11, 2020
79273fa
Fix cannot find type `ucred` for MacOs by using fake definitions
LinkTed Oct 17, 2020
ea5e012
Fix test cases for MacOs
LinkTed Oct 21, 2020
c779405
Fix docs for MacOs (correction)
LinkTed Nov 3, 2020
ead7185
Fix docs for MacOs (again)
LinkTed Nov 4, 2020
64efcbe
Use true previous lint level when detecting overriden forbids
Mark-Simulacrum Nov 7, 2020
685e1f3
Fix zero-sized BTreeMap gdb pretty-printer
artemmukhin Nov 20, 2020
9b9dd4a
Bug fix for android platform, because of the wrong behavior of CMSG_N…
LinkTed Nov 24, 2020
8983752
Add comment for the previous android bug fix
LinkTed Nov 26, 2020
de3a0bd
Fixes #79357 unstable or-pat suggestions
nico-abram Nov 23, 2020
0183b41
Pass arguments up to 2*usize by value
erikdesjardins Nov 30, 2020
53943d6
make test work in llvm 9
erikdesjardins Nov 30, 2020
528355c
add const_allocate intrisic
vn-ki Dec 1, 2020
b5b811a
review comments
vn-ki Dec 1, 2020
a6c4cbd
review comment and one more test
vn-ki Dec 1, 2020
f2f3a8e
Add long explanation of E0546
sasurau4 Nov 29, 2020
ea5aff4
bless stability-attribute-sanity ui test
sasurau4 Nov 29, 2020
b787d72
Fix SGX CI
Dec 1, 2020
878cfb5
Fix `unknown-crate` when using self-profile with rustdoc
jyn514 Dec 1, 2020
66884e3
Add json backend
P1n3appl3 Aug 3, 2020
1098cce
Add tests for rustdoc json
aDotInTheVoid Nov 29, 2020
40b5470
Address review comments.
aDotInTheVoid Nov 30, 2020
6018200
Discard `const_stability`
aDotInTheVoid Dec 1, 2020
3c4bc8c
Ignore trait implementations with negative polarity when suggesting t…
ThePuzzlemaker Dec 1, 2020
859463b
Fix UI tests for negative polarity implementations of traits
ThePuzzlemaker Dec 1, 2020
b287806
Add regression test for #79458
ThePuzzlemaker Dec 1, 2020
4eb76fc
Use more std:: instead of core:: in docs for consistency, add more in…
poliorcetics Dec 1, 2020
eb4860c
Auto merge of #78864 - Mark-Simulacrum:warn-on-forbids, r=pnkfelix
bors Dec 2, 2020
cdcce11
Tweak diagnostics on shadowing lifetimes/labels
JohnTitor Dec 2, 2020
92e4fb0
Auto merge of #79235 - ortem:fix-btreemap-gdb-pretty-printer, r=Mark-…
bors Dec 2, 2020
88c6cf8
Pass around Symbols instead of Idents in doctree
jyn514 Dec 2, 2020
5009798
Update cargo
ehuss Dec 2, 2020
d37afad
Auto merge of #79606 - ThePuzzlemaker:issue-79458-fix, r=scottmcm
bors Dec 2, 2020
5a22826
Clean up doc attributes check before adding more
GuillaumeGomez Dec 1, 2020
dc10ccf
Add checks for #[doc(keyword = "...")] and move them into rustc_passes
GuillaumeGomez Dec 1, 2020
8a35b93
Add rustc_lexer as dependency to rustc_passes
GuillaumeGomez Dec 1, 2020
1b7fe09
add comment and bless some tests
vn-ki Dec 2, 2020
899a59e
rename MemoryKind::Heap to ConstHeap; bless test
vn-ki Dec 2, 2020
67a67d8
disable a ptr equality test on Miri
RalfJung Dec 2, 2020
7e74b72
break formatting so rustfmt is happy
RalfJung Dec 2, 2020
a094ff9
Auto merge of #79547 - erikdesjardins:byval, r=nagisa
bors Dec 2, 2020
37354eb
Revert "Auto merge of #79209 - spastorino:trait-inheritance-self, r=n…
spastorino Dec 2, 2020
4e7a2dc
Use `item_name` instead of pretty printing
jyn514 Dec 2, 2020
af69066
Auto merge of #69864 - LinkTed:master, r=Amanieu
bors Dec 2, 2020
9866136
Add tests for #[doc(keyword = "...")] and update other doc attributes…
GuillaumeGomez Dec 1, 2020
15f9453
Remove check keyword identifier check from rustdoc
GuillaumeGomez Dec 2, 2020
f4db9ff
Auto merge of #79364 - nico-abram:unstable-or-pat-suggestion, r=matth…
bors Dec 2, 2020
908bf5a
rustc_metadata: Remove some dead code
petrochenkov Dec 2, 2020
d619271
Normalize windows path seperators.
aDotInTheVoid Dec 2, 2020
7dc1e85
Auto merge of #79539 - aDotInTheVoid:json-mvp, r=jyn514
bors Dec 2, 2020
b4def89
Auto merge of #79637 - spastorino:revert-trait-inheritance-self, r=Ma…
bors Dec 3, 2020
c7cff21
Auto merge of #79533 - sasurau4:feature/add-long-explanation-E0546, r…
bors Dec 3, 2020
bc6eb6f
move intrinsic to CTFE, add FIXME
vn-ki Dec 3, 2020
56c64f8
Add lint pass for doc keyword
GuillaumeGomez Nov 29, 2020
d015f0d
Auto merge of #79594 - vn-ki:const-eval-intrinsic, r=oli-obk
bors Dec 3, 2020
2203527
Auto merge of #79586 - jyn514:crate-name, r=davidtwco
bors Dec 3, 2020
0105e4a
Add test for EXISTING_DOC_KEYWORD internal lint
GuillaumeGomez Dec 3, 2020
1f95c91
Auto merge of #79613 - GuillaumeGomez:doc-keyword-checks, r=oli-obk
bors Dec 3, 2020
50eb3a8
Only deny doc_keyword in std and set it as "allow" by default
GuillaumeGomez Dec 3, 2020
ff0ebd2
move interpret::MemoryKind::Heap to const eval
vn-ki Dec 3, 2020
c45ee4b
Coverage tests for remaining TerminatorKinds and async, improve Assert
richkadel Nov 16, 2020
f6c9c1a
Removed -base from run-make-fulldeps/coverage-*-base
richkadel Dec 1, 2020
def932c
Combination of commits
richkadel Dec 1, 2020
d96f351
Addressed feedback from 2020-12-01
richkadel Dec 2, 2020
b0c140a
Workaround for inconsistent order of llvm-cov results on Windows
richkadel Dec 2, 2020
f101fd8
Fixed cross-crate generic call test to compile lib and bin separately
richkadel Dec 2, 2020
5be3f9f
Auto merge of #79620 - JohnTitor:label-name-sugg, r=davidtwco
bors Dec 3, 2020
dc4bd90
Tweak to Makefile to overcome MacOS make corruption bug
richkadel Dec 3, 2020
0ad3dce
Fix some clippy lints
jyn514 Dec 3, 2020
5d4a712
Render Markdown in search results
camelid Oct 5, 2020
e178030
Use `createElement` and `innerHTML` instead of `DOMParser`
camelid Nov 17, 2020
07e9426
Make `length_limit` a `usize`
camelid Nov 24, 2020
b903519
Add rustdoc-js test
camelid Nov 24, 2020
f0cf5a9
Add more rustdoc-js test cases
camelid Nov 24, 2020
376507f
Add missing feature flag
camelid Dec 3, 2020
793c40e
Inline `is_covered_by`
Nadrieril Dec 3, 2020
6f2fbc1
Rollup merge of #77686 - camelid:rustdoc-render-search-results, r=Gui…
Dylan-DPC Dec 4, 2020
f406052
Rollup merge of #79541 - GuillaumeGomez:doc-keyword-lint-pass, r=lcnr
Dylan-DPC Dec 4, 2020
6b42900
Rollup merge of #79602 - jethrogb:sgx-fix-79038, r=Mark-Simulacrum
Dylan-DPC Dec 4, 2020
88f0c72
Rollup merge of #79611 - poliorcetics:use-std-in-docs, r=jyn514
Dylan-DPC Dec 4, 2020
14895ea
Rollup merge of #79623 - jyn514:ident, r=GuillaumeGomez
Dylan-DPC Dec 4, 2020
aef5edd
Rollup merge of #79627 - ehuss:update-cargo, r=ehuss
Dylan-DPC Dec 4, 2020
0a52b43
Rollup merge of #79631 - RalfJung:miri-const_str_ptr, r=oli-obk
Dylan-DPC Dec 4, 2020
5495bb9
Rollup merge of #79638 - jyn514:intra-link-self-raw, r=Manishearth
Dylan-DPC Dec 4, 2020
0fbbe94
Rollup merge of #79646 - petrochenkov:inclean, r=davidtwco
Dylan-DPC Dec 4, 2020
a2aa3d6
Rollup merge of #79664 - vn-ki:move-memkind-heap, r=oli-obk
Dylan-DPC Dec 4, 2020
5cebbaa
Rollup merge of #79678 - jyn514:THE-PAPERCLIP-COMETH, r=varkor
Dylan-DPC Dec 4, 2020
6513f50
Auto merge of #79109 - richkadel:llvm-coverage-counters-2.0.5, r=tmandry
bors Dec 4, 2020
e9dd18c
Auto merge of #79686 - Dylan-DPC:rollup-leama5f, r=Dylan-DPC
bors Dec 4, 2020
cb56b1a
Fix comment that refers to dead enforce_object_limitations function.
benjaminp Sep 20, 2020
4d8a7c2
Unnest some .chain calls, so it's clearer what's going on.
benjaminp Oct 21, 2020
76ff0f4
The details of higher-rank sub are in the rustc book not a doc module.
benjaminp Oct 21, 2020
504f136
Writeback walks the HIR not the AST.
benjaminp Oct 21, 2020
e622543
Auto merge of #78177 - benjaminp:cleanups, r=jyn514
bors Dec 4, 2020
2218520
Auto merge of #79680 - Nadrieril:fix-regression-79284, r=jonas-schievink
bors Dec 4, 2020
356ea6b
Move format machinery tests to where they belong
matklad Dec 4, 2020
9274b37
Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate`
TimDiekmann Dec 4, 2020
98fc02d
check the recursion limit when finding struct tail
SNCPlay42 Nov 26, 2020
db5d697
std: impl of `Write` for `&mut [u8]`: document the buffer full error
ijackson Dec 3, 2020
19c7619
IntoInnerError: Provide into_parts
ijackson Nov 2, 2020
b777552
IntoInnerError: Provide into_error
ijackson Dec 4, 2020
3ff10e7
Auto merge of #79286 - TimDiekmann:rename-allocref, r=Lokathor,Wodann…
bors Dec 4, 2020
b766abc
Simplify unscheduling of drops after moves
matthewjasper Oct 5, 2020
7f3e855
Use `record_operands_moved` more aggresively
matthewjasper Oct 24, 2020
a5fbaed
Auto merge of #79673 - ijackson:intoinnerintoinnererror, r=m-ou-se
bors Dec 4, 2020
4fef391
Avoid leaking block expression values
matthewjasper Oct 24, 2020
0781b44
Auto merge of #76301 - matklad:fmt-test, r=matklad
bors Dec 5, 2020
b1d7836
Ping me when nomicon's toolstate is broken
JohnTitor Dec 5, 2020
e0e26b4
update Miri
RalfJung Dec 5, 2020
551a2c6
Auto merge of #79724 - RalfJung:miri, r=RalfJung
bors Dec 5, 2020
9122b76
Auto merge of #78373 - matthewjasper:drop-on-into, r=pnkfelix
bors Dec 5, 2020
5bb68c3
Auto merge of #79445 - SNCPlay42:struct-tail-recursion-limit, r=oli-obk
bors Dec 5, 2020
15eaa00
Auto merge of #79719 - JohnTitor:nomicon, r=Mark-Simulacrum
bors Dec 5, 2020
76c68aa
Writeback min_capture map to TypeckResults
arora-aman Nov 21, 2020
6e5cca7
Use min_captures for creating UpvarSusbts::tupled_upvar_tys
arora-aman Nov 26, 2020
d952362
Move handling UpvarRef to PlaceBuilder
arora-aman Nov 19, 2020
6a1d069
Use Places for captures in MIR
arora-aman Nov 26, 2020
e2efdd1
Use precise places when lowering Closures in THIR
arora-aman Nov 26, 2020
237ad12
Use closure_min_captures in borrow checker
arora-aman Nov 25, 2020
01df563
Test cases for RFC 2229
arora-aman Nov 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4011,6 +4011,7 @@ dependencies = [
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc_lexer",
"rustc_middle",
"rustc_serialize",
"rustc_session",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `_ => else_block` where `else_block` is `{}` if there's `None`:
let else_pat = self.pat_wild(span);
let (else_expr, contains_else_clause) = match else_opt {
None => (self.expr_block_empty(span), false),
None => (self.expr_block_empty(span.shrink_to_hi()), false),
Some(els) => (self.lower_expr(els), true),
};
let else_arm = self.arm(else_pat, else_expr);
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
return;
}

// FIXME(richkadel): Make sure probestack plays nice with `-Z instrument-coverage`
// or disable it if not, similar to above early exits.

// Flag our internal `__rust_probestack` function as the stack probe symbol.
// This is defined in the `compiler-builtins` crate for each architecture.
llvm::AddFunctionAttrStringValue(
Expand Down
174 changes: 167 additions & 7 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use crate::coverageinfo;
use crate::llvm;

use llvm::coverageinfo::CounterMappingRegion;
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression, FunctionCoverage};
use rustc_codegen_ssa::traits::ConstMethods;
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_hir::def_id::{DefId, DefIdSet, LOCAL_CRATE};
use rustc_llvm::RustString;
use rustc_middle::mir::coverage::CodeRegion;
use rustc_middle::ty::{Instance, TyCtxt};
use rustc_span::Symbol;

use std::ffi::CString;

Expand All @@ -26,14 +29,17 @@ use tracing::debug;
/// undocumented details in Clang's implementation (that may or may not be important) were also
/// replicated for Rust's Coverage Map.
pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
let tcx = cx.tcx;
// Ensure LLVM supports Coverage Map Version 4 (encoded as a zero-based value: 3).
// If not, the LLVM Version must be less than 11.
let version = coverageinfo::mapping_version();
if version != 3 {
cx.tcx.sess.fatal("rustc option `-Z instrument-coverage` requires LLVM 11 or higher.");
tcx.sess.fatal("rustc option `-Z instrument-coverage` requires LLVM 11 or higher.");
}

let function_coverage_map = match cx.coverage_context() {
debug!("Generating coverage map for CodegenUnit: `{}`", cx.codegen_unit.name());

let mut function_coverage_map = match cx.coverage_context() {
Some(ctx) => ctx.take_function_coverage_map(),
None => return,
};
Expand All @@ -42,14 +48,15 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
return;
}

add_unreachable_coverage(tcx, &mut function_coverage_map);

let mut mapgen = CoverageMapGenerator::new();

// Encode coverage mappings and generate function records
let mut function_data = Vec::new();
for (instance, function_coverage) in function_coverage_map {
debug!("Generate coverage map for: {:?}", instance);

let mangled_function_name = cx.tcx.symbol_name(instance).to_string();
debug!("Generate function coverage for {}, {:?}", cx.codegen_unit.name(), instance);
let mangled_function_name = tcx.symbol_name(instance).to_string();
let function_source_hash = function_coverage.source_hash();
let (expressions, counter_regions) =
function_coverage.get_expressions_and_counter_regions();
Expand Down Expand Up @@ -228,3 +235,156 @@ fn save_function_record(
let is_used = true;
coverageinfo::save_func_record_to_mod(cx, func_name_hash, func_record_val, is_used);
}

/// When finalizing the coverage map, `FunctionCoverage` only has the `CodeRegion`s and counters for
/// the functions that went through codegen; such as public functions and "used" functions
/// (functions referenced by other "used" or public items). Any other functions considered unused,
/// or "Unreachable" were still parsed and processed through the MIR stage.
///
/// We can find the unreachable functions by the set different of all MIR `DefId`s (`tcx` query
/// `mir_keys`) minus the codegenned `DefId`s (`tcx` query `collect_and_partition_mono_items`).
///
/// *HOWEVER* the codegenned `DefId`s are partitioned across multiple `CodegenUnit`s (CGUs), and
/// this function is processing a `function_coverage_map` for the functions (`Instance`/`DefId`)
/// allocated to only one of those CGUs. We must NOT inject any "Unreachable" functions's
/// `CodeRegion`s more than once, so we have to pick which CGU's `function_coverage_map` to add
/// each "Unreachable" function to.
///
/// Some constraints:
///
/// 1. The file name of an "Unreachable" function must match the file name of the existing
/// codegenned (covered) function to which the unreachable code regions will be added.
/// 2. The function to which the unreachable code regions will be added must not be a genaric
/// function (must not have type parameters) because the coverage tools will get confused
/// if the codegenned function has more than one instantiation and additional `CodeRegion`s
/// attached to only one of those instantiations.
fn add_unreachable_coverage<'tcx>(
tcx: TyCtxt<'tcx>,
function_coverage_map: &mut FxHashMap<Instance<'tcx>, FunctionCoverage<'tcx>>,
) {
// FIXME(#79622): Can this solution be simplified and/or improved? Are there other sources
// of compiler state data that might help (or better sources that could be exposed, but
// aren't yet)?

// Note: If the crate *only* defines generic functions, there are no codegenerated non-generic
// functions to add any unreachable code to. In this case, the unreachable code regions will
// have no coverage, instead of having coverage with zero executions.
//
// This is probably still an improvement over Clang, which does not generate any coverage
// for uninstantiated template functions.

let has_non_generic_def_ids =
function_coverage_map.keys().any(|instance| instance.def.attrs(tcx).len() == 0);

if !has_non_generic_def_ids {
// There are no non-generic functions to add unreachable `CodeRegion`s to
return;
}

let all_def_ids: DefIdSet =
tcx.mir_keys(LOCAL_CRATE).iter().map(|local_def_id| local_def_id.to_def_id()).collect();

let (codegenned_def_ids, _) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);

let mut unreachable_def_ids_by_file: FxHashMap<Symbol, Vec<DefId>> = FxHashMap::default();
for &non_codegenned_def_id in all_def_ids.difference(codegenned_def_ids) {
// Make sure the non-codegenned (unreachable) function has a file_name
if let Some(non_codegenned_file_name) = tcx.covered_file_name(non_codegenned_def_id) {
let def_ids = unreachable_def_ids_by_file
.entry(*non_codegenned_file_name)
.or_insert_with(|| Vec::new());
def_ids.push(non_codegenned_def_id);
}
}

if unreachable_def_ids_by_file.is_empty() {
// There are no unreachable functions with file names to add (in any CGU)
return;
}

// Since there may be multiple `CodegenUnit`s, some codegenned_def_ids may be codegenned in a
// different CGU, and will be added to the function_coverage_map for each CGU. Determine which
// function_coverage_map has the responsibility for publishing unreachable coverage
// based on file name:
//
// For each covered file name, sort ONLY the non-generic codegenned_def_ids, and if
// covered_def_ids.contains(the first def_id) for a given file_name, add the unreachable code
// region in this function_coverage_map. Otherwise, ignore it and assume another CGU's
// function_coverage_map will be adding it (because it will be first for one, and only one,
// of them).
let mut sorted_codegenned_def_ids: Vec<DefId> =
codegenned_def_ids.iter().map(|def_id| *def_id).collect();
sorted_codegenned_def_ids.sort_unstable();

let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default();
for &def_id in sorted_codegenned_def_ids.iter() {
// Only consider non-generic functions, to potentially add unreachable code regions
if tcx.generics_of(def_id).count() == 0 {
if let Some(covered_file_name) = tcx.covered_file_name(def_id) {
// Only add files known to have unreachable functions
if unreachable_def_ids_by_file.contains_key(covered_file_name) {
first_covered_def_id_by_file.entry(*covered_file_name).or_insert(def_id);
}
}
}
}

// Get the set of def_ids with coverage regions, known by *this* CoverageContext.
let cgu_covered_def_ids: DefIdSet =
function_coverage_map.keys().map(|instance| instance.def.def_id()).collect();

let mut cgu_covered_files: FxHashSet<Symbol> = first_covered_def_id_by_file
.iter()
.filter_map(
|(&file_name, def_id)| {
if cgu_covered_def_ids.contains(def_id) { Some(file_name) } else { None }
},
)
.collect();

// Find the first covered, non-generic function (instance) for each cgu_covered_file. Take the
// unreachable code regions for that file, and add them to the function.
//
// There are three `for` loops here, but (a) the lists have already been reduced to the minimum
// required values, the lists are further reduced (by `remove()` calls) when elements are no
// longer needed, and there are several opportunities to branch out of loops early.
for (instance, function_coverage) in function_coverage_map.iter_mut() {
if instance.def.attrs(tcx).len() > 0 {
continue;
}
// The covered function is not generic...
let covered_def_id = instance.def.def_id();
if let Some(covered_file_name) = tcx.covered_file_name(covered_def_id) {
if !cgu_covered_files.remove(&covered_file_name) {
continue;
}
// The covered function's file is one of the files with unreachable code regions, so
// all of the unreachable code regions for this file will be added to this function.
for def_id in
unreachable_def_ids_by_file.remove(&covered_file_name).into_iter().flatten()
{
// Note, this loop adds an unreachable code regions for each MIR-derived region.
// Alternatively, we could add a single code region for the maximum span of all
// code regions here.
//
// Observed downsides of this approach are:
//
// 1. The coverage results will appear inconsistent compared with the same (or
// similar) code in a function that is reached.
// 2. If the function is unreachable from one crate but reachable when compiling
// another referencing crate (such as a cross-crate reference to a
// generic function or inlined function), actual coverage regions overlaid
// on a single larger code span of `Zero` coverage can appear confusing or
// wrong. Chaning the unreachable coverage from a `code_region` to a
// `gap_region` can help, but still can look odd with `0` line counts for
// lines between executed (> 0) lines (such as for blank lines or comments).
for &region in tcx.covered_code_regions(def_id) {
function_coverage.add_unreachable_region(region.clone());
}
}
if cgu_covered_files.is_empty() {
break;
}
}
}
}
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![feature(bool_to_option)]
#![feature(option_expect_none)]
#![feature(box_patterns)]
#![feature(drain_filter)]
#![feature(try_blocks)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ fn run_compiler(
file_loader: None,
diagnostic_output,
stderr: None,
crate_name: None,
lint_caps: Default::default(),
register_lints: None,
override_queries: None,
Expand Down Expand Up @@ -307,7 +306,6 @@ fn run_compiler(
file_loader,
diagnostic_output,
stderr: None,
crate_name: None,
lint_caps: Default::default(),
register_lints: None,
override_queries: None,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ E0537: include_str!("./error_codes/E0537.md"),
E0538: include_str!("./error_codes/E0538.md"),
E0539: include_str!("./error_codes/E0539.md"),
E0541: include_str!("./error_codes/E0541.md"),
E0546: include_str!("./error_codes/E0546.md"),
E0550: include_str!("./error_codes/E0550.md"),
E0551: include_str!("./error_codes/E0551.md"),
E0552: include_str!("./error_codes/E0552.md"),
Expand Down Expand Up @@ -603,7 +604,6 @@ E0779: include_str!("./error_codes/E0779.md"),
E0543, // missing 'reason'
E0544, // multiple stability levels
E0545, // incorrect 'issue'
E0546, // missing 'feature'
E0547, // missing 'issue'
// E0548, // replaced with a generic attribute input check
// rustc_deprecated attribute must be paired with either stable or unstable
Expand Down
27 changes: 27 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0546.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
A feature name is missing.

Erroneous code example:

```compile_fail,E0546
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]

#[unstable(issue = "none")] // invalid
fn unstable_fn() {}

#[stable(since = "1.0.0")] // invalid
fn stable_fn() {}
```

To fix the issue you need to provide a feature name.

```
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]

#[unstable(feature = "unstable_fn", issue = "none")] // ok!
fn unstable_fn() {}

#[stable(feature = "stable_fn", since = "1.0.0")] // ok!
fn stable_fn() {}
```
10 changes: 4 additions & 6 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,10 @@ impl Annotatable {
pub fn derive_allowed(&self) -> bool {
match *self {
Annotatable::Stmt(ref stmt) => match stmt.kind {
ast::StmtKind::Item(ref item) => match item.kind {
ast::ItemKind::Struct(..)
| ast::ItemKind::Enum(..)
| ast::ItemKind::Union(..) => true,
_ => false,
},
ast::StmtKind::Item(ref item) => matches!(
item.kind,
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..)
),
_ => false,
},
Annotatable::Item(ref item) => match item.kind {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
// Collect the invoc regardless of whether or not attributes are permitted here
// expansion will eat the attribute so it won't error later.
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
if let Some(attr) = attr.0.as_ref() {
self.cfg.maybe_emit_expr_attr_err(attr)
}

// AstFragmentKind::Expr requires the macro to emit an expression.
return self
Expand Down Expand Up @@ -1231,7 +1233,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
self.cfg.configure_expr_kind(&mut expr.kind);

if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
if let Some(attr) = attr.0.as_ref() {
self.cfg.maybe_emit_expr_attr_err(attr)
}

return self
.collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::OptExpr)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@ impl StructField<'_> {
// Still necessary in couple of places
pub fn is_positional(&self) -> bool {
let first = self.ident.as_str().as_bytes()[0];
first >= b'0' && first <= b'9'
(b'0'..=b'9').contains(&first)
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
// as-is, we need to do some extra work here in order to make sure
// that function subtyping works correctly with respect to regions
//
// Note: this is a subtle algorithm. For a full explanation,
// please see the large comment at the end of the file in the (inlined) module
// `doc`.
// Note: this is a subtle algorithm. For a full explanation, please see
// the rustc dev guide:
// <https://rustc-dev-guide.rust-lang.org/borrow_check/region_inference/placeholders_and_universes.html>

let span = self.trace.cause.span;

Expand Down
Loading