Skip to content

Commit 80cd51e

Browse files
committed
Auto merge of #156036 - jhpratt:rollup-FAjbWYG, r=jhpratt
Rollup of 6 pull requests Successful merges: - #149637 (Do not run jump-threading for GPUs) - #155948 (Fix order-dependent visibility diagnostics) - #155600 (Adds a couple UI tests for polonius) - #155995 (-Zembed-source: also embed external source) - #156019 (Feed cleanups) - #156031 (Return a single diagnostic from `lex_token_trees`.)
2 parents 0469a92 + 7e9e361 commit 80cd51e

28 files changed

Lines changed: 469 additions & 221 deletions

File tree

compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] {
4747

4848
fn make_file_info(source_file: &SourceFile, embed_source: bool) -> Option<FileInfo> {
4949
let has_md5 = source_file.src_hash.kind == SourceFileHashAlgorithm::Md5;
50-
let has_source = embed_source && source_file.src.is_some();
50+
let has_source = embed_source
51+
&& (source_file.src.is_some() || source_file.external_src.read().get_source().is_some());
5152

5253
if !has_md5 && !has_source {
5354
return None;
@@ -62,6 +63,8 @@ fn make_file_info(source_file: &SourceFile, embed_source: bool) -> Option<FileIn
6263
if embed_source {
6364
if let Some(src) = &source_file.src {
6465
info.source = Some(LineString::String(src.as_bytes().to_vec()));
66+
} else if let Some(src) = source_file.external_src.read().get_source() {
67+
info.source = Some(LineString::String(src.as_bytes().to_vec()));
6568
}
6669
}
6770

@@ -79,19 +82,22 @@ impl DebugContext {
7982
let span = hygiene::walk_chain_collapsed(span, function_span);
8083
match tcx.sess.source_map().lookup_line(span.lo()) {
8184
Ok(SourceFileAndLine { sf: file, line }) => {
82-
let file_id = self.add_source_file(&file);
85+
let file_id = self.add_source_file(tcx, &file);
8386
let line_pos = file.lines()[line];
8487
let col = file.relative_position(span.lo()) - line_pos;
8588

8689
(file_id, u64::try_from(line).unwrap() + 1, u64::from(col.to_u32()) + 1)
8790
}
88-
Err(file) => (self.add_source_file(&file), 0, 0),
91+
Err(file) => (self.add_source_file(tcx, &file), 0, 0),
8992
}
9093
}
9194

92-
pub(crate) fn add_source_file(&mut self, source_file: &SourceFile) -> FileId {
95+
pub(crate) fn add_source_file(&mut self, tcx: TyCtxt<'_>, source_file: &SourceFile) -> FileId {
9396
let cache_key = (source_file.stable_id, source_file.src_hash);
9497
*self.created_files.entry(cache_key).or_insert_with(|| {
98+
if self.embed_source && source_file.src.is_none() {
99+
tcx.sess.source_map().ensure_source_file_source_present(source_file);
100+
}
95101
let line_program: &mut LineProgram = &mut self.dwarf.unit.line_program;
96102
let line_strings: &mut LineStringTable = &mut self.dwarf.line_strings;
97103

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::borrow::Cow;
22
use std::fmt::{self, Write};
33
use std::hash::{Hash, Hasher};
44
use std::path::PathBuf;
5-
use std::sync::Arc;
65
use std::{assert_matches, iter, ptr};
76

87
use libc::{c_longlong, c_uint};
@@ -607,8 +606,16 @@ pub(crate) fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFi
607606
};
608607
let hash_value = hex_encode(source_file.src_hash.hash_bytes());
609608

610-
let source =
611-
cx.sess().opts.unstable_opts.embed_source.then_some(()).and(source_file.src.as_ref());
609+
let mut source = None;
610+
let external_src;
611+
if cx.sess().opts.unstable_opts.embed_source {
612+
source = source_file.src.as_deref().map(String::as_str);
613+
if source.is_none() {
614+
cx.tcx.sess.source_map().ensure_source_file_source_present(source_file);
615+
external_src = source_file.external_src.read();
616+
source = external_src.get_source();
617+
}
618+
}
612619

613620
create_file(DIB(cx), &file_name, &directory, &hash_value, hash_kind, source)
614621
}
@@ -626,7 +633,7 @@ fn create_file<'ll>(
626633
directory: &str,
627634
hash_value: &str,
628635
hash_kind: llvm::ChecksumKind,
629-
source: Option<&Arc<String>>,
636+
source: Option<&str>,
630637
) -> &'ll DIFile {
631638
unsafe {
632639
llvm::LLVMRustDIBuilderCreateFile(

compiler/rustc_middle/src/ty/context.rs

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::cmp::Ordering;
1010
use std::env::VarError;
1111
use std::ffi::OsStr;
1212
use std::hash::{Hash, Hasher};
13-
use std::marker::{PhantomData, PointeeSized};
13+
use std::marker::PointeeSized;
1414
use std::ops::{Bound, Deref};
1515
use std::sync::{Arc, OnceLock};
1616
use std::{fmt, iter, mem};
@@ -539,36 +539,14 @@ pub struct FreeRegionInfo {
539539

540540
/// This struct should only be created by `create_def`.
541541
#[derive(Copy, Clone)]
542-
pub struct TyCtxtFeed<'tcx, KEY: Copy> {
542+
pub struct TyCtxtFeed<'tcx, K: Copy> {
543543
pub tcx: TyCtxt<'tcx>,
544544
// Do not allow direct access, as downstream code must not mutate this field.
545-
key: KEY,
545+
key: K,
546546
}
547547

548-
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
549-
/// allowed to feed queries for that `DefId`.
550-
impl<KEY: Copy> !HashStable for TyCtxtFeed<'_, KEY> {}
551-
552-
/// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`.
553-
/// Use this to pass around when you have a `TyCtxt` elsewhere.
554-
/// Just an optimization to save space and not store hundreds of
555-
/// `TyCtxtFeed` in the resolver.
556-
#[derive(Copy, Clone)]
557-
pub struct Feed<'tcx, KEY: Copy> {
558-
_tcx: PhantomData<TyCtxt<'tcx>>,
559-
// Do not allow direct access, as downstream code must not mutate this field.
560-
key: KEY,
561-
}
562-
563-
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
564-
/// allowed to feed queries for that `DefId`.
565-
impl<KEY: Copy> !HashStable for Feed<'_, KEY> {}
566-
567-
impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
568-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
569-
self.key.fmt(f)
570-
}
571-
}
548+
/// Only queries that create a `DefId` are allowed to feed queries for that `DefId`.
549+
impl<K: Copy> !HashStable for TyCtxtFeed<'_, K> {}
572550

573551
/// Some workarounds to use cases that cannot use `create_def`.
574552
/// Do not add new ways to create `TyCtxtFeed` without consulting
@@ -622,28 +600,11 @@ impl<'tcx> TyCtxt<'tcx> {
622600
}
623601
}
624602

625-
impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
603+
impl<'tcx, K: Copy> TyCtxtFeed<'tcx, K> {
626604
#[inline(always)]
627-
pub fn key(&self) -> KEY {
605+
pub fn key(&self) -> K {
628606
self.key
629607
}
630-
631-
#[inline(always)]
632-
pub fn downgrade(self) -> Feed<'tcx, KEY> {
633-
Feed { _tcx: PhantomData, key: self.key }
634-
}
635-
}
636-
637-
impl<'tcx, KEY: Copy> Feed<'tcx, KEY> {
638-
#[inline(always)]
639-
pub fn key(&self) -> KEY {
640-
self.key
641-
}
642-
643-
#[inline(always)]
644-
pub fn upgrade(self, tcx: TyCtxt<'tcx>) -> TyCtxtFeed<'tcx, KEY> {
645-
TyCtxtFeed { tcx, key: self.key }
646-
}
647608
}
648609

649610
impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub use self::consts::{
8383
const_lit_matches_ty,
8484
};
8585
pub use self::context::{
86-
CtxtInterners, CurrentGcx, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
86+
CtxtInterners, CurrentGcx, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
8787
};
8888
pub use self::fold::*;
8989
pub use self::instance::{Instance, InstanceKind, ReifyReason};

compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ const MAX_COST: u8 = 100;
7676

7777
impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
7878
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
79+
if sess.target.is_like_gpu {
80+
// Jump threading can duplicate calls in control-flow.
81+
// This leads to incorrect code when done for so called "convergent" operations on GPU
82+
// targets, similar to how inline assembly cannot be duplicated on all targets.
83+
// Conservatively prevent this by disabling the pass.
84+
// See also issue #137086.
85+
return false;
86+
}
7987
sess.mir_opt_level() >= 2
8088
}
8189

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub(crate) fn lex_token_trees<'psess, 'src>(
115115
Err(errs) => {
116116
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
117117
// because the delimiter mismatch is more likely to be the root cause of error
118-
unmatched_closing_delims.extend(errs);
118+
unmatched_closing_delims.push(errs);
119119
Err(unmatched_closing_delims)
120120
}
121121
}

compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
1414
pub(super) fn lex_token_trees(
1515
&mut self,
1616
is_delimited: bool,
17-
) -> Result<(Spacing, TokenStream), Vec<Diag<'psess>>> {
17+
) -> Result<(Spacing, TokenStream), Diag<'psess>> {
1818
// Move past the opening delimiter.
1919
let open_spacing = self.bump_minimal();
2020

@@ -35,11 +35,11 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
3535
return if is_delimited {
3636
Ok((open_spacing, TokenStream::new(buf)))
3737
} else {
38-
Err(vec![self.close_delim_err(delim)])
38+
Err(self.close_delim_err(delim))
3939
};
4040
} else if self.token.kind == token::Eof {
4141
return if is_delimited {
42-
Err(vec![self.eof_err()])
42+
Err(self.eof_err())
4343
} else {
4444
Ok((open_spacing, TokenStream::new(buf)))
4545
};
@@ -54,7 +54,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
5454
fn lex_token_tree_open_delim(
5555
&mut self,
5656
open_delim: Delimiter,
57-
) -> Result<TokenTree, Vec<Diag<'psess>>> {
57+
) -> Result<TokenTree, Diag<'psess>> {
5858
// The span for beginning of the delimited section.
5959
let pre_span = self.token.span;
6060

0 commit comments

Comments
 (0)