Skip to content

Commit 8927649

Browse files
committed
Auto merge of #147603 - matthiaskrgr:rollup-j6uae13, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #138799 (core: simplify `Extend` for tuples) - #145897 (Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#4 of Batch #2]) - #146692 (Save x.py's help text for saving output time) - #147240 (Add an ACP list item to the library tracking issue template) - #147246 (Explain not existed key in BTreeMap::split_off) - #147393 (Extract most code from `define_feedable!`) - #147503 (Fix documentation of Instant::now on mac) - #147549 (Replace `LLVMRustContextCreate` with normal LLVM-C API calls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3be6803 + 64b37b9 commit 8927649

File tree

65 files changed

+698
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+698
-409
lines changed

.github/ISSUE_TEMPLATE/library_tracking_issue.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ If the feature is changed later, please add those PRs here as well.
5151

5252
(Remember to update the `S-tracking-*` label when checking boxes.)
5353

54+
- [ ] ACP: rust-lang/libs-team#...
5455
- [ ] Implementation: #...
5556
- [ ] Final comment period (FCP)[^1]
5657
- [ ] Stabilization PR

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4848
use rustc_span::Symbol;
4949
use rustc_target::spec::{RelocModel, TlsModel};
5050

51+
use crate::llvm::ToLlvmBool;
52+
5153
mod abi;
5254
mod allocator;
5355
mod asm;
@@ -384,7 +386,8 @@ unsafe impl Sync for ModuleLlvm {}
384386
impl ModuleLlvm {
385387
fn new(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
386388
unsafe {
387-
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
389+
let llcx = llvm::LLVMContextCreate();
390+
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
388391
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
389392
ModuleLlvm {
390393
llmod_raw,
@@ -396,7 +399,8 @@ impl ModuleLlvm {
396399

397400
fn new_metadata(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
398401
unsafe {
399-
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
402+
let llcx = llvm::LLVMContextCreate();
403+
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
400404
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
401405
ModuleLlvm {
402406
llmod_raw,
@@ -427,7 +431,8 @@ impl ModuleLlvm {
427431
dcx: DiagCtxtHandle<'_>,
428432
) -> Self {
429433
unsafe {
430-
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
434+
let llcx = llvm::LLVMContextCreate();
435+
llvm::LLVMContextSetDiscardValueNames(llcx, cgcx.fewer_names.to_llvm_bool());
431436
let llmod_raw = back::lto::parse_module(llcx, name, buffer, dcx);
432437
let tm = ModuleLlvm::tm_from_cgcx(cgcx, name.to_str().unwrap(), dcx);
433438

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,9 @@ pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) ->
905905

906906
unsafe extern "C" {
907907
// Create and destroy contexts.
908+
pub(crate) fn LLVMContextCreate() -> &'static mut Context;
908909
pub(crate) fn LLVMContextDispose(C: &'static mut Context);
910+
pub(crate) fn LLVMContextSetDiscardValueNames(C: &Context, Discard: Bool);
909911
pub(crate) fn LLVMGetMDKindIDInContext(
910912
C: &Context,
911913
Name: *const c_char,
@@ -1925,9 +1927,6 @@ unsafe extern "C" {
19251927
pub(crate) fn LLVMRustInstallErrorHandlers();
19261928
pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();
19271929

1928-
// Create and destroy contexts.
1929-
pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
1930-
19311930
// Operations on all values
19321931
pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
19331932
Val: &'a Value,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ extern "C" void LLVMRustSetLastError(const char *Err) {
123123
LastError = strdup(Err);
124124
}
125125

126-
extern "C" LLVMContextRef LLVMRustContextCreate(bool shouldDiscardNames) {
127-
auto ctx = new LLVMContext();
128-
ctx->setDiscardValueNames(shouldDiscardNames);
129-
return wrap(ctx);
130-
}
131-
132126
extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
133127
const char *Target) {
134128
#if LLVM_VERSION_GE(21, 0)
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//! Helper functions that serve as the immediate implementation of
2+
//! `tcx.$query(..)` and its variations.
3+
4+
use std::fmt::Debug;
5+
6+
use rustc_data_structures::fingerprint::Fingerprint;
7+
use rustc_query_system::dep_graph::{DepKind, DepNodeParams};
8+
use rustc_query_system::ich::StableHashingContext;
9+
use rustc_query_system::query::{QueryCache, QueryMode, try_get_cached};
10+
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
11+
12+
use crate::dep_graph;
13+
use crate::query::IntoQueryParam;
14+
use crate::query::erase::{self, Erase, EraseType};
15+
use crate::ty::TyCtxt;
16+
17+
/// Shared implementation of `tcx.$query(..)` and `tcx.at(span).$query(..)`
18+
/// for all queries.
19+
#[inline(always)]
20+
pub(crate) fn query_get_at<'tcx, Cache>(
21+
tcx: TyCtxt<'tcx>,
22+
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
23+
query_cache: &Cache,
24+
span: Span,
25+
key: Cache::Key,
26+
) -> Cache::Value
27+
where
28+
Cache: QueryCache,
29+
{
30+
let key = key.into_query_param();
31+
match try_get_cached(tcx, query_cache, &key) {
32+
Some(value) => value,
33+
None => execute_query(tcx, span, key, QueryMode::Get).unwrap(),
34+
}
35+
}
36+
37+
/// Shared implementation of `tcx.ensure_ok().$query(..)` for most queries,
38+
/// and `tcx.ensure_done().$query(..)` for all queries.
39+
#[inline]
40+
pub(crate) fn query_ensure<'tcx, Cache>(
41+
tcx: TyCtxt<'tcx>,
42+
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
43+
query_cache: &Cache,
44+
key: Cache::Key,
45+
check_cache: bool,
46+
) where
47+
Cache: QueryCache,
48+
{
49+
let key = key.into_query_param();
50+
if try_get_cached(tcx, query_cache, &key).is_none() {
51+
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache });
52+
}
53+
}
54+
55+
/// Shared implementation of `tcx.ensure_ok().$query(..)` for queries that
56+
/// have the `return_result_from_ensure_ok` modifier.
57+
#[inline]
58+
pub(crate) fn query_ensure_error_guaranteed<'tcx, Cache, T>(
59+
tcx: TyCtxt<'tcx>,
60+
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
61+
query_cache: &Cache,
62+
key: Cache::Key,
63+
check_cache: bool,
64+
) -> Result<(), ErrorGuaranteed>
65+
where
66+
Cache: QueryCache<Value = Erase<Result<T, ErrorGuaranteed>>>,
67+
Result<T, ErrorGuaranteed>: EraseType,
68+
{
69+
let key = key.into_query_param();
70+
if let Some(res) = try_get_cached(tcx, query_cache, &key) {
71+
erase::restore(res).map(drop)
72+
} else {
73+
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache })
74+
.map(erase::restore)
75+
.map(|res| res.map(drop))
76+
// Either we actually executed the query, which means we got a full `Result`,
77+
// or we can just assume the query succeeded, because it was green in the
78+
// incremental cache. If it is green, that means that the previous compilation
79+
// that wrote to the incremental cache compiles successfully. That is only
80+
// possible if the cache entry was `Ok(())`, so we emit that here, without
81+
// actually encoding the `Result` in the cache or loading it from there.
82+
.unwrap_or(Ok(()))
83+
}
84+
}
85+
86+
/// Common implementation of query feeding, used by `define_feedable!`.
87+
pub(crate) fn query_feed<'tcx, Cache, Value>(
88+
tcx: TyCtxt<'tcx>,
89+
dep_kind: DepKind,
90+
hasher: Option<fn(&mut StableHashingContext<'_>, &Value) -> Fingerprint>,
91+
cache: &Cache,
92+
key: Cache::Key,
93+
erased: Erase<Value>,
94+
) where
95+
Cache: QueryCache<Value = Erase<Value>>,
96+
Cache::Key: DepNodeParams<TyCtxt<'tcx>>,
97+
Value: EraseType + Debug,
98+
{
99+
let value = erase::restore::<Value>(erased);
100+
101+
match try_get_cached(tcx, cache, &key) {
102+
Some(old) => {
103+
let old = erase::restore::<Value>(old);
104+
if let Some(hasher) = hasher {
105+
let (value_hash, old_hash): (Fingerprint, Fingerprint) = tcx
106+
.with_stable_hashing_context(|mut hcx| {
107+
(hasher(&mut hcx, &value), hasher(&mut hcx, &old))
108+
});
109+
if old_hash != value_hash {
110+
// We have an inconsistency. This can happen if one of the two
111+
// results is tainted by errors. In this case, delay a bug to
112+
// ensure compilation is doomed, and keep the `old` value.
113+
tcx.dcx().delayed_bug(format!(
114+
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
115+
old value: {old:?}\nnew value: {value:?}",
116+
));
117+
}
118+
} else {
119+
// The query is `no_hash`, so we have no way to perform a sanity check.
120+
// If feeding the same value multiple times needs to be supported,
121+
// the query should not be marked `no_hash`.
122+
bug!(
123+
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
124+
old value: {old:?}\nnew value: {value:?}",
125+
)
126+
}
127+
}
128+
None => {
129+
let dep_node = dep_graph::DepNode::construct(tcx, dep_kind, &key);
130+
let dep_node_index = tcx.dep_graph.with_feed_task(dep_node, tcx, &value, hasher);
131+
cache.complete(key, erased, dep_node_index);
132+
}
133+
}
134+
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ use std::sync::Arc;
7070
use rustc_abi::Align;
7171
use rustc_arena::TypedArena;
7272
use rustc_ast::expand::allocator::AllocatorKind;
73-
use rustc_data_structures::fingerprint::Fingerprint;
7473
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
7574
use rustc_data_structures::sorted_map::SortedMap;
7675
use rustc_data_structures::steal::Steal;
@@ -88,9 +87,7 @@ use rustc_index::IndexVec;
8887
use rustc_lint_defs::LintId;
8988
use rustc_macros::rustc_queries;
9089
use rustc_query_system::ich::StableHashingContext;
91-
use rustc_query_system::query::{
92-
QueryCache, QueryMode, QueryStackDeferred, QueryState, try_get_cached,
93-
};
90+
use rustc_query_system::query::{QueryMode, QueryStackDeferred, QueryState};
9491
use rustc_session::Limits;
9592
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
9693
use rustc_session::cstore::{
@@ -103,6 +100,8 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
103100
use rustc_target::spec::{PanicStrategy, SanitizerSet};
104101
use {rustc_abi as abi, rustc_ast as ast, rustc_hir as hir};
105102

103+
pub use self::keys::{AsLocalKey, Key, LocalCrate};
104+
pub use self::plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
106105
use crate::infer::canonical::{self, Canonical};
107106
use crate::lint::LintExpectation;
108107
use crate::metadata::ModChild;
@@ -119,9 +118,7 @@ use crate::mir::interpret::{
119118
};
120119
use crate::mir::mono::{CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions};
121120
use crate::query::erase::{Erase, erase, restore};
122-
use crate::query::plumbing::{
123-
CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
124-
};
121+
use crate::query::plumbing::{CyclePlaceholder, DynamicQuery};
125122
use crate::traits::query::{
126123
CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal,
127124
CanonicalMethodAutoderefStepsGoal, CanonicalPredicateGoal, CanonicalTypeOpAscribeUserTypeGoal,
@@ -145,12 +142,11 @@ use crate::{dep_graph, mir, thir};
145142

146143
mod arena_cached;
147144
pub mod erase;
145+
pub(crate) mod inner;
148146
mod keys;
149-
pub use keys::{AsLocalKey, Key, LocalCrate};
150147
pub mod on_disk_cache;
151148
#[macro_use]
152149
pub mod plumbing;
153-
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
154150

155151
// Each of these queries corresponds to a function pointer field in the
156152
// `Providers` struct for requesting a value of that type, and a method

0 commit comments

Comments
 (0)