@@ -2393,7 +2393,7 @@ static void jl_prepare_serialization_data(jl_array_t *mod_array, jl_array_t *new
23932393static void jl_save_system_image_to_stream (ios_t * f , jl_array_t * mod_array ,
23942394 jl_array_t * worklist , jl_array_t * extext_methods ,
23952395 jl_array_t * new_specializations , jl_array_t * method_roots_list ,
2396- jl_array_t * ext_targets , jl_array_t * edges ) JL_GC_DISABLED
2396+ jl_array_t * ext_targets , jl_array_t * edges , jl_array_t * newly_deleted ) JL_GC_DISABLED
23972397{
23982398 htable_new (& field_replace , 0 );
23992399 // strip metadata and IR when requested
@@ -2514,6 +2514,10 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
25142514 jl_queue_for_serialization (& s , ext_targets );
25152515 jl_queue_for_serialization (& s , edges );
25162516 }
2517+ if (newly_deleted ) {
2518+ jl_queue_for_serialization (& s , newly_deleted );
2519+ }
2520+
25172521 jl_serialize_reachable (& s );
25182522 // step 1.2: ensure all gvars are part of the sysimage too
25192523 record_gvars (& s , & gvars );
@@ -2647,6 +2651,7 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
26472651 jl_write_value (& s , method_roots_list );
26482652 jl_write_value (& s , ext_targets );
26492653 jl_write_value (& s , edges );
2654+ jl_write_value (& s , newly_deleted );
26502655 }
26512656 write_uint32 (f , jl_array_len (s .link_ids_gctags ));
26522657 ios_write (f , (char * )jl_array_data (s .link_ids_gctags ), jl_array_len (s .link_ids_gctags ) * sizeof (uint32_t ));
@@ -2726,11 +2731,11 @@ JL_DLLEXPORT void jl_create_system_image(void **_native_data, jl_array_t *workli
27262731 }
27272732
27282733 jl_array_t * mod_array = NULL , * extext_methods = NULL , * new_specializations = NULL ;
2729- jl_array_t * method_roots_list = NULL , * ext_targets = NULL , * edges = NULL ;
2734+ jl_array_t * method_roots_list = NULL , * ext_targets = NULL , * edges = NULL , * _newly_deleted = NULL ;
27302735 int64_t checksumpos = 0 ;
27312736 int64_t checksumpos_ff = 0 ;
27322737 int64_t datastartpos = 0 ;
2733- JL_GC_PUSH6 (& mod_array , & extext_methods , & new_specializations , & method_roots_list , & ext_targets , & edges );
2738+ JL_GC_PUSH7 (& mod_array , & extext_methods , & new_specializations , & method_roots_list , & ext_targets , & edges , & _newly_deleted );
27342739
27352740 if (worklist ) {
27362741 mod_array = jl_get_loaded_modules (); // __toplevel__ modules loaded in this session (from Base.loaded_modules_array)
@@ -2777,7 +2782,10 @@ JL_DLLEXPORT void jl_create_system_image(void **_native_data, jl_array_t *workli
27772782 }
27782783 if (_native_data != NULL )
27792784 native_functions = * _native_data ;
2780- jl_save_system_image_to_stream (ff , mod_array , worklist , extext_methods , new_specializations , method_roots_list , ext_targets , edges );
2785+ // Otherwise serialization will be confused.
2786+ if (newly_deleted )
2787+ _newly_deleted = jl_array_copy (newly_deleted );
2788+ jl_save_system_image_to_stream (ff , mod_array , worklist , extext_methods , new_specializations , method_roots_list , ext_targets , edges , _newly_deleted );
27812789 if (_native_data != NULL )
27822790 native_functions = NULL ;
27832791 // make sure we don't run any Julia code concurrently before this point
@@ -2861,6 +2869,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
28612869 jl_array_t * * extext_methods ,
28622870 jl_array_t * * new_specializations , jl_array_t * * method_roots_list ,
28632871 jl_array_t * * ext_targets , jl_array_t * * edges ,
2872+ jl_array_t * * newly_deleted ,
28642873 char * * base , arraylist_t * ccallable_list , pkgcachesizes * cachesizes ) JL_GC_DISABLED
28652874{
28662875 int en = jl_gc_enable (0 );
@@ -2922,7 +2931,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
29222931 assert (!ios_eof (f ));
29232932 s .s = f ;
29242933 uintptr_t offset_restored = 0 , offset_init_order = 0 , offset_extext_methods = 0 , offset_new_specializations = 0 , offset_method_roots_list = 0 ;
2925- uintptr_t offset_ext_targets = 0 , offset_edges = 0 ;
2934+ uintptr_t offset_ext_targets = 0 , offset_edges = 0 , offset_newly_deleted = 0 ;
29262935 if (!s .incremental ) {
29272936 size_t i ;
29282937 for (i = 0 ; tags [i ] != NULL ; i ++ ) {
@@ -2956,6 +2965,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
29562965 offset_method_roots_list = jl_read_offset (& s );
29572966 offset_ext_targets = jl_read_offset (& s );
29582967 offset_edges = jl_read_offset (& s );
2968+ offset_newly_deleted = jl_read_offset (& s );
29592969 }
29602970 s .buildid_depmods_idxs = depmod_to_imageidx (depmods );
29612971 size_t nlinks_gctags = read_uint32 (f );
@@ -2989,6 +2999,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
29892999 * method_roots_list = (jl_array_t * )jl_delayed_reloc (& s , offset_method_roots_list );
29903000 * ext_targets = (jl_array_t * )jl_delayed_reloc (& s , offset_ext_targets );
29913001 * edges = (jl_array_t * )jl_delayed_reloc (& s , offset_edges );
3002+ * newly_deleted = (jl_array_t * )jl_delayed_reloc (& s , offset_newly_deleted );
29923003 if (!* new_specializations )
29933004 * new_specializations = jl_alloc_vec_any (0 );
29943005 }
@@ -3176,6 +3187,11 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
31763187 assert (jl_is_datatype (obj ));
31773188 jl_cache_type_ ((jl_datatype_t * )obj );
31783189 }
3190+
3191+ // Delete methods before inserting new ones.
3192+ if (newly_deleted )
3193+ jl_delete_methods (* newly_deleted );
3194+
31793195 // Perform fixups: things like updating world ages, inserting methods & specializations, etc.
31803196 size_t world = jl_atomic_load_acquire (& jl_world_counter );
31813197 for (size_t i = 0 ; i < s .uniquing_objs .len ; i ++ ) {
@@ -3402,11 +3418,11 @@ static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, i
34023418 assert (datastartpos > 0 && datastartpos < dataendpos );
34033419 needs_permalloc = jl_options .permalloc_pkgimg || needs_permalloc ;
34043420 jl_value_t * restored = NULL ;
3405- jl_array_t * init_order = NULL , * extext_methods = NULL , * new_specializations = NULL , * method_roots_list = NULL , * ext_targets = NULL , * edges = NULL ;
3421+ jl_array_t * init_order = NULL , * extext_methods = NULL , * new_specializations = NULL , * method_roots_list = NULL , * ext_targets = NULL , * edges = NULL , * newly_deleted = NULL ;
34063422 jl_svec_t * cachesizes_sv = NULL ;
34073423 char * base ;
34083424 arraylist_t ccallable_list ;
3409- JL_GC_PUSH8 (& restored , & init_order , & extext_methods , & new_specializations , & method_roots_list , & ext_targets , & edges , & cachesizes_sv );
3425+ JL_GC_PUSH9 (& restored , & init_order , & extext_methods , & new_specializations , & method_roots_list , & ext_targets , & edges , & newly_deleted , & cachesizes_sv );
34103426
34113427 { // make a permanent in-memory copy of f (excluding the header)
34123428 ios_bufmode (f , bm_none );
@@ -3430,11 +3446,12 @@ static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, i
34303446 ios_close (f );
34313447 ios_static_buffer (f , sysimg , len );
34323448 pkgcachesizes cachesizes ;
3433- jl_restore_system_image_from_stream_ (f , image , depmods , checksum , (jl_array_t * * )& restored , & init_order , & extext_methods , & new_specializations , & method_roots_list , & ext_targets , & edges , & base , & ccallable_list , & cachesizes );
3449+ jl_restore_system_image_from_stream_ (f , image , depmods , checksum , (jl_array_t * * )& restored , & init_order , & extext_methods , & new_specializations , & method_roots_list , & ext_targets , & edges , & newly_deleted , & base , & ccallable_list , & cachesizes );
34343450 JL_SIGATOMIC_END ();
34353451
34363452 // Insert method extensions
34373453 jl_insert_methods (extext_methods );
3454+
34383455 // No special processing of `new_specializations` is required because recaching handled it
34393456 // Add roots to methods
34403457 jl_copy_roots (method_roots_list , jl_worklist_key ((jl_array_t * )restored ));
@@ -3470,7 +3487,7 @@ static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, i
34703487static void jl_restore_system_image_from_stream (ios_t * f , jl_image_t * image , uint32_t checksum )
34713488{
34723489 JL_TIMING (LOAD_IMAGE , LOAD_Sysimg );
3473- jl_restore_system_image_from_stream_ (f , image , NULL , checksum | ((uint64_t )0xfdfcfbfa << 32 ), NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL );
3490+ jl_restore_system_image_from_stream_ (f , image , NULL , checksum | ((uint64_t )0xfdfcfbfa << 32 ), NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL );
34743491}
34753492
34763493JL_DLLEXPORT jl_value_t * jl_restore_incremental_from_buf (void * pkgimage_handle , const char * buf , jl_image_t * image , size_t sz , jl_array_t * depmods , int completeinfo , const char * pkgname , bool needs_permalloc )
0 commit comments