| author | |
| committer | |
| log | c4c5020f0267758c7eb127689177cf1a70fb6d97 |
| tree | e2acc6873952863d72d1a1e55104a3518fdefc89 |
| parent | 9654a54d4a2729200d38dbb6eec827cb03dc0f90 |
* Rename std.builtin.GlobalVisibility to std.builtin.SymbolVisibility
* Add missing compile error. From the LLVM language reference: "A
symbol with internal or private linkage must have default
visibility."7 files changed, 44 insertions(+), 34 deletions(-)
lib/std/builtin.zig+2-2| ... | ... | @@ -70,7 +70,7 @@ pub const GlobalLinkage = enum { |
| 70 | 70 | |
| 71 | 71 | /// This data structure is used by the Zig language code generation and |
| 72 | 72 | /// therefore must be kept in sync with the compiler implementation. |
| 73 | pub const GlobalVisibility = enum { | |
| 73 | pub const SymbolVisibility = enum { | |
| 74 | 74 | default, |
| 75 | 75 | hidden, |
| 76 | 76 | protected, |
| ... | ... | @@ -663,7 +663,7 @@ pub const ExportOptions = struct { |
| 663 | 663 | name: []const u8, |
| 664 | 664 | linkage: GlobalLinkage = .Strong, |
| 665 | 665 | section: ?[]const u8 = null, |
| 666 | visibility: GlobalVisibility = .default, | |
| 666 | visibility: SymbolVisibility = .default, | |
| 667 | 667 | }; |
| 668 | 668 | |
| 669 | 669 | /// This data structure is used by the Zig language code generation and |
src/Sema.zig+20-10| ... | ... | @@ -14999,27 +14999,37 @@ fn resolveExportOptions( |
| 14999 | 14999 | const air_ref = sema.resolveInst(zir_ref); |
| 15000 | 15000 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 15001 | 15001 | |
| 15002 | const name = try sema.fieldVal(block, src, options, "name", src); | |
| 15003 | const name_val = try sema.resolveConstValue(block, src, name); | |
| 15002 | const name_operand = try sema.fieldVal(block, src, options, "name", src); | |
| 15003 | const name_val = try sema.resolveConstValue(block, src, name_operand); | |
| 15004 | const name_ty = Type.initTag(.const_slice_u8); | |
| 15005 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, sema.mod); | |
| 15004 | 15006 | |
| 15005 | const linkage = try sema.fieldVal(block, src, options, "linkage", src); | |
| 15006 | const linkage_val = try sema.resolveConstValue(block, src, linkage); | |
| 15007 | const linkage_operand = try sema.fieldVal(block, src, options, "linkage", src); | |
| 15008 | const linkage_val = try sema.resolveConstValue(block, src, linkage_operand); | |
| 15009 | const linkage = linkage_val.toEnum(std.builtin.GlobalLinkage); | |
| 15007 | 15010 | |
| 15008 | 15011 | const section = try sema.fieldVal(block, src, options, "section", src); |
| 15009 | 15012 | const section_val = try sema.resolveConstValue(block, src, section); |
| 15010 | 15013 | |
| 15011 | const visibility = try sema.fieldVal(block, src, options, "visibility", src); | |
| 15012 | const visibility_val = try sema.resolveConstValue(block, src, visibility); | |
| 15014 | const visibility_operand = try sema.fieldVal(block, src, options, "visibility", src); | |
| 15015 | const visibility_val = try sema.resolveConstValue(block, src, visibility_operand); | |
| 15016 | const visibility = visibility_val.toEnum(std.builtin.SymbolVisibility); | |
| 15017 | ||
| 15018 | if (visibility != .default and linkage == .Internal) { | |
| 15019 | return sema.fail(block, src, "symbol '{s}' exported with internal linkage has non-default visibility {s}", .{ | |
| 15020 | name, @tagName(visibility), | |
| 15021 | }); | |
| 15022 | } | |
| 15013 | 15023 | |
| 15014 | 15024 | if (!section_val.isNull()) { |
| 15015 | 15025 | return sema.fail(block, src, "TODO: implement exporting with linksection", .{}); |
| 15016 | 15026 | } |
| 15017 | const name_ty = Type.initTag(.const_slice_u8); | |
| 15027 | ||
| 15018 | 15028 | return std.builtin.ExportOptions{ |
| 15019 | .name = try name_val.toAllocatedBytes(name_ty, sema.arena, sema.mod), | |
| 15020 | .linkage = linkage_val.toEnum(std.builtin.GlobalLinkage), | |
| 15029 | .name = name, | |
| 15030 | .linkage = linkage, | |
| 15021 | 15031 | .section = null, // TODO |
| 15022 | .visibility = visibility_val.toEnum(std.builtin.GlobalVisibility), | |
| 15032 | .visibility = visibility, | |
| 15023 | 15033 | }; |
| 15024 | 15034 | } |
| 15025 | 15035 |
src/stage1/all_types.hpp+5-5| ... | ... | @@ -571,10 +571,10 @@ enum GlobalLinkageId { |
| 571 | 571 | GlobalLinkageIdLinkOnce, |
| 572 | 572 | }; |
| 573 | 573 | |
| 574 | enum GlobalVisibilityId { | |
| 575 | GlobalVisibilityIdDefault, | |
| 576 | GlobalVisibilityIdHidden, | |
| 577 | GlobalVisibilityIdProtected, | |
| 574 | enum SymbolVisibilityId { | |
| 575 | SymbolVisibilityIdDefault, | |
| 576 | SymbolVisibilityIdHidden, | |
| 577 | SymbolVisibilityIdProtected, | |
| 578 | 578 | }; |
| 579 | 579 | |
| 580 | 580 | enum TldId { |
| ... | ... | @@ -1660,7 +1660,7 @@ enum FnAnalState { |
| 1660 | 1660 | struct GlobalExport { |
| 1661 | 1661 | Buf name; |
| 1662 | 1662 | GlobalLinkageId linkage; |
| 1663 | GlobalVisibilityId visibility; | |
| 1663 | SymbolVisibilityId visibility; | |
| 1664 | 1664 | }; |
| 1665 | 1665 | |
| 1666 | 1666 | struct ZigFn { |
src/stage1/analyze.cpp+5-5| ... | ... | @@ -3717,7 +3717,7 @@ ZigType *get_test_fn_type(CodeGen *g) { |
| 3717 | 3717 | return g->test_fn_type; |
| 3718 | 3718 | } |
| 3719 | 3719 | |
| 3720 | void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLinkageId linkage, GlobalVisibilityId visibility) { | |
| 3720 | void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLinkageId linkage, SymbolVisibilityId visibility) { | |
| 3721 | 3721 | GlobalExport *global_export = var->export_list.add_one(); |
| 3722 | 3722 | memset(global_export, 0, sizeof(GlobalExport)); |
| 3723 | 3723 | buf_init_from_str(&global_export->name, symbol_name); |
| ... | ... | @@ -3725,7 +3725,7 @@ void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLink |
| 3725 | 3725 | global_export->visibility = visibility; |
| 3726 | 3726 | } |
| 3727 | 3727 | |
| 3728 | void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, GlobalVisibilityId visibility, CallingConvention cc) { | |
| 3728 | void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, SymbolVisibilityId visibility, CallingConvention cc) { | |
| 3729 | 3729 | CallingConvention winapi_cc = g->zig_target->arch == ZigLLVM_x86 |
| 3730 | 3730 | ? CallingConventionStdcall |
| 3731 | 3731 | : CallingConventionC; |
| ... | ... | @@ -3854,13 +3854,13 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3854 | 3854 | case CallingConventionWin64: |
| 3855 | 3855 | case CallingConventionPtxKernel: |
| 3856 | 3856 | add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name), |
| 3857 | GlobalLinkageIdStrong, GlobalVisibilityIdDefault, fn_cc); | |
| 3857 | GlobalLinkageIdStrong, SymbolVisibilityIdDefault, fn_cc); | |
| 3858 | 3858 | break; |
| 3859 | 3859 | case CallingConventionUnspecified: |
| 3860 | 3860 | // An exported function without a specific calling |
| 3861 | 3861 | // convention defaults to C |
| 3862 | 3862 | add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name), |
| 3863 | GlobalLinkageIdStrong, GlobalVisibilityIdDefault, CallingConventionC); | |
| 3863 | GlobalLinkageIdStrong, SymbolVisibilityIdDefault, CallingConventionC); | |
| 3864 | 3864 | break; |
| 3865 | 3865 | } |
| 3866 | 3866 | } |
| ... | ... | @@ -4323,7 +4323,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { |
| 4323 | 4323 | |
| 4324 | 4324 | if (is_export) { |
| 4325 | 4325 | validate_export_var_type(g, type, source_node); |
| 4326 | add_var_export(g, tld_var->var, tld_var->var->name, GlobalLinkageIdStrong, GlobalVisibilityIdDefault); | |
| 4326 | add_var_export(g, tld_var->var, tld_var->var->name, GlobalLinkageIdStrong, SymbolVisibilityIdDefault); | |
| 4327 | 4327 | } |
| 4328 | 4328 | |
| 4329 | 4329 | if (is_extern) { |
src/stage1/analyze.hpp+2-2| ... | ... | @@ -221,8 +221,8 @@ ZigType *get_align_amt_type(CodeGen *g); |
| 221 | 221 | ZigPackage *new_anonymous_package(void); |
| 222 | 222 | |
| 223 | 223 | Buf *const_value_to_buffer(ZigValue *const_val); |
| 224 | void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, GlobalVisibilityId visibility, CallingConvention cc); | |
| 225 | void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, GlobalVisibilityId visibility); | |
| 224 | void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, SymbolVisibilityId visibility, CallingConvention cc); | |
| 225 | void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, SymbolVisibilityId visibility); | |
| 226 | 226 | |
| 227 | 227 | |
| 228 | 228 | ZigValue *get_builtin_value(CodeGen *codegen, const char *name); |
src/stage1/codegen.cpp+6-6| ... | ... | @@ -242,13 +242,13 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id, bool is_extern) { |
| 242 | 242 | zig_unreachable(); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | static LLVMVisibility to_llvm_visibility(GlobalVisibilityId id) { | |
| 245 | static LLVMVisibility to_llvm_visibility(SymbolVisibilityId id) { | |
| 246 | 246 | switch (id) { |
| 247 | case GlobalVisibilityIdDefault: | |
| 247 | case SymbolVisibilityIdDefault: | |
| 248 | 248 | return LLVMDefaultVisibility; |
| 249 | case GlobalVisibilityIdHidden: | |
| 249 | case SymbolVisibilityIdHidden: | |
| 250 | 250 | return LLVMHiddenVisibility; |
| 251 | case GlobalVisibilityIdProtected: | |
| 251 | case SymbolVisibilityIdProtected: | |
| 252 | 252 | return LLVMProtectedVisibility; |
| 253 | 253 | } |
| 254 | 254 | zig_unreachable(); |
| ... | ... | @@ -412,7 +412,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { |
| 412 | 412 | const char *unmangled_name = buf_ptr(&fn->symbol_name); |
| 413 | 413 | const char *symbol_name; |
| 414 | 414 | GlobalLinkageId linkage; |
| 415 | GlobalVisibilityId visibility = GlobalVisibilityIdDefault; | |
| 415 | SymbolVisibilityId visibility = SymbolVisibilityIdDefault; | |
| 416 | 416 | if (fn->body_node == nullptr) { |
| 417 | 417 | symbol_name = unmangled_name; |
| 418 | 418 | linkage = GlobalLinkageIdStrong; |
| ... | ... | @@ -8967,7 +8967,7 @@ static void do_code_gen(CodeGen *g) { |
| 8967 | 8967 | assert(var->decl_node); |
| 8968 | 8968 | |
| 8969 | 8969 | GlobalLinkageId linkage; |
| 8970 | GlobalVisibilityId visibility = GlobalVisibilityIdDefault; | |
| 8970 | SymbolVisibilityId visibility = SymbolVisibilityIdDefault; | |
| 8971 | 8971 | const char *unmangled_name = var->name; |
| 8972 | 8972 | const char *symbol_name; |
| 8973 | 8973 | if (var->export_list.length == 0) { |
src/stage1/ir.cpp+4-4| ... | ... | @@ -8635,11 +8635,11 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, Stage1AirInst *value, Glob |
| 8635 | 8635 | return true; |
| 8636 | 8636 | } |
| 8637 | 8637 | |
| 8638 | static bool ir_resolve_global_visibility(IrAnalyze *ira, Stage1AirInst *value, GlobalVisibilityId *out) { | |
| 8638 | static bool ir_resolve_global_visibility(IrAnalyze *ira, Stage1AirInst *value, SymbolVisibilityId *out) { | |
| 8639 | 8639 | if (type_is_invalid(value->value->type)) |
| 8640 | 8640 | return false; |
| 8641 | 8641 | |
| 8642 | ZigType *global_visibility_type = get_builtin_type(ira->codegen, "GlobalVisibility"); | |
| 8642 | ZigType *global_visibility_type = get_builtin_type(ira->codegen, "SymbolVisibility"); | |
| 8643 | 8643 | |
| 8644 | 8644 | Stage1AirInst *casted_value = ir_implicit_cast(ira, value, global_visibility_type); |
| 8645 | 8645 | if (type_is_invalid(casted_value->value->type)) |
| ... | ... | @@ -8649,7 +8649,7 @@ static bool ir_resolve_global_visibility(IrAnalyze *ira, Stage1AirInst *value, G |
| 8649 | 8649 | if (!const_val) |
| 8650 | 8650 | return false; |
| 8651 | 8651 | |
| 8652 | *out = (GlobalVisibilityId)bigint_as_u32(&const_val->data.x_enum_tag); | |
| 8652 | *out = (SymbolVisibilityId)bigint_as_u32(&const_val->data.x_enum_tag); | |
| 8653 | 8653 | return true; |
| 8654 | 8654 | } |
| 8655 | 8655 | |
| ... | ... | @@ -11714,7 +11714,7 @@ static Stage1AirInst *ir_analyze_instruction_export(IrAnalyze *ira, Stage1ZirIns |
| 11714 | 11714 | if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id)) |
| 11715 | 11715 | return ira->codegen->invalid_inst_gen; |
| 11716 | 11716 | |
| 11717 | GlobalVisibilityId global_visibility_id; | |
| 11717 | SymbolVisibilityId global_visibility_id; | |
| 11718 | 11718 | if (!ir_resolve_global_visibility(ira, visibility_inst, &global_visibility_id)) |
| 11719 | 11719 | return ira->codegen->invalid_inst_gen; |
| 11720 | 11720 |