| author | |
| committer | |
| log | 3d637e6dd257d617867e12ac949d966d2c2ef48a |
| tree | 4e9b0513c63fd21c91850f777c40154081f71dab |
| parent | 130ad08001f73d62e0c6daf3848da4f7aedff614 |
Make it properly use `std.builtin.ExportOptions`.5 files changed, 70 insertions(+), 20 deletions(-)
src/AstGen.zig+12-9| ... | ... | @@ -6127,15 +6127,18 @@ fn builtinCall( |
| 6127 | 6127 | .c_import => return cImport( gz, scope, rl, node, params[0]), |
| 6128 | 6128 | |
| 6129 | 6129 | .@"export" => { |
| 6130 | // TODO: @export is supposed to be able to export things other than functions. | |
| 6131 | // Instead of `comptimeExpr` here we need `decl_ref`. | |
| 6132 | const fn_to_export = try comptimeExpr(gz, scope, .none, params[0]); | |
| 6133 | // TODO: the second parameter here is supposed to be | |
| 6134 | // `std.builtin.ExportOptions`, not a string. | |
| 6135 | const export_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]); | |
| 6136 | _ = try gz.addPlNode(.@"export", node, Zir.Inst.Bin{ | |
| 6137 | .lhs = fn_to_export, | |
| 6138 | .rhs = export_name, | |
| 6130 | const node_tags = tree.nodes.items(.tag); | |
| 6131 | // This function causes a Decl to be exported. The first parameter is not an expression, | |
| 6132 | // but an identifier of the Decl to be exported. | |
| 6133 | if (node_tags[params[0]] != .identifier) { | |
| 6134 | return astgen.failNode(params[0], "the first @export parameter must be an identifier", .{}); | |
| 6135 | } | |
| 6136 | const ident_token = main_tokens[params[0]]; | |
| 6137 | const decl_name = try gz.identAsString(ident_token); | |
| 6138 | const options = try comptimeExpr(gz, scope, .{ .ty = .export_options_type }, params[1]); | |
| 6139 | _ = try gz.addPlNode(.@"export", node, Zir.Inst.Export{ | |
| 6140 | .decl_name = decl_name, | |
| 6141 | .options = options, | |
| 6139 | 6142 | }); |
| 6140 | 6143 | return rvalue(gz, scope, rl, .void_value, node); |
| 6141 | 6144 | }, |
src/Sema.zig+9-10| ... | ... | @@ -1766,21 +1766,20 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError! |
| 1766 | 1766 | defer tracy.end(); |
| 1767 | 1767 | |
| 1768 | 1768 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1769 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | |
| 1769 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; | |
| 1770 | 1770 | const src = inst_data.src(); |
| 1771 | 1771 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 1772 | 1772 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 1773 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); | |
| 1774 | const decl = try sema.lookupIdentifier(block, lhs_src, decl_name); | |
| 1775 | const options = try sema.resolveInstConst(block, rhs_src, extra.options); | |
| 1773 | 1776 | |
| 1774 | // TODO (see corresponding TODO in AstGen) this is supposed to be a `decl_ref` | |
| 1775 | // instruction, which could reference any decl, which is then supposed to get | |
| 1776 | // exported, regardless of whether or not it is a function. | |
| 1777 | const target_fn = try sema.resolveInstConst(block, lhs_src, extra.lhs); | |
| 1778 | // TODO (see corresponding TODO in AstGen) this is supposed to be | |
| 1779 | // `std.builtin.ExportOptions`, not a string. | |
| 1780 | const export_name = try sema.resolveConstString(block, rhs_src, extra.rhs); | |
| 1777 | // TODO respect the name, linkage, and section options. Until then we export | |
| 1778 | // as the decl name. | |
| 1779 | _ = options; | |
| 1780 | const export_name = mem.spanZ(decl.name); | |
| 1781 | 1781 | |
| 1782 | const actual_fn = target_fn.val.castTag(.function).?.data; | |
| 1783 | try sema.mod.analyzeExport(&block.base, src, export_name, actual_fn.owner_decl); | |
| 1782 | try sema.mod.analyzeExport(&block.base, src, export_name, decl); | |
| 1784 | 1783 | } |
| 1785 | 1784 | |
| 1786 | 1785 | fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void { |
src/Zir.zig+24-1| ... | ... | @@ -1352,6 +1352,7 @@ pub const Inst = struct { |
| 1352 | 1352 | float_mode_type, |
| 1353 | 1353 | reduce_op_type, |
| 1354 | 1354 | call_options_type, |
| 1355 | export_options_type, | |
| 1355 | 1356 | |
| 1356 | 1357 | /// `undefined` (untyped) |
| 1357 | 1358 | undef, |
| ... | ... | @@ -1575,6 +1576,10 @@ pub const Inst = struct { |
| 1575 | 1576 | .ty = Type.initTag(.type), |
| 1576 | 1577 | .val = Value.initTag(.call_options_type), |
| 1577 | 1578 | }, |
| 1579 | .export_options_type = .{ | |
| 1580 | .ty = Type.initTag(.type), | |
| 1581 | .val = Value.initTag(.export_options_type), | |
| 1582 | }, | |
| 1578 | 1583 | |
| 1579 | 1584 | .undef = .{ |
| 1580 | 1585 | .ty = Type.initTag(.@"undefined"), |
| ... | ... | @@ -2214,6 +2219,12 @@ pub const Inst = struct { |
| 2214 | 2219 | src_node: i32, |
| 2215 | 2220 | }; |
| 2216 | 2221 | |
| 2222 | pub const Export = struct { | |
| 2223 | /// Null-terminated string index. | |
| 2224 | decl_name: u32, | |
| 2225 | options: Ref, | |
| 2226 | }; | |
| 2227 | ||
| 2217 | 2228 | /// Trailing: `CompileErrors.Item` for each `items_len`. |
| 2218 | 2229 | pub const CompileErrors = struct { |
| 2219 | 2230 | items_len: u32, |
| ... | ... | @@ -2451,7 +2462,6 @@ const Writer = struct { |
| 2451 | 2462 | .xor, |
| 2452 | 2463 | .store_node, |
| 2453 | 2464 | .error_union_type, |
| 2454 | .@"export", | |
| 2455 | 2465 | .merge_error_sets, |
| 2456 | 2466 | .bit_and, |
| 2457 | 2467 | .bit_or, |
| ... | ... | @@ -2479,6 +2489,8 @@ const Writer = struct { |
| 2479 | 2489 | .bitcast_result_ptr, |
| 2480 | 2490 | => try self.writePlNodeBin(stream, inst), |
| 2481 | 2491 | |
| 2492 | .@"export" => try self.writePlNodeExport(stream, inst), | |
| 2493 | ||
| 2482 | 2494 | .call, |
| 2483 | 2495 | .call_chkused, |
| 2484 | 2496 | .call_compile_time, |
| ... | ... | @@ -2729,6 +2741,17 @@ const Writer = struct { |
| 2729 | 2741 | try self.writeSrc(stream, inst_data.src()); |
| 2730 | 2742 | } |
| 2731 | 2743 | |
| 2744 | fn writePlNodeExport(self: *Writer, stream: anytype, inst: Inst.Index) !void { | |
| 2745 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; | |
| 2746 | const extra = self.code.extraData(Inst.Export, inst_data.payload_index).data; | |
| 2747 | const decl_name = self.code.nullTerminatedString(extra.decl_name); | |
| 2748 | ||
| 2749 | try stream.print("{}, ", .{std.zig.fmtId(decl_name)}); | |
| 2750 | try self.writeInstRef(stream, extra.options); | |
| 2751 | try stream.writeAll(") "); | |
| 2752 | try self.writeSrc(stream, inst_data.src()); | |
| 2753 | } | |
| 2754 | ||
| 2732 | 2755 | fn writePlNodeErrorSetDecl(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 2733 | 2756 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 2734 | 2757 | const extra = self.code.extraData(Inst.ErrorSetDecl, inst_data.payload_index); |
src/type.zig+18| ... | ... | @@ -99,6 +99,7 @@ pub const Type = extern union { |
| 99 | 99 | .empty_struct_literal, |
| 100 | 100 | .@"struct", |
| 101 | 101 | .call_options, |
| 102 | .export_options, | |
| 102 | 103 | => return .Struct, |
| 103 | 104 | |
| 104 | 105 | .enum_full, |
| ... | ... | @@ -616,6 +617,7 @@ pub const Type = extern union { |
| 616 | 617 | .float_mode, |
| 617 | 618 | .reduce_op, |
| 618 | 619 | .call_options, |
| 620 | .export_options, | |
| 619 | 621 | => unreachable, |
| 620 | 622 | |
| 621 | 623 | .array_u8, |
| ... | ... | @@ -794,6 +796,7 @@ pub const Type = extern union { |
| 794 | 796 | .float_mode => return writer.writeAll("std.builtin.FloatMode"), |
| 795 | 797 | .reduce_op => return writer.writeAll("std.builtin.ReduceOp"), |
| 796 | 798 | .call_options => return writer.writeAll("std.builtin.CallOptions"), |
| 799 | .export_options => return writer.writeAll("std.builtin.ExportOptions"), | |
| 797 | 800 | .function => { |
| 798 | 801 | const payload = ty.castTag(.function).?.data; |
| 799 | 802 | try writer.writeAll("fn("); |
| ... | ... | @@ -1008,6 +1011,7 @@ pub const Type = extern union { |
| 1008 | 1011 | .float_mode => return Value.initTag(.float_mode_type), |
| 1009 | 1012 | .reduce_op => return Value.initTag(.reduce_op_type), |
| 1010 | 1013 | .call_options => return Value.initTag(.call_options_type), |
| 1014 | .export_options => return Value.initTag(.export_options_type), | |
| 1011 | 1015 | .inferred_alloc_const => unreachable, |
| 1012 | 1016 | .inferred_alloc_mut => unreachable, |
| 1013 | 1017 | else => return Value.Tag.ty.create(allocator, self), |
| ... | ... | @@ -1065,6 +1069,7 @@ pub const Type = extern union { |
| 1065 | 1069 | .float_mode, |
| 1066 | 1070 | .reduce_op, |
| 1067 | 1071 | .call_options, |
| 1072 | .export_options, | |
| 1068 | 1073 | => true, |
| 1069 | 1074 | |
| 1070 | 1075 | .@"struct" => { |
| ... | ... | @@ -1175,6 +1180,7 @@ pub const Type = extern union { |
| 1175 | 1180 | .float_mode, |
| 1176 | 1181 | .reduce_op, |
| 1177 | 1182 | .call_options, |
| 1183 | .export_options, | |
| 1178 | 1184 | => return 1, |
| 1179 | 1185 | |
| 1180 | 1186 | .fn_noreturn_no_args, // represents machine code; not a pointer |
| ... | ... | @@ -1352,6 +1358,7 @@ pub const Type = extern union { |
| 1352 | 1358 | .float_mode, |
| 1353 | 1359 | .reduce_op, |
| 1354 | 1360 | .call_options, |
| 1361 | .export_options, | |
| 1355 | 1362 | => return 1, |
| 1356 | 1363 | |
| 1357 | 1364 | .array_u8 => self.castTag(.array_u8).?.data, |
| ... | ... | @@ -1615,6 +1622,7 @@ pub const Type = extern union { |
| 1615 | 1622 | .float_mode, |
| 1616 | 1623 | .reduce_op, |
| 1617 | 1624 | .call_options, |
| 1625 | .export_options, | |
| 1618 | 1626 | => @panic("TODO at some point we gotta resolve builtin types"), |
| 1619 | 1627 | }; |
| 1620 | 1628 | } |
| ... | ... | @@ -2238,6 +2246,7 @@ pub const Type = extern union { |
| 2238 | 2246 | .float_mode, |
| 2239 | 2247 | .reduce_op, |
| 2240 | 2248 | .call_options, |
| 2249 | .export_options, | |
| 2241 | 2250 | => return null, |
| 2242 | 2251 | |
| 2243 | 2252 | .@"struct" => { |
| ... | ... | @@ -2403,6 +2412,7 @@ pub const Type = extern union { |
| 2403 | 2412 | .float_mode, |
| 2404 | 2413 | .reduce_op, |
| 2405 | 2414 | .call_options, |
| 2415 | .export_options, | |
| 2406 | 2416 | => @panic("TODO resolve std.builtin types"), |
| 2407 | 2417 | |
| 2408 | 2418 | else => unreachable, |
| ... | ... | @@ -2425,6 +2435,7 @@ pub const Type = extern union { |
| 2425 | 2435 | .float_mode, |
| 2426 | 2436 | .reduce_op, |
| 2427 | 2437 | .call_options, |
| 2438 | .export_options, | |
| 2428 | 2439 | => @panic("TODO resolve std.builtin types"), |
| 2429 | 2440 | else => unreachable, |
| 2430 | 2441 | } |
| ... | ... | @@ -2446,6 +2457,7 @@ pub const Type = extern union { |
| 2446 | 2457 | .float_mode, |
| 2447 | 2458 | .reduce_op, |
| 2448 | 2459 | .call_options, |
| 2460 | .export_options, | |
| 2449 | 2461 | => @panic("TODO resolve std.builtin types"), |
| 2450 | 2462 | else => unreachable, |
| 2451 | 2463 | } |
| ... | ... | @@ -2489,6 +2501,7 @@ pub const Type = extern union { |
| 2489 | 2501 | .float_mode, |
| 2490 | 2502 | .reduce_op, |
| 2491 | 2503 | .call_options, |
| 2504 | .export_options, | |
| 2492 | 2505 | => @panic("TODO resolve std.builtin types"), |
| 2493 | 2506 | else => unreachable, |
| 2494 | 2507 | } |
| ... | ... | @@ -2518,6 +2531,7 @@ pub const Type = extern union { |
| 2518 | 2531 | .float_mode, |
| 2519 | 2532 | .reduce_op, |
| 2520 | 2533 | .call_options, |
| 2534 | .export_options, | |
| 2521 | 2535 | => @panic("TODO resolve std.builtin types"), |
| 2522 | 2536 | else => unreachable, |
| 2523 | 2537 | } |
| ... | ... | @@ -2548,6 +2562,7 @@ pub const Type = extern union { |
| 2548 | 2562 | .float_mode, |
| 2549 | 2563 | .reduce_op, |
| 2550 | 2564 | .call_options, |
| 2565 | .export_options, | |
| 2551 | 2566 | => @panic("TODO resolve std.builtin types"), |
| 2552 | 2567 | else => unreachable, |
| 2553 | 2568 | } |
| ... | ... | @@ -2587,6 +2602,7 @@ pub const Type = extern union { |
| 2587 | 2602 | .float_mode, |
| 2588 | 2603 | .reduce_op, |
| 2589 | 2604 | .call_options, |
| 2605 | .export_options, | |
| 2590 | 2606 | => @panic("TODO resolve std.builtin types"), |
| 2591 | 2607 | |
| 2592 | 2608 | else => unreachable, |
| ... | ... | @@ -2643,6 +2659,7 @@ pub const Type = extern union { |
| 2643 | 2659 | float_mode, |
| 2644 | 2660 | reduce_op, |
| 2645 | 2661 | call_options, |
| 2662 | export_options, | |
| 2646 | 2663 | @"null", |
| 2647 | 2664 | @"undefined", |
| 2648 | 2665 | fn_noreturn_no_args, |
| ... | ... | @@ -2754,6 +2771,7 @@ pub const Type = extern union { |
| 2754 | 2771 | .float_mode, |
| 2755 | 2772 | .reduce_op, |
| 2756 | 2773 | .call_options, |
| 2774 | .export_options, | |
| 2757 | 2775 | => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"), |
| 2758 | 2776 | |
| 2759 | 2777 | .array_u8, |
src/value.zig+7| ... | ... | @@ -72,6 +72,7 @@ pub const Value = extern union { |
| 72 | 72 | float_mode_type, |
| 73 | 73 | reduce_op_type, |
| 74 | 74 | call_options_type, |
| 75 | export_options_type, | |
| 75 | 76 | |
| 76 | 77 | undef, |
| 77 | 78 | zero, |
| ... | ... | @@ -185,6 +186,7 @@ pub const Value = extern union { |
| 185 | 186 | .float_mode_type, |
| 186 | 187 | .reduce_op_type, |
| 187 | 188 | .call_options_type, |
| 189 | .export_options_type, | |
| 188 | 190 | => @compileError("Value Tag " ++ @tagName(t) ++ " has no payload"), |
| 189 | 191 | |
| 190 | 192 | .int_big_positive, |
| ... | ... | @@ -351,6 +353,7 @@ pub const Value = extern union { |
| 351 | 353 | .float_mode_type, |
| 352 | 354 | .reduce_op_type, |
| 353 | 355 | .call_options_type, |
| 356 | .export_options_type, | |
| 354 | 357 | => unreachable, |
| 355 | 358 | |
| 356 | 359 | .ty => { |
| ... | ... | @@ -506,6 +509,7 @@ pub const Value = extern union { |
| 506 | 509 | .float_mode_type => return out_stream.writeAll("std.builtin.FloatMode"), |
| 507 | 510 | .reduce_op_type => return out_stream.writeAll("std.builtin.ReduceOp"), |
| 508 | 511 | .call_options_type => return out_stream.writeAll("std.builtin.CallOptions"), |
| 512 | .export_options_type => return out_stream.writeAll("std.builtin.ExportOptions"), | |
| 509 | 513 | .abi_align_default => return out_stream.writeAll("(default ABI alignment)"), |
| 510 | 514 | |
| 511 | 515 | .empty_struct_value => return out_stream.writeAll("struct {}{}"), |
| ... | ... | @@ -635,6 +639,7 @@ pub const Value = extern union { |
| 635 | 639 | .float_mode_type => Type.initTag(.float_mode), |
| 636 | 640 | .reduce_op_type => Type.initTag(.reduce_op), |
| 637 | 641 | .call_options_type => Type.initTag(.call_options), |
| 642 | .export_options_type => Type.initTag(.export_options), | |
| 638 | 643 | |
| 639 | 644 | .int_type => { |
| 640 | 645 | const payload = self.castTag(.int_type).?.data; |
| ... | ... | @@ -1181,6 +1186,7 @@ pub const Value = extern union { |
| 1181 | 1186 | .float_mode_type, |
| 1182 | 1187 | .reduce_op_type, |
| 1183 | 1188 | .call_options_type, |
| 1189 | .export_options_type, | |
| 1184 | 1190 | => @panic("TODO this hash function looks pretty broken. audit it"), |
| 1185 | 1191 | } |
| 1186 | 1192 | return hasher.final(); |
| ... | ... | @@ -1336,6 +1342,7 @@ pub const Value = extern union { |
| 1336 | 1342 | .float_mode_type, |
| 1337 | 1343 | .reduce_op_type, |
| 1338 | 1344 | .call_options_type, |
| 1345 | .export_options_type, | |
| 1339 | 1346 | => true, |
| 1340 | 1347 | |
| 1341 | 1348 | .zero, |