|
78 | 78 | pcs_declarations strings.Builder // -prof profile counter declarations for each function |
79 | 79 | cov_declarations strings.Builder // -cov coverage |
80 | 80 | embedded_data strings.Builder // data to embed in the executable/binary |
| 81 | + interface_index_definitions strings.Builder // real interface index symbols for -parallel-cc helpers |
81 | 82 | shared_types strings.Builder // shared/lock types |
82 | 83 | shared_functions strings.Builder // shared constructors |
83 | 84 | out_options_forward strings.Builder // forward `option_xxxx` types |
@@ -399,6 +400,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO |
399 | 400 | pcs_declarations: strings.new_builder(100) |
400 | 401 | cov_declarations: strings.new_builder(100) |
401 | 402 | embedded_data: strings.new_builder(1000) |
| 403 | + interface_index_definitions: strings.new_builder(100) |
402 | 404 | out_options_forward: strings.new_builder(100) |
403 | 405 | out_options: strings.new_builder(100) |
404 | 406 | out_results_forward: strings.new_builder(100) |
@@ -899,6 +901,10 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO |
899 | 901 | if g.embedded_data.len > 0 { |
900 | 902 | helpers.write_string2('\n// V embedded data:\n', g.embedded_data.str()) |
901 | 903 | } |
| 904 | + if g.interface_index_definitions.len > 0 { |
| 905 | + helpers.write_string2('\n// V interface index definitions:\n', |
| 906 | + g.interface_index_definitions.str()) |
| 907 | + } |
902 | 908 | if g.pref.parallel_cc { |
903 | 909 | helpers.writeln('\n// V global/const non-precomputed definitions:') |
904 | 910 | for var_name in g.sorted_global_const_names { |
@@ -1036,6 +1042,7 @@ fn cgen_process_one_file_cb(mut p pool.PoolProcessor, idx int, wid int) voidptr |
1036 | 1042 | cov_declarations: strings.new_builder(100) |
1037 | 1043 | hotcode_definitions: strings.new_builder(100) |
1038 | 1044 | embedded_data: strings.new_builder(1000) |
| 1045 | + interface_index_definitions: strings.new_builder(100) |
1039 | 1046 | out_options_forward: strings.new_builder(100) |
1040 | 1047 | out_options: strings.new_builder(100) |
1041 | 1048 | out_results_forward: strings.new_builder(100) |
@@ -1124,6 +1131,7 @@ pub fn (mut g Gen) free_builders() { |
1124 | 1131 | g.cov_declarations.free() |
1125 | 1132 | g.hotcode_definitions.free() |
1126 | 1133 | g.embedded_data.free() |
| 1134 | + g.interface_index_definitions.free() |
1127 | 1135 | g.shared_types.free() |
1128 | 1136 | g.shared_functions.free() |
1129 | 1137 | g.channel_definitions.free() |
@@ -14147,6 +14155,11 @@ fn (mut g Gen) interface_table() string { |
14147 | 14155 | // That keeps stray bytes from overlapping storage, like unions, from |
14148 | 14156 | // aliasing a valid concrete interface variant. |
14149 | 14157 | interface_index_name := '_${interface_name}_${cctype}_index' |
| 14158 | + interface_index_case_name := if g.pref.use_cache { |
| 14159 | + '${interface_index_name}_enum' |
| 14160 | + } else { |
| 14161 | + interface_index_name |
| 14162 | + } |
14150 | 14163 | if already_generated_mwrappers[interface_index_name] > 0 { |
14151 | 14164 | continue |
14152 | 14165 | } |
@@ -14236,8 +14249,15 @@ static inline __shared__${interface_name} ${shared_fn_name}(__shared__${cctype}* |
14236 | 14249 | return ${cast_shared_struct_str}; |
14237 | 14250 | }') |
14238 | 14251 | if shared_interface_mtx_helper_needed { |
14239 | | - shared_interface_mtx_cases.writeln('\t\tcase ${interface_index_name}:') |
14240 | | - shared_interface_mtx_cases.writeln('\t\t\treturn &(((__shared__${cctype}*)((char*)x->val._${cctype} - __offsetof(__shared__${cctype}, val)))->mtx);') |
| 14252 | + mtx_expr := '&(((__shared__${cctype}*)((char*)x->val._${cctype} - __offsetof(__shared__${cctype}, val)))->mtx)' |
| 14253 | + if g.pref.build_mode == .build_module { |
| 14254 | + shared_interface_mtx_cases.writeln('\tif (x->val._typ == ${interface_index_name}) {') |
| 14255 | + shared_interface_mtx_cases.writeln('\t\treturn ${mtx_expr};') |
| 14256 | + shared_interface_mtx_cases.writeln('\t}') |
| 14257 | + } else { |
| 14258 | + shared_interface_mtx_cases.writeln('\t\tcase ${interface_index_case_name}:') |
| 14259 | + shared_interface_mtx_cases.writeln('\t\t\treturn ${mtx_expr};') |
| 14260 | + } |
14241 | 14261 | } |
14242 | 14262 | } |
14243 | 14263 |
|
@@ -14501,7 +14521,24 @@ return ${cast_shared_struct_str}; |
14501 | 14521 | } |
14502 | 14522 | iin_idx := already_generated_mwrappers[interface_index_name] - iinidx_minimum_base + 1 |
14503 | 14523 | if g.pref.build_mode != .build_module { |
14504 | | - sb.writeln('enum { ${interface_index_name} = ${iin_idx} };') |
| 14524 | + if g.pref.use_cache { |
| 14525 | + // With -usecache, modules like `builtin` are compiled separately |
| 14526 | + // in build_module mode, where the index is emitted as |
| 14527 | + // `extern const u32 ..._index;` and referenced. The main program |
| 14528 | + // must therefore provide a real, externally-linked definition |
| 14529 | + // (not a compile-time `enum` constant, which has no linker |
| 14530 | + // symbol), otherwise the reference is undefined at link time - |
| 14531 | + // e.g. `undefined symbol: _IError_None___index` on FreeBSD/clang. |
| 14532 | + sb.writeln('enum { ${interface_index_case_name} = ${iin_idx} };') |
| 14533 | + if g.pref.parallel_cc { |
| 14534 | + sb.writeln('extern const u32 ${interface_index_name};') |
| 14535 | + g.interface_index_definitions.writeln('const u32 ${interface_index_name} = ${interface_index_case_name};') |
| 14536 | + } else { |
| 14537 | + sb.writeln('const u32 ${interface_index_name} = ${interface_index_case_name};') |
| 14538 | + } |
| 14539 | + } else { |
| 14540 | + sb.writeln('enum { ${interface_index_name} = ${iin_idx} };') |
| 14541 | + } |
14505 | 14542 | } else { |
14506 | 14543 | sb.writeln('extern const u32 ${interface_index_name};') |
14507 | 14544 | } |
@@ -14566,11 +14603,16 @@ return ${cast_shared_struct_str}; |
14566 | 14603 | cast_functions.writeln(' |
14567 | 14604 | static inline sync__RwMutex* ${shared_interface_mtx_helper_name}(__shared__${interface_name}* x) {') |
14568 | 14605 | if shared_interface_mtx_cases.len > 0 { |
14569 | | - cast_functions.writeln('\tswitch (x->val._typ) {') |
14570 | | - cast_functions.write_string(shared_interface_mtx_cases.str()) |
14571 | | - cast_functions.writeln('\t\tdefault:') |
14572 | | - cast_functions.writeln('\t\t\treturn &x->mtx;') |
14573 | | - cast_functions.writeln('\t}') |
| 14606 | + if g.pref.build_mode == .build_module { |
| 14607 | + cast_functions.write_string(shared_interface_mtx_cases.str()) |
| 14608 | + cast_functions.writeln('\treturn &x->mtx;') |
| 14609 | + } else { |
| 14610 | + cast_functions.writeln('\tswitch (x->val._typ) {') |
| 14611 | + cast_functions.write_string(shared_interface_mtx_cases.str()) |
| 14612 | + cast_functions.writeln('\t\tdefault:') |
| 14613 | + cast_functions.writeln('\t\t\treturn &x->mtx;') |
| 14614 | + cast_functions.writeln('\t}') |
| 14615 | + } |
14574 | 14616 | } else { |
14575 | 14617 | cast_functions.writeln('\treturn &x->mtx;') |
14576 | 14618 | } |
|
0 commit comments