Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d5e6b6f
core: simplify `Extend` for tuples
joboet Mar 21, 2025
af66ece
Add tests for `Extend<(T, U)> for (ExtendT, ExtendU)`
steffahn Feb 22, 2025
6eef285
Add an ACP list item to the library tracking issue template
tgross35 Oct 1, 2025
8fcb7e1
extended doc comment
Kivooeo Oct 1, 2025
c33b667
Hoist stranded `use` declarations
Zalathar Oct 6, 2025
b97bdcb
Extract query-method inner functions to `query::inner`
Zalathar Oct 8, 2025
cb0c092
Prepare `define_feedable!` for code extraction
Zalathar Oct 6, 2025
a282336
Extract most code from `define_feedable!`
Zalathar Oct 6, 2025
0abecda
Replace `LLVMRustContextCreate` with normal LLVM-C API calls
AMS21 Oct 10, 2025
dff4561
Fix documentation of Instant::now on mac
stepancheg Oct 10, 2025
340702c
write x.py's help for saving output time
Shunpoco Sep 17, 2025
6ca6981
Add test batch 4
Oneirical Aug 20, 2025
817720c
Rollup merge of #138799 - joboet:extend-tuple, r=Mark-Simulacrum
matthiaskrgr Oct 12, 2025
f58eab7
Rollup merge of #145897 - Oneirical:uncountable-integer-11, r=jieyouxu
matthiaskrgr Oct 12, 2025
f64f890
Rollup merge of #146692 - Shunpoco:issue-141903, r=Mark-Simulacrum
matthiaskrgr Oct 12, 2025
8a2ec10
Rollup merge of #147240 - tgross35:tracking-template, r=Mark-Simulacrum
matthiaskrgr Oct 12, 2025
b96bd11
Rollup merge of #147246 - Kivooeo:btree-map-split-off-doc, r=Mark-Sim…
matthiaskrgr Oct 12, 2025
0765b43
Rollup merge of #147393 - Zalathar:feed, r=cjgillot
matthiaskrgr Oct 12, 2025
f5a6b1b
Rollup merge of #147503 - stepancheg:instant-now-mac-doc, r=joboet
matthiaskrgr Oct 12, 2025
64b37b9
Rollup merge of #147549 - AMS21:remove_llvm_rust_context_create, r=Za…
matthiaskrgr Oct 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/library_tracking_issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ If the feature is changed later, please add those PRs here as well.

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

- [ ] ACP: rust-lang/libs-team#...
- [ ] Implementation: #...
- [ ] Final comment period (FCP)[^1]
- [ ] Stabilization PR
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_span::Symbol;
use rustc_target::spec::{RelocModel, TlsModel};

use crate::llvm::ToLlvmBool;

