authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-26 17:09:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:21-07:00
log951c5b3f67e086c50ba8d0cd9318cb770fd3f724
tree2d8e5b59801793cabd22b868312ccacd3e4b974e
parentb8a8fb927b791b369234012a3d4ff5e2c4c466c9

frontend: fix "any" default resolution ambiguity

In Compilation.create, update the resolved config to account for the default resolution of the root module. This makes it so that, for example, reading comp.config.any_non_single_threaded is valid in order to determine whether any module has single_threaded=false.

2 files changed, 35 insertions(+), 6 deletions(-)

src/Compilation.zig+12-1
...@@ -1198,7 +1198,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1198,7 +1198,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
11981198
1199 const use_llvm = options.config.use_llvm;1199 const use_llvm = options.config.use_llvm;
12001200
1201 const any_unwind_tables = options.config.any_unwind_tables;1201 // The "any" values provided by resolved config only account for
1202 // explicitly-provided settings. We now make them additionally account
1203 // for default setting resolution.
1204 const any_unwind_tables = options.config.any_unwind_tables or options.root_mod.unwind_tables;
1205 const any_non_single_threaded = options.config.any_non_single_threaded or !options.root_mod.single_threaded;
1206 const any_sanitize_thread = options.config.any_sanitize_thread or options.root_mod.sanitize_thread;
12021207
1203 const link_eh_frame_hdr = options.link_eh_frame_hdr or any_unwind_tables;1208 const link_eh_frame_hdr = options.link_eh_frame_hdr or any_unwind_tables;
1204 const build_id = options.build_id orelse .none;1209 const build_id = options.build_id orelse .none;
...@@ -1503,6 +1508,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1503,6 +1508,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1503 .native_system_include_paths = options.native_system_include_paths,1508 .native_system_include_paths = options.native_system_include_paths,
1504 };1509 };
15051510
1511 // Prevent some footguns by making the "any" fields of config reflect
1512 // the default Module settings.
1513 comp.config.any_unwind_tables = any_unwind_tables;
1514 comp.config.any_non_single_threaded = any_non_single_threaded;
1515 comp.config.any_sanitize_thread = any_sanitize_thread;
1516
1506 const lf_open_opts: link.File.OpenOptions = .{1517 const lf_open_opts: link.File.OpenOptions = .{
1507 .linker_script = options.linker_script,1518 .linker_script = options.linker_script,
1508 .z_nodelete = options.linker_z_nodelete,1519 .z_nodelete = options.linker_z_nodelete,
src/Compilation/Config.zig+23-5
...@@ -1,4 +1,7 @@...@@ -1,4 +1,7 @@
1//! User-specified settings that have all the defaults resolved into concrete values.1//! User-specified settings that have all the defaults resolved into concrete
2//! values. These values are observable before calling Compilation.create for
3//! the benefit of Module creation API, which needs access to these details in
4//! order to resolve per-Module defaults.
25
3have_zcu: bool,6have_zcu: bool,
4output_mode: std.builtin.OutputMode,7output_mode: std.builtin.OutputMode,
...@@ -6,12 +9,27 @@ link_mode: std.builtin.LinkMode,...@@ -6,12 +9,27 @@ link_mode: std.builtin.LinkMode,
6link_libc: bool,9link_libc: bool,
7link_libcpp: bool,10link_libcpp: bool,
8link_libunwind: bool,11link_libunwind: bool,
9any_unwind_tables: bool,12/// True if and only if the c_source_files field will have nonzero length when
13/// calling Compilation.create.
10any_c_source_files: bool,14any_c_source_files: bool,
15/// This is true if any Module has unwind_tables set explicitly to true. Until
16/// Compilation.create is called, it is possible for this to be false while in
17/// fact all Module instances have unwind_tables=true due to the default
18/// being unwind_tables=true. After Compilation.create is called this will
19/// also take into account the default setting, making this value true if and
20/// only if any Module has unwind_tables set to true.
21any_unwind_tables: bool,
22/// This is true if any Module has single_threaded set explicitly to false. Until
23/// Compilation.create is called, it is possible for this to be false while in
24/// fact all Module instances have single_threaded=false due to the default
25/// being non-single-threaded. After Compilation.create is called this will
26/// also take into account the default setting, making this value true if and
27/// only if any Module has single_threaded set to false.
11any_non_single_threaded: bool,28any_non_single_threaded: bool,
12/// This is true if any Module has error_tracing set to true. Function types29/// This is true if and only if any Module has error_tracing set to true.
13/// and function calling convention depend on this global value, however, other30/// Function types and function calling convention depend on this global value,
14/// kinds of error tracing are omitted depending on the per-Module setting.31/// however, other kinds of error tracing are omitted depending on the
32/// per-Module setting.
15any_error_tracing: bool,33any_error_tracing: bool,
16any_sanitize_thread: bool,34any_sanitize_thread: bool,
17pie: bool,35pie: bool,