| ... | ... | @@ -21,11 +21,9 @@ air_values: std.ArrayListUnmanaged(Value) = .{}, |
| 21 | 21 | /// Maps ZIR to AIR. |
| 22 | 22 | inst_map: InstMap = .{}, |
| 23 | 23 | /// When analyzing an inline function call, owner_decl is the Decl of the caller |
| 24 | | /// and `src_decl` of `Scope.Block` is the `Decl` of the callee. |
| 24 | /// and `src_decl` of `Block` is the `Decl` of the callee. |
| 25 | 25 | /// This `Decl` owns the arena memory of this `Sema`. |
| 26 | 26 | owner_decl: *Decl, |
| 27 | | /// How to look up decl names. |
| 28 | | namespace: *Scope.Namespace, |
| 29 | 27 | /// For an inline or comptime function call, this will be the root parent function |
| 30 | 28 | /// which contains the callsite. Corresponds to `owner_decl`. |
| 31 | 29 | owner_func: ?*Module.Fn, |
| ... | ... | @@ -62,9 +60,6 @@ comptime_args_fn_inst: Zir.Inst.Index = 0, |
| 62 | 60 | /// extra hash table lookup in the `monomorphed_funcs` set. |
| 63 | 61 | /// Sema will set this to null when it takes ownership. |
| 64 | 62 | preallocated_new_func: ?*Module.Fn = null, |
| 65 | | /// Collects struct, union, enum, and opaque decls which need to have their |
| 66 | | /// fields resolved before this Sema is deinitialized. |
| 67 | | types_pending_resolution: std.ArrayListUnmanaged(Type) = .{}, |
| 68 | 63 | |
| 69 | 64 | const std = @import("std"); |
| 70 | 65 | const mem = std.mem; |
| ... | ... | @@ -80,7 +75,7 @@ const Air = @import("Air.zig"); |
| 80 | 75 | const Zir = @import("Zir.zig"); |
| 81 | 76 | const Module = @import("Module.zig"); |
| 82 | 77 | const trace = @import("tracy.zig").trace; |
| 83 | | const Scope = Module.Scope; |
| 78 | const Namespace = Module.Namespace; |
| 84 | 79 | const CompileError = Module.CompileError; |
| 85 | 80 | const SemaError = Module.SemaError; |
| 86 | 81 | const Decl = Module.Decl; |
| ... | ... | @@ -94,6 +89,286 @@ const crash_report = @import("crash_report.zig"); |
| 94 | 89 | |
| 95 | 90 | pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Ref); |
| 96 | 91 | |
| 92 | /// This is the context needed to semantically analyze ZIR instructions and |
| 93 | /// produce AIR instructions. |
| 94 | /// This is a temporary structure stored on the stack; references to it are valid only |
| 95 | /// during semantic analysis of the block. |
| 96 | pub const Block = struct { |
| 97 | parent: ?*Block, |
| 98 | /// Shared among all child blocks. |
| 99 | sema: *Sema, |
| 100 | /// This Decl is the Decl according to the Zig source code corresponding to this Block. |
| 101 | /// This can vary during inline or comptime function calls. See `Sema.owner_decl` |
| 102 | /// for the one that will be the same for all Block instances. |
| 103 | src_decl: *Decl, |
| 104 | /// The namespace to use for lookups from this source block |
| 105 | /// When analyzing fields, this is different from src_decl.src_namepsace. |
| 106 | namespace: *Namespace, |
| 107 | /// The AIR instructions generated for this block. |
| 108 | instructions: std.ArrayListUnmanaged(Air.Inst.Index), |
| 109 | // `param` instructions are collected here to be used by the `func` instruction. |
| 110 | params: std.ArrayListUnmanaged(Param) = .{}, |
| 111 | |
| 112 | wip_capture_scope: *CaptureScope, |
| 113 | |
| 114 | label: ?*Label = null, |
| 115 | inlining: ?*Inlining, |
| 116 | /// If runtime_index is not 0 then one of these is guaranteed to be non null. |
| 117 | runtime_cond: ?LazySrcLoc = null, |
| 118 | runtime_loop: ?LazySrcLoc = null, |
| 119 | /// Non zero if a non-inline loop or a runtime conditional have been encountered. |
| 120 | /// Stores to to comptime variables are only allowed when var.runtime_index <= runtime_index. |
| 121 | runtime_index: u32 = 0, |
| 122 | |
| 123 | is_comptime: bool, |
| 124 | |
| 125 | /// when null, it is determined by build mode, changed by @setRuntimeSafety |
| 126 | want_safety: ?bool = null, |
| 127 | |
| 128 | c_import_buf: ?*std.ArrayList(u8) = null, |
| 129 | |
| 130 | const Param = struct { |
| 131 | /// `noreturn` means `anytype`. |
| 132 | ty: Type, |
| 133 | is_comptime: bool, |
| 134 | }; |
| 135 | |
| 136 | /// This `Block` maps a block ZIR instruction to the corresponding |
| 137 | /// AIR instruction for break instruction analysis. |
| 138 | pub const Label = struct { |
| 139 | zir_block: Zir.Inst.Index, |
| 140 | merges: Merges, |
| 141 | }; |
| 142 | |
| 143 | /// This `Block` indicates that an inline function call is happening |
| 144 | /// and return instructions should be analyzed as a break instruction |
| 145 | /// to this AIR block instruction. |
| 146 | /// It is shared among all the blocks in an inline or comptime called |
| 147 | /// function. |
| 148 | pub const Inlining = struct { |
| 149 | comptime_result: Air.Inst.Ref, |
| 150 | merges: Merges, |
| 151 | }; |
| 152 | |
| 153 | pub const Merges = struct { |
| 154 | block_inst: Air.Inst.Index, |
| 155 | /// Separate array list from break_inst_list so that it can be passed directly |
| 156 | /// to resolvePeerTypes. |
| 157 | results: std.ArrayListUnmanaged(Air.Inst.Ref), |
| 158 | /// Keeps track of the break instructions so that the operand can be replaced |
| 159 | /// if we need to add type coercion at the end of block analysis. |
| 160 | /// Same indexes, capacity, length as `results`. |
| 161 | br_list: std.ArrayListUnmanaged(Air.Inst.Index), |
| 162 | }; |
| 163 | |
| 164 | /// For debugging purposes. |
| 165 | pub fn dump(block: *Block, mod: Module) void { |
| 166 | Zir.dumpBlock(mod, block); |
| 167 | } |
| 168 | |
| 169 | pub fn makeSubBlock(parent: *Block) Block { |
| 170 | return .{ |
| 171 | .parent = parent, |
| 172 | .sema = parent.sema, |
| 173 | .src_decl = parent.src_decl, |
| 174 | .namespace = parent.namespace, |
| 175 | .instructions = .{}, |
| 176 | .wip_capture_scope = parent.wip_capture_scope, |
| 177 | .label = null, |
| 178 | .inlining = parent.inlining, |
| 179 | .is_comptime = parent.is_comptime, |
| 180 | .runtime_cond = parent.runtime_cond, |
| 181 | .runtime_loop = parent.runtime_loop, |
| 182 | .runtime_index = parent.runtime_index, |
| 183 | .want_safety = parent.want_safety, |
| 184 | .c_import_buf = parent.c_import_buf, |
| 185 | }; |
| 186 | } |
| 187 | |
| 188 | pub fn wantSafety(block: *const Block) bool { |
| 189 | return block.want_safety orelse switch (block.sema.mod.optimizeMode()) { |
| 190 | .Debug => true, |
| 191 | .ReleaseSafe => true, |
| 192 | .ReleaseFast => false, |
| 193 | .ReleaseSmall => false, |
| 194 | }; |
| 195 | } |
| 196 | |
| 197 | pub fn getFileScope(block: *Block) *Module.File { |
| 198 | return block.namespace.file_scope; |
| 199 | } |
| 200 | |
| 201 | pub fn addTy( |
| 202 | block: *Block, |
| 203 | tag: Air.Inst.Tag, |
| 204 | ty: Type, |
| 205 | ) error{OutOfMemory}!Air.Inst.Ref { |
| 206 | return block.addInst(.{ |
| 207 | .tag = tag, |
| 208 | .data = .{ .ty = ty }, |
| 209 | }); |
| 210 | } |
| 211 | |
| 212 | pub fn addTyOp( |
| 213 | block: *Block, |
| 214 | tag: Air.Inst.Tag, |
| 215 | ty: Type, |
| 216 | operand: Air.Inst.Ref, |
| 217 | ) error{OutOfMemory}!Air.Inst.Ref { |
| 218 | return block.addInst(.{ |
| 219 | .tag = tag, |
| 220 | .data = .{ .ty_op = .{ |
| 221 | .ty = try block.sema.addType(ty), |
| 222 | .operand = operand, |
| 223 | } }, |
| 224 | }); |
| 225 | } |
| 226 | |
| 227 | pub fn addNoOp(block: *Block, tag: Air.Inst.Tag) error{OutOfMemory}!Air.Inst.Ref { |
| 228 | return block.addInst(.{ |
| 229 | .tag = tag, |
| 230 | .data = .{ .no_op = {} }, |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | pub fn addUnOp( |
| 235 | block: *Block, |
| 236 | tag: Air.Inst.Tag, |
| 237 | operand: Air.Inst.Ref, |
| 238 | ) error{OutOfMemory}!Air.Inst.Ref { |
| 239 | return block.addInst(.{ |
| 240 | .tag = tag, |
| 241 | .data = .{ .un_op = operand }, |
| 242 | }); |
| 243 | } |
| 244 | |
| 245 | pub fn addBr( |
| 246 | block: *Block, |
| 247 | target_block: Air.Inst.Index, |
| 248 | operand: Air.Inst.Ref, |
| 249 | ) error{OutOfMemory}!Air.Inst.Ref { |
| 250 | return block.addInst(.{ |
| 251 | .tag = .br, |
| 252 | .data = .{ .br = .{ |
| 253 | .block_inst = target_block, |
| 254 | .operand = operand, |
| 255 | } }, |
| 256 | }); |
| 257 | } |
| 258 | |
| 259 | pub fn addBinOp( |
| 260 | block: *Block, |
| 261 | tag: Air.Inst.Tag, |
| 262 | lhs: Air.Inst.Ref, |
| 263 | rhs: Air.Inst.Ref, |
| 264 | ) error{OutOfMemory}!Air.Inst.Ref { |
| 265 | return block.addInst(.{ |
| 266 | .tag = tag, |
| 267 | .data = .{ .bin_op = .{ |
| 268 | .lhs = lhs, |
| 269 | .rhs = rhs, |
| 270 | } }, |
| 271 | }); |
| 272 | } |
| 273 | |
| 274 | pub fn addArg(block: *Block, ty: Type, name: u32) error{OutOfMemory}!Air.Inst.Ref { |
| 275 | return block.addInst(.{ |
| 276 | .tag = .arg, |
| 277 | .data = .{ .ty_str = .{ |
| 278 | .ty = try block.sema.addType(ty), |
| 279 | .str = name, |
| 280 | } }, |
| 281 | }); |
| 282 | } |
| 283 | |
| 284 | pub fn addStructFieldPtr( |
| 285 | block: *Block, |
| 286 | struct_ptr: Air.Inst.Ref, |
| 287 | field_index: u32, |
| 288 | ptr_field_ty: Type, |
| 289 | ) !Air.Inst.Ref { |
| 290 | const ty = try block.sema.addType(ptr_field_ty); |
| 291 | const tag: Air.Inst.Tag = switch (field_index) { |
| 292 | 0 => .struct_field_ptr_index_0, |
| 293 | 1 => .struct_field_ptr_index_1, |
| 294 | 2 => .struct_field_ptr_index_2, |
| 295 | 3 => .struct_field_ptr_index_3, |
| 296 | else => { |
| 297 | return block.addInst(.{ |
| 298 | .tag = .struct_field_ptr, |
| 299 | .data = .{ .ty_pl = .{ |
| 300 | .ty = ty, |
| 301 | .payload = try block.sema.addExtra(Air.StructField{ |
| 302 | .struct_operand = struct_ptr, |
| 303 | .field_index = @intCast(u32, field_index), |
| 304 | }), |
| 305 | } }, |
| 306 | }); |
| 307 | }, |
| 308 | }; |
| 309 | return block.addInst(.{ |
| 310 | .tag = tag, |
| 311 | .data = .{ .ty_op = .{ |
| 312 | .ty = ty, |
| 313 | .operand = struct_ptr, |
| 314 | } }, |
| 315 | }); |
| 316 | } |
| 317 | |
| 318 | pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref { |
| 319 | return Air.indexToRef(try block.addInstAsIndex(inst)); |
| 320 | } |
| 321 | |
| 322 | pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index { |
| 323 | const sema = block.sema; |
| 324 | const gpa = sema.gpa; |
| 325 | |
| 326 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 327 | try block.instructions.ensureUnusedCapacity(gpa, 1); |
| 328 | |
| 329 | const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len); |
| 330 | sema.air_instructions.appendAssumeCapacity(inst); |
| 331 | block.instructions.appendAssumeCapacity(result_index); |
| 332 | return result_index; |
| 333 | } |
| 334 | |
| 335 | pub fn startAnonDecl(block: *Block) !WipAnonDecl { |
| 336 | return WipAnonDecl{ |
| 337 | .block = block, |
| 338 | .new_decl_arena = std.heap.ArenaAllocator.init(block.sema.gpa), |
| 339 | .finished = false, |
| 340 | }; |
| 341 | } |
| 342 | |
| 343 | pub const WipAnonDecl = struct { |
| 344 | block: *Block, |
| 345 | new_decl_arena: std.heap.ArenaAllocator, |
| 346 | finished: bool, |
| 347 | |
| 348 | pub fn arena(wad: *WipAnonDecl) *Allocator { |
| 349 | return &wad.new_decl_arena.allocator; |
| 350 | } |
| 351 | |
| 352 | pub fn deinit(wad: *WipAnonDecl) void { |
| 353 | if (!wad.finished) { |
| 354 | wad.new_decl_arena.deinit(); |
| 355 | } |
| 356 | wad.* = undefined; |
| 357 | } |
| 358 | |
| 359 | pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value) !*Decl { |
| 360 | const new_decl = try wad.block.sema.mod.createAnonymousDecl(wad.block, .{ |
| 361 | .ty = ty, |
| 362 | .val = val, |
| 363 | }); |
| 364 | errdefer wad.block.sema.mod.abortAnonDecl(new_decl); |
| 365 | try new_decl.finalizeNewArena(&wad.new_decl_arena); |
| 366 | wad.finished = true; |
| 367 | return new_decl; |
| 368 | } |
| 369 | }; |
| 370 | }; |
| 371 | |
| 97 | 372 | pub fn deinit(sema: *Sema) void { |
| 98 | 373 | const gpa = sema.gpa; |
| 99 | 374 | sema.air_instructions.deinit(gpa); |
| ... | ... | @@ -101,14 +376,13 @@ pub fn deinit(sema: *Sema) void { |
| 101 | 376 | sema.air_values.deinit(gpa); |
| 102 | 377 | sema.inst_map.deinit(gpa); |
| 103 | 378 | sema.decl_val_table.deinit(gpa); |
| 104 | | sema.types_pending_resolution.deinit(gpa); |
| 105 | 379 | sema.* = undefined; |
| 106 | 380 | } |
| 107 | 381 | |
| 108 | 382 | /// Returns only the result from the body that is specified. |
| 109 | 383 | /// Only appropriate to call when it is determined at comptime that this body |
| 110 | 384 | /// has no peers. |
| 111 | | fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 385 | fn resolveBody(sema: *Sema, block: *Block, body: []const Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 112 | 386 | const break_inst = try sema.analyzeBody(block, body); |
| 113 | 387 | const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand; |
| 114 | 388 | return sema.resolveInst(operand_ref); |
| ... | ... | @@ -131,7 +405,7 @@ const always_noreturn: CompileError!Zir.Inst.Index = @as(Zir.Inst.Index, undefin |
| 131 | 405 | /// well as the operand. No block scope needs to be created for this strategy. |
| 132 | 406 | pub fn analyzeBody( |
| 133 | 407 | sema: *Sema, |
| 134 | | block: *Scope.Block, |
| 408 | block: *Block, |
| 135 | 409 | body: []const Zir.Inst.Index, |
| 136 | 410 | ) CompileError!Zir.Inst.Index { |
| 137 | 411 | // No tracy calls here, to avoid interfering with the tail call mechanism. |
| ... | ... | @@ -148,9 +422,9 @@ pub fn analyzeBody( |
| 148 | 422 | wip_captures.deinit(); |
| 149 | 423 | }; |
| 150 | 424 | |
| 151 | | const map = &block.sema.inst_map; |
| 152 | | const tags = block.sema.code.instructions.items(.tag); |
| 153 | | const datas = block.sema.code.instructions.items(.data); |
| 425 | const map = &sema.inst_map; |
| 426 | const tags = sema.code.instructions.items(.tag); |
| 427 | const datas = sema.code.instructions.items(.data); |
| 154 | 428 | |
| 155 | 429 | var orig_captures: usize = parent_capture_scope.captures.count(); |
| 156 | 430 | |
| ... | ... | @@ -673,7 +947,7 @@ pub fn analyzeBody( |
| 673 | 947 | return result; |
| 674 | 948 | } |
| 675 | 949 | |
| 676 | | fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 950 | fn zirExtended(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 677 | 951 | const extended = sema.code.instructions.items(.data)[inst].extended; |
| 678 | 952 | switch (extended.opcode) { |
| 679 | 953 | // zig fmt: off |
| ... | ... | @@ -725,7 +999,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref { |
| 725 | 999 | |
| 726 | 1000 | fn resolveConstBool( |
| 727 | 1001 | sema: *Sema, |
| 728 | | block: *Scope.Block, |
| 1002 | block: *Block, |
| 729 | 1003 | src: LazySrcLoc, |
| 730 | 1004 | zir_ref: Zir.Inst.Ref, |
| 731 | 1005 | ) !bool { |
| ... | ... | @@ -738,7 +1012,7 @@ fn resolveConstBool( |
| 738 | 1012 | |
| 739 | 1013 | fn resolveConstString( |
| 740 | 1014 | sema: *Sema, |
| 741 | | block: *Scope.Block, |
| 1015 | block: *Block, |
| 742 | 1016 | src: LazySrcLoc, |
| 743 | 1017 | zir_ref: Zir.Inst.Ref, |
| 744 | 1018 | ) ![]u8 { |
| ... | ... | @@ -749,14 +1023,14 @@ fn resolveConstString( |
| 749 | 1023 | return val.toAllocatedBytes(sema.arena); |
| 750 | 1024 | } |
| 751 | 1025 | |
| 752 | | pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 1026 | pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 753 | 1027 | const air_inst = sema.resolveInst(zir_ref); |
| 754 | 1028 | return sema.analyzeAsType(block, src, air_inst); |
| 755 | 1029 | } |
| 756 | 1030 | |
| 757 | 1031 | fn analyzeAsType( |
| 758 | 1032 | sema: *Sema, |
| 759 | | block: *Scope.Block, |
| 1033 | block: *Block, |
| 760 | 1034 | src: LazySrcLoc, |
| 761 | 1035 | air_inst: Air.Inst.Ref, |
| 762 | 1036 | ) !Type { |
| ... | ... | @@ -773,7 +1047,7 @@ fn analyzeAsType( |
| 773 | 1047 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. |
| 774 | 1048 | fn resolveValue( |
| 775 | 1049 | sema: *Sema, |
| 776 | | block: *Scope.Block, |
| 1050 | block: *Block, |
| 777 | 1051 | src: LazySrcLoc, |
| 778 | 1052 | air_ref: Air.Inst.Ref, |
| 779 | 1053 | ) CompileError!Value { |
| ... | ... | @@ -788,7 +1062,7 @@ fn resolveValue( |
| 788 | 1062 | /// Value Tag `undef` may be returned. |
| 789 | 1063 | fn resolveConstMaybeUndefVal( |
| 790 | 1064 | sema: *Sema, |
| 791 | | block: *Scope.Block, |
| 1065 | block: *Block, |
| 792 | 1066 | src: LazySrcLoc, |
| 793 | 1067 | inst: Air.Inst.Ref, |
| 794 | 1068 | ) CompileError!Value { |
| ... | ... | @@ -806,7 +1080,7 @@ fn resolveConstMaybeUndefVal( |
| 806 | 1080 | /// See `resolveValue` for an alternative. |
| 807 | 1081 | fn resolveConstValue( |
| 808 | 1082 | sema: *Sema, |
| 809 | | block: *Scope.Block, |
| 1083 | block: *Block, |
| 810 | 1084 | src: LazySrcLoc, |
| 811 | 1085 | air_ref: Air.Inst.Ref, |
| 812 | 1086 | ) CompileError!Value { |
| ... | ... | @@ -825,7 +1099,7 @@ fn resolveConstValue( |
| 825 | 1099 | /// Value Tag `undef` causes this function to return a compile error. |
| 826 | 1100 | fn resolveDefinedValue( |
| 827 | 1101 | sema: *Sema, |
| 828 | | block: *Scope.Block, |
| 1102 | block: *Block, |
| 829 | 1103 | src: LazySrcLoc, |
| 830 | 1104 | air_ref: Air.Inst.Ref, |
| 831 | 1105 | ) CompileError!?Value { |
| ... | ... | @@ -843,7 +1117,7 @@ fn resolveDefinedValue( |
| 843 | 1117 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. |
| 844 | 1118 | fn resolveMaybeUndefVal( |
| 845 | 1119 | sema: *Sema, |
| 846 | | block: *Scope.Block, |
| 1120 | block: *Block, |
| 847 | 1121 | src: LazySrcLoc, |
| 848 | 1122 | inst: Air.Inst.Ref, |
| 849 | 1123 | ) CompileError!?Value { |
| ... | ... | @@ -858,7 +1132,7 @@ fn resolveMaybeUndefVal( |
| 858 | 1132 | /// Returns all Value tags including `variable` and `undef`. |
| 859 | 1133 | fn resolveMaybeUndefValAllowVariables( |
| 860 | 1134 | sema: *Sema, |
| 861 | | block: *Scope.Block, |
| 1135 | block: *Block, |
| 862 | 1136 | src: LazySrcLoc, |
| 863 | 1137 | inst: Air.Inst.Ref, |
| 864 | 1138 | ) CompileError!?Value { |
| ... | ... | @@ -885,20 +1159,77 @@ fn resolveMaybeUndefValAllowVariables( |
| 885 | 1159 | } |
| 886 | 1160 | } |
| 887 | 1161 | |
| 888 | | fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { |
| 889 | | return sema.mod.fail(&block.base, src, "unable to resolve comptime value", .{}); |
| 1162 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 1163 | return sema.fail(block, src, "unable to resolve comptime value", .{}); |
| 1164 | } |
| 1165 | |
| 1166 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 1167 | return sema.fail(block, src, "use of undefined value here causes undefined behavior", .{}); |
| 890 | 1168 | } |
| 891 | 1169 | |
| 892 | | fn failWithUseOfUndef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { |
| 893 | | return sema.mod.fail(&block.base, src, "use of undefined value here causes undefined behavior", .{}); |
| 1170 | fn failWithDivideByZero(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 1171 | return sema.fail(block, src, "division by zero here causes undefined behavior", .{}); |
| 894 | 1172 | } |
| 895 | 1173 | |
| 896 | | fn failWithDivideByZero(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { |
| 897 | | return sema.mod.fail(&block.base, src, "division by zero here causes undefined behavior", .{}); |
| 1174 | fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError { |
| 1175 | return sema.fail(block, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty }); |
| 898 | 1176 | } |
| 899 | 1177 | |
| 900 | | fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError { |
| 901 | | return sema.mod.fail(&block.base, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty }); |
| 1178 | /// We don't return a pointer to the new error note because the pointer |
| 1179 | /// becomes invalid when you add another one. |
| 1180 | fn errNote( |
| 1181 | sema: *Sema, |
| 1182 | block: *Block, |
| 1183 | src: LazySrcLoc, |
| 1184 | parent: *Module.ErrorMsg, |
| 1185 | comptime format: []const u8, |
| 1186 | args: anytype, |
| 1187 | ) error{OutOfMemory}!void { |
| 1188 | return sema.mod.errNoteNonLazy(src.toSrcLoc(block.src_decl), parent, format, args); |
| 1189 | } |
| 1190 | |
| 1191 | fn errMsg( |
| 1192 | sema: *Sema, |
| 1193 | block: *Block, |
| 1194 | src: LazySrcLoc, |
| 1195 | comptime format: []const u8, |
| 1196 | args: anytype, |
| 1197 | ) error{OutOfMemory}!*Module.ErrorMsg { |
| 1198 | return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(block.src_decl), format, args); |
| 1199 | } |
| 1200 | |
| 1201 | pub fn fail( |
| 1202 | sema: *Sema, |
| 1203 | block: *Block, |
| 1204 | src: LazySrcLoc, |
| 1205 | comptime format: []const u8, |
| 1206 | args: anytype, |
| 1207 | ) CompileError { |
| 1208 | const err_msg = try sema.errMsg(block, src, format, args); |
| 1209 | return sema.failWithOwnedErrorMsg(err_msg); |
| 1210 | } |
| 1211 | |
| 1212 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 1213 | @setCold(true); |
| 1214 | |
| 1215 | const mod = sema.mod; |
| 1216 | |
| 1217 | { |
| 1218 | errdefer err_msg.destroy(mod.gpa); |
| 1219 | if (err_msg.src_loc.lazy == .unneeded) { |
| 1220 | return error.NeededSourceLocation; |
| 1221 | } |
| 1222 | try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1); |
| 1223 | try mod.failed_files.ensureUnusedCapacity(mod.gpa, 1); |
| 1224 | } |
| 1225 | if (sema.owner_func) |func| { |
| 1226 | func.state = .sema_failure; |
| 1227 | } else { |
| 1228 | sema.owner_decl.analysis = .sema_failure; |
| 1229 | sema.owner_decl.generation = mod.generation; |
| 1230 | } |
| 1231 | mod.failed_decls.putAssumeCapacityNoClobber(sema.owner_decl, err_msg); |
| 1232 | return error.AnalysisFail; |
| 902 | 1233 | } |
| 903 | 1234 | |
| 904 | 1235 | /// Appropriate to call when the coercion has already been done by result |
| ... | ... | @@ -907,7 +1238,7 @@ fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs |
| 907 | 1238 | /// TODO don't ever call this since we're migrating towards ResultLoc.coerced_ty. |
| 908 | 1239 | fn resolveAlreadyCoercedInt( |
| 909 | 1240 | sema: *Sema, |
| 910 | | block: *Scope.Block, |
| 1241 | block: *Block, |
| 911 | 1242 | src: LazySrcLoc, |
| 912 | 1243 | zir_ref: Zir.Inst.Ref, |
| 913 | 1244 | comptime Int: type, |
| ... | ... | @@ -923,15 +1254,15 @@ fn resolveAlreadyCoercedInt( |
| 923 | 1254 | |
| 924 | 1255 | fn resolveAlign( |
| 925 | 1256 | sema: *Sema, |
| 926 | | block: *Scope.Block, |
| 1257 | block: *Block, |
| 927 | 1258 | src: LazySrcLoc, |
| 928 | 1259 | zir_ref: Zir.Inst.Ref, |
| 929 | 1260 | ) !u16 { |
| 930 | 1261 | const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16)); |
| 931 | 1262 | const alignment = @intCast(u16, alignment_big); // We coerce to u16 in the prev line. |
| 932 | | if (alignment == 0) return sema.mod.fail(&block.base, src, "alignment must be >= 1", .{}); |
| 1263 | if (alignment == 0) return sema.fail(block, src, "alignment must be >= 1", .{}); |
| 933 | 1264 | if (!std.math.isPowerOfTwo(alignment)) { |
| 934 | | return sema.mod.fail(&block.base, src, "alignment value {d} is not a power of two", .{ |
| 1265 | return sema.fail(block, src, "alignment value {d} is not a power of two", .{ |
| 935 | 1266 | alignment, |
| 936 | 1267 | }); |
| 937 | 1268 | } |
| ... | ... | @@ -940,7 +1271,7 @@ fn resolveAlign( |
| 940 | 1271 | |
| 941 | 1272 | fn resolveInt( |
| 942 | 1273 | sema: *Sema, |
| 943 | | block: *Scope.Block, |
| 1274 | block: *Block, |
| 944 | 1275 | src: LazySrcLoc, |
| 945 | 1276 | zir_ref: Zir.Inst.Ref, |
| 946 | 1277 | dest_type: Type, |
| ... | ... | @@ -956,7 +1287,7 @@ fn resolveInt( |
| 956 | 1287 | // a function that does not. |
| 957 | 1288 | pub fn resolveInstConst( |
| 958 | 1289 | sema: *Sema, |
| 959 | | block: *Scope.Block, |
| 1290 | block: *Block, |
| 960 | 1291 | src: LazySrcLoc, |
| 961 | 1292 | zir_ref: Zir.Inst.Ref, |
| 962 | 1293 | ) CompileError!TypedValue { |
| ... | ... | @@ -972,7 +1303,7 @@ pub fn resolveInstConst( |
| 972 | 1303 | // See `resolveInstConst` for an alternative. |
| 973 | 1304 | pub fn resolveInstValue( |
| 974 | 1305 | sema: *Sema, |
| 975 | | block: *Scope.Block, |
| 1306 | block: *Block, |
| 976 | 1307 | src: LazySrcLoc, |
| 977 | 1308 | zir_ref: Zir.Inst.Ref, |
| 978 | 1309 | ) CompileError!TypedValue { |
| ... | ... | @@ -984,13 +1315,13 @@ pub fn resolveInstValue( |
| 984 | 1315 | }; |
| 985 | 1316 | } |
| 986 | 1317 | |
| 987 | | fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1318 | fn zirBitcastResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 988 | 1319 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 989 | 1320 | const src = inst_data.src(); |
| 990 | | return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{}); |
| 1321 | return sema.fail(block, src, "TODO implement zir_sema.zirBitcastResultPtr", .{}); |
| 991 | 1322 | } |
| 992 | 1323 | |
| 993 | | fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1324 | fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 994 | 1325 | const tracy = trace(@src()); |
| 995 | 1326 | defer tracy.end(); |
| 996 | 1327 | |
| ... | ... | @@ -1052,7 +1383,7 @@ pub fn analyzeStructDecl( |
| 1052 | 1383 | |
| 1053 | 1384 | fn zirStructDecl( |
| 1054 | 1385 | sema: *Sema, |
| 1055 | | block: *Scope.Block, |
| 1386 | block: *Block, |
| 1056 | 1387 | extended: Zir.Inst.Extended.InstData, |
| 1057 | 1388 | inst: Zir.Inst.Index, |
| 1058 | 1389 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -1069,12 +1400,12 @@ fn zirStructDecl( |
| 1069 | 1400 | const struct_ty = try Type.Tag.@"struct".create(&new_decl_arena.allocator, struct_obj); |
| 1070 | 1401 | const struct_val = try Value.Tag.ty.create(&new_decl_arena.allocator, struct_ty); |
| 1071 | 1402 | const type_name = try sema.createTypeName(block, small.name_strategy); |
| 1072 | | const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{ |
| 1403 | const new_decl = try sema.mod.createAnonymousDeclNamed(block, .{ |
| 1073 | 1404 | .ty = Type.initTag(.type), |
| 1074 | 1405 | .val = struct_val, |
| 1075 | 1406 | }, type_name); |
| 1076 | 1407 | new_decl.owns_tv = true; |
| 1077 | | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 1408 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 1078 | 1409 | struct_obj.* = .{ |
| 1079 | 1410 | .owner_decl = new_decl, |
| 1080 | 1411 | .fields = .{}, |
| ... | ... | @@ -1084,7 +1415,7 @@ fn zirStructDecl( |
| 1084 | 1415 | .status = .none, |
| 1085 | 1416 | .known_has_bits = undefined, |
| 1086 | 1417 | .namespace = .{ |
| 1087 | | .parent = sema.owner_decl.namespace, |
| 1418 | .parent = block.namespace, |
| 1088 | 1419 | .ty = struct_ty, |
| 1089 | 1420 | .file_scope = block.getFileScope(), |
| 1090 | 1421 | }, |
| ... | ... | @@ -1093,13 +1424,11 @@ fn zirStructDecl( |
| 1093 | 1424 | &struct_obj.namespace, new_decl, new_decl.name, |
| 1094 | 1425 | }); |
| 1095 | 1426 | try sema.analyzeStructDecl(new_decl, inst, struct_obj); |
| 1096 | | try sema.types_pending_resolution.ensureUnusedCapacity(sema.gpa, 1); |
| 1097 | 1427 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 1098 | | sema.types_pending_resolution.appendAssumeCapacity(struct_ty); |
| 1099 | 1428 | return sema.analyzeDeclVal(block, src, new_decl); |
| 1100 | 1429 | } |
| 1101 | 1430 | |
| 1102 | | fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 { |
| 1431 | fn createTypeName(sema: *Sema, block: *Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 { |
| 1103 | 1432 | switch (name_strategy) { |
| 1104 | 1433 | .anon => { |
| 1105 | 1434 | // It would be neat to have "struct:line:column" but this name has |
| ... | ... | @@ -1127,7 +1456,7 @@ fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.Name |
| 1127 | 1456 | |
| 1128 | 1457 | fn zirEnumDecl( |
| 1129 | 1458 | sema: *Sema, |
| 1130 | | block: *Scope.Block, |
| 1459 | block: *Block, |
| 1131 | 1460 | extended: Zir.Inst.Extended.InstData, |
| 1132 | 1461 | ) CompileError!Air.Inst.Ref { |
| 1133 | 1462 | const tracy = trace(@src()); |
| ... | ... | @@ -1180,12 +1509,12 @@ fn zirEnumDecl( |
| 1180 | 1509 | const enum_ty = Type.initPayload(&enum_ty_payload.base); |
| 1181 | 1510 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); |
| 1182 | 1511 | const type_name = try sema.createTypeName(block, small.name_strategy); |
| 1183 | | const new_decl = try mod.createAnonymousDeclNamed(&block.base, .{ |
| 1512 | const new_decl = try mod.createAnonymousDeclNamed(block, .{ |
| 1184 | 1513 | .ty = Type.initTag(.type), |
| 1185 | 1514 | .val = enum_val, |
| 1186 | 1515 | }, type_name); |
| 1187 | 1516 | new_decl.owns_tv = true; |
| 1188 | | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 1517 | errdefer mod.abortAnonDecl(new_decl); |
| 1189 | 1518 | |
| 1190 | 1519 | enum_obj.* = .{ |
| 1191 | 1520 | .owner_decl = new_decl, |
| ... | ... | @@ -1194,7 +1523,7 @@ fn zirEnumDecl( |
| 1194 | 1523 | .values = .{}, |
| 1195 | 1524 | .node_offset = src.node_offset, |
| 1196 | 1525 | .namespace = .{ |
| 1197 | | .parent = sema.owner_decl.namespace, |
| 1526 | .parent = block.namespace, |
| 1198 | 1527 | .ty = enum_ty, |
| 1199 | 1528 | .file_scope = block.getFileScope(), |
| 1200 | 1529 | }, |
| ... | ... | @@ -1227,10 +1556,6 @@ fn zirEnumDecl( |
| 1227 | 1556 | sema.owner_decl = new_decl; |
| 1228 | 1557 | defer sema.owner_decl = prev_owner_decl; |
| 1229 | 1558 | |
| 1230 | | const prev_namespace = sema.namespace; |
| 1231 | | sema.namespace = &enum_obj.namespace; |
| 1232 | | defer sema.namespace = prev_namespace; |
| 1233 | | |
| 1234 | 1559 | const prev_owner_func = sema.owner_func; |
| 1235 | 1560 | sema.owner_func = null; |
| 1236 | 1561 | defer sema.owner_func = prev_owner_func; |
| ... | ... | @@ -1242,10 +1567,11 @@ fn zirEnumDecl( |
| 1242 | 1567 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope); |
| 1243 | 1568 | defer wip_captures.deinit(); |
| 1244 | 1569 | |
| 1245 | | var enum_block: Scope.Block = .{ |
| 1570 | var enum_block: Block = .{ |
| 1246 | 1571 | .parent = null, |
| 1247 | 1572 | .sema = sema, |
| 1248 | 1573 | .src_decl = new_decl, |
| 1574 | .namespace = &enum_obj.namespace, |
| 1249 | 1575 | .wip_capture_scope = wip_captures.scope, |
| 1250 | 1576 | .instructions = .{}, |
| 1251 | 1577 | .inlining = null, |
| ... | ... | @@ -1303,12 +1629,12 @@ fn zirEnumDecl( |
| 1303 | 1629 | const field_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, field_i); |
| 1304 | 1630 | const other_tag_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, gop.index); |
| 1305 | 1631 | const msg = msg: { |
| 1306 | | const msg = try mod.errMsg(&block.base, field_src, "duplicate enum tag", .{}); |
| 1632 | const msg = try sema.errMsg(block, field_src, "duplicate enum tag", .{}); |
| 1307 | 1633 | errdefer msg.destroy(gpa); |
| 1308 | | try mod.errNote(&block.base, other_tag_src, msg, "other tag here", .{}); |
| 1634 | try sema.errNote(block, other_tag_src, msg, "other tag here", .{}); |
| 1309 | 1635 | break :msg msg; |
| 1310 | 1636 | }; |
| 1311 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1637 | return sema.failWithOwnedErrorMsg(msg); |
| 1312 | 1638 | } |
| 1313 | 1639 | |
| 1314 | 1640 | if (has_tag_value) { |
| ... | ... | @@ -1331,7 +1657,7 @@ fn zirEnumDecl( |
| 1331 | 1657 | |
| 1332 | 1658 | fn zirUnionDecl( |
| 1333 | 1659 | sema: *Sema, |
| 1334 | | block: *Scope.Block, |
| 1660 | block: *Block, |
| 1335 | 1661 | extended: Zir.Inst.Extended.InstData, |
| 1336 | 1662 | inst: Zir.Inst.Index, |
| 1337 | 1663 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -1370,12 +1696,12 @@ fn zirUnionDecl( |
| 1370 | 1696 | const union_ty = Type.initPayload(&union_payload.base); |
| 1371 | 1697 | const union_val = try Value.Tag.ty.create(&new_decl_arena.allocator, union_ty); |
| 1372 | 1698 | const type_name = try sema.createTypeName(block, small.name_strategy); |
| 1373 | | const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{ |
| 1699 | const new_decl = try sema.mod.createAnonymousDeclNamed(block, .{ |
| 1374 | 1700 | .ty = Type.initTag(.type), |
| 1375 | 1701 | .val = union_val, |
| 1376 | 1702 | }, type_name); |
| 1377 | 1703 | new_decl.owns_tv = true; |
| 1378 | | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 1704 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 1379 | 1705 | union_obj.* = .{ |
| 1380 | 1706 | .owner_decl = new_decl, |
| 1381 | 1707 | .tag_ty = Type.initTag(.@"null"), |
| ... | ... | @@ -1385,7 +1711,7 @@ fn zirUnionDecl( |
| 1385 | 1711 | .layout = small.layout, |
| 1386 | 1712 | .status = .none, |
| 1387 | 1713 | .namespace = .{ |
| 1388 | | .parent = sema.owner_decl.namespace, |
| 1714 | .parent = block.namespace, |
| 1389 | 1715 | .ty = union_ty, |
| 1390 | 1716 | .file_scope = block.getFileScope(), |
| 1391 | 1717 | }, |
| ... | ... | @@ -1396,15 +1722,13 @@ fn zirUnionDecl( |
| 1396 | 1722 | |
| 1397 | 1723 | _ = try sema.mod.scanNamespace(&union_obj.namespace, extra_index, decls_len, new_decl); |
| 1398 | 1724 | |
| 1399 | | try sema.types_pending_resolution.ensureUnusedCapacity(sema.gpa, 1); |
| 1400 | 1725 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 1401 | | sema.types_pending_resolution.appendAssumeCapacity(union_ty); |
| 1402 | 1726 | return sema.analyzeDeclVal(block, src, new_decl); |
| 1403 | 1727 | } |
| 1404 | 1728 | |
| 1405 | 1729 | fn zirOpaqueDecl( |
| 1406 | 1730 | sema: *Sema, |
| 1407 | | block: *Scope.Block, |
| 1731 | block: *Block, |
| 1408 | 1732 | extended: Zir.Inst.Extended.InstData, |
| 1409 | 1733 | inst: Zir.Inst.Index, |
| 1410 | 1734 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -1413,12 +1737,12 @@ fn zirOpaqueDecl( |
| 1413 | 1737 | |
| 1414 | 1738 | _ = extended; |
| 1415 | 1739 | _ = inst; |
| 1416 | | return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{}); |
| 1740 | return sema.fail(block, sema.src, "TODO implement zirOpaqueDecl", .{}); |
| 1417 | 1741 | } |
| 1418 | 1742 | |
| 1419 | 1743 | fn zirErrorSetDecl( |
| 1420 | 1744 | sema: *Sema, |
| 1421 | | block: *Scope.Block, |
| 1745 | block: *Block, |
| 1422 | 1746 | inst: Zir.Inst.Index, |
| 1423 | 1747 | name_strategy: Zir.Inst.NameStrategy, |
| 1424 | 1748 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -1438,12 +1762,12 @@ fn zirErrorSetDecl( |
| 1438 | 1762 | const error_set_ty = try Type.Tag.error_set.create(&new_decl_arena.allocator, error_set); |
| 1439 | 1763 | const error_set_val = try Value.Tag.ty.create(&new_decl_arena.allocator, error_set_ty); |
| 1440 | 1764 | const type_name = try sema.createTypeName(block, name_strategy); |
| 1441 | | const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{ |
| 1765 | const new_decl = try sema.mod.createAnonymousDeclNamed(block, .{ |
| 1442 | 1766 | .ty = Type.initTag(.type), |
| 1443 | 1767 | .val = error_set_val, |
| 1444 | 1768 | }, type_name); |
| 1445 | 1769 | new_decl.owns_tv = true; |
| 1446 | | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 1770 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 1447 | 1771 | const names = try new_decl_arena.allocator.alloc([]const u8, fields.len); |
| 1448 | 1772 | for (fields) |str_index, i| { |
| 1449 | 1773 | names[i] = try new_decl_arena.allocator.dupe(u8, sema.code.nullTerminatedString(str_index)); |
| ... | ... | @@ -1460,7 +1784,7 @@ fn zirErrorSetDecl( |
| 1460 | 1784 | |
| 1461 | 1785 | fn zirRetPtr( |
| 1462 | 1786 | sema: *Sema, |
| 1463 | | block: *Scope.Block, |
| 1787 | block: *Block, |
| 1464 | 1788 | extended: Zir.Inst.Extended.InstData, |
| 1465 | 1789 | ) CompileError!Air.Inst.Ref { |
| 1466 | 1790 | const tracy = trace(@src()); |
| ... | ... | @@ -1480,7 +1804,7 @@ fn zirRetPtr( |
| 1480 | 1804 | return block.addTy(.alloc, ptr_type); |
| 1481 | 1805 | } |
| 1482 | 1806 | |
| 1483 | | fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1807 | fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1484 | 1808 | const tracy = trace(@src()); |
| 1485 | 1809 | defer tracy.end(); |
| 1486 | 1810 | |
| ... | ... | @@ -1491,7 +1815,7 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 1491 | 1815 | |
| 1492 | 1816 | fn zirRetType( |
| 1493 | 1817 | sema: *Sema, |
| 1494 | | block: *Scope.Block, |
| 1818 | block: *Block, |
| 1495 | 1819 | extended: Zir.Inst.Extended.InstData, |
| 1496 | 1820 | ) CompileError!Air.Inst.Ref { |
| 1497 | 1821 | const tracy = trace(@src()); |
| ... | ... | @@ -1502,7 +1826,7 @@ fn zirRetType( |
| 1502 | 1826 | return sema.addType(sema.fn_ret_ty); |
| 1503 | 1827 | } |
| 1504 | 1828 | |
| 1505 | | fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 1829 | fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 1506 | 1830 | const tracy = trace(@src()); |
| 1507 | 1831 | defer tracy.end(); |
| 1508 | 1832 | |
| ... | ... | @@ -1515,18 +1839,18 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) C |
| 1515 | 1839 | |
| 1516 | 1840 | fn ensureResultUsed( |
| 1517 | 1841 | sema: *Sema, |
| 1518 | | block: *Scope.Block, |
| 1842 | block: *Block, |
| 1519 | 1843 | operand: Air.Inst.Ref, |
| 1520 | 1844 | src: LazySrcLoc, |
| 1521 | 1845 | ) CompileError!void { |
| 1522 | 1846 | const operand_ty = sema.typeOf(operand); |
| 1523 | 1847 | switch (operand_ty.zigTypeTag()) { |
| 1524 | 1848 | .Void, .NoReturn => return, |
| 1525 | | else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}), |
| 1849 | else => return sema.fail(block, src, "expression value is ignored", .{}), |
| 1526 | 1850 | } |
| 1527 | 1851 | } |
| 1528 | 1852 | |
| 1529 | | fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 1853 | fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 1530 | 1854 | const tracy = trace(@src()); |
| 1531 | 1855 | defer tracy.end(); |
| 1532 | 1856 | |
| ... | ... | @@ -1535,12 +1859,12 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1535 | 1859 | const src = inst_data.src(); |
| 1536 | 1860 | const operand_ty = sema.typeOf(operand); |
| 1537 | 1861 | switch (operand_ty.zigTypeTag()) { |
| 1538 | | .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}), |
| 1862 | .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discarded", .{}), |
| 1539 | 1863 | else => return, |
| 1540 | 1864 | } |
| 1541 | 1865 | } |
| 1542 | 1866 | |
| 1543 | | fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1867 | fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1544 | 1868 | const tracy = trace(@src()); |
| 1545 | 1869 | defer tracy.end(); |
| 1546 | 1870 | |
| ... | ... | @@ -1561,15 +1885,15 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1561 | 1885 | } |
| 1562 | 1886 | if (!elem_ty.isIndexable()) { |
| 1563 | 1887 | const msg = msg: { |
| 1564 | | const msg = try sema.mod.errMsg( |
| 1565 | | &block.base, |
| 1888 | const msg = try sema.errMsg( |
| 1889 | block, |
| 1566 | 1890 | src, |
| 1567 | 1891 | "type '{}' does not support indexing", |
| 1568 | 1892 | .{elem_ty}, |
| 1569 | 1893 | ); |
| 1570 | 1894 | errdefer msg.destroy(sema.gpa); |
| 1571 | | try sema.mod.errNote( |
| 1572 | | &block.base, |
| 1895 | try sema.errNote( |
| 1896 | block, |
| 1573 | 1897 | src, |
| 1574 | 1898 | msg, |
| 1575 | 1899 | "for loop operand must be an array, slice, tuple, or vector", |
| ... | ... | @@ -1577,18 +1901,18 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1577 | 1901 | ); |
| 1578 | 1902 | break :msg msg; |
| 1579 | 1903 | }; |
| 1580 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1904 | return sema.failWithOwnedErrorMsg(msg); |
| 1581 | 1905 | } |
| 1582 | 1906 | const result_ptr = try sema.fieldPtr(block, src, array, "len", src); |
| 1583 | 1907 | return sema.analyzeLoad(block, src, result_ptr, src); |
| 1584 | 1908 | } |
| 1585 | 1909 | |
| 1586 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirIndexablePtrLen", .{}); |
| 1910 | return sema.fail(block, src, "TODO implement Sema.zirIndexablePtrLen", .{}); |
| 1587 | 1911 | } |
| 1588 | 1912 | |
| 1589 | 1913 | fn zirAllocExtended( |
| 1590 | 1914 | sema: *Sema, |
| 1591 | | block: *Scope.Block, |
| 1915 | block: *Block, |
| 1592 | 1916 | extended: Zir.Inst.Extended.InstData, |
| 1593 | 1917 | ) CompileError!Air.Inst.Ref { |
| 1594 | 1918 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| ... | ... | @@ -1604,7 +1928,7 @@ fn zirAllocExtended( |
| 1604 | 1928 | extra_index += 1; |
| 1605 | 1929 | break :blk try sema.resolveType(block, ty_src, type_ref); |
| 1606 | 1930 | } else { |
| 1607 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended inferred", .{}); |
| 1931 | return sema.fail(block, src, "TODO implement Sema.zirAllocExtended inferred", .{}); |
| 1608 | 1932 | }; |
| 1609 | 1933 | |
| 1610 | 1934 | const alignment: u16 = if (small.has_align) blk: { |
| ... | ... | @@ -1615,11 +1939,11 @@ fn zirAllocExtended( |
| 1615 | 1939 | } else 0; |
| 1616 | 1940 | |
| 1617 | 1941 | if (small.is_comptime) { |
| 1618 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended comptime", .{}); |
| 1942 | return sema.fail(block, src, "TODO implement Sema.zirAllocExtended comptime", .{}); |
| 1619 | 1943 | } |
| 1620 | 1944 | |
| 1621 | 1945 | if (!small.is_const) { |
| 1622 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended var", .{}); |
| 1946 | return sema.fail(block, src, "TODO implement Sema.zirAllocExtended var", .{}); |
| 1623 | 1947 | } |
| 1624 | 1948 | |
| 1625 | 1949 | const ptr_type = try Type.ptr(sema.arena, .{ |
| ... | ... | @@ -1631,7 +1955,7 @@ fn zirAllocExtended( |
| 1631 | 1955 | return block.addTy(.alloc, ptr_type); |
| 1632 | 1956 | } |
| 1633 | 1957 | |
| 1634 | | fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1958 | fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1635 | 1959 | const tracy = trace(@src()); |
| 1636 | 1960 | defer tracy.end(); |
| 1637 | 1961 | |
| ... | ... | @@ -1651,7 +1975,7 @@ fn zirAllocInferredComptime(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air. |
| 1651 | 1975 | ); |
| 1652 | 1976 | } |
| 1653 | 1977 | |
| 1654 | | fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1978 | fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1655 | 1979 | const tracy = trace(@src()); |
| 1656 | 1980 | defer tracy.end(); |
| 1657 | 1981 | |
| ... | ... | @@ -1667,7 +1991,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 1667 | 1991 | return block.addTy(.alloc, ptr_type); |
| 1668 | 1992 | } |
| 1669 | 1993 | |
| 1670 | | fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1994 | fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 1671 | 1995 | const tracy = trace(@src()); |
| 1672 | 1996 | defer tracy.end(); |
| 1673 | 1997 | |
| ... | ... | @@ -1689,7 +2013,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 1689 | 2013 | |
| 1690 | 2014 | fn zirAllocInferred( |
| 1691 | 2015 | sema: *Sema, |
| 1692 | | block: *Scope.Block, |
| 2016 | block: *Block, |
| 1693 | 2017 | inst: Zir.Inst.Index, |
| 1694 | 2018 | inferred_alloc_ty: Type, |
| 1695 | 2019 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -1720,7 +2044,7 @@ fn zirAllocInferred( |
| 1720 | 2044 | return result; |
| 1721 | 2045 | } |
| 1722 | 2046 | |
| 1723 | | fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2047 | fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 1724 | 2048 | const tracy = trace(@src()); |
| 1725 | 2049 | defer tracy.end(); |
| 1726 | 2050 | |
| ... | ... | @@ -1779,7 +2103,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1779 | 2103 | } |
| 1780 | 2104 | } |
| 1781 | 2105 | |
| 1782 | | fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2106 | fn zirValidateStructInitPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 1783 | 2107 | const tracy = trace(@src()); |
| 1784 | 2108 | defer tracy.end(); |
| 1785 | 2109 | |
| ... | ... | @@ -1811,18 +2135,16 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind |
| 1811 | 2135 | |
| 1812 | 2136 | fn validateUnionInitPtr( |
| 1813 | 2137 | sema: *Sema, |
| 1814 | | block: *Scope.Block, |
| 2138 | block: *Block, |
| 1815 | 2139 | union_obj: *Module.Union, |
| 1816 | 2140 | init_src: LazySrcLoc, |
| 1817 | 2141 | instrs: []const Zir.Inst.Index, |
| 1818 | 2142 | union_ptr: Air.Inst.Ref, |
| 1819 | 2143 | ) CompileError!void { |
| 1820 | | const mod = sema.mod; |
| 1821 | | |
| 1822 | 2144 | if (instrs.len != 1) { |
| 1823 | 2145 | // TODO add note for other field |
| 1824 | 2146 | // TODO add note for union declared here |
| 1825 | | return mod.fail(&block.base, init_src, "only one union field can be active at once", .{}); |
| 2147 | return sema.fail(block, init_src, "only one union field can be active at once", .{}); |
| 1826 | 2148 | } |
| 1827 | 2149 | |
| 1828 | 2150 | const field_ptr = instrs[0]; |
| ... | ... | @@ -1852,13 +2174,12 @@ fn validateUnionInitPtr( |
| 1852 | 2174 | |
| 1853 | 2175 | fn validateStructInitPtr( |
| 1854 | 2176 | sema: *Sema, |
| 1855 | | block: *Scope.Block, |
| 2177 | block: *Block, |
| 1856 | 2178 | struct_obj: *Module.Struct, |
| 1857 | 2179 | init_src: LazySrcLoc, |
| 1858 | 2180 | instrs: []const Zir.Inst.Index, |
| 1859 | 2181 | ) CompileError!void { |
| 1860 | 2182 | const gpa = sema.gpa; |
| 1861 | | const mod = sema.mod; |
| 1862 | 2183 | |
| 1863 | 2184 | // Maps field index to field_ptr index of where it was already initialized. |
| 1864 | 2185 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count()); |
| ... | ... | @@ -1877,12 +2198,12 @@ fn validateStructInitPtr( |
| 1877 | 2198 | const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node; |
| 1878 | 2199 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node }; |
| 1879 | 2200 | const msg = msg: { |
| 1880 | | const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{}); |
| 2201 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| 1881 | 2202 | errdefer msg.destroy(gpa); |
| 1882 | | try mod.errNote(&block.base, other_field_src, msg, "other field here", .{}); |
| 2203 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 1883 | 2204 | break :msg msg; |
| 1884 | 2205 | }; |
| 1885 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2206 | return sema.failWithOwnedErrorMsg(msg); |
| 1886 | 2207 | } |
| 1887 | 2208 | found_fields[field_index] = field_ptr; |
| 1888 | 2209 | } |
| ... | ... | @@ -1897,85 +2218,83 @@ fn validateStructInitPtr( |
| 1897 | 2218 | const template = "missing struct field: {s}"; |
| 1898 | 2219 | const args = .{field_name}; |
| 1899 | 2220 | if (root_msg) |msg| { |
| 1900 | | try mod.errNote(&block.base, init_src, msg, template, args); |
| 2221 | try sema.errNote(block, init_src, msg, template, args); |
| 1901 | 2222 | } else { |
| 1902 | | root_msg = try mod.errMsg(&block.base, init_src, template, args); |
| 2223 | root_msg = try sema.errMsg(block, init_src, template, args); |
| 1903 | 2224 | } |
| 1904 | 2225 | } |
| 1905 | 2226 | if (root_msg) |msg| { |
| 1906 | 2227 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1907 | 2228 | defer gpa.free(fqn); |
| 1908 | | try mod.errNoteNonLazy( |
| 2229 | try sema.mod.errNoteNonLazy( |
| 1909 | 2230 | struct_obj.srcLoc(), |
| 1910 | 2231 | msg, |
| 1911 | 2232 | "struct '{s}' declared here", |
| 1912 | 2233 | .{fqn}, |
| 1913 | 2234 | ); |
| 1914 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2235 | return sema.failWithOwnedErrorMsg(msg); |
| 1915 | 2236 | } |
| 1916 | 2237 | } |
| 1917 | 2238 | |
| 1918 | | fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2239 | fn zirValidateArrayInitPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 1919 | 2240 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1920 | 2241 | const src = inst_data.src(); |
| 1921 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirValidateArrayInitPtr", .{}); |
| 2242 | return sema.fail(block, src, "TODO implement Sema.zirValidateArrayInitPtr", .{}); |
| 1922 | 2243 | } |
| 1923 | 2244 | |
| 1924 | 2245 | fn failWithBadFieldAccess( |
| 1925 | 2246 | sema: *Sema, |
| 1926 | | block: *Scope.Block, |
| 2247 | block: *Block, |
| 1927 | 2248 | struct_obj: *Module.Struct, |
| 1928 | 2249 | field_src: LazySrcLoc, |
| 1929 | 2250 | field_name: []const u8, |
| 1930 | 2251 | ) CompileError { |
| 1931 | | const mod = sema.mod; |
| 1932 | 2252 | const gpa = sema.gpa; |
| 1933 | 2253 | |
| 1934 | 2254 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1935 | 2255 | defer gpa.free(fqn); |
| 1936 | 2256 | |
| 1937 | 2257 | const msg = msg: { |
| 1938 | | const msg = try mod.errMsg( |
| 1939 | | &block.base, |
| 2258 | const msg = try sema.errMsg( |
| 2259 | block, |
| 1940 | 2260 | field_src, |
| 1941 | 2261 | "no field named '{s}' in struct '{s}'", |
| 1942 | 2262 | .{ field_name, fqn }, |
| 1943 | 2263 | ); |
| 1944 | 2264 | errdefer msg.destroy(gpa); |
| 1945 | | try mod.errNoteNonLazy(struct_obj.srcLoc(), msg, "struct declared here", .{}); |
| 2265 | try sema.mod.errNoteNonLazy(struct_obj.srcLoc(), msg, "struct declared here", .{}); |
| 1946 | 2266 | break :msg msg; |
| 1947 | 2267 | }; |
| 1948 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2268 | return sema.failWithOwnedErrorMsg(msg); |
| 1949 | 2269 | } |
| 1950 | 2270 | |
| 1951 | 2271 | fn failWithBadUnionFieldAccess( |
| 1952 | 2272 | sema: *Sema, |
| 1953 | | block: *Scope.Block, |
| 2273 | block: *Block, |
| 1954 | 2274 | union_obj: *Module.Union, |
| 1955 | 2275 | field_src: LazySrcLoc, |
| 1956 | 2276 | field_name: []const u8, |
| 1957 | 2277 | ) CompileError { |
| 1958 | | const mod = sema.mod; |
| 1959 | 2278 | const gpa = sema.gpa; |
| 1960 | 2279 | |
| 1961 | 2280 | const fqn = try union_obj.getFullyQualifiedName(gpa); |
| 1962 | 2281 | defer gpa.free(fqn); |
| 1963 | 2282 | |
| 1964 | 2283 | const msg = msg: { |
| 1965 | | const msg = try mod.errMsg( |
| 1966 | | &block.base, |
| 2284 | const msg = try sema.errMsg( |
| 2285 | block, |
| 1967 | 2286 | field_src, |
| 1968 | 2287 | "no field named '{s}' in union '{s}'", |
| 1969 | 2288 | .{ field_name, fqn }, |
| 1970 | 2289 | ); |
| 1971 | 2290 | errdefer msg.destroy(gpa); |
| 1972 | | try mod.errNoteNonLazy(union_obj.srcLoc(), msg, "union declared here", .{}); |
| 2291 | try sema.mod.errNoteNonLazy(union_obj.srcLoc(), msg, "union declared here", .{}); |
| 1973 | 2292 | break :msg msg; |
| 1974 | 2293 | }; |
| 1975 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2294 | return sema.failWithOwnedErrorMsg(msg); |
| 1976 | 2295 | } |
| 1977 | 2296 | |
| 1978 | | fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2297 | fn zirStoreToBlockPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 1979 | 2298 | const tracy = trace(@src()); |
| 1980 | 2299 | defer tracy.end(); |
| 1981 | 2300 | |
| ... | ... | @@ -2000,7 +2319,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 2000 | 2319 | return sema.storePtr(block, src, bitcasted_ptr, value); |
| 2001 | 2320 | } |
| 2002 | 2321 | |
| 2003 | | fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2322 | fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2004 | 2323 | const tracy = trace(@src()); |
| 2005 | 2324 | defer tracy.end(); |
| 2006 | 2325 | |
| ... | ... | @@ -2048,7 +2367,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 2048 | 2367 | unreachable; |
| 2049 | 2368 | } |
| 2050 | 2369 | |
| 2051 | | fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2370 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2052 | 2371 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2053 | 2372 | const src = inst_data.src(); |
| 2054 | 2373 | const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32); |
| ... | ... | @@ -2056,7 +2375,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 2056 | 2375 | sema.branch_quota = quota; |
| 2057 | 2376 | } |
| 2058 | 2377 | |
| 2059 | | fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2378 | fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2060 | 2379 | const tracy = trace(@src()); |
| 2061 | 2380 | defer tracy.end(); |
| 2062 | 2381 | |
| ... | ... | @@ -2066,7 +2385,7 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2066 | 2385 | return sema.storePtr(block, sema.src, ptr, value); |
| 2067 | 2386 | } |
| 2068 | 2387 | |
| 2069 | | fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2388 | fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2070 | 2389 | const tracy = trace(@src()); |
| 2071 | 2390 | defer tracy.end(); |
| 2072 | 2391 | |
| ... | ... | @@ -2078,7 +2397,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 2078 | 2397 | return sema.storePtr(block, src, ptr, value); |
| 2079 | 2398 | } |
| 2080 | 2399 | |
| 2081 | | fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2400 | fn zirStr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2082 | 2401 | const tracy = trace(@src()); |
| 2083 | 2402 | defer tracy.end(); |
| 2084 | 2403 | |
| ... | ... | @@ -2097,16 +2416,16 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 2097 | 2416 | const decl_ty = try Type.Tag.array_u8_sentinel_0.create(&new_decl_arena.allocator, bytes.len); |
| 2098 | 2417 | const decl_val = try Value.Tag.bytes.create(&new_decl_arena.allocator, bytes); |
| 2099 | 2418 | |
| 2100 | | const new_decl = try sema.mod.createAnonymousDecl(&block.base, .{ |
| 2419 | const new_decl = try sema.mod.createAnonymousDecl(block, .{ |
| 2101 | 2420 | .ty = decl_ty, |
| 2102 | 2421 | .val = decl_val, |
| 2103 | 2422 | }); |
| 2104 | | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 2423 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 2105 | 2424 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 2106 | 2425 | return sema.analyzeDeclRef(new_decl); |
| 2107 | 2426 | } |
| 2108 | 2427 | |
| 2109 | | fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2428 | fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2110 | 2429 | _ = block; |
| 2111 | 2430 | const tracy = trace(@src()); |
| 2112 | 2431 | defer tracy.end(); |
| ... | ... | @@ -2115,7 +2434,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 2115 | 2434 | return sema.addIntUnsigned(Type.initTag(.comptime_int), int); |
| 2116 | 2435 | } |
| 2117 | 2436 | |
| 2118 | | fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2437 | fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2119 | 2438 | _ = block; |
| 2120 | 2439 | const tracy = trace(@src()); |
| 2121 | 2440 | defer tracy.end(); |
| ... | ... | @@ -2133,7 +2452,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 2133 | 2452 | ); |
| 2134 | 2453 | } |
| 2135 | 2454 | |
| 2136 | | fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2455 | fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2137 | 2456 | _ = block; |
| 2138 | 2457 | const arena = sema.arena; |
| 2139 | 2458 | const number = sema.code.instructions.items(.data)[inst].float; |
| ... | ... | @@ -2143,7 +2462,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2143 | 2462 | ); |
| 2144 | 2463 | } |
| 2145 | 2464 | |
| 2146 | | fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2465 | fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2147 | 2466 | _ = block; |
| 2148 | 2467 | const arena = sema.arena; |
| 2149 | 2468 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| ... | ... | @@ -2155,7 +2474,7 @@ fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 2155 | 2474 | ); |
| 2156 | 2475 | } |
| 2157 | 2476 | |
| 2158 | | fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 2477 | fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 2159 | 2478 | const tracy = trace(@src()); |
| 2160 | 2479 | defer tracy.end(); |
| 2161 | 2480 | |
| ... | ... | @@ -2163,12 +2482,12 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 2163 | 2482 | const src = inst_data.src(); |
| 2164 | 2483 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2165 | 2484 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand); |
| 2166 | | return sema.mod.fail(&block.base, src, "{s}", .{msg}); |
| 2485 | return sema.fail(block, src, "{s}", .{msg}); |
| 2167 | 2486 | } |
| 2168 | 2487 | |
| 2169 | 2488 | fn zirCompileLog( |
| 2170 | 2489 | sema: *Sema, |
| 2171 | | block: *Scope.Block, |
| 2490 | block: *Block, |
| 2172 | 2491 | extended: Zir.Inst.Extended.InstData, |
| 2173 | 2492 | ) CompileError!Air.Inst.Ref { |
| 2174 | 2493 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); |
| ... | ... | @@ -2200,7 +2519,7 @@ fn zirCompileLog( |
| 2200 | 2519 | return Air.Inst.Ref.void_value; |
| 2201 | 2520 | } |
| 2202 | 2521 | |
| 2203 | | fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 2522 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 2204 | 2523 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2205 | 2524 | const src: LazySrcLoc = inst_data.src(); |
| 2206 | 2525 | const msg_inst = sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -2208,7 +2527,7 @@ fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2208 | 2527 | return sema.panicWithMsg(block, src, msg_inst); |
| 2209 | 2528 | } |
| 2210 | 2529 | |
| 2211 | | fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2530 | fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2212 | 2531 | const tracy = trace(@src()); |
| 2213 | 2532 | defer tracy.end(); |
| 2214 | 2533 | |
| ... | ... | @@ -2236,7 +2555,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2236 | 2555 | .payload = undefined, |
| 2237 | 2556 | } }, |
| 2238 | 2557 | }); |
| 2239 | | var label: Scope.Block.Label = .{ |
| 2558 | var label: Block.Label = .{ |
| 2240 | 2559 | .zir_block = inst, |
| 2241 | 2560 | .merges = .{ |
| 2242 | 2561 | .results = .{}, |
| ... | ... | @@ -2271,7 +2590,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2271 | 2590 | return sema.analyzeBlockBody(parent_block, src, &child_block, merges); |
| 2272 | 2591 | } |
| 2273 | 2592 | |
| 2274 | | fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2593 | fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2275 | 2594 | const tracy = trace(@src()); |
| 2276 | 2595 | defer tracy.end(); |
| 2277 | 2596 | |
| ... | ... | @@ -2282,15 +2601,16 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2282 | 2601 | |
| 2283 | 2602 | // we check this here to avoid undefined symbols |
| 2284 | 2603 | if (!@import("build_options").have_llvm) |
| 2285 | | return sema.mod.fail(&parent_block.base, src, "cannot do C import on Zig compiler not built with LLVM-extension", .{}); |
| 2604 | return sema.fail(parent_block, src, "cannot do C import on Zig compiler not built with LLVM-extension", .{}); |
| 2286 | 2605 | |
| 2287 | 2606 | var c_import_buf = std.ArrayList(u8).init(sema.gpa); |
| 2288 | 2607 | defer c_import_buf.deinit(); |
| 2289 | 2608 | |
| 2290 | | var child_block: Scope.Block = .{ |
| 2609 | var child_block: Block = .{ |
| 2291 | 2610 | .parent = parent_block, |
| 2292 | 2611 | .sema = sema, |
| 2293 | 2612 | .src_decl = parent_block.src_decl, |
| 2613 | .namespace = parent_block.namespace, |
| 2294 | 2614 | .wip_capture_scope = parent_block.wip_capture_scope, |
| 2295 | 2615 | .instructions = .{}, |
| 2296 | 2616 | .inlining = parent_block.inlining, |
| ... | ... | @@ -2302,15 +2622,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2302 | 2622 | _ = try sema.analyzeBody(&child_block, body); |
| 2303 | 2623 | |
| 2304 | 2624 | const c_import_res = sema.mod.comp.cImport(c_import_buf.items) catch |err| |
| 2305 | | return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)}); |
| 2625 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 2306 | 2626 | |
| 2307 | 2627 | if (c_import_res.errors.len != 0) { |
| 2308 | 2628 | const msg = msg: { |
| 2309 | | const msg = try sema.mod.errMsg(&child_block.base, src, "C import failed", .{}); |
| 2629 | const msg = try sema.errMsg(&child_block, src, "C import failed", .{}); |
| 2310 | 2630 | errdefer msg.destroy(sema.gpa); |
| 2311 | 2631 | |
| 2312 | 2632 | if (!sema.mod.comp.bin_file.options.link_libc) |
| 2313 | | try sema.mod.errNote(&child_block.base, src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 2633 | try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 2314 | 2634 | |
| 2315 | 2635 | for (c_import_res.errors) |_| { |
| 2316 | 2636 | // TODO integrate with LazySrcLoc |
| ... | ... | @@ -2322,7 +2642,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2322 | 2642 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); |
| 2323 | 2643 | break :msg msg; |
| 2324 | 2644 | }; |
| 2325 | | return sema.mod.failWithOwnedErrorMsg(&child_block.base, msg); |
| 2645 | return sema.failWithOwnedErrorMsg(msg); |
| 2326 | 2646 | } |
| 2327 | 2647 | const c_import_pkg = Package.create( |
| 2328 | 2648 | sema.gpa, |
| ... | ... | @@ -2338,10 +2658,10 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2338 | 2658 | try c_import_pkg.add(sema.gpa, "std", std_pkg); |
| 2339 | 2659 | |
| 2340 | 2660 | const result = sema.mod.importPkg(c_import_pkg) catch |err| |
| 2341 | | return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)}); |
| 2661 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 2342 | 2662 | |
| 2343 | 2663 | sema.mod.astGenFile(result.file) catch |err| |
| 2344 | | return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)}); |
| 2664 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 2345 | 2665 | |
| 2346 | 2666 | try sema.mod.semaFile(result.file); |
| 2347 | 2667 | const file_root_decl = result.file.root_decl.?; |
| ... | ... | @@ -2349,15 +2669,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2349 | 2669 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); |
| 2350 | 2670 | } |
| 2351 | 2671 | |
| 2352 | | fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2672 | fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2353 | 2673 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 2354 | 2674 | const src = inst_data.src(); |
| 2355 | | return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{}); |
| 2675 | return sema.fail(parent_block, src, "TODO: implement Sema.zirSuspendBlock", .{}); |
| 2356 | 2676 | } |
| 2357 | 2677 | |
| 2358 | 2678 | fn zirBlock( |
| 2359 | 2679 | sema: *Sema, |
| 2360 | | parent_block: *Scope.Block, |
| 2680 | parent_block: *Block, |
| 2361 | 2681 | inst: Zir.Inst.Index, |
| 2362 | 2682 | ) CompileError!Air.Inst.Ref { |
| 2363 | 2683 | const tracy = trace(@src()); |
| ... | ... | @@ -2378,7 +2698,7 @@ fn zirBlock( |
| 2378 | 2698 | .data = undefined, |
| 2379 | 2699 | }); |
| 2380 | 2700 | |
| 2381 | | var label: Scope.Block.Label = .{ |
| 2701 | var label: Block.Label = .{ |
| 2382 | 2702 | .zir_block = inst, |
| 2383 | 2703 | .merges = .{ |
| 2384 | 2704 | .results = .{}, |
| ... | ... | @@ -2387,10 +2707,11 @@ fn zirBlock( |
| 2387 | 2707 | }, |
| 2388 | 2708 | }; |
| 2389 | 2709 | |
| 2390 | | var child_block: Scope.Block = .{ |
| 2710 | var child_block: Block = .{ |
| 2391 | 2711 | .parent = parent_block, |
| 2392 | 2712 | .sema = sema, |
| 2393 | 2713 | .src_decl = parent_block.src_decl, |
| 2714 | .namespace = parent_block.namespace, |
| 2394 | 2715 | .wip_capture_scope = parent_block.wip_capture_scope, |
| 2395 | 2716 | .instructions = .{}, |
| 2396 | 2717 | .label = &label, |
| ... | ... | @@ -2410,11 +2731,11 @@ fn zirBlock( |
| 2410 | 2731 | |
| 2411 | 2732 | fn resolveBlockBody( |
| 2412 | 2733 | sema: *Sema, |
| 2413 | | parent_block: *Scope.Block, |
| 2734 | parent_block: *Block, |
| 2414 | 2735 | src: LazySrcLoc, |
| 2415 | | child_block: *Scope.Block, |
| 2736 | child_block: *Block, |
| 2416 | 2737 | body: []const Zir.Inst.Index, |
| 2417 | | merges: *Scope.Block.Merges, |
| 2738 | merges: *Block.Merges, |
| 2418 | 2739 | ) CompileError!Air.Inst.Ref { |
| 2419 | 2740 | if (child_block.is_comptime) { |
| 2420 | 2741 | return sema.resolveBody(child_block, body); |
| ... | ... | @@ -2426,10 +2747,10 @@ fn resolveBlockBody( |
| 2426 | 2747 | |
| 2427 | 2748 | fn analyzeBlockBody( |
| 2428 | 2749 | sema: *Sema, |
| 2429 | | parent_block: *Scope.Block, |
| 2750 | parent_block: *Block, |
| 2430 | 2751 | src: LazySrcLoc, |
| 2431 | | child_block: *Scope.Block, |
| 2432 | | merges: *Scope.Block.Merges, |
| 2752 | child_block: *Block, |
| 2753 | merges: *Block.Merges, |
| 2433 | 2754 | ) CompileError!Air.Inst.Ref { |
| 2434 | 2755 | const tracy = trace(@src()); |
| 2435 | 2756 | defer tracy.end(); |
| ... | ... | @@ -2527,7 +2848,7 @@ fn analyzeBlockBody( |
| 2527 | 2848 | return Air.indexToRef(merges.block_inst); |
| 2528 | 2849 | } |
| 2529 | 2850 | |
| 2530 | | fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2851 | fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2531 | 2852 | const tracy = trace(@src()); |
| 2532 | 2853 | defer tracy.end(); |
| 2533 | 2854 | |
| ... | ... | @@ -2538,14 +2859,14 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 2538 | 2859 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 2539 | 2860 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); |
| 2540 | 2861 | if (extra.namespace != .none) { |
| 2541 | | return sema.mod.fail(&block.base, src, "TODO: implement exporting with field access", .{}); |
| 2862 | return sema.fail(block, src, "TODO: implement exporting with field access", .{}); |
| 2542 | 2863 | } |
| 2543 | 2864 | const decl = try sema.lookupIdentifier(block, operand_src, decl_name); |
| 2544 | 2865 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 2545 | | try sema.mod.analyzeExport(block, src, options, decl); |
| 2866 | try sema.analyzeExport(block, src, options, decl); |
| 2546 | 2867 | } |
| 2547 | 2868 | |
| 2548 | | fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2869 | fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2549 | 2870 | const tracy = trace(@src()); |
| 2550 | 2871 | defer tracy.end(); |
| 2551 | 2872 | |
| ... | ... | @@ -2558,45 +2879,122 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2558 | 2879 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 2559 | 2880 | const decl = switch (operand.val.tag()) { |
| 2560 | 2881 | .function => operand.val.castTag(.function).?.data.owner_decl, |
| 2561 | | else => return sema.mod.fail(&block.base, operand_src, "TODO implement exporting arbitrary Value objects", .{}), // TODO put this Value into an anonymous Decl and then export it. |
| 2882 | else => return sema.fail(block, operand_src, "TODO implement exporting arbitrary Value objects", .{}), // TODO put this Value into an anonymous Decl and then export it. |
| 2562 | 2883 | }; |
| 2563 | | try sema.mod.analyzeExport(block, src, options, decl); |
| 2884 | try sema.analyzeExport(block, src, options, decl); |
| 2564 | 2885 | } |
| 2565 | 2886 | |
| 2566 | | fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2887 | pub fn analyzeExport( |
| 2888 | sema: *Sema, |
| 2889 | block: *Block, |
| 2890 | src: LazySrcLoc, |
| 2891 | borrowed_options: std.builtin.ExportOptions, |
| 2892 | exported_decl: *Decl, |
| 2893 | ) !void { |
| 2894 | const Export = Module.Export; |
| 2567 | 2895 | const mod = sema.mod; |
| 2896 | |
| 2897 | try mod.ensureDeclAnalyzed(exported_decl); |
| 2898 | switch (exported_decl.ty.zigTypeTag()) { |
| 2899 | .Fn => {}, |
| 2900 | else => return sema.fail(block, src, "unable to export type '{}'", .{exported_decl.ty}), |
| 2901 | } |
| 2902 | |
| 2903 | const gpa = mod.gpa; |
| 2904 | |
| 2905 | try mod.decl_exports.ensureUnusedCapacity(gpa, 1); |
| 2906 | try mod.export_owners.ensureUnusedCapacity(gpa, 1); |
| 2907 | |
| 2908 | const new_export = try gpa.create(Export); |
| 2909 | errdefer gpa.destroy(new_export); |
| 2910 | |
| 2911 | const symbol_name = try gpa.dupe(u8, borrowed_options.name); |
| 2912 | errdefer gpa.free(symbol_name); |
| 2913 | |
| 2914 | const section: ?[]const u8 = if (borrowed_options.section) |s| try gpa.dupe(u8, s) else null; |
| 2915 | errdefer if (section) |s| gpa.free(s); |
| 2916 | |
| 2917 | const src_decl = block.src_decl; |
| 2918 | const owner_decl = sema.owner_decl; |
| 2919 | |
| 2920 | log.debug("exporting Decl '{s}' as symbol '{s}' from Decl '{s}'", .{ |
| 2921 | exported_decl.name, symbol_name, owner_decl.name, |
| 2922 | }); |
| 2923 | |
| 2924 | new_export.* = .{ |
| 2925 | .options = .{ |
| 2926 | .name = symbol_name, |
| 2927 | .linkage = borrowed_options.linkage, |
| 2928 | .section = section, |
| 2929 | }, |
| 2930 | .src = src, |
| 2931 | .link = switch (mod.comp.bin_file.tag) { |
| 2932 | .coff => .{ .coff = {} }, |
| 2933 | .elf => .{ .elf = .{} }, |
| 2934 | .macho => .{ .macho = .{} }, |
| 2935 | .plan9 => .{ .plan9 = null }, |
| 2936 | .c => .{ .c = {} }, |
| 2937 | .wasm => .{ .wasm = {} }, |
| 2938 | .spirv => .{ .spirv = {} }, |
| 2939 | }, |
| 2940 | .owner_decl = owner_decl, |
| 2941 | .src_decl = src_decl, |
| 2942 | .exported_decl = exported_decl, |
| 2943 | .status = .in_progress, |
| 2944 | }; |
| 2945 | |
| 2946 | // Add to export_owners table. |
| 2947 | const eo_gop = mod.export_owners.getOrPutAssumeCapacity(owner_decl); |
| 2948 | if (!eo_gop.found_existing) { |
| 2949 | eo_gop.value_ptr.* = &[0]*Export{}; |
| 2950 | } |
| 2951 | eo_gop.value_ptr.* = try gpa.realloc(eo_gop.value_ptr.*, eo_gop.value_ptr.len + 1); |
| 2952 | eo_gop.value_ptr.*[eo_gop.value_ptr.len - 1] = new_export; |
| 2953 | errdefer eo_gop.value_ptr.* = gpa.shrink(eo_gop.value_ptr.*, eo_gop.value_ptr.len - 1); |
| 2954 | |
| 2955 | // Add to exported_decl table. |
| 2956 | const de_gop = mod.decl_exports.getOrPutAssumeCapacity(exported_decl); |
| 2957 | if (!de_gop.found_existing) { |
| 2958 | de_gop.value_ptr.* = &[0]*Export{}; |
| 2959 | } |
| 2960 | de_gop.value_ptr.* = try gpa.realloc(de_gop.value_ptr.*, de_gop.value_ptr.len + 1); |
| 2961 | de_gop.value_ptr.*[de_gop.value_ptr.len - 1] = new_export; |
| 2962 | errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1); |
| 2963 | } |
| 2964 | |
| 2965 | fn zirSetAlignStack(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2568 | 2966 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2569 | 2967 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2570 | 2968 | const src: LazySrcLoc = inst_data.src(); |
| 2571 | 2969 | const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand); |
| 2572 | 2970 | if (alignment > 256) { |
| 2573 | | return mod.fail(&block.base, src, "attempt to @setAlignStack({d}); maximum is 256", .{ |
| 2971 | return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{ |
| 2574 | 2972 | alignment, |
| 2575 | 2973 | }); |
| 2576 | 2974 | } |
| 2577 | 2975 | const func = sema.owner_func orelse |
| 2578 | | return mod.fail(&block.base, src, "@setAlignStack outside function body", .{}); |
| 2976 | return sema.fail(block, src, "@setAlignStack outside function body", .{}); |
| 2579 | 2977 | |
| 2580 | 2978 | switch (func.owner_decl.ty.fnCallingConvention()) { |
| 2581 | | .Naked => return mod.fail(&block.base, src, "@setAlignStack in naked function", .{}), |
| 2582 | | .Inline => return mod.fail(&block.base, src, "@setAlignStack in inline function", .{}), |
| 2979 | .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}), |
| 2980 | .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}), |
| 2583 | 2981 | else => {}, |
| 2584 | 2982 | } |
| 2585 | 2983 | |
| 2586 | | const gop = try mod.align_stack_fns.getOrPut(mod.gpa, func); |
| 2984 | const gop = try sema.mod.align_stack_fns.getOrPut(sema.mod.gpa, func); |
| 2587 | 2985 | if (gop.found_existing) { |
| 2588 | 2986 | const msg = msg: { |
| 2589 | | const msg = try mod.errMsg(&block.base, src, "multiple @setAlignStack in the same function body", .{}); |
| 2590 | | errdefer msg.destroy(mod.gpa); |
| 2591 | | try mod.errNote(&block.base, src, msg, "other instance here", .{}); |
| 2987 | const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{}); |
| 2988 | errdefer msg.destroy(sema.gpa); |
| 2989 | try sema.errNote(block, src, msg, "other instance here", .{}); |
| 2592 | 2990 | break :msg msg; |
| 2593 | 2991 | }; |
| 2594 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2992 | return sema.failWithOwnedErrorMsg(msg); |
| 2595 | 2993 | } |
| 2596 | 2994 | gop.value_ptr.* = .{ .alignment = alignment, .src = src }; |
| 2597 | 2995 | } |
| 2598 | 2996 | |
| 2599 | | fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2997 | fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2600 | 2998 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2601 | 2999 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2602 | 3000 | const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand); |
| ... | ... | @@ -2604,19 +3002,19 @@ fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2604 | 3002 | func.is_cold = is_cold; |
| 2605 | 3003 | } |
| 2606 | 3004 | |
| 2607 | | fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 3005 | fn zirSetFloatMode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2608 | 3006 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2609 | 3007 | const src: LazySrcLoc = inst_data.src(); |
| 2610 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirSetFloatMode", .{}); |
| 3008 | return sema.fail(block, src, "TODO: implement Sema.zirSetFloatMode", .{}); |
| 2611 | 3009 | } |
| 2612 | 3010 | |
| 2613 | | fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 3011 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2614 | 3012 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2615 | 3013 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2616 | 3014 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand); |
| 2617 | 3015 | } |
| 2618 | 3016 | |
| 2619 | | fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 3017 | fn zirFence(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2620 | 3018 | if (block.is_comptime) return; |
| 2621 | 3019 | |
| 2622 | 3020 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| ... | ... | @@ -2624,7 +3022,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2624 | 3022 | const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand); |
| 2625 | 3023 | |
| 2626 | 3024 | if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) { |
| 2627 | | return sema.mod.fail(&block.base, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| 3025 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| 2628 | 3026 | } |
| 2629 | 3027 | |
| 2630 | 3028 | _ = try block.addInst(.{ |
| ... | ... | @@ -2633,7 +3031,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2633 | 3031 | }); |
| 2634 | 3032 | } |
| 2635 | 3033 | |
| 2636 | | fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 3034 | fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 2637 | 3035 | const tracy = trace(@src()); |
| 2638 | 3036 | defer tracy.end(); |
| 2639 | 3037 | |
| ... | ... | @@ -2655,7 +3053,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2655 | 3053 | } |
| 2656 | 3054 | } |
| 2657 | 3055 | |
| 2658 | | fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 3056 | fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2659 | 3057 | const tracy = trace(@src()); |
| 2660 | 3058 | defer tracy.end(); |
| 2661 | 3059 | |
| ... | ... | @@ -2675,7 +3073,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2675 | 3073 | }); |
| 2676 | 3074 | } |
| 2677 | 3075 | |
| 2678 | | fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3076 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2679 | 3077 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 2680 | 3078 | const src = inst_data.src(); |
| 2681 | 3079 | const decl_name = inst_data.get(sema.code); |
| ... | ... | @@ -2683,7 +3081,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2683 | 3081 | return sema.analyzeDeclRef(decl); |
| 2684 | 3082 | } |
| 2685 | 3083 | |
| 2686 | | fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3084 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2687 | 3085 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 2688 | 3086 | const src = inst_data.src(); |
| 2689 | 3087 | const decl_name = inst_data.get(sema.code); |
| ... | ... | @@ -2691,8 +3089,8 @@ fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2691 | 3089 | return sema.analyzeDeclVal(block, src, decl); |
| 2692 | 3090 | } |
| 2693 | 3091 | |
| 2694 | | fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []const u8) !*Decl { |
| 2695 | | var namespace = sema.namespace; |
| 3092 | fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: []const u8) !*Decl { |
| 3093 | var namespace = block.namespace; |
| 2696 | 3094 | while (true) { |
| 2697 | 3095 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl| { |
| 2698 | 3096 | return decl; |
| ... | ... | @@ -2706,9 +3104,9 @@ fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []c |
| 2706 | 3104 | /// only for ones in the specified namespace. |
| 2707 | 3105 | fn lookupInNamespace( |
| 2708 | 3106 | sema: *Sema, |
| 2709 | | block: *Scope.Block, |
| 3107 | block: *Block, |
| 2710 | 3108 | src: LazySrcLoc, |
| 2711 | | namespace: *Scope.Namespace, |
| 3109 | namespace: *Namespace, |
| 2712 | 3110 | ident_name: []const u8, |
| 2713 | 3111 | observe_usingnamespace: bool, |
| 2714 | 3112 | ) CompileError!?*Decl { |
| ... | ... | @@ -2721,10 +3119,10 @@ fn lookupInNamespace( |
| 2721 | 3119 | } |
| 2722 | 3120 | |
| 2723 | 3121 | if (observe_usingnamespace and namespace.usingnamespace_set.count() != 0) { |
| 2724 | | const src_file = block.src_decl.namespace.file_scope; |
| 3122 | const src_file = block.namespace.file_scope; |
| 2725 | 3123 | |
| 2726 | 3124 | const gpa = sema.gpa; |
| 2727 | | var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Scope.Namespace, void) = .{}; |
| 3125 | var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, void) = .{}; |
| 2728 | 3126 | defer checked_namespaces.deinit(gpa); |
| 2729 | 3127 | |
| 2730 | 3128 | // Keep track of name conflicts for error notes. |
| ... | ... | @@ -2739,7 +3137,7 @@ fn lookupInNamespace( |
| 2739 | 3137 | if (check_ns.decls.get(ident_name)) |decl| { |
| 2740 | 3138 | // Skip decls which are not marked pub, which are in a different |
| 2741 | 3139 | // file than the `a.b`/`@hasDecl` syntax. |
| 2742 | | if (decl.is_pub or src_file == decl.namespace.file_scope) { |
| 3140 | if (decl.is_pub or src_file == decl.getFileScope()) { |
| 2743 | 3141 | try candidates.append(gpa, decl); |
| 2744 | 3142 | } |
| 2745 | 3143 | } |
| ... | ... | @@ -2747,7 +3145,7 @@ fn lookupInNamespace( |
| 2747 | 3145 | while (it.next()) |entry| { |
| 2748 | 3146 | const sub_usingnamespace_decl = entry.key_ptr.*; |
| 2749 | 3147 | const sub_is_pub = entry.value_ptr.*; |
| 2750 | | if (!sub_is_pub and src_file != sub_usingnamespace_decl.namespace.file_scope) { |
| 3148 | if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScope()) { |
| 2751 | 3149 | // Skip usingnamespace decls which are not marked pub, which are in |
| 2752 | 3150 | // a different file than the `a.b`/`@hasDecl` syntax. |
| 2753 | 3151 | continue; |
| ... | ... | @@ -2768,7 +3166,7 @@ fn lookupInNamespace( |
| 2768 | 3166 | }, |
| 2769 | 3167 | else => { |
| 2770 | 3168 | const msg = msg: { |
| 2771 | | const msg = try mod.errMsg(&block.base, src, "ambiguous reference", .{}); |
| 3169 | const msg = try sema.errMsg(block, src, "ambiguous reference", .{}); |
| 2772 | 3170 | errdefer msg.destroy(gpa); |
| 2773 | 3171 | for (candidates.items) |candidate| { |
| 2774 | 3172 | const src_loc = candidate.srcLoc(); |
| ... | ... | @@ -2776,7 +3174,7 @@ fn lookupInNamespace( |
| 2776 | 3174 | } |
| 2777 | 3175 | break :msg msg; |
| 2778 | 3176 | }; |
| 2779 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 3177 | return sema.failWithOwnedErrorMsg(msg); |
| 2780 | 3178 | }, |
| 2781 | 3179 | } |
| 2782 | 3180 | } else if (namespace.decls.get(ident_name)) |decl| { |
| ... | ... | @@ -2796,7 +3194,7 @@ fn lookupInNamespace( |
| 2796 | 3194 | |
| 2797 | 3195 | fn zirCall( |
| 2798 | 3196 | sema: *Sema, |
| 2799 | | block: *Scope.Block, |
| 3197 | block: *Block, |
| 2800 | 3198 | inst: Zir.Inst.Index, |
| 2801 | 3199 | ) CompileError!Air.Inst.Ref { |
| 2802 | 3200 | const tracy = trace(@src()); |
| ... | ... | @@ -2898,7 +3296,7 @@ const GenericRemoveAdapter = struct { |
| 2898 | 3296 | |
| 2899 | 3297 | fn analyzeCall( |
| 2900 | 3298 | sema: *Sema, |
| 2901 | | block: *Scope.Block, |
| 3299 | block: *Block, |
| 2902 | 3300 | func: Air.Inst.Ref, |
| 2903 | 3301 | func_src: LazySrcLoc, |
| 2904 | 3302 | call_src: LazySrcLoc, |
| ... | ... | @@ -2910,14 +3308,14 @@ fn analyzeCall( |
| 2910 | 3308 | |
| 2911 | 3309 | const func_ty = sema.typeOf(func); |
| 2912 | 3310 | if (func_ty.zigTypeTag() != .Fn) |
| 2913 | | return mod.fail(&block.base, func_src, "type '{}' not a function", .{func_ty}); |
| 3311 | return sema.fail(block, func_src, "type '{}' not a function", .{func_ty}); |
| 2914 | 3312 | |
| 2915 | 3313 | const func_ty_info = func_ty.fnInfo(); |
| 2916 | 3314 | const cc = func_ty_info.cc; |
| 2917 | 3315 | if (cc == .Naked) { |
| 2918 | 3316 | // TODO add error note: declared here |
| 2919 | | return mod.fail( |
| 2920 | | &block.base, |
| 3317 | return sema.fail( |
| 3318 | block, |
| 2921 | 3319 | func_src, |
| 2922 | 3320 | "unable to call function with naked calling convention", |
| 2923 | 3321 | .{}, |
| ... | ... | @@ -2928,8 +3326,8 @@ fn analyzeCall( |
| 2928 | 3326 | assert(cc == .C); |
| 2929 | 3327 | if (uncasted_args.len < fn_params_len) { |
| 2930 | 3328 | // TODO add error note: declared here |
| 2931 | | return mod.fail( |
| 2932 | | &block.base, |
| 3329 | return sema.fail( |
| 3330 | block, |
| 2933 | 3331 | func_src, |
| 2934 | 3332 | "expected at least {d} argument(s), found {d}", |
| 2935 | 3333 | .{ fn_params_len, uncasted_args.len }, |
| ... | ... | @@ -2937,8 +3335,8 @@ fn analyzeCall( |
| 2937 | 3335 | } |
| 2938 | 3336 | } else if (fn_params_len != uncasted_args.len) { |
| 2939 | 3337 | // TODO add error note: declared here |
| 2940 | | return mod.fail( |
| 2941 | | &block.base, |
| 3338 | return sema.fail( |
| 3339 | block, |
| 2942 | 3340 | func_src, |
| 2943 | 3341 | "expected {d} argument(s), found {d}", |
| 2944 | 3342 | .{ fn_params_len, uncasted_args.len }, |
| ... | ... | @@ -2956,7 +3354,7 @@ fn analyzeCall( |
| 2956 | 3354 | .never_inline, |
| 2957 | 3355 | .no_async, |
| 2958 | 3356 | .always_tail, |
| 2959 | | => return mod.fail(&block.base, call_src, "TODO implement call with modifier {}", .{ |
| 3357 | => return sema.fail(block, call_src, "TODO implement call with modifier {}", .{ |
| 2960 | 3358 | modifier, |
| 2961 | 3359 | }), |
| 2962 | 3360 | } |
| ... | ... | @@ -2971,7 +3369,7 @@ fn analyzeCall( |
| 2971 | 3369 | const func_val = try sema.resolveConstValue(block, func_src, func); |
| 2972 | 3370 | const module_fn = switch (func_val.tag()) { |
| 2973 | 3371 | .function => func_val.castTag(.function).?.data, |
| 2974 | | .extern_fn => return mod.fail(&block.base, call_src, "{s} call of extern function", .{ |
| 3372 | .extern_fn => return sema.fail(block, call_src, "{s} call of extern function", .{ |
| 2975 | 3373 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| 2976 | 3374 | }), |
| 2977 | 3375 | else => unreachable, |
| ... | ... | @@ -2979,7 +3377,7 @@ fn analyzeCall( |
| 2979 | 3377 | |
| 2980 | 3378 | // Analyze the ZIR. The same ZIR gets analyzed into a runtime function |
| 2981 | 3379 | // or an inlined call depending on what union tag the `label` field is |
| 2982 | | // set to in the `Scope.Block`. |
| 3380 | // set to in the `Block`. |
| 2983 | 3381 | // This block instruction will be used to capture the return value from the |
| 2984 | 3382 | // inlined function. |
| 2985 | 3383 | const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len); |
| ... | ... | @@ -2989,7 +3387,7 @@ fn analyzeCall( |
| 2989 | 3387 | }); |
| 2990 | 3388 | // This one is shared among sub-blocks within the same callee, but not |
| 2991 | 3389 | // shared among the entire inline/comptime call stack. |
| 2992 | | var inlining: Scope.Block.Inlining = .{ |
| 3390 | var inlining: Block.Inlining = .{ |
| 2993 | 3391 | .comptime_result = undefined, |
| 2994 | 3392 | .merges = .{ |
| 2995 | 3393 | .results = .{}, |
| ... | ... | @@ -3000,7 +3398,7 @@ fn analyzeCall( |
| 3000 | 3398 | // In order to save a bit of stack space, directly modify Sema rather |
| 3001 | 3399 | // than create a child one. |
| 3002 | 3400 | const parent_zir = sema.code; |
| 3003 | | sema.code = module_fn.owner_decl.namespace.file_scope.zir; |
| 3401 | sema.code = module_fn.owner_decl.getFileScope().zir; |
| 3004 | 3402 | defer sema.code = parent_zir; |
| 3005 | 3403 | |
| 3006 | 3404 | const parent_inst_map = sema.inst_map; |
| ... | ... | @@ -3010,10 +3408,6 @@ fn analyzeCall( |
| 3010 | 3408 | sema.inst_map = parent_inst_map; |
| 3011 | 3409 | } |
| 3012 | 3410 | |
| 3013 | | const parent_namespace = sema.namespace; |
| 3014 | | sema.namespace = module_fn.owner_decl.namespace; |
| 3015 | | defer sema.namespace = parent_namespace; |
| 3016 | | |
| 3017 | 3411 | const parent_func = sema.func; |
| 3018 | 3412 | sema.func = module_fn; |
| 3019 | 3413 | defer sema.func = parent_func; |
| ... | ... | @@ -3021,10 +3415,11 @@ fn analyzeCall( |
| 3021 | 3415 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, module_fn.owner_decl.src_scope); |
| 3022 | 3416 | defer wip_captures.deinit(); |
| 3023 | 3417 | |
| 3024 | | var child_block: Scope.Block = .{ |
| 3418 | var child_block: Block = .{ |
| 3025 | 3419 | .parent = null, |
| 3026 | 3420 | .sema = sema, |
| 3027 | 3421 | .src_decl = module_fn.owner_decl, |
| 3422 | .namespace = module_fn.owner_decl.src_namespace, |
| 3028 | 3423 | .wip_capture_scope = wip_captures.scope, |
| 3029 | 3424 | .instructions = .{}, |
| 3030 | 3425 | .label = null, |
| ... | ... | @@ -3180,12 +3575,6 @@ fn analyzeCall( |
| 3180 | 3575 | }); |
| 3181 | 3576 | delete_memoized_call_key = false; |
| 3182 | 3577 | } |
| 3183 | | |
| 3184 | | // Much like in `Module.semaDecl`, if the result is a struct or union type, |
| 3185 | | // we need to resolve the field type expressions right here, right now, while |
| 3186 | | // the child `Sema` is still available, with the AIR instruction map intact, |
| 3187 | | // because the field type expressions may reference into it. |
| 3188 | | try sema.resolvePendingTypes(&child_block); |
| 3189 | 3578 | } |
| 3190 | 3579 | |
| 3191 | 3580 | break :res2 result; |
| ... | ... | @@ -3200,7 +3589,7 @@ fn analyzeCall( |
| 3200 | 3589 | // Check the Module's generic function map with an adapted context, so that we |
| 3201 | 3590 | // can match against `uncasted_args` rather than doing the work below to create a |
| 3202 | 3591 | // generic Scope only to junk it if it matches an existing instantiation. |
| 3203 | | const namespace = module_fn.owner_decl.namespace; |
| 3592 | const namespace = module_fn.owner_decl.src_namespace; |
| 3204 | 3593 | const fn_zir = namespace.file_scope.zir; |
| 3205 | 3594 | const fn_info = fn_zir.getFnInfo(module_fn.zir_body_inst); |
| 3206 | 3595 | const zir_tags = fn_zir.instructions.items(.tag); |
| ... | ... | @@ -3276,12 +3665,12 @@ fn analyzeCall( |
| 3276 | 3665 | |
| 3277 | 3666 | // Create a Decl for the new function. |
| 3278 | 3667 | const src_decl = namespace.getDecl(); |
| 3279 | | const new_decl = try mod.allocateNewDecl(namespace, module_fn.owner_decl.src_node, src_decl.src_scope); |
| 3280 | 3668 | // TODO better names for generic function instantiations |
| 3281 | 3669 | const name_index = mod.getNextAnonNameIndex(); |
| 3282 | | new_decl.name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ |
| 3670 | const decl_name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ |
| 3283 | 3671 | module_fn.owner_decl.name, name_index, |
| 3284 | 3672 | }); |
| 3673 | const new_decl = try mod.allocateNewDecl(decl_name, namespace, module_fn.owner_decl.src_node, src_decl.src_scope); |
| 3285 | 3674 | new_decl.src_line = module_fn.owner_decl.src_line; |
| 3286 | 3675 | new_decl.is_pub = module_fn.owner_decl.is_pub; |
| 3287 | 3676 | new_decl.is_exported = module_fn.owner_decl.is_exported; |
| ... | ... | @@ -3297,6 +3686,11 @@ fn analyzeCall( |
| 3297 | 3686 | |
| 3298 | 3687 | namespace.anon_decls.putAssumeCapacityNoClobber(new_decl, {}); |
| 3299 | 3688 | |
| 3689 | // The generic function Decl is guaranteed to be the first dependency |
| 3690 | // of each of its instantiations. |
| 3691 | assert(new_decl.dependencies.keys().len == 0); |
| 3692 | try mod.declareDeclDependency(new_decl, module_fn.owner_decl); |
| 3693 | |
| 3300 | 3694 | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); |
| 3301 | 3695 | errdefer new_decl_arena.deinit(); |
| 3302 | 3696 | |
| ... | ... | @@ -3311,7 +3705,6 @@ fn analyzeCall( |
| 3311 | 3705 | .perm_arena = &new_decl_arena.allocator, |
| 3312 | 3706 | .code = fn_zir, |
| 3313 | 3707 | .owner_decl = new_decl, |
| 3314 | | .namespace = namespace, |
| 3315 | 3708 | .func = null, |
| 3316 | 3709 | .fn_ret_ty = Type.initTag(.void), |
| 3317 | 3710 | .owner_func = null, |
| ... | ... | @@ -3324,10 +3717,11 @@ fn analyzeCall( |
| 3324 | 3717 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope); |
| 3325 | 3718 | defer wip_captures.deinit(); |
| 3326 | 3719 | |
| 3327 | | var child_block: Scope.Block = .{ |
| 3720 | var child_block: Block = .{ |
| 3328 | 3721 | .parent = null, |
| 3329 | 3722 | .sema = &child_sema, |
| 3330 | 3723 | .src_decl = new_decl, |
| 3724 | .namespace = namespace, |
| 3331 | 3725 | .wip_capture_scope = wip_captures.scope, |
| 3332 | 3726 | .instructions = .{}, |
| 3333 | 3727 | .inlining = null, |
| ... | ... | @@ -3430,11 +3824,6 @@ fn analyzeCall( |
| 3430 | 3824 | }); |
| 3431 | 3825 | assert(!new_decl.ty.fnInfo().is_generic); |
| 3432 | 3826 | |
| 3433 | | // The generic function Decl is guaranteed to be the first dependency |
| 3434 | | // of each of its instantiations. |
| 3435 | | assert(new_decl.dependencies.keys().len == 0); |
| 3436 | | try mod.declareDeclDependency(new_decl, module_fn.owner_decl); |
| 3437 | | |
| 3438 | 3827 | // Queue up a `codegen_func` work item for the new Fn. The `comptime_args` field |
| 3439 | 3828 | // will be populated, ensuring it will have `analyzeBody` called with the ZIR |
| 3440 | 3829 | // parameters mapped appropriately. |
| ... | ... | @@ -3489,7 +3878,7 @@ fn analyzeCall( |
| 3489 | 3878 | |
| 3490 | 3879 | fn finishGenericCall( |
| 3491 | 3880 | sema: *Sema, |
| 3492 | | block: *Scope.Block, |
| 3881 | block: *Block, |
| 3493 | 3882 | call_src: LazySrcLoc, |
| 3494 | 3883 | callee: *Module.Fn, |
| 3495 | 3884 | func_src: LazySrcLoc, |
| ... | ... | @@ -3556,7 +3945,7 @@ fn finishGenericCall( |
| 3556 | 3945 | return func_inst; |
| 3557 | 3946 | } |
| 3558 | 3947 | |
| 3559 | | fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3948 | fn zirIntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3560 | 3949 | _ = block; |
| 3561 | 3950 | const tracy = trace(@src()); |
| 3562 | 3951 | defer tracy.end(); |
| ... | ... | @@ -3567,7 +3956,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 3567 | 3956 | return sema.addType(ty); |
| 3568 | 3957 | } |
| 3569 | 3958 | |
| 3570 | | fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3959 | fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3571 | 3960 | const tracy = trace(@src()); |
| 3572 | 3961 | defer tracy.end(); |
| 3573 | 3962 | |
| ... | ... | @@ -3579,7 +3968,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 3579 | 3968 | return sema.addType(opt_type); |
| 3580 | 3969 | } |
| 3581 | 3970 | |
| 3582 | | fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3971 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3583 | 3972 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3584 | 3973 | const src = inst_data.src(); |
| 3585 | 3974 | const array_type = try sema.resolveType(block, src, inst_data.operand); |
| ... | ... | @@ -3587,7 +3976,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 3587 | 3976 | return sema.addType(elem_type); |
| 3588 | 3977 | } |
| 3589 | 3978 | |
| 3590 | | fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3979 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3591 | 3980 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3592 | 3981 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 3593 | 3982 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| ... | ... | @@ -3601,7 +3990,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3601 | 3990 | return sema.addType(vector_type); |
| 3602 | 3991 | } |
| 3603 | 3992 | |
| 3604 | | fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3993 | fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3605 | 3994 | const tracy = trace(@src()); |
| 3606 | 3995 | defer tracy.end(); |
| 3607 | 3996 | |
| ... | ... | @@ -3613,7 +4002,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3613 | 4002 | return sema.addType(array_ty); |
| 3614 | 4003 | } |
| 3615 | 4004 | |
| 3616 | | fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4005 | fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3617 | 4006 | const tracy = trace(@src()); |
| 3618 | 4007 | defer tracy.end(); |
| 3619 | 4008 | |
| ... | ... | @@ -3629,7 +4018,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 3629 | 4018 | return sema.addType(array_ty); |
| 3630 | 4019 | } |
| 3631 | 4020 | |
| 3632 | | fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4021 | fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3633 | 4022 | const tracy = trace(@src()); |
| 3634 | 4023 | defer tracy.end(); |
| 3635 | 4024 | |
| ... | ... | @@ -3641,7 +4030,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 3641 | 4030 | return sema.addType(anyframe_type); |
| 3642 | 4031 | } |
| 3643 | 4032 | |
| 3644 | | fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4033 | fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3645 | 4034 | const tracy = trace(@src()); |
| 3646 | 4035 | defer tracy.end(); |
| 3647 | 4036 | |
| ... | ... | @@ -3653,7 +4042,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3653 | 4042 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); |
| 3654 | 4043 | |
| 3655 | 4044 | if (error_union.zigTypeTag() != .ErrorSet) { |
| 3656 | | return sema.mod.fail(&block.base, lhs_src, "expected error set type, found {}", .{ |
| 4045 | return sema.fail(block, lhs_src, "expected error set type, found {}", .{ |
| 3657 | 4046 | error_union.elemType(), |
| 3658 | 4047 | }); |
| 3659 | 4048 | } |
| ... | ... | @@ -3661,7 +4050,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3661 | 4050 | return sema.addType(err_union_ty); |
| 3662 | 4051 | } |
| 3663 | 4052 | |
| 3664 | | fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4053 | fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3665 | 4054 | _ = block; |
| 3666 | 4055 | const tracy = trace(@src()); |
| 3667 | 4056 | defer tracy.end(); |
| ... | ... | @@ -3679,7 +4068,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3679 | 4068 | ); |
| 3680 | 4069 | } |
| 3681 | 4070 | |
| 3682 | | fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4071 | fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3683 | 4072 | const tracy = trace(@src()); |
| 3684 | 4073 | defer tracy.end(); |
| 3685 | 4074 | |
| ... | ... | @@ -3706,7 +4095,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3706 | 4095 | return block.addTyOp(.bitcast, result_ty, op_coerced); |
| 3707 | 4096 | } |
| 3708 | 4097 | |
| 3709 | | fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4098 | fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3710 | 4099 | const tracy = trace(@src()); |
| 3711 | 4100 | defer tracy.end(); |
| 3712 | 4101 | |
| ... | ... | @@ -3719,7 +4108,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3719 | 4108 | if (try sema.resolveDefinedValue(block, operand_src, op)) |value| { |
| 3720 | 4109 | const int = value.toUnsignedInt(); |
| 3721 | 4110 | if (int > sema.mod.global_error_set.count() or int == 0) |
| 3722 | | return sema.mod.fail(&block.base, operand_src, "integer value {d} represents no error", .{int}); |
| 4111 | return sema.fail(block, operand_src, "integer value {d} represents no error", .{int}); |
| 3723 | 4112 | const payload = try sema.arena.create(Value.Payload.Error); |
| 3724 | 4113 | payload.* = .{ |
| 3725 | 4114 | .base = .{ .tag = .@"error" }, |
| ... | ... | @@ -3729,14 +4118,14 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3729 | 4118 | } |
| 3730 | 4119 | try sema.requireRuntimeBlock(block, src); |
| 3731 | 4120 | if (block.wantSafety()) { |
| 3732 | | return sema.mod.fail(&block.base, src, "TODO: get max errors in compilation", .{}); |
| 4121 | return sema.fail(block, src, "TODO: get max errors in compilation", .{}); |
| 3733 | 4122 | // const is_gt_max = @panic("TODO get max errors in compilation"); |
| 3734 | 4123 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); |
| 3735 | 4124 | } |
| 3736 | 4125 | return block.addTyOp(.bitcast, Type.initTag(.anyerror), op); |
| 3737 | 4126 | } |
| 3738 | 4127 | |
| 3739 | | fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4128 | fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3740 | 4129 | const tracy = trace(@src()); |
| 3741 | 4130 | defer tracy.end(); |
| 3742 | 4131 | |
| ... | ... | @@ -3749,19 +4138,19 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3749 | 4138 | const rhs = sema.resolveInst(extra.rhs); |
| 3750 | 4139 | if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) { |
| 3751 | 4140 | const msg = msg: { |
| 3752 | | const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{}); |
| 4141 | const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{}); |
| 3753 | 4142 | errdefer msg.destroy(sema.gpa); |
| 3754 | | try sema.mod.errNote(&block.base, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 4143 | try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 3755 | 4144 | break :msg msg; |
| 3756 | 4145 | }; |
| 3757 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 4146 | return sema.failWithOwnedErrorMsg(msg); |
| 3758 | 4147 | } |
| 3759 | 4148 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); |
| 3760 | 4149 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); |
| 3761 | 4150 | if (lhs_ty.zigTypeTag() != .ErrorSet) |
| 3762 | | return sema.mod.fail(&block.base, lhs_src, "expected error set type, found {}", .{lhs_ty}); |
| 4151 | return sema.fail(block, lhs_src, "expected error set type, found {}", .{lhs_ty}); |
| 3763 | 4152 | if (rhs_ty.zigTypeTag() != .ErrorSet) |
| 3764 | | return sema.mod.fail(&block.base, rhs_src, "expected error set type, found {}", .{rhs_ty}); |
| 4153 | return sema.fail(block, rhs_src, "expected error set type, found {}", .{rhs_ty}); |
| 3765 | 4154 | |
| 3766 | 4155 | // Anything merged with anyerror is anyerror. |
| 3767 | 4156 | if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) { |
| ... | ... | @@ -3820,7 +4209,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3820 | 4209 | return sema.addConstant(Type.initTag(.type), try Value.Tag.ty.create(sema.arena, error_set_ty)); |
| 3821 | 4210 | } |
| 3822 | 4211 | |
| 3823 | | fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4212 | fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3824 | 4213 | _ = block; |
| 3825 | 4214 | const tracy = trace(@src()); |
| 3826 | 4215 | defer tracy.end(); |
| ... | ... | @@ -3833,8 +4222,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 3833 | 4222 | ); |
| 3834 | 4223 | } |
| 3835 | 4224 | |
| 3836 | | fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3837 | | const mod = sema.mod; |
| 4225 | fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3838 | 4226 | const arena = sema.arena; |
| 3839 | 4227 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3840 | 4228 | const src = inst_data.src(); |
| ... | ... | @@ -3846,17 +4234,17 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3846 | 4234 | .Enum => operand, |
| 3847 | 4235 | .Union => { |
| 3848 | 4236 | //if (!operand_ty.unionHasTag()) { |
| 3849 | | // return mod.fail( |
| 3850 | | // &block.base, |
| 4237 | // return sema.fail( |
| 4238 | // block, |
| 3851 | 4239 | // operand_src, |
| 3852 | 4240 | // "untagged union '{}' cannot be converted to integer", |
| 3853 | 4241 | // .{dest_ty_src}, |
| 3854 | 4242 | // ); |
| 3855 | 4243 | //} |
| 3856 | | return mod.fail(&block.base, operand_src, "TODO zirEnumToInt for tagged unions", .{}); |
| 4244 | return sema.fail(block, operand_src, "TODO zirEnumToInt for tagged unions", .{}); |
| 3857 | 4245 | }, |
| 3858 | 4246 | else => { |
| 3859 | | return mod.fail(&block.base, operand_src, "expected enum or tagged union, found {}", .{ |
| 4247 | return sema.fail(block, operand_src, "expected enum or tagged union, found {}", .{ |
| 3860 | 4248 | operand_ty, |
| 3861 | 4249 | }); |
| 3862 | 4250 | }, |
| ... | ... | @@ -3880,9 +4268,8 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3880 | 4268 | return block.addTyOp(.bitcast, int_tag_ty, enum_tag); |
| 3881 | 4269 | } |
| 3882 | 4270 | |
| 3883 | | fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3884 | | const mod = sema.mod; |
| 3885 | | const target = mod.getTarget(); |
| 4271 | fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4272 | const target = sema.mod.getTarget(); |
| 3886 | 4273 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3887 | 4274 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3888 | 4275 | const src = inst_data.src(); |
| ... | ... | @@ -3892,7 +4279,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3892 | 4279 | const operand = sema.resolveInst(extra.rhs); |
| 3893 | 4280 | |
| 3894 | 4281 | if (dest_ty.zigTypeTag() != .Enum) { |
| 3895 | | return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty}); |
| 4282 | return sema.fail(block, dest_ty_src, "expected enum, found {}", .{dest_ty}); |
| 3896 | 4283 | } |
| 3897 | 4284 | |
| 3898 | 4285 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| { |
| ... | ... | @@ -3904,14 +4291,14 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3904 | 4291 | } |
| 3905 | 4292 | if (!dest_ty.enumHasInt(int_val, target)) { |
| 3906 | 4293 | const msg = msg: { |
| 3907 | | const msg = try mod.errMsg( |
| 3908 | | &block.base, |
| 4294 | const msg = try sema.errMsg( |
| 4295 | block, |
| 3909 | 4296 | src, |
| 3910 | 4297 | "enum '{}' has no tag with value {}", |
| 3911 | 4298 | .{ dest_ty, int_val }, |
| 3912 | 4299 | ); |
| 3913 | 4300 | errdefer msg.destroy(sema.gpa); |
| 3914 | | try mod.errNoteNonLazy( |
| 4301 | try sema.mod.errNoteNonLazy( |
| 3915 | 4302 | dest_ty.declSrcLoc(), |
| 3916 | 4303 | msg, |
| 3917 | 4304 | "enum declared here", |
| ... | ... | @@ -3919,7 +4306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3919 | 4306 | ); |
| 3920 | 4307 | break :msg msg; |
| 3921 | 4308 | }; |
| 3922 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 4309 | return sema.failWithOwnedErrorMsg(msg); |
| 3923 | 4310 | } |
| 3924 | 4311 | return sema.addConstant(dest_ty, int_val); |
| 3925 | 4312 | } |
| ... | ... | @@ -3931,7 +4318,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3931 | 4318 | /// Pointer in, pointer out. |
| 3932 | 4319 | fn zirOptionalPayloadPtr( |
| 3933 | 4320 | sema: *Sema, |
| 3934 | | block: *Scope.Block, |
| 4321 | block: *Block, |
| 3935 | 4322 | inst: Zir.Inst.Index, |
| 3936 | 4323 | safety_check: bool, |
| 3937 | 4324 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -3946,7 +4333,7 @@ fn zirOptionalPayloadPtr( |
| 3946 | 4333 | |
| 3947 | 4334 | const opt_type = optional_ptr_ty.elemType(); |
| 3948 | 4335 | if (opt_type.zigTypeTag() != .Optional) { |
| 3949 | | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 4336 | return sema.fail(block, src, "expected optional type, found {}", .{opt_type}); |
| 3950 | 4337 | } |
| 3951 | 4338 | |
| 3952 | 4339 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| ... | ... | @@ -3959,7 +4346,7 @@ fn zirOptionalPayloadPtr( |
| 3959 | 4346 | if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| { |
| 3960 | 4347 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 3961 | 4348 | if (val.isNull()) { |
| 3962 | | return sema.mod.fail(&block.base, src, "unable to unwrap null", .{}); |
| 4349 | return sema.fail(block, src, "unable to unwrap null", .{}); |
| 3963 | 4350 | } |
| 3964 | 4351 | // The same Value represents the pointer to the optional and the payload. |
| 3965 | 4352 | return sema.addConstant( |
| ... | ... | @@ -3980,7 +4367,7 @@ fn zirOptionalPayloadPtr( |
| 3980 | 4367 | /// Value in, value out. |
| 3981 | 4368 | fn zirOptionalPayload( |
| 3982 | 4369 | sema: *Sema, |
| 3983 | | block: *Scope.Block, |
| 4370 | block: *Block, |
| 3984 | 4371 | inst: Zir.Inst.Index, |
| 3985 | 4372 | safety_check: bool, |
| 3986 | 4373 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -3993,14 +4380,14 @@ fn zirOptionalPayload( |
| 3993 | 4380 | const operand_ty = sema.typeOf(operand); |
| 3994 | 4381 | const opt_type = operand_ty; |
| 3995 | 4382 | if (opt_type.zigTypeTag() != .Optional) { |
| 3996 | | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 4383 | return sema.fail(block, src, "expected optional type, found {}", .{opt_type}); |
| 3997 | 4384 | } |
| 3998 | 4385 | |
| 3999 | 4386 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 4000 | 4387 | |
| 4001 | 4388 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 4002 | 4389 | if (val.isNull()) { |
| 4003 | | return sema.mod.fail(&block.base, src, "unable to unwrap null", .{}); |
| 4390 | return sema.fail(block, src, "unable to unwrap null", .{}); |
| 4004 | 4391 | } |
| 4005 | 4392 | const sub_val = val.castTag(.opt_payload).?.data; |
| 4006 | 4393 | return sema.addConstant(child_type, sub_val); |
| ... | ... | @@ -4017,7 +4404,7 @@ fn zirOptionalPayload( |
| 4017 | 4404 | /// Value in, value out |
| 4018 | 4405 | fn zirErrUnionPayload( |
| 4019 | 4406 | sema: *Sema, |
| 4020 | | block: *Scope.Block, |
| 4407 | block: *Block, |
| 4021 | 4408 | inst: Zir.Inst.Index, |
| 4022 | 4409 | safety_check: bool, |
| 4023 | 4410 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -4030,11 +4417,11 @@ fn zirErrUnionPayload( |
| 4030 | 4417 | const operand_src = src; |
| 4031 | 4418 | const operand_ty = sema.typeOf(operand); |
| 4032 | 4419 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 4033 | | return sema.mod.fail(&block.base, operand_src, "expected error union type, found '{}'", .{operand_ty}); |
| 4420 | return sema.fail(block, operand_src, "expected error union type, found '{}'", .{operand_ty}); |
| 4034 | 4421 | |
| 4035 | 4422 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 4036 | 4423 | if (val.getError()) |name| { |
| 4037 | | return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name}); |
| 4424 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); |
| 4038 | 4425 | } |
| 4039 | 4426 | const data = val.castTag(.eu_payload).?.data; |
| 4040 | 4427 | const result_ty = operand_ty.errorUnionPayload(); |
| ... | ... | @@ -4052,7 +4439,7 @@ fn zirErrUnionPayload( |
| 4052 | 4439 | /// Pointer in, pointer out. |
| 4053 | 4440 | fn zirErrUnionPayloadPtr( |
| 4054 | 4441 | sema: *Sema, |
| 4055 | | block: *Scope.Block, |
| 4442 | block: *Block, |
| 4056 | 4443 | inst: Zir.Inst.Index, |
| 4057 | 4444 | safety_check: bool, |
| 4058 | 4445 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -4066,7 +4453,7 @@ fn zirErrUnionPayloadPtr( |
| 4066 | 4453 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4067 | 4454 | |
| 4068 | 4455 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) |
| 4069 | | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4456 | return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4070 | 4457 | |
| 4071 | 4458 | const payload_ty = operand_ty.elemType().errorUnionPayload(); |
| 4072 | 4459 | const operand_pointer_ty = try Type.ptr(sema.arena, .{ |
| ... | ... | @@ -4078,7 +4465,7 @@ fn zirErrUnionPayloadPtr( |
| 4078 | 4465 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { |
| 4079 | 4466 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 4080 | 4467 | if (val.getError()) |name| { |
| 4081 | | return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name}); |
| 4468 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); |
| 4082 | 4469 | } |
| 4083 | 4470 | return sema.addConstant( |
| 4084 | 4471 | operand_pointer_ty, |
| ... | ... | @@ -4096,7 +4483,7 @@ fn zirErrUnionPayloadPtr( |
| 4096 | 4483 | } |
| 4097 | 4484 | |
| 4098 | 4485 | /// Value in, value out |
| 4099 | | fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4486 | fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4100 | 4487 | const tracy = trace(@src()); |
| 4101 | 4488 | defer tracy.end(); |
| 4102 | 4489 | |
| ... | ... | @@ -4105,7 +4492,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 4105 | 4492 | const operand = sema.resolveInst(inst_data.operand); |
| 4106 | 4493 | const operand_ty = sema.typeOf(operand); |
| 4107 | 4494 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 4108 | | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4495 | return sema.fail(block, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4109 | 4496 | |
| 4110 | 4497 | const result_ty = operand_ty.errorUnionSet(); |
| 4111 | 4498 | |
| ... | ... | @@ -4119,7 +4506,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 4119 | 4506 | } |
| 4120 | 4507 | |
| 4121 | 4508 | /// Pointer in, value out |
| 4122 | | fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4509 | fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4123 | 4510 | const tracy = trace(@src()); |
| 4124 | 4511 | defer tracy.end(); |
| 4125 | 4512 | |
| ... | ... | @@ -4130,7 +4517,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 4130 | 4517 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4131 | 4518 | |
| 4132 | 4519 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) |
| 4133 | | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4520 | return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4134 | 4521 | |
| 4135 | 4522 | const result_ty = operand_ty.elemType().errorUnionSet(); |
| 4136 | 4523 | |
| ... | ... | @@ -4145,7 +4532,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 4145 | 4532 | return block.addTyOp(.unwrap_errunion_err_ptr, result_ty, operand); |
| 4146 | 4533 | } |
| 4147 | 4534 | |
| 4148 | | fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 4535 | fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4149 | 4536 | const tracy = trace(@src()); |
| 4150 | 4537 | defer tracy.end(); |
| 4151 | 4538 | |
| ... | ... | @@ -4154,15 +4541,15 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 4154 | 4541 | const operand = sema.resolveInst(inst_data.operand); |
| 4155 | 4542 | const operand_ty = sema.typeOf(operand); |
| 4156 | 4543 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 4157 | | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4544 | return sema.fail(block, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4158 | 4545 | if (operand_ty.errorUnionPayload().zigTypeTag() != .Void) { |
| 4159 | | return sema.mod.fail(&block.base, src, "expression value is ignored", .{}); |
| 4546 | return sema.fail(block, src, "expression value is ignored", .{}); |
| 4160 | 4547 | } |
| 4161 | 4548 | } |
| 4162 | 4549 | |
| 4163 | 4550 | fn zirFunc( |
| 4164 | 4551 | sema: *Sema, |
| 4165 | | block: *Scope.Block, |
| 4552 | block: *Block, |
| 4166 | 4553 | inst: Zir.Inst.Index, |
| 4167 | 4554 | inferred_error_set: bool, |
| 4168 | 4555 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -4205,7 +4592,7 @@ fn zirFunc( |
| 4205 | 4592 | |
| 4206 | 4593 | fn funcCommon( |
| 4207 | 4594 | sema: *Sema, |
| 4208 | | block: *Scope.Block, |
| 4595 | block: *Block, |
| 4209 | 4596 | src_node_offset: i32, |
| 4210 | 4597 | body_inst: Zir.Inst.Index, |
| 4211 | 4598 | ret_ty_body: []const Zir.Inst.Index, |
| ... | ... | @@ -4297,7 +4684,7 @@ fn funcCommon( |
| 4297 | 4684 | } |
| 4298 | 4685 | |
| 4299 | 4686 | if (align_val.tag() != .null_value) { |
| 4300 | | return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{}); |
| 4687 | return sema.fail(block, src, "TODO implement support for function prototypes to have alignment specified", .{}); |
| 4301 | 4688 | } |
| 4302 | 4689 | |
| 4303 | 4690 | is_generic = is_generic or bare_return_type.requiresComptime(); |
| ... | ... | @@ -4329,15 +4716,15 @@ fn funcCommon( |
| 4329 | 4716 | const lib_name_src: LazySrcLoc = .{ .node_offset_lib_name = src_node_offset }; |
| 4330 | 4717 | log.debug("extern fn symbol expected in lib '{s}'", .{lib_name}); |
| 4331 | 4718 | mod.comp.stage1AddLinkLib(lib_name) catch |err| { |
| 4332 | | return mod.fail(&block.base, lib_name_src, "unable to add link lib '{s}': {s}", .{ |
| 4719 | return sema.fail(block, lib_name_src, "unable to add link lib '{s}': {s}", .{ |
| 4333 | 4720 | lib_name, @errorName(err), |
| 4334 | 4721 | }); |
| 4335 | 4722 | }; |
| 4336 | 4723 | const target = mod.getTarget(); |
| 4337 | 4724 | if (target_util.is_libc_lib_name(target, lib_name)) { |
| 4338 | 4725 | if (!mod.comp.bin_file.options.link_libc) { |
| 4339 | | return mod.fail( |
| 4340 | | &block.base, |
| 4726 | return sema.fail( |
| 4727 | block, |
| 4341 | 4728 | lib_name_src, |
| 4342 | 4729 | "dependency on libc must be explicitly specified in the build command", |
| 4343 | 4730 | .{}, |
| ... | ... | @@ -4347,8 +4734,8 @@ fn funcCommon( |
| 4347 | 4734 | } |
| 4348 | 4735 | if (target_util.is_libcpp_lib_name(target, lib_name)) { |
| 4349 | 4736 | if (!mod.comp.bin_file.options.link_libcpp) { |
| 4350 | | return mod.fail( |
| 4351 | | &block.base, |
| 4737 | return sema.fail( |
| 4738 | block, |
| 4352 | 4739 | lib_name_src, |
| 4353 | 4740 | "dependency on libc++ must be explicitly specified in the build command", |
| 4354 | 4741 | .{}, |
| ... | ... | @@ -4357,8 +4744,8 @@ fn funcCommon( |
| 4357 | 4744 | break :blk; |
| 4358 | 4745 | } |
| 4359 | 4746 | if (!target.isWasm() and !mod.comp.bin_file.options.pic) { |
| 4360 | | return mod.fail( |
| 4361 | | &block.base, |
| 4747 | return sema.fail( |
| 4748 | block, |
| 4362 | 4749 | lib_name_src, |
| 4363 | 4750 | "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.", |
| 4364 | 4751 | .{ lib_name, lib_name }, |
| ... | ... | @@ -4404,7 +4791,7 @@ fn funcCommon( |
| 4404 | 4791 | |
| 4405 | 4792 | fn zirParam( |
| 4406 | 4793 | sema: *Sema, |
| 4407 | | block: *Scope.Block, |
| 4794 | block: *Block, |
| 4408 | 4795 | inst: Zir.Inst.Index, |
| 4409 | 4796 | is_comptime: bool, |
| 4410 | 4797 | ) CompileError!void { |
| ... | ... | @@ -4474,7 +4861,7 @@ fn zirParam( |
| 4474 | 4861 | |
| 4475 | 4862 | fn zirParamAnytype( |
| 4476 | 4863 | sema: *Sema, |
| 4477 | | block: *Scope.Block, |
| 4864 | block: *Block, |
| 4478 | 4865 | inst: Zir.Inst.Index, |
| 4479 | 4866 | is_comptime: bool, |
| 4480 | 4867 | ) CompileError!void { |
| ... | ... | @@ -4509,7 +4896,7 @@ fn zirParamAnytype( |
| 4509 | 4896 | try sema.inst_map.put(sema.gpa, inst, .generic_poison); |
| 4510 | 4897 | } |
| 4511 | 4898 | |
| 4512 | | fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4899 | fn zirAs(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4513 | 4900 | const tracy = trace(@src()); |
| 4514 | 4901 | defer tracy.end(); |
| 4515 | 4902 | |
| ... | ... | @@ -4517,7 +4904,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Ai |
| 4517 | 4904 | return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs); |
| 4518 | 4905 | } |
| 4519 | 4906 | |
| 4520 | | fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4907 | fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4521 | 4908 | const tracy = trace(@src()); |
| 4522 | 4909 | defer tracy.end(); |
| 4523 | 4910 | |
| ... | ... | @@ -4529,7 +4916,7 @@ fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 4529 | 4916 | |
| 4530 | 4917 | fn analyzeAs( |
| 4531 | 4918 | sema: *Sema, |
| 4532 | | block: *Scope.Block, |
| 4919 | block: *Block, |
| 4533 | 4920 | src: LazySrcLoc, |
| 4534 | 4921 | zir_dest_type: Zir.Inst.Ref, |
| 4535 | 4922 | zir_operand: Zir.Inst.Ref, |
| ... | ... | @@ -4539,7 +4926,7 @@ fn analyzeAs( |
| 4539 | 4926 | return sema.coerce(block, dest_type, operand, src); |
| 4540 | 4927 | } |
| 4541 | 4928 | |
| 4542 | | fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4929 | fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4543 | 4930 | const tracy = trace(@src()); |
| 4544 | 4931 | defer tracy.end(); |
| 4545 | 4932 | |
| ... | ... | @@ -4548,7 +4935,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4548 | 4935 | const ptr_ty = sema.typeOf(ptr); |
| 4549 | 4936 | if (ptr_ty.zigTypeTag() != .Pointer) { |
| 4550 | 4937 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 4551 | | return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}); |
| 4938 | return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty}); |
| 4552 | 4939 | } |
| 4553 | 4940 | // TODO handle known-pointer-address |
| 4554 | 4941 | const src = inst_data.src(); |
| ... | ... | @@ -4556,7 +4943,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4556 | 4943 | return block.addUnOp(.ptrtoint, ptr); |
| 4557 | 4944 | } |
| 4558 | 4945 | |
| 4559 | | fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4946 | fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4560 | 4947 | const tracy = trace(@src()); |
| 4561 | 4948 | defer tracy.end(); |
| 4562 | 4949 | |
| ... | ... | @@ -4575,7 +4962,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4575 | 4962 | } |
| 4576 | 4963 | } |
| 4577 | 4964 | |
| 4578 | | fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4965 | fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4579 | 4966 | const tracy = trace(@src()); |
| 4580 | 4967 | defer tracy.end(); |
| 4581 | 4968 | |
| ... | ... | @@ -4588,7 +4975,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4588 | 4975 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src); |
| 4589 | 4976 | } |
| 4590 | 4977 | |
| 4591 | | fn zirFieldCallBind(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4978 | fn zirFieldCallBind(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4592 | 4979 | const tracy = trace(@src()); |
| 4593 | 4980 | defer tracy.end(); |
| 4594 | 4981 | |
| ... | ... | @@ -4601,7 +4988,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4601 | 4988 | return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src); |
| 4602 | 4989 | } |
| 4603 | 4990 | |
| 4604 | | fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4991 | fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4605 | 4992 | const tracy = trace(@src()); |
| 4606 | 4993 | defer tracy.end(); |
| 4607 | 4994 | |
| ... | ... | @@ -4614,7 +5001,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4614 | 5001 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 4615 | 5002 | } |
| 4616 | 5003 | |
| 4617 | | fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5004 | fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4618 | 5005 | const tracy = trace(@src()); |
| 4619 | 5006 | defer tracy.end(); |
| 4620 | 5007 | |
| ... | ... | @@ -4627,7 +5014,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4627 | 5014 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src); |
| 4628 | 5015 | } |
| 4629 | 5016 | |
| 4630 | | fn zirFieldCallBindNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5017 | fn zirFieldCallBindNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4631 | 5018 | const tracy = trace(@src()); |
| 4632 | 5019 | defer tracy.end(); |
| 4633 | 5020 | |
| ... | ... | @@ -4640,7 +5027,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 4640 | 5027 | return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src); |
| 4641 | 5028 | } |
| 4642 | 5029 | |
| 4643 | | fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5030 | fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4644 | 5031 | const tracy = trace(@src()); |
| 4645 | 5032 | defer tracy.end(); |
| 4646 | 5033 | |
| ... | ... | @@ -4659,14 +5046,14 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4659 | 5046 | if (try sema.isComptimeKnown(block, operand_src, operand)) { |
| 4660 | 5047 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4661 | 5048 | } else if (dest_is_comptime_int) { |
| 4662 | | return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_int'", .{}); |
| 5049 | return sema.fail(block, src, "unable to cast runtime value to 'comptime_int'", .{}); |
| 4663 | 5050 | } |
| 4664 | 5051 | |
| 4665 | 5052 | try sema.requireRuntimeBlock(block, operand_src); |
| 4666 | 5053 | return block.addTyOp(.intcast, dest_type, operand); |
| 4667 | 5054 | } |
| 4668 | 5055 | |
| 4669 | | fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5056 | fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4670 | 5057 | const tracy = trace(@src()); |
| 4671 | 5058 | defer tracy.end(); |
| 4672 | 5059 | |
| ... | ... | @@ -4680,7 +5067,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4680 | 5067 | return sema.bitcast(block, dest_type, operand, operand_src); |
| 4681 | 5068 | } |
| 4682 | 5069 | |
| 4683 | | fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5070 | fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4684 | 5071 | const tracy = trace(@src()); |
| 4685 | 5072 | defer tracy.end(); |
| 4686 | 5073 | |
| ... | ... | @@ -4696,8 +5083,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4696 | 5083 | const dest_is_comptime_float = switch (dest_type.zigTypeTag()) { |
| 4697 | 5084 | .ComptimeFloat => true, |
| 4698 | 5085 | .Float => false, |
| 4699 | | else => return sema.mod.fail( |
| 4700 | | &block.base, |
| 5086 | else => return sema.fail( |
| 5087 | block, |
| 4701 | 5088 | dest_ty_src, |
| 4702 | 5089 | "expected float type, found '{}'", |
| 4703 | 5090 | .{dest_type}, |
| ... | ... | @@ -4707,8 +5094,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4707 | 5094 | const operand_ty = sema.typeOf(operand); |
| 4708 | 5095 | switch (operand_ty.zigTypeTag()) { |
| 4709 | 5096 | .ComptimeFloat, .Float, .ComptimeInt => {}, |
| 4710 | | else => return sema.mod.fail( |
| 4711 | | &block.base, |
| 5097 | else => return sema.fail( |
| 5098 | block, |
| 4712 | 5099 | operand_src, |
| 4713 | 5100 | "expected float type, found '{}'", |
| 4714 | 5101 | .{operand_ty}, |
| ... | ... | @@ -4719,7 +5106,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4719 | 5106 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4720 | 5107 | } |
| 4721 | 5108 | if (dest_is_comptime_float) { |
| 4722 | | return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_float'", .{}); |
| 5109 | return sema.fail(block, src, "unable to cast runtime value to 'comptime_float'", .{}); |
| 4723 | 5110 | } |
| 4724 | 5111 | const target = sema.mod.getTarget(); |
| 4725 | 5112 | const src_bits = operand_ty.floatBits(target); |
| ... | ... | @@ -4731,7 +5118,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4731 | 5118 | return block.addTyOp(.fptrunc, dest_type, operand); |
| 4732 | 5119 | } |
| 4733 | 5120 | |
| 4734 | | fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5121 | fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4735 | 5122 | const tracy = trace(@src()); |
| 4736 | 5123 | defer tracy.end(); |
| 4737 | 5124 | |
| ... | ... | @@ -4741,7 +5128,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4741 | 5128 | return sema.elemVal(block, sema.src, array, elem_index, sema.src); |
| 4742 | 5129 | } |
| 4743 | 5130 | |
| 4744 | | fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5131 | fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4745 | 5132 | const tracy = trace(@src()); |
| 4746 | 5133 | defer tracy.end(); |
| 4747 | 5134 | |
| ... | ... | @@ -4754,7 +5141,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 4754 | 5141 | return sema.elemVal(block, src, array, elem_index, elem_index_src); |
| 4755 | 5142 | } |
| 4756 | 5143 | |
| 4757 | | fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5144 | fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4758 | 5145 | const tracy = trace(@src()); |
| 4759 | 5146 | defer tracy.end(); |
| 4760 | 5147 | |
| ... | ... | @@ -4764,7 +5151,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4764 | 5151 | return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src); |
| 4765 | 5152 | } |
| 4766 | 5153 | |
| 4767 | | fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5154 | fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4768 | 5155 | const tracy = trace(@src()); |
| 4769 | 5156 | defer tracy.end(); |
| 4770 | 5157 | |
| ... | ... | @@ -4777,7 +5164,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 4777 | 5164 | return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src); |
| 4778 | 5165 | } |
| 4779 | 5166 | |
| 4780 | | fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5167 | fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4781 | 5168 | const tracy = trace(@src()); |
| 4782 | 5169 | defer tracy.end(); |
| 4783 | 5170 | |
| ... | ... | @@ -4790,7 +5177,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 4790 | 5177 | return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded); |
| 4791 | 5178 | } |
| 4792 | 5179 | |
| 4793 | | fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5180 | fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4794 | 5181 | const tracy = trace(@src()); |
| 4795 | 5182 | defer tracy.end(); |
| 4796 | 5183 | |
| ... | ... | @@ -4804,7 +5191,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4804 | 5191 | return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded); |
| 4805 | 5192 | } |
| 4806 | 5193 | |
| 4807 | | fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5194 | fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4808 | 5195 | const tracy = trace(@src()); |
| 4809 | 5196 | defer tracy.end(); |
| 4810 | 5197 | |
| ... | ... | @@ -4822,7 +5209,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4822 | 5209 | |
| 4823 | 5210 | fn zirSwitchCapture( |
| 4824 | 5211 | sema: *Sema, |
| 4825 | | block: *Scope.Block, |
| 5212 | block: *Block, |
| 4826 | 5213 | inst: Zir.Inst.Index, |
| 4827 | 5214 | is_multi: bool, |
| 4828 | 5215 | is_ref: bool, |
| ... | ... | @@ -4837,12 +5224,12 @@ fn zirSwitchCapture( |
| 4837 | 5224 | |
| 4838 | 5225 | _ = is_ref; |
| 4839 | 5226 | _ = is_multi; |
| 4840 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCapture", .{}); |
| 5227 | return sema.fail(block, src, "TODO implement Sema for zirSwitchCapture", .{}); |
| 4841 | 5228 | } |
| 4842 | 5229 | |
| 4843 | 5230 | fn zirSwitchCaptureElse( |
| 4844 | 5231 | sema: *Sema, |
| 4845 | | block: *Scope.Block, |
| 5232 | block: *Block, |
| 4846 | 5233 | inst: Zir.Inst.Index, |
| 4847 | 5234 | is_ref: bool, |
| 4848 | 5235 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -4855,12 +5242,12 @@ fn zirSwitchCaptureElse( |
| 4855 | 5242 | const src = switch_info.src(); |
| 4856 | 5243 | |
| 4857 | 5244 | _ = is_ref; |
| 4858 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCaptureElse", .{}); |
| 5245 | return sema.fail(block, src, "TODO implement Sema for zirSwitchCaptureElse", .{}); |
| 4859 | 5246 | } |
| 4860 | 5247 | |
| 4861 | 5248 | fn zirSwitchBlock( |
| 4862 | 5249 | sema: *Sema, |
| 4863 | | block: *Scope.Block, |
| 5250 | block: *Block, |
| 4864 | 5251 | inst: Zir.Inst.Index, |
| 4865 | 5252 | is_ref: bool, |
| 4866 | 5253 | special_prong: Zir.SpecialProng, |
| ... | ... | @@ -4893,7 +5280,7 @@ fn zirSwitchBlock( |
| 4893 | 5280 | |
| 4894 | 5281 | fn zirSwitchBlockMulti( |
| 4895 | 5282 | sema: *Sema, |
| 4896 | | block: *Scope.Block, |
| 5283 | block: *Block, |
| 4897 | 5284 | inst: Zir.Inst.Index, |
| 4898 | 5285 | is_ref: bool, |
| 4899 | 5286 | special_prong: Zir.SpecialProng, |
| ... | ... | @@ -4926,7 +5313,7 @@ fn zirSwitchBlockMulti( |
| 4926 | 5313 | |
| 4927 | 5314 | fn analyzeSwitch( |
| 4928 | 5315 | sema: *Sema, |
| 4929 | | block: *Scope.Block, |
| 5316 | block: *Block, |
| 4930 | 5317 | operand: Air.Inst.Ref, |
| 4931 | 5318 | extra_end: usize, |
| 4932 | 5319 | special_prong: Zir.SpecialProng, |
| ... | ... | @@ -4936,7 +5323,6 @@ fn analyzeSwitch( |
| 4936 | 5323 | src_node_offset: i32, |
| 4937 | 5324 | ) CompileError!Air.Inst.Ref { |
| 4938 | 5325 | const gpa = sema.gpa; |
| 4939 | | const mod = sema.mod; |
| 4940 | 5326 | |
| 4941 | 5327 | const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) { |
| 4942 | 5328 | .none => .{ .body = &.{}, .end = extra_end }, |
| ... | ... | @@ -4958,15 +5344,15 @@ fn analyzeSwitch( |
| 4958 | 5344 | // Validate usage of '_' prongs. |
| 4959 | 5345 | if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) { |
| 4960 | 5346 | const msg = msg: { |
| 4961 | | const msg = try mod.errMsg( |
| 4962 | | &block.base, |
| 5347 | const msg = try sema.errMsg( |
| 5348 | block, |
| 4963 | 5349 | src, |
| 4964 | 5350 | "'_' prong only allowed when switching on non-exhaustive enums", |
| 4965 | 5351 | .{}, |
| 4966 | 5352 | ); |
| 4967 | 5353 | errdefer msg.destroy(gpa); |
| 4968 | | try mod.errNote( |
| 4969 | | &block.base, |
| 5354 | try sema.errNote( |
| 5355 | block, |
| 4970 | 5356 | special_prong_src, |
| 4971 | 5357 | msg, |
| 4972 | 5358 | "'_' prong here", |
| ... | ... | @@ -4974,7 +5360,7 @@ fn analyzeSwitch( |
| 4974 | 5360 | ); |
| 4975 | 5361 | break :msg msg; |
| 4976 | 5362 | }; |
| 4977 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5363 | return sema.failWithOwnedErrorMsg(msg); |
| 4978 | 5364 | } |
| 4979 | 5365 | |
| 4980 | 5366 | // Validate for duplicate items, missing else prong, and invalid range. |
| ... | ... | @@ -5037,8 +5423,8 @@ fn analyzeSwitch( |
| 5037 | 5423 | .none => { |
| 5038 | 5424 | if (!all_tags_handled) { |
| 5039 | 5425 | const msg = msg: { |
| 5040 | | const msg = try mod.errMsg( |
| 5041 | | &block.base, |
| 5426 | const msg = try sema.errMsg( |
| 5427 | block, |
| 5042 | 5428 | src, |
| 5043 | 5429 | "switch must handle all possibilities", |
| 5044 | 5430 | .{}, |
| ... | ... | @@ -5050,15 +5436,15 @@ fn analyzeSwitch( |
| 5050 | 5436 | const field_name = operand_ty.enumFieldName(i); |
| 5051 | 5437 | |
| 5052 | 5438 | // TODO have this point to the tag decl instead of here |
| 5053 | | try mod.errNote( |
| 5054 | | &block.base, |
| 5439 | try sema.errNote( |
| 5440 | block, |
| 5055 | 5441 | src, |
| 5056 | 5442 | msg, |
| 5057 | 5443 | "unhandled enumeration value: '{s}'", |
| 5058 | 5444 | .{field_name}, |
| 5059 | 5445 | ); |
| 5060 | 5446 | } |
| 5061 | | try mod.errNoteNonLazy( |
| 5447 | try sema.mod.errNoteNonLazy( |
| 5062 | 5448 | operand_ty.declSrcLoc(), |
| 5063 | 5449 | msg, |
| 5064 | 5450 | "enum '{}' declared here", |
| ... | ... | @@ -5066,20 +5452,20 @@ fn analyzeSwitch( |
| 5066 | 5452 | ); |
| 5067 | 5453 | break :msg msg; |
| 5068 | 5454 | }; |
| 5069 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5455 | return sema.failWithOwnedErrorMsg(msg); |
| 5070 | 5456 | } |
| 5071 | 5457 | }, |
| 5072 | 5458 | .under => { |
| 5073 | | if (all_tags_handled) return mod.fail( |
| 5074 | | &block.base, |
| 5459 | if (all_tags_handled) return sema.fail( |
| 5460 | block, |
| 5075 | 5461 | special_prong_src, |
| 5076 | 5462 | "unreachable '_' prong; all cases already handled", |
| 5077 | 5463 | .{}, |
| 5078 | 5464 | ); |
| 5079 | 5465 | }, |
| 5080 | 5466 | .@"else" => { |
| 5081 | | if (all_tags_handled) return mod.fail( |
| 5082 | | &block.base, |
| 5467 | if (all_tags_handled) return sema.fail( |
| 5468 | block, |
| 5083 | 5469 | special_prong_src, |
| 5084 | 5470 | "unreachable else prong; all cases already handled", |
| 5085 | 5471 | .{}, |
| ... | ... | @@ -5088,8 +5474,8 @@ fn analyzeSwitch( |
| 5088 | 5474 | } |
| 5089 | 5475 | }, |
| 5090 | 5476 | |
| 5091 | | .ErrorSet => return mod.fail(&block.base, src, "TODO validate switch .ErrorSet", .{}), |
| 5092 | | .Union => return mod.fail(&block.base, src, "TODO validate switch .Union", .{}), |
| 5477 | .ErrorSet => return sema.fail(block, src, "TODO validate switch .ErrorSet", .{}), |
| 5478 | .Union => return sema.fail(block, src, "TODO validate switch .Union", .{}), |
| 5093 | 5479 | .Int, .ComptimeInt => { |
| 5094 | 5480 | var range_set = RangeSet.init(gpa); |
| 5095 | 5481 | defer range_set.deinit(); |
| ... | ... | @@ -5164,12 +5550,13 @@ fn analyzeSwitch( |
| 5164 | 5550 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 5165 | 5551 | defer arena.deinit(); |
| 5166 | 5552 | |
| 5167 | | const min_int = try operand_ty.minInt(&arena.allocator, mod.getTarget()); |
| 5168 | | const max_int = try operand_ty.maxInt(&arena.allocator, mod.getTarget()); |
| 5553 | const target = sema.mod.getTarget(); |
| 5554 | const min_int = try operand_ty.minInt(&arena.allocator, target); |
| 5555 | const max_int = try operand_ty.maxInt(&arena.allocator, target); |
| 5169 | 5556 | if (try range_set.spans(min_int, max_int, operand_ty)) { |
| 5170 | 5557 | if (special_prong == .@"else") { |
| 5171 | | return mod.fail( |
| 5172 | | &block.base, |
| 5558 | return sema.fail( |
| 5559 | block, |
| 5173 | 5560 | special_prong_src, |
| 5174 | 5561 | "unreachable else prong; all cases already handled", |
| 5175 | 5562 | .{}, |
| ... | ... | @@ -5179,8 +5566,8 @@ fn analyzeSwitch( |
| 5179 | 5566 | } |
| 5180 | 5567 | } |
| 5181 | 5568 | if (special_prong != .@"else") { |
| 5182 | | return mod.fail( |
| 5183 | | &block.base, |
| 5569 | return sema.fail( |
| 5570 | block, |
| 5184 | 5571 | src, |
| 5185 | 5572 | "switch must handle all possibilities", |
| 5186 | 5573 | .{}, |
| ... | ... | @@ -5241,8 +5628,8 @@ fn analyzeSwitch( |
| 5241 | 5628 | switch (special_prong) { |
| 5242 | 5629 | .@"else" => { |
| 5243 | 5630 | if (true_count + false_count == 2) { |
| 5244 | | return mod.fail( |
| 5245 | | &block.base, |
| 5631 | return sema.fail( |
| 5632 | block, |
| 5246 | 5633 | src, |
| 5247 | 5634 | "unreachable else prong; all cases already handled", |
| 5248 | 5635 | .{}, |
| ... | ... | @@ -5251,8 +5638,8 @@ fn analyzeSwitch( |
| 5251 | 5638 | }, |
| 5252 | 5639 | .under, .none => { |
| 5253 | 5640 | if (true_count + false_count < 2) { |
| 5254 | | return mod.fail( |
| 5255 | | &block.base, |
| 5641 | return sema.fail( |
| 5642 | block, |
| 5256 | 5643 | src, |
| 5257 | 5644 | "switch must handle all possibilities", |
| 5258 | 5645 | .{}, |
| ... | ... | @@ -5263,8 +5650,8 @@ fn analyzeSwitch( |
| 5263 | 5650 | }, |
| 5264 | 5651 | .EnumLiteral, .Void, .Fn, .Pointer, .Type => { |
| 5265 | 5652 | if (special_prong != .@"else") { |
| 5266 | | return mod.fail( |
| 5267 | | &block.base, |
| 5653 | return sema.fail( |
| 5654 | block, |
| 5268 | 5655 | src, |
| 5269 | 5656 | "else prong required when switching on type '{}'", |
| 5270 | 5657 | .{operand_ty}, |
| ... | ... | @@ -5334,7 +5721,7 @@ fn analyzeSwitch( |
| 5334 | 5721 | .AnyFrame, |
| 5335 | 5722 | .ComptimeFloat, |
| 5336 | 5723 | .Float, |
| 5337 | | => return mod.fail(&block.base, operand_src, "invalid switch operand type '{}'", .{ |
| 5724 | => return sema.fail(block, operand_src, "invalid switch operand type '{}'", .{ |
| 5338 | 5725 | operand_ty, |
| 5339 | 5726 | }), |
| 5340 | 5727 | } |
| ... | ... | @@ -5344,7 +5731,7 @@ fn analyzeSwitch( |
| 5344 | 5731 | .tag = .block, |
| 5345 | 5732 | .data = undefined, |
| 5346 | 5733 | }); |
| 5347 | | var label: Scope.Block.Label = .{ |
| 5734 | var label: Block.Label = .{ |
| 5348 | 5735 | .zir_block = switch_inst, |
| 5349 | 5736 | .merges = .{ |
| 5350 | 5737 | .results = .{}, |
| ... | ... | @@ -5353,10 +5740,11 @@ fn analyzeSwitch( |
| 5353 | 5740 | }, |
| 5354 | 5741 | }; |
| 5355 | 5742 | |
| 5356 | | var child_block: Scope.Block = .{ |
| 5743 | var child_block: Block = .{ |
| 5357 | 5744 | .parent = block, |
| 5358 | 5745 | .sema = sema, |
| 5359 | 5746 | .src_decl = block.src_decl, |
| 5747 | .namespace = block.namespace, |
| 5360 | 5748 | .wip_capture_scope = block.wip_capture_scope, |
| 5361 | 5749 | .instructions = .{}, |
| 5362 | 5750 | .label = &label, |
| ... | ... | @@ -5663,7 +6051,7 @@ fn analyzeSwitch( |
| 5663 | 6051 | |
| 5664 | 6052 | fn resolveSwitchItemVal( |
| 5665 | 6053 | sema: *Sema, |
| 5666 | | block: *Scope.Block, |
| 6054 | block: *Block, |
| 5667 | 6055 | item_ref: Zir.Inst.Ref, |
| 5668 | 6056 | switch_node_offset: i32, |
| 5669 | 6057 | switch_prong_src: Module.SwitchProngSrc, |
| ... | ... | @@ -5690,7 +6078,7 @@ fn resolveSwitchItemVal( |
| 5690 | 6078 | |
| 5691 | 6079 | fn validateSwitchRange( |
| 5692 | 6080 | sema: *Sema, |
| 5693 | | block: *Scope.Block, |
| 6081 | block: *Block, |
| 5694 | 6082 | range_set: *RangeSet, |
| 5695 | 6083 | first_ref: Zir.Inst.Ref, |
| 5696 | 6084 | last_ref: Zir.Inst.Ref, |
| ... | ... | @@ -5706,7 +6094,7 @@ fn validateSwitchRange( |
| 5706 | 6094 | |
| 5707 | 6095 | fn validateSwitchItem( |
| 5708 | 6096 | sema: *Sema, |
| 5709 | | block: *Scope.Block, |
| 6097 | block: *Block, |
| 5710 | 6098 | range_set: *RangeSet, |
| 5711 | 6099 | item_ref: Zir.Inst.Ref, |
| 5712 | 6100 | operand_ty: Type, |
| ... | ... | @@ -5720,25 +6108,24 @@ fn validateSwitchItem( |
| 5720 | 6108 | |
| 5721 | 6109 | fn validateSwitchItemEnum( |
| 5722 | 6110 | sema: *Sema, |
| 5723 | | block: *Scope.Block, |
| 6111 | block: *Block, |
| 5724 | 6112 | seen_fields: []?Module.SwitchProngSrc, |
| 5725 | 6113 | item_ref: Zir.Inst.Ref, |
| 5726 | 6114 | src_node_offset: i32, |
| 5727 | 6115 | switch_prong_src: Module.SwitchProngSrc, |
| 5728 | 6116 | ) CompileError!void { |
| 5729 | | const mod = sema.mod; |
| 5730 | 6117 | const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); |
| 5731 | 6118 | const field_index = item_tv.ty.enumTagFieldIndex(item_tv.val) orelse { |
| 5732 | 6119 | const msg = msg: { |
| 5733 | 6120 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); |
| 5734 | | const msg = try mod.errMsg( |
| 5735 | | &block.base, |
| 6121 | const msg = try sema.errMsg( |
| 6122 | block, |
| 5736 | 6123 | src, |
| 5737 | 6124 | "enum '{}' has no tag with value '{}'", |
| 5738 | 6125 | .{ item_tv.ty, item_tv.val }, |
| 5739 | 6126 | ); |
| 5740 | 6127 | errdefer msg.destroy(sema.gpa); |
| 5741 | | try mod.errNoteNonLazy( |
| 6128 | try sema.mod.errNoteNonLazy( |
| 5742 | 6129 | item_tv.ty.declSrcLoc(), |
| 5743 | 6130 | msg, |
| 5744 | 6131 | "enum declared here", |
| ... | ... | @@ -5746,7 +6133,7 @@ fn validateSwitchItemEnum( |
| 5746 | 6133 | ); |
| 5747 | 6134 | break :msg msg; |
| 5748 | 6135 | }; |
| 5749 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 6136 | return sema.failWithOwnedErrorMsg(msg); |
| 5750 | 6137 | }; |
| 5751 | 6138 | const maybe_prev_src = seen_fields[field_index]; |
| 5752 | 6139 | seen_fields[field_index] = switch_prong_src; |
| ... | ... | @@ -5755,26 +6142,25 @@ fn validateSwitchItemEnum( |
| 5755 | 6142 | |
| 5756 | 6143 | fn validateSwitchDupe( |
| 5757 | 6144 | sema: *Sema, |
| 5758 | | block: *Scope.Block, |
| 6145 | block: *Block, |
| 5759 | 6146 | maybe_prev_src: ?Module.SwitchProngSrc, |
| 5760 | 6147 | switch_prong_src: Module.SwitchProngSrc, |
| 5761 | 6148 | src_node_offset: i32, |
| 5762 | 6149 | ) CompileError!void { |
| 5763 | 6150 | const prev_prong_src = maybe_prev_src orelse return; |
| 5764 | | const mod = sema.mod; |
| 5765 | 6151 | const gpa = sema.gpa; |
| 5766 | 6152 | const src = switch_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5767 | 6153 | const prev_src = prev_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5768 | 6154 | const msg = msg: { |
| 5769 | | const msg = try mod.errMsg( |
| 5770 | | &block.base, |
| 6155 | const msg = try sema.errMsg( |
| 6156 | block, |
| 5771 | 6157 | src, |
| 5772 | 6158 | "duplicate switch value", |
| 5773 | 6159 | .{}, |
| 5774 | 6160 | ); |
| 5775 | 6161 | errdefer msg.destroy(sema.gpa); |
| 5776 | | try mod.errNote( |
| 5777 | | &block.base, |
| 6162 | try sema.errNote( |
| 6163 | block, |
| 5778 | 6164 | prev_src, |
| 5779 | 6165 | msg, |
| 5780 | 6166 | "previous value here", |
| ... | ... | @@ -5782,12 +6168,12 @@ fn validateSwitchDupe( |
| 5782 | 6168 | ); |
| 5783 | 6169 | break :msg msg; |
| 5784 | 6170 | }; |
| 5785 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 6171 | return sema.failWithOwnedErrorMsg(msg); |
| 5786 | 6172 | } |
| 5787 | 6173 | |
| 5788 | 6174 | fn validateSwitchItemBool( |
| 5789 | 6175 | sema: *Sema, |
| 5790 | | block: *Scope.Block, |
| 6176 | block: *Block, |
| 5791 | 6177 | true_count: *u8, |
| 5792 | 6178 | false_count: *u8, |
| 5793 | 6179 | item_ref: Zir.Inst.Ref, |
| ... | ... | @@ -5802,7 +6188,7 @@ fn validateSwitchItemBool( |
| 5802 | 6188 | } |
| 5803 | 6189 | if (true_count.* + false_count.* > 2) { |
| 5804 | 6190 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); |
| 5805 | | return sema.mod.fail(&block.base, src, "duplicate switch value", .{}); |
| 6191 | return sema.fail(block, src, "duplicate switch value", .{}); |
| 5806 | 6192 | } |
| 5807 | 6193 | } |
| 5808 | 6194 | |
| ... | ... | @@ -5810,7 +6196,7 @@ const ValueSrcMap = std.HashMap(Value, Module.SwitchProngSrc, Value.HashContext, |
| 5810 | 6196 | |
| 5811 | 6197 | fn validateSwitchItemSparse( |
| 5812 | 6198 | sema: *Sema, |
| 5813 | | block: *Scope.Block, |
| 6199 | block: *Block, |
| 5814 | 6200 | seen_values: *ValueSrcMap, |
| 5815 | 6201 | item_ref: Zir.Inst.Ref, |
| 5816 | 6202 | src_node_offset: i32, |
| ... | ... | @@ -5823,7 +6209,7 @@ fn validateSwitchItemSparse( |
| 5823 | 6209 | |
| 5824 | 6210 | fn validateSwitchNoRange( |
| 5825 | 6211 | sema: *Sema, |
| 5826 | | block: *Scope.Block, |
| 6212 | block: *Block, |
| 5827 | 6213 | ranges_len: u32, |
| 5828 | 6214 | operand_ty: Type, |
| 5829 | 6215 | src_node_offset: i32, |
| ... | ... | @@ -5835,15 +6221,15 @@ fn validateSwitchNoRange( |
| 5835 | 6221 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; |
| 5836 | 6222 | |
| 5837 | 6223 | const msg = msg: { |
| 5838 | | const msg = try sema.mod.errMsg( |
| 5839 | | &block.base, |
| 6224 | const msg = try sema.errMsg( |
| 6225 | block, |
| 5840 | 6226 | operand_src, |
| 5841 | 6227 | "ranges not allowed when switching on type '{}'", |
| 5842 | 6228 | .{operand_ty}, |
| 5843 | 6229 | ); |
| 5844 | 6230 | errdefer msg.destroy(sema.gpa); |
| 5845 | | try sema.mod.errNote( |
| 5846 | | &block.base, |
| 6231 | try sema.errNote( |
| 6232 | block, |
| 5847 | 6233 | range_src, |
| 5848 | 6234 | msg, |
| 5849 | 6235 | "range here", |
| ... | ... | @@ -5851,19 +6237,19 @@ fn validateSwitchNoRange( |
| 5851 | 6237 | ); |
| 5852 | 6238 | break :msg msg; |
| 5853 | 6239 | }; |
| 5854 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 6240 | return sema.failWithOwnedErrorMsg(msg); |
| 5855 | 6241 | } |
| 5856 | 6242 | |
| 5857 | | fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6243 | fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5858 | 6244 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5859 | 6245 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5860 | 6246 | _ = extra; |
| 5861 | 6247 | const src = inst_data.src(); |
| 5862 | 6248 | |
| 5863 | | return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{}); |
| 6249 | return sema.fail(block, src, "TODO implement zirHasField", .{}); |
| 5864 | 6250 | } |
| 5865 | 6251 | |
| 5866 | | fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6252 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5867 | 6253 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5868 | 6254 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5869 | 6255 | const src = inst_data.src(); |
| ... | ... | @@ -5871,23 +6257,22 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 5871 | 6257 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 5872 | 6258 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 5873 | 6259 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs); |
| 5874 | | const mod = sema.mod; |
| 5875 | 6260 | |
| 5876 | | const namespace = container_type.getNamespace() orelse return mod.fail( |
| 5877 | | &block.base, |
| 6261 | const namespace = container_type.getNamespace() orelse return sema.fail( |
| 6262 | block, |
| 5878 | 6263 | lhs_src, |
| 5879 | 6264 | "expected struct, enum, union, or opaque, found '{}'", |
| 5880 | 6265 | .{container_type}, |
| 5881 | 6266 | ); |
| 5882 | 6267 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { |
| 5883 | | if (decl.is_pub or decl.namespace.file_scope == block.base.namespace().file_scope) { |
| 6268 | if (decl.is_pub or decl.getFileScope() == block.getFileScope()) { |
| 5884 | 6269 | return Air.Inst.Ref.bool_true; |
| 5885 | 6270 | } |
| 5886 | 6271 | } |
| 5887 | 6272 | return Air.Inst.Ref.bool_false; |
| 5888 | 6273 | } |
| 5889 | 6274 | |
| 5890 | | fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6275 | fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5891 | 6276 | const tracy = trace(@src()); |
| 5892 | 6277 | defer tracy.end(); |
| 5893 | 6278 | |
| ... | ... | @@ -5898,29 +6283,29 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 5898 | 6283 | |
| 5899 | 6284 | const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) { |
| 5900 | 6285 | error.ImportOutsidePkgPath => { |
| 5901 | | return mod.fail(&block.base, src, "import of file outside package path: '{s}'", .{operand}); |
| 6286 | return sema.fail(block, src, "import of file outside package path: '{s}'", .{operand}); |
| 5902 | 6287 | }, |
| 5903 | 6288 | else => { |
| 5904 | 6289 | // TODO: these errors are file system errors; make sure an update() will |
| 5905 | 6290 | // retry this and not cache the file system error, which may be transient. |
| 5906 | | return mod.fail(&block.base, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); |
| 6291 | return sema.fail(block, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); |
| 5907 | 6292 | }, |
| 5908 | 6293 | }; |
| 5909 | 6294 | try mod.semaFile(result.file); |
| 5910 | 6295 | const file_root_decl = result.file.root_decl.?; |
| 5911 | | try sema.mod.declareDeclDependency(sema.owner_decl, file_root_decl); |
| 6296 | try mod.declareDeclDependency(sema.owner_decl, file_root_decl); |
| 5912 | 6297 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); |
| 5913 | 6298 | } |
| 5914 | 6299 | |
| 5915 | | fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6300 | fn zirRetErrValueCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5916 | 6301 | _ = block; |
| 5917 | 6302 | _ = inst; |
| 5918 | | return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{}); |
| 6303 | return sema.fail(block, sema.src, "TODO implement zirRetErrValueCode", .{}); |
| 5919 | 6304 | } |
| 5920 | 6305 | |
| 5921 | 6306 | fn zirShl( |
| 5922 | 6307 | sema: *Sema, |
| 5923 | | block: *Scope.Block, |
| 6308 | block: *Block, |
| 5924 | 6309 | inst: Zir.Inst.Index, |
| 5925 | 6310 | air_tag: Air.Inst.Tag, |
| 5926 | 6311 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -5952,8 +6337,8 @@ fn zirShl( |
| 5952 | 6337 | } |
| 5953 | 6338 | const val = try lhs_val.shl(rhs_val, sema.arena); |
| 5954 | 6339 | switch (air_tag) { |
| 5955 | | .shl_exact => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_exact", .{}), |
| 5956 | | .shl_sat => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_sat", .{}), |
| 6340 | .shl_exact => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_exact", .{}), |
| 6341 | .shl_sat => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_sat", .{}), |
| 5957 | 6342 | .shl => {}, |
| 5958 | 6343 | else => unreachable, |
| 5959 | 6344 | } |
| ... | ... | @@ -5971,7 +6356,7 @@ fn zirShl( |
| 5971 | 6356 | return block.addBinOp(air_tag, lhs, rhs); |
| 5972 | 6357 | } |
| 5973 | 6358 | |
| 5974 | | fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6359 | fn zirShr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5975 | 6360 | const tracy = trace(@src()); |
| 5976 | 6361 | defer tracy.end(); |
| 5977 | 6362 | |
| ... | ... | @@ -6004,7 +6389,7 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 6004 | 6389 | |
| 6005 | 6390 | fn zirBitwise( |
| 6006 | 6391 | sema: *Sema, |
| 6007 | | block: *Scope.Block, |
| 6392 | block: *Block, |
| 6008 | 6393 | inst: Zir.Inst.Index, |
| 6009 | 6394 | air_tag: Air.Inst.Tag, |
| 6010 | 6395 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -6035,14 +6420,14 @@ fn zirBitwise( |
| 6035 | 6420 | |
| 6036 | 6421 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { |
| 6037 | 6422 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { |
| 6038 | | return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{ |
| 6423 | return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{ |
| 6039 | 6424 | lhs_ty.arrayLen(), |
| 6040 | 6425 | rhs_ty.arrayLen(), |
| 6041 | 6426 | }); |
| 6042 | 6427 | } |
| 6043 | | return sema.mod.fail(&block.base, src, "TODO implement support for vectors in zirBitwise", .{}); |
| 6428 | return sema.fail(block, src, "TODO implement support for vectors in zirBitwise", .{}); |
| 6044 | 6429 | } else if (lhs_ty.zigTypeTag() == .Vector or rhs_ty.zigTypeTag() == .Vector) { |
| 6045 | | return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6430 | return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6046 | 6431 | lhs_ty, |
| 6047 | 6432 | rhs_ty, |
| 6048 | 6433 | }); |
| ... | ... | @@ -6051,7 +6436,7 @@ fn zirBitwise( |
| 6051 | 6436 | const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt; |
| 6052 | 6437 | |
| 6053 | 6438 | if (!is_int) { |
| 6054 | | return sema.mod.fail(&block.base, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) }); |
| 6439 | return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) }); |
| 6055 | 6440 | } |
| 6056 | 6441 | |
| 6057 | 6442 | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { |
| ... | ... | @@ -6070,15 +6455,15 @@ fn zirBitwise( |
| 6070 | 6455 | return block.addBinOp(air_tag, casted_lhs, casted_rhs); |
| 6071 | 6456 | } |
| 6072 | 6457 | |
| 6073 | | fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6458 | fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6074 | 6459 | const tracy = trace(@src()); |
| 6075 | 6460 | defer tracy.end(); |
| 6076 | 6461 | |
| 6077 | 6462 | _ = inst; |
| 6078 | | return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{}); |
| 6463 | return sema.fail(block, sema.src, "TODO implement zirBitNot", .{}); |
| 6079 | 6464 | } |
| 6080 | 6465 | |
| 6081 | | fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6466 | fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6082 | 6467 | const tracy = trace(@src()); |
| 6083 | 6468 | defer tracy.end(); |
| 6084 | 6469 | |
| ... | ... | @@ -6092,11 +6477,11 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6092 | 6477 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 6093 | 6478 | |
| 6094 | 6479 | const lhs_info = getArrayCatInfo(lhs_ty) orelse |
| 6095 | | return sema.mod.fail(&block.base, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6480 | return sema.fail(block, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6096 | 6481 | const rhs_info = getArrayCatInfo(rhs_ty) orelse |
| 6097 | | return sema.mod.fail(&block.base, rhs_src, "expected array, found '{}'", .{rhs_ty}); |
| 6482 | return sema.fail(block, rhs_src, "expected array, found '{}'", .{rhs_ty}); |
| 6098 | 6483 | if (!lhs_info.elem_type.eql(rhs_info.elem_type)) { |
| 6099 | | return sema.mod.fail(&block.base, rhs_src, "expected array of type '{}', found '{}'", .{ lhs_info.elem_type, rhs_ty }); |
| 6484 | return sema.fail(block, rhs_src, "expected array of type '{}', found '{}'", .{ lhs_info.elem_type, rhs_ty }); |
| 6100 | 6485 | } |
| 6101 | 6486 | |
| 6102 | 6487 | // When there is a sentinel mismatch, no sentinel on the result. The type system |
| ... | ... | @@ -6142,10 +6527,10 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6142 | 6527 | else |
| 6143 | 6528 | sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(ty, val)); |
| 6144 | 6529 | } else { |
| 6145 | | return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_cat", .{}); |
| 6530 | return sema.fail(block, lhs_src, "TODO runtime array_cat", .{}); |
| 6146 | 6531 | } |
| 6147 | 6532 | } else { |
| 6148 | | return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_cat", .{}); |
| 6533 | return sema.fail(block, lhs_src, "TODO runtime array_cat", .{}); |
| 6149 | 6534 | } |
| 6150 | 6535 | } |
| 6151 | 6536 | |
| ... | ... | @@ -6162,7 +6547,7 @@ fn getArrayCatInfo(t: Type) ?Type.ArrayInfo { |
| 6162 | 6547 | }; |
| 6163 | 6548 | } |
| 6164 | 6549 | |
| 6165 | | fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6550 | fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6166 | 6551 | const tracy = trace(@src()); |
| 6167 | 6552 | defer tracy.end(); |
| 6168 | 6553 | |
| ... | ... | @@ -6176,9 +6561,9 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6176 | 6561 | // In `**` rhs has to be comptime-known, but lhs can be runtime-known |
| 6177 | 6562 | const tomulby = try sema.resolveInt(block, rhs_src, extra.rhs, Type.initTag(.usize)); |
| 6178 | 6563 | const mulinfo = getArrayCatInfo(lhs_ty) orelse |
| 6179 | | return sema.mod.fail(&block.base, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6564 | return sema.fail(block, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6180 | 6565 | |
| 6181 | | const final_len = std.math.mul(u64, mulinfo.len, tomulby) catch return sema.mod.fail(&block.base, rhs_src, "operation results in overflow", .{}); |
| 6566 | const final_len = std.math.mul(u64, mulinfo.len, tomulby) catch return sema.fail(block, rhs_src, "operation results in overflow", .{}); |
| 6182 | 6567 | if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| { |
| 6183 | 6568 | var anon_decl = try block.startAnonDecl(); |
| 6184 | 6569 | defer anon_decl.deinit(); |
| ... | ... | @@ -6211,12 +6596,12 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6211 | 6596 | return sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(final_ty, val)); |
| 6212 | 6597 | } |
| 6213 | 6598 | } |
| 6214 | | return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_mul", .{}); |
| 6599 | return sema.fail(block, lhs_src, "TODO runtime array_mul", .{}); |
| 6215 | 6600 | } |
| 6216 | 6601 | |
| 6217 | 6602 | fn zirNegate( |
| 6218 | 6603 | sema: *Sema, |
| 6219 | | block: *Scope.Block, |
| 6604 | block: *Block, |
| 6220 | 6605 | inst: Zir.Inst.Index, |
| 6221 | 6606 | tag_override: Zir.Inst.Tag, |
| 6222 | 6607 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -6235,7 +6620,7 @@ fn zirNegate( |
| 6235 | 6620 | |
| 6236 | 6621 | fn zirArithmetic( |
| 6237 | 6622 | sema: *Sema, |
| 6238 | | block: *Scope.Block, |
| 6623 | block: *Block, |
| 6239 | 6624 | inst: Zir.Inst.Index, |
| 6240 | 6625 | zir_tag: Zir.Inst.Tag, |
| 6241 | 6626 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -6255,7 +6640,7 @@ fn zirArithmetic( |
| 6255 | 6640 | |
| 6256 | 6641 | fn zirOverflowArithmetic( |
| 6257 | 6642 | sema: *Sema, |
| 6258 | | block: *Scope.Block, |
| 6643 | block: *Block, |
| 6259 | 6644 | extended: Zir.Inst.Extended.InstData, |
| 6260 | 6645 | ) CompileError!Air.Inst.Ref { |
| 6261 | 6646 | const tracy = trace(@src()); |
| ... | ... | @@ -6264,12 +6649,12 @@ fn zirOverflowArithmetic( |
| 6264 | 6649 | const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data; |
| 6265 | 6650 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6266 | 6651 | |
| 6267 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirOverflowArithmetic", .{}); |
| 6652 | return sema.fail(block, src, "TODO implement Sema.zirOverflowArithmetic", .{}); |
| 6268 | 6653 | } |
| 6269 | 6654 | |
| 6270 | 6655 | fn analyzeArithmetic( |
| 6271 | 6656 | sema: *Sema, |
| 6272 | | block: *Scope.Block, |
| 6657 | block: *Block, |
| 6273 | 6658 | /// TODO performance investigation: make this comptime? |
| 6274 | 6659 | zir_tag: Zir.Inst.Tag, |
| 6275 | 6660 | lhs: Air.Inst.Ref, |
| ... | ... | @@ -6284,13 +6669,13 @@ fn analyzeArithmetic( |
| 6284 | 6669 | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(); |
| 6285 | 6670 | if (lhs_zig_ty_tag == .Vector and rhs_zig_ty_tag == .Vector) { |
| 6286 | 6671 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { |
| 6287 | | return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{ |
| 6672 | return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{ |
| 6288 | 6673 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), |
| 6289 | 6674 | }); |
| 6290 | 6675 | } |
| 6291 | | return sema.mod.fail(&block.base, src, "TODO implement support for vectors in Sema.analyzeArithmetic", .{}); |
| 6676 | return sema.fail(block, src, "TODO implement support for vectors in Sema.analyzeArithmetic", .{}); |
| 6292 | 6677 | } else if (lhs_zig_ty_tag == .Vector or rhs_zig_ty_tag == .Vector) { |
| 6293 | | return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6678 | return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6294 | 6679 | lhs_ty, rhs_ty, |
| 6295 | 6680 | }); |
| 6296 | 6681 | } |
| ... | ... | @@ -6302,8 +6687,8 @@ fn analyzeArithmetic( |
| 6302 | 6687 | const air_tag: Air.Inst.Tag = switch (zir_tag) { |
| 6303 | 6688 | .add => .ptr_add, |
| 6304 | 6689 | .sub => .ptr_sub, |
| 6305 | | else => return sema.mod.fail( |
| 6306 | | &block.base, |
| 6690 | else => return sema.fail( |
| 6691 | block, |
| 6307 | 6692 | op_src, |
| 6308 | 6693 | "invalid pointer arithmetic operand: '{s}''", |
| 6309 | 6694 | .{@tagName(zir_tag)}, |
| ... | ... | @@ -6317,7 +6702,7 @@ fn analyzeArithmetic( |
| 6317 | 6702 | if (try sema.resolveDefinedValue(block, rhs_src, casted_rhs)) |rhs_val| { |
| 6318 | 6703 | _ = lhs_val; |
| 6319 | 6704 | _ = rhs_val; |
| 6320 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for comptime pointer arithmetic", .{}); |
| 6705 | return sema.fail(block, src, "TODO implement Sema for comptime pointer arithmetic", .{}); |
| 6321 | 6706 | } else { |
| 6322 | 6707 | break :runtime_src rhs_src; |
| 6323 | 6708 | } |
| ... | ... | @@ -6348,7 +6733,7 @@ fn analyzeArithmetic( |
| 6348 | 6733 | const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat; |
| 6349 | 6734 | |
| 6350 | 6735 | if (!is_int and !(is_float and floatOpAllowed(zir_tag))) { |
| 6351 | | return sema.mod.fail(&block.base, src, "invalid operands to binary expression: '{s}' and '{s}'", .{ |
| 6736 | return sema.fail(block, src, "invalid operands to binary expression: '{s}' and '{s}'", .{ |
| 6352 | 6737 | @tagName(lhs_zig_ty_tag), @tagName(rhs_zig_ty_tag), |
| 6353 | 6738 | }); |
| 6354 | 6739 | } |
| ... | ... | @@ -6930,7 +7315,7 @@ fn analyzeArithmetic( |
| 6930 | 7315 | return block.addBinOp(rs.air_tag, casted_lhs, casted_rhs); |
| 6931 | 7316 | } |
| 6932 | 7317 | |
| 6933 | | fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7318 | fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6934 | 7319 | const tracy = trace(@src()); |
| 6935 | 7320 | defer tracy.end(); |
| 6936 | 7321 | |
| ... | ... | @@ -6943,7 +7328,7 @@ fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError! |
| 6943 | 7328 | |
| 6944 | 7329 | fn zirAsm( |
| 6945 | 7330 | sema: *Sema, |
| 6946 | | block: *Scope.Block, |
| 7331 | block: *Block, |
| 6947 | 7332 | extended: Zir.Inst.Extended.InstData, |
| 6948 | 7333 | inst: Zir.Inst.Index, |
| 6949 | 7334 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -6958,7 +7343,7 @@ fn zirAsm( |
| 6958 | 7343 | const clobbers_len = @truncate(u5, extended.small >> 10); |
| 6959 | 7344 | |
| 6960 | 7345 | if (outputs_len > 1) { |
| 6961 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for asm with more than 1 output", .{}); |
| 7346 | return sema.fail(block, src, "TODO implement Sema for asm with more than 1 output", .{}); |
| 6962 | 7347 | } |
| 6963 | 7348 | |
| 6964 | 7349 | var extra_i = extra.end; |
| ... | ... | @@ -6973,7 +7358,7 @@ fn zirAsm( |
| 6973 | 7358 | output_type_bits >>= 1; |
| 6974 | 7359 | |
| 6975 | 7360 | if (!is_type) { |
| 6976 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for asm with non `->` output", .{}); |
| 7361 | return sema.fail(block, src, "TODO implement Sema for asm with non `->` output", .{}); |
| 6977 | 7362 | } |
| 6978 | 7363 | |
| 6979 | 7364 | const constraint = sema.code.nullTerminatedString(output.data.constraint); |
| ... | ... | @@ -7022,7 +7407,7 @@ fn zirAsm( |
| 7022 | 7407 | /// Only called for equality operators. See also `zirCmp`. |
| 7023 | 7408 | fn zirCmpEq( |
| 7024 | 7409 | sema: *Sema, |
| 7025 | | block: *Scope.Block, |
| 7410 | block: *Block, |
| 7026 | 7411 | inst: Zir.Inst.Index, |
| 7027 | 7412 | op: std.math.CompareOperator, |
| 7028 | 7413 | air_tag: Air.Inst.Tag, |
| ... | ... | @@ -7030,7 +7415,6 @@ fn zirCmpEq( |
| 7030 | 7415 | const tracy = trace(@src()); |
| 7031 | 7416 | defer tracy.end(); |
| 7032 | 7417 | |
| 7033 | | const mod = sema.mod; |
| 7034 | 7418 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 7035 | 7419 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 7036 | 7420 | const src: LazySrcLoc = inst_data.src(); |
| ... | ... | @@ -7059,11 +7443,11 @@ fn zirCmpEq( |
| 7059 | 7443 | return sema.analyzeIsNull(block, src, opt_operand, op == .neq); |
| 7060 | 7444 | } |
| 7061 | 7445 | if (((lhs_ty_tag == .Null and rhs_ty.isCPtr()) or (rhs_ty_tag == .Null and lhs_ty.isCPtr()))) { |
| 7062 | | return mod.fail(&block.base, src, "TODO implement C pointer cmp", .{}); |
| 7446 | return sema.fail(block, src, "TODO implement C pointer cmp", .{}); |
| 7063 | 7447 | } |
| 7064 | 7448 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { |
| 7065 | 7449 | const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty; |
| 7066 | | return mod.fail(&block.base, src, "comparison of '{}' with null", .{non_null_type}); |
| 7450 | return sema.fail(block, src, "comparison of '{}' with null", .{non_null_type}); |
| 7067 | 7451 | } |
| 7068 | 7452 | if (lhs_ty_tag == .EnumLiteral and rhs_ty_tag == .Union) { |
| 7069 | 7453 | return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op); |
| ... | ... | @@ -7112,7 +7496,7 @@ fn zirCmpEq( |
| 7112 | 7496 | |
| 7113 | 7497 | fn analyzeCmpUnionTag( |
| 7114 | 7498 | sema: *Sema, |
| 7115 | | block: *Scope.Block, |
| 7499 | block: *Block, |
| 7116 | 7500 | un: Air.Inst.Ref, |
| 7117 | 7501 | un_src: LazySrcLoc, |
| 7118 | 7502 | tag: Air.Inst.Ref, |
| ... | ... | @@ -7122,7 +7506,7 @@ fn analyzeCmpUnionTag( |
| 7122 | 7506 | const union_ty = sema.typeOf(un); |
| 7123 | 7507 | const union_tag_ty = union_ty.unionTagType() orelse { |
| 7124 | 7508 | // TODO note at declaration site that says "union foo is not tagged" |
| 7125 | | return sema.mod.fail(&block.base, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| 7509 | return sema.fail(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| 7126 | 7510 | }; |
| 7127 | 7511 | // Coerce both the union and the tag to the union's tag type, and then execute the |
| 7128 | 7512 | // enum comparison codepath. |
| ... | ... | @@ -7135,7 +7519,7 @@ fn analyzeCmpUnionTag( |
| 7135 | 7519 | /// Only called for non-equality operators. See also `zirCmpEq`. |
| 7136 | 7520 | fn zirCmp( |
| 7137 | 7521 | sema: *Sema, |
| 7138 | | block: *Scope.Block, |
| 7522 | block: *Block, |
| 7139 | 7523 | inst: Zir.Inst.Index, |
| 7140 | 7524 | op: std.math.CompareOperator, |
| 7141 | 7525 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -7154,7 +7538,7 @@ fn zirCmp( |
| 7154 | 7538 | |
| 7155 | 7539 | fn analyzeCmp( |
| 7156 | 7540 | sema: *Sema, |
| 7157 | | block: *Scope.Block, |
| 7541 | block: *Block, |
| 7158 | 7542 | src: LazySrcLoc, |
| 7159 | 7543 | lhs: Air.Inst.Ref, |
| 7160 | 7544 | rhs: Air.Inst.Ref, |
| ... | ... | @@ -7174,7 +7558,7 @@ fn analyzeCmp( |
| 7174 | 7558 | const instructions = &[_]Air.Inst.Ref{ lhs, rhs }; |
| 7175 | 7559 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]LazySrcLoc{ lhs_src, rhs_src } }); |
| 7176 | 7560 | if (!resolved_type.isSelfComparable(is_equality_cmp)) { |
| 7177 | | return sema.mod.fail(&block.base, src, "{s} operator not allowed for type '{}'", .{ |
| 7561 | return sema.fail(block, src, "{s} operator not allowed for type '{}'", .{ |
| 7178 | 7562 | @tagName(op), resolved_type, |
| 7179 | 7563 | }); |
| 7180 | 7564 | } |
| ... | ... | @@ -7185,7 +7569,7 @@ fn analyzeCmp( |
| 7185 | 7569 | |
| 7186 | 7570 | fn cmpSelf( |
| 7187 | 7571 | sema: *Sema, |
| 7188 | | block: *Scope.Block, |
| 7572 | block: *Block, |
| 7189 | 7573 | casted_lhs: Air.Inst.Ref, |
| 7190 | 7574 | casted_rhs: Air.Inst.Ref, |
| 7191 | 7575 | op: std.math.CompareOperator, |
| ... | ... | @@ -7243,7 +7627,7 @@ fn cmpSelf( |
| 7243 | 7627 | /// cmp_neq(x, true ) => not(x) |
| 7244 | 7628 | fn runtimeBoolCmp( |
| 7245 | 7629 | sema: *Sema, |
| 7246 | | block: *Scope.Block, |
| 7630 | block: *Block, |
| 7247 | 7631 | op: std.math.CompareOperator, |
| 7248 | 7632 | lhs: Air.Inst.Ref, |
| 7249 | 7633 | rhs: bool, |
| ... | ... | @@ -7257,7 +7641,7 @@ fn runtimeBoolCmp( |
| 7257 | 7641 | } |
| 7258 | 7642 | } |
| 7259 | 7643 | |
| 7260 | | fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7644 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7261 | 7645 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7262 | 7646 | const src = inst_data.src(); |
| 7263 | 7647 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -7271,7 +7655,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7271 | 7655 | .Null, |
| 7272 | 7656 | .BoundFn, |
| 7273 | 7657 | .Opaque, |
| 7274 | | => return sema.mod.fail(&block.base, src, "no size available for type '{}'", .{operand_ty}), |
| 7658 | => return sema.fail(block, src, "no size available for type '{}'", .{operand_ty}), |
| 7275 | 7659 | .Type, |
| 7276 | 7660 | .EnumLiteral, |
| 7277 | 7661 | .ComptimeFloat, |
| ... | ... | @@ -7298,7 +7682,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7298 | 7682 | return sema.addIntUnsigned(Type.initTag(.comptime_int), abi_size); |
| 7299 | 7683 | } |
| 7300 | 7684 | |
| 7301 | | fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7685 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7302 | 7686 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7303 | 7687 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 7304 | 7688 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| ... | ... | @@ -7309,17 +7693,17 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 7309 | 7693 | |
| 7310 | 7694 | fn zirThis( |
| 7311 | 7695 | sema: *Sema, |
| 7312 | | block: *Scope.Block, |
| 7696 | block: *Block, |
| 7313 | 7697 | extended: Zir.Inst.Extended.InstData, |
| 7314 | 7698 | ) CompileError!Air.Inst.Ref { |
| 7315 | | const this_decl = block.base.namespace().getDecl(); |
| 7699 | const this_decl = block.namespace.getDecl(); |
| 7316 | 7700 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 7317 | 7701 | return sema.analyzeDeclVal(block, src, this_decl); |
| 7318 | 7702 | } |
| 7319 | 7703 | |
| 7320 | 7704 | fn zirClosureCapture( |
| 7321 | 7705 | sema: *Sema, |
| 7322 | | block: *Scope.Block, |
| 7706 | block: *Block, |
| 7323 | 7707 | inst: Zir.Inst.Index, |
| 7324 | 7708 | ) CompileError!void { |
| 7325 | 7709 | // TODO: Compile error when closed over values are modified |
| ... | ... | @@ -7333,7 +7717,7 @@ fn zirClosureCapture( |
| 7333 | 7717 | |
| 7334 | 7718 | fn zirClosureGet( |
| 7335 | 7719 | sema: *Sema, |
| 7336 | | block: *Scope.Block, |
| 7720 | block: *Block, |
| 7337 | 7721 | inst: Zir.Inst.Index, |
| 7338 | 7722 | ) CompileError!Air.Inst.Ref { |
| 7339 | 7723 | // TODO CLOSURE: Test this with inline functions |
| ... | ... | @@ -7355,23 +7739,23 @@ fn zirClosureGet( |
| 7355 | 7739 | |
| 7356 | 7740 | fn zirRetAddr( |
| 7357 | 7741 | sema: *Sema, |
| 7358 | | block: *Scope.Block, |
| 7742 | block: *Block, |
| 7359 | 7743 | extended: Zir.Inst.Extended.InstData, |
| 7360 | 7744 | ) CompileError!Air.Inst.Ref { |
| 7361 | 7745 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 7362 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{}); |
| 7746 | return sema.fail(block, src, "TODO: implement Sema.zirRetAddr", .{}); |
| 7363 | 7747 | } |
| 7364 | 7748 | |
| 7365 | 7749 | fn zirBuiltinSrc( |
| 7366 | 7750 | sema: *Sema, |
| 7367 | | block: *Scope.Block, |
| 7751 | block: *Block, |
| 7368 | 7752 | extended: Zir.Inst.Extended.InstData, |
| 7369 | 7753 | ) CompileError!Air.Inst.Ref { |
| 7370 | 7754 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 7371 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{}); |
| 7755 | return sema.fail(block, src, "TODO: implement Sema.zirBuiltinSrc", .{}); |
| 7372 | 7756 | } |
| 7373 | 7757 | |
| 7374 | | fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7758 | fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7375 | 7759 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7376 | 7760 | const src = inst_data.src(); |
| 7377 | 7761 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| ... | ... | @@ -7570,13 +7954,13 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 7570 | 7954 | }), |
| 7571 | 7955 | ); |
| 7572 | 7956 | }, |
| 7573 | | else => |t| return sema.mod.fail(&block.base, src, "TODO: implement zirTypeInfo for {s}", .{ |
| 7957 | else => |t| return sema.fail(block, src, "TODO: implement zirTypeInfo for {s}", .{ |
| 7574 | 7958 | @tagName(t), |
| 7575 | 7959 | }), |
| 7576 | 7960 | } |
| 7577 | 7961 | } |
| 7578 | 7962 | |
| 7579 | | fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7963 | fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7580 | 7964 | _ = block; |
| 7581 | 7965 | const zir_datas = sema.code.instructions.items(.data); |
| 7582 | 7966 | const inst_data = zir_datas[inst].un_node; |
| ... | ... | @@ -7585,7 +7969,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7585 | 7969 | return sema.addType(operand_ty); |
| 7586 | 7970 | } |
| 7587 | 7971 | |
| 7588 | | fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7972 | fn zirTypeofElem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7589 | 7973 | _ = block; |
| 7590 | 7974 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7591 | 7975 | const operand_ptr = sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -7593,7 +7977,7 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 7593 | 7977 | return sema.addType(elem_ty); |
| 7594 | 7978 | } |
| 7595 | 7979 | |
| 7596 | | fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7980 | fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7597 | 7981 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7598 | 7982 | const src = inst_data.src(); |
| 7599 | 7983 | const operand = sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -7601,14 +7985,14 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 7601 | 7985 | return sema.log2IntType(block, operand_ty, src); |
| 7602 | 7986 | } |
| 7603 | 7987 | |
| 7604 | | fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7988 | fn zirLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7605 | 7989 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7606 | 7990 | const src = inst_data.src(); |
| 7607 | 7991 | const operand = try sema.resolveType(block, src, inst_data.operand); |
| 7608 | 7992 | return sema.log2IntType(block, operand, src); |
| 7609 | 7993 | } |
| 7610 | 7994 | |
| 7611 | | fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) CompileError!Air.Inst.Ref { |
| 7995 | fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Air.Inst.Ref { |
| 7612 | 7996 | switch (operand.zigTypeTag()) { |
| 7613 | 7997 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, |
| 7614 | 7998 | .Int => { |
| ... | ... | @@ -7620,8 +8004,8 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) |
| 7620 | 8004 | const res = try Module.makeIntType(sema.arena, .unsigned, count); |
| 7621 | 8005 | return sema.addType(res); |
| 7622 | 8006 | }, |
| 7623 | | else => return sema.mod.fail( |
| 7624 | | &block.base, |
| 8007 | else => return sema.fail( |
| 8008 | block, |
| 7625 | 8009 | src, |
| 7626 | 8010 | "bit shifting operation expected integer type, found '{}'", |
| 7627 | 8011 | .{operand}, |
| ... | ... | @@ -7631,7 +8015,7 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) |
| 7631 | 8015 | |
| 7632 | 8016 | fn zirTypeofPeer( |
| 7633 | 8017 | sema: *Sema, |
| 7634 | | block: *Scope.Block, |
| 8018 | block: *Block, |
| 7635 | 8019 | extended: Zir.Inst.Extended.InstData, |
| 7636 | 8020 | ) CompileError!Air.Inst.Ref { |
| 7637 | 8021 | const tracy = trace(@src()); |
| ... | ... | @@ -7652,7 +8036,7 @@ fn zirTypeofPeer( |
| 7652 | 8036 | return sema.addType(result_type); |
| 7653 | 8037 | } |
| 7654 | 8038 | |
| 7655 | | fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8039 | fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7656 | 8040 | const tracy = trace(@src()); |
| 7657 | 8041 | defer tracy.end(); |
| 7658 | 8042 | |
| ... | ... | @@ -7676,7 +8060,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 7676 | 8060 | |
| 7677 | 8061 | fn zirBoolBr( |
| 7678 | 8062 | sema: *Sema, |
| 7679 | | parent_block: *Scope.Block, |
| 8063 | parent_block: *Block, |
| 7680 | 8064 | inst: Zir.Inst.Index, |
| 7681 | 8065 | is_bool_or: bool, |
| 7682 | 8066 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -7762,7 +8146,7 @@ fn zirBoolBr( |
| 7762 | 8146 | |
| 7763 | 8147 | fn zirIsNonNull( |
| 7764 | 8148 | sema: *Sema, |
| 7765 | | block: *Scope.Block, |
| 8149 | block: *Block, |
| 7766 | 8150 | inst: Zir.Inst.Index, |
| 7767 | 8151 | ) CompileError!Air.Inst.Ref { |
| 7768 | 8152 | const tracy = trace(@src()); |
| ... | ... | @@ -7776,7 +8160,7 @@ fn zirIsNonNull( |
| 7776 | 8160 | |
| 7777 | 8161 | fn zirIsNonNullPtr( |
| 7778 | 8162 | sema: *Sema, |
| 7779 | | block: *Scope.Block, |
| 8163 | block: *Block, |
| 7780 | 8164 | inst: Zir.Inst.Index, |
| 7781 | 8165 | ) CompileError!Air.Inst.Ref { |
| 7782 | 8166 | const tracy = trace(@src()); |
| ... | ... | @@ -7789,7 +8173,7 @@ fn zirIsNonNullPtr( |
| 7789 | 8173 | return sema.analyzeIsNull(block, src, loaded, true); |
| 7790 | 8174 | } |
| 7791 | 8175 | |
| 7792 | | fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8176 | fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7793 | 8177 | const tracy = trace(@src()); |
| 7794 | 8178 | defer tracy.end(); |
| 7795 | 8179 | |
| ... | ... | @@ -7798,7 +8182,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 7798 | 8182 | return sema.analyzeIsNonErr(block, inst_data.src(), operand); |
| 7799 | 8183 | } |
| 7800 | 8184 | |
| 7801 | | fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8185 | fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7802 | 8186 | const tracy = trace(@src()); |
| 7803 | 8187 | defer tracy.end(); |
| 7804 | 8188 | |
| ... | ... | @@ -7811,7 +8195,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 7811 | 8195 | |
| 7812 | 8196 | fn zirCondbr( |
| 7813 | 8197 | sema: *Sema, |
| 7814 | | parent_block: *Scope.Block, |
| 8198 | parent_block: *Block, |
| 7815 | 8199 | inst: Zir.Inst.Index, |
| 7816 | 8200 | ) CompileError!Zir.Inst.Index { |
| 7817 | 8201 | const tracy = trace(@src()); |
| ... | ... | @@ -7866,7 +8250,7 @@ fn zirCondbr( |
| 7866 | 8250 | return always_noreturn; |
| 7867 | 8251 | } |
| 7868 | 8252 | |
| 7869 | | fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 8253 | fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 7870 | 8254 | const tracy = trace(@src()); |
| 7871 | 8255 | defer tracy.end(); |
| 7872 | 8256 | |
| ... | ... | @@ -7885,7 +8269,7 @@ fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 7885 | 8269 | |
| 7886 | 8270 | fn zirRetErrValue( |
| 7887 | 8271 | sema: *Sema, |
| 7888 | | block: *Scope.Block, |
| 8272 | block: *Block, |
| 7889 | 8273 | inst: Zir.Inst.Index, |
| 7890 | 8274 | ) CompileError!Zir.Inst.Index { |
| 7891 | 8275 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| ... | ... | @@ -7909,7 +8293,7 @@ fn zirRetErrValue( |
| 7909 | 8293 | |
| 7910 | 8294 | fn zirRetCoerce( |
| 7911 | 8295 | sema: *Sema, |
| 7912 | | block: *Scope.Block, |
| 8296 | block: *Block, |
| 7913 | 8297 | inst: Zir.Inst.Index, |
| 7914 | 8298 | ) CompileError!Zir.Inst.Index { |
| 7915 | 8299 | const tracy = trace(@src()); |
| ... | ... | @@ -7922,7 +8306,7 @@ fn zirRetCoerce( |
| 7922 | 8306 | return sema.analyzeRet(block, operand, src, true); |
| 7923 | 8307 | } |
| 7924 | 8308 | |
| 7925 | | fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 8309 | fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 7926 | 8310 | const tracy = trace(@src()); |
| 7927 | 8311 | defer tracy.end(); |
| 7928 | 8312 | |
| ... | ... | @@ -7937,7 +8321,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 7937 | 8321 | return sema.analyzeRet(block, operand, src, false); |
| 7938 | 8322 | } |
| 7939 | 8323 | |
| 7940 | | fn zirRetLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 8324 | fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 7941 | 8325 | const tracy = trace(@src()); |
| 7942 | 8326 | defer tracy.end(); |
| 7943 | 8327 | |
| ... | ... | @@ -7954,7 +8338,7 @@ fn zirRetLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 7954 | 8338 | |
| 7955 | 8339 | fn analyzeRet( |
| 7956 | 8340 | sema: *Sema, |
| 7957 | | block: *Scope.Block, |
| 8341 | block: *Block, |
| 7958 | 8342 | uncasted_operand: Air.Inst.Ref, |
| 7959 | 8343 | src: LazySrcLoc, |
| 7960 | 8344 | need_coercion: bool, |
| ... | ... | @@ -7987,7 +8371,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool { |
| 7987 | 8371 | }; |
| 7988 | 8372 | } |
| 7989 | 8373 | |
| 7990 | | fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8374 | fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 7991 | 8375 | const tracy = trace(@src()); |
| 7992 | 8376 | defer tracy.end(); |
| 7993 | 8377 | |
| ... | ... | @@ -8004,7 +8388,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 8004 | 8388 | return sema.addType(ty); |
| 8005 | 8389 | } |
| 8006 | 8390 | |
| 8007 | | fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8391 | fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8008 | 8392 | const tracy = trace(@src()); |
| 8009 | 8393 | defer tracy.end(); |
| 8010 | 8394 | |
| ... | ... | @@ -8045,7 +8429,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8045 | 8429 | } else 0; |
| 8046 | 8430 | |
| 8047 | 8431 | if (bit_end != 0 and bit_start >= bit_end * 8) |
| 8048 | | return sema.mod.fail(&block.base, src, "bit offset starts after end of host integer", .{}); |
| 8432 | return sema.fail(block, src, "bit offset starts after end of host integer", .{}); |
| 8049 | 8433 | |
| 8050 | 8434 | const elem_type = try sema.resolveType(block, .unneeded, extra.data.elem_type); |
| 8051 | 8435 | |
| ... | ... | @@ -8064,7 +8448,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8064 | 8448 | return sema.addType(ty); |
| 8065 | 8449 | } |
| 8066 | 8450 | |
| 8067 | | fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8451 | fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8068 | 8452 | const tracy = trace(@src()); |
| 8069 | 8453 | defer tracy.end(); |
| 8070 | 8454 | |
| ... | ... | @@ -8075,14 +8459,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 8075 | 8459 | return sema.addConstant(struct_type, Value.initTag(.empty_struct_value)); |
| 8076 | 8460 | } |
| 8077 | 8461 | |
| 8078 | | fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8462 | fn zirUnionInitPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8079 | 8463 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8080 | 8464 | const src = inst_data.src(); |
| 8081 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{}); |
| 8465 | return sema.fail(block, src, "TODO: Sema.zirUnionInitPtr", .{}); |
| 8082 | 8466 | } |
| 8083 | 8467 | |
| 8084 | | fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8085 | | const mod = sema.mod; |
| 8468 | fn zirStructInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8086 | 8469 | const gpa = sema.gpa; |
| 8087 | 8470 | const zir_datas = sema.code.instructions.items(.data); |
| 8088 | 8471 | const inst_data = zir_datas[inst].pl_node; |
| ... | ... | @@ -8126,12 +8509,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8126 | 8509 | const other_field_type_data = zir_datas[other_field_type].pl_node; |
| 8127 | 8510 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node }; |
| 8128 | 8511 | const msg = msg: { |
| 8129 | | const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{}); |
| 8512 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| 8130 | 8513 | errdefer msg.destroy(gpa); |
| 8131 | | try mod.errNote(&block.base, other_field_src, msg, "other field here", .{}); |
| 8514 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 8132 | 8515 | break :msg msg; |
| 8133 | 8516 | }; |
| 8134 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 8517 | return sema.failWithOwnedErrorMsg(msg); |
| 8135 | 8518 | } |
| 8136 | 8519 | found_fields[field_index] = item.data.field_type; |
| 8137 | 8520 | field_inits[field_index] = sema.resolveInst(item.data.init); |
| ... | ... | @@ -8149,9 +8532,9 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8149 | 8532 | const template = "missing struct field: {s}"; |
| 8150 | 8533 | const args = .{field_name}; |
| 8151 | 8534 | if (root_msg) |msg| { |
| 8152 | | try mod.errNote(&block.base, src, msg, template, args); |
| 8535 | try sema.errNote(block, src, msg, template, args); |
| 8153 | 8536 | } else { |
| 8154 | | root_msg = try mod.errMsg(&block.base, src, template, args); |
| 8537 | root_msg = try sema.errMsg(block, src, template, args); |
| 8155 | 8538 | } |
| 8156 | 8539 | } else { |
| 8157 | 8540 | field_inits[i] = try sema.addConstant(field.ty, field.default_val); |
| ... | ... | @@ -8160,17 +8543,17 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8160 | 8543 | if (root_msg) |msg| { |
| 8161 | 8544 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 8162 | 8545 | defer gpa.free(fqn); |
| 8163 | | try mod.errNoteNonLazy( |
| 8546 | try sema.mod.errNoteNonLazy( |
| 8164 | 8547 | struct_obj.srcLoc(), |
| 8165 | 8548 | msg, |
| 8166 | 8549 | "struct '{s}' declared here", |
| 8167 | 8550 | .{fqn}, |
| 8168 | 8551 | ); |
| 8169 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 8552 | return sema.failWithOwnedErrorMsg(msg); |
| 8170 | 8553 | } |
| 8171 | 8554 | |
| 8172 | 8555 | if (is_ref) { |
| 8173 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true", .{}); |
| 8556 | return sema.fail(block, src, "TODO: Sema.zirStructInit is_ref=true", .{}); |
| 8174 | 8557 | } |
| 8175 | 8558 | |
| 8176 | 8559 | const is_comptime = for (field_inits) |field_init| { |
| ... | ... | @@ -8187,12 +8570,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8187 | 8570 | return sema.addConstant(resolved_ty, try Value.Tag.@"struct".create(sema.arena, values)); |
| 8188 | 8571 | } |
| 8189 | 8572 | |
| 8190 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{}); |
| 8573 | return sema.fail(block, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{}); |
| 8191 | 8574 | } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| { |
| 8192 | 8575 | const union_obj = union_payload.data; |
| 8193 | 8576 | |
| 8194 | 8577 | if (extra.data.fields_len != 1) { |
| 8195 | | return sema.mod.fail(&block.base, src, "union initialization expects exactly one field", .{}); |
| 8578 | return sema.fail(block, src, "union initialization expects exactly one field", .{}); |
| 8196 | 8579 | } |
| 8197 | 8580 | |
| 8198 | 8581 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); |
| ... | ... | @@ -8205,7 +8588,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8205 | 8588 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); |
| 8206 | 8589 | |
| 8207 | 8590 | if (is_ref) { |
| 8208 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true union", .{}); |
| 8591 | return sema.fail(block, src, "TODO: Sema.zirStructInit is_ref=true union", .{}); |
| 8209 | 8592 | } |
| 8210 | 8593 | |
| 8211 | 8594 | const init_inst = sema.resolveInst(item.data.init); |
| ... | ... | @@ -8218,20 +8601,20 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8218 | 8601 | }), |
| 8219 | 8602 | ); |
| 8220 | 8603 | } |
| 8221 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known union values", .{}); |
| 8604 | return sema.fail(block, src, "TODO: Sema.zirStructInit for runtime-known union values", .{}); |
| 8222 | 8605 | } |
| 8223 | 8606 | unreachable; |
| 8224 | 8607 | } |
| 8225 | 8608 | |
| 8226 | | fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8609 | fn zirStructInitAnon(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8227 | 8610 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8228 | 8611 | const src = inst_data.src(); |
| 8229 | 8612 | |
| 8230 | 8613 | _ = is_ref; |
| 8231 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{}); |
| 8614 | return sema.fail(block, src, "TODO: Sema.zirStructInitAnon", .{}); |
| 8232 | 8615 | } |
| 8233 | 8616 | |
| 8234 | | fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8617 | fn zirArrayInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8235 | 8618 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8236 | 8619 | const src = inst_data.src(); |
| 8237 | 8620 | |
| ... | ... | @@ -8249,10 +8632,13 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8249 | 8632 | var anon_decl = try block.startAnonDecl(); |
| 8250 | 8633 | defer anon_decl.deinit(); |
| 8251 | 8634 | assert(!(resolved_args.len == 0)); |
| 8252 | | const final_ty = try Type.Tag.array.create(anon_decl.arena(), .{ .len = resolved_args.len, .elem_type = sema.typeOf(resolved_args[0]) }); |
| 8635 | const final_ty = try Type.Tag.array.create(anon_decl.arena(), .{ |
| 8636 | .len = resolved_args.len, |
| 8637 | .elem_type = try sema.typeOf(resolved_args[0]).copy(anon_decl.arena()), |
| 8638 | }); |
| 8253 | 8639 | const buf = try anon_decl.arena().alloc(Value, resolved_args.len); |
| 8254 | 8640 | for (resolved_args) |arg, i| { |
| 8255 | | buf[i] = (try sema.resolveMaybeUndefVal(block, src, arg)).?; |
| 8641 | buf[i] = try (try sema.resolveMaybeUndefVal(block, src, arg)).?.copy(anon_decl.arena()); |
| 8256 | 8642 | } |
| 8257 | 8643 | |
| 8258 | 8644 | const val = try Value.Tag.array.create(anon_decl.arena(), buf); |
| ... | ... | @@ -8280,21 +8666,21 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8280 | 8666 | try sema.analyzeLoad(block, .unneeded, alloc, .unneeded); |
| 8281 | 8667 | } |
| 8282 | 8668 | |
| 8283 | | fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8669 | fn zirArrayInitAnon(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8284 | 8670 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8285 | 8671 | const src = inst_data.src(); |
| 8286 | 8672 | |
| 8287 | 8673 | _ = is_ref; |
| 8288 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{}); |
| 8674 | return sema.fail(block, src, "TODO: Sema.zirArrayInitAnon", .{}); |
| 8289 | 8675 | } |
| 8290 | 8676 | |
| 8291 | | fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8677 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8292 | 8678 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8293 | 8679 | const src = inst_data.src(); |
| 8294 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{}); |
| 8680 | return sema.fail(block, src, "TODO: Sema.zirFieldTypeRef", .{}); |
| 8295 | 8681 | } |
| 8296 | 8682 | |
| 8297 | | fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8683 | fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8298 | 8684 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8299 | 8685 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 8300 | 8686 | const src = inst_data.src(); |
| ... | ... | @@ -8314,7 +8700,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8314 | 8700 | return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name); |
| 8315 | 8701 | return sema.addType(field.ty); |
| 8316 | 8702 | }, |
| 8317 | | else => return sema.mod.fail(&block.base, src, "expected struct or union; found '{}'", .{ |
| 8703 | else => return sema.fail(block, src, "expected struct or union; found '{}'", .{ |
| 8318 | 8704 | resolved_ty, |
| 8319 | 8705 | }), |
| 8320 | 8706 | } |
| ... | ... | @@ -8322,32 +8708,32 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8322 | 8708 | |
| 8323 | 8709 | fn zirErrorReturnTrace( |
| 8324 | 8710 | sema: *Sema, |
| 8325 | | block: *Scope.Block, |
| 8711 | block: *Block, |
| 8326 | 8712 | extended: Zir.Inst.Extended.InstData, |
| 8327 | 8713 | ) CompileError!Air.Inst.Ref { |
| 8328 | 8714 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 8329 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{}); |
| 8715 | return sema.fail(block, src, "TODO: Sema.zirErrorReturnTrace", .{}); |
| 8330 | 8716 | } |
| 8331 | 8717 | |
| 8332 | 8718 | fn zirFrame( |
| 8333 | 8719 | sema: *Sema, |
| 8334 | | block: *Scope.Block, |
| 8720 | block: *Block, |
| 8335 | 8721 | extended: Zir.Inst.Extended.InstData, |
| 8336 | 8722 | ) CompileError!Air.Inst.Ref { |
| 8337 | 8723 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 8338 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{}); |
| 8724 | return sema.fail(block, src, "TODO: Sema.zirFrame", .{}); |
| 8339 | 8725 | } |
| 8340 | 8726 | |
| 8341 | 8727 | fn zirFrameAddress( |
| 8342 | 8728 | sema: *Sema, |
| 8343 | | block: *Scope.Block, |
| 8729 | block: *Block, |
| 8344 | 8730 | extended: Zir.Inst.Extended.InstData, |
| 8345 | 8731 | ) CompileError!Air.Inst.Ref { |
| 8346 | 8732 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 8347 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{}); |
| 8733 | return sema.fail(block, src, "TODO: Sema.zirFrameAddress", .{}); |
| 8348 | 8734 | } |
| 8349 | 8735 | |
| 8350 | | fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8736 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8351 | 8737 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8352 | 8738 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8353 | 8739 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| ... | ... | @@ -8356,7 +8742,7 @@ fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8356 | 8742 | return sema.addIntUnsigned(Type.comptime_int, abi_align); |
| 8357 | 8743 | } |
| 8358 | 8744 | |
| 8359 | | fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8745 | fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8360 | 8746 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8361 | 8747 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8362 | 8748 | const operand = sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -8368,31 +8754,31 @@ fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8368 | 8754 | return block.addUnOp(.bool_to_int, operand); |
| 8369 | 8755 | } |
| 8370 | 8756 | |
| 8371 | | fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8757 | fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8372 | 8758 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8373 | 8759 | const src = inst_data.src(); |
| 8374 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{}); |
| 8760 | return sema.fail(block, src, "TODO: Sema.zirEmbedFile", .{}); |
| 8375 | 8761 | } |
| 8376 | 8762 | |
| 8377 | | fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8763 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8378 | 8764 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8379 | 8765 | const src = inst_data.src(); |
| 8380 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{}); |
| 8766 | return sema.fail(block, src, "TODO: Sema.zirErrorName", .{}); |
| 8381 | 8767 | } |
| 8382 | 8768 | |
| 8383 | | fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8769 | fn zirUnaryMath(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8384 | 8770 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8385 | 8771 | const src = inst_data.src(); |
| 8386 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{}); |
| 8772 | return sema.fail(block, src, "TODO: Sema.zirUnaryMath", .{}); |
| 8387 | 8773 | } |
| 8388 | 8774 | |
| 8389 | | fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8775 | fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8390 | 8776 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8391 | 8777 | const src = inst_data.src(); |
| 8392 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{}); |
| 8778 | return sema.fail(block, src, "TODO: Sema.zirTagName", .{}); |
| 8393 | 8779 | } |
| 8394 | 8780 | |
| 8395 | | fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8781 | fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8396 | 8782 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8397 | 8783 | const src = inst_data.src(); |
| 8398 | 8784 | const type_info_ty = try sema.getBuiltinType(block, src, "TypeInfo"); |
| ... | ... | @@ -8422,55 +8808,55 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 8422 | 8808 | }; |
| 8423 | 8809 | return sema.addType(ty); |
| 8424 | 8810 | }, |
| 8425 | | .Float => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Float", .{}), |
| 8426 | | .Pointer => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Pointer", .{}), |
| 8427 | | .Array => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Array", .{}), |
| 8428 | | .Struct => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Struct", .{}), |
| 8811 | .Float => return sema.fail(block, src, "TODO: Sema.zirReify for Float", .{}), |
| 8812 | .Pointer => return sema.fail(block, src, "TODO: Sema.zirReify for Pointer", .{}), |
| 8813 | .Array => return sema.fail(block, src, "TODO: Sema.zirReify for Array", .{}), |
| 8814 | .Struct => return sema.fail(block, src, "TODO: Sema.zirReify for Struct", .{}), |
| 8429 | 8815 | .ComptimeFloat => return Air.Inst.Ref.comptime_float_type, |
| 8430 | 8816 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, |
| 8431 | 8817 | .Undefined => return Air.Inst.Ref.undefined_type, |
| 8432 | 8818 | .Null => return Air.Inst.Ref.null_type, |
| 8433 | | .Optional => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Optional", .{}), |
| 8434 | | .ErrorUnion => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorUnion", .{}), |
| 8435 | | .ErrorSet => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorSet", .{}), |
| 8436 | | .Enum => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Enum", .{}), |
| 8437 | | .Union => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Union", .{}), |
| 8438 | | .Fn => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Fn", .{}), |
| 8819 | .Optional => return sema.fail(block, src, "TODO: Sema.zirReify for Optional", .{}), |
| 8820 | .ErrorUnion => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorUnion", .{}), |
| 8821 | .ErrorSet => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorSet", .{}), |
| 8822 | .Enum => return sema.fail(block, src, "TODO: Sema.zirReify for Enum", .{}), |
| 8823 | .Union => return sema.fail(block, src, "TODO: Sema.zirReify for Union", .{}), |
| 8824 | .Fn => return sema.fail(block, src, "TODO: Sema.zirReify for Fn", .{}), |
| 8439 | 8825 | .BoundFn => @panic("TODO delete BoundFn from the language"), |
| 8440 | | .Opaque => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Opaque", .{}), |
| 8441 | | .Frame => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Frame", .{}), |
| 8826 | .Opaque => return sema.fail(block, src, "TODO: Sema.zirReify for Opaque", .{}), |
| 8827 | .Frame => return sema.fail(block, src, "TODO: Sema.zirReify for Frame", .{}), |
| 8442 | 8828 | .AnyFrame => return Air.Inst.Ref.anyframe_type, |
| 8443 | | .Vector => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Vector", .{}), |
| 8829 | .Vector => return sema.fail(block, src, "TODO: Sema.zirReify for Vector", .{}), |
| 8444 | 8830 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, |
| 8445 | 8831 | } |
| 8446 | 8832 | } |
| 8447 | 8833 | |
| 8448 | | fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8834 | fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8449 | 8835 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8450 | 8836 | const src = inst_data.src(); |
| 8451 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{}); |
| 8837 | return sema.fail(block, src, "TODO: Sema.zirTypeName", .{}); |
| 8452 | 8838 | } |
| 8453 | 8839 | |
| 8454 | | fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8840 | fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8455 | 8841 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8456 | 8842 | const src = inst_data.src(); |
| 8457 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{}); |
| 8843 | return sema.fail(block, src, "TODO: Sema.zirFrameType", .{}); |
| 8458 | 8844 | } |
| 8459 | 8845 | |
| 8460 | | fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8846 | fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8461 | 8847 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8462 | 8848 | const src = inst_data.src(); |
| 8463 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{}); |
| 8849 | return sema.fail(block, src, "TODO: Sema.zirFrameSize", .{}); |
| 8464 | 8850 | } |
| 8465 | 8851 | |
| 8466 | | fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8852 | fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8467 | 8853 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8468 | 8854 | const src = inst_data.src(); |
| 8469 | 8855 | // TODO don't forget the safety check! |
| 8470 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{}); |
| 8856 | return sema.fail(block, src, "TODO: Sema.zirFloatToInt", .{}); |
| 8471 | 8857 | } |
| 8472 | 8858 | |
| 8473 | | fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8859 | fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8474 | 8860 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8475 | 8861 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8476 | 8862 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -8492,7 +8878,7 @@ fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 8492 | 8878 | return block.addTyOp(.int_to_float, dest_ty, operand); |
| 8493 | 8879 | } |
| 8494 | 8880 | |
| 8495 | | fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8881 | fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8496 | 8882 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8497 | 8883 | const src = inst_data.src(); |
| 8498 | 8884 | |
| ... | ... | @@ -8505,15 +8891,15 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8505 | 8891 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8506 | 8892 | const type_res = try sema.resolveType(block, src, extra.lhs); |
| 8507 | 8893 | if (type_res.zigTypeTag() != .Pointer) |
| 8508 | | return sema.mod.fail(&block.base, type_src, "expected pointer, found '{}'", .{type_res}); |
| 8894 | return sema.fail(block, type_src, "expected pointer, found '{}'", .{type_res}); |
| 8509 | 8895 | const ptr_align = type_res.ptrAlignment(sema.mod.getTarget()); |
| 8510 | 8896 | |
| 8511 | 8897 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| 8512 | 8898 | const addr = val.toUnsignedInt(); |
| 8513 | 8899 | if (!type_res.isAllowzeroPtr() and addr == 0) |
| 8514 | | return sema.mod.fail(&block.base, operand_src, "pointer type '{}' does not allow address zero", .{type_res}); |
| 8900 | return sema.fail(block, operand_src, "pointer type '{}' does not allow address zero", .{type_res}); |
| 8515 | 8901 | if (addr != 0 and addr % ptr_align != 0) |
| 8516 | | return sema.mod.fail(&block.base, operand_src, "pointer type '{}' requires aligned address", .{type_res}); |
| 8902 | return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{type_res}); |
| 8517 | 8903 | |
| 8518 | 8904 | const val_payload = try sema.arena.create(Value.Payload.U64); |
| 8519 | 8905 | val_payload.* = .{ |
| ... | ... | @@ -8548,13 +8934,13 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8548 | 8934 | return block.addTyOp(.bitcast, type_res, operand_coerced); |
| 8549 | 8935 | } |
| 8550 | 8936 | |
| 8551 | | fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8937 | fn zirErrSetCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8552 | 8938 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8553 | 8939 | const src = inst_data.src(); |
| 8554 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{}); |
| 8940 | return sema.fail(block, src, "TODO: Sema.zirErrSetCast", .{}); |
| 8555 | 8941 | } |
| 8556 | 8942 | |
| 8557 | | fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8943 | fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8558 | 8944 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8559 | 8945 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8560 | 8946 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| ... | ... | @@ -8563,12 +8949,12 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8563 | 8949 | const operand = sema.resolveInst(extra.rhs); |
| 8564 | 8950 | const operand_ty = sema.typeOf(operand); |
| 8565 | 8951 | if (operand_ty.zigTypeTag() != .Pointer) { |
| 8566 | | return sema.mod.fail(&block.base, operand_src, "expected pointer, found {s} type '{}'", .{ |
| 8952 | return sema.fail(block, operand_src, "expected pointer, found {s} type '{}'", .{ |
| 8567 | 8953 | @tagName(operand_ty.zigTypeTag()), operand_ty, |
| 8568 | 8954 | }); |
| 8569 | 8955 | } |
| 8570 | 8956 | if (dest_ty.zigTypeTag() != .Pointer) { |
| 8571 | | return sema.mod.fail(&block.base, dest_ty_src, "expected pointer, found {s} type '{}'", .{ |
| 8957 | return sema.fail(block, dest_ty_src, "expected pointer, found {s} type '{}'", .{ |
| 8572 | 8958 | @tagName(dest_ty.zigTypeTag()), dest_ty, |
| 8573 | 8959 | }); |
| 8574 | 8960 | } |
| ... | ... | @@ -8578,7 +8964,7 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8578 | 8964 | return block.addTyOp(.bitcast, dest_ty, operand); |
| 8579 | 8965 | } |
| 8580 | 8966 | |
| 8581 | | fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8967 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8582 | 8968 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8583 | 8969 | const src = inst_data.src(); |
| 8584 | 8970 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -8587,7 +8973,6 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8587 | 8973 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 8588 | 8974 | const operand = sema.resolveInst(extra.rhs); |
| 8589 | 8975 | const operand_ty = sema.typeOf(operand); |
| 8590 | | const mod = sema.mod; |
| 8591 | 8976 | const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_ty); |
| 8592 | 8977 | const src_is_comptime_int = try sema.checkIntType(block, operand_src, operand_ty); |
| 8593 | 8978 | |
| ... | ... | @@ -8595,7 +8980,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8595 | 8980 | return sema.coerce(block, dest_ty, operand, operand_src); |
| 8596 | 8981 | } |
| 8597 | 8982 | |
| 8598 | | const target = mod.getTarget(); |
| 8983 | const target = sema.mod.getTarget(); |
| 8599 | 8984 | const src_info = operand_ty.intInfo(target); |
| 8600 | 8985 | const dest_info = dest_ty.intInfo(target); |
| 8601 | 8986 | |
| ... | ... | @@ -8605,28 +8990,28 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8605 | 8990 | |
| 8606 | 8991 | if (!src_is_comptime_int) { |
| 8607 | 8992 | if (src_info.signedness != dest_info.signedness) { |
| 8608 | | return mod.fail(&block.base, operand_src, "expected {s} integer type, found '{}'", .{ |
| 8993 | return sema.fail(block, operand_src, "expected {s} integer type, found '{}'", .{ |
| 8609 | 8994 | @tagName(dest_info.signedness), operand_ty, |
| 8610 | 8995 | }); |
| 8611 | 8996 | } |
| 8612 | 8997 | if (src_info.bits > 0 and src_info.bits < dest_info.bits) { |
| 8613 | 8998 | const msg = msg: { |
| 8614 | | const msg = try mod.errMsg( |
| 8615 | | &block.base, |
| 8999 | const msg = try sema.errMsg( |
| 9000 | block, |
| 8616 | 9001 | src, |
| 8617 | 9002 | "destination type '{}' has more bits than source type '{}'", |
| 8618 | 9003 | .{ dest_ty, operand_ty }, |
| 8619 | 9004 | ); |
| 8620 | | errdefer msg.destroy(mod.gpa); |
| 8621 | | try mod.errNote(&block.base, dest_ty_src, msg, "destination type has {d} bits", .{ |
| 9005 | errdefer msg.destroy(sema.gpa); |
| 9006 | try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{ |
| 8622 | 9007 | dest_info.bits, |
| 8623 | 9008 | }); |
| 8624 | | try mod.errNote(&block.base, operand_src, msg, "source type has {d} bits", .{ |
| 9009 | try sema.errNote(block, operand_src, msg, "source type has {d} bits", .{ |
| 8625 | 9010 | src_info.bits, |
| 8626 | 9011 | }); |
| 8627 | 9012 | break :msg msg; |
| 8628 | 9013 | }; |
| 8629 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 9014 | return sema.failWithOwnedErrorMsg(msg); |
| 8630 | 9015 | } |
| 8631 | 9016 | } |
| 8632 | 9017 | |
| ... | ... | @@ -8639,13 +9024,13 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8639 | 9024 | return block.addTyOp(.trunc, dest_ty, operand); |
| 8640 | 9025 | } |
| 8641 | 9026 | |
| 8642 | | fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9027 | fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8643 | 9028 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8644 | 9029 | const src = inst_data.src(); |
| 8645 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{}); |
| 9030 | return sema.fail(block, src, "TODO: Sema.zirAlignCast", .{}); |
| 8646 | 9031 | } |
| 8647 | 9032 | |
| 8648 | | fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9033 | fn zirClz(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8649 | 9034 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8650 | 9035 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8651 | 9036 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| ... | ... | @@ -8653,7 +9038,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8653 | 9038 | const operand_ty = sema.typeOf(operand); |
| 8654 | 9039 | // TODO implement support for vectors |
| 8655 | 9040 | if (operand_ty.zigTypeTag() != .Int) { |
| 8656 | | return sema.mod.fail(&block.base, ty_src, "expected integer type, found '{}'", .{ |
| 9041 | return sema.fail(block, ty_src, "expected integer type, found '{}'", .{ |
| 8657 | 9042 | operand_ty, |
| 8658 | 9043 | }); |
| 8659 | 9044 | } |
| ... | ... | @@ -8672,7 +9057,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8672 | 9057 | return block.addTyOp(.clz, result_ty, operand); |
| 8673 | 9058 | } |
| 8674 | 9059 | |
| 8675 | | fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9060 | fn zirCtz(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8676 | 9061 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8677 | 9062 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8678 | 9063 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| ... | ... | @@ -8680,7 +9065,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8680 | 9065 | const operand_ty = sema.typeOf(operand); |
| 8681 | 9066 | // TODO implement support for vectors |
| 8682 | 9067 | if (operand_ty.zigTypeTag() != .Int) { |
| 8683 | | return sema.mod.fail(&block.base, ty_src, "expected integer type, found '{}'", .{ |
| 9068 | return sema.fail(block, ty_src, "expected integer type, found '{}'", .{ |
| 8684 | 9069 | operand_ty, |
| 8685 | 9070 | }); |
| 8686 | 9071 | } |
| ... | ... | @@ -8692,85 +9077,85 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8692 | 9077 | |
| 8693 | 9078 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 8694 | 9079 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 8695 | | return sema.mod.fail(&block.base, operand_src, "TODO: implement comptime @ctz", .{}); |
| 9080 | return sema.fail(block, operand_src, "TODO: implement comptime @ctz", .{}); |
| 8696 | 9081 | } else operand_src; |
| 8697 | 9082 | |
| 8698 | 9083 | try sema.requireRuntimeBlock(block, runtime_src); |
| 8699 | 9084 | return block.addTyOp(.ctz, result_ty, operand); |
| 8700 | 9085 | } |
| 8701 | 9086 | |
| 8702 | | fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9087 | fn zirPopCount(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8703 | 9088 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8704 | 9089 | const src = inst_data.src(); |
| 8705 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{}); |
| 9090 | return sema.fail(block, src, "TODO: Sema.zirPopCount", .{}); |
| 8706 | 9091 | } |
| 8707 | 9092 | |
| 8708 | | fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9093 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8709 | 9094 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8710 | 9095 | const src = inst_data.src(); |
| 8711 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{}); |
| 9096 | return sema.fail(block, src, "TODO: Sema.zirByteSwap", .{}); |
| 8712 | 9097 | } |
| 8713 | 9098 | |
| 8714 | | fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9099 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8715 | 9100 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8716 | 9101 | const src = inst_data.src(); |
| 8717 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{}); |
| 9102 | return sema.fail(block, src, "TODO: Sema.zirBitReverse", .{}); |
| 8718 | 9103 | } |
| 8719 | 9104 | |
| 8720 | | fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9105 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8721 | 9106 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8722 | 9107 | const src = inst_data.src(); |
| 8723 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{}); |
| 9108 | return sema.fail(block, src, "TODO: Sema.zirDivExact", .{}); |
| 8724 | 9109 | } |
| 8725 | 9110 | |
| 8726 | | fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9111 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8727 | 9112 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8728 | 9113 | const src = inst_data.src(); |
| 8729 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{}); |
| 9114 | return sema.fail(block, src, "TODO: Sema.zirDivFloor", .{}); |
| 8730 | 9115 | } |
| 8731 | 9116 | |
| 8732 | | fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9117 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8733 | 9118 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8734 | 9119 | const src = inst_data.src(); |
| 8735 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{}); |
| 9120 | return sema.fail(block, src, "TODO: Sema.zirDivTrunc", .{}); |
| 8736 | 9121 | } |
| 8737 | 9122 | |
| 8738 | | fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9123 | fn zirShrExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8739 | 9124 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8740 | 9125 | const src = inst_data.src(); |
| 8741 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{}); |
| 9126 | return sema.fail(block, src, "TODO: Sema.zirShrExact", .{}); |
| 8742 | 9127 | } |
| 8743 | 9128 | |
| 8744 | | fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9129 | fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8745 | 9130 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8746 | 9131 | const src = inst_data.src(); |
| 8747 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{}); |
| 9132 | return sema.fail(block, src, "TODO: Sema.zirBitOffsetOf", .{}); |
| 8748 | 9133 | } |
| 8749 | 9134 | |
| 8750 | | fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9135 | fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8751 | 9136 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8752 | 9137 | const src = inst_data.src(); |
| 8753 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{}); |
| 9138 | return sema.fail(block, src, "TODO: Sema.zirOffsetOf", .{}); |
| 8754 | 9139 | } |
| 8755 | 9140 | |
| 8756 | 9141 | /// Returns `true` if the type was a comptime_int. |
| 8757 | | fn checkIntType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!bool { |
| 9142 | fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool { |
| 8758 | 9143 | switch (ty.zigTypeTag()) { |
| 8759 | 9144 | .ComptimeInt => return true, |
| 8760 | 9145 | .Int => return false, |
| 8761 | | else => return sema.mod.fail(&block.base, src, "expected integer type, found '{}'", .{ty}), |
| 9146 | else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty}), |
| 8762 | 9147 | } |
| 8763 | 9148 | } |
| 8764 | 9149 | |
| 8765 | 9150 | fn checkFloatType( |
| 8766 | 9151 | sema: *Sema, |
| 8767 | | block: *Scope.Block, |
| 9152 | block: *Block, |
| 8768 | 9153 | ty_src: LazySrcLoc, |
| 8769 | 9154 | ty: Type, |
| 8770 | 9155 | ) CompileError!void { |
| 8771 | 9156 | switch (ty.zigTypeTag()) { |
| 8772 | 9157 | .ComptimeFloat, .Float => {}, |
| 8773 | | else => return sema.mod.fail(&block.base, ty_src, "expected float type, found '{}'", .{ |
| 9158 | else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ |
| 8774 | 9159 | ty, |
| 8775 | 9160 | }), |
| 8776 | 9161 | } |
| ... | ... | @@ -8778,7 +9163,7 @@ fn checkFloatType( |
| 8778 | 9163 | |
| 8779 | 9164 | fn checkAtomicOperandType( |
| 8780 | 9165 | sema: *Sema, |
| 8781 | | block: *Scope.Block, |
| 9166 | block: *Block, |
| 8782 | 9167 | ty_src: LazySrcLoc, |
| 8783 | 9168 | ty: Type, |
| 8784 | 9169 | ) CompileError!void { |
| ... | ... | @@ -8791,8 +9176,8 @@ fn checkAtomicOperandType( |
| 8791 | 9176 | .Float => { |
| 8792 | 9177 | const bit_count = ty.floatBits(target); |
| 8793 | 9178 | if (bit_count > max_atomic_bits) { |
| 8794 | | return sema.mod.fail( |
| 8795 | | &block.base, |
| 9179 | return sema.fail( |
| 9180 | block, |
| 8796 | 9181 | ty_src, |
| 8797 | 9182 | "expected {d}-bit float type or smaller; found {d}-bit float type", |
| 8798 | 9183 | .{ max_atomic_bits, bit_count }, |
| ... | ... | @@ -8804,8 +9189,8 @@ fn checkAtomicOperandType( |
| 8804 | 9189 | else => { |
| 8805 | 9190 | if (ty.isPtrAtRuntime()) return; |
| 8806 | 9191 | |
| 8807 | | return sema.mod.fail( |
| 8808 | | &block.base, |
| 9192 | return sema.fail( |
| 9193 | block, |
| 8809 | 9194 | ty_src, |
| 8810 | 9195 | "expected bool, integer, float, enum, or pointer type; found {}", |
| 8811 | 9196 | .{ty}, |
| ... | ... | @@ -8814,8 +9199,8 @@ fn checkAtomicOperandType( |
| 8814 | 9199 | }; |
| 8815 | 9200 | const bit_count = int_ty.intInfo(target).bits; |
| 8816 | 9201 | if (bit_count > max_atomic_bits) { |
| 8817 | | return sema.mod.fail( |
| 8818 | | &block.base, |
| 9202 | return sema.fail( |
| 9203 | block, |
| 8819 | 9204 | ty_src, |
| 8820 | 9205 | "expected {d}-bit integer type or smaller; found {d}-bit integer type", |
| 8821 | 9206 | .{ max_atomic_bits, bit_count }, |
| ... | ... | @@ -8825,7 +9210,7 @@ fn checkAtomicOperandType( |
| 8825 | 9210 | |
| 8826 | 9211 | fn resolveExportOptions( |
| 8827 | 9212 | sema: *Sema, |
| 8828 | | block: *Scope.Block, |
| 9213 | block: *Block, |
| 8829 | 9214 | src: LazySrcLoc, |
| 8830 | 9215 | zir_ref: Zir.Inst.Ref, |
| 8831 | 9216 | ) CompileError!std.builtin.ExportOptions { |
| ... | ... | @@ -8839,7 +9224,7 @@ fn resolveExportOptions( |
| 8839 | 9224 | const linkage_index = struct_obj.fields.getIndex("linkage").?; |
| 8840 | 9225 | const section_index = struct_obj.fields.getIndex("section").?; |
| 8841 | 9226 | if (!fields[section_index].isNull()) { |
| 8842 | | return sema.mod.fail(&block.base, src, "TODO: implement exporting with linksection", .{}); |
| 9227 | return sema.fail(block, src, "TODO: implement exporting with linksection", .{}); |
| 8843 | 9228 | } |
| 8844 | 9229 | return std.builtin.ExportOptions{ |
| 8845 | 9230 | .name = try fields[name_index].toAllocatedBytes(sema.arena), |
| ... | ... | @@ -8850,7 +9235,7 @@ fn resolveExportOptions( |
| 8850 | 9235 | |
| 8851 | 9236 | fn resolveAtomicOrder( |
| 8852 | 9237 | sema: *Sema, |
| 8853 | | block: *Scope.Block, |
| 9238 | block: *Block, |
| 8854 | 9239 | src: LazySrcLoc, |
| 8855 | 9240 | zir_ref: Zir.Inst.Ref, |
| 8856 | 9241 | ) CompileError!std.builtin.AtomicOrder { |
| ... | ... | @@ -8863,7 +9248,7 @@ fn resolveAtomicOrder( |
| 8863 | 9248 | |
| 8864 | 9249 | fn resolveAtomicRmwOp( |
| 8865 | 9250 | sema: *Sema, |
| 8866 | | block: *Scope.Block, |
| 9251 | block: *Block, |
| 8867 | 9252 | src: LazySrcLoc, |
| 8868 | 9253 | zir_ref: Zir.Inst.Ref, |
| 8869 | 9254 | ) CompileError!std.builtin.AtomicRmwOp { |
| ... | ... | @@ -8876,11 +9261,10 @@ fn resolveAtomicRmwOp( |
| 8876 | 9261 | |
| 8877 | 9262 | fn zirCmpxchg( |
| 8878 | 9263 | sema: *Sema, |
| 8879 | | block: *Scope.Block, |
| 9264 | block: *Block, |
| 8880 | 9265 | inst: Zir.Inst.Index, |
| 8881 | 9266 | air_tag: Air.Inst.Tag, |
| 8882 | 9267 | ) CompileError!Air.Inst.Ref { |
| 8883 | | const mod = sema.mod; |
| 8884 | 9268 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8885 | 9269 | const extra = sema.code.extraData(Zir.Inst.Cmpxchg, inst_data.payload_index).data; |
| 8886 | 9270 | const src = inst_data.src(); |
| ... | ... | @@ -8896,8 +9280,8 @@ fn zirCmpxchg( |
| 8896 | 9280 | const elem_ty = sema.typeOf(ptr).elemType(); |
| 8897 | 9281 | try sema.checkAtomicOperandType(block, elem_ty_src, elem_ty); |
| 8898 | 9282 | if (elem_ty.zigTypeTag() == .Float) { |
| 8899 | | return mod.fail( |
| 8900 | | &block.base, |
| 9283 | return sema.fail( |
| 9284 | block, |
| 8901 | 9285 | elem_ty_src, |
| 8902 | 9286 | "expected bool, integer, enum, or pointer type; found '{}'", |
| 8903 | 9287 | .{elem_ty}, |
| ... | ... | @@ -8909,16 +9293,16 @@ fn zirCmpxchg( |
| 8909 | 9293 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order); |
| 8910 | 9294 | |
| 8911 | 9295 | if (@enumToInt(success_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { |
| 8912 | | return mod.fail(&block.base, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); |
| 9296 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); |
| 8913 | 9297 | } |
| 8914 | 9298 | if (@enumToInt(failure_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { |
| 8915 | | return mod.fail(&block.base, failure_order_src, "failure atomic ordering must be Monotonic or stricter", .{}); |
| 9299 | return sema.fail(block, failure_order_src, "failure atomic ordering must be Monotonic or stricter", .{}); |
| 8916 | 9300 | } |
| 8917 | 9301 | if (@enumToInt(failure_order) > @enumToInt(success_order)) { |
| 8918 | | return mod.fail(&block.base, failure_order_src, "failure atomic ordering must be no stricter than success", .{}); |
| 9302 | return sema.fail(block, failure_order_src, "failure atomic ordering must be no stricter than success", .{}); |
| 8919 | 9303 | } |
| 8920 | 9304 | if (failure_order == .Release or failure_order == .AcqRel) { |
| 8921 | | return mod.fail(&block.base, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{}); |
| 9305 | return sema.fail(block, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{}); |
| 8922 | 9306 | } |
| 8923 | 9307 | |
| 8924 | 9308 | const result_ty = try Module.optionalType(sema.arena, elem_ty); |
| ... | ... | @@ -8965,31 +9349,31 @@ fn zirCmpxchg( |
| 8965 | 9349 | }); |
| 8966 | 9350 | } |
| 8967 | 9351 | |
| 8968 | | fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9352 | fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8969 | 9353 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8970 | 9354 | const src = inst_data.src(); |
| 8971 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{}); |
| 9355 | return sema.fail(block, src, "TODO: Sema.zirSplat", .{}); |
| 8972 | 9356 | } |
| 8973 | 9357 | |
| 8974 | | fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9358 | fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8975 | 9359 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8976 | 9360 | const src = inst_data.src(); |
| 8977 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{}); |
| 9361 | return sema.fail(block, src, "TODO: Sema.zirReduce", .{}); |
| 8978 | 9362 | } |
| 8979 | 9363 | |
| 8980 | | fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9364 | fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8981 | 9365 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8982 | 9366 | const src = inst_data.src(); |
| 8983 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{}); |
| 9367 | return sema.fail(block, src, "TODO: Sema.zirShuffle", .{}); |
| 8984 | 9368 | } |
| 8985 | 9369 | |
| 8986 | | fn zirSelect(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9370 | fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8987 | 9371 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8988 | 9372 | const src = inst_data.src(); |
| 8989 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirSelect", .{}); |
| 9373 | return sema.fail(block, src, "TODO: Sema.zirSelect", .{}); |
| 8990 | 9374 | } |
| 8991 | 9375 | |
| 8992 | | fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9376 | fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8993 | 9377 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8994 | 9378 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8995 | 9379 | // zig fmt: off |
| ... | ... | @@ -9004,8 +9388,8 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 9004 | 9388 | |
| 9005 | 9389 | switch (order) { |
| 9006 | 9390 | .Release, .AcqRel => { |
| 9007 | | return sema.mod.fail( |
| 9008 | | &block.base, |
| 9391 | return sema.fail( |
| 9392 | block, |
| 9009 | 9393 | order_src, |
| 9010 | 9394 | "@atomicLoad atomic ordering must not be Release or AcqRel", |
| 9011 | 9395 | .{}, |
| ... | ... | @@ -9034,8 +9418,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 9034 | 9418 | }); |
| 9035 | 9419 | } |
| 9036 | 9420 | |
| 9037 | | fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9038 | | const mod = sema.mod; |
| 9421 | fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9039 | 9422 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9040 | 9423 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 9041 | 9424 | const src = inst_data.src(); |
| ... | ... | @@ -9053,14 +9436,14 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9053 | 9436 | |
| 9054 | 9437 | switch (operand_ty.zigTypeTag()) { |
| 9055 | 9438 | .Enum => if (op != .Xchg) { |
| 9056 | | return mod.fail(&block.base, op_src, "@atomicRmw with enum only allowed with .Xchg", .{}); |
| 9439 | return sema.fail(block, op_src, "@atomicRmw with enum only allowed with .Xchg", .{}); |
| 9057 | 9440 | }, |
| 9058 | 9441 | .Bool => if (op != .Xchg) { |
| 9059 | | return mod.fail(&block.base, op_src, "@atomicRmw with bool only allowed with .Xchg", .{}); |
| 9442 | return sema.fail(block, op_src, "@atomicRmw with bool only allowed with .Xchg", .{}); |
| 9060 | 9443 | }, |
| 9061 | 9444 | .Float => switch (op) { |
| 9062 | 9445 | .Xchg, .Add, .Sub => {}, |
| 9063 | | else => return mod.fail(&block.base, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, and .Sub", .{}), |
| 9446 | else => return sema.fail(block, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, and .Sub", .{}), |
| 9064 | 9447 | }, |
| 9065 | 9448 | else => {}, |
| 9066 | 9449 | } |
| ... | ... | @@ -9068,7 +9451,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9068 | 9451 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); |
| 9069 | 9452 | |
| 9070 | 9453 | if (order == .Unordered) { |
| 9071 | | return mod.fail(&block.base, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); |
| 9454 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); |
| 9072 | 9455 | } |
| 9073 | 9456 | |
| 9074 | 9457 | // special case zero bit types |
| ... | ... | @@ -9113,7 +9496,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9113 | 9496 | }); |
| 9114 | 9497 | } |
| 9115 | 9498 | |
| 9116 | | fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 9499 | fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 9117 | 9500 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9118 | 9501 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 9119 | 9502 | const src = inst_data.src(); |
| ... | ... | @@ -9131,8 +9514,8 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9131 | 9514 | |
| 9132 | 9515 | const air_tag: Air.Inst.Tag = switch (order) { |
| 9133 | 9516 | .Acquire, .AcqRel => { |
| 9134 | | return sema.mod.fail( |
| 9135 | | &block.base, |
| 9517 | return sema.fail( |
| 9518 | block, |
| 9136 | 9519 | order_src, |
| 9137 | 9520 | "@atomicStore atomic ordering must not be Acquire or AcqRel", |
| 9138 | 9521 | .{}, |
| ... | ... | @@ -9147,37 +9530,37 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9147 | 9530 | return sema.storePtr2(block, src, ptr, ptr_src, operand, operand_src, air_tag); |
| 9148 | 9531 | } |
| 9149 | 9532 | |
| 9150 | | fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9533 | fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9151 | 9534 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9152 | 9535 | const src = inst_data.src(); |
| 9153 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{}); |
| 9536 | return sema.fail(block, src, "TODO: Sema.zirMulAdd", .{}); |
| 9154 | 9537 | } |
| 9155 | 9538 | |
| 9156 | | fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9539 | fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9157 | 9540 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9158 | 9541 | const src = inst_data.src(); |
| 9159 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{}); |
| 9542 | return sema.fail(block, src, "TODO: Sema.zirBuiltinCall", .{}); |
| 9160 | 9543 | } |
| 9161 | 9544 | |
| 9162 | | fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9545 | fn zirFieldPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9163 | 9546 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9164 | 9547 | const src = inst_data.src(); |
| 9165 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{}); |
| 9548 | return sema.fail(block, src, "TODO: Sema.zirFieldPtrType", .{}); |
| 9166 | 9549 | } |
| 9167 | 9550 | |
| 9168 | | fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9551 | fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9169 | 9552 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9170 | 9553 | const src = inst_data.src(); |
| 9171 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{}); |
| 9554 | return sema.fail(block, src, "TODO: Sema.zirFieldParentPtr", .{}); |
| 9172 | 9555 | } |
| 9173 | 9556 | |
| 9174 | | fn zirMaximum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9557 | fn zirMaximum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9175 | 9558 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9176 | 9559 | const src = inst_data.src(); |
| 9177 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMaximum", .{}); |
| 9560 | return sema.fail(block, src, "TODO: Sema.zirMaximum", .{}); |
| 9178 | 9561 | } |
| 9179 | 9562 | |
| 9180 | | fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 9563 | fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 9181 | 9564 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9182 | 9565 | const extra = sema.code.extraData(Zir.Inst.Memcpy, inst_data.payload_index).data; |
| 9183 | 9566 | const src = inst_data.src(); |
| ... | ... | @@ -9188,16 +9571,16 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9188 | 9571 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9189 | 9572 | |
| 9190 | 9573 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { |
| 9191 | | return sema.mod.fail(&block.base, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9574 | return sema.fail(block, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9192 | 9575 | } |
| 9193 | 9576 | if (dest_ptr_ty.isConstPtr()) { |
| 9194 | | return sema.mod.fail(&block.base, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9577 | return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9195 | 9578 | } |
| 9196 | 9579 | |
| 9197 | 9580 | const uncasted_src_ptr = sema.resolveInst(extra.source); |
| 9198 | 9581 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); |
| 9199 | 9582 | if (uncasted_src_ptr_ty.zigTypeTag() != .Pointer) { |
| 9200 | | return sema.mod.fail(&block.base, src_src, "expected pointer, found '{}'", .{ |
| 9583 | return sema.fail(block, src_src, "expected pointer, found '{}'", .{ |
| 9201 | 9584 | uncasted_src_ptr_ty, |
| 9202 | 9585 | }); |
| 9203 | 9586 | } |
| ... | ... | @@ -9224,7 +9607,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9224 | 9607 | _ = dest_ptr_val; |
| 9225 | 9608 | _ = src_ptr_val; |
| 9226 | 9609 | _ = len_val; |
| 9227 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy at comptime", .{}); |
| 9610 | return sema.fail(block, src, "TODO: Sema.zirMemcpy at comptime", .{}); |
| 9228 | 9611 | } else break :rs len_src; |
| 9229 | 9612 | } else break :rs src_src; |
| 9230 | 9613 | } else dest_src; |
| ... | ... | @@ -9242,7 +9625,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9242 | 9625 | }); |
| 9243 | 9626 | } |
| 9244 | 9627 | |
| 9245 | | fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 9628 | fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 9246 | 9629 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9247 | 9630 | const extra = sema.code.extraData(Zir.Inst.Memset, inst_data.payload_index).data; |
| 9248 | 9631 | const src = inst_data.src(); |
| ... | ... | @@ -9252,10 +9635,10 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9252 | 9635 | const dest_ptr = sema.resolveInst(extra.dest); |
| 9253 | 9636 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9254 | 9637 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { |
| 9255 | | return sema.mod.fail(&block.base, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9638 | return sema.fail(block, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9256 | 9639 | } |
| 9257 | 9640 | if (dest_ptr_ty.isConstPtr()) { |
| 9258 | | return sema.mod.fail(&block.base, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9641 | return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9259 | 9642 | } |
| 9260 | 9643 | const elem_ty = dest_ptr_ty.elemType2(); |
| 9261 | 9644 | const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src); |
| ... | ... | @@ -9270,7 +9653,7 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9270 | 9653 | _ = ptr_val; |
| 9271 | 9654 | _ = len_val; |
| 9272 | 9655 | _ = val; |
| 9273 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset at comptime", .{}); |
| 9656 | return sema.fail(block, src, "TODO: Sema.zirMemset at comptime", .{}); |
| 9274 | 9657 | } else break :rs value_src; |
| 9275 | 9658 | } else break :rs len_src; |
| 9276 | 9659 | } else dest_src; |
| ... | ... | @@ -9288,27 +9671,27 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9288 | 9671 | }); |
| 9289 | 9672 | } |
| 9290 | 9673 | |
| 9291 | | fn zirMinimum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9674 | fn zirMinimum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9292 | 9675 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9293 | 9676 | const src = inst_data.src(); |
| 9294 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMinimum", .{}); |
| 9677 | return sema.fail(block, src, "TODO: Sema.zirMinimum", .{}); |
| 9295 | 9678 | } |
| 9296 | 9679 | |
| 9297 | | fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9680 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9298 | 9681 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9299 | 9682 | const src = inst_data.src(); |
| 9300 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{}); |
| 9683 | return sema.fail(block, src, "TODO: Sema.zirBuiltinAsyncCall", .{}); |
| 9301 | 9684 | } |
| 9302 | 9685 | |
| 9303 | | fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9686 | fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9304 | 9687 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9305 | 9688 | const src = inst_data.src(); |
| 9306 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{}); |
| 9689 | return sema.fail(block, src, "TODO: Sema.zirResume", .{}); |
| 9307 | 9690 | } |
| 9308 | 9691 | |
| 9309 | 9692 | fn zirAwait( |
| 9310 | 9693 | sema: *Sema, |
| 9311 | | block: *Scope.Block, |
| 9694 | block: *Block, |
| 9312 | 9695 | inst: Zir.Inst.Index, |
| 9313 | 9696 | is_nosuspend: bool, |
| 9314 | 9697 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -9316,12 +9699,12 @@ fn zirAwait( |
| 9316 | 9699 | const src = inst_data.src(); |
| 9317 | 9700 | |
| 9318 | 9701 | _ = is_nosuspend; |
| 9319 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAwait", .{}); |
| 9702 | return sema.fail(block, src, "TODO: Sema.zirAwait", .{}); |
| 9320 | 9703 | } |
| 9321 | 9704 | |
| 9322 | 9705 | fn zirVarExtended( |
| 9323 | 9706 | sema: *Sema, |
| 9324 | | block: *Scope.Block, |
| 9707 | block: *Block, |
| 9325 | 9708 | extended: Zir.Inst.Extended.InstData, |
| 9326 | 9709 | ) CompileError!Air.Inst.Ref { |
| 9327 | 9710 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| ... | ... | @@ -9376,7 +9759,7 @@ fn zirVarExtended( |
| 9376 | 9759 | if (lib_name != null) { |
| 9377 | 9760 | // Look at the sema code for functions which has this logic, it just needs to |
| 9378 | 9761 | // be extracted and shared by both var and func |
| 9379 | | return sema.mod.fail(&block.base, src, "TODO: handle var with lib_name in Sema", .{}); |
| 9762 | return sema.fail(block, src, "TODO: handle var with lib_name in Sema", .{}); |
| 9380 | 9763 | } |
| 9381 | 9764 | |
| 9382 | 9765 | const new_var = try sema.gpa.create(Module.Var); |
| ... | ... | @@ -9396,7 +9779,7 @@ fn zirVarExtended( |
| 9396 | 9779 | |
| 9397 | 9780 | fn zirFuncExtended( |
| 9398 | 9781 | sema: *Sema, |
| 9399 | | block: *Scope.Block, |
| 9782 | block: *Block, |
| 9400 | 9783 | extended: Zir.Inst.Extended.InstData, |
| 9401 | 9784 | inst: Zir.Inst.Index, |
| 9402 | 9785 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -9463,7 +9846,7 @@ fn zirFuncExtended( |
| 9463 | 9846 | |
| 9464 | 9847 | fn zirCUndef( |
| 9465 | 9848 | sema: *Sema, |
| 9466 | | block: *Scope.Block, |
| 9849 | block: *Block, |
| 9467 | 9850 | extended: Zir.Inst.Extended.InstData, |
| 9468 | 9851 | ) CompileError!Air.Inst.Ref { |
| 9469 | 9852 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | ... | @@ -9476,7 +9859,7 @@ fn zirCUndef( |
| 9476 | 9859 | |
| 9477 | 9860 | fn zirCInclude( |
| 9478 | 9861 | sema: *Sema, |
| 9479 | | block: *Scope.Block, |
| 9862 | block: *Block, |
| 9480 | 9863 | extended: Zir.Inst.Extended.InstData, |
| 9481 | 9864 | ) CompileError!Air.Inst.Ref { |
| 9482 | 9865 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | ... | @@ -9489,7 +9872,7 @@ fn zirCInclude( |
| 9489 | 9872 | |
| 9490 | 9873 | fn zirCDefine( |
| 9491 | 9874 | sema: *Sema, |
| 9492 | | block: *Scope.Block, |
| 9875 | block: *Block, |
| 9493 | 9876 | extended: Zir.Inst.Extended.InstData, |
| 9494 | 9877 | ) CompileError!Air.Inst.Ref { |
| 9495 | 9878 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| ... | ... | @@ -9507,41 +9890,41 @@ fn zirCDefine( |
| 9507 | 9890 | |
| 9508 | 9891 | fn zirWasmMemorySize( |
| 9509 | 9892 | sema: *Sema, |
| 9510 | | block: *Scope.Block, |
| 9893 | block: *Block, |
| 9511 | 9894 | extended: Zir.Inst.Extended.InstData, |
| 9512 | 9895 | ) CompileError!Air.Inst.Ref { |
| 9513 | 9896 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 9514 | 9897 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 9515 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{}); |
| 9898 | return sema.fail(block, src, "TODO: implement Sema.zirWasmMemorySize", .{}); |
| 9516 | 9899 | } |
| 9517 | 9900 | |
| 9518 | 9901 | fn zirWasmMemoryGrow( |
| 9519 | 9902 | sema: *Sema, |
| 9520 | | block: *Scope.Block, |
| 9903 | block: *Block, |
| 9521 | 9904 | extended: Zir.Inst.Extended.InstData, |
| 9522 | 9905 | ) CompileError!Air.Inst.Ref { |
| 9523 | 9906 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9524 | 9907 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 9525 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{}); |
| 9908 | return sema.fail(block, src, "TODO: implement Sema.zirWasmMemoryGrow", .{}); |
| 9526 | 9909 | } |
| 9527 | 9910 | |
| 9528 | 9911 | fn zirBuiltinExtern( |
| 9529 | 9912 | sema: *Sema, |
| 9530 | | block: *Scope.Block, |
| 9913 | block: *Block, |
| 9531 | 9914 | extended: Zir.Inst.Extended.InstData, |
| 9532 | 9915 | ) CompileError!Air.Inst.Ref { |
| 9533 | 9916 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9534 | 9917 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 9535 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{}); |
| 9918 | return sema.fail(block, src, "TODO: implement Sema.zirBuiltinExtern", .{}); |
| 9536 | 9919 | } |
| 9537 | 9920 | |
| 9538 | | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 9921 | fn requireFunctionBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 9539 | 9922 | if (sema.func == null) { |
| 9540 | | return sema.mod.fail(&block.base, src, "instruction illegal outside function body", .{}); |
| 9923 | return sema.fail(block, src, "instruction illegal outside function body", .{}); |
| 9541 | 9924 | } |
| 9542 | 9925 | } |
| 9543 | 9926 | |
| 9544 | | fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 9927 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 9545 | 9928 | if (block.is_comptime) { |
| 9546 | 9929 | return sema.failWithNeededComptime(block, src); |
| 9547 | 9930 | } |
| ... | ... | @@ -9551,7 +9934,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void |
| 9551 | 9934 | /// Emit a compile error if type cannot be used for a runtime variable. |
| 9552 | 9935 | fn validateVarType( |
| 9553 | 9936 | sema: *Sema, |
| 9554 | | block: *Scope.Block, |
| 9937 | block: *Block, |
| 9555 | 9938 | src: LazySrcLoc, |
| 9556 | 9939 | var_ty: Type, |
| 9557 | 9940 | is_extern: bool, |
| ... | ... | @@ -9595,7 +9978,7 @@ fn validateVarType( |
| 9595 | 9978 | }, |
| 9596 | 9979 | } else unreachable; // TODO should not need else unreachable |
| 9597 | 9980 | if (!ok) { |
| 9598 | | return sema.mod.fail(&block.base, src, "variable of type '{}' must be const or comptime", .{var_ty}); |
| 9981 | return sema.fail(block, src, "variable of type '{}' must be const or comptime", .{var_ty}); |
| 9599 | 9982 | } |
| 9600 | 9983 | } |
| 9601 | 9984 | |
| ... | ... | @@ -9610,17 +9993,18 @@ pub const PanicId = enum { |
| 9610 | 9993 | |
| 9611 | 9994 | fn addSafetyCheck( |
| 9612 | 9995 | sema: *Sema, |
| 9613 | | parent_block: *Scope.Block, |
| 9996 | parent_block: *Block, |
| 9614 | 9997 | ok: Air.Inst.Ref, |
| 9615 | 9998 | panic_id: PanicId, |
| 9616 | 9999 | ) !void { |
| 9617 | 10000 | const gpa = sema.gpa; |
| 9618 | 10001 | |
| 9619 | | var fail_block: Scope.Block = .{ |
| 10002 | var fail_block: Block = .{ |
| 9620 | 10003 | .parent = parent_block, |
| 9621 | 10004 | .sema = sema, |
| 9622 | | .wip_capture_scope = parent_block.wip_capture_scope, |
| 9623 | 10005 | .src_decl = parent_block.src_decl, |
| 10006 | .namespace = parent_block.namespace, |
| 10007 | .wip_capture_scope = parent_block.wip_capture_scope, |
| 9624 | 10008 | .instructions = .{}, |
| 9625 | 10009 | .inlining = parent_block.inlining, |
| 9626 | 10010 | .is_comptime = parent_block.is_comptime, |
| ... | ... | @@ -9679,7 +10063,7 @@ fn addSafetyCheck( |
| 9679 | 10063 | |
| 9680 | 10064 | fn panicWithMsg( |
| 9681 | 10065 | sema: *Sema, |
| 9682 | | block: *Scope.Block, |
| 10066 | block: *Block, |
| 9683 | 10067 | src: LazySrcLoc, |
| 9684 | 10068 | msg_inst: Air.Inst.Ref, |
| 9685 | 10069 | ) !Zir.Inst.Index { |
| ... | ... | @@ -9699,7 +10083,7 @@ fn panicWithMsg( |
| 9699 | 10083 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 9700 | 10084 | const ptr_stack_trace_ty = try Type.ptr(arena, .{ |
| 9701 | 10085 | .pointee_type = stack_trace_ty, |
| 9702 | | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic |
| 10086 | .@"addrspace" = target_util.defaultAddressSpace(mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic |
| 9703 | 10087 | }); |
| 9704 | 10088 | const null_stack_trace = try sema.addConstant( |
| 9705 | 10089 | try Module.optionalType(arena, ptr_stack_trace_ty), |
| ... | ... | @@ -9713,7 +10097,7 @@ fn panicWithMsg( |
| 9713 | 10097 | |
| 9714 | 10098 | fn safetyPanic( |
| 9715 | 10099 | sema: *Sema, |
| 9716 | | block: *Scope.Block, |
| 10100 | block: *Block, |
| 9717 | 10101 | src: LazySrcLoc, |
| 9718 | 10102 | panic_id: PanicId, |
| 9719 | 10103 | ) CompileError!Zir.Inst.Index { |
| ... | ... | @@ -9741,17 +10125,17 @@ fn safetyPanic( |
| 9741 | 10125 | return sema.panicWithMsg(block, src, casted_msg_inst); |
| 9742 | 10126 | } |
| 9743 | 10127 | |
| 9744 | | fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 10128 | fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 9745 | 10129 | sema.branch_count += 1; |
| 9746 | 10130 | if (sema.branch_count > sema.branch_quota) { |
| 9747 | 10131 | // TODO show the "called from here" stack |
| 9748 | | return sema.mod.fail(&block.base, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota}); |
| 10132 | return sema.fail(block, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota}); |
| 9749 | 10133 | } |
| 9750 | 10134 | } |
| 9751 | 10135 | |
| 9752 | 10136 | fn fieldVal( |
| 9753 | 10137 | sema: *Sema, |
| 9754 | | block: *Scope.Block, |
| 10138 | block: *Block, |
| 9755 | 10139 | src: LazySrcLoc, |
| 9756 | 10140 | object: Air.Inst.Ref, |
| 9757 | 10141 | field_name: []const u8, |
| ... | ... | @@ -9760,7 +10144,6 @@ fn fieldVal( |
| 9760 | 10144 | // When editing this function, note that there is corresponding logic to be edited |
| 9761 | 10145 | // in `fieldPtr`. This function takes a value and returns a value. |
| 9762 | 10146 | |
| 9763 | | const mod = sema.mod; |
| 9764 | 10147 | const arena = sema.arena; |
| 9765 | 10148 | const object_src = src; // TODO better source location |
| 9766 | 10149 | const object_ty = sema.typeOf(object); |
| ... | ... | @@ -9773,8 +10156,8 @@ fn fieldVal( |
| 9773 | 10156 | try Value.Tag.int_u64.create(arena, object_ty.arrayLen()), |
| 9774 | 10157 | ); |
| 9775 | 10158 | } else { |
| 9776 | | return mod.fail( |
| 9777 | | &block.base, |
| 10159 | return sema.fail( |
| 10160 | block, |
| 9778 | 10161 | field_name_src, |
| 9779 | 10162 | "no member named '{s}' in '{}'", |
| 9780 | 10163 | .{ field_name, object_ty }, |
| ... | ... | @@ -9788,8 +10171,8 @@ fn fieldVal( |
| 9788 | 10171 | const result_ty = object_ty.slicePtrFieldType(buf); |
| 9789 | 10172 | if (try sema.resolveMaybeUndefVal(block, object_src, object)) |val| { |
| 9790 | 10173 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 9791 | | return mod.fail( |
| 9792 | | &block.base, |
| 10174 | return sema.fail( |
| 10175 | block, |
| 9793 | 10176 | field_name_src, |
| 9794 | 10177 | "TODO implement comptime slice ptr", |
| 9795 | 10178 | .{}, |
| ... | ... | @@ -9809,8 +10192,8 @@ fn fieldVal( |
| 9809 | 10192 | try sema.requireRuntimeBlock(block, src); |
| 9810 | 10193 | return block.addTyOp(.slice_len, result_ty, object); |
| 9811 | 10194 | } else { |
| 9812 | | return mod.fail( |
| 9813 | | &block.base, |
| 10195 | return sema.fail( |
| 10196 | block, |
| 9814 | 10197 | field_name_src, |
| 9815 | 10198 | "no member named '{s}' in '{}'", |
| 9816 | 10199 | .{ field_name, object_ty }, |
| ... | ... | @@ -9827,8 +10210,8 @@ fn fieldVal( |
| 9827 | 10210 | try Value.Tag.int_u64.create(arena, ptr_child.arrayLen()), |
| 9828 | 10211 | ); |
| 9829 | 10212 | } else { |
| 9830 | | return mod.fail( |
| 9831 | | &block.base, |
| 10213 | return sema.fail( |
| 10214 | block, |
| 9832 | 10215 | field_name_src, |
| 9833 | 10216 | "no member named '{s}' in '{}'", |
| 9834 | 10217 | .{ field_name, object_ty }, |
| ... | ... | @@ -9865,10 +10248,10 @@ fn fieldVal( |
| 9865 | 10248 | break :blk name; |
| 9866 | 10249 | } |
| 9867 | 10250 | } |
| 9868 | | return mod.fail(&block.base, src, "no error named '{s}' in '{}'", .{ |
| 10251 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ |
| 9869 | 10252 | field_name, child_type, |
| 9870 | 10253 | }); |
| 9871 | | } else (try mod.getErrorValue(field_name)).key; |
| 10254 | } else (try sema.mod.getErrorValue(field_name)).key; |
| 9872 | 10255 | |
| 9873 | 10256 | return sema.addConstant( |
| 9874 | 10257 | try child_type.copy(arena), |
| ... | ... | @@ -9888,7 +10271,7 @@ fn fieldVal( |
| 9888 | 10271 | .Union => "union", |
| 9889 | 10272 | else => unreachable, |
| 9890 | 10273 | }; |
| 9891 | | return mod.fail(&block.base, src, "{s} '{}' has no member named '{s}'", .{ |
| 10274 | return sema.fail(block, src, "{s} '{}' has no member named '{s}'", .{ |
| 9892 | 10275 | kw_name, child_type, field_name, |
| 9893 | 10276 | }); |
| 9894 | 10277 | }, |
| ... | ... | @@ -9900,14 +10283,14 @@ fn fieldVal( |
| 9900 | 10283 | } |
| 9901 | 10284 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 9902 | 10285 | const msg = msg: { |
| 9903 | | const msg = try mod.errMsg( |
| 9904 | | &block.base, |
| 10286 | const msg = try sema.errMsg( |
| 10287 | block, |
| 9905 | 10288 | src, |
| 9906 | 10289 | "enum '{}' has no member named '{s}'", |
| 9907 | 10290 | .{ child_type, field_name }, |
| 9908 | 10291 | ); |
| 9909 | 10292 | errdefer msg.destroy(sema.gpa); |
| 9910 | | try mod.errNoteNonLazy( |
| 10293 | try sema.mod.errNoteNonLazy( |
| 9911 | 10294 | child_type.declSrcLoc(), |
| 9912 | 10295 | msg, |
| 9913 | 10296 | "enum declared here", |
| ... | ... | @@ -9915,25 +10298,25 @@ fn fieldVal( |
| 9915 | 10298 | ); |
| 9916 | 10299 | break :msg msg; |
| 9917 | 10300 | }; |
| 9918 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 10301 | return sema.failWithOwnedErrorMsg(msg); |
| 9919 | 10302 | }; |
| 9920 | 10303 | const field_index_u32 = @intCast(u32, field_index); |
| 9921 | 10304 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32); |
| 9922 | 10305 | return sema.addConstant(try child_type.copy(arena), enum_val); |
| 9923 | 10306 | }, |
| 9924 | | else => return mod.fail(&block.base, src, "type '{}' has no members", .{child_type}), |
| 10307 | else => return sema.fail(block, src, "type '{}' has no members", .{child_type}), |
| 9925 | 10308 | } |
| 9926 | 10309 | }, |
| 9927 | 10310 | .Struct => return sema.structFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9928 | 10311 | .Union => return sema.unionFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9929 | 10312 | else => {}, |
| 9930 | 10313 | } |
| 9931 | | return mod.fail(&block.base, src, "type '{}' does not support field access", .{object_ty}); |
| 10314 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty}); |
| 9932 | 10315 | } |
| 9933 | 10316 | |
| 9934 | 10317 | fn fieldPtr( |
| 9935 | 10318 | sema: *Sema, |
| 9936 | | block: *Scope.Block, |
| 10319 | block: *Block, |
| 9937 | 10320 | src: LazySrcLoc, |
| 9938 | 10321 | object_ptr: Air.Inst.Ref, |
| 9939 | 10322 | field_name: []const u8, |
| ... | ... | @@ -9942,12 +10325,11 @@ fn fieldPtr( |
| 9942 | 10325 | // When editing this function, note that there is corresponding logic to be edited |
| 9943 | 10326 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 9944 | 10327 | |
| 9945 | | const mod = sema.mod; |
| 9946 | 10328 | const object_ptr_src = src; // TODO better source location |
| 9947 | 10329 | const object_ptr_ty = sema.typeOf(object_ptr); |
| 9948 | 10330 | const object_ty = switch (object_ptr_ty.zigTypeTag()) { |
| 9949 | 10331 | .Pointer => object_ptr_ty.elemType(), |
| 9950 | | else => return mod.fail(&block.base, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty}), |
| 10332 | else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty}), |
| 9951 | 10333 | }; |
| 9952 | 10334 | switch (object_ty.zigTypeTag()) { |
| 9953 | 10335 | .Array => { |
| ... | ... | @@ -9959,8 +10341,8 @@ fn fieldPtr( |
| 9959 | 10341 | try Value.Tag.int_u64.create(anon_decl.arena(), object_ty.arrayLen()), |
| 9960 | 10342 | )); |
| 9961 | 10343 | } else { |
| 9962 | | return mod.fail( |
| 9963 | | &block.base, |
| 10344 | return sema.fail( |
| 10345 | block, |
| 9964 | 10346 | field_name_src, |
| 9965 | 10347 | "no member named '{s}' in '{}'", |
| 9966 | 10348 | .{ field_name, object_ty }, |
| ... | ... | @@ -9977,22 +10359,22 @@ fn fieldPtr( |
| 9977 | 10359 | // the runtime value to it, and then return the `alloc`. |
| 9978 | 10360 | // In both cases the pointer should be const. |
| 9979 | 10361 | if (mem.eql(u8, field_name, "ptr")) { |
| 9980 | | return mod.fail( |
| 9981 | | &block.base, |
| 10362 | return sema.fail( |
| 10363 | block, |
| 9982 | 10364 | field_name_src, |
| 9983 | 10365 | "TODO: implement reference to 'ptr' field of slice '{}'", |
| 9984 | 10366 | .{object_ty}, |
| 9985 | 10367 | ); |
| 9986 | 10368 | } else if (mem.eql(u8, field_name, "len")) { |
| 9987 | | return mod.fail( |
| 9988 | | &block.base, |
| 10369 | return sema.fail( |
| 10370 | block, |
| 9989 | 10371 | field_name_src, |
| 9990 | 10372 | "TODO: implement reference to 'len' field of slice '{}'", |
| 9991 | 10373 | .{object_ty}, |
| 9992 | 10374 | ); |
| 9993 | 10375 | } else { |
| 9994 | | return mod.fail( |
| 9995 | | &block.base, |
| 10376 | return sema.fail( |
| 10377 | block, |
| 9996 | 10378 | field_name_src, |
| 9997 | 10379 | "no member named '{s}' in '{}'", |
| 9998 | 10380 | .{ field_name, object_ty }, |
| ... | ... | @@ -10011,8 +10393,8 @@ fn fieldPtr( |
| 10011 | 10393 | try Value.Tag.int_u64.create(anon_decl.arena(), ptr_child.arrayLen()), |
| 10012 | 10394 | )); |
| 10013 | 10395 | } else { |
| 10014 | | return mod.fail( |
| 10015 | | &block.base, |
| 10396 | return sema.fail( |
| 10397 | block, |
| 10016 | 10398 | field_name_src, |
| 10017 | 10399 | "no member named '{s}' in '{}'", |
| 10018 | 10400 | .{ field_name, object_ty }, |
| ... | ... | @@ -10051,10 +10433,10 @@ fn fieldPtr( |
| 10051 | 10433 | break :blk name; |
| 10052 | 10434 | } |
| 10053 | 10435 | } |
| 10054 | | return mod.fail(&block.base, src, "no error named '{s}' in '{}'", .{ |
| 10436 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ |
| 10055 | 10437 | field_name, child_type, |
| 10056 | 10438 | }); |
| 10057 | | } else (try mod.getErrorValue(field_name)).key; |
| 10439 | } else (try sema.mod.getErrorValue(field_name)).key; |
| 10058 | 10440 | |
| 10059 | 10441 | var anon_decl = try block.startAnonDecl(); |
| 10060 | 10442 | defer anon_decl.deinit(); |
| ... | ... | @@ -10076,7 +10458,7 @@ fn fieldPtr( |
| 10076 | 10458 | .Union => "union", |
| 10077 | 10459 | else => unreachable, |
| 10078 | 10460 | }; |
| 10079 | | return mod.fail(&block.base, src, "{s} '{}' has no member named '{s}'", .{ |
| 10461 | return sema.fail(block, src, "{s} '{}' has no member named '{s}'", .{ |
| 10080 | 10462 | kw_name, child_type, field_name, |
| 10081 | 10463 | }); |
| 10082 | 10464 | }, |
| ... | ... | @@ -10088,14 +10470,14 @@ fn fieldPtr( |
| 10088 | 10470 | } |
| 10089 | 10471 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 10090 | 10472 | const msg = msg: { |
| 10091 | | const msg = try mod.errMsg( |
| 10092 | | &block.base, |
| 10473 | const msg = try sema.errMsg( |
| 10474 | block, |
| 10093 | 10475 | src, |
| 10094 | 10476 | "enum '{}' has no member named '{s}'", |
| 10095 | 10477 | .{ child_type, field_name }, |
| 10096 | 10478 | ); |
| 10097 | 10479 | errdefer msg.destroy(sema.gpa); |
| 10098 | | try mod.errNoteNonLazy( |
| 10480 | try sema.mod.errNoteNonLazy( |
| 10099 | 10481 | child_type.declSrcLoc(), |
| 10100 | 10482 | msg, |
| 10101 | 10483 | "enum declared here", |
| ... | ... | @@ -10103,7 +10485,7 @@ fn fieldPtr( |
| 10103 | 10485 | ); |
| 10104 | 10486 | break :msg msg; |
| 10105 | 10487 | }; |
| 10106 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 10488 | return sema.failWithOwnedErrorMsg(msg); |
| 10107 | 10489 | }; |
| 10108 | 10490 | const field_index_u32 = @intCast(u32, field_index); |
| 10109 | 10491 | var anon_decl = try block.startAnonDecl(); |
| ... | ... | @@ -10113,19 +10495,19 @@ fn fieldPtr( |
| 10113 | 10495 | try Value.Tag.enum_field_index.create(anon_decl.arena(), field_index_u32), |
| 10114 | 10496 | )); |
| 10115 | 10497 | }, |
| 10116 | | else => return mod.fail(&block.base, src, "type '{}' has no members", .{child_type}), |
| 10498 | else => return sema.fail(block, src, "type '{}' has no members", .{child_type}), |
| 10117 | 10499 | } |
| 10118 | 10500 | }, |
| 10119 | 10501 | .Struct => return sema.structFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10120 | 10502 | .Union => return sema.unionFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10121 | 10503 | else => {}, |
| 10122 | 10504 | } |
| 10123 | | return mod.fail(&block.base, src, "type '{}' does not support field access", .{object_ty}); |
| 10505 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty}); |
| 10124 | 10506 | } |
| 10125 | 10507 | |
| 10126 | 10508 | fn fieldCallBind( |
| 10127 | 10509 | sema: *Sema, |
| 10128 | | block: *Scope.Block, |
| 10510 | block: *Block, |
| 10129 | 10511 | src: LazySrcLoc, |
| 10130 | 10512 | raw_ptr: Air.Inst.Ref, |
| 10131 | 10513 | field_name: []const u8, |
| ... | ... | @@ -10134,13 +10516,12 @@ fn fieldCallBind( |
| 10134 | 10516 | // When editing this function, note that there is corresponding logic to be edited |
| 10135 | 10517 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 10136 | 10518 | |
| 10137 | | const mod = sema.mod; |
| 10138 | 10519 | const raw_ptr_src = src; // TODO better source location |
| 10139 | 10520 | const raw_ptr_ty = sema.typeOf(raw_ptr); |
| 10140 | 10521 | const inner_ty = if (raw_ptr_ty.zigTypeTag() == .Pointer and raw_ptr_ty.ptrSize() == .One) |
| 10141 | 10522 | raw_ptr_ty.childType() |
| 10142 | 10523 | else |
| 10143 | | return mod.fail(&block.base, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty}); |
| 10524 | return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty}); |
| 10144 | 10525 | |
| 10145 | 10526 | // Optionally dereference a second pointer to get the concrete type. |
| 10146 | 10527 | const is_double_ptr = inner_ty.zigTypeTag() == .Pointer and inner_ty.ptrSize() == .One; |
| ... | ... | @@ -10209,7 +10590,7 @@ fn fieldCallBind( |
| 10209 | 10590 | }; |
| 10210 | 10591 | return sema.analyzeLoad(block, src, ptr_inst, src); |
| 10211 | 10592 | }, |
| 10212 | | .Union => return sema.mod.fail(&block.base, src, "TODO implement field calls on unions", .{}), |
| 10593 | .Union => return sema.fail(block, src, "TODO implement field calls on unions", .{}), |
| 10213 | 10594 | .Type => { |
| 10214 | 10595 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); |
| 10215 | 10596 | return sema.fieldVal(block, src, namespace, field_name, field_name_src); |
| ... | ... | @@ -10262,29 +10643,28 @@ fn fieldCallBind( |
| 10262 | 10643 | else => {}, |
| 10263 | 10644 | } |
| 10264 | 10645 | |
| 10265 | | return mod.fail(&block.base, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name }); |
| 10646 | return sema.fail(block, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name }); |
| 10266 | 10647 | } |
| 10267 | 10648 | |
| 10268 | 10649 | fn namespaceLookup( |
| 10269 | 10650 | sema: *Sema, |
| 10270 | | block: *Scope.Block, |
| 10651 | block: *Block, |
| 10271 | 10652 | src: LazySrcLoc, |
| 10272 | | namespace: *Scope.Namespace, |
| 10653 | namespace: *Namespace, |
| 10273 | 10654 | decl_name: []const u8, |
| 10274 | 10655 | ) CompileError!?*Decl { |
| 10275 | | const mod = sema.mod; |
| 10276 | 10656 | const gpa = sema.gpa; |
| 10277 | 10657 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { |
| 10278 | | if (!decl.is_pub and decl.namespace.file_scope != block.getFileScope()) { |
| 10658 | if (!decl.is_pub and decl.getFileScope() != block.getFileScope()) { |
| 10279 | 10659 | const msg = msg: { |
| 10280 | | const msg = try mod.errMsg(&block.base, src, "'{s}' is not marked 'pub'", .{ |
| 10660 | const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{ |
| 10281 | 10661 | decl_name, |
| 10282 | 10662 | }); |
| 10283 | 10663 | errdefer msg.destroy(gpa); |
| 10284 | | try mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{}); |
| 10664 | try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{}); |
| 10285 | 10665 | break :msg msg; |
| 10286 | 10666 | }; |
| 10287 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 10667 | return sema.failWithOwnedErrorMsg(msg); |
| 10288 | 10668 | } |
| 10289 | 10669 | return decl; |
| 10290 | 10670 | } |
| ... | ... | @@ -10293,9 +10673,9 @@ fn namespaceLookup( |
| 10293 | 10673 | |
| 10294 | 10674 | fn namespaceLookupRef( |
| 10295 | 10675 | sema: *Sema, |
| 10296 | | block: *Scope.Block, |
| 10676 | block: *Block, |
| 10297 | 10677 | src: LazySrcLoc, |
| 10298 | | namespace: *Scope.Namespace, |
| 10678 | namespace: *Namespace, |
| 10299 | 10679 | decl_name: []const u8, |
| 10300 | 10680 | ) CompileError!?Air.Inst.Ref { |
| 10301 | 10681 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| ... | ... | @@ -10304,7 +10684,7 @@ fn namespaceLookupRef( |
| 10304 | 10684 | |
| 10305 | 10685 | fn structFieldPtr( |
| 10306 | 10686 | sema: *Sema, |
| 10307 | | block: *Scope.Block, |
| 10687 | block: *Block, |
| 10308 | 10688 | src: LazySrcLoc, |
| 10309 | 10689 | struct_ptr: Air.Inst.Ref, |
| 10310 | 10690 | field_name: []const u8, |
| ... | ... | @@ -10344,7 +10724,7 @@ fn structFieldPtr( |
| 10344 | 10724 | |
| 10345 | 10725 | fn structFieldVal( |
| 10346 | 10726 | sema: *Sema, |
| 10347 | | block: *Scope.Block, |
| 10727 | block: *Block, |
| 10348 | 10728 | src: LazySrcLoc, |
| 10349 | 10729 | struct_byval: Air.Inst.Ref, |
| 10350 | 10730 | field_name: []const u8, |
| ... | ... | @@ -10382,7 +10762,7 @@ fn structFieldVal( |
| 10382 | 10762 | |
| 10383 | 10763 | fn unionFieldPtr( |
| 10384 | 10764 | sema: *Sema, |
| 10385 | | block: *Scope.Block, |
| 10765 | block: *Block, |
| 10386 | 10766 | src: LazySrcLoc, |
| 10387 | 10767 | union_ptr: Air.Inst.Ref, |
| 10388 | 10768 | field_name: []const u8, |
| ... | ... | @@ -10424,7 +10804,7 @@ fn unionFieldPtr( |
| 10424 | 10804 | |
| 10425 | 10805 | fn unionFieldVal( |
| 10426 | 10806 | sema: *Sema, |
| 10427 | | block: *Scope.Block, |
| 10807 | block: *Block, |
| 10428 | 10808 | src: LazySrcLoc, |
| 10429 | 10809 | union_byval: Air.Inst.Ref, |
| 10430 | 10810 | field_name: []const u8, |
| ... | ... | @@ -10450,12 +10830,12 @@ fn unionFieldVal( |
| 10450 | 10830 | } |
| 10451 | 10831 | |
| 10452 | 10832 | try sema.requireRuntimeBlock(block, src); |
| 10453 | | return sema.mod.fail(&block.base, src, "TODO implement runtime union field access", .{}); |
| 10833 | return sema.fail(block, src, "TODO implement runtime union field access", .{}); |
| 10454 | 10834 | } |
| 10455 | 10835 | |
| 10456 | 10836 | fn elemPtr( |
| 10457 | 10837 | sema: *Sema, |
| 10458 | | block: *Scope.Block, |
| 10838 | block: *Block, |
| 10459 | 10839 | src: LazySrcLoc, |
| 10460 | 10840 | array_ptr: Air.Inst.Ref, |
| 10461 | 10841 | elem_index: Air.Inst.Ref, |
| ... | ... | @@ -10465,10 +10845,10 @@ fn elemPtr( |
| 10465 | 10845 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 10466 | 10846 | const array_ty = switch (array_ptr_ty.zigTypeTag()) { |
| 10467 | 10847 | .Pointer => array_ptr_ty.elemType(), |
| 10468 | | else => return sema.mod.fail(&block.base, array_ptr_src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 10848 | else => return sema.fail(block, array_ptr_src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 10469 | 10849 | }; |
| 10470 | 10850 | if (!array_ty.isIndexable()) { |
| 10471 | | return sema.mod.fail(&block.base, src, "array access of non-array type '{}'", .{array_ty}); |
| 10851 | return sema.fail(block, src, "array access of non-array type '{}'", .{array_ty}); |
| 10472 | 10852 | } |
| 10473 | 10853 | if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) { |
| 10474 | 10854 | // we have to deref the ptr operand to get the actual array pointer |
| ... | ... | @@ -10479,12 +10859,12 @@ fn elemPtr( |
| 10479 | 10859 | return sema.elemPtrArray(block, src, array_ptr, elem_index, elem_index_src); |
| 10480 | 10860 | } |
| 10481 | 10861 | |
| 10482 | | return sema.mod.fail(&block.base, src, "TODO implement more analyze elemptr", .{}); |
| 10862 | return sema.fail(block, src, "TODO implement more analyze elemptr", .{}); |
| 10483 | 10863 | } |
| 10484 | 10864 | |
| 10485 | 10865 | fn elemVal( |
| 10486 | 10866 | sema: *Sema, |
| 10487 | | block: *Scope.Block, |
| 10867 | block: *Block, |
| 10488 | 10868 | src: LazySrcLoc, |
| 10489 | 10869 | array_maybe_ptr: Air.Inst.Ref, |
| 10490 | 10870 | elem_index: Air.Inst.Ref, |
| ... | ... | @@ -10497,7 +10877,7 @@ fn elemVal( |
| 10497 | 10877 | .Slice => { |
| 10498 | 10878 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |slice_val| { |
| 10499 | 10879 | _ = slice_val; |
| 10500 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10880 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10501 | 10881 | } |
| 10502 | 10882 | try sema.requireRuntimeBlock(block, src); |
| 10503 | 10883 | return block.addBinOp(.slice_elem_val, array_maybe_ptr, elem_index); |
| ... | ... | @@ -10505,7 +10885,7 @@ fn elemVal( |
| 10505 | 10885 | .Many, .C => { |
| 10506 | 10886 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |ptr_val| { |
| 10507 | 10887 | _ = ptr_val; |
| 10508 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10888 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10509 | 10889 | } |
| 10510 | 10890 | try sema.requireRuntimeBlock(block, src); |
| 10511 | 10891 | return block.addBinOp(.ptr_elem_val, array_maybe_ptr, elem_index); |
| ... | ... | @@ -10520,7 +10900,7 @@ fn elemVal( |
| 10520 | 10900 | const slice = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10521 | 10901 | if (try sema.resolveDefinedValue(block, src, slice)) |slice_val| { |
| 10522 | 10902 | _ = slice_val; |
| 10523 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10903 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10524 | 10904 | } |
| 10525 | 10905 | try sema.requireRuntimeBlock(block, src); |
| 10526 | 10906 | return block.addBinOp(.slice_elem_val, slice, elem_index); |
| ... | ... | @@ -10534,7 +10914,7 @@ fn elemVal( |
| 10534 | 10914 | const ptr = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10535 | 10915 | if (try sema.resolveDefinedValue(block, src, ptr)) |ptr_val| { |
| 10536 | 10916 | _ = ptr_val; |
| 10537 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10917 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10538 | 10918 | } |
| 10539 | 10919 | try sema.requireRuntimeBlock(block, src); |
| 10540 | 10920 | return block.addBinOp(.ptr_elem_val, ptr, elem_index); |
| ... | ... | @@ -10542,8 +10922,8 @@ fn elemVal( |
| 10542 | 10922 | try sema.requireRuntimeBlock(block, src); |
| 10543 | 10923 | return block.addBinOp(.ptr_ptr_elem_val, array_maybe_ptr, elem_index); |
| 10544 | 10924 | }, |
| 10545 | | .One => return sema.mod.fail( |
| 10546 | | &block.base, |
| 10925 | .One => return sema.fail( |
| 10926 | block, |
| 10547 | 10927 | array_ptr_src, |
| 10548 | 10928 | "expected pointer, found '{}'", |
| 10549 | 10929 | .{indexable_ty.elemType()}, |
| ... | ... | @@ -10553,8 +10933,8 @@ fn elemVal( |
| 10553 | 10933 | const ptr = try sema.elemPtr(block, src, array_maybe_ptr, elem_index, elem_index_src); |
| 10554 | 10934 | return sema.analyzeLoad(block, src, ptr, elem_index_src); |
| 10555 | 10935 | }, |
| 10556 | | else => return sema.mod.fail( |
| 10557 | | &block.base, |
| 10936 | else => return sema.fail( |
| 10937 | block, |
| 10558 | 10938 | array_ptr_src, |
| 10559 | 10939 | "expected pointer, found '{}'", |
| 10560 | 10940 | .{indexable_ty}, |
| ... | ... | @@ -10562,8 +10942,8 @@ fn elemVal( |
| 10562 | 10942 | } |
| 10563 | 10943 | }, |
| 10564 | 10944 | }, |
| 10565 | | else => return sema.mod.fail( |
| 10566 | | &block.base, |
| 10945 | else => return sema.fail( |
| 10946 | block, |
| 10567 | 10947 | array_ptr_src, |
| 10568 | 10948 | "expected pointer, found '{}'", |
| 10569 | 10949 | .{maybe_ptr_ty}, |
| ... | ... | @@ -10573,7 +10953,7 @@ fn elemVal( |
| 10573 | 10953 | |
| 10574 | 10954 | fn elemPtrArray( |
| 10575 | 10955 | sema: *Sema, |
| 10576 | | block: *Scope.Block, |
| 10956 | block: *Block, |
| 10577 | 10957 | src: LazySrcLoc, |
| 10578 | 10958 | array_ptr: Air.Inst.Ref, |
| 10579 | 10959 | elem_index: Air.Inst.Ref, |
| ... | ... | @@ -10613,7 +10993,7 @@ fn elemPtrArray( |
| 10613 | 10993 | |
| 10614 | 10994 | fn coerce( |
| 10615 | 10995 | sema: *Sema, |
| 10616 | | block: *Scope.Block, |
| 10996 | block: *Block, |
| 10617 | 10997 | dest_type_unresolved: Type, |
| 10618 | 10998 | inst: Air.Inst.Ref, |
| 10619 | 10999 | inst_src: LazySrcLoc, |
| ... | ... | @@ -10631,10 +11011,10 @@ fn coerce( |
| 10631 | 11011 | if (dest_type.eql(inst_ty)) |
| 10632 | 11012 | return inst; |
| 10633 | 11013 | |
| 10634 | | const mod = sema.mod; |
| 10635 | 11014 | const arena = sema.arena; |
| 11015 | const target = sema.mod.getTarget(); |
| 10636 | 11016 | |
| 10637 | | const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty, false, mod.getTarget()); |
| 11017 | const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty, false, target); |
| 10638 | 11018 | if (in_memory_result == .ok) { |
| 10639 | 11019 | return sema.bitcast(block, dest_type, inst, inst_src); |
| 10640 | 11020 | } |
| ... | ... | @@ -10651,8 +11031,6 @@ fn coerce( |
| 10651 | 11031 | if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some| |
| 10652 | 11032 | return some; |
| 10653 | 11033 | |
| 10654 | | const target = mod.getTarget(); |
| 10655 | | |
| 10656 | 11034 | switch (dest_type.zigTypeTag()) { |
| 10657 | 11035 | .Optional => { |
| 10658 | 11036 | // null to ?T |
| ... | ... | @@ -10679,7 +11057,7 @@ fn coerce( |
| 10679 | 11057 | if (inst_ty.ptrAddressSpace() != dest_type.ptrAddressSpace()) break :src_array_ptr; |
| 10680 | 11058 | |
| 10681 | 11059 | const dst_elem_type = dest_type.elemType(); |
| 10682 | | switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type, dest_is_mut, mod.getTarget())) { |
| 11060 | switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type, dest_is_mut, target)) { |
| 10683 | 11061 | .ok => {}, |
| 10684 | 11062 | .no_match => break :src_array_ptr, |
| 10685 | 11063 | } |
| ... | ... | @@ -10748,14 +11126,14 @@ fn coerce( |
| 10748 | 11126 | const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type); |
| 10749 | 11127 | const field_index = resolved_dest_type.enumFieldIndex(bytes) orelse { |
| 10750 | 11128 | const msg = msg: { |
| 10751 | | const msg = try mod.errMsg( |
| 10752 | | &block.base, |
| 11129 | const msg = try sema.errMsg( |
| 11130 | block, |
| 10753 | 11131 | inst_src, |
| 10754 | 11132 | "enum '{}' has no field named '{s}'", |
| 10755 | 11133 | .{ resolved_dest_type, bytes }, |
| 10756 | 11134 | ); |
| 10757 | 11135 | errdefer msg.destroy(sema.gpa); |
| 10758 | | try mod.errNoteNonLazy( |
| 11136 | try sema.mod.errNoteNonLazy( |
| 10759 | 11137 | resolved_dest_type.declSrcLoc(), |
| 10760 | 11138 | msg, |
| 10761 | 11139 | "enum declared here", |
| ... | ... | @@ -10763,7 +11141,7 @@ fn coerce( |
| 10763 | 11141 | ); |
| 10764 | 11142 | break :msg msg; |
| 10765 | 11143 | }; |
| 10766 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 11144 | return sema.failWithOwnedErrorMsg(msg); |
| 10767 | 11145 | }; |
| 10768 | 11146 | return sema.addConstant( |
| 10769 | 11147 | resolved_dest_type, |
| ... | ... | @@ -10786,7 +11164,7 @@ fn coerce( |
| 10786 | 11164 | else => {}, |
| 10787 | 11165 | } |
| 10788 | 11166 | |
| 10789 | | return mod.fail(&block.base, inst_src, "expected {}, found {}", .{ dest_type, inst_ty }); |
| 11167 | return sema.fail(block, inst_src, "expected {}, found {}", .{ dest_type, inst_ty }); |
| 10790 | 11168 | } |
| 10791 | 11169 | |
| 10792 | 11170 | const InMemoryCoercionResult = enum { |
| ... | ... | @@ -10887,7 +11265,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type, dest_is_mut: bool, tar |
| 10887 | 11265 | |
| 10888 | 11266 | fn coerceNum( |
| 10889 | 11267 | sema: *Sema, |
| 10890 | | block: *Scope.Block, |
| 11268 | block: *Block, |
| 10891 | 11269 | dest_type: Type, |
| 10892 | 11270 | inst: Air.Inst.Ref, |
| 10893 | 11271 | inst_src: LazySrcLoc, |
| ... | ... | @@ -10903,13 +11281,13 @@ fn coerceNum( |
| 10903 | 11281 | .ComptimeInt, .Int => switch (src_zig_tag) { |
| 10904 | 11282 | .Float, .ComptimeFloat => { |
| 10905 | 11283 | if (val.floatHasFraction()) { |
| 10906 | | return sema.mod.fail(&block.base, inst_src, "fractional component prevents float value {} from coercion to type '{}'", .{ val, dest_type }); |
| 11284 | return sema.fail(block, inst_src, "fractional component prevents float value {} from coercion to type '{}'", .{ val, dest_type }); |
| 10907 | 11285 | } |
| 10908 | | return sema.mod.fail(&block.base, inst_src, "TODO float to int", .{}); |
| 11286 | return sema.fail(block, inst_src, "TODO float to int", .{}); |
| 10909 | 11287 | }, |
| 10910 | 11288 | .Int, .ComptimeInt => { |
| 10911 | 11289 | if (!val.intFitsInType(dest_type, target)) { |
| 10912 | | return sema.mod.fail(&block.base, inst_src, "type {} cannot represent integer value {}", .{ dest_type, val }); |
| 11290 | return sema.fail(block, inst_src, "type {} cannot represent integer value {}", .{ dest_type, val }); |
| 10913 | 11291 | } |
| 10914 | 11292 | return try sema.addConstant(dest_type, val); |
| 10915 | 11293 | }, |
| ... | ... | @@ -10923,8 +11301,8 @@ fn coerceNum( |
| 10923 | 11301 | .Float => { |
| 10924 | 11302 | const result_val = try val.floatCast(sema.arena, dest_type); |
| 10925 | 11303 | if (!val.eql(result_val, dest_type)) { |
| 10926 | | return sema.mod.fail( |
| 10927 | | &block.base, |
| 11304 | return sema.fail( |
| 11305 | block, |
| 10928 | 11306 | inst_src, |
| 10929 | 11307 | "type {} cannot represent float value {}", |
| 10930 | 11308 | .{ dest_type, val }, |
| ... | ... | @@ -10937,8 +11315,8 @@ fn coerceNum( |
| 10937 | 11315 | // TODO implement this compile error |
| 10938 | 11316 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); |
| 10939 | 11317 | //if (!int_again_val.eql(val, inst_ty)) { |
| 10940 | | // return sema.mod.fail( |
| 10941 | | // &block.base, |
| 11318 | // return sema.fail( |
| 11319 | // block, |
| 10942 | 11320 | // inst_src, |
| 10943 | 11321 | // "type {} cannot represent integer value {}", |
| 10944 | 11322 | // .{ dest_type, val }, |
| ... | ... | @@ -10955,13 +11333,13 @@ fn coerceNum( |
| 10955 | 11333 | |
| 10956 | 11334 | fn coerceVarArgParam( |
| 10957 | 11335 | sema: *Sema, |
| 10958 | | block: *Scope.Block, |
| 11336 | block: *Block, |
| 10959 | 11337 | inst: Air.Inst.Ref, |
| 10960 | 11338 | inst_src: LazySrcLoc, |
| 10961 | 11339 | ) !Air.Inst.Ref { |
| 10962 | 11340 | const inst_ty = sema.typeOf(inst); |
| 10963 | 11341 | switch (inst_ty.zigTypeTag()) { |
| 10964 | | .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}), |
| 11342 | .ComptimeInt, .ComptimeFloat => return sema.fail(block, inst_src, "integer and float literals in var args function must be casted", .{}), |
| 10965 | 11343 | else => {}, |
| 10966 | 11344 | } |
| 10967 | 11345 | // TODO implement more of this function. |
| ... | ... | @@ -10971,17 +11349,17 @@ fn coerceVarArgParam( |
| 10971 | 11349 | // TODO migrate callsites to use storePtr2 instead. |
| 10972 | 11350 | fn storePtr( |
| 10973 | 11351 | sema: *Sema, |
| 10974 | | block: *Scope.Block, |
| 11352 | block: *Block, |
| 10975 | 11353 | src: LazySrcLoc, |
| 10976 | 11354 | ptr: Air.Inst.Ref, |
| 10977 | 11355 | uncasted_operand: Air.Inst.Ref, |
| 10978 | | ) !void { |
| 11356 | ) CompileError!void { |
| 10979 | 11357 | return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store); |
| 10980 | 11358 | } |
| 10981 | 11359 | |
| 10982 | 11360 | fn storePtr2( |
| 10983 | 11361 | sema: *Sema, |
| 10984 | | block: *Scope.Block, |
| 11362 | block: *Block, |
| 10985 | 11363 | src: LazySrcLoc, |
| 10986 | 11364 | ptr: Air.Inst.Ref, |
| 10987 | 11365 | ptr_src: LazySrcLoc, |
| ... | ... | @@ -10991,7 +11369,7 @@ fn storePtr2( |
| 10991 | 11369 | ) !void { |
| 10992 | 11370 | const ptr_ty = sema.typeOf(ptr); |
| 10993 | 11371 | if (ptr_ty.isConstPtr()) |
| 10994 | | return sema.mod.fail(&block.base, src, "cannot assign to constant", .{}); |
| 11372 | return sema.fail(block, src, "cannot assign to constant", .{}); |
| 10995 | 11373 | |
| 10996 | 11374 | const elem_ty = ptr_ty.elemType(); |
| 10997 | 11375 | const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src); |
| ... | ... | @@ -11000,7 +11378,7 @@ fn storePtr2( |
| 11000 | 11378 | |
| 11001 | 11379 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 11002 | 11380 | const operand_val = (try sema.resolveMaybeUndefVal(block, operand_src, operand)) orelse |
| 11003 | | return sema.mod.fail(&block.base, src, "cannot store runtime value in compile time variable", .{}); |
| 11381 | return sema.fail(block, src, "cannot store runtime value in compile time variable", .{}); |
| 11004 | 11382 | if (ptr_val.tag() == .decl_ref_mut) { |
| 11005 | 11383 | try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty); |
| 11006 | 11384 | return; |
| ... | ... | @@ -11018,7 +11396,7 @@ fn storePtr2( |
| 11018 | 11396 | /// assert the store must be done at comptime. |
| 11019 | 11397 | fn storePtrVal( |
| 11020 | 11398 | sema: *Sema, |
| 11021 | | block: *Scope.Block, |
| 11399 | block: *Block, |
| 11022 | 11400 | src: LazySrcLoc, |
| 11023 | 11401 | ptr_val: Value, |
| 11024 | 11402 | operand_val: Value, |
| ... | ... | @@ -11028,21 +11406,21 @@ fn storePtrVal( |
| 11028 | 11406 | if (decl_ref_mut.data.runtime_index < block.runtime_index) { |
| 11029 | 11407 | if (block.runtime_cond) |cond_src| { |
| 11030 | 11408 | const msg = msg: { |
| 11031 | | const msg = try sema.mod.errMsg(&block.base, src, "store to comptime variable depends on runtime condition", .{}); |
| 11409 | const msg = try sema.errMsg(block, src, "store to comptime variable depends on runtime condition", .{}); |
| 11032 | 11410 | errdefer msg.destroy(sema.gpa); |
| 11033 | | try sema.mod.errNote(&block.base, cond_src, msg, "runtime condition here", .{}); |
| 11411 | try sema.errNote(block, cond_src, msg, "runtime condition here", .{}); |
| 11034 | 11412 | break :msg msg; |
| 11035 | 11413 | }; |
| 11036 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 11414 | return sema.failWithOwnedErrorMsg(msg); |
| 11037 | 11415 | } |
| 11038 | 11416 | if (block.runtime_loop) |loop_src| { |
| 11039 | 11417 | const msg = msg: { |
| 11040 | | const msg = try sema.mod.errMsg(&block.base, src, "cannot store to comptime variable in non-inline loop", .{}); |
| 11418 | const msg = try sema.errMsg(block, src, "cannot store to comptime variable in non-inline loop", .{}); |
| 11041 | 11419 | errdefer msg.destroy(sema.gpa); |
| 11042 | | try sema.mod.errNote(&block.base, loop_src, msg, "non-inline loop here", .{}); |
| 11420 | try sema.errNote(block, loop_src, msg, "non-inline loop here", .{}); |
| 11043 | 11421 | break :msg msg; |
| 11044 | 11422 | }; |
| 11045 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 11423 | return sema.failWithOwnedErrorMsg(msg); |
| 11046 | 11424 | } |
| 11047 | 11425 | unreachable; |
| 11048 | 11426 | } |
| ... | ... | @@ -11063,7 +11441,7 @@ fn storePtrVal( |
| 11063 | 11441 | |
| 11064 | 11442 | fn bitcast( |
| 11065 | 11443 | sema: *Sema, |
| 11066 | | block: *Scope.Block, |
| 11444 | block: *Block, |
| 11067 | 11445 | dest_type: Type, |
| 11068 | 11446 | inst: Air.Inst.Ref, |
| 11069 | 11447 | inst_src: LazySrcLoc, |
| ... | ... | @@ -11079,7 +11457,7 @@ fn bitcast( |
| 11079 | 11457 | |
| 11080 | 11458 | fn coerceArrayPtrToSlice( |
| 11081 | 11459 | sema: *Sema, |
| 11082 | | block: *Scope.Block, |
| 11460 | block: *Block, |
| 11083 | 11461 | dest_type: Type, |
| 11084 | 11462 | inst: Air.Inst.Ref, |
| 11085 | 11463 | inst_src: LazySrcLoc, |
| ... | ... | @@ -11094,7 +11472,7 @@ fn coerceArrayPtrToSlice( |
| 11094 | 11472 | |
| 11095 | 11473 | fn coerceArrayPtrToMany( |
| 11096 | 11474 | sema: *Sema, |
| 11097 | | block: *Scope.Block, |
| 11475 | block: *Block, |
| 11098 | 11476 | dest_type: Type, |
| 11099 | 11477 | inst: Air.Inst.Ref, |
| 11100 | 11478 | inst_src: LazySrcLoc, |
| ... | ... | @@ -11109,7 +11487,7 @@ fn coerceArrayPtrToMany( |
| 11109 | 11487 | |
| 11110 | 11488 | fn analyzeDeclVal( |
| 11111 | 11489 | sema: *Sema, |
| 11112 | | block: *Scope.Block, |
| 11490 | block: *Block, |
| 11113 | 11491 | src: LazySrcLoc, |
| 11114 | 11492 | decl: *Decl, |
| 11115 | 11493 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -11163,7 +11541,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { |
| 11163 | 11541 | |
| 11164 | 11542 | fn analyzeRef( |
| 11165 | 11543 | sema: *Sema, |
| 11166 | | block: *Scope.Block, |
| 11544 | block: *Block, |
| 11167 | 11545 | src: LazySrcLoc, |
| 11168 | 11546 | operand: Air.Inst.Ref, |
| 11169 | 11547 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -11198,7 +11576,7 @@ fn analyzeRef( |
| 11198 | 11576 | |
| 11199 | 11577 | fn analyzeLoad( |
| 11200 | 11578 | sema: *Sema, |
| 11201 | | block: *Scope.Block, |
| 11579 | block: *Block, |
| 11202 | 11580 | src: LazySrcLoc, |
| 11203 | 11581 | ptr: Air.Inst.Ref, |
| 11204 | 11582 | ptr_src: LazySrcLoc, |
| ... | ... | @@ -11206,7 +11584,7 @@ fn analyzeLoad( |
| 11206 | 11584 | const ptr_ty = sema.typeOf(ptr); |
| 11207 | 11585 | const elem_ty = switch (ptr_ty.zigTypeTag()) { |
| 11208 | 11586 | .Pointer => ptr_ty.elemType(), |
| 11209 | | else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}), |
| 11587 | else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty}), |
| 11210 | 11588 | }; |
| 11211 | 11589 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { |
| 11212 | 11590 | if (try ptr_val.pointerDeref(sema.arena)) |elem_val| { |
| ... | ... | @@ -11220,7 +11598,7 @@ fn analyzeLoad( |
| 11220 | 11598 | |
| 11221 | 11599 | fn analyzeSliceLen( |
| 11222 | 11600 | sema: *Sema, |
| 11223 | | block: *Scope.Block, |
| 11601 | block: *Block, |
| 11224 | 11602 | src: LazySrcLoc, |
| 11225 | 11603 | slice_inst: Air.Inst.Ref, |
| 11226 | 11604 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -11228,7 +11606,7 @@ fn analyzeSliceLen( |
| 11228 | 11606 | if (slice_val.isUndef()) { |
| 11229 | 11607 | return sema.addConstUndef(Type.initTag(.usize)); |
| 11230 | 11608 | } |
| 11231 | | return sema.mod.fail(&block.base, src, "TODO implement Sema analyzeSliceLen on comptime slice", .{}); |
| 11609 | return sema.fail(block, src, "TODO implement Sema analyzeSliceLen on comptime slice", .{}); |
| 11232 | 11610 | } |
| 11233 | 11611 | try sema.requireRuntimeBlock(block, src); |
| 11234 | 11612 | return block.addTyOp(.slice_len, Type.initTag(.usize), slice_inst); |
| ... | ... | @@ -11236,7 +11614,7 @@ fn analyzeSliceLen( |
| 11236 | 11614 | |
| 11237 | 11615 | fn analyzeIsNull( |
| 11238 | 11616 | sema: *Sema, |
| 11239 | | block: *Scope.Block, |
| 11617 | block: *Block, |
| 11240 | 11618 | src: LazySrcLoc, |
| 11241 | 11619 | operand: Air.Inst.Ref, |
| 11242 | 11620 | invert_logic: bool, |
| ... | ... | @@ -11261,7 +11639,7 @@ fn analyzeIsNull( |
| 11261 | 11639 | |
| 11262 | 11640 | fn analyzeIsNonErr( |
| 11263 | 11641 | sema: *Sema, |
| 11264 | | block: *Scope.Block, |
| 11642 | block: *Block, |
| 11265 | 11643 | src: LazySrcLoc, |
| 11266 | 11644 | operand: Air.Inst.Ref, |
| 11267 | 11645 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -11287,7 +11665,7 @@ fn analyzeIsNonErr( |
| 11287 | 11665 | |
| 11288 | 11666 | fn analyzeSlice( |
| 11289 | 11667 | sema: *Sema, |
| 11290 | | block: *Scope.Block, |
| 11668 | block: *Block, |
| 11291 | 11669 | src: LazySrcLoc, |
| 11292 | 11670 | array_ptr: Air.Inst.Ref, |
| 11293 | 11671 | start: Air.Inst.Ref, |
| ... | ... | @@ -11298,7 +11676,7 @@ fn analyzeSlice( |
| 11298 | 11676 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 11299 | 11677 | const ptr_child = switch (array_ptr_ty.zigTypeTag()) { |
| 11300 | 11678 | .Pointer => array_ptr_ty.elemType(), |
| 11301 | | else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 11679 | else => return sema.fail(block, src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 11302 | 11680 | }; |
| 11303 | 11681 | |
| 11304 | 11682 | var array_type = ptr_child; |
| ... | ... | @@ -11311,11 +11689,11 @@ fn analyzeSlice( |
| 11311 | 11689 | break :blk ptr_child.elemType().elemType(); |
| 11312 | 11690 | } |
| 11313 | 11691 | |
| 11314 | | return sema.mod.fail(&block.base, src, "slice of single-item pointer", .{}); |
| 11692 | return sema.fail(block, src, "slice of single-item pointer", .{}); |
| 11315 | 11693 | } |
| 11316 | 11694 | break :blk ptr_child.elemType(); |
| 11317 | 11695 | }, |
| 11318 | | else => return sema.mod.fail(&block.base, src, "slice of non-array type '{}'", .{ptr_child}), |
| 11696 | else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_child}), |
| 11319 | 11697 | }; |
| 11320 | 11698 | |
| 11321 | 11699 | const slice_sentinel = if (sentinel_opt != .none) blk: { |
| ... | ... | @@ -11331,7 +11709,7 @@ fn analyzeSlice( |
| 11331 | 11709 | const start_u64 = start_val.toUnsignedInt(); |
| 11332 | 11710 | const end_u64 = end_val.toUnsignedInt(); |
| 11333 | 11711 | if (start_u64 > end_u64) { |
| 11334 | | return sema.mod.fail(&block.base, src, "out of bounds slice", .{}); |
| 11712 | return sema.fail(block, src, "out of bounds slice", .{}); |
| 11335 | 11713 | } |
| 11336 | 11714 | |
| 11337 | 11715 | const len = end_u64 - start_u64; |
| ... | ... | @@ -11356,13 +11734,13 @@ fn analyzeSlice( |
| 11356 | 11734 | }); |
| 11357 | 11735 | _ = return_type; |
| 11358 | 11736 | |
| 11359 | | return sema.mod.fail(&block.base, src, "TODO implement analysis of slice", .{}); |
| 11737 | return sema.fail(block, src, "TODO implement analysis of slice", .{}); |
| 11360 | 11738 | } |
| 11361 | 11739 | |
| 11362 | 11740 | /// Asserts that lhs and rhs types are both numeric. |
| 11363 | 11741 | fn cmpNumeric( |
| 11364 | 11742 | sema: *Sema, |
| 11365 | | block: *Scope.Block, |
| 11743 | block: *Block, |
| 11366 | 11744 | src: LazySrcLoc, |
| 11367 | 11745 | lhs: Air.Inst.Ref, |
| 11368 | 11746 | rhs: Air.Inst.Ref, |
| ... | ... | @@ -11381,13 +11759,13 @@ fn cmpNumeric( |
| 11381 | 11759 | |
| 11382 | 11760 | if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) { |
| 11383 | 11761 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { |
| 11384 | | return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{ |
| 11762 | return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{ |
| 11385 | 11763 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), |
| 11386 | 11764 | }); |
| 11387 | 11765 | } |
| 11388 | | return sema.mod.fail(&block.base, src, "TODO implement support for vectors in cmpNumeric", .{}); |
| 11766 | return sema.fail(block, src, "TODO implement support for vectors in cmpNumeric", .{}); |
| 11389 | 11767 | } else if (lhs_ty_tag == .Vector or rhs_ty_tag == .Vector) { |
| 11390 | | return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to comparison operator: '{}' and '{}'", .{ |
| 11768 | return sema.fail(block, src, "mixed scalar and vector operands to comparison operator: '{}' and '{}'", .{ |
| 11391 | 11769 | lhs_ty, rhs_ty, |
| 11392 | 11770 | }); |
| 11393 | 11771 | } |
| ... | ... | @@ -11537,7 +11915,7 @@ fn cmpNumeric( |
| 11537 | 11915 | const dest_type = if (dest_float_type) |ft| ft else blk: { |
| 11538 | 11916 | const max_bits = std.math.max(lhs_bits, rhs_bits); |
| 11539 | 11917 | const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) { |
| 11540 | | error.Overflow => return sema.mod.fail(&block.base, src, "{d} exceeds maximum integer bit count", .{max_bits}), |
| 11918 | error.Overflow => return sema.fail(block, src, "{d} exceeds maximum integer bit count", .{max_bits}), |
| 11541 | 11919 | }; |
| 11542 | 11920 | const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; |
| 11543 | 11921 | break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); |
| ... | ... | @@ -11550,7 +11928,7 @@ fn cmpNumeric( |
| 11550 | 11928 | |
| 11551 | 11929 | fn wrapOptional( |
| 11552 | 11930 | sema: *Sema, |
| 11553 | | block: *Scope.Block, |
| 11931 | block: *Block, |
| 11554 | 11932 | dest_type: Type, |
| 11555 | 11933 | inst: Air.Inst.Ref, |
| 11556 | 11934 | inst_src: LazySrcLoc, |
| ... | ... | @@ -11565,7 +11943,7 @@ fn wrapOptional( |
| 11565 | 11943 | |
| 11566 | 11944 | fn wrapErrorUnion( |
| 11567 | 11945 | sema: *Sema, |
| 11568 | | block: *Scope.Block, |
| 11946 | block: *Block, |
| 11569 | 11947 | dest_type: Type, |
| 11570 | 11948 | inst: Air.Inst.Ref, |
| 11571 | 11949 | inst_src: LazySrcLoc, |
| ... | ... | @@ -11584,8 +11962,8 @@ fn wrapErrorUnion( |
| 11584 | 11962 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11585 | 11963 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; |
| 11586 | 11964 | if (!mem.eql(u8, expected_name, n)) { |
| 11587 | | return sema.mod.fail( |
| 11588 | | &block.base, |
| 11965 | return sema.fail( |
| 11966 | block, |
| 11589 | 11967 | inst_src, |
| 11590 | 11968 | "expected type '{}', found type '{}'", |
| 11591 | 11969 | .{ dest_err_set_ty, inst_ty }, |
| ... | ... | @@ -11602,8 +11980,8 @@ fn wrapErrorUnion( |
| 11602 | 11980 | if (mem.eql(u8, expected_name, name)) break true; |
| 11603 | 11981 | } else false; |
| 11604 | 11982 | if (!found) { |
| 11605 | | return sema.mod.fail( |
| 11606 | | &block.base, |
| 11983 | return sema.fail( |
| 11984 | block, |
| 11607 | 11985 | inst_src, |
| 11608 | 11986 | "expected type '{}', found type '{}'", |
| 11609 | 11987 | .{ dest_err_set_ty, inst_ty }, |
| ... | ... | @@ -11614,8 +11992,8 @@ fn wrapErrorUnion( |
| 11614 | 11992 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11615 | 11993 | const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map; |
| 11616 | 11994 | if (!map.contains(expected_name)) { |
| 11617 | | return sema.mod.fail( |
| 11618 | | &block.base, |
| 11995 | return sema.fail( |
| 11996 | block, |
| 11619 | 11997 | inst_src, |
| 11620 | 11998 | "expected type '{}', found type '{}'", |
| 11621 | 11999 | .{ dest_err_set_ty, inst_ty }, |
| ... | ... | @@ -11641,7 +12019,7 @@ fn wrapErrorUnion( |
| 11641 | 12019 | |
| 11642 | 12020 | fn unionToTag( |
| 11643 | 12021 | sema: *Sema, |
| 11644 | | block: *Scope.Block, |
| 12022 | block: *Block, |
| 11645 | 12023 | dest_type: Type, |
| 11646 | 12024 | un: Air.Inst.Ref, |
| 11647 | 12025 | un_src: LazySrcLoc, |
| ... | ... | @@ -11655,7 +12033,7 @@ fn unionToTag( |
| 11655 | 12033 | |
| 11656 | 12034 | fn resolvePeerTypes( |
| 11657 | 12035 | sema: *Sema, |
| 11658 | | block: *Scope.Block, |
| 12036 | block: *Block, |
| 11659 | 12037 | src: LazySrcLoc, |
| 11660 | 12038 | instructions: []Air.Inst.Ref, |
| 11661 | 12039 | candidate_srcs: Module.PeerTypeCandidateSrc, |
| ... | ... | @@ -11750,18 +12128,18 @@ fn resolvePeerTypes( |
| 11750 | 12128 | ); |
| 11751 | 12129 | |
| 11752 | 12130 | const msg = msg: { |
| 11753 | | const msg = try sema.mod.errMsg(&block.base, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty }); |
| 12131 | const msg = try sema.errMsg(block, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty }); |
| 11754 | 12132 | errdefer msg.destroy(sema.gpa); |
| 11755 | 12133 | |
| 11756 | 12134 | if (chosen_src) |src_loc| |
| 11757 | | try sema.mod.errNote(&block.base, src_loc, msg, "type '{}' here", .{chosen_ty}); |
| 12135 | try sema.errNote(block, src_loc, msg, "type '{}' here", .{chosen_ty}); |
| 11758 | 12136 | |
| 11759 | 12137 | if (candidate_src) |src_loc| |
| 11760 | | try sema.mod.errNote(&block.base, src_loc, msg, "type '{}' here", .{candidate_ty}); |
| 12138 | try sema.errNote(block, src_loc, msg, "type '{}' here", .{candidate_ty}); |
| 11761 | 12139 | |
| 11762 | 12140 | break :msg msg; |
| 11763 | 12141 | }; |
| 11764 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 12142 | return sema.failWithOwnedErrorMsg(msg); |
| 11765 | 12143 | } |
| 11766 | 12144 | |
| 11767 | 12145 | return sema.typeOf(chosen); |
| ... | ... | @@ -11769,7 +12147,7 @@ fn resolvePeerTypes( |
| 11769 | 12147 | |
| 11770 | 12148 | pub fn resolveTypeLayout( |
| 11771 | 12149 | sema: *Sema, |
| 11772 | | block: *Scope.Block, |
| 12150 | block: *Block, |
| 11773 | 12151 | src: LazySrcLoc, |
| 11774 | 12152 | ty: Type, |
| 11775 | 12153 | ) CompileError!void { |
| ... | ... | @@ -11780,7 +12158,7 @@ pub fn resolveTypeLayout( |
| 11780 | 12158 | switch (struct_obj.status) { |
| 11781 | 12159 | .none, .have_field_types => {}, |
| 11782 | 12160 | .field_types_wip, .layout_wip => { |
| 11783 | | return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty}); |
| 12161 | return sema.fail(block, src, "struct {} depends on itself", .{ty}); |
| 11784 | 12162 | }, |
| 11785 | 12163 | .have_layout => return, |
| 11786 | 12164 | } |
| ... | ... | @@ -11794,78 +12172,23 @@ pub fn resolveTypeLayout( |
| 11794 | 12172 | } |
| 11795 | 12173 | } |
| 11796 | 12174 | |
| 11797 | | pub fn resolvePendingTypes(sema: *Sema, block: *Scope.Block) !void { |
| 11798 | | for (sema.types_pending_resolution.items) |ty| { |
| 11799 | | // If an error happens resolving the fields of a struct, it will be marked |
| 11800 | | // invalid and a proper compile error set up. But we should still look at the |
| 11801 | | // other types pending resolution. |
| 11802 | | const src: LazySrcLoc = .{ .node_offset = 0 }; |
| 11803 | | sema.resolveDeclFields(block, src, ty) catch continue; |
| 11804 | | } |
| 11805 | | } |
| 11806 | | |
| 11807 | | /// `sema` and `block` are expected to be the same ones used for the `Decl`. |
| 11808 | | pub fn resolveDeclFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) !void { |
| 12175 | fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type { |
| 11809 | 12176 | switch (ty.tag()) { |
| 11810 | 12177 | .@"struct" => { |
| 11811 | 12178 | const struct_obj = ty.castTag(.@"struct").?.data; |
| 11812 | | if (struct_obj.owner_decl.namespace != sema.owner_decl.namespace) return; |
| 11813 | 12179 | switch (struct_obj.status) { |
| 11814 | 12180 | .none => {}, |
| 11815 | 12181 | .field_types_wip => { |
| 11816 | | return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty}); |
| 12182 | return sema.fail(block, src, "struct {} depends on itself", .{ty}); |
| 11817 | 12183 | }, |
| 11818 | | .have_field_types, .have_layout, .layout_wip => return, |
| 12184 | .have_field_types, .have_layout, .layout_wip => return ty, |
| 11819 | 12185 | } |
| 11820 | | const prev_namespace = sema.namespace; |
| 11821 | | sema.namespace = &struct_obj.namespace; |
| 11822 | | defer sema.namespace = prev_namespace; |
| 11823 | | |
| 11824 | | const old_src = block.src_decl; |
| 11825 | | defer block.src_decl = old_src; |
| 11826 | | block.src_decl = struct_obj.owner_decl; |
| 11827 | 12186 | |
| 11828 | 12187 | struct_obj.status = .field_types_wip; |
| 11829 | | try sema.analyzeStructFields(block, struct_obj); |
| 12188 | try semaStructFields(sema.mod, struct_obj); |
| 11830 | 12189 | struct_obj.status = .have_field_types; |
| 11831 | | }, |
| 11832 | | .@"union", .union_tagged => { |
| 11833 | | const union_obj = ty.cast(Type.Payload.Union).?.data; |
| 11834 | | if (union_obj.owner_decl.namespace != sema.owner_decl.namespace) return; |
| 11835 | | switch (union_obj.status) { |
| 11836 | | .none => {}, |
| 11837 | | .field_types_wip => { |
| 11838 | | return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty}); |
| 11839 | | }, |
| 11840 | | .have_field_types, .have_layout, .layout_wip => return, |
| 11841 | | } |
| 11842 | | const prev_namespace = sema.namespace; |
| 11843 | | sema.namespace = &union_obj.namespace; |
| 11844 | | defer sema.namespace = prev_namespace; |
| 11845 | 12190 | |
| 11846 | | const old_src = block.src_decl; |
| 11847 | | defer block.src_decl = old_src; |
| 11848 | | block.src_decl = union_obj.owner_decl; |
| 11849 | | |
| 11850 | | union_obj.status = .field_types_wip; |
| 11851 | | try sema.analyzeUnionFields(block, union_obj); |
| 11852 | | union_obj.status = .have_field_types; |
| 11853 | | }, |
| 11854 | | else => return, |
| 11855 | | } |
| 11856 | | } |
| 11857 | | |
| 11858 | | fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type { |
| 11859 | | switch (ty.tag()) { |
| 11860 | | .@"struct" => { |
| 11861 | | const struct_obj = ty.castTag(.@"struct").?.data; |
| 11862 | | switch (struct_obj.status) { |
| 11863 | | .none => unreachable, |
| 11864 | | .field_types_wip => { |
| 11865 | | return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty}); |
| 11866 | | }, |
| 11867 | | .have_field_types, .have_layout, .layout_wip => return ty, |
| 11868 | | } |
| 12191 | return ty; |
| 11869 | 12192 | }, |
| 11870 | 12193 | .type_info => return sema.resolveBuiltinTypeFields(block, src, "TypeInfo"), |
| 11871 | 12194 | .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"), |
| ... | ... | @@ -11881,12 +12204,18 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11881 | 12204 | .@"union", .union_tagged => { |
| 11882 | 12205 | const union_obj = ty.cast(Type.Payload.Union).?.data; |
| 11883 | 12206 | switch (union_obj.status) { |
| 11884 | | .none => unreachable, |
| 12207 | .none => {}, |
| 11885 | 12208 | .field_types_wip => { |
| 11886 | | return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty}); |
| 12209 | return sema.fail(block, src, "union {} depends on itself", .{ty}); |
| 11887 | 12210 | }, |
| 11888 | 12211 | .have_field_types, .have_layout, .layout_wip => return ty, |
| 11889 | 12212 | } |
| 12213 | |
| 12214 | union_obj.status = .field_types_wip; |
| 12215 | try semaUnionFields(sema.mod, union_obj); |
| 12216 | union_obj.status = .have_field_types; |
| 12217 | |
| 12218 | return ty; |
| 11890 | 12219 | }, |
| 11891 | 12220 | else => return ty, |
| 11892 | 12221 | } |
| ... | ... | @@ -11894,7 +12223,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11894 | 12223 | |
| 11895 | 12224 | fn resolveBuiltinTypeFields( |
| 11896 | 12225 | sema: *Sema, |
| 11897 | | block: *Scope.Block, |
| 12226 | block: *Block, |
| 11898 | 12227 | src: LazySrcLoc, |
| 11899 | 12228 | name: []const u8, |
| 11900 | 12229 | ) CompileError!Type { |
| ... | ... | @@ -11902,16 +12231,16 @@ fn resolveBuiltinTypeFields( |
| 11902 | 12231 | return sema.resolveTypeFields(block, src, resolved_ty); |
| 11903 | 12232 | } |
| 11904 | 12233 | |
| 11905 | | fn analyzeStructFields( |
| 11906 | | sema: *Sema, |
| 11907 | | block: *Scope.Block, |
| 12234 | fn semaStructFields( |
| 12235 | mod: *Module, |
| 11908 | 12236 | struct_obj: *Module.Struct, |
| 11909 | 12237 | ) CompileError!void { |
| 11910 | 12238 | const tracy = trace(@src()); |
| 11911 | 12239 | defer tracy.end(); |
| 11912 | 12240 | |
| 11913 | | const gpa = sema.gpa; |
| 11914 | | const zir = sema.code; |
| 12241 | const gpa = mod.gpa; |
| 12242 | const decl = struct_obj.owner_decl; |
| 12243 | const zir = struct_obj.namespace.file_scope.zir; |
| 11915 | 12244 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| 11916 | 12245 | assert(extended.opcode == .struct_decl); |
| 11917 | 12246 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); |
| ... | ... | @@ -11950,15 +12279,51 @@ fn analyzeStructFields( |
| 11950 | 12279 | } |
| 11951 | 12280 | extra_index += body.len; |
| 11952 | 12281 | |
| 11953 | | var decl_arena = struct_obj.owner_decl.value_arena.?.promote(gpa); |
| 11954 | | defer struct_obj.owner_decl.value_arena.?.* = decl_arena.state; |
| 12282 | var decl_arena = decl.value_arena.?.promote(gpa); |
| 12283 | defer decl.value_arena.?.* = decl_arena.state; |
| 12284 | |
| 12285 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 12286 | defer analysis_arena.deinit(); |
| 12287 | |
| 12288 | var sema: Sema = .{ |
| 12289 | .mod = mod, |
| 12290 | .gpa = gpa, |
| 12291 | .arena = &analysis_arena.allocator, |
| 12292 | .perm_arena = &decl_arena.allocator, |
| 12293 | .code = zir, |
| 12294 | .owner_decl = decl, |
| 12295 | .func = null, |
| 12296 | .fn_ret_ty = Type.initTag(.void), |
| 12297 | .owner_func = null, |
| 12298 | }; |
| 12299 | defer sema.deinit(); |
| 11955 | 12300 | |
| 11956 | | try struct_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len); |
| 12301 | var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope); |
| 12302 | defer wip_captures.deinit(); |
| 12303 | |
| 12304 | var block_scope: Block = .{ |
| 12305 | .parent = null, |
| 12306 | .sema = &sema, |
| 12307 | .src_decl = decl, |
| 12308 | .namespace = &struct_obj.namespace, |
| 12309 | .wip_capture_scope = wip_captures.scope, |
| 12310 | .instructions = .{}, |
| 12311 | .inlining = null, |
| 12312 | .is_comptime = true, |
| 12313 | }; |
| 12314 | defer { |
| 12315 | assert(block_scope.instructions.items.len == 0); |
| 12316 | block_scope.params.deinit(gpa); |
| 12317 | } |
| 11957 | 12318 | |
| 11958 | 12319 | if (body.len != 0) { |
| 11959 | | _ = try sema.analyzeBody(block, body); |
| 12320 | _ = try sema.analyzeBody(&block_scope, body); |
| 11960 | 12321 | } |
| 11961 | 12322 | |
| 12323 | try wip_captures.finalize(); |
| 12324 | |
| 12325 | try struct_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len); |
| 12326 | |
| 11962 | 12327 | const bits_per_field = 4; |
| 11963 | 12328 | const fields_per_u32 = 32 / bits_per_field; |
| 11964 | 12329 | const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable; |
| ... | ... | @@ -11995,7 +12360,7 @@ fn analyzeStructFields( |
| 11995 | 12360 | // TODO: if we need to report an error here, use a source location |
| 11996 | 12361 | // that points to this type expression rather than the struct. |
| 11997 | 12362 | // But only resolve the source location if we need to emit a compile error. |
| 11998 | | try sema.resolveType(block, src, field_type_ref); |
| 12363 | try sema.resolveType(&block_scope, src, field_type_ref); |
| 11999 | 12364 | |
| 12000 | 12365 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 12001 | 12366 | assert(!gop.found_existing); |
| ... | ... | @@ -12013,7 +12378,7 @@ fn analyzeStructFields( |
| 12013 | 12378 | // TODO: if we need to report an error here, use a source location |
| 12014 | 12379 | // that points to this alignment expression rather than the struct. |
| 12015 | 12380 | // But only resolve the source location if we need to emit a compile error. |
| 12016 | | const abi_align_val = (try sema.resolveInstConst(block, src, align_ref)).val; |
| 12381 | const abi_align_val = (try sema.resolveInstConst(&block_scope, src, align_ref)).val; |
| 12017 | 12382 | gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator); |
| 12018 | 12383 | } |
| 12019 | 12384 | if (has_default) { |
| ... | ... | @@ -12023,23 +12388,23 @@ fn analyzeStructFields( |
| 12023 | 12388 | // TODO: if we need to report an error here, use a source location |
| 12024 | 12389 | // that points to this default value expression rather than the struct. |
| 12025 | 12390 | // But only resolve the source location if we need to emit a compile error. |
| 12026 | | const default_val = (try sema.resolveMaybeUndefVal(block, src, default_inst)) orelse |
| 12027 | | return sema.failWithNeededComptime(block, src); |
| 12391 | const default_val = (try sema.resolveMaybeUndefVal(&block_scope, src, default_inst)) orelse |
| 12392 | return sema.failWithNeededComptime(&block_scope, src); |
| 12028 | 12393 | gop.value_ptr.default_val = try default_val.copy(&decl_arena.allocator); |
| 12029 | 12394 | } |
| 12030 | 12395 | } |
| 12031 | 12396 | } |
| 12032 | 12397 | |
| 12033 | | fn analyzeUnionFields( |
| 12034 | | sema: *Sema, |
| 12035 | | block: *Scope.Block, |
| 12398 | fn semaUnionFields( |
| 12399 | mod: *Module, |
| 12036 | 12400 | union_obj: *Module.Union, |
| 12037 | 12401 | ) CompileError!void { |
| 12038 | 12402 | const tracy = trace(@src()); |
| 12039 | 12403 | defer tracy.end(); |
| 12040 | 12404 | |
| 12041 | | const gpa = sema.gpa; |
| 12042 | | const zir = sema.code; |
| 12405 | const gpa = mod.gpa; |
| 12406 | const decl = union_obj.owner_decl; |
| 12407 | const zir = union_obj.namespace.file_scope.zir; |
| 12043 | 12408 | const extended = zir.instructions.items(.data)[union_obj.zir_index].extended; |
| 12044 | 12409 | assert(extended.opcode == .union_decl); |
| 12045 | 12410 | const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small); |
| ... | ... | @@ -12087,20 +12452,57 @@ fn analyzeUnionFields( |
| 12087 | 12452 | var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa); |
| 12088 | 12453 | defer union_obj.owner_decl.value_arena.?.* = decl_arena.state; |
| 12089 | 12454 | |
| 12090 | | try union_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len); |
| 12455 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 12456 | defer analysis_arena.deinit(); |
| 12457 | |
| 12458 | var sema: Sema = .{ |
| 12459 | .mod = mod, |
| 12460 | .gpa = gpa, |
| 12461 | .arena = &analysis_arena.allocator, |
| 12462 | .perm_arena = &decl_arena.allocator, |
| 12463 | .code = zir, |
| 12464 | .owner_decl = decl, |
| 12465 | .func = null, |
| 12466 | .fn_ret_ty = Type.initTag(.void), |
| 12467 | .owner_func = null, |
| 12468 | }; |
| 12469 | defer sema.deinit(); |
| 12470 | |
| 12471 | var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope); |
| 12472 | defer wip_captures.deinit(); |
| 12473 | |
| 12474 | var block_scope: Block = .{ |
| 12475 | .parent = null, |
| 12476 | .sema = &sema, |
| 12477 | .src_decl = decl, |
| 12478 | .namespace = &union_obj.namespace, |
| 12479 | .wip_capture_scope = wip_captures.scope, |
| 12480 | .instructions = .{}, |
| 12481 | .inlining = null, |
| 12482 | .is_comptime = true, |
| 12483 | }; |
| 12484 | defer { |
| 12485 | assert(block_scope.instructions.items.len == 0); |
| 12486 | block_scope.params.deinit(gpa); |
| 12487 | } |
| 12091 | 12488 | |
| 12092 | 12489 | if (body.len != 0) { |
| 12093 | | _ = try sema.analyzeBody(block, body); |
| 12490 | _ = try sema.analyzeBody(&block_scope, body); |
| 12094 | 12491 | } |
| 12492 | |
| 12493 | try wip_captures.finalize(); |
| 12494 | |
| 12495 | try union_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len); |
| 12496 | |
| 12095 | 12497 | var int_tag_ty: Type = undefined; |
| 12096 | 12498 | var enum_field_names: ?*Module.EnumNumbered.NameMap = null; |
| 12097 | 12499 | var enum_value_map: ?*Module.EnumNumbered.ValueMap = null; |
| 12098 | 12500 | if (tag_type_ref != .none) { |
| 12099 | | const provided_ty = try sema.resolveType(block, src, tag_type_ref); |
| 12501 | const provided_ty = try sema.resolveType(&block_scope, src, tag_type_ref); |
| 12100 | 12502 | if (small.auto_enum_tag) { |
| 12101 | 12503 | // The provided type is an integer type and we must construct the enum tag type here. |
| 12102 | 12504 | int_tag_ty = provided_ty; |
| 12103 | | union_obj.tag_ty = try sema.generateUnionTagTypeNumbered(block, fields_len, provided_ty); |
| 12505 | union_obj.tag_ty = try sema.generateUnionTagTypeNumbered(&block_scope, fields_len, provided_ty); |
| 12104 | 12506 | enum_field_names = &union_obj.tag_ty.castTag(.enum_numbered).?.data.fields; |
| 12105 | 12507 | enum_value_map = &union_obj.tag_ty.castTag(.enum_numbered).?.data.values; |
| 12106 | 12508 | } else { |
| ... | ... | @@ -12111,7 +12513,7 @@ fn analyzeUnionFields( |
| 12111 | 12513 | // If auto_enum_tag is false, this is an untagged union. However, for semantic analysis |
| 12112 | 12514 | // purposes, we still auto-generate an enum tag type the same way. That the union is |
| 12113 | 12515 | // untagged is represented by the Type tag (union vs union_tagged). |
| 12114 | | union_obj.tag_ty = try sema.generateUnionTagTypeSimple(block, fields_len); |
| 12516 | union_obj.tag_ty = try sema.generateUnionTagTypeSimple(&block_scope, fields_len); |
| 12115 | 12517 | enum_field_names = &union_obj.tag_ty.castTag(.enum_simple).?.data.fields; |
| 12116 | 12518 | } |
| 12117 | 12519 | |
| ... | ... | @@ -12160,8 +12562,8 @@ fn analyzeUnionFields( |
| 12160 | 12562 | |
| 12161 | 12563 | if (enum_value_map) |map| { |
| 12162 | 12564 | const tag_src = src; // TODO better source location |
| 12163 | | const coerced = try sema.coerce(block, int_tag_ty, tag_ref, tag_src); |
| 12164 | | const val = try sema.resolveConstValue(block, tag_src, coerced); |
| 12565 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); |
| 12566 | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced); |
| 12165 | 12567 | map.putAssumeCapacityContext(val, {}, .{ .ty = int_tag_ty }); |
| 12166 | 12568 | } |
| 12167 | 12569 | |
| ... | ... | @@ -12177,7 +12579,7 @@ fn analyzeUnionFields( |
| 12177 | 12579 | // TODO: if we need to report an error here, use a source location |
| 12178 | 12580 | // that points to this type expression rather than the union. |
| 12179 | 12581 | // But only resolve the source location if we need to emit a compile error. |
| 12180 | | try sema.resolveType(block, src, field_type_ref); |
| 12582 | try sema.resolveType(&block_scope, src, field_type_ref); |
| 12181 | 12583 | |
| 12182 | 12584 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); |
| 12183 | 12585 | assert(!gop.found_existing); |
| ... | ... | @@ -12190,7 +12592,7 @@ fn analyzeUnionFields( |
| 12190 | 12592 | // TODO: if we need to report an error here, use a source location |
| 12191 | 12593 | // that points to this alignment expression rather than the struct. |
| 12192 | 12594 | // But only resolve the source location if we need to emit a compile error. |
| 12193 | | const abi_align_val = (try sema.resolveInstConst(block, src, align_ref)).val; |
| 12595 | const abi_align_val = (try sema.resolveInstConst(&block_scope, src, align_ref)).val; |
| 12194 | 12596 | gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator); |
| 12195 | 12597 | } else { |
| 12196 | 12598 | gop.value_ptr.abi_align = Value.initTag(.abi_align_default); |
| ... | ... | @@ -12200,7 +12602,7 @@ fn analyzeUnionFields( |
| 12200 | 12602 | |
| 12201 | 12603 | fn generateUnionTagTypeNumbered( |
| 12202 | 12604 | sema: *Sema, |
| 12203 | | block: *Scope.Block, |
| 12605 | block: *Block, |
| 12204 | 12606 | fields_len: u32, |
| 12205 | 12607 | int_ty: Type, |
| 12206 | 12608 | ) !Type { |
| ... | ... | @@ -12218,12 +12620,12 @@ fn generateUnionTagTypeNumbered( |
| 12218 | 12620 | const enum_ty = Type.initPayload(&enum_ty_payload.base); |
| 12219 | 12621 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); |
| 12220 | 12622 | // TODO better type name |
| 12221 | | const new_decl = try mod.createAnonymousDecl(&block.base, .{ |
| 12623 | const new_decl = try mod.createAnonymousDecl(block, .{ |
| 12222 | 12624 | .ty = Type.initTag(.type), |
| 12223 | 12625 | .val = enum_val, |
| 12224 | 12626 | }); |
| 12225 | 12627 | new_decl.owns_tv = true; |
| 12226 | | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 12628 | errdefer mod.abortAnonDecl(new_decl); |
| 12227 | 12629 | |
| 12228 | 12630 | enum_obj.* = .{ |
| 12229 | 12631 | .owner_decl = new_decl, |
| ... | ... | @@ -12239,7 +12641,7 @@ fn generateUnionTagTypeNumbered( |
| 12239 | 12641 | return enum_ty; |
| 12240 | 12642 | } |
| 12241 | 12643 | |
| 12242 | | fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) !Type { |
| 12644 | fn generateUnionTagTypeSimple(sema: *Sema, block: *Block, fields_len: u32) !Type { |
| 12243 | 12645 | const mod = sema.mod; |
| 12244 | 12646 | |
| 12245 | 12647 | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); |
| ... | ... | @@ -12254,12 +12656,12 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) |
| 12254 | 12656 | const enum_ty = Type.initPayload(&enum_ty_payload.base); |
| 12255 | 12657 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); |
| 12256 | 12658 | // TODO better type name |
| 12257 | | const new_decl = try mod.createAnonymousDecl(&block.base, .{ |
| 12659 | const new_decl = try mod.createAnonymousDecl(block, .{ |
| 12258 | 12660 | .ty = Type.initTag(.type), |
| 12259 | 12661 | .val = enum_val, |
| 12260 | 12662 | }); |
| 12261 | 12663 | new_decl.owns_tv = true; |
| 12262 | | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 12664 | errdefer mod.abortAnonDecl(new_decl); |
| 12263 | 12665 | |
| 12264 | 12666 | enum_obj.* = .{ |
| 12265 | 12667 | .owner_decl = new_decl, |
| ... | ... | @@ -12274,7 +12676,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) |
| 12274 | 12676 | |
| 12275 | 12677 | fn getBuiltin( |
| 12276 | 12678 | sema: *Sema, |
| 12277 | | block: *Scope.Block, |
| 12679 | block: *Block, |
| 12278 | 12680 | src: LazySrcLoc, |
| 12279 | 12681 | name: []const u8, |
| 12280 | 12682 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -12284,7 +12686,7 @@ fn getBuiltin( |
| 12284 | 12686 | const opt_builtin_inst = try sema.namespaceLookupRef( |
| 12285 | 12687 | block, |
| 12286 | 12688 | src, |
| 12287 | | std_file.root_decl.?.namespace, |
| 12689 | std_file.root_decl.?.src_namespace, |
| 12288 | 12690 | "builtin", |
| 12289 | 12691 | ); |
| 12290 | 12692 | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src); |
| ... | ... | @@ -12300,7 +12702,7 @@ fn getBuiltin( |
| 12300 | 12702 | |
| 12301 | 12703 | fn getBuiltinType( |
| 12302 | 12704 | sema: *Sema, |
| 12303 | | block: *Scope.Block, |
| 12705 | block: *Block, |
| 12304 | 12706 | src: LazySrcLoc, |
| 12305 | 12707 | name: []const u8, |
| 12306 | 12708 | ) CompileError!Type { |
| ... | ... | @@ -12314,7 +12716,7 @@ fn getBuiltinType( |
| 12314 | 12716 | /// that the types are already resolved. |
| 12315 | 12717 | fn typeHasOnePossibleValue( |
| 12316 | 12718 | sema: *Sema, |
| 12317 | | block: *Scope.Block, |
| 12719 | block: *Block, |
| 12318 | 12720 | src: LazySrcLoc, |
| 12319 | 12721 | starting_type: Type, |
| 12320 | 12722 | ) CompileError!?Value { |
| ... | ... | @@ -12477,8 +12879,8 @@ fn typeHasOnePossibleValue( |
| 12477 | 12879 | }; |
| 12478 | 12880 | } |
| 12479 | 12881 | |
| 12480 | | fn getAstTree(sema: *Sema, block: *Scope.Block) CompileError!*const std.zig.Ast { |
| 12481 | | return block.src_decl.namespace.file_scope.getTree(sema.gpa) catch |err| { |
| 12882 | fn getAstTree(sema: *Sema, block: *Block) CompileError!*const std.zig.Ast { |
| 12883 | return block.namespace.file_scope.getTree(sema.gpa) catch |err| { |
| 12482 | 12884 | log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); |
| 12483 | 12885 | return error.AnalysisFail; |
| 12484 | 12886 | }; |
| ... | ... | @@ -12667,7 +13069,7 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { |
| 12667 | 13069 | |
| 12668 | 13070 | fn isComptimeKnown( |
| 12669 | 13071 | sema: *Sema, |
| 12670 | | block: *Scope.Block, |
| 13072 | block: *Block, |
| 12671 | 13073 | src: LazySrcLoc, |
| 12672 | 13074 | inst: Air.Inst.Ref, |
| 12673 | 13075 | ) !bool { |
| ... | ... | @@ -12676,7 +13078,7 @@ fn isComptimeKnown( |
| 12676 | 13078 | |
| 12677 | 13079 | fn analyzeComptimeAlloc( |
| 12678 | 13080 | sema: *Sema, |
| 12679 | | block: *Scope.Block, |
| 13081 | block: *Block, |
| 12680 | 13082 | var_type: Type, |
| 12681 | 13083 | ) CompileError!Air.Inst.Ref { |
| 12682 | 13084 | const ptr_type = try Type.ptr(sema.arena, .{ |
| ... | ... | @@ -12719,7 +13121,7 @@ pub const AddressSpaceContext = enum { |
| 12719 | 13121 | |
| 12720 | 13122 | pub fn analyzeAddrspace( |
| 12721 | 13123 | sema: *Sema, |
| 12722 | | block: *Scope.Block, |
| 13124 | block: *Block, |
| 12723 | 13125 | src: LazySrcLoc, |
| 12724 | 13126 | zir_ref: Zir.Inst.Ref, |
| 12725 | 13127 | ctx: AddressSpaceContext, |
| ... | ... | @@ -12743,8 +13145,8 @@ pub fn analyzeAddrspace( |
| 12743 | 13145 | .pointer => "pointers", |
| 12744 | 13146 | }; |
| 12745 | 13147 | |
| 12746 | | return sema.mod.fail( |
| 12747 | | &block.base, |
| 13148 | return sema.fail( |
| 13149 | block, |
| 12748 | 13150 | src, |
| 12749 | 13151 | "{s} with address space '{s}' are not supported on {s}", |
| 12750 | 13152 | .{ entity, @tagName(address_space), arch.genericName() }, |