mod abi;
mod allocator;
mod asm;
Expand Down Expand Up @@ -384,7 +386,8 @@ unsafe impl Sync for ModuleLlvm {}
impl ModuleLlvm {
fn new(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llcx = llvm::LLVMContextCreate();
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
ModuleLlvm {
llmod_raw,
Expand All @@ -396,7 +399,8 @@ impl ModuleLlvm {

fn new_metadata(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llcx = llvm::LLVMContextCreate();
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
ModuleLlvm {
llmod_raw,
Expand Down Expand Up @@ -427,7 +431,8 @@ impl ModuleLlvm {
dcx: DiagCtxtHandle<'_>,
) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
let llcx = llvm::LLVMContextCreate();
llvm::LLVMContextSetDiscardValueNames(llcx, cgcx.fewer_names.to_llvm_bool());
let llmod_raw = back::lto::parse_module(llcx, name, buffer, dcx);
let tm = ModuleLlvm::tm_from_cgcx(cgcx, name.to_str().unwrap(), dcx);

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,9 @@ pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) ->

unsafe extern "C" {
// Create and destroy contexts.
pub(crate) fn LLVMContextCreate() -> &'static mut Context;
pub(crate) fn LLVMContextDispose(C: &'static mut Context);
pub(crate) fn LLVMContextSetDiscardValueNames(C: &Context, Discard: Bool);
pub(crate) fn LLVMGetMDKindIDInContext(
C: &Context,
Name: *const c_char,
Expand Down Expand Up @@ -1925,9 +1927,6 @@ unsafe extern "C" {
pub(crate) fn LLVMRustInstallErrorHandlers();
pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();

// Create and destroy contexts.
pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;

// Operations on all values
pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
Val: &'a Value,
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ extern "C" void LLVMRustSetLastError(const char *Err) {
LastError = strdup(Err);
}

extern "C" LLVMContextRef LLVMRustContextCreate(bool shouldDiscardNames) {
auto ctx = new LLVMContext();
ctx->setDiscardValueNames(shouldDiscardNames);
return wrap(ctx);
}

extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
const char *Target) {
#if LLVM_VERSION_GE(21, 0)
Expand Down
134 changes: 134 additions & 0 deletions compiler/rustc_middle/src/query/inner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
//! Helper functions that serve as the immediate implementation of
//! `tcx.$query(..)` and its variations.
use std::fmt::Debug;

use rustc_data_structures::fingerprint::Fingerprint;
use rustc_query_system::dep_graph::{DepKind, DepNodeParams};
use rustc_query_system::ich::StableHashingContext;
use rustc_query_system::query::{QueryCache, QueryMode, try_get_cached};
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};

use crate::dep_graph;
use crate::query::IntoQueryParam;
use crate::query::erase::{self, Erase, EraseType};
use crate::ty::TyCtxt;

/// Shared implementation of `tcx.$query(..)` and `tcx.at(span).$query(..)`
/// for all queries.
#[inline(always)]
pub(crate) fn query_get_at<'tcx, Cache>(
tcx: TyCtxt<'tcx>,
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
query_cache: &Cache,
span: Span,
key: Cache::Key,
) -> Cache::Value
where
Cache: QueryCache,
{
let key = key.into_query_param();
match try_get_cached(tcx, query_cache, &key) {
Some(value) => value,
None => execute_query(tcx, span, key, QueryMode::Get).unwrap(),
}
}

/// Shared implementation of `tcx.ensure_ok().$query(..)` for most queries,
/// and `tcx.ensure_done().$query(..)` for all queries.
#[inline]
pub(crate) fn query_ensure<'tcx, Cache>(
tcx: TyCtxt<'tcx>,
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
query_cache: &Cache,
key: Cache::Key,
check_cache: bool,
) where
Cache: QueryCache,
{
let key = key.into_query_param();
if try_get_cached(tcx, query_cache, &key).is_none() {
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache });
}
}

/// Shared implementation of `tcx.ensure_ok().$query(..)` for queries that
/// have the `return_result_from_ensure_ok` modifier.
#[inline]
pub(crate) fn query_ensure_error_guaranteed<'tcx, Cache, T>(
tcx: TyCtxt<'tcx>,
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
query_cache: &Cache,
key: Cache::Key,
check_cache: bool,
) -> Result<(), ErrorGuaranteed>
where
Cache: QueryCache<Value = Erase<Result<T, ErrorGuaranteed>>>,
Result<T, ErrorGuaranteed>: EraseType,
{
let key = key.into_query_param();
if let Some(res) = try_get_cached(tcx, query_cache, &key) {
erase::restore(res).map(drop)
} else {
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache })
.map(erase::restore)
.map(|res| res.map(drop))
// Either we actually executed the query, which means we got a full `Result`,
// or we can just assume the query succeeded, because it was green in the
// incremental cache. If it is green, that means that the previous compilation
// that wrote to the incremental cache compiles successfully. That is only
// possible if the cache entry was `Ok(())`, so we emit that here, without
// actually encoding the `Result` in the cache or loading it from there.
.unwrap_or(Ok(()))
}
}

/// Common implementation of query feeding, used by `define_feedable!`.
pub(crate) fn query_feed<'tcx, Cache, Value>(
tcx: TyCtxt<'tcx>,
dep_kind: DepKind,
hasher: Option<fn(&mut StableHashingContext<'_>, &Value) -> Fingerprint>,
cache: &Cache,
key: Cache::Key,
erased: Erase<Value>,
) where
Cache: QueryCache<Value = Erase<Value>>,
Cache::Key: DepNodeParams<TyCtxt<'tcx>>,
Value: EraseType + Debug,
{
let value = erase::restore::<Value>(erased);

match try_get_cached(tcx, cache, &key) {
Some(old) => {
let old = erase::restore::<Value>(old);
if let Some(hasher) = hasher {
let (value_hash, old_hash): (Fingerprint, Fingerprint) = tcx
.with_stable_hashing_context(|mut hcx| {
(hasher(&mut hcx, &value), hasher(&mut hcx, &old))
});
if old_hash != value_hash {
// We have an inconsistency. This can happen if one of the two
// results is tainted by errors. In this case, delay a bug to
// ensure compilation is doomed, and keep the `old` value.
tcx.dcx().delayed_bug(format!(
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
old value: {old:?}\nnew value: {value:?}",
));
}
} else {
// The query is `no_hash`, so we have no way to perform a sanity check.
// If feeding the same value multiple times needs to be supported,
// the query should not be marked `no_hash`.
bug!(
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
old value: {old:?}\nnew value: {value:?}",
)
}
}
None => {
let dep_node = dep_graph::DepNode::construct(tcx, dep_kind, &key);
let dep_node_index = tcx.dep_graph.with_feed_task(dep_node, tcx, &value, hasher);
cache.complete(key, erased, dep_node_index);
}
}
}
14 changes: 5 additions & 9 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ use std::sync::Arc;
use rustc_abi::Align;
use rustc_arena::TypedArena;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::steal::Steal;
Expand All @@ -88,9 +87,7 @@ use rustc_index::IndexVec;
use rustc_lint_defs::LintId;
use rustc_macros::rustc_queries;
use rustc_query_system::ich::StableHashingContext;
use rustc_query_system::query::{
QueryCache, QueryMode, QueryStackDeferred, QueryState, try_get_cached,
};
use rustc_query_system::query::{QueryMode, QueryStackDeferred, QueryState};
use rustc_session::Limits;
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
use rustc_session::cstore::{
Expand All @@ -103,6 +100,8 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_target::spec::{PanicStrategy, SanitizerSet};
use {rustc_abi as abi, rustc_ast as ast, rustc_hir as hir};

pub use self::keys::{AsLocalKey, Key, LocalCrate};
pub use self::plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
use crate::infer::canonical::{self, Canonical};
use crate::lint::LintExpectation;
use crate::metadata::ModChild;
Expand All @@ -119,9 +118,7 @@ use crate::mir::interpret::{
};
use crate::mir::mono::{CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions};
use crate::query::erase::{Erase, erase, restore};
use crate::query::plumbing::{
CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
};
use crate::query::plumbing::{CyclePlaceholder, DynamicQuery};
use crate::traits::query::{
CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal,
CanonicalMethodAutoderefStepsGoal, CanonicalPredicateGoal, CanonicalTypeOpAscribeUserTypeGoal,
Expand All @@ -145,12 +142,11 @@ use crate::{dep_graph, mir, thir};

mod arena_cached;
pub mod erase;
pub(crate) mod inner;
mod keys;
pub use keys::{AsLocalKey, Key, LocalCrate};
pub mod on_disk_cache;
#[macro_use]
pub mod plumbing;
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};

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