Skip to content

Commit

Permalink
Auto merge of rust-lang#3648 - rust-lang:rustup-2024-06-05, r=RalfJung
Browse files Browse the repository at this point in the history
Automatic Rustup
  • Loading branch information
bors committed Jun 5, 2024
2 parents 3d6f7fb + 727a259 commit fda57ac
Show file tree
Hide file tree
Showing 22 changed files with 1,715 additions and 191 deletions.
98 changes: 60 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ chalk-solve = { version = "0.97.0", default-features = false }
chalk-ir = "0.97.0"
chalk-recursive = { version = "0.97.0", default-features = false }
chalk-derive = "0.97.0"
command-group = "2.0.1"
crossbeam-channel = "0.5.8"
dissimilar = "1.0.7"
dot = "0.1.4"
Expand All @@ -132,6 +131,7 @@ object = { version = "0.33.0", default-features = false, features = [
"macho",
"pe",
] }
process-wrap = { version = "8.0.2", features = ["std"] }
pulldown-cmark-to-cmark = "10.0.4"
pulldown-cmark = { version = "0.9.0", default-features = false }
rayon = "1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/flycheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tracing.workspace = true
rustc-hash.workspace = true
serde_json.workspace = true
serde.workspace = true
command-group.workspace = true
process-wrap.workspace = true

# local deps
paths.workspace = true
Expand Down
16 changes: 11 additions & 5 deletions crates/flycheck/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::{
process::{ChildStderr, ChildStdout, Command, Stdio},
};

use command_group::{CommandGroup, GroupChild};
use crossbeam_channel::Sender;
use process_wrap::std::{StdChildWrapper, StdCommandWrap};
use stdx::process::streaming_output;

/// Cargo output is structured as a one JSON per line. This trait abstracts parsing one line of
Expand Down Expand Up @@ -85,7 +85,7 @@ impl<T: ParseFromLine> CargoActor<T> {
}
}

struct JodGroupChild(GroupChild);
struct JodGroupChild(Box<dyn StdChildWrapper>);

