From cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 7 Aug 2026 20:51:59 +0900 Subject: fix(autoload-generator): survive listeners that re-enter dump() AutoloadGenerator::dump dispatches PRE_AUTOLOAD_DUMP / POST_AUTOLOAD_DUMP, and EventDispatcher::make_autoloader answers those by walking back into the Composer graph -- the local repository, the installation manager, and the generator itself. Installer::run held mutable borrows of all three across the dump call, so any plugin subscribing to either event panicked with "RefCell already borrowed" before its listener ran. dump() and build_package_map() now take the local repository, the installation manager and the locker as shared handles instead of &mut dyn, and the borrow is taken where it is used. The generator itself is re-entered, not just borrowed twice: PHP listeners reach it through Composer::getAutoloadGenerator() and call setDevMode() while dump() is running, and make_autoloader asks the same object for a package map. That is not expressible behind &mut self, so the mutable state moves into Cell/RefCell fields and the whole AutoloadGeneratorInterface takes &self. Co-Authored-By: Claude Opus 5 (1M context) --- .../shirabe/src/command/dump_autoload_command.rs | 32 ++++++++-------------- crates/shirabe/src/command/reinstall_command.rs | 18 +++++------- 2 files changed, 18 insertions(+), 32 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/dump_autoload_command.rs b/crates/shirabe/src/command/dump_autoload_command.rs index 59295e23..8aad0705 100644 --- a/crates/shirabe/src/command/dump_autoload_command.rs +++ b/crates/shirabe/src/command/dump_autoload_command.rs @@ -188,10 +188,7 @@ impl Command for DumpAutoloadCommand { .as_bool() .unwrap_or(false) { - composer - .get_autoload_generator() - .borrow_mut() - .set_dry_run(true); + composer.get_autoload_generator().borrow().set_dry_run(true); } if input .borrow() @@ -201,7 +198,7 @@ impl Command for DumpAutoloadCommand { { composer .get_autoload_generator() - .borrow_mut() + .borrow() .set_dev_mode(false); } if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { @@ -221,24 +218,24 @@ impl Command for DumpAutoloadCommand { } composer .get_autoload_generator() - .borrow_mut() + .borrow() .set_dev_mode(true); } composer .get_autoload_generator() - .borrow_mut() + .borrow() .set_class_map_authoritative(authoritative); composer .get_autoload_generator() - .borrow_mut() + .borrow() .set_run_scripts(true); composer .get_autoload_generator() - .borrow_mut() + .borrow() .set_apcu(apcu, apcu_prefix); composer .get_autoload_generator() - .borrow_mut() + .borrow() .set_platform_requirement_filter(platform_requirement_filter); let strict_ambiguous = input .borrow() @@ -256,22 +253,15 @@ impl Command for DumpAutoloadCommand { let autoload_generator = composer.get_autoload_generator(); let config_ref = config.borrow(); - let mut local_repo_ref = local_repo_handle.borrow_mut(); - let local_repo = local_repo_ref - .as_installed_repository_interface_mut() - .expect("local repository must be an InstalledRepositoryInterface"); - let mut installation_manager_ref = installation_manager.borrow_mut(); - let mut locker_ref = locker.borrow_mut(); - - let class_map = autoload_generator.borrow_mut().dump( + let class_map = autoload_generator.borrow().dump( &config_ref, - local_repo, + local_repo_handle, package, - &mut *installation_manager_ref, + installation_manager, "composer", optimize, None, - Some(&mut *locker_ref), + Some(locker), strict_ambiguous, )?; let number_of_classes = class_map.map.len(); diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs index 05543870..b16b6c92 100644 --- a/crates/shirabe/src/command/reinstall_command.rs +++ b/crates/shirabe/src/command/reinstall_command.rs @@ -307,27 +307,23 @@ impl Command for ReinstallCommand { let autoload_generator = composer.get_autoload_generator(); autoload_generator - .borrow_mut() + .borrow() .set_class_map_authoritative(authoritative); - autoload_generator.borrow_mut().set_apcu(apcu, apcu_prefix); + autoload_generator.borrow().set_apcu(apcu, apcu_prefix); autoload_generator - .borrow_mut() + .borrow() .set_platform_requirement_filter(self.get_platform_requirement_filter(input)?); let locker = composer.get_locker(); - let mut local_repo_ref = local_repo.borrow_mut(); - let repo = local_repo_ref - .as_installed_repository_interface_mut() - .expect("local repository must be an InstalledRepositoryInterface"); - autoload_generator.borrow_mut().dump( + autoload_generator.borrow().dump( &config.borrow(), - repo, + local_repo.clone(), package.clone(), - &mut *installation_manager.borrow_mut(), + installation_manager.clone(), "composer", optimize, None, - Some(&mut *locker.borrow_mut()), + Some(locker.clone()), false, )?; } -- cgit v1.3.1