Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@
path = src/gcc
url = https://github.com/rust-lang/gcc.git
shallow = true
[submodule "src/tpde"]
path = src/tpde
url = https://github.com/rust-lang/tpde.git
shallow = true
7 changes: 5 additions & 2 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@
# Whether to build Enzyme as AutoDiff backend.
#llvm.enzyme = false

# Whether to build LLVM with support for it's gpu offload runtime.
# Whether to build LLVM with support for its gpu offload runtime.
#llvm.offload = false

# Whether to build TPDE as an experimental alternative LLVM backend.
#llvm.tpde = false

# Absolute path to the directory containing ClangConfig.cmake
#llvm.offload-clang-dir = ""

Expand Down Expand Up @@ -842,7 +845,7 @@
# sysroot.
#rust.llvm-tools = true

# Indicates whether the `self-contained` llvm-bitcode-linker, will be made available
# Indicates whether the `self-contained` llvm-bitcode-linker will be made available
# in the sysroot. It is required for running nvptx tests.
#rust.llvm-bitcode-linker = false

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
// loop iteration. In this case, try using the loop terminator location in
// `find_sub_region_live_at`.
if let Some(loop_terminator_location) =
regioncx.find_loop_terminator_location(borrow.region, body)
regioncx.find_loop_terminator_location(borrow.region, body, location)
{
region_sub = self
.regioncx
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/region_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,16 +816,19 @@ impl<'tcx> RegionInferenceContextInner<'tcx> {
&self,
r: RegionVid,
body: &Body<'_>,
from_location: Location,
) -> Option<Location> {
let scc = self.constraint_sccs.scc(r);
let locations = self.scc_values.locations_outlived_by(scc);
for location in locations {
let bb = &body[location.block];
if let Some(terminator) = &bb.terminator
if from_location.is_predecessor_of(location, body) {
let bb = &body[location.block];
if let Some(terminator) = &bb.terminator
// terminator of a loop should be TerminatorKind::FalseUnwind
&& let TerminatorKind::FalseUnwind { .. } = terminator.kind
{
return Some(location);
{
return Some(location);
}
}
}
None
Expand Down
53 changes: 38 additions & 15 deletions compiler/rustc_interface/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,51 @@
//! Users can override these limits via an attribute on the crate like
//! `#![recursion_limit="22"]`. This pass just looks for those attributes.
use rustc_ast::{self as ast, DUMMY_NODE_ID};
use rustc_attr_ir::target::Target;
use rustc_attr_ir::{Attribute, find_attr};
use rustc_middle::query::Providers;
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_feature::Features;
use rustc_session::{Limits, Session};
use rustc_span::{DUMMY_SP, sym};
use rustc_structures::Limit;

pub(crate) fn provide(providers: &mut Providers) {
providers.limits = |tcx, ()| {
let attrs = tcx.hir_krate_attrs();
Limits {
recursion_limit: get_recursion_limit(tcx.hir_krate_attrs(), tcx.sess),
move_size_limit: find_attr!(attrs, MoveSizeLimit { limit } => *limit)
.unwrap_or(Limit::new(tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0))),
type_length_limit: find_attr!(attrs, TypeLengthLimit { limit } => *limit)
.unwrap_or(Limit::new(2usize.pow(24))),
pattern_complexity_limit: find_attr!(attrs, PatternComplexityLimit { limit } => *limit)
.unwrap_or(Limit::unlimited()),
}
pub fn get_limits(krate_attrs: &[ast::Attribute], sess: &Session, features: &Features) -> Limits {
let attrs = AttributeParser::parse_limited_all(
sess,
&krate_attrs,
Some(&|attr| {
attr.has_any_name(&[
sym::recursion_limit,
sym::move_size_limit,
sym::type_length_limit,
sym::pattern_complexity_limit,
])
}),
Target::Crate,
DUMMY_SP,
DUMMY_NODE_ID,
Some(features),
// errors are fatal here, but lints aren't.
// If things aren't fatal we continue, and will parse this again.
// That makes the same lint trigger again.
// So, no lints here to avoid duplicates.
ShouldEmit::EarlyFatal { also_emit_lints: false },
None,
);
let attrs = &attrs;
Limits {
recursion_limit: get_recursion_limit(attrs, sess),
move_size_limit: find_attr!(attrs, MoveSizeLimit { limit } => *limit)
.unwrap_or(Limit::new(sess.opts.unstable_opts.move_size_limit.unwrap_or(0))),
type_length_limit: find_attr!(attrs, TypeLengthLimit { limit } => *limit)
.unwrap_or(Limit::new(2usize.pow(24))),
pattern_complexity_limit: find_attr!(attrs, PatternComplexityLimit { limit } => *limit)
.unwrap_or(Limit::unlimited()),
}
}

// This one is separate because it must be read prior to macro expansion.
pub(crate) fn get_recursion_limit(attrs: &[Attribute], sess: &Session) -> Limit {
fn get_recursion_limit(attrs: &[Attribute], sess: &Session) -> Limit {
let limit_from_crate = find_attr!(attrs, RecursionLimit { limit } => limit.0).unwrap_or(128);
Limit::new(
sess.opts
Expand Down
27 changes: 6 additions & 21 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use rustc_session::{IncrCompSession, Session};
use rustc_span::{
DUMMY_SP, ErrorGuaranteed, ExpnKind, SourceFileHash, SourceFileHashAlgorithm, Span, Symbol, sym,
};
use rustc_structures::{CrateType, Limit};
use rustc_structures::CrateType;
use rustc_trait_selection::{solve, traits};
use tracing::{info, instrument};

Expand Down Expand Up @@ -201,7 +201,7 @@ fn configure_and_expand(
}

// Create the config for macro expansion
let recursion_limit = get_recursion_limit(pre_configured_attrs, sess);
let recursion_limit = tcx.recursion_limit();
let cfg = rustc_expand::expand::ExpansionConfig {
crate_name,
features,
Expand Down Expand Up @@ -905,7 +905,6 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
providers.queries.env_var_os = env_var_os;
providers.queries.proc_macro_decls_static = |tcx, _| tcx.hir_crate_items(()).proc_macro_decls();
rustc_ast_lowering::provide(&mut providers.queries);
limits::provide(&mut providers.queries);
rustc_expand_queries::provide(&mut providers.queries);
rustc_const_eval::provide(providers);
rustc_middle::hir::provide(&mut providers.queries);
Expand Down Expand Up @@ -1037,11 +1036,13 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
feed.crate_name(crate_name);

let feed = tcx.feed_unit_query();
feed.features_query(tcx.arena.alloc(rustc_expand::config::features(
let features = tcx.arena.alloc(rustc_expand::config::features(
tcx.sess,
&pre_configured_attrs,
crate_name,
)));
));
feed.features_query(features);
feed.limits(limits::get_limits(&pre_configured_attrs, tcx.sess, features));
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
feed.output_filenames(Arc::new(outputs));

Expand Down Expand Up @@ -1523,19 +1524,3 @@ pub fn collect_crate_types(
fn default_output_for_target(sess: &Session) -> CrateType {
if !sess.target.executables { CrateType::StaticLib } else { CrateType::Executable }
}

fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit {
let attr = AttributeParser::parse_limited_sym_should_emit(
sess,
&krate_attrs,
&[sym::recursion_limit],
DUMMY_SP,
None,
// errors are fatal here, but lints aren't.
// If things aren't fatal we continue, and will parse this again.
// That makes the same lint trigger again.
// So, no lints here to avoid duplicates.
ShouldEmit::EarlyFatal { also_emit_lints: false },
);
crate::limits::get_recursion_limit(attr.as_slice(), sess)
}
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,7 @@ rustc_queries! {
}

query limits(key: ()) -> Limits {
feedable
desc { "looking up limits" }
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ pub const fn likely(b: bool) -> bool {
/// // Use outside of a branch condition may still influence a nearby branch
/// let cond = unlikely(x != 0);
/// if cond {
/// println!("this branch is likely to be taken");
/// println!("this branch is unlikely to be taken");
/// }
/// }
/// ```
Expand Down
19 changes: 19 additions & 0 deletions library/std/src/sys/fs/unsupported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ pub struct FileType(!);
#[derive(Debug)]
pub struct DirBuilder {}

// Dummy Drops so that `needs_drop::<std::fs::File>()` etc. is true independent of platform,
// avoiding a portability hazard.
// The types not listed here are pure data and don’t implement Drop even when real.
impl Drop for File {
fn drop(&mut self) {
self.0
}
}
impl Drop for ReadDir {
fn drop(&mut self) {
self.0
}
}
impl Drop for DirEntry {
fn drop(&mut self) {
self.0
}
}

impl FileAttr {
pub fn size(&self) -> u64 {
self.0
Expand Down
7 changes: 7 additions & 0 deletions library/std/src/sys/fs/vexos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@ impl Drop for File {
}
}

impl Drop for ReadDir {
fn drop(&mut self) {
// Dummy Drop so that `needs_drop::<ReadDir>()` is true independent of platform.
self.0
}
}

pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
// While there *is* a userspace function for reading file directories,
// the necessary implementation cannot currently be done cleanly, as
Expand Down
20 changes: 20 additions & 0 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,26 @@ impl CommandLineStep for Assemble {

maybe_install_llvm_bitcode_linker();

if builder.config.llvm_tpde {
debug!("`llvm_tpde` requested");
// The rustc TPDE integration is Linux-only for now
if !host.contains("linux") {
builder.info(&format!("host target `{host}` not supported by tpde. skipping"));
} else {
// Put TPDE next to librustc_driver.so
let tpde_output = builder.ensure(llvm::Tpde { target: host });
let target_libdir =
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
let target_dst_lib =
target_libdir.join(tpde_output.plugin_path().file_name().unwrap());
builder.copy_link(
tpde_output.plugin_path(),
&target_dst_lib,
FileType::NativeLibrary,
);
}
}

// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
// so that it can be found when the newly built `rustc` is run.
debug!(
Expand Down
Loading
Loading