impl Drop for JodGroupChild {
fn drop(&mut self) {
Expand Down Expand Up @@ -119,14 +119,20 @@ impl<T> fmt::Debug for CommandHandle<T> {
impl<T: ParseFromLine> CommandHandle<T> {
pub(crate) fn spawn(mut command: Command, sender: Sender<T>) -> std::io::Result<Self> {
command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null());
let mut child = command.group_spawn().map(JodGroupChild)?;

let program = command.get_program().into();
let arguments = command.get_args().map(|arg| arg.into()).collect::<Vec<OsString>>();
let current_dir = command.get_current_dir().map(|arg| arg.to_path_buf());

let stdout = child.0.inner().stdout.take().unwrap();
let stderr = child.0.inner().stderr.take().unwrap();
let mut child = StdCommandWrap::from(command);
#[cfg(unix)]
child.wrap(process_wrap::std::ProcessSession);
#[cfg(windows)]
child.wrap(process_wrap::std::JobObject);
let mut child = child.spawn().map(JodGroupChild)?;

let stdout = child.0.stdout().take().unwrap();
let stderr = child.0.stderr().take().unwrap();

let actor = CargoActor::<T>::new(sender, stdout, stderr);
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
Expand Down
27 changes: 27 additions & 0 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ pub enum Message {
/// Request adding a diagnostic with fixes included to a file
AddDiagnostic { id: usize, workspace_root: AbsPathBuf, diagnostic: Diagnostic },

/// Request clearing all previous diagnostics
ClearDiagnostics { id: usize },

/// Request check progress notification to client
Progress {
/// Flycheck instance ID
Expand All @@ -180,6 +183,9 @@ impl fmt::Debug for Message {
.field("workspace_root", workspace_root)
.field("diagnostic_code", &diagnostic.code.as_ref().map(|it| &it.code))
.finish(),
Message::ClearDiagnostics { id } => {
f.debug_struct("ClearDiagnostics").field("id", id).finish()
}
Message::Progress { id, progress } => {
f.debug_struct("Progress").field("id", id).field("progress", progress).finish()
}
Expand Down Expand Up @@ -220,13 +226,22 @@ struct FlycheckActor {
command_handle: Option<CommandHandle<CargoCheckMessage>>,
/// The receiver side of the channel mentioned above.
command_receiver: Option<Receiver<CargoCheckMessage>>,

status: FlycheckStatus,
}

enum Event {
RequestStateChange(StateChange),
CheckEvent(Option<CargoCheckMessage>),
}

#[derive(PartialEq)]
enum FlycheckStatus {
Started,
DiagnosticSent,
Finished,
}

const SAVED_FILE_PLACEHOLDER: &str = "$saved_file";

impl FlycheckActor {
Expand All @@ -248,6 +263,7 @@ impl FlycheckActor {
manifest_path,
command_handle: None,
command_receiver: None,
status: FlycheckStatus::Finished,
}
}

Expand Down Expand Up @@ -298,12 +314,14 @@ impl FlycheckActor {
self.command_handle = Some(command_handle);
self.command_receiver = Some(receiver);
self.report_progress(Progress::DidStart);
self.status = FlycheckStatus::Started;
}
Err(error) => {
self.report_progress(Progress::DidFailToRestart(format!(
"Failed to run the following command: {} error={}",
formatted_command, error
)));
self.status = FlycheckStatus::Finished;
}
}
}
Expand All @@ -323,7 +341,11 @@ impl FlycheckActor {
error
);
}
if self.status == FlycheckStatus::Started {
self.send(Message::ClearDiagnostics { id: self.id });
}
self.report_progress(Progress::DidFinish(res));
self.status = FlycheckStatus::Finished;
}
Event::CheckEvent(Some(message)) => match message {
CargoCheckMessage::CompilerArtifact(msg) => {
Expand All @@ -341,11 +363,15 @@ impl FlycheckActor {
message = msg.message,
"diagnostic received"
);
if self.status == FlycheckStatus::Started {
self.send(Message::ClearDiagnostics { id: self.id });
}
self.send(Message::AddDiagnostic {
id: self.id,
workspace_root: self.root.clone(),
diagnostic: msg,
});
self.status = FlycheckStatus::DiagnosticSent;
}
},
}
Expand All @@ -362,6 +388,7 @@ impl FlycheckActor {
);
command_handle.cancel();
self.report_progress(Progress::DidCancel);
self.status = FlycheckStatus::Finished;
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub fn expand_speculative(
// prefer tokens of the same kind and text
// Note the inversion of the score here, as we want to prefer the first token in case
// of all tokens having the same score
(t.kind() != token_to_map.kind()) as u8 + (t.text() != token_to_map.text()) as u8
(t.kind() != token_to_map.kind()) as u8 + 2 * ((t.text() != token_to_map.text()) as u8)
})?;
Some((node.syntax_node(), token))
}
Expand Down
22 changes: 9 additions & 13 deletions crates/hir-expand/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,20 @@ impl<FileId: Copy, N: AstNode> InFileWrapper<FileId, N> {
// region:specific impls

impl InFile<&SyntaxNode> {
/// Skips the attributed item that caused the macro invocation we are climbing up
pub fn ancestors_with_macros_skip_attr_item(
/// Traverse up macro calls and skips the macro invocation node
pub fn ancestors_with_macros(
self,
db: &dyn db::ExpandDatabase,
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() {
Some(parent) => Some(node.with_value(parent)),
None => {
let macro_file_id = node.file_id.macro_file()?;
let parent_node = macro_file_id.call_node(db);
if macro_file_id.is_attr_macro(db) {
// macro call was an attributed item, skip it
// FIXME: does this fail if this is a direct expansion of another macro?
parent_node.map(|node| node.parent()).transpose()
} else {
Some(parent_node)
}
}
None => db
.lookup_intern_macro_call(node.file_id.macro_file()?.macro_call_id)
.to_node_item(db)
.syntax()
.cloned()
.map(|node| node.parent())
.transpose(),
};
iter::successors(succ(&self.cloned()), succ)
}
Expand Down
16 changes: 14 additions & 2 deletions crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use std::{fmt, hash::Hash};
use base_db::{salsa::impl_intern_value_trivial, CrateId, FileId};
use either::Either;
use span::{
Edition, ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData,
SyntaxContextId,
Edition, ErasedFileAstId, FileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor,
SyntaxContextData, SyntaxContextId,
};
use syntax::{
ast::{self, AstNode},
Expand Down Expand Up @@ -546,6 +546,18 @@ impl MacroCallLoc {
}
}

pub fn to_node_item(&self, db: &dyn ExpandDatabase) -> InFile<ast::Item> {
match self.kind {
MacroCallKind::FnLike { ast_id, .. } => {
InFile::new(ast_id.file_id, ast_id.map(FileAstId::upcast).to_node(db))
}
MacroCallKind::Derive { ast_id, .. } => {
InFile::new(ast_id.file_id, ast_id.map(FileAstId::upcast).to_node(db))
}
MacroCallKind::Attr { ast_id, .. } => InFile::new(ast_id.file_id, ast_id.to_node(db)),
}
}

fn expand_to(&self) -> ExpandTo {
match self.kind {
MacroCallKind::FnLike { expand_to, .. } => expand_to,
Expand Down
Loading

0 comments on commit fda57ac

Please sign in to comment.