authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-27 10:42:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 19:49:07-07:00
log5b05e99dd48520c0efd5f624760b3218bc1311ec
tree0a7ffe3bcc62f7c3d3c71f5b01492a663e6ad92f
parent372b407740224ae20fad49647bbde56330b24967

Compilation: consolidate module hashing code


1 files changed, 21 insertions(+), 41 deletions(-)

src/Compilation.zig+21-41
...@@ -799,6 +799,24 @@ pub const EmitLoc = struct {...@@ -799,6 +799,24 @@ pub const EmitLoc = struct {
799};799};
800800
801pub const cache_helpers = struct {801pub const cache_helpers = struct {
802 pub fn addModule(hh: *Cache.HashHelper, mod: *const Package.Module) void {
803 addResolvedTarget(hh, mod.resolved_target);
804 hh.add(mod.optimize_mode);
805 hh.add(mod.code_model);
806 hh.add(mod.single_threaded);
807 hh.add(mod.error_tracing);
808 hh.add(mod.valgrind);
809 hh.add(mod.pic);
810 hh.add(mod.strip);
811 hh.add(mod.omit_frame_pointer);
812 hh.add(mod.stack_check);
813 hh.add(mod.red_zone);
814 hh.add(mod.sanitize_c);
815 hh.add(mod.sanitize_thread);
816 hh.add(mod.unwind_tables);
817 hh.add(mod.structured_cfg);
818 }
819
802 pub fn addResolvedTarget(820 pub fn addResolvedTarget(
803 hh: *Cache.HashHelper,821 hh: *Cache.HashHelper,
804 resolved_target: Package.Module.ResolvedTarget,822 resolved_target: Package.Module.ResolvedTarget,
...@@ -1131,21 +1149,7 @@ fn addModuleTableToCacheHash(...@@ -1131,21 +1149,7 @@ fn addModuleTableToCacheHash(
1131 continue;1149 continue;
1132 }1150 }
11331151
1134 cache_helpers.addResolvedTarget(hash, mod.resolved_target);1152 cache_helpers.addModule(hash, mod);
1135 hash.add(mod.optimize_mode);
1136 hash.add(mod.code_model);
1137 hash.add(mod.single_threaded);
1138 hash.add(mod.error_tracing);
1139 hash.add(mod.valgrind);
1140 hash.add(mod.pic);
1141 hash.add(mod.strip);
1142 hash.add(mod.omit_frame_pointer);
1143 hash.add(mod.stack_check);
1144 hash.add(mod.red_zone);
1145 hash.add(mod.sanitize_c);
1146 hash.add(mod.sanitize_thread);
1147 hash.add(mod.unwind_tables);
1148 hash.add(mod.structured_cfg);
11491153
1150 switch (hash_type) {1154 switch (hash_type) {
1151 .path_bytes => {1155 .path_bytes => {
...@@ -2406,19 +2410,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2406,19 +2410,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2406 man.hash.add(mod.emit_h != null);2410 man.hash.add(mod.emit_h != null);
2407 man.hash.add(mod.error_limit);2411 man.hash.add(mod.error_limit);
2408 } else {2412 } else {
2409 cache_helpers.addResolvedTarget(&man.hash, comp.root_mod.resolved_target);2413 cache_helpers.addModule(&man.hash, comp.root_mod);
2410 man.hash.add(comp.root_mod.optimize_mode);
2411 man.hash.add(comp.root_mod.code_model);
2412 man.hash.add(comp.root_mod.single_threaded);
2413 man.hash.add(comp.root_mod.error_tracing);
2414 man.hash.add(comp.root_mod.pic);
2415 man.hash.add(comp.root_mod.omit_frame_pointer);
2416 man.hash.add(comp.root_mod.stack_check);
2417 man.hash.add(comp.root_mod.red_zone);
2418 man.hash.add(comp.root_mod.sanitize_c);
2419 man.hash.add(comp.root_mod.sanitize_thread);
2420 man.hash.add(comp.root_mod.unwind_tables);
2421 man.hash.add(comp.root_mod.structured_cfg);
2422 }2414 }
24232415
2424 for (comp.objects) |obj| {2416 for (comp.objects) |obj| {
...@@ -3855,19 +3847,7 @@ pub fn obtainCObjectCacheManifest(...@@ -3855,19 +3847,7 @@ pub fn obtainCObjectCacheManifest(
3855 // Only things that need to be added on top of the base hash, and only things3847 // Only things that need to be added on top of the base hash, and only things
3856 // that apply both to @cImport and compiling C objects. No linking stuff here!3848 // that apply both to @cImport and compiling C objects. No linking stuff here!
3857 // Also nothing that applies only to compiling .zig code.3849 // Also nothing that applies only to compiling .zig code.
3858 cache_helpers.addResolvedTarget(&man.hash, owner_mod.resolved_target);3850 cache_helpers.addModule(&man.hash, owner_mod);
3859 man.hash.add(owner_mod.optimize_mode);
3860 man.hash.add(owner_mod.code_model);
3861 man.hash.add(owner_mod.single_threaded);
3862 man.hash.add(owner_mod.error_tracing);
3863 man.hash.add(owner_mod.pic);
3864 man.hash.add(owner_mod.omit_frame_pointer);
3865 man.hash.add(owner_mod.stack_check);
3866 man.hash.add(owner_mod.red_zone);
3867 man.hash.add(owner_mod.sanitize_c);
3868 man.hash.add(owner_mod.sanitize_thread);
3869 man.hash.add(owner_mod.unwind_tables);
3870 man.hash.add(owner_mod.structured_cfg);
3871 man.hash.addListOfBytes(owner_mod.cc_argv);3851 man.hash.addListOfBytes(owner_mod.cc_argv);
3872 man.hash.add(comp.config.link_libcpp);3852 man.hash.add(comp.config.link_libcpp);
38733853