Skip to content
Draft
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
22 changes: 21 additions & 1 deletion crates/rpl_interface/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_span::Symbol;
// use crate::passes::create_rpl_ctxt;

pub static RPL_ARGS_ENV: &str = "RPL_ARGS";
pub static RPL_PATS_ENV: &str = "RPL_PATS";
Comment on lines 18 to +19
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RPL_PATS_ENV is introduced here, but the driver still hard-codes "RPL_PATS". To avoid drift/typos, consider re-exporting RPL_PATS_ENV from crates/rpl_interface/src/lib.rs (like RPL_ARGS_ENV) and using the constant everywhere.

Copilot uses AI. Check for mistakes.

fn track_rpl_args(psess: &mut ParseSess, args_env_var: &Option<String>) {
psess.env_depinfo.get_mut().insert((
Expand All @@ -40,6 +41,20 @@ fn track_files(psess: &mut ParseSess) {
}
}

fn track_rpl_pats(psess: &mut ParseSess, pats_env_var: Option<String>, pats: &[String]) {
let rpl_pats = pats_env_var;
psess
.env_depinfo
.get_mut()
.insert((Symbol::intern(RPL_PATS_ENV), rpl_pats.as_deref().map(Symbol::intern)));

let pat_depinfo = psess.file_depinfo.get_mut();

for path in pats {
pat_depinfo.insert(Symbol::intern(path));
}
Comment on lines +51 to +55
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

track_rpl_pats records the raw RPL_PATS arguments into file_depinfo, but RPL_PATS is commonly set to a directory (e.g. docs/patterns-pest). Tracking only the directory path won’t cause Cargo/rustc to rerun when an existing .rpl file inside that directory changes (directory mtime doesn’t update on file content changes). Consider tracking the actual .rpl files read (e.g. the canonicalized paths produced by collect_file_from_string_args/traverse_rpl) rather than the input roots.

Copilot uses AI. Check for mistakes.
}

/// This is different from `DefaultCallbacks` that it will inform Cargo to track the value of
/// `RPL_ARGS` environment variable.
pub struct RustcCallbacks {
Expand All @@ -66,13 +81,15 @@ impl rustc_driver::Callbacks for DefaultCallbacks {}

pub struct RplCallbacks {
rpl_args_var: Option<String>,
rpl_pats_var: Option<String>,
pattern_paths: Option<Vec<String>>,
}

impl RplCallbacks {
pub fn new(rpl_args_var: Option<String>, pattern_paths: Option<Vec<String>>) -> Self {
pub fn new(rpl_args_var: Option<String>, rpl_pats_var: Option<String>, pattern_paths: Option<Vec<String>>) -> Self {
Self {
rpl_args_var,
rpl_pats_var,
pattern_paths,
}
}
Expand Down Expand Up @@ -102,9 +119,12 @@ impl rustc_driver::Callbacks for RplCallbacks {
#[allow(rustc::bad_opt_access)]
fn config(&mut self, config: &mut interface::Config) {
let rpl_args_var = self.rpl_args_var.take();
let rpl_pats_var = self.rpl_pats_var.take();
let rpl_pats = self.pattern_paths.clone();
Comment on lines 121 to +123
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let rpl_pats = self.pattern_paths.clone(); needlessly clones the full pattern path list just to feed dep-info tracking. Since patterns are already being collected into PATTERNS in this method, you can derive the tracked path list once from that result (or take() the option) and avoid the extra allocation/copy.

Copilot uses AI. Check for mistakes.
config.psess_created = Some(Box::new(move |psess| {
track_rpl_args(psess, &rpl_args_var);
track_files(psess);
track_rpl_pats(psess, rpl_pats_var, rpl_pats.as_deref().unwrap_or(&[]));
}));
config.locale_resources = crate::default_locale_resources();

Expand Down
8 changes: 6 additions & 2 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ pub fn main() {
let mut args: Vec<String> = orig_args.clone();
pass_sysroot_env_if_given(&mut args, sys_root_env);

let pattern_paths = match env::var("RPL_PATS") {
let rpl_pats_var = env::var("RPL_PATS");
let pattern_paths = match &rpl_pats_var {
Comment on lines +224 to +225
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The driver hard-codes the env var name ("RPL_PATS") instead of using a shared constant (similar to rpl_interface::RPL_ARGS_ENV). Consider re-exporting/using RPL_PATS_ENV so changes to the env var name can’t silently diverge across crates.

Copilot uses AI. Check for mistakes.
Ok(val) => Some(val.split(':').map(ToString::to_string).collect()),
Err(env::VarError::NotPresent) => None,
Err(env::VarError::NotUnicode(var)) => {
Expand Down Expand Up @@ -261,7 +262,10 @@ pub fn main() {
/* rustc_driver::RunCompiler::new(&args, &mut RplCallbacks::new(rpl_args_var))
.set_using_internal_features(using_internal_features)
.run() */
rustc_driver::run_compiler(&args, &mut RplCallbacks::new(rpl_args_var, pattern_paths))
rustc_driver::run_compiler(
&args,
&mut RplCallbacks::new(rpl_args_var, rpl_pats_var.ok(), pattern_paths),
)
} else {
rustc_driver::run_compiler(&args, &mut RustcCallbacks::new(rpl_args_var))
}
Expand Down