| ... | @@ -21,11 +21,9 @@ air_values: std.ArrayListUnmanaged(Value) = .{}, | ... | @@ -21,11 +21,9 @@ air_values: std.ArrayListUnmanaged(Value) = .{}, |
| 21 | /// Maps ZIR to AIR. | 21 | /// Maps ZIR to AIR. |
| 22 | inst_map: InstMap = .{}, | 22 | inst_map: InstMap = .{}, |
| 23 | /// When analyzing an inline function call, owner_decl is the Decl of the caller | 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 | /// This `Decl` owns the arena memory of this `Sema`. | 25 | /// This `Decl` owns the arena memory of this `Sema`. |
| 26 | owner_decl: *Decl, | 26 | owner_decl: *Decl, |
| 27 | /// How to look up decl names. | | |
| 28 | namespace: *Scope.Namespace, | | |
| 29 | /// For an inline or comptime function call, this will be the root parent function | 27 | /// For an inline or comptime function call, this will be the root parent function |
| 30 | /// which contains the callsite. Corresponds to `owner_decl`. | 28 | /// which contains the callsite. Corresponds to `owner_decl`. |
| 31 | owner_func: ?*Module.Fn, | 29 | owner_func: ?*Module.Fn, |
| ... | @@ -62,9 +60,6 @@ comptime_args_fn_inst: Zir.Inst.Index = 0, | ... | @@ -62,9 +60,6 @@ comptime_args_fn_inst: Zir.Inst.Index = 0, |
| 62 | /// extra hash table lookup in the `monomorphed_funcs` set. | 60 | /// extra hash table lookup in the `monomorphed_funcs` set. |
| 63 | /// Sema will set this to null when it takes ownership. | 61 | /// Sema will set this to null when it takes ownership. |
| 64 | preallocated_new_func: ?*Module.Fn = null, | 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 | const std = @import("std"); | 64 | const std = @import("std"); |
| 70 | const mem = std.mem; | 65 | const mem = std.mem; |
| ... | @@ -80,7 +75,7 @@ const Air = @import("Air.zig"); | ... | @@ -80,7 +75,7 @@ const Air = @import("Air.zig"); |
| 80 | const Zir = @import("Zir.zig"); | 75 | const Zir = @import("Zir.zig"); |
| 81 | const Module = @import("Module.zig"); | 76 | const Module = @import("Module.zig"); |
| 82 | const trace = @import("tracy.zig").trace; | 77 | const trace = @import("tracy.zig").trace; |
| 83 | const Scope = Module.Scope; | 78 | const Namespace = Module.Namespace; |
| 84 | const CompileError = Module.CompileError; | 79 | const CompileError = Module.CompileError; |
| 85 | const SemaError = Module.SemaError; | 80 | const SemaError = Module.SemaError; |
| 86 | const Decl = Module.Decl; | 81 | const Decl = Module.Decl; |
| ... | @@ -94,6 +89,286 @@ const crash_report = @import("crash_report.zig"); | ... | @@ -94,6 +89,286 @@ const crash_report = @import("crash_report.zig"); |
| 94 | | 89 | |
| 95 | pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Ref); | 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 | pub fn deinit(sema: *Sema) void { | 372 | pub fn deinit(sema: *Sema) void { |
| 98 | const gpa = sema.gpa; | 373 | const gpa = sema.gpa; |
| 99 | sema.air_instructions.deinit(gpa); | 374 | sema.air_instructions.deinit(gpa); |
| ... | @@ -101,14 +376,13 @@ pub fn deinit(sema: *Sema) void { | ... | @@ -101,14 +376,13 @@ pub fn deinit(sema: *Sema) void { |
| 101 | sema.air_values.deinit(gpa); | 376 | sema.air_values.deinit(gpa); |
| 102 | sema.inst_map.deinit(gpa); | 377 | sema.inst_map.deinit(gpa); |
| 103 | sema.decl_val_table.deinit(gpa); | 378 | sema.decl_val_table.deinit(gpa); |
| 104 | sema.types_pending_resolution.deinit(gpa); | | |
| 105 | sema.* = undefined; | 379 | sema.* = undefined; |
| 106 | } | 380 | } |
| 107 | | 381 | |
| 108 | /// Returns only the result from the body that is specified. | 382 | /// Returns only the result from the body that is specified. |
| 109 | /// Only appropriate to call when it is determined at comptime that this body | 383 | /// Only appropriate to call when it is determined at comptime that this body |
| 110 | /// has no peers. | 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 | const break_inst = try sema.analyzeBody(block, body); | 386 | const break_inst = try sema.analyzeBody(block, body); |
| 113 | const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand; | 387 | const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand; |
| 114 | return sema.resolveInst(operand_ref); | 388 | return sema.resolveInst(operand_ref); |
| ... | @@ -131,7 +405,7 @@ const always_noreturn: CompileError!Zir.Inst.Index = @as(Zir.Inst.Index, undefin | ... | @@ -131,7 +405,7 @@ const always_noreturn: CompileError!Zir.Inst.Index = @as(Zir.Inst.Index, undefin |
| 131 | /// well as the operand. No block scope needs to be created for this strategy. | 405 | /// well as the operand. No block scope needs to be created for this strategy. |
| 132 | pub fn analyzeBody( | 406 | pub fn analyzeBody( |
| 133 | sema: *Sema, | 407 | sema: *Sema, |
| 134 | block: *Scope.Block, | 408 | block: *Block, |
| 135 | body: []const Zir.Inst.Index, | 409 | body: []const Zir.Inst.Index, |
| 136 | ) CompileError!Zir.Inst.Index { | 410 | ) CompileError!Zir.Inst.Index { |
| 137 | // No tracy calls here, to avoid interfering with the tail call mechanism. | 411 | // No tracy calls here, to avoid interfering with the tail call mechanism. |
| ... | @@ -148,9 +422,9 @@ pub fn analyzeBody( | ... | @@ -148,9 +422,9 @@ pub fn analyzeBody( |
| 148 | wip_captures.deinit(); | 422 | wip_captures.deinit(); |
| 149 | }; | 423 | }; |
| 150 | | 424 | |
| 151 | const map = &block.sema.inst_map; | 425 | const map = &sema.inst_map; |
| 152 | const tags = block.sema.code.instructions.items(.tag); | 426 | const tags = sema.code.instructions.items(.tag); |
| 153 | const datas = block.sema.code.instructions.items(.data); | 427 | const datas = sema.code.instructions.items(.data); |
| 154 | | 428 | |
| 155 | var orig_captures: usize = parent_capture_scope.captures.count(); | 429 | var orig_captures: usize = parent_capture_scope.captures.count(); |
| 156 | | 430 | |
| ... | @@ -673,7 +947,7 @@ pub fn analyzeBody( | ... | @@ -673,7 +947,7 @@ pub fn analyzeBody( |
| 673 | return result; | 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 | const extended = sema.code.instructions.items(.data)[inst].extended; | 951 | const extended = sema.code.instructions.items(.data)[inst].extended; |
| 678 | switch (extended.opcode) { | 952 | switch (extended.opcode) { |
| 679 | // zig fmt: off | 953 | // zig fmt: off |
| ... | @@ -725,7 +999,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref { | ... | @@ -725,7 +999,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref { |
| 725 | | 999 | |
| 726 | fn resolveConstBool( | 1000 | fn resolveConstBool( |
| 727 | sema: *Sema, | 1001 | sema: *Sema, |
| 728 | block: *Scope.Block, | 1002 | block: *Block, |
| 729 | src: LazySrcLoc, | 1003 | src: LazySrcLoc, |
| 730 | zir_ref: Zir.Inst.Ref, | 1004 | zir_ref: Zir.Inst.Ref, |
| 731 | ) !bool { | 1005 | ) !bool { |
| ... | @@ -738,7 +1012,7 @@ fn resolveConstBool( | ... | @@ -738,7 +1012,7 @@ fn resolveConstBool( |
| 738 | | 1012 | |
| 739 | fn resolveConstString( | 1013 | fn resolveConstString( |
| 740 | sema: *Sema, | 1014 | sema: *Sema, |
| 741 | block: *Scope.Block, | 1015 | block: *Block, |
| 742 | src: LazySrcLoc, | 1016 | src: LazySrcLoc, |
| 743 | zir_ref: Zir.Inst.Ref, | 1017 | zir_ref: Zir.Inst.Ref, |
| 744 | ) ![]u8 { | 1018 | ) ![]u8 { |
| ... | @@ -749,14 +1023,14 @@ fn resolveConstString( | ... | @@ -749,14 +1023,14 @@ fn resolveConstString( |
| 749 | return val.toAllocatedBytes(sema.arena); | 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 | const air_inst = sema.resolveInst(zir_ref); | 1027 | const air_inst = sema.resolveInst(zir_ref); |
| 754 | return sema.analyzeAsType(block, src, air_inst); | 1028 | return sema.analyzeAsType(block, src, air_inst); |
| 755 | } | 1029 | } |
| 756 | | 1030 | |
| 757 | fn analyzeAsType( | 1031 | fn analyzeAsType( |
| 758 | sema: *Sema, | 1032 | sema: *Sema, |
| 759 | block: *Scope.Block, | 1033 | block: *Block, |
| 760 | src: LazySrcLoc, | 1034 | src: LazySrcLoc, |
| 761 | air_inst: Air.Inst.Ref, | 1035 | air_inst: Air.Inst.Ref, |
| 762 | ) !Type { | 1036 | ) !Type { |
| ... | @@ -773,7 +1047,7 @@ fn analyzeAsType( | ... | @@ -773,7 +1047,7 @@ fn analyzeAsType( |
| 773 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. | 1047 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. |
| 774 | fn resolveValue( | 1048 | fn resolveValue( |
| 775 | sema: *Sema, | 1049 | sema: *Sema, |
| 776 | block: *Scope.Block, | 1050 | block: *Block, |
| 777 | src: LazySrcLoc, | 1051 | src: LazySrcLoc, |
| 778 | air_ref: Air.Inst.Ref, | 1052 | air_ref: Air.Inst.Ref, |
| 779 | ) CompileError!Value { | 1053 | ) CompileError!Value { |
| ... | @@ -788,7 +1062,7 @@ fn resolveValue( | ... | @@ -788,7 +1062,7 @@ fn resolveValue( |
| 788 | /// Value Tag `undef` may be returned. | 1062 | /// Value Tag `undef` may be returned. |
| 789 | fn resolveConstMaybeUndefVal( | 1063 | fn resolveConstMaybeUndefVal( |
| 790 | sema: *Sema, | 1064 | sema: *Sema, |
| 791 | block: *Scope.Block, | 1065 | block: *Block, |
| 792 | src: LazySrcLoc, | 1066 | src: LazySrcLoc, |
| 793 | inst: Air.Inst.Ref, | 1067 | inst: Air.Inst.Ref, |
| 794 | ) CompileError!Value { | 1068 | ) CompileError!Value { |
| ... | @@ -806,7 +1080,7 @@ fn resolveConstMaybeUndefVal( | ... | @@ -806,7 +1080,7 @@ fn resolveConstMaybeUndefVal( |
| 806 | /// See `resolveValue` for an alternative. | 1080 | /// See `resolveValue` for an alternative. |
| 807 | fn resolveConstValue( | 1081 | fn resolveConstValue( |
| 808 | sema: *Sema, | 1082 | sema: *Sema, |
| 809 | block: *Scope.Block, | 1083 | block: *Block, |
| 810 | src: LazySrcLoc, | 1084 | src: LazySrcLoc, |
| 811 | air_ref: Air.Inst.Ref, | 1085 | air_ref: Air.Inst.Ref, |
| 812 | ) CompileError!Value { | 1086 | ) CompileError!Value { |
| ... | @@ -825,7 +1099,7 @@ fn resolveConstValue( | ... | @@ -825,7 +1099,7 @@ fn resolveConstValue( |
| 825 | /// Value Tag `undef` causes this function to return a compile error. | 1099 | /// Value Tag `undef` causes this function to return a compile error. |
| 826 | fn resolveDefinedValue( | 1100 | fn resolveDefinedValue( |
| 827 | sema: *Sema, | 1101 | sema: *Sema, |
| 828 | block: *Scope.Block, | 1102 | block: *Block, |
| 829 | src: LazySrcLoc, | 1103 | src: LazySrcLoc, |
| 830 | air_ref: Air.Inst.Ref, | 1104 | air_ref: Air.Inst.Ref, |
| 831 | ) CompileError!?Value { | 1105 | ) CompileError!?Value { |
| ... | @@ -843,7 +1117,7 @@ fn resolveDefinedValue( | ... | @@ -843,7 +1117,7 @@ fn resolveDefinedValue( |
| 843 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. | 1117 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. |
| 844 | fn resolveMaybeUndefVal( | 1118 | fn resolveMaybeUndefVal( |
| 845 | sema: *Sema, | 1119 | sema: *Sema, |
| 846 | block: *Scope.Block, | 1120 | block: *Block, |
| 847 | src: LazySrcLoc, | 1121 | src: LazySrcLoc, |
| 848 | inst: Air.Inst.Ref, | 1122 | inst: Air.Inst.Ref, |
| 849 | ) CompileError!?Value { | 1123 | ) CompileError!?Value { |
| ... | @@ -858,7 +1132,7 @@ fn resolveMaybeUndefVal( | ... | @@ -858,7 +1132,7 @@ fn resolveMaybeUndefVal( |
| 858 | /// Returns all Value tags including `variable` and `undef`. | 1132 | /// Returns all Value tags including `variable` and `undef`. |
| 859 | fn resolveMaybeUndefValAllowVariables( | 1133 | fn resolveMaybeUndefValAllowVariables( |
| 860 | sema: *Sema, | 1134 | sema: *Sema, |
| 861 | block: *Scope.Block, | 1135 | block: *Block, |
| 862 | src: LazySrcLoc, | 1136 | src: LazySrcLoc, |
| 863 | inst: Air.Inst.Ref, | 1137 | inst: Air.Inst.Ref, |
| 864 | ) CompileError!?Value { | 1138 | ) CompileError!?Value { |
| ... | @@ -885,20 +1159,77 @@ fn resolveMaybeUndefValAllowVariables( | ... | @@ -885,20 +1159,77 @@ fn resolveMaybeUndefValAllowVariables( |
| 885 | } | 1159 | } |
| 886 | } | 1160 | } |
| 887 | | 1161 | |
| 888 | fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { | 1162 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 889 | return sema.mod.fail(&block.base, src, "unable to resolve comptime value", .{}); | 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 { | 1170 | fn failWithDivideByZero(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 893 | return sema.mod.fail(&block.base, src, "use of undefined value here causes undefined behavior", .{}); | 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 { | 1174 | fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError { |
| 897 | return sema.mod.fail(&block.base, src, "division by zero here causes undefined behavior", .{}); | 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 { | 1178 | /// We don't return a pointer to the new error note because the pointer |
| 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 }); | 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 | /// Appropriate to call when the coercion has already been done by result | 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,7 +1238,7 @@ fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs |
| 907 | /// TODO don't ever call this since we're migrating towards ResultLoc.coerced_ty. | 1238 | /// TODO don't ever call this since we're migrating towards ResultLoc.coerced_ty. |
| 908 | fn resolveAlreadyCoercedInt( | 1239 | fn resolveAlreadyCoercedInt( |
| 909 | sema: *Sema, | 1240 | sema: *Sema, |
| 910 | block: *Scope.Block, | 1241 | block: *Block, |
| 911 | src: LazySrcLoc, | 1242 | src: LazySrcLoc, |
| 912 | zir_ref: Zir.Inst.Ref, | 1243 | zir_ref: Zir.Inst.Ref, |
| 913 | comptime Int: type, | 1244 | comptime Int: type, |
| ... | @@ -923,15 +1254,15 @@ fn resolveAlreadyCoercedInt( | ... | @@ -923,15 +1254,15 @@ fn resolveAlreadyCoercedInt( |
| 923 | | 1254 | |
| 924 | fn resolveAlign( | 1255 | fn resolveAlign( |
| 925 | sema: *Sema, | 1256 | sema: *Sema, |
| 926 | block: *Scope.Block, | 1257 | block: *Block, |
| 927 | src: LazySrcLoc, | 1258 | src: LazySrcLoc, |
| 928 | zir_ref: Zir.Inst.Ref, | 1259 | zir_ref: Zir.Inst.Ref, |
| 929 | ) !u16 { | 1260 | ) !u16 { |
| 930 | const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16)); | 1261 | const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16)); |
| 931 | const alignment = @intCast(u16, alignment_big); // We coerce to u16 in the prev line. | 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 | if (!std.math.isPowerOfTwo(alignment)) { | 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 | alignment, | 1266 | alignment, |
| 936 | }); | 1267 | }); |
| 937 | } | 1268 | } |
| ... | @@ -940,7 +1271,7 @@ fn resolveAlign( | ... | @@ -940,7 +1271,7 @@ fn resolveAlign( |
| 940 | | 1271 | |
| 941 | fn resolveInt( | 1272 | fn resolveInt( |
| 942 | sema: *Sema, | 1273 | sema: *Sema, |
| 943 | block: *Scope.Block, | 1274 | block: *Block, |
| 944 | src: LazySrcLoc, | 1275 | src: LazySrcLoc, |
| 945 | zir_ref: Zir.Inst.Ref, | 1276 | zir_ref: Zir.Inst.Ref, |
| 946 | dest_type: Type, | 1277 | dest_type: Type, |
| ... | @@ -956,7 +1287,7 @@ fn resolveInt( | ... | @@ -956,7 +1287,7 @@ fn resolveInt( |
| 956 | // a function that does not. | 1287 | // a function that does not. |
| 957 | pub fn resolveInstConst( | 1288 | pub fn resolveInstConst( |
| 958 | sema: *Sema, | 1289 | sema: *Sema, |
| 959 | block: *Scope.Block, | 1290 | block: *Block, |
| 960 | src: LazySrcLoc, | 1291 | src: LazySrcLoc, |
| 961 | zir_ref: Zir.Inst.Ref, | 1292 | zir_ref: Zir.Inst.Ref, |
| 962 | ) CompileError!TypedValue { | 1293 | ) CompileError!TypedValue { |
| ... | @@ -972,7 +1303,7 @@ pub fn resolveInstConst( | ... | @@ -972,7 +1303,7 @@ pub fn resolveInstConst( |
| 972 | // See `resolveInstConst` for an alternative. | 1303 | // See `resolveInstConst` for an alternative. |
| 973 | pub fn resolveInstValue( | 1304 | pub fn resolveInstValue( |
| 974 | sema: *Sema, | 1305 | sema: *Sema, |
| 975 | block: *Scope.Block, | 1306 | block: *Block, |
| 976 | src: LazySrcLoc, | 1307 | src: LazySrcLoc, |
| 977 | zir_ref: Zir.Inst.Ref, | 1308 | zir_ref: Zir.Inst.Ref, |
| 978 | ) CompileError!TypedValue { | 1309 | ) CompileError!TypedValue { |
| ... | @@ -984,13 +1315,13 @@ pub fn resolveInstValue( | ... | @@ -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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 1319 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 989 | const src = inst_data.src(); | 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 | const tracy = trace(@src()); | 1325 | const tracy = trace(@src()); |
| 995 | defer tracy.end(); | 1326 | defer tracy.end(); |
| 996 | | 1327 | |
| ... | @@ -1052,7 +1383,7 @@ pub fn analyzeStructDecl( | ... | @@ -1052,7 +1383,7 @@ pub fn analyzeStructDecl( |
| 1052 | | 1383 | |
| 1053 | fn zirStructDecl( | 1384 | fn zirStructDecl( |
| 1054 | sema: *Sema, | 1385 | sema: *Sema, |
| 1055 | block: *Scope.Block, | 1386 | block: *Block, |
| 1056 | extended: Zir.Inst.Extended.InstData, | 1387 | extended: Zir.Inst.Extended.InstData, |
| 1057 | inst: Zir.Inst.Index, | 1388 | inst: Zir.Inst.Index, |
| 1058 | ) CompileError!Air.Inst.Ref { | 1389 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -1069,12 +1400,12 @@ fn zirStructDecl( | ... | @@ -1069,12 +1400,12 @@ fn zirStructDecl( |
| 1069 | const struct_ty = try Type.Tag.@"struct".create(&new_decl_arena.allocator, struct_obj); | 1400 | const struct_ty = try Type.Tag.@"struct".create(&new_decl_arena.allocator, struct_obj); |
| 1070 | const struct_val = try Value.Tag.ty.create(&new_decl_arena.allocator, struct_ty); | 1401 | const struct_val = try Value.Tag.ty.create(&new_decl_arena.allocator, struct_ty); |
| 1071 | const type_name = try sema.createTypeName(block, small.name_strategy); | 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 | .ty = Type.initTag(.type), | 1404 | .ty = Type.initTag(.type), |
| 1074 | .val = struct_val, | 1405 | .val = struct_val, |
| 1075 | }, type_name); | 1406 | }, type_name); |
| 1076 | new_decl.owns_tv = true; | 1407 | new_decl.owns_tv = true; |
| 1077 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 1408 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 1078 | struct_obj.* = .{ | 1409 | struct_obj.* = .{ |
| 1079 | .owner_decl = new_decl, | 1410 | .owner_decl = new_decl, |
| 1080 | .fields = .{}, | 1411 | .fields = .{}, |
| ... | @@ -1084,7 +1415,7 @@ fn zirStructDecl( | ... | @@ -1084,7 +1415,7 @@ fn zirStructDecl( |
| 1084 | .status = .none, | 1415 | .status = .none, |
| 1085 | .known_has_bits = undefined, | 1416 | .known_has_bits = undefined, |
| 1086 | .namespace = .{ | 1417 | .namespace = .{ |
| 1087 | .parent = sema.owner_decl.namespace, | 1418 | .parent = block.namespace, |
| 1088 | .ty = struct_ty, | 1419 | .ty = struct_ty, |
| 1089 | .file_scope = block.getFileScope(), | 1420 | .file_scope = block.getFileScope(), |
| 1090 | }, | 1421 | }, |
| ... | @@ -1093,13 +1424,11 @@ fn zirStructDecl( | ... | @@ -1093,13 +1424,11 @@ fn zirStructDecl( |
| 1093 | &struct_obj.namespace, new_decl, new_decl.name, | 1424 | &struct_obj.namespace, new_decl, new_decl.name, |
| 1094 | }); | 1425 | }); |
| 1095 | try sema.analyzeStructDecl(new_decl, inst, struct_obj); | 1426 | try sema.analyzeStructDecl(new_decl, inst, struct_obj); |
| 1096 | try sema.types_pending_resolution.ensureUnusedCapacity(sema.gpa, 1); | | |
| 1097 | try new_decl.finalizeNewArena(&new_decl_arena); | 1427 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 1098 | sema.types_pending_resolution.appendAssumeCapacity(struct_ty); | | |
| 1099 | return sema.analyzeDeclVal(block, src, new_decl); | 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 | switch (name_strategy) { | 1432 | switch (name_strategy) { |
| 1104 | .anon => { | 1433 | .anon => { |
| 1105 | // It would be neat to have "struct:line:column" but this name has | 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,7 +1456,7 @@ fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.Name |
| 1127 | | 1456 | |
| 1128 | fn zirEnumDecl( | 1457 | fn zirEnumDecl( |
| 1129 | sema: *Sema, | 1458 | sema: *Sema, |
| 1130 | block: *Scope.Block, | 1459 | block: *Block, |
| 1131 | extended: Zir.Inst.Extended.InstData, | 1460 | extended: Zir.Inst.Extended.InstData, |
| 1132 | ) CompileError!Air.Inst.Ref { | 1461 | ) CompileError!Air.Inst.Ref { |
| 1133 | const tracy = trace(@src()); | 1462 | const tracy = trace(@src()); |
| ... | @@ -1180,12 +1509,12 @@ fn zirEnumDecl( | ... | @@ -1180,12 +1509,12 @@ fn zirEnumDecl( |
| 1180 | const enum_ty = Type.initPayload(&enum_ty_payload.base); | 1509 | const enum_ty = Type.initPayload(&enum_ty_payload.base); |
| 1181 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); | 1510 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); |
| 1182 | const type_name = try sema.createTypeName(block, small.name_strategy); | 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 | .ty = Type.initTag(.type), | 1513 | .ty = Type.initTag(.type), |
| 1185 | .val = enum_val, | 1514 | .val = enum_val, |
| 1186 | }, type_name); | 1515 | }, type_name); |
| 1187 | new_decl.owns_tv = true; | 1516 | new_decl.owns_tv = true; |
| 1188 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 1517 | errdefer mod.abortAnonDecl(new_decl); |
| 1189 | | 1518 | |
| 1190 | enum_obj.* = .{ | 1519 | enum_obj.* = .{ |
| 1191 | .owner_decl = new_decl, | 1520 | .owner_decl = new_decl, |
| ... | @@ -1194,7 +1523,7 @@ fn zirEnumDecl( | ... | @@ -1194,7 +1523,7 @@ fn zirEnumDecl( |
| 1194 | .values = .{}, | 1523 | .values = .{}, |
| 1195 | .node_offset = src.node_offset, | 1524 | .node_offset = src.node_offset, |
| 1196 | .namespace = .{ | 1525 | .namespace = .{ |
| 1197 | .parent = sema.owner_decl.namespace, | 1526 | .parent = block.namespace, |
| 1198 | .ty = enum_ty, | 1527 | .ty = enum_ty, |
| 1199 | .file_scope = block.getFileScope(), | 1528 | .file_scope = block.getFileScope(), |
| 1200 | }, | 1529 | }, |
| ... | @@ -1227,10 +1556,6 @@ fn zirEnumDecl( | ... | @@ -1227,10 +1556,6 @@ fn zirEnumDecl( |
| 1227 | sema.owner_decl = new_decl; | 1556 | sema.owner_decl = new_decl; |
| 1228 | defer sema.owner_decl = prev_owner_decl; | 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 | const prev_owner_func = sema.owner_func; | 1559 | const prev_owner_func = sema.owner_func; |
| 1235 | sema.owner_func = null; | 1560 | sema.owner_func = null; |
| 1236 | defer sema.owner_func = prev_owner_func; | 1561 | defer sema.owner_func = prev_owner_func; |
| ... | @@ -1242,10 +1567,11 @@ fn zirEnumDecl( | ... | @@ -1242,10 +1567,11 @@ fn zirEnumDecl( |
| 1242 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope); | 1567 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope); |
| 1243 | defer wip_captures.deinit(); | 1568 | defer wip_captures.deinit(); |
| 1244 | | 1569 | |
| 1245 | var enum_block: Scope.Block = .{ | 1570 | var enum_block: Block = .{ |
| 1246 | .parent = null, | 1571 | .parent = null, |
| 1247 | .sema = sema, | 1572 | .sema = sema, |
| 1248 | .src_decl = new_decl, | 1573 | .src_decl = new_decl, |
| | 1574 | .namespace = &enum_obj.namespace, |
| 1249 | .wip_capture_scope = wip_captures.scope, | 1575 | .wip_capture_scope = wip_captures.scope, |
| 1250 | .instructions = .{}, | 1576 | .instructions = .{}, |
| 1251 | .inlining = null, | 1577 | .inlining = null, |
| ... | @@ -1303,12 +1629,12 @@ fn zirEnumDecl( | ... | @@ -1303,12 +1629,12 @@ fn zirEnumDecl( |
| 1303 | const field_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, field_i); | 1629 | const field_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, field_i); |
| 1304 | const other_tag_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, gop.index); | 1630 | const other_tag_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, gop.index); |
| 1305 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 1635 | break :msg msg; |
| 1310 | }; | 1636 | }; |
| 1311 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 1637 | return sema.failWithOwnedErrorMsg(msg); |
| 1312 | } | 1638 | } |
| 1313 | | 1639 | |
| 1314 | if (has_tag_value) { | 1640 | if (has_tag_value) { |
| ... | @@ -1331,7 +1657,7 @@ fn zirEnumDecl( | ... | @@ -1331,7 +1657,7 @@ fn zirEnumDecl( |
| 1331 | | 1657 | |
| 1332 | fn zirUnionDecl( | 1658 | fn zirUnionDecl( |
| 1333 | sema: *Sema, | 1659 | sema: *Sema, |
| 1334 | block: *Scope.Block, | 1660 | block: *Block, |
| 1335 | extended: Zir.Inst.Extended.InstData, | 1661 | extended: Zir.Inst.Extended.InstData, |
| 1336 | inst: Zir.Inst.Index, | 1662 | inst: Zir.Inst.Index, |
| 1337 | ) CompileError!Air.Inst.Ref { | 1663 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -1370,12 +1696,12 @@ fn zirUnionDecl( | ... | @@ -1370,12 +1696,12 @@ fn zirUnionDecl( |
| 1370 | const union_ty = Type.initPayload(&union_payload.base); | 1696 | const union_ty = Type.initPayload(&union_payload.base); |
| 1371 | const union_val = try Value.Tag.ty.create(&new_decl_arena.allocator, union_ty); | 1697 | const union_val = try Value.Tag.ty.create(&new_decl_arena.allocator, union_ty); |
| 1372 | const type_name = try sema.createTypeName(block, small.name_strategy); | 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 | .ty = Type.initTag(.type), | 1700 | .ty = Type.initTag(.type), |
| 1375 | .val = union_val, | 1701 | .val = union_val, |
| 1376 | }, type_name); | 1702 | }, type_name); |
| 1377 | new_decl.owns_tv = true; | 1703 | new_decl.owns_tv = true; |
| 1378 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 1704 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 1379 | union_obj.* = .{ | 1705 | union_obj.* = .{ |
| 1380 | .owner_decl = new_decl, | 1706 | .owner_decl = new_decl, |
| 1381 | .tag_ty = Type.initTag(.@"null"), | 1707 | .tag_ty = Type.initTag(.@"null"), |
| ... | @@ -1385,7 +1711,7 @@ fn zirUnionDecl( | ... | @@ -1385,7 +1711,7 @@ fn zirUnionDecl( |
| 1385 | .layout = small.layout, | 1711 | .layout = small.layout, |
| 1386 | .status = .none, | 1712 | .status = .none, |
| 1387 | .namespace = .{ | 1713 | .namespace = .{ |
| 1388 | .parent = sema.owner_decl.namespace, | 1714 | .parent = block.namespace, |
| 1389 | .ty = union_ty, | 1715 | .ty = union_ty, |
| 1390 | .file_scope = block.getFileScope(), | 1716 | .file_scope = block.getFileScope(), |
| 1391 | }, | 1717 | }, |
| ... | @@ -1396,15 +1722,13 @@ fn zirUnionDecl( | ... | @@ -1396,15 +1722,13 @@ fn zirUnionDecl( |
| 1396 | | 1722 | |
| 1397 | _ = try sema.mod.scanNamespace(&union_obj.namespace, extra_index, decls_len, new_decl); | 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 | try new_decl.finalizeNewArena(&new_decl_arena); | 1725 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 1401 | sema.types_pending_resolution.appendAssumeCapacity(union_ty); | | |
| 1402 | return sema.analyzeDeclVal(block, src, new_decl); | 1726 | return sema.analyzeDeclVal(block, src, new_decl); |
| 1403 | } | 1727 | } |
| 1404 | | 1728 | |
| 1405 | fn zirOpaqueDecl( | 1729 | fn zirOpaqueDecl( |
| 1406 | sema: *Sema, | 1730 | sema: *Sema, |
| 1407 | block: *Scope.Block, | 1731 | block: *Block, |
| 1408 | extended: Zir.Inst.Extended.InstData, | 1732 | extended: Zir.Inst.Extended.InstData, |
| 1409 | inst: Zir.Inst.Index, | 1733 | inst: Zir.Inst.Index, |
| 1410 | ) CompileError!Air.Inst.Ref { | 1734 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -1413,12 +1737,12 @@ fn zirOpaqueDecl( | ... | @@ -1413,12 +1737,12 @@ fn zirOpaqueDecl( |
| 1413 | | 1737 | |
| 1414 | _ = extended; | 1738 | _ = extended; |
| 1415 | _ = inst; | 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 | fn zirErrorSetDecl( | 1743 | fn zirErrorSetDecl( |
| 1420 | sema: *Sema, | 1744 | sema: *Sema, |
| 1421 | block: *Scope.Block, | 1745 | block: *Block, |
| 1422 | inst: Zir.Inst.Index, | 1746 | inst: Zir.Inst.Index, |
| 1423 | name_strategy: Zir.Inst.NameStrategy, | 1747 | name_strategy: Zir.Inst.NameStrategy, |
| 1424 | ) CompileError!Air.Inst.Ref { | 1748 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -1438,12 +1762,12 @@ fn zirErrorSetDecl( | ... | @@ -1438,12 +1762,12 @@ fn zirErrorSetDecl( |
| 1438 | const error_set_ty = try Type.Tag.error_set.create(&new_decl_arena.allocator, error_set); | 1762 | const error_set_ty = try Type.Tag.error_set.create(&new_decl_arena.allocator, error_set); |
| 1439 | const error_set_val = try Value.Tag.ty.create(&new_decl_arena.allocator, error_set_ty); | 1763 | const error_set_val = try Value.Tag.ty.create(&new_decl_arena.allocator, error_set_ty); |
| 1440 | const type_name = try sema.createTypeName(block, name_strategy); | 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 | .ty = Type.initTag(.type), | 1766 | .ty = Type.initTag(.type), |
| 1443 | .val = error_set_val, | 1767 | .val = error_set_val, |
| 1444 | }, type_name); | 1768 | }, type_name); |
| 1445 | new_decl.owns_tv = true; | 1769 | new_decl.owns_tv = true; |
| 1446 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 1770 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 1447 | const names = try new_decl_arena.allocator.alloc([]const u8, fields.len); | 1771 | const names = try new_decl_arena.allocator.alloc([]const u8, fields.len); |
| 1448 | for (fields) |str_index, i| { | 1772 | for (fields) |str_index, i| { |
| 1449 | names[i] = try new_decl_arena.allocator.dupe(u8, sema.code.nullTerminatedString(str_index)); | 1773 | names[i] = try new_decl_arena.allocator.dupe(u8, sema.code.nullTerminatedString(str_index)); |
| ... | @@ -1460,7 +1784,7 @@ fn zirErrorSetDecl( | ... | @@ -1460,7 +1784,7 @@ fn zirErrorSetDecl( |
| 1460 | | 1784 | |
| 1461 | fn zirRetPtr( | 1785 | fn zirRetPtr( |
| 1462 | sema: *Sema, | 1786 | sema: *Sema, |
| 1463 | block: *Scope.Block, | 1787 | block: *Block, |
| 1464 | extended: Zir.Inst.Extended.InstData, | 1788 | extended: Zir.Inst.Extended.InstData, |
| 1465 | ) CompileError!Air.Inst.Ref { | 1789 | ) CompileError!Air.Inst.Ref { |
| 1466 | const tracy = trace(@src()); | 1790 | const tracy = trace(@src()); |
| ... | @@ -1480,7 +1804,7 @@ fn zirRetPtr( | ... | @@ -1480,7 +1804,7 @@ fn zirRetPtr( |
| 1480 | return block.addTy(.alloc, ptr_type); | 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 | const tracy = trace(@src()); | 1808 | const tracy = trace(@src()); |
| 1485 | defer tracy.end(); | 1809 | defer tracy.end(); |
| 1486 | | 1810 | |
| ... | @@ -1491,7 +1815,7 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -1491,7 +1815,7 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 1491 | | 1815 | |
| 1492 | fn zirRetType( | 1816 | fn zirRetType( |
| 1493 | sema: *Sema, | 1817 | sema: *Sema, |
| 1494 | block: *Scope.Block, | 1818 | block: *Block, |
| 1495 | extended: Zir.Inst.Extended.InstData, | 1819 | extended: Zir.Inst.Extended.InstData, |
| 1496 | ) CompileError!Air.Inst.Ref { | 1820 | ) CompileError!Air.Inst.Ref { |
| 1497 | const tracy = trace(@src()); | 1821 | const tracy = trace(@src()); |
| ... | @@ -1502,7 +1826,7 @@ fn zirRetType( | ... | @@ -1502,7 +1826,7 @@ fn zirRetType( |
| 1502 | return sema.addType(sema.fn_ret_ty); | 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 | const tracy = trace(@src()); | 1830 | const tracy = trace(@src()); |
| 1507 | defer tracy.end(); | 1831 | defer tracy.end(); |
| 1508 | | 1832 | |
| ... | @@ -1515,18 +1839,18 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) C | ... | @@ -1515,18 +1839,18 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) C |
| 1515 | | 1839 | |
| 1516 | fn ensureResultUsed( | 1840 | fn ensureResultUsed( |
| 1517 | sema: *Sema, | 1841 | sema: *Sema, |
| 1518 | block: *Scope.Block, | 1842 | block: *Block, |
| 1519 | operand: Air.Inst.Ref, | 1843 | operand: Air.Inst.Ref, |
| 1520 | src: LazySrcLoc, | 1844 | src: LazySrcLoc, |
| 1521 | ) CompileError!void { | 1845 | ) CompileError!void { |
| 1522 | const operand_ty = sema.typeOf(operand); | 1846 | const operand_ty = sema.typeOf(operand); |
| 1523 | switch (operand_ty.zigTypeTag()) { | 1847 | switch (operand_ty.zigTypeTag()) { |
| 1524 | .Void, .NoReturn => return, | 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 | const tracy = trace(@src()); | 1854 | const tracy = trace(@src()); |
| 1531 | defer tracy.end(); | 1855 | defer tracy.end(); |
| 1532 | | 1856 | |
| ... | @@ -1535,12 +1859,12 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde | ... | @@ -1535,12 +1859,12 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1535 | const src = inst_data.src(); | 1859 | const src = inst_data.src(); |
| 1536 | const operand_ty = sema.typeOf(operand); | 1860 | const operand_ty = sema.typeOf(operand); |
| 1537 | switch (operand_ty.zigTypeTag()) { | 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 | else => return, | 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 | const tracy = trace(@src()); | 1868 | const tracy = trace(@src()); |
| 1545 | defer tracy.end(); | 1869 | defer tracy.end(); |
| 1546 | | 1870 | |
| ... | @@ -1561,15 +1885,15 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co | ... | @@ -1561,15 +1885,15 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1561 | } | 1885 | } |
| 1562 | if (!elem_ty.isIndexable()) { | 1886 | if (!elem_ty.isIndexable()) { |
| 1563 | const msg = msg: { | 1887 | const msg = msg: { |
| 1564 | const msg = try sema.mod.errMsg( | 1888 | const msg = try sema.errMsg( |
| 1565 | &block.base, | 1889 | block, |
| 1566 | src, | 1890 | src, |
| 1567 | "type '{}' does not support indexing", | 1891 | "type '{}' does not support indexing", |
| 1568 | .{elem_ty}, | 1892 | .{elem_ty}, |
| 1569 | ); | 1893 | ); |
| 1570 | errdefer msg.destroy(sema.gpa); | 1894 | errdefer msg.destroy(sema.gpa); |
| 1571 | try sema.mod.errNote( | 1895 | try sema.errNote( |
| 1572 | &block.base, | 1896 | block, |
| 1573 | src, | 1897 | src, |
| 1574 | msg, | 1898 | msg, |
| 1575 | "for loop operand must be an array, slice, tuple, or vector", | 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,18 +1901,18 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1577 | ); | 1901 | ); |
| 1578 | break :msg msg; | 1902 | break :msg msg; |
| 1579 | }; | 1903 | }; |
| 1580 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 1904 | return sema.failWithOwnedErrorMsg(msg); |
| 1581 | } | 1905 | } |
| 1582 | const result_ptr = try sema.fieldPtr(block, src, array, "len", src); | 1906 | const result_ptr = try sema.fieldPtr(block, src, array, "len", src); |
| 1583 | return sema.analyzeLoad(block, src, result_ptr, src); | 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 | fn zirAllocExtended( | 1913 | fn zirAllocExtended( |
| 1590 | sema: *Sema, | 1914 | sema: *Sema, |
| 1591 | block: *Scope.Block, | 1915 | block: *Block, |
| 1592 | extended: Zir.Inst.Extended.InstData, | 1916 | extended: Zir.Inst.Extended.InstData, |
| 1593 | ) CompileError!Air.Inst.Ref { | 1917 | ) CompileError!Air.Inst.Ref { |
| 1594 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); | 1918 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| ... | @@ -1604,7 +1928,7 @@ fn zirAllocExtended( | ... | @@ -1604,7 +1928,7 @@ fn zirAllocExtended( |
| 1604 | extra_index += 1; | 1928 | extra_index += 1; |
| 1605 | break :blk try sema.resolveType(block, ty_src, type_ref); | 1929 | break :blk try sema.resolveType(block, ty_src, type_ref); |
| 1606 | } else { | 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 | const alignment: u16 = if (small.has_align) blk: { | 1934 | const alignment: u16 = if (small.has_align) blk: { |
| ... | @@ -1615,11 +1939,11 @@ fn zirAllocExtended( | ... | @@ -1615,11 +1939,11 @@ fn zirAllocExtended( |
| 1615 | } else 0; | 1939 | } else 0; |
| 1616 | | 1940 | |
| 1617 | if (small.is_comptime) { | 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 | if (!small.is_const) { | 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 | const ptr_type = try Type.ptr(sema.arena, .{ | 1949 | const ptr_type = try Type.ptr(sema.arena, .{ |
| ... | @@ -1631,7 +1955,7 @@ fn zirAllocExtended( | ... | @@ -1631,7 +1955,7 @@ fn zirAllocExtended( |
| 1631 | return block.addTy(.alloc, ptr_type); | 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 | const tracy = trace(@src()); | 1959 | const tracy = trace(@src()); |
| 1636 | defer tracy.end(); | 1960 | defer tracy.end(); |
| 1637 | | 1961 | |
| ... | @@ -1651,7 +1975,7 @@ fn zirAllocInferredComptime(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -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 | const tracy = trace(@src()); | 1979 | const tracy = trace(@src()); |
| 1656 | defer tracy.end(); | 1980 | defer tracy.end(); |
| 1657 | | 1981 | |
| ... | @@ -1667,7 +1991,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError | ... | @@ -1667,7 +1991,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 1667 | return block.addTy(.alloc, ptr_type); | 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 | const tracy = trace(@src()); | 1995 | const tracy = trace(@src()); |
| 1672 | defer tracy.end(); | 1996 | defer tracy.end(); |
| 1673 | | 1997 | |
| ... | @@ -1689,7 +2013,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -1689,7 +2013,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 1689 | | 2013 | |
| 1690 | fn zirAllocInferred( | 2014 | fn zirAllocInferred( |
| 1691 | sema: *Sema, | 2015 | sema: *Sema, |
| 1692 | block: *Scope.Block, | 2016 | block: *Block, |
| 1693 | inst: Zir.Inst.Index, | 2017 | inst: Zir.Inst.Index, |
| 1694 | inferred_alloc_ty: Type, | 2018 | inferred_alloc_ty: Type, |
| 1695 | ) CompileError!Air.Inst.Ref { | 2019 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -1720,7 +2044,7 @@ fn zirAllocInferred( | ... | @@ -1720,7 +2044,7 @@ fn zirAllocInferred( |
| 1720 | return result; | 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 | const tracy = trace(@src()); | 2048 | const tracy = trace(@src()); |
| 1725 | defer tracy.end(); | 2049 | defer tracy.end(); |
| 1726 | | 2050 | |
| ... | @@ -1779,7 +2103,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde | ... | @@ -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 | const tracy = trace(@src()); | 2107 | const tracy = trace(@src()); |
| 1784 | defer tracy.end(); | 2108 | defer tracy.end(); |
| 1785 | | 2109 | |
| ... | @@ -1811,18 +2135,16 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind | ... | @@ -1811,18 +2135,16 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind |
| 1811 | | 2135 | |
| 1812 | fn validateUnionInitPtr( | 2136 | fn validateUnionInitPtr( |
| 1813 | sema: *Sema, | 2137 | sema: *Sema, |
| 1814 | block: *Scope.Block, | 2138 | block: *Block, |
| 1815 | union_obj: *Module.Union, | 2139 | union_obj: *Module.Union, |
| 1816 | init_src: LazySrcLoc, | 2140 | init_src: LazySrcLoc, |
| 1817 | instrs: []const Zir.Inst.Index, | 2141 | instrs: []const Zir.Inst.Index, |
| 1818 | union_ptr: Air.Inst.Ref, | 2142 | union_ptr: Air.Inst.Ref, |
| 1819 | ) CompileError!void { | 2143 | ) CompileError!void { |
| 1820 | const mod = sema.mod; | | |
| 1821 | | | |
| 1822 | if (instrs.len != 1) { | 2144 | if (instrs.len != 1) { |
| 1823 | // TODO add note for other field | 2145 | // TODO add note for other field |
| 1824 | // TODO add note for union declared here | 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 | const field_ptr = instrs[0]; | 2150 | const field_ptr = instrs[0]; |
| ... | @@ -1852,13 +2174,12 @@ fn validateUnionInitPtr( | ... | @@ -1852,13 +2174,12 @@ fn validateUnionInitPtr( |
| 1852 | | 2174 | |
| 1853 | fn validateStructInitPtr( | 2175 | fn validateStructInitPtr( |
| 1854 | sema: *Sema, | 2176 | sema: *Sema, |
| 1855 | block: *Scope.Block, | 2177 | block: *Block, |
| 1856 | struct_obj: *Module.Struct, | 2178 | struct_obj: *Module.Struct, |
| 1857 | init_src: LazySrcLoc, | 2179 | init_src: LazySrcLoc, |
| 1858 | instrs: []const Zir.Inst.Index, | 2180 | instrs: []const Zir.Inst.Index, |
| 1859 | ) CompileError!void { | 2181 | ) CompileError!void { |
| 1860 | const gpa = sema.gpa; | 2182 | const gpa = sema.gpa; |
| 1861 | const mod = sema.mod; | | |
| 1862 | | 2183 | |
| 1863 | // Maps field index to field_ptr index of where it was already initialized. | 2184 | // Maps field index to field_ptr index of where it was already initialized. |
| 1864 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count()); | 2185 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count()); |
| ... | @@ -1877,12 +2198,12 @@ fn validateStructInitPtr( | ... | @@ -1877,12 +2198,12 @@ fn validateStructInitPtr( |
| 1877 | const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node; | 2198 | const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node; |
| 1878 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node }; | 2199 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node }; |
| 1879 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 2204 | break :msg msg; |
| 1884 | }; | 2205 | }; |
| 1885 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 2206 | return sema.failWithOwnedErrorMsg(msg); |
| 1886 | } | 2207 | } |
| 1887 | found_fields[field_index] = field_ptr; | 2208 | found_fields[field_index] = field_ptr; |
| 1888 | } | 2209 | } |
| ... | @@ -1897,85 +2218,83 @@ fn validateStructInitPtr( | ... | @@ -1897,85 +2218,83 @@ fn validateStructInitPtr( |
| 1897 | const template = "missing struct field: {s}"; | 2218 | const template = "missing struct field: {s}"; |
| 1898 | const args = .{field_name}; | 2219 | const args = .{field_name}; |
| 1899 | if (root_msg) |msg| { | 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 | } else { | 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 | if (root_msg) |msg| { | 2226 | if (root_msg) |msg| { |
| 1906 | const fqn = try struct_obj.getFullyQualifiedName(gpa); | 2227 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1907 | defer gpa.free(fqn); | 2228 | defer gpa.free(fqn); |
| 1908 | try mod.errNoteNonLazy( | 2229 | try sema.mod.errNoteNonLazy( |
| 1909 | struct_obj.srcLoc(), | 2230 | struct_obj.srcLoc(), |
| 1910 | msg, | 2231 | msg, |
| 1911 | "struct '{s}' declared here", | 2232 | "struct '{s}' declared here", |
| 1912 | .{fqn}, | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 2240 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1920 | const src = inst_data.src(); | 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 | fn failWithBadFieldAccess( | 2245 | fn failWithBadFieldAccess( |
| 1925 | sema: *Sema, | 2246 | sema: *Sema, |
| 1926 | block: *Scope.Block, | 2247 | block: *Block, |
| 1927 | struct_obj: *Module.Struct, | 2248 | struct_obj: *Module.Struct, |
| 1928 | field_src: LazySrcLoc, | 2249 | field_src: LazySrcLoc, |
| 1929 | field_name: []const u8, | 2250 | field_name: []const u8, |
| 1930 | ) CompileError { | 2251 | ) CompileError { |
| 1931 | const mod = sema.mod; | | |
| 1932 | const gpa = sema.gpa; | 2252 | const gpa = sema.gpa; |
| 1933 | | 2253 | |
| 1934 | const fqn = try struct_obj.getFullyQualifiedName(gpa); | 2254 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1935 | defer gpa.free(fqn); | 2255 | defer gpa.free(fqn); |
| 1936 | | 2256 | |
| 1937 | const msg = msg: { | 2257 | const msg = msg: { |
| 1938 | const msg = try mod.errMsg( | 2258 | const msg = try sema.errMsg( |
| 1939 | &block.base, | 2259 | block, |
| 1940 | field_src, | 2260 | field_src, |
| 1941 | "no field named '{s}' in struct '{s}'", | 2261 | "no field named '{s}' in struct '{s}'", |
| 1942 | .{ field_name, fqn }, | 2262 | .{ field_name, fqn }, |
| 1943 | ); | 2263 | ); |
| 1944 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 2266 | break :msg msg; |
| 1947 | }; | 2267 | }; |
| 1948 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 2268 | return sema.failWithOwnedErrorMsg(msg); |
| 1949 | } | 2269 | } |
| 1950 | | 2270 | |
| 1951 | fn failWithBadUnionFieldAccess( | 2271 | fn failWithBadUnionFieldAccess( |
| 1952 | sema: *Sema, | 2272 | sema: *Sema, |
| 1953 | block: *Scope.Block, | 2273 | block: *Block, |
| 1954 | union_obj: *Module.Union, | 2274 | union_obj: *Module.Union, |
| 1955 | field_src: LazySrcLoc, | 2275 | field_src: LazySrcLoc, |
| 1956 | field_name: []const u8, | 2276 | field_name: []const u8, |
| 1957 | ) CompileError { | 2277 | ) CompileError { |
| 1958 | const mod = sema.mod; | | |
| 1959 | const gpa = sema.gpa; | 2278 | const gpa = sema.gpa; |
| 1960 | | 2279 | |
| 1961 | const fqn = try union_obj.getFullyQualifiedName(gpa); | 2280 | const fqn = try union_obj.getFullyQualifiedName(gpa); |
| 1962 | defer gpa.free(fqn); | 2281 | defer gpa.free(fqn); |
| 1963 | | 2282 | |
| 1964 | const msg = msg: { | 2283 | const msg = msg: { |
| 1965 | const msg = try mod.errMsg( | 2284 | const msg = try sema.errMsg( |
| 1966 | &block.base, | 2285 | block, |
| 1967 | field_src, | 2286 | field_src, |
| 1968 | "no field named '{s}' in union '{s}'", | 2287 | "no field named '{s}' in union '{s}'", |
| 1969 | .{ field_name, fqn }, | 2288 | .{ field_name, fqn }, |
| 1970 | ); | 2289 | ); |
| 1971 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 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 | const tracy = trace(@src()); | 2298 | const tracy = trace(@src()); |
| 1980 | defer tracy.end(); | 2299 | defer tracy.end(); |
| 1981 | | 2300 | |
| ... | @@ -2000,7 +2319,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co | ... | @@ -2000,7 +2319,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 2000 | return sema.storePtr(block, src, bitcasted_ptr, value); | 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 | const tracy = trace(@src()); | 2323 | const tracy = trace(@src()); |
| 2005 | defer tracy.end(); | 2324 | defer tracy.end(); |
| 2006 | | 2325 | |
| ... | @@ -2048,7 +2367,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) | ... | @@ -2048,7 +2367,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 2048 | unreachable; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 2371 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2053 | const src = inst_data.src(); | 2372 | const src = inst_data.src(); |
| 2054 | const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32); | 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,7 +2375,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 2056 | sema.branch_quota = quota; | 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 | const tracy = trace(@src()); | 2379 | const tracy = trace(@src()); |
| 2061 | defer tracy.end(); | 2380 | defer tracy.end(); |
| 2062 | | 2381 | |
| ... | @@ -2066,7 +2385,7 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError | ... | @@ -2066,7 +2385,7 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2066 | return sema.storePtr(block, sema.src, ptr, value); | 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 | const tracy = trace(@src()); | 2389 | const tracy = trace(@src()); |
| 2071 | defer tracy.end(); | 2390 | defer tracy.end(); |
| 2072 | | 2391 | |
| ... | @@ -2078,7 +2397,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -2078,7 +2397,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 2078 | return sema.storePtr(block, src, ptr, value); | 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 | const tracy = trace(@src()); | 2401 | const tracy = trace(@src()); |
| 2083 | defer tracy.end(); | 2402 | defer tracy.end(); |
| 2084 | | 2403 | |
| ... | @@ -2097,16 +2416,16 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -2097,16 +2416,16 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 2097 | const decl_ty = try Type.Tag.array_u8_sentinel_0.create(&new_decl_arena.allocator, bytes.len); | 2416 | const decl_ty = try Type.Tag.array_u8_sentinel_0.create(&new_decl_arena.allocator, bytes.len); |
| 2098 | const decl_val = try Value.Tag.bytes.create(&new_decl_arena.allocator, bytes); | 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 | .ty = decl_ty, | 2420 | .ty = decl_ty, |
| 2102 | .val = decl_val, | 2421 | .val = decl_val, |
| 2103 | }); | 2422 | }); |
| 2104 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 2423 | errdefer sema.mod.abortAnonDecl(new_decl); |
| 2105 | try new_decl.finalizeNewArena(&new_decl_arena); | 2424 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 2106 | return sema.analyzeDeclRef(new_decl); | 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 | _ = block; | 2429 | _ = block; |
| 2111 | const tracy = trace(@src()); | 2430 | const tracy = trace(@src()); |
| 2112 | defer tracy.end(); | 2431 | defer tracy.end(); |
| ... | @@ -2115,7 +2434,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -2115,7 +2434,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 2115 | return sema.addIntUnsigned(Type.initTag(.comptime_int), int); | 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 | _ = block; | 2438 | _ = block; |
| 2120 | const tracy = trace(@src()); | 2439 | const tracy = trace(@src()); |
| 2121 | defer tracy.end(); | 2440 | defer tracy.end(); |
| ... | @@ -2133,7 +2452,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -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 | _ = block; | 2456 | _ = block; |
| 2138 | const arena = sema.arena; | 2457 | const arena = sema.arena; |
| 2139 | const number = sema.code.instructions.items(.data)[inst].float; | 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,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 | _ = block; | 2466 | _ = block; |
| 2148 | const arena = sema.arena; | 2467 | const arena = sema.arena; |
| 2149 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 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,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 | const tracy = trace(@src()); | 2478 | const tracy = trace(@src()); |
| 2160 | defer tracy.end(); | 2479 | defer tracy.end(); |
| 2161 | | 2480 | |
| ... | @@ -2163,12 +2482,12 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi | ... | @@ -2163,12 +2482,12 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 2163 | const src = inst_data.src(); | 2482 | const src = inst_data.src(); |
| 2164 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 2483 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2165 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand); | 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 | fn zirCompileLog( | 2488 | fn zirCompileLog( |
| 2170 | sema: *Sema, | 2489 | sema: *Sema, |
| 2171 | block: *Scope.Block, | 2490 | block: *Block, |
| 2172 | extended: Zir.Inst.Extended.InstData, | 2491 | extended: Zir.Inst.Extended.InstData, |
| 2173 | ) CompileError!Air.Inst.Ref { | 2492 | ) CompileError!Air.Inst.Ref { |
| 2174 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); | 2493 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); |
| ... | @@ -2200,7 +2519,7 @@ fn zirCompileLog( | ... | @@ -2200,7 +2519,7 @@ fn zirCompileLog( |
| 2200 | return Air.Inst.Ref.void_value; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 2523 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2205 | const src: LazySrcLoc = inst_data.src(); | 2524 | const src: LazySrcLoc = inst_data.src(); |
| 2206 | const msg_inst = sema.resolveInst(inst_data.operand); | 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,7 +2527,7 @@ fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2208 | return sema.panicWithMsg(block, src, msg_inst); | 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 | const tracy = trace(@src()); | 2531 | const tracy = trace(@src()); |
| 2213 | defer tracy.end(); | 2532 | defer tracy.end(); |
| 2214 | | 2533 | |
| ... | @@ -2236,7 +2555,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -2236,7 +2555,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2236 | .payload = undefined, | 2555 | .payload = undefined, |
| 2237 | } }, | 2556 | } }, |
| 2238 | }); | 2557 | }); |
| 2239 | var label: Scope.Block.Label = .{ | 2558 | var label: Block.Label = .{ |
| 2240 | .zir_block = inst, | 2559 | .zir_block = inst, |
| 2241 | .merges = .{ | 2560 | .merges = .{ |
| 2242 | .results = .{}, | 2561 | .results = .{}, |
| ... | @@ -2271,7 +2590,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -2271,7 +2590,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2271 | return sema.analyzeBlockBody(parent_block, src, &child_block, merges); | 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 | const tracy = trace(@src()); | 2594 | const tracy = trace(@src()); |
| 2276 | defer tracy.end(); | 2595 | defer tracy.end(); |
| 2277 | | 2596 | |
| ... | @@ -2282,15 +2601,16 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2282,15 +2601,16 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2282 | | 2601 | |
| 2283 | // we check this here to avoid undefined symbols | 2602 | // we check this here to avoid undefined symbols |
| 2284 | if (!@import("build_options").have_llvm) | 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 | var c_import_buf = std.ArrayList(u8).init(sema.gpa); | 2606 | var c_import_buf = std.ArrayList(u8).init(sema.gpa); |
| 2288 | defer c_import_buf.deinit(); | 2607 | defer c_import_buf.deinit(); |
| 2289 | | 2608 | |
| 2290 | var child_block: Scope.Block = .{ | 2609 | var child_block: Block = .{ |
| 2291 | .parent = parent_block, | 2610 | .parent = parent_block, |
| 2292 | .sema = sema, | 2611 | .sema = sema, |
| 2293 | .src_decl = parent_block.src_decl, | 2612 | .src_decl = parent_block.src_decl, |
| | 2613 | .namespace = parent_block.namespace, |
| 2294 | .wip_capture_scope = parent_block.wip_capture_scope, | 2614 | .wip_capture_scope = parent_block.wip_capture_scope, |
| 2295 | .instructions = .{}, | 2615 | .instructions = .{}, |
| 2296 | .inlining = parent_block.inlining, | 2616 | .inlining = parent_block.inlining, |
| ... | @@ -2302,15 +2622,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2302,15 +2622,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2302 | _ = try sema.analyzeBody(&child_block, body); | 2622 | _ = try sema.analyzeBody(&child_block, body); |
| 2303 | | 2623 | |
| 2304 | const c_import_res = sema.mod.comp.cImport(c_import_buf.items) catch |err| | 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 | if (c_import_res.errors.len != 0) { | 2627 | if (c_import_res.errors.len != 0) { |
| 2308 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 2630 | errdefer msg.destroy(sema.gpa); |
| 2311 | | 2631 | |
| 2312 | if (!sema.mod.comp.bin_file.options.link_libc) | 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 | for (c_import_res.errors) |_| { | 2635 | for (c_import_res.errors) |_| { |
| 2316 | // TODO integrate with LazySrcLoc | 2636 | // TODO integrate with LazySrcLoc |
| ... | @@ -2322,7 +2642,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2322,7 +2642,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2322 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); | 2642 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); |
| 2323 | break :msg msg; | 2643 | break :msg msg; |
| 2324 | }; | 2644 | }; |
| 2325 | return sema.mod.failWithOwnedErrorMsg(&child_block.base, msg); | 2645 | return sema.failWithOwnedErrorMsg(msg); |
| 2326 | } | 2646 | } |
| 2327 | const c_import_pkg = Package.create( | 2647 | const c_import_pkg = Package.create( |
| 2328 | sema.gpa, | 2648 | sema.gpa, |
| ... | @@ -2338,10 +2658,10 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2338,10 +2658,10 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2338 | try c_import_pkg.add(sema.gpa, "std", std_pkg); | 2658 | try c_import_pkg.add(sema.gpa, "std", std_pkg); |
| 2339 | | 2659 | |
| 2340 | const result = sema.mod.importPkg(c_import_pkg) catch |err| | 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 | sema.mod.astGenFile(result.file) catch |err| | 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 | try sema.mod.semaFile(result.file); | 2666 | try sema.mod.semaFile(result.file); |
| 2347 | const file_root_decl = result.file.root_decl.?; | 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,15 +2669,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2349 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 2673 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 2354 | const src = inst_data.src(); | 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 | fn zirBlock( | 2678 | fn zirBlock( |
| 2359 | sema: *Sema, | 2679 | sema: *Sema, |
| 2360 | parent_block: *Scope.Block, | 2680 | parent_block: *Block, |
| 2361 | inst: Zir.Inst.Index, | 2681 | inst: Zir.Inst.Index, |
| 2362 | ) CompileError!Air.Inst.Ref { | 2682 | ) CompileError!Air.Inst.Ref { |
| 2363 | const tracy = trace(@src()); | 2683 | const tracy = trace(@src()); |
| ... | @@ -2378,7 +2698,7 @@ fn zirBlock( | ... | @@ -2378,7 +2698,7 @@ fn zirBlock( |
| 2378 | .data = undefined, | 2698 | .data = undefined, |
| 2379 | }); | 2699 | }); |
| 2380 | | 2700 | |
| 2381 | var label: Scope.Block.Label = .{ | 2701 | var label: Block.Label = .{ |
| 2382 | .zir_block = inst, | 2702 | .zir_block = inst, |
| 2383 | .merges = .{ | 2703 | .merges = .{ |
| 2384 | .results = .{}, | 2704 | .results = .{}, |
| ... | @@ -2387,10 +2707,11 @@ fn zirBlock( | ... | @@ -2387,10 +2707,11 @@ fn zirBlock( |
| 2387 | }, | 2707 | }, |
| 2388 | }; | 2708 | }; |
| 2389 | | 2709 | |
| 2390 | var child_block: Scope.Block = .{ | 2710 | var child_block: Block = .{ |
| 2391 | .parent = parent_block, | 2711 | .parent = parent_block, |
| 2392 | .sema = sema, | 2712 | .sema = sema, |
| 2393 | .src_decl = parent_block.src_decl, | 2713 | .src_decl = parent_block.src_decl, |
| | 2714 | .namespace = parent_block.namespace, |
| 2394 | .wip_capture_scope = parent_block.wip_capture_scope, | 2715 | .wip_capture_scope = parent_block.wip_capture_scope, |
| 2395 | .instructions = .{}, | 2716 | .instructions = .{}, |
| 2396 | .label = &label, | 2717 | .label = &label, |
| ... | @@ -2410,11 +2731,11 @@ fn zirBlock( | ... | @@ -2410,11 +2731,11 @@ fn zirBlock( |
| 2410 | | 2731 | |
| 2411 | fn resolveBlockBody( | 2732 | fn resolveBlockBody( |
| 2412 | sema: *Sema, | 2733 | sema: *Sema, |
| 2413 | parent_block: *Scope.Block, | 2734 | parent_block: *Block, |
| 2414 | src: LazySrcLoc, | 2735 | src: LazySrcLoc, |
| 2415 | child_block: *Scope.Block, | 2736 | child_block: *Block, |
| 2416 | body: []const Zir.Inst.Index, | 2737 | body: []const Zir.Inst.Index, |
| 2417 | merges: *Scope.Block.Merges, | 2738 | merges: *Block.Merges, |
| 2418 | ) CompileError!Air.Inst.Ref { | 2739 | ) CompileError!Air.Inst.Ref { |
| 2419 | if (child_block.is_comptime) { | 2740 | if (child_block.is_comptime) { |
| 2420 | return sema.resolveBody(child_block, body); | 2741 | return sema.resolveBody(child_block, body); |
| ... | @@ -2426,10 +2747,10 @@ fn resolveBlockBody( | ... | @@ -2426,10 +2747,10 @@ fn resolveBlockBody( |
| 2426 | | 2747 | |
| 2427 | fn analyzeBlockBody( | 2748 | fn analyzeBlockBody( |
| 2428 | sema: *Sema, | 2749 | sema: *Sema, |
| 2429 | parent_block: *Scope.Block, | 2750 | parent_block: *Block, |
| 2430 | src: LazySrcLoc, | 2751 | src: LazySrcLoc, |
| 2431 | child_block: *Scope.Block, | 2752 | child_block: *Block, |
| 2432 | merges: *Scope.Block.Merges, | 2753 | merges: *Block.Merges, |
| 2433 | ) CompileError!Air.Inst.Ref { | 2754 | ) CompileError!Air.Inst.Ref { |
| 2434 | const tracy = trace(@src()); | 2755 | const tracy = trace(@src()); |
| 2435 | defer tracy.end(); | 2756 | defer tracy.end(); |
| ... | @@ -2527,7 +2848,7 @@ fn analyzeBlockBody( | ... | @@ -2527,7 +2848,7 @@ fn analyzeBlockBody( |
| 2527 | return Air.indexToRef(merges.block_inst); | 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 | const tracy = trace(@src()); | 2852 | const tracy = trace(@src()); |
| 2532 | defer tracy.end(); | 2853 | defer tracy.end(); |
| 2533 | | 2854 | |
| ... | @@ -2538,14 +2859,14 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -2538,14 +2859,14 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 2538 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 2859 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 2539 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); | 2860 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); |
| 2540 | if (extra.namespace != .none) { | 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 | const decl = try sema.lookupIdentifier(block, operand_src, decl_name); | 2864 | const decl = try sema.lookupIdentifier(block, operand_src, decl_name); |
| 2544 | const options = try sema.resolveExportOptions(block, options_src, extra.options); | 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 | const tracy = trace(@src()); | 2870 | const tracy = trace(@src()); |
| 2550 | defer tracy.end(); | 2871 | defer tracy.end(); |
| 2551 | | 2872 | |
| ... | @@ -2558,45 +2879,122 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -2558,45 +2879,122 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2558 | const options = try sema.resolveExportOptions(block, options_src, extra.options); | 2879 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 2559 | const decl = switch (operand.val.tag()) { | 2880 | const decl = switch (operand.val.tag()) { |
| 2560 | .function => operand.val.castTag(.function).?.data.owner_decl, | 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 | const mod = sema.mod; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 2966 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2569 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 2967 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2570 | const src: LazySrcLoc = inst_data.src(); | 2968 | const src: LazySrcLoc = inst_data.src(); |
| 2571 | const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand); | 2969 | const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand); |
| 2572 | if (alignment > 256) { | 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 | alignment, | 2972 | alignment, |
| 2575 | }); | 2973 | }); |
| 2576 | } | 2974 | } |
| 2577 | const func = sema.owner_func orelse | 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 | switch (func.owner_decl.ty.fnCallingConvention()) { | 2978 | switch (func.owner_decl.ty.fnCallingConvention()) { |
| 2581 | .Naked => return mod.fail(&block.base, src, "@setAlignStack in naked function", .{}), | 2979 | .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}), |
| 2582 | .Inline => return mod.fail(&block.base, src, "@setAlignStack in inline function", .{}), | 2980 | .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}), |
| 2583 | else => {}, | 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 | if (gop.found_existing) { | 2985 | if (gop.found_existing) { |
| 2588 | const msg = msg: { | 2986 | const msg = msg: { |
| 2589 | const msg = try mod.errMsg(&block.base, src, "multiple @setAlignStack in the same function body", .{}); | 2987 | const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{}); |
| 2590 | errdefer msg.destroy(mod.gpa); | 2988 | errdefer msg.destroy(sema.gpa); |
| 2591 | try mod.errNote(&block.base, src, msg, "other instance here", .{}); | 2989 | try sema.errNote(block, src, msg, "other instance here", .{}); |
| 2592 | break :msg msg; | 2990 | break :msg msg; |
| 2593 | }; | 2991 | }; |
| 2594 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 2992 | return sema.failWithOwnedErrorMsg(msg); |
| 2595 | } | 2993 | } |
| 2596 | gop.value_ptr.* = .{ .alignment = alignment, .src = src }; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 2998 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2601 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 2999 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2602 | const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand); | 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,19 +3002,19 @@ fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2604 | func.is_cold = is_cold; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 3006 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2609 | const src: LazySrcLoc = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 3012 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2615 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 3013 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2616 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand); | 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 | if (block.is_comptime) return; | 3018 | if (block.is_comptime) return; |
| 2621 | | 3019 | |
| 2622 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 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,7 +3022,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2624 | const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand); | 3022 | const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand); |
| 2625 | | 3023 | |
| 2626 | if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) { | 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 | _ = try block.addInst(.{ | 3028 | _ = try block.addInst(.{ |
| ... | @@ -2633,7 +3031,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError | ... | @@ -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 | const tracy = trace(@src()); | 3035 | const tracy = trace(@src()); |
| 2638 | defer tracy.end(); | 3036 | defer tracy.end(); |
| 2639 | | 3037 | |
| ... | @@ -2655,7 +3053,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -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 | const tracy = trace(@src()); | 3057 | const tracy = trace(@src()); |
| 2660 | defer tracy.end(); | 3058 | defer tracy.end(); |
| 2661 | | 3059 | |
| ... | @@ -2675,7 +3073,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -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 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 3077 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 2680 | const src = inst_data.src(); | 3078 | const src = inst_data.src(); |
| 2681 | const decl_name = inst_data.get(sema.code); | 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,7 +3081,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2683 | return sema.analyzeDeclRef(decl); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 3085 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 2688 | const src = inst_data.src(); | 3086 | const src = inst_data.src(); |
| 2689 | const decl_name = inst_data.get(sema.code); | 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,8 +3089,8 @@ fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2691 | return sema.analyzeDeclVal(block, src, decl); | 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 { | 3092 | fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: []const u8) !*Decl { |
| 2695 | var namespace = sema.namespace; | 3093 | var namespace = block.namespace; |
| 2696 | while (true) { | 3094 | while (true) { |
| 2697 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl| { | 3095 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl| { |
| 2698 | return decl; | 3096 | return decl; |
| ... | @@ -2706,9 +3104,9 @@ fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []c | ... | @@ -2706,9 +3104,9 @@ fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []c |
| 2706 | /// only for ones in the specified namespace. | 3104 | /// only for ones in the specified namespace. |
| 2707 | fn lookupInNamespace( | 3105 | fn lookupInNamespace( |
| 2708 | sema: *Sema, | 3106 | sema: *Sema, |
| 2709 | block: *Scope.Block, | 3107 | block: *Block, |
| 2710 | src: LazySrcLoc, | 3108 | src: LazySrcLoc, |
| 2711 | namespace: *Scope.Namespace, | 3109 | namespace: *Namespace, |
| 2712 | ident_name: []const u8, | 3110 | ident_name: []const u8, |
| 2713 | observe_usingnamespace: bool, | 3111 | observe_usingnamespace: bool, |
| 2714 | ) CompileError!?*Decl { | 3112 | ) CompileError!?*Decl { |
| ... | @@ -2721,10 +3119,10 @@ fn lookupInNamespace( | ... | @@ -2721,10 +3119,10 @@ fn lookupInNamespace( |
| 2721 | } | 3119 | } |
| 2722 | | 3120 | |
| 2723 | if (observe_usingnamespace and namespace.usingnamespace_set.count() != 0) { | 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 | const gpa = sema.gpa; | 3124 | const gpa = sema.gpa; |
| 2727 | var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Scope.Namespace, void) = .{}; | 3125 | var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, void) = .{}; |
| 2728 | defer checked_namespaces.deinit(gpa); | 3126 | defer checked_namespaces.deinit(gpa); |
| 2729 | | 3127 | |
| 2730 | // Keep track of name conflicts for error notes. | 3128 | // Keep track of name conflicts for error notes. |
| ... | @@ -2739,7 +3137,7 @@ fn lookupInNamespace( | ... | @@ -2739,7 +3137,7 @@ fn lookupInNamespace( |
| 2739 | if (check_ns.decls.get(ident_name)) |decl| { | 3137 | if (check_ns.decls.get(ident_name)) |decl| { |
| 2740 | // Skip decls which are not marked pub, which are in a different | 3138 | // Skip decls which are not marked pub, which are in a different |
| 2741 | // file than the `a.b`/`@hasDecl` syntax. | 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 | try candidates.append(gpa, decl); | 3141 | try candidates.append(gpa, decl); |
| 2744 | } | 3142 | } |
| 2745 | } | 3143 | } |
| ... | @@ -2747,7 +3145,7 @@ fn lookupInNamespace( | ... | @@ -2747,7 +3145,7 @@ fn lookupInNamespace( |
| 2747 | while (it.next()) |entry| { | 3145 | while (it.next()) |entry| { |
| 2748 | const sub_usingnamespace_decl = entry.key_ptr.*; | 3146 | const sub_usingnamespace_decl = entry.key_ptr.*; |
| 2749 | const sub_is_pub = entry.value_ptr.*; | 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 | // Skip usingnamespace decls which are not marked pub, which are in | 3149 | // Skip usingnamespace decls which are not marked pub, which are in |
| 2752 | // a different file than the `a.b`/`@hasDecl` syntax. | 3150 | // a different file than the `a.b`/`@hasDecl` syntax. |
| 2753 | continue; | 3151 | continue; |
| ... | @@ -2768,7 +3166,7 @@ fn lookupInNamespace( | ... | @@ -2768,7 +3166,7 @@ fn lookupInNamespace( |
| 2768 | }, | 3166 | }, |
| 2769 | else => { | 3167 | else => { |
| 2770 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 3170 | errdefer msg.destroy(gpa); |
| 2773 | for (candidates.items) |candidate| { | 3171 | for (candidates.items) |candidate| { |
| 2774 | const src_loc = candidate.srcLoc(); | 3172 | const src_loc = candidate.srcLoc(); |
| ... | @@ -2776,7 +3174,7 @@ fn lookupInNamespace( | ... | @@ -2776,7 +3174,7 @@ fn lookupInNamespace( |
| 2776 | } | 3174 | } |
| 2777 | break :msg msg; | 3175 | break :msg msg; |
| 2778 | }; | 3176 | }; |
| 2779 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 3177 | return sema.failWithOwnedErrorMsg(msg); |
| 2780 | }, | 3178 | }, |
| 2781 | } | 3179 | } |
| 2782 | } else if (namespace.decls.get(ident_name)) |decl| { | 3180 | } else if (namespace.decls.get(ident_name)) |decl| { |
| ... | @@ -2796,7 +3194,7 @@ fn lookupInNamespace( | ... | @@ -2796,7 +3194,7 @@ fn lookupInNamespace( |
| 2796 | | 3194 | |
| 2797 | fn zirCall( | 3195 | fn zirCall( |
| 2798 | sema: *Sema, | 3196 | sema: *Sema, |
| 2799 | block: *Scope.Block, | 3197 | block: *Block, |
| 2800 | inst: Zir.Inst.Index, | 3198 | inst: Zir.Inst.Index, |
| 2801 | ) CompileError!Air.Inst.Ref { | 3199 | ) CompileError!Air.Inst.Ref { |
| 2802 | const tracy = trace(@src()); | 3200 | const tracy = trace(@src()); |
| ... | @@ -2898,7 +3296,7 @@ const GenericRemoveAdapter = struct { | ... | @@ -2898,7 +3296,7 @@ const GenericRemoveAdapter = struct { |
| 2898 | | 3296 | |
| 2899 | fn analyzeCall( | 3297 | fn analyzeCall( |
| 2900 | sema: *Sema, | 3298 | sema: *Sema, |
| 2901 | block: *Scope.Block, | 3299 | block: *Block, |
| 2902 | func: Air.Inst.Ref, | 3300 | func: Air.Inst.Ref, |
| 2903 | func_src: LazySrcLoc, | 3301 | func_src: LazySrcLoc, |
| 2904 | call_src: LazySrcLoc, | 3302 | call_src: LazySrcLoc, |
| ... | @@ -2910,14 +3308,14 @@ fn analyzeCall( | ... | @@ -2910,14 +3308,14 @@ fn analyzeCall( |
| 2910 | | 3308 | |
| 2911 | const func_ty = sema.typeOf(func); | 3309 | const func_ty = sema.typeOf(func); |
| 2912 | if (func_ty.zigTypeTag() != .Fn) | 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 | const func_ty_info = func_ty.fnInfo(); | 3313 | const func_ty_info = func_ty.fnInfo(); |
| 2916 | const cc = func_ty_info.cc; | 3314 | const cc = func_ty_info.cc; |
| 2917 | if (cc == .Naked) { | 3315 | if (cc == .Naked) { |
| 2918 | // TODO add error note: declared here | 3316 | // TODO add error note: declared here |
| 2919 | return mod.fail( | 3317 | return sema.fail( |
| 2920 | &block.base, | 3318 | block, |
| 2921 | func_src, | 3319 | func_src, |
| 2922 | "unable to call function with naked calling convention", | 3320 | "unable to call function with naked calling convention", |
| 2923 | .{}, | 3321 | .{}, |
| ... | @@ -2928,8 +3326,8 @@ fn analyzeCall( | ... | @@ -2928,8 +3326,8 @@ fn analyzeCall( |
| 2928 | assert(cc == .C); | 3326 | assert(cc == .C); |
| 2929 | if (uncasted_args.len < fn_params_len) { | 3327 | if (uncasted_args.len < fn_params_len) { |
| 2930 | // TODO add error note: declared here | 3328 | // TODO add error note: declared here |
| 2931 | return mod.fail( | 3329 | return sema.fail( |
| 2932 | &block.base, | 3330 | block, |
| 2933 | func_src, | 3331 | func_src, |
| 2934 | "expected at least {d} argument(s), found {d}", | 3332 | "expected at least {d} argument(s), found {d}", |
| 2935 | .{ fn_params_len, uncasted_args.len }, | 3333 | .{ fn_params_len, uncasted_args.len }, |
| ... | @@ -2937,8 +3335,8 @@ fn analyzeCall( | ... | @@ -2937,8 +3335,8 @@ fn analyzeCall( |
| 2937 | } | 3335 | } |
| 2938 | } else if (fn_params_len != uncasted_args.len) { | 3336 | } else if (fn_params_len != uncasted_args.len) { |
| 2939 | // TODO add error note: declared here | 3337 | // TODO add error note: declared here |
| 2940 | return mod.fail( | 3338 | return sema.fail( |
| 2941 | &block.base, | 3339 | block, |
| 2942 | func_src, | 3340 | func_src, |
| 2943 | "expected {d} argument(s), found {d}", | 3341 | "expected {d} argument(s), found {d}", |
| 2944 | .{ fn_params_len, uncasted_args.len }, | 3342 | .{ fn_params_len, uncasted_args.len }, |
| ... | @@ -2956,7 +3354,7 @@ fn analyzeCall( | ... | @@ -2956,7 +3354,7 @@ fn analyzeCall( |
| 2956 | .never_inline, | 3354 | .never_inline, |
| 2957 | .no_async, | 3355 | .no_async, |
| 2958 | .always_tail, | 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 | modifier, | 3358 | modifier, |
| 2961 | }), | 3359 | }), |
| 2962 | } | 3360 | } |
| ... | @@ -2971,7 +3369,7 @@ fn analyzeCall( | ... | @@ -2971,7 +3369,7 @@ fn analyzeCall( |
| 2971 | const func_val = try sema.resolveConstValue(block, func_src, func); | 3369 | const func_val = try sema.resolveConstValue(block, func_src, func); |
| 2972 | const module_fn = switch (func_val.tag()) { | 3370 | const module_fn = switch (func_val.tag()) { |
| 2973 | .function => func_val.castTag(.function).?.data, | 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 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), | 3373 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| 2976 | }), | 3374 | }), |
| 2977 | else => unreachable, | 3375 | else => unreachable, |
| ... | @@ -2979,7 +3377,7 @@ fn analyzeCall( | ... | @@ -2979,7 +3377,7 @@ fn analyzeCall( |
| 2979 | | 3377 | |
| 2980 | // Analyze the ZIR. The same ZIR gets analyzed into a runtime function | 3378 | // Analyze the ZIR. The same ZIR gets analyzed into a runtime function |
| 2981 | // or an inlined call depending on what union tag the `label` field is | 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 | // This block instruction will be used to capture the return value from the | 3381 | // This block instruction will be used to capture the return value from the |
| 2984 | // inlined function. | 3382 | // inlined function. |
| 2985 | const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len); | 3383 | const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len); |
| ... | @@ -2989,7 +3387,7 @@ fn analyzeCall( | ... | @@ -2989,7 +3387,7 @@ fn analyzeCall( |
| 2989 | }); | 3387 | }); |
| 2990 | // This one is shared among sub-blocks within the same callee, but not | 3388 | // This one is shared among sub-blocks within the same callee, but not |
| 2991 | // shared among the entire inline/comptime call stack. | 3389 | // shared among the entire inline/comptime call stack. |
| 2992 | var inlining: Scope.Block.Inlining = .{ | 3390 | var inlining: Block.Inlining = .{ |
| 2993 | .comptime_result = undefined, | 3391 | .comptime_result = undefined, |
| 2994 | .merges = .{ | 3392 | .merges = .{ |
| 2995 | .results = .{}, | 3393 | .results = .{}, |
| ... | @@ -3000,7 +3398,7 @@ fn analyzeCall( | ... | @@ -3000,7 +3398,7 @@ fn analyzeCall( |
| 3000 | // In order to save a bit of stack space, directly modify Sema rather | 3398 | // In order to save a bit of stack space, directly modify Sema rather |
| 3001 | // than create a child one. | 3399 | // than create a child one. |
| 3002 | const parent_zir = sema.code; | 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 | defer sema.code = parent_zir; | 3402 | defer sema.code = parent_zir; |
| 3005 | | 3403 | |
| 3006 | const parent_inst_map = sema.inst_map; | 3404 | const parent_inst_map = sema.inst_map; |
| ... | @@ -3010,10 +3408,6 @@ fn analyzeCall( | ... | @@ -3010,10 +3408,6 @@ fn analyzeCall( |
| 3010 | sema.inst_map = parent_inst_map; | 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 | const parent_func = sema.func; | 3411 | const parent_func = sema.func; |
| 3018 | sema.func = module_fn; | 3412 | sema.func = module_fn; |
| 3019 | defer sema.func = parent_func; | 3413 | defer sema.func = parent_func; |
| ... | @@ -3021,10 +3415,11 @@ fn analyzeCall( | ... | @@ -3021,10 +3415,11 @@ fn analyzeCall( |
| 3021 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, module_fn.owner_decl.src_scope); | 3415 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, module_fn.owner_decl.src_scope); |
| 3022 | defer wip_captures.deinit(); | 3416 | defer wip_captures.deinit(); |
| 3023 | | 3417 | |
| 3024 | var child_block: Scope.Block = .{ | 3418 | var child_block: Block = .{ |
| 3025 | .parent = null, | 3419 | .parent = null, |
| 3026 | .sema = sema, | 3420 | .sema = sema, |
| 3027 | .src_decl = module_fn.owner_decl, | 3421 | .src_decl = module_fn.owner_decl, |
| | 3422 | .namespace = module_fn.owner_decl.src_namespace, |
| 3028 | .wip_capture_scope = wip_captures.scope, | 3423 | .wip_capture_scope = wip_captures.scope, |
| 3029 | .instructions = .{}, | 3424 | .instructions = .{}, |
| 3030 | .label = null, | 3425 | .label = null, |
| ... | @@ -3180,12 +3575,6 @@ fn analyzeCall( | ... | @@ -3180,12 +3575,6 @@ fn analyzeCall( |
| 3180 | }); | 3575 | }); |
| 3181 | delete_memoized_call_key = false; | 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 | break :res2 result; | 3580 | break :res2 result; |
| ... | @@ -3200,7 +3589,7 @@ fn analyzeCall( | ... | @@ -3200,7 +3589,7 @@ fn analyzeCall( |
| 3200 | // Check the Module's generic function map with an adapted context, so that we | 3589 | // Check the Module's generic function map with an adapted context, so that we |
| 3201 | // can match against `uncasted_args` rather than doing the work below to create a | 3590 | // can match against `uncasted_args` rather than doing the work below to create a |
| 3202 | // generic Scope only to junk it if it matches an existing instantiation. | 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 | const fn_zir = namespace.file_scope.zir; | 3593 | const fn_zir = namespace.file_scope.zir; |
| 3205 | const fn_info = fn_zir.getFnInfo(module_fn.zir_body_inst); | 3594 | const fn_info = fn_zir.getFnInfo(module_fn.zir_body_inst); |
| 3206 | const zir_tags = fn_zir.instructions.items(.tag); | 3595 | const zir_tags = fn_zir.instructions.items(.tag); |
| ... | @@ -3276,12 +3665,12 @@ fn analyzeCall( | ... | @@ -3276,12 +3665,12 @@ fn analyzeCall( |
| 3276 | | 3665 | |
| 3277 | // Create a Decl for the new function. | 3666 | // Create a Decl for the new function. |
| 3278 | const src_decl = namespace.getDecl(); | 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 | // TODO better names for generic function instantiations | 3668 | // TODO better names for generic function instantiations |
| 3281 | const name_index = mod.getNextAnonNameIndex(); | 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 | module_fn.owner_decl.name, name_index, | 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 | new_decl.src_line = module_fn.owner_decl.src_line; | 3674 | new_decl.src_line = module_fn.owner_decl.src_line; |
| 3286 | new_decl.is_pub = module_fn.owner_decl.is_pub; | 3675 | new_decl.is_pub = module_fn.owner_decl.is_pub; |
| 3287 | new_decl.is_exported = module_fn.owner_decl.is_exported; | 3676 | new_decl.is_exported = module_fn.owner_decl.is_exported; |
| ... | @@ -3297,6 +3686,11 @@ fn analyzeCall( | ... | @@ -3297,6 +3686,11 @@ fn analyzeCall( |
| 3297 | | 3686 | |
| 3298 | namespace.anon_decls.putAssumeCapacityNoClobber(new_decl, {}); | 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 | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); | 3694 | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); |
| 3301 | errdefer new_decl_arena.deinit(); | 3695 | errdefer new_decl_arena.deinit(); |
| 3302 | | 3696 | |
| ... | @@ -3311,7 +3705,6 @@ fn analyzeCall( | ... | @@ -3311,7 +3705,6 @@ fn analyzeCall( |
| 3311 | .perm_arena = &new_decl_arena.allocator, | 3705 | .perm_arena = &new_decl_arena.allocator, |
| 3312 | .code = fn_zir, | 3706 | .code = fn_zir, |
| 3313 | .owner_decl = new_decl, | 3707 | .owner_decl = new_decl, |
| 3314 | .namespace = namespace, | | |
| 3315 | .func = null, | 3708 | .func = null, |
| 3316 | .fn_ret_ty = Type.initTag(.void), | 3709 | .fn_ret_ty = Type.initTag(.void), |
| 3317 | .owner_func = null, | 3710 | .owner_func = null, |
| ... | @@ -3324,10 +3717,11 @@ fn analyzeCall( | ... | @@ -3324,10 +3717,11 @@ fn analyzeCall( |
| 3324 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope); | 3717 | var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope); |
| 3325 | defer wip_captures.deinit(); | 3718 | defer wip_captures.deinit(); |
| 3326 | | 3719 | |
| 3327 | var child_block: Scope.Block = .{ | 3720 | var child_block: Block = .{ |
| 3328 | .parent = null, | 3721 | .parent = null, |
| 3329 | .sema = &child_sema, | 3722 | .sema = &child_sema, |
| 3330 | .src_decl = new_decl, | 3723 | .src_decl = new_decl, |
| | 3724 | .namespace = namespace, |
| 3331 | .wip_capture_scope = wip_captures.scope, | 3725 | .wip_capture_scope = wip_captures.scope, |
| 3332 | .instructions = .{}, | 3726 | .instructions = .{}, |
| 3333 | .inlining = null, | 3727 | .inlining = null, |
| ... | @@ -3430,11 +3824,6 @@ fn analyzeCall( | ... | @@ -3430,11 +3824,6 @@ fn analyzeCall( |
| 3430 | }); | 3824 | }); |
| 3431 | assert(!new_decl.ty.fnInfo().is_generic); | 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 | // Queue up a `codegen_func` work item for the new Fn. The `comptime_args` field | 3827 | // Queue up a `codegen_func` work item for the new Fn. The `comptime_args` field |
| 3439 | // will be populated, ensuring it will have `analyzeBody` called with the ZIR | 3828 | // will be populated, ensuring it will have `analyzeBody` called with the ZIR |
| 3440 | // parameters mapped appropriately. | 3829 | // parameters mapped appropriately. |
| ... | @@ -3489,7 +3878,7 @@ fn analyzeCall( | ... | @@ -3489,7 +3878,7 @@ fn analyzeCall( |
| 3489 | | 3878 | |
| 3490 | fn finishGenericCall( | 3879 | fn finishGenericCall( |
| 3491 | sema: *Sema, | 3880 | sema: *Sema, |
| 3492 | block: *Scope.Block, | 3881 | block: *Block, |
| 3493 | call_src: LazySrcLoc, | 3882 | call_src: LazySrcLoc, |
| 3494 | callee: *Module.Fn, | 3883 | callee: *Module.Fn, |
| 3495 | func_src: LazySrcLoc, | 3884 | func_src: LazySrcLoc, |
| ... | @@ -3556,7 +3945,7 @@ fn finishGenericCall( | ... | @@ -3556,7 +3945,7 @@ fn finishGenericCall( |
| 3556 | return func_inst; | 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 | _ = block; | 3949 | _ = block; |
| 3561 | const tracy = trace(@src()); | 3950 | const tracy = trace(@src()); |
| 3562 | defer tracy.end(); | 3951 | defer tracy.end(); |
| ... | @@ -3567,7 +3956,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -3567,7 +3956,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 3567 | return sema.addType(ty); | 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 | const tracy = trace(@src()); | 3960 | const tracy = trace(@src()); |
| 3572 | defer tracy.end(); | 3961 | defer tracy.end(); |
| 3573 | | 3962 | |
| ... | @@ -3579,7 +3968,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi | ... | @@ -3579,7 +3968,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 3579 | return sema.addType(opt_type); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 3972 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3584 | const src = inst_data.src(); | 3973 | const src = inst_data.src(); |
| 3585 | const array_type = try sema.resolveType(block, src, inst_data.operand); | 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,7 +3976,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 3587 | return sema.addType(elem_type); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 3980 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3592 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 3981 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 3593 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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,7 +3990,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3601 | return sema.addType(vector_type); | 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 | const tracy = trace(@src()); | 3994 | const tracy = trace(@src()); |
| 3606 | defer tracy.end(); | 3995 | defer tracy.end(); |
| 3607 | | 3996 | |
| ... | @@ -3613,7 +4002,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3613,7 +4002,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3613 | return sema.addType(array_ty); | 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 | const tracy = trace(@src()); | 4006 | const tracy = trace(@src()); |
| 3618 | defer tracy.end(); | 4007 | defer tracy.end(); |
| 3619 | | 4008 | |
| ... | @@ -3629,7 +4018,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) | ... | @@ -3629,7 +4018,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 3629 | return sema.addType(array_ty); | 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 | const tracy = trace(@src()); | 4022 | const tracy = trace(@src()); |
| 3634 | defer tracy.end(); | 4023 | defer tracy.end(); |
| 3635 | | 4024 | |
| ... | @@ -3641,7 +4030,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi | ... | @@ -3641,7 +4030,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 3641 | return sema.addType(anyframe_type); | 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 | const tracy = trace(@src()); | 4034 | const tracy = trace(@src()); |
| 3646 | defer tracy.end(); | 4035 | defer tracy.end(); |
| 3647 | | 4036 | |
| ... | @@ -3653,7 +4042,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -3653,7 +4042,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3653 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); | 4042 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); |
| 3654 | | 4043 | |
| 3655 | if (error_union.zigTypeTag() != .ErrorSet) { | 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 | error_union.elemType(), | 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,7 +4050,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3661 | return sema.addType(err_union_ty); | 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 | _ = block; | 4054 | _ = block; |
| 3666 | const tracy = trace(@src()); | 4055 | const tracy = trace(@src()); |
| 3667 | defer tracy.end(); | 4056 | defer tracy.end(); |
| ... | @@ -3679,7 +4068,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile | ... | @@ -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 | const tracy = trace(@src()); | 4072 | const tracy = trace(@src()); |
| 3684 | defer tracy.end(); | 4073 | defer tracy.end(); |
| 3685 | | 4074 | |
| ... | @@ -3706,7 +4095,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile | ... | @@ -3706,7 +4095,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3706 | return block.addTyOp(.bitcast, result_ty, op_coerced); | 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 | const tracy = trace(@src()); | 4099 | const tracy = trace(@src()); |
| 3711 | defer tracy.end(); | 4100 | defer tracy.end(); |
| 3712 | | 4101 | |
| ... | @@ -3719,7 +4108,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile | ... | @@ -3719,7 +4108,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3719 | if (try sema.resolveDefinedValue(block, operand_src, op)) |value| { | 4108 | if (try sema.resolveDefinedValue(block, operand_src, op)) |value| { |
| 3720 | const int = value.toUnsignedInt(); | 4109 | const int = value.toUnsignedInt(); |
| 3721 | if (int > sema.mod.global_error_set.count() or int == 0) | 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 | const payload = try sema.arena.create(Value.Payload.Error); | 4112 | const payload = try sema.arena.create(Value.Payload.Error); |
| 3724 | payload.* = .{ | 4113 | payload.* = .{ |
| 3725 | .base = .{ .tag = .@"error" }, | 4114 | .base = .{ .tag = .@"error" }, |
| ... | @@ -3729,14 +4118,14 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile | ... | @@ -3729,14 +4118,14 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3729 | } | 4118 | } |
| 3730 | try sema.requireRuntimeBlock(block, src); | 4119 | try sema.requireRuntimeBlock(block, src); |
| 3731 | if (block.wantSafety()) { | 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 | // const is_gt_max = @panic("TODO get max errors in compilation"); | 4122 | // const is_gt_max = @panic("TODO get max errors in compilation"); |
| 3734 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); | 4123 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); |
| 3735 | } | 4124 | } |
| 3736 | return block.addTyOp(.bitcast, Type.initTag(.anyerror), op); | 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 | const tracy = trace(@src()); | 4129 | const tracy = trace(@src()); |
| 3741 | defer tracy.end(); | 4130 | defer tracy.end(); |
| 3742 | | 4131 | |
| ... | @@ -3749,19 +4138,19 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -3749,19 +4138,19 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3749 | const rhs = sema.resolveInst(extra.rhs); | 4138 | const rhs = sema.resolveInst(extra.rhs); |
| 3750 | if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) { | 4139 | if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) { |
| 3751 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 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 | break :msg msg; | 4144 | break :msg msg; |
| 3756 | }; | 4145 | }; |
| 3757 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 4146 | return sema.failWithOwnedErrorMsg(msg); |
| 3758 | } | 4147 | } |
| 3759 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); | 4148 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); |
| 3760 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); | 4149 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); |
| 3761 | if (lhs_ty.zigTypeTag() != .ErrorSet) | 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 | if (rhs_ty.zigTypeTag() != .ErrorSet) | 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 | // Anything merged with anyerror is anyerror. | 4155 | // Anything merged with anyerror is anyerror. |
| 3767 | if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) { | 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,7 +4209,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3820 | return sema.addConstant(Type.initTag(.type), try Value.Tag.ty.create(sema.arena, error_set_ty)); | 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 | _ = block; | 4213 | _ = block; |
| 3825 | const tracy = trace(@src()); | 4214 | const tracy = trace(@src()); |
| 3826 | defer tracy.end(); | 4215 | defer tracy.end(); |
| ... | @@ -3833,8 +4222,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -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 { | 4225 | fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3837 | const mod = sema.mod; | | |
| 3838 | const arena = sema.arena; | 4226 | const arena = sema.arena; |
| 3839 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 4227 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3840 | const src = inst_data.src(); | 4228 | const src = inst_data.src(); |
| ... | @@ -3846,17 +4234,17 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3846,17 +4234,17 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3846 | .Enum => operand, | 4234 | .Enum => operand, |
| 3847 | .Union => { | 4235 | .Union => { |
| 3848 | //if (!operand_ty.unionHasTag()) { | 4236 | //if (!operand_ty.unionHasTag()) { |
| 3849 | // return mod.fail( | 4237 | // return sema.fail( |
| 3850 | // &block.base, | 4238 | // block, |
| 3851 | // operand_src, | 4239 | // operand_src, |
| 3852 | // "untagged union '{}' cannot be converted to integer", | 4240 | // "untagged union '{}' cannot be converted to integer", |
| 3853 | // .{dest_ty_src}, | 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 | else => { | 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 | operand_ty, | 4248 | operand_ty, |
| 3861 | }); | 4249 | }); |
| 3862 | }, | 4250 | }, |
| ... | @@ -3880,9 +4268,8 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3880,9 +4268,8 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3880 | return block.addTyOp(.bitcast, int_tag_ty, enum_tag); | 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 { | 4271 | fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3884 | const mod = sema.mod; | 4272 | const target = sema.mod.getTarget(); |
| 3885 | const target = mod.getTarget(); | | |
| 3886 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 4273 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3887 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 4274 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3888 | const src = inst_data.src(); | 4275 | const src = inst_data.src(); |
| ... | @@ -3892,7 +4279,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3892,7 +4279,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3892 | const operand = sema.resolveInst(extra.rhs); | 4279 | const operand = sema.resolveInst(extra.rhs); |
| 3893 | | 4280 | |
| 3894 | if (dest_ty.zigTypeTag() != .Enum) { | 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 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| { | 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,14 +4291,14 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3904 | } | 4291 | } |
| 3905 | if (!dest_ty.enumHasInt(int_val, target)) { | 4292 | if (!dest_ty.enumHasInt(int_val, target)) { |
| 3906 | const msg = msg: { | 4293 | const msg = msg: { |
| 3907 | const msg = try mod.errMsg( | 4294 | const msg = try sema.errMsg( |
| 3908 | &block.base, | 4295 | block, |
| 3909 | src, | 4296 | src, |
| 3910 | "enum '{}' has no tag with value {}", | 4297 | "enum '{}' has no tag with value {}", |
| 3911 | .{ dest_ty, int_val }, | 4298 | .{ dest_ty, int_val }, |
| 3912 | ); | 4299 | ); |
| 3913 | errdefer msg.destroy(sema.gpa); | 4300 | errdefer msg.destroy(sema.gpa); |
| 3914 | try mod.errNoteNonLazy( | 4301 | try sema.mod.errNoteNonLazy( |
| 3915 | dest_ty.declSrcLoc(), | 4302 | dest_ty.declSrcLoc(), |
| 3916 | msg, | 4303 | msg, |
| 3917 | "enum declared here", | 4304 | "enum declared here", |
| ... | @@ -3919,7 +4306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3919,7 +4306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3919 | ); | 4306 | ); |
| 3920 | break :msg msg; | 4307 | break :msg msg; |
| 3921 | }; | 4308 | }; |
| 3922 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 4309 | return sema.failWithOwnedErrorMsg(msg); |
| 3923 | } | 4310 | } |
| 3924 | return sema.addConstant(dest_ty, int_val); | 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,7 +4318,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3931 | /// Pointer in, pointer out. | 4318 | /// Pointer in, pointer out. |
| 3932 | fn zirOptionalPayloadPtr( | 4319 | fn zirOptionalPayloadPtr( |
| 3933 | sema: *Sema, | 4320 | sema: *Sema, |
| 3934 | block: *Scope.Block, | 4321 | block: *Block, |
| 3935 | inst: Zir.Inst.Index, | 4322 | inst: Zir.Inst.Index, |
| 3936 | safety_check: bool, | 4323 | safety_check: bool, |
| 3937 | ) CompileError!Air.Inst.Ref { | 4324 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -3946,7 +4333,7 @@ fn zirOptionalPayloadPtr( | ... | @@ -3946,7 +4333,7 @@ fn zirOptionalPayloadPtr( |
| 3946 | | 4333 | |
| 3947 | const opt_type = optional_ptr_ty.elemType(); | 4334 | const opt_type = optional_ptr_ty.elemType(); |
| 3948 | if (opt_type.zigTypeTag() != .Optional) { | 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 | const child_type = try opt_type.optionalChildAlloc(sema.arena); | 4339 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| ... | @@ -3959,7 +4346,7 @@ fn zirOptionalPayloadPtr( | ... | @@ -3959,7 +4346,7 @@ fn zirOptionalPayloadPtr( |
| 3959 | if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| { | 4346 | if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| { |
| 3960 | if (try pointer_val.pointerDeref(sema.arena)) |val| { | 4347 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 3961 | if (val.isNull()) { | 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 | // The same Value represents the pointer to the optional and the payload. | 4351 | // The same Value represents the pointer to the optional and the payload. |
| 3965 | return sema.addConstant( | 4352 | return sema.addConstant( |
| ... | @@ -3980,7 +4367,7 @@ fn zirOptionalPayloadPtr( | ... | @@ -3980,7 +4367,7 @@ fn zirOptionalPayloadPtr( |
| 3980 | /// Value in, value out. | 4367 | /// Value in, value out. |
| 3981 | fn zirOptionalPayload( | 4368 | fn zirOptionalPayload( |
| 3982 | sema: *Sema, | 4369 | sema: *Sema, |
| 3983 | block: *Scope.Block, | 4370 | block: *Block, |
| 3984 | inst: Zir.Inst.Index, | 4371 | inst: Zir.Inst.Index, |
| 3985 | safety_check: bool, | 4372 | safety_check: bool, |
| 3986 | ) CompileError!Air.Inst.Ref { | 4373 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -3993,14 +4380,14 @@ fn zirOptionalPayload( | ... | @@ -3993,14 +4380,14 @@ fn zirOptionalPayload( |
| 3993 | const operand_ty = sema.typeOf(operand); | 4380 | const operand_ty = sema.typeOf(operand); |
| 3994 | const opt_type = operand_ty; | 4381 | const opt_type = operand_ty; |
| 3995 | if (opt_type.zigTypeTag() != .Optional) { | 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 | const child_type = try opt_type.optionalChildAlloc(sema.arena); | 4386 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 4000 | | 4387 | |
| 4001 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 4388 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 4002 | if (val.isNull()) { | 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 | const sub_val = val.castTag(.opt_payload).?.data; | 4392 | const sub_val = val.castTag(.opt_payload).?.data; |
| 4006 | return sema.addConstant(child_type, sub_val); | 4393 | return sema.addConstant(child_type, sub_val); |
| ... | @@ -4017,7 +4404,7 @@ fn zirOptionalPayload( | ... | @@ -4017,7 +4404,7 @@ fn zirOptionalPayload( |
| 4017 | /// Value in, value out | 4404 | /// Value in, value out |
| 4018 | fn zirErrUnionPayload( | 4405 | fn zirErrUnionPayload( |
| 4019 | sema: *Sema, | 4406 | sema: *Sema, |
| 4020 | block: *Scope.Block, | 4407 | block: *Block, |
| 4021 | inst: Zir.Inst.Index, | 4408 | inst: Zir.Inst.Index, |
| 4022 | safety_check: bool, | 4409 | safety_check: bool, |
| 4023 | ) CompileError!Air.Inst.Ref { | 4410 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -4030,11 +4417,11 @@ fn zirErrUnionPayload( | ... | @@ -4030,11 +4417,11 @@ fn zirErrUnionPayload( |
| 4030 | const operand_src = src; | 4417 | const operand_src = src; |
| 4031 | const operand_ty = sema.typeOf(operand); | 4418 | const operand_ty = sema.typeOf(operand); |
| 4032 | if (operand_ty.zigTypeTag() != .ErrorUnion) | 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 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 4422 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 4036 | if (val.getError()) |name| { | 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 | const data = val.castTag(.eu_payload).?.data; | 4426 | const data = val.castTag(.eu_payload).?.data; |
| 4040 | const result_ty = operand_ty.errorUnionPayload(); | 4427 | const result_ty = operand_ty.errorUnionPayload(); |
| ... | @@ -4052,7 +4439,7 @@ fn zirErrUnionPayload( | ... | @@ -4052,7 +4439,7 @@ fn zirErrUnionPayload( |
| 4052 | /// Pointer in, pointer out. | 4439 | /// Pointer in, pointer out. |
| 4053 | fn zirErrUnionPayloadPtr( | 4440 | fn zirErrUnionPayloadPtr( |
| 4054 | sema: *Sema, | 4441 | sema: *Sema, |
| 4055 | block: *Scope.Block, | 4442 | block: *Block, |
| 4056 | inst: Zir.Inst.Index, | 4443 | inst: Zir.Inst.Index, |
| 4057 | safety_check: bool, | 4444 | safety_check: bool, |
| 4058 | ) CompileError!Air.Inst.Ref { | 4445 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -4066,7 +4453,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -4066,7 +4453,7 @@ fn zirErrUnionPayloadPtr( |
| 4066 | assert(operand_ty.zigTypeTag() == .Pointer); | 4453 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4067 | | 4454 | |
| 4068 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) | 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 | const payload_ty = operand_ty.elemType().errorUnionPayload(); | 4458 | const payload_ty = operand_ty.elemType().errorUnionPayload(); |
| 4072 | const operand_pointer_ty = try Type.ptr(sema.arena, .{ | 4459 | const operand_pointer_ty = try Type.ptr(sema.arena, .{ |
| ... | @@ -4078,7 +4465,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -4078,7 +4465,7 @@ fn zirErrUnionPayloadPtr( |
| 4078 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { | 4465 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { |
| 4079 | if (try pointer_val.pointerDeref(sema.arena)) |val| { | 4466 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 4080 | if (val.getError()) |name| { | 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 | return sema.addConstant( | 4470 | return sema.addConstant( |
| 4084 | operand_pointer_ty, | 4471 | operand_pointer_ty, |
| ... | @@ -4096,7 +4483,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -4096,7 +4483,7 @@ fn zirErrUnionPayloadPtr( |
| 4096 | } | 4483 | } |
| 4097 | | 4484 | |
| 4098 | /// Value in, value out | 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 | const tracy = trace(@src()); | 4487 | const tracy = trace(@src()); |
| 4101 | defer tracy.end(); | 4488 | defer tracy.end(); |
| 4102 | | 4489 | |
| ... | @@ -4105,7 +4492,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi | ... | @@ -4105,7 +4492,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 4105 | const operand = sema.resolveInst(inst_data.operand); | 4492 | const operand = sema.resolveInst(inst_data.operand); |
| 4106 | const operand_ty = sema.typeOf(operand); | 4493 | const operand_ty = sema.typeOf(operand); |
| 4107 | if (operand_ty.zigTypeTag() != .ErrorUnion) | 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 | const result_ty = operand_ty.errorUnionSet(); | 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,7 +4506,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 4119 | } | 4506 | } |
| 4120 | | 4507 | |
| 4121 | /// Pointer in, value out | 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 | const tracy = trace(@src()); | 4510 | const tracy = trace(@src()); |
| 4124 | defer tracy.end(); | 4511 | defer tracy.end(); |
| 4125 | | 4512 | |
| ... | @@ -4130,7 +4517,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co | ... | @@ -4130,7 +4517,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 4130 | assert(operand_ty.zigTypeTag() == .Pointer); | 4517 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4131 | | 4518 | |
| 4132 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) | 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 | const result_ty = operand_ty.elemType().errorUnionSet(); | 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,7 +4532,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 4145 | return block.addTyOp(.unwrap_errunion_err_ptr, result_ty, operand); | 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 | const tracy = trace(@src()); | 4536 | const tracy = trace(@src()); |
| 4150 | defer tracy.end(); | 4537 | defer tracy.end(); |
| 4151 | | 4538 | |
| ... | @@ -4154,15 +4541,15 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde | ... | @@ -4154,15 +4541,15 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 4154 | const operand = sema.resolveInst(inst_data.operand); | 4541 | const operand = sema.resolveInst(inst_data.operand); |
| 4155 | const operand_ty = sema.typeOf(operand); | 4542 | const operand_ty = sema.typeOf(operand); |
| 4156 | if (operand_ty.zigTypeTag() != .ErrorUnion) | 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 | if (operand_ty.errorUnionPayload().zigTypeTag() != .Void) { | 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 | fn zirFunc( | 4550 | fn zirFunc( |
| 4164 | sema: *Sema, | 4551 | sema: *Sema, |
| 4165 | block: *Scope.Block, | 4552 | block: *Block, |
| 4166 | inst: Zir.Inst.Index, | 4553 | inst: Zir.Inst.Index, |
| 4167 | inferred_error_set: bool, | 4554 | inferred_error_set: bool, |
| 4168 | ) CompileError!Air.Inst.Ref { | 4555 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -4205,7 +4592,7 @@ fn zirFunc( | ... | @@ -4205,7 +4592,7 @@ fn zirFunc( |
| 4205 | | 4592 | |
| 4206 | fn funcCommon( | 4593 | fn funcCommon( |
| 4207 | sema: *Sema, | 4594 | sema: *Sema, |
| 4208 | block: *Scope.Block, | 4595 | block: *Block, |
| 4209 | src_node_offset: i32, | 4596 | src_node_offset: i32, |
| 4210 | body_inst: Zir.Inst.Index, | 4597 | body_inst: Zir.Inst.Index, |
| 4211 | ret_ty_body: []const Zir.Inst.Index, | 4598 | ret_ty_body: []const Zir.Inst.Index, |
| ... | @@ -4297,7 +4684,7 @@ fn funcCommon( | ... | @@ -4297,7 +4684,7 @@ fn funcCommon( |
| 4297 | } | 4684 | } |
| 4298 | | 4685 | |
| 4299 | if (align_val.tag() != .null_value) { | 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 | is_generic = is_generic or bare_return_type.requiresComptime(); | 4690 | is_generic = is_generic or bare_return_type.requiresComptime(); |
| ... | @@ -4329,15 +4716,15 @@ fn funcCommon( | ... | @@ -4329,15 +4716,15 @@ fn funcCommon( |
| 4329 | const lib_name_src: LazySrcLoc = .{ .node_offset_lib_name = src_node_offset }; | 4716 | const lib_name_src: LazySrcLoc = .{ .node_offset_lib_name = src_node_offset }; |
| 4330 | log.debug("extern fn symbol expected in lib '{s}'", .{lib_name}); | 4717 | log.debug("extern fn symbol expected in lib '{s}'", .{lib_name}); |
| 4331 | mod.comp.stage1AddLinkLib(lib_name) catch |err| { | 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 | lib_name, @errorName(err), | 4720 | lib_name, @errorName(err), |
| 4334 | }); | 4721 | }); |
| 4335 | }; | 4722 | }; |
| 4336 | const target = mod.getTarget(); | 4723 | const target = mod.getTarget(); |
| 4337 | if (target_util.is_libc_lib_name(target, lib_name)) { | 4724 | if (target_util.is_libc_lib_name(target, lib_name)) { |
| 4338 | if (!mod.comp.bin_file.options.link_libc) { | 4725 | if (!mod.comp.bin_file.options.link_libc) { |
| 4339 | return mod.fail( | 4726 | return sema.fail( |
| 4340 | &block.base, | 4727 | block, |
| 4341 | lib_name_src, | 4728 | lib_name_src, |
| 4342 | "dependency on libc must be explicitly specified in the build command", | 4729 | "dependency on libc must be explicitly specified in the build command", |
| 4343 | .{}, | 4730 | .{}, |
| ... | @@ -4347,8 +4734,8 @@ fn funcCommon( | ... | @@ -4347,8 +4734,8 @@ fn funcCommon( |
| 4347 | } | 4734 | } |
| 4348 | if (target_util.is_libcpp_lib_name(target, lib_name)) { | 4735 | if (target_util.is_libcpp_lib_name(target, lib_name)) { |
| 4349 | if (!mod.comp.bin_file.options.link_libcpp) { | 4736 | if (!mod.comp.bin_file.options.link_libcpp) { |
| 4350 | return mod.fail( | 4737 | return sema.fail( |
| 4351 | &block.base, | 4738 | block, |
| 4352 | lib_name_src, | 4739 | lib_name_src, |
| 4353 | "dependency on libc++ must be explicitly specified in the build command", | 4740 | "dependency on libc++ must be explicitly specified in the build command", |
| 4354 | .{}, | 4741 | .{}, |
| ... | @@ -4357,8 +4744,8 @@ fn funcCommon( | ... | @@ -4357,8 +4744,8 @@ fn funcCommon( |
| 4357 | break :blk; | 4744 | break :blk; |
| 4358 | } | 4745 | } |
| 4359 | if (!target.isWasm() and !mod.comp.bin_file.options.pic) { | 4746 | if (!target.isWasm() and !mod.comp.bin_file.options.pic) { |
| 4360 | return mod.fail( | 4747 | return sema.fail( |
| 4361 | &block.base, | 4748 | block, |
| 4362 | lib_name_src, | 4749 | lib_name_src, |
| 4363 | "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.", | 4750 | "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.", |
| 4364 | .{ lib_name, lib_name }, | 4751 | .{ lib_name, lib_name }, |
| ... | @@ -4404,7 +4791,7 @@ fn funcCommon( | ... | @@ -4404,7 +4791,7 @@ fn funcCommon( |
| 4404 | | 4791 | |
| 4405 | fn zirParam( | 4792 | fn zirParam( |
| 4406 | sema: *Sema, | 4793 | sema: *Sema, |
| 4407 | block: *Scope.Block, | 4794 | block: *Block, |
| 4408 | inst: Zir.Inst.Index, | 4795 | inst: Zir.Inst.Index, |
| 4409 | is_comptime: bool, | 4796 | is_comptime: bool, |
| 4410 | ) CompileError!void { | 4797 | ) CompileError!void { |
| ... | @@ -4474,7 +4861,7 @@ fn zirParam( | ... | @@ -4474,7 +4861,7 @@ fn zirParam( |
| 4474 | | 4861 | |
| 4475 | fn zirParamAnytype( | 4862 | fn zirParamAnytype( |
| 4476 | sema: *Sema, | 4863 | sema: *Sema, |
| 4477 | block: *Scope.Block, | 4864 | block: *Block, |
| 4478 | inst: Zir.Inst.Index, | 4865 | inst: Zir.Inst.Index, |
| 4479 | is_comptime: bool, | 4866 | is_comptime: bool, |
| 4480 | ) CompileError!void { | 4867 | ) CompileError!void { |
| ... | @@ -4509,7 +4896,7 @@ fn zirParamAnytype( | ... | @@ -4509,7 +4896,7 @@ fn zirParamAnytype( |
| 4509 | try sema.inst_map.put(sema.gpa, inst, .generic_poison); | 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 | const tracy = trace(@src()); | 4900 | const tracy = trace(@src()); |
| 4514 | defer tracy.end(); | 4901 | defer tracy.end(); |
| 4515 | | 4902 | |
| ... | @@ -4517,7 +4904,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -4517,7 +4904,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Ai |
| 4517 | return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs); | 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 | const tracy = trace(@src()); | 4908 | const tracy = trace(@src()); |
| 4522 | defer tracy.end(); | 4909 | defer tracy.end(); |
| 4523 | | 4910 | |
| ... | @@ -4529,7 +4916,7 @@ fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -4529,7 +4916,7 @@ fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 4529 | | 4916 | |
| 4530 | fn analyzeAs( | 4917 | fn analyzeAs( |
| 4531 | sema: *Sema, | 4918 | sema: *Sema, |
| 4532 | block: *Scope.Block, | 4919 | block: *Block, |
| 4533 | src: LazySrcLoc, | 4920 | src: LazySrcLoc, |
| 4534 | zir_dest_type: Zir.Inst.Ref, | 4921 | zir_dest_type: Zir.Inst.Ref, |
| 4535 | zir_operand: Zir.Inst.Ref, | 4922 | zir_operand: Zir.Inst.Ref, |
| ... | @@ -4539,7 +4926,7 @@ fn analyzeAs( | ... | @@ -4539,7 +4926,7 @@ fn analyzeAs( |
| 4539 | return sema.coerce(block, dest_type, operand, src); | 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 | const tracy = trace(@src()); | 4930 | const tracy = trace(@src()); |
| 4544 | defer tracy.end(); | 4931 | defer tracy.end(); |
| 4545 | | 4932 | |
| ... | @@ -4548,7 +4935,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -4548,7 +4935,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4548 | const ptr_ty = sema.typeOf(ptr); | 4935 | const ptr_ty = sema.typeOf(ptr); |
| 4549 | if (ptr_ty.zigTypeTag() != .Pointer) { | 4936 | if (ptr_ty.zigTypeTag() != .Pointer) { |
| 4550 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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 | // TODO handle known-pointer-address | 4940 | // TODO handle known-pointer-address |
| 4554 | const src = inst_data.src(); | 4941 | const src = inst_data.src(); |
| ... | @@ -4556,7 +4943,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -4556,7 +4943,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4556 | return block.addUnOp(.ptrtoint, ptr); | 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 | const tracy = trace(@src()); | 4947 | const tracy = trace(@src()); |
| 4561 | defer tracy.end(); | 4948 | defer tracy.end(); |
| 4562 | | 4949 | |
| ... | @@ -4575,7 +4962,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -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 | const tracy = trace(@src()); | 4966 | const tracy = trace(@src()); |
| 4580 | defer tracy.end(); | 4967 | defer tracy.end(); |
| 4581 | | 4968 | |
| ... | @@ -4588,7 +4975,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -4588,7 +4975,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4588 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src); | 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 | const tracy = trace(@src()); | 4979 | const tracy = trace(@src()); |
| 4593 | defer tracy.end(); | 4980 | defer tracy.end(); |
| 4594 | | 4981 | |
| ... | @@ -4601,7 +4988,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp | ... | @@ -4601,7 +4988,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4601 | return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src); | 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 | const tracy = trace(@src()); | 4992 | const tracy = trace(@src()); |
| 4606 | defer tracy.end(); | 4993 | defer tracy.end(); |
| 4607 | | 4994 | |
| ... | @@ -4614,7 +5001,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp | ... | @@ -4614,7 +5001,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4614 | return sema.fieldVal(block, src, object, field_name, field_name_src); | 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 | const tracy = trace(@src()); | 5005 | const tracy = trace(@src()); |
| 4619 | defer tracy.end(); | 5006 | defer tracy.end(); |
| 4620 | | 5007 | |
| ... | @@ -4627,7 +5014,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp | ... | @@ -4627,7 +5014,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4627 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src); | 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 | const tracy = trace(@src()); | 5018 | const tracy = trace(@src()); |
| 4632 | defer tracy.end(); | 5019 | defer tracy.end(); |
| 4633 | | 5020 | |
| ... | @@ -4640,7 +5027,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) | ... | @@ -4640,7 +5027,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 4640 | return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src); | 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 | const tracy = trace(@src()); | 5031 | const tracy = trace(@src()); |
| 4645 | defer tracy.end(); | 5032 | defer tracy.end(); |
| 4646 | | 5033 | |
| ... | @@ -4659,14 +5046,14 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4659,14 +5046,14 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4659 | if (try sema.isComptimeKnown(block, operand_src, operand)) { | 5046 | if (try sema.isComptimeKnown(block, operand_src, operand)) { |
| 4660 | return sema.coerce(block, dest_type, operand, operand_src); | 5047 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4661 | } else if (dest_is_comptime_int) { | 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 | try sema.requireRuntimeBlock(block, operand_src); | 5052 | try sema.requireRuntimeBlock(block, operand_src); |
| 4666 | return block.addTyOp(.intcast, dest_type, operand); | 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 | const tracy = trace(@src()); | 5057 | const tracy = trace(@src()); |
| 4671 | defer tracy.end(); | 5058 | defer tracy.end(); |
| 4672 | | 5059 | |
| ... | @@ -4680,7 +5067,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4680,7 +5067,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4680 | return sema.bitcast(block, dest_type, operand, operand_src); | 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 | const tracy = trace(@src()); | 5071 | const tracy = trace(@src()); |
| 4685 | defer tracy.end(); | 5072 | defer tracy.end(); |
| 4686 | | 5073 | |
| ... | @@ -4696,8 +5083,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4696,8 +5083,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4696 | const dest_is_comptime_float = switch (dest_type.zigTypeTag()) { | 5083 | const dest_is_comptime_float = switch (dest_type.zigTypeTag()) { |
| 4697 | .ComptimeFloat => true, | 5084 | .ComptimeFloat => true, |
| 4698 | .Float => false, | 5085 | .Float => false, |
| 4699 | else => return sema.mod.fail( | 5086 | else => return sema.fail( |
| 4700 | &block.base, | 5087 | block, |
| 4701 | dest_ty_src, | 5088 | dest_ty_src, |
| 4702 | "expected float type, found '{}'", | 5089 | "expected float type, found '{}'", |
| 4703 | .{dest_type}, | 5090 | .{dest_type}, |
| ... | @@ -4707,8 +5094,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4707,8 +5094,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4707 | const operand_ty = sema.typeOf(operand); | 5094 | const operand_ty = sema.typeOf(operand); |
| 4708 | switch (operand_ty.zigTypeTag()) { | 5095 | switch (operand_ty.zigTypeTag()) { |
| 4709 | .ComptimeFloat, .Float, .ComptimeInt => {}, | 5096 | .ComptimeFloat, .Float, .ComptimeInt => {}, |
| 4710 | else => return sema.mod.fail( | 5097 | else => return sema.fail( |
| 4711 | &block.base, | 5098 | block, |
| 4712 | operand_src, | 5099 | operand_src, |
| 4713 | "expected float type, found '{}'", | 5100 | "expected float type, found '{}'", |
| 4714 | .{operand_ty}, | 5101 | .{operand_ty}, |
| ... | @@ -4719,7 +5106,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4719,7 +5106,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4719 | return sema.coerce(block, dest_type, operand, operand_src); | 5106 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4720 | } | 5107 | } |
| 4721 | if (dest_is_comptime_float) { | 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 | const target = sema.mod.getTarget(); | 5111 | const target = sema.mod.getTarget(); |
| 4725 | const src_bits = operand_ty.floatBits(target); | 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,7 +5118,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4731 | return block.addTyOp(.fptrunc, dest_type, operand); | 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 | const tracy = trace(@src()); | 5122 | const tracy = trace(@src()); |
| 4736 | defer tracy.end(); | 5123 | defer tracy.end(); |
| 4737 | | 5124 | |
| ... | @@ -4741,7 +5128,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4741,7 +5128,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4741 | return sema.elemVal(block, sema.src, array, elem_index, sema.src); | 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 | const tracy = trace(@src()); | 5132 | const tracy = trace(@src()); |
| 4746 | defer tracy.end(); | 5133 | defer tracy.end(); |
| 4747 | | 5134 | |
| ... | @@ -4754,7 +5141,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -4754,7 +5141,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 4754 | return sema.elemVal(block, src, array, elem_index, elem_index_src); | 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 | const tracy = trace(@src()); | 5145 | const tracy = trace(@src()); |
| 4759 | defer tracy.end(); | 5146 | defer tracy.end(); |
| 4760 | | 5147 | |
| ... | @@ -4764,7 +5151,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4764,7 +5151,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4764 | return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src); | 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 | const tracy = trace(@src()); | 5155 | const tracy = trace(@src()); |
| 4769 | defer tracy.end(); | 5156 | defer tracy.end(); |
| 4770 | | 5157 | |
| ... | @@ -4777,7 +5164,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -4777,7 +5164,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 4777 | return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src); | 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 | const tracy = trace(@src()); | 5168 | const tracy = trace(@src()); |
| 4782 | defer tracy.end(); | 5169 | defer tracy.end(); |
| 4783 | | 5170 | |
| ... | @@ -4790,7 +5177,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile | ... | @@ -4790,7 +5177,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 4790 | return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded); | 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 | const tracy = trace(@src()); | 5181 | const tracy = trace(@src()); |
| 4795 | defer tracy.end(); | 5182 | defer tracy.end(); |
| 4796 | | 5183 | |
| ... | @@ -4804,7 +5191,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -4804,7 +5191,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4804 | return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded); | 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 | const tracy = trace(@src()); | 5195 | const tracy = trace(@src()); |
| 4809 | defer tracy.end(); | 5196 | defer tracy.end(); |
| 4810 | | 5197 | |
| ... | @@ -4822,7 +5209,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp | ... | @@ -4822,7 +5209,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 4822 | | 5209 | |
| 4823 | fn zirSwitchCapture( | 5210 | fn zirSwitchCapture( |
| 4824 | sema: *Sema, | 5211 | sema: *Sema, |
| 4825 | block: *Scope.Block, | 5212 | block: *Block, |
| 4826 | inst: Zir.Inst.Index, | 5213 | inst: Zir.Inst.Index, |
| 4827 | is_multi: bool, | 5214 | is_multi: bool, |
| 4828 | is_ref: bool, | 5215 | is_ref: bool, |
| ... | @@ -4837,12 +5224,12 @@ fn zirSwitchCapture( | ... | @@ -4837,12 +5224,12 @@ fn zirSwitchCapture( |
| 4837 | | 5224 | |
| 4838 | _ = is_ref; | 5225 | _ = is_ref; |
| 4839 | _ = is_multi; | 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 | fn zirSwitchCaptureElse( | 5230 | fn zirSwitchCaptureElse( |
| 4844 | sema: *Sema, | 5231 | sema: *Sema, |
| 4845 | block: *Scope.Block, | 5232 | block: *Block, |
| 4846 | inst: Zir.Inst.Index, | 5233 | inst: Zir.Inst.Index, |
| 4847 | is_ref: bool, | 5234 | is_ref: bool, |
| 4848 | ) CompileError!Air.Inst.Ref { | 5235 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -4855,12 +5242,12 @@ fn zirSwitchCaptureElse( | ... | @@ -4855,12 +5242,12 @@ fn zirSwitchCaptureElse( |
| 4855 | const src = switch_info.src(); | 5242 | const src = switch_info.src(); |
| 4856 | | 5243 | |
| 4857 | _ = is_ref; | 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 | fn zirSwitchBlock( | 5248 | fn zirSwitchBlock( |
| 4862 | sema: *Sema, | 5249 | sema: *Sema, |
| 4863 | block: *Scope.Block, | 5250 | block: *Block, |
| 4864 | inst: Zir.Inst.Index, | 5251 | inst: Zir.Inst.Index, |
| 4865 | is_ref: bool, | 5252 | is_ref: bool, |
| 4866 | special_prong: Zir.SpecialProng, | 5253 | special_prong: Zir.SpecialProng, |
| ... | @@ -4893,7 +5280,7 @@ fn zirSwitchBlock( | ... | @@ -4893,7 +5280,7 @@ fn zirSwitchBlock( |
| 4893 | | 5280 | |
| 4894 | fn zirSwitchBlockMulti( | 5281 | fn zirSwitchBlockMulti( |
| 4895 | sema: *Sema, | 5282 | sema: *Sema, |
| 4896 | block: *Scope.Block, | 5283 | block: *Block, |
| 4897 | inst: Zir.Inst.Index, | 5284 | inst: Zir.Inst.Index, |
| 4898 | is_ref: bool, | 5285 | is_ref: bool, |
| 4899 | special_prong: Zir.SpecialProng, | 5286 | special_prong: Zir.SpecialProng, |
| ... | @@ -4926,7 +5313,7 @@ fn zirSwitchBlockMulti( | ... | @@ -4926,7 +5313,7 @@ fn zirSwitchBlockMulti( |
| 4926 | | 5313 | |
| 4927 | fn analyzeSwitch( | 5314 | fn analyzeSwitch( |
| 4928 | sema: *Sema, | 5315 | sema: *Sema, |
| 4929 | block: *Scope.Block, | 5316 | block: *Block, |
| 4930 | operand: Air.Inst.Ref, | 5317 | operand: Air.Inst.Ref, |
| 4931 | extra_end: usize, | 5318 | extra_end: usize, |
| 4932 | special_prong: Zir.SpecialProng, | 5319 | special_prong: Zir.SpecialProng, |
| ... | @@ -4936,7 +5323,6 @@ fn analyzeSwitch( | ... | @@ -4936,7 +5323,6 @@ fn analyzeSwitch( |
| 4936 | src_node_offset: i32, | 5323 | src_node_offset: i32, |
| 4937 | ) CompileError!Air.Inst.Ref { | 5324 | ) CompileError!Air.Inst.Ref { |
| 4938 | const gpa = sema.gpa; | 5325 | const gpa = sema.gpa; |
| 4939 | const mod = sema.mod; | | |
| 4940 | | 5326 | |
| 4941 | const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) { | 5327 | const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) { |
| 4942 | .none => .{ .body = &.{}, .end = extra_end }, | 5328 | .none => .{ .body = &.{}, .end = extra_end }, |
| ... | @@ -4958,15 +5344,15 @@ fn analyzeSwitch( | ... | @@ -4958,15 +5344,15 @@ fn analyzeSwitch( |
| 4958 | // Validate usage of '_' prongs. | 5344 | // Validate usage of '_' prongs. |
| 4959 | if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) { | 5345 | if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) { |
| 4960 | const msg = msg: { | 5346 | const msg = msg: { |
| 4961 | const msg = try mod.errMsg( | 5347 | const msg = try sema.errMsg( |
| 4962 | &block.base, | 5348 | block, |
| 4963 | src, | 5349 | src, |
| 4964 | "'_' prong only allowed when switching on non-exhaustive enums", | 5350 | "'_' prong only allowed when switching on non-exhaustive enums", |
| 4965 | .{}, | 5351 | .{}, |
| 4966 | ); | 5352 | ); |
| 4967 | errdefer msg.destroy(gpa); | 5353 | errdefer msg.destroy(gpa); |
| 4968 | try mod.errNote( | 5354 | try sema.errNote( |
| 4969 | &block.base, | 5355 | block, |
| 4970 | special_prong_src, | 5356 | special_prong_src, |
| 4971 | msg, | 5357 | msg, |
| 4972 | "'_' prong here", | 5358 | "'_' prong here", |
| ... | @@ -4974,7 +5360,7 @@ fn analyzeSwitch( | ... | @@ -4974,7 +5360,7 @@ fn analyzeSwitch( |
| 4974 | ); | 5360 | ); |
| 4975 | break :msg msg; | 5361 | break :msg msg; |
| 4976 | }; | 5362 | }; |
| 4977 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 5363 | return sema.failWithOwnedErrorMsg(msg); |
| 4978 | } | 5364 | } |
| 4979 | | 5365 | |
| 4980 | // Validate for duplicate items, missing else prong, and invalid range. | 5366 | // Validate for duplicate items, missing else prong, and invalid range. |
| ... | @@ -5037,8 +5423,8 @@ fn analyzeSwitch( | ... | @@ -5037,8 +5423,8 @@ fn analyzeSwitch( |
| 5037 | .none => { | 5423 | .none => { |
| 5038 | if (!all_tags_handled) { | 5424 | if (!all_tags_handled) { |
| 5039 | const msg = msg: { | 5425 | const msg = msg: { |
| 5040 | const msg = try mod.errMsg( | 5426 | const msg = try sema.errMsg( |
| 5041 | &block.base, | 5427 | block, |
| 5042 | src, | 5428 | src, |
| 5043 | "switch must handle all possibilities", | 5429 | "switch must handle all possibilities", |
| 5044 | .{}, | 5430 | .{}, |
| ... | @@ -5050,15 +5436,15 @@ fn analyzeSwitch( | ... | @@ -5050,15 +5436,15 @@ fn analyzeSwitch( |
| 5050 | const field_name = operand_ty.enumFieldName(i); | 5436 | const field_name = operand_ty.enumFieldName(i); |
| 5051 | | 5437 | |
| 5052 | // TODO have this point to the tag decl instead of here | 5438 | // TODO have this point to the tag decl instead of here |
| 5053 | try mod.errNote( | 5439 | try sema.errNote( |
| 5054 | &block.base, | 5440 | block, |
| 5055 | src, | 5441 | src, |
| 5056 | msg, | 5442 | msg, |
| 5057 | "unhandled enumeration value: '{s}'", | 5443 | "unhandled enumeration value: '{s}'", |
| 5058 | .{field_name}, | 5444 | .{field_name}, |
| 5059 | ); | 5445 | ); |
| 5060 | } | 5446 | } |
| 5061 | try mod.errNoteNonLazy( | 5447 | try sema.mod.errNoteNonLazy( |
| 5062 | operand_ty.declSrcLoc(), | 5448 | operand_ty.declSrcLoc(), |
| 5063 | msg, | 5449 | msg, |
| 5064 | "enum '{}' declared here", | 5450 | "enum '{}' declared here", |
| ... | @@ -5066,20 +5452,20 @@ fn analyzeSwitch( | ... | @@ -5066,20 +5452,20 @@ fn analyzeSwitch( |
| 5066 | ); | 5452 | ); |
| 5067 | break :msg msg; | 5453 | break :msg msg; |
| 5068 | }; | 5454 | }; |
| 5069 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 5455 | return sema.failWithOwnedErrorMsg(msg); |
| 5070 | } | 5456 | } |
| 5071 | }, | 5457 | }, |
| 5072 | .under => { | 5458 | .under => { |
| 5073 | if (all_tags_handled) return mod.fail( | 5459 | if (all_tags_handled) return sema.fail( |
| 5074 | &block.base, | 5460 | block, |
| 5075 | special_prong_src, | 5461 | special_prong_src, |
| 5076 | "unreachable '_' prong; all cases already handled", | 5462 | "unreachable '_' prong; all cases already handled", |
| 5077 | .{}, | 5463 | .{}, |
| 5078 | ); | 5464 | ); |
| 5079 | }, | 5465 | }, |
| 5080 | .@"else" => { | 5466 | .@"else" => { |
| 5081 | if (all_tags_handled) return mod.fail( | 5467 | if (all_tags_handled) return sema.fail( |
| 5082 | &block.base, | 5468 | block, |
| 5083 | special_prong_src, | 5469 | special_prong_src, |
| 5084 | "unreachable else prong; all cases already handled", | 5470 | "unreachable else prong; all cases already handled", |
| 5085 | .{}, | 5471 | .{}, |
| ... | @@ -5088,8 +5474,8 @@ fn analyzeSwitch( | ... | @@ -5088,8 +5474,8 @@ fn analyzeSwitch( |
| 5088 | } | 5474 | } |
| 5089 | }, | 5475 | }, |
| 5090 | | 5476 | |
| 5091 | .ErrorSet => return mod.fail(&block.base, src, "TODO validate switch .ErrorSet", .{}), | 5477 | .ErrorSet => return sema.fail(block, src, "TODO validate switch .ErrorSet", .{}), |
| 5092 | .Union => return mod.fail(&block.base, src, "TODO validate switch .Union", .{}), | 5478 | .Union => return sema.fail(block, src, "TODO validate switch .Union", .{}), |
| 5093 | .Int, .ComptimeInt => { | 5479 | .Int, .ComptimeInt => { |
| 5094 | var range_set = RangeSet.init(gpa); | 5480 | var range_set = RangeSet.init(gpa); |
| 5095 | defer range_set.deinit(); | 5481 | defer range_set.deinit(); |
| ... | @@ -5164,12 +5550,13 @@ fn analyzeSwitch( | ... | @@ -5164,12 +5550,13 @@ fn analyzeSwitch( |
| 5164 | var arena = std.heap.ArenaAllocator.init(gpa); | 5550 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 5165 | defer arena.deinit(); | 5551 | defer arena.deinit(); |
| 5166 | | 5552 | |
| 5167 | const min_int = try operand_ty.minInt(&arena.allocator, mod.getTarget()); | 5553 | const target = sema.mod.getTarget(); |
| 5168 | const max_int = try operand_ty.maxInt(&arena.allocator, 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 | if (try range_set.spans(min_int, max_int, operand_ty)) { | 5556 | if (try range_set.spans(min_int, max_int, operand_ty)) { |
| 5170 | if (special_prong == .@"else") { | 5557 | if (special_prong == .@"else") { |
| 5171 | return mod.fail( | 5558 | return sema.fail( |
| 5172 | &block.base, | 5559 | block, |
| 5173 | special_prong_src, | 5560 | special_prong_src, |
| 5174 | "unreachable else prong; all cases already handled", | 5561 | "unreachable else prong; all cases already handled", |
| 5175 | .{}, | 5562 | .{}, |
| ... | @@ -5179,8 +5566,8 @@ fn analyzeSwitch( | ... | @@ -5179,8 +5566,8 @@ fn analyzeSwitch( |
| 5179 | } | 5566 | } |
| 5180 | } | 5567 | } |
| 5181 | if (special_prong != .@"else") { | 5568 | if (special_prong != .@"else") { |
| 5182 | return mod.fail( | 5569 | return sema.fail( |
| 5183 | &block.base, | 5570 | block, |
| 5184 | src, | 5571 | src, |
| 5185 | "switch must handle all possibilities", | 5572 | "switch must handle all possibilities", |
| 5186 | .{}, | 5573 | .{}, |
| ... | @@ -5241,8 +5628,8 @@ fn analyzeSwitch( | ... | @@ -5241,8 +5628,8 @@ fn analyzeSwitch( |
| 5241 | switch (special_prong) { | 5628 | switch (special_prong) { |
| 5242 | .@"else" => { | 5629 | .@"else" => { |
| 5243 | if (true_count + false_count == 2) { | 5630 | if (true_count + false_count == 2) { |
| 5244 | return mod.fail( | 5631 | return sema.fail( |
| 5245 | &block.base, | 5632 | block, |
| 5246 | src, | 5633 | src, |
| 5247 | "unreachable else prong; all cases already handled", | 5634 | "unreachable else prong; all cases already handled", |
| 5248 | .{}, | 5635 | .{}, |
| ... | @@ -5251,8 +5638,8 @@ fn analyzeSwitch( | ... | @@ -5251,8 +5638,8 @@ fn analyzeSwitch( |
| 5251 | }, | 5638 | }, |
| 5252 | .under, .none => { | 5639 | .under, .none => { |
| 5253 | if (true_count + false_count < 2) { | 5640 | if (true_count + false_count < 2) { |
| 5254 | return mod.fail( | 5641 | return sema.fail( |
| 5255 | &block.base, | 5642 | block, |
| 5256 | src, | 5643 | src, |
| 5257 | "switch must handle all possibilities", | 5644 | "switch must handle all possibilities", |
| 5258 | .{}, | 5645 | .{}, |
| ... | @@ -5263,8 +5650,8 @@ fn analyzeSwitch( | ... | @@ -5263,8 +5650,8 @@ fn analyzeSwitch( |
| 5263 | }, | 5650 | }, |
| 5264 | .EnumLiteral, .Void, .Fn, .Pointer, .Type => { | 5651 | .EnumLiteral, .Void, .Fn, .Pointer, .Type => { |
| 5265 | if (special_prong != .@"else") { | 5652 | if (special_prong != .@"else") { |
| 5266 | return mod.fail( | 5653 | return sema.fail( |
| 5267 | &block.base, | 5654 | block, |
| 5268 | src, | 5655 | src, |
| 5269 | "else prong required when switching on type '{}'", | 5656 | "else prong required when switching on type '{}'", |
| 5270 | .{operand_ty}, | 5657 | .{operand_ty}, |
| ... | @@ -5334,7 +5721,7 @@ fn analyzeSwitch( | ... | @@ -5334,7 +5721,7 @@ fn analyzeSwitch( |
| 5334 | .AnyFrame, | 5721 | .AnyFrame, |
| 5335 | .ComptimeFloat, | 5722 | .ComptimeFloat, |
| 5336 | .Float, | 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 | operand_ty, | 5725 | operand_ty, |
| 5339 | }), | 5726 | }), |
| 5340 | } | 5727 | } |
| ... | @@ -5344,7 +5731,7 @@ fn analyzeSwitch( | ... | @@ -5344,7 +5731,7 @@ fn analyzeSwitch( |
| 5344 | .tag = .block, | 5731 | .tag = .block, |
| 5345 | .data = undefined, | 5732 | .data = undefined, |
| 5346 | }); | 5733 | }); |
| 5347 | var label: Scope.Block.Label = .{ | 5734 | var label: Block.Label = .{ |
| 5348 | .zir_block = switch_inst, | 5735 | .zir_block = switch_inst, |
| 5349 | .merges = .{ | 5736 | .merges = .{ |
| 5350 | .results = .{}, | 5737 | .results = .{}, |
| ... | @@ -5353,10 +5740,11 @@ fn analyzeSwitch( | ... | @@ -5353,10 +5740,11 @@ fn analyzeSwitch( |
| 5353 | }, | 5740 | }, |
| 5354 | }; | 5741 | }; |
| 5355 | | 5742 | |
| 5356 | var child_block: Scope.Block = .{ | 5743 | var child_block: Block = .{ |
| 5357 | .parent = block, | 5744 | .parent = block, |
| 5358 | .sema = sema, | 5745 | .sema = sema, |
| 5359 | .src_decl = block.src_decl, | 5746 | .src_decl = block.src_decl, |
| | 5747 | .namespace = block.namespace, |
| 5360 | .wip_capture_scope = block.wip_capture_scope, | 5748 | .wip_capture_scope = block.wip_capture_scope, |
| 5361 | .instructions = .{}, | 5749 | .instructions = .{}, |
| 5362 | .label = &label, | 5750 | .label = &label, |
| ... | @@ -5663,7 +6051,7 @@ fn analyzeSwitch( | ... | @@ -5663,7 +6051,7 @@ fn analyzeSwitch( |
| 5663 | | 6051 | |
| 5664 | fn resolveSwitchItemVal( | 6052 | fn resolveSwitchItemVal( |
| 5665 | sema: *Sema, | 6053 | sema: *Sema, |
| 5666 | block: *Scope.Block, | 6054 | block: *Block, |
| 5667 | item_ref: Zir.Inst.Ref, | 6055 | item_ref: Zir.Inst.Ref, |
| 5668 | switch_node_offset: i32, | 6056 | switch_node_offset: i32, |
| 5669 | switch_prong_src: Module.SwitchProngSrc, | 6057 | switch_prong_src: Module.SwitchProngSrc, |
| ... | @@ -5690,7 +6078,7 @@ fn resolveSwitchItemVal( | ... | @@ -5690,7 +6078,7 @@ fn resolveSwitchItemVal( |
| 5690 | | 6078 | |
| 5691 | fn validateSwitchRange( | 6079 | fn validateSwitchRange( |
| 5692 | sema: *Sema, | 6080 | sema: *Sema, |
| 5693 | block: *Scope.Block, | 6081 | block: *Block, |
| 5694 | range_set: *RangeSet, | 6082 | range_set: *RangeSet, |
| 5695 | first_ref: Zir.Inst.Ref, | 6083 | first_ref: Zir.Inst.Ref, |
| 5696 | last_ref: Zir.Inst.Ref, | 6084 | last_ref: Zir.Inst.Ref, |
| ... | @@ -5706,7 +6094,7 @@ fn validateSwitchRange( | ... | @@ -5706,7 +6094,7 @@ fn validateSwitchRange( |
| 5706 | | 6094 | |
| 5707 | fn validateSwitchItem( | 6095 | fn validateSwitchItem( |
| 5708 | sema: *Sema, | 6096 | sema: *Sema, |
| 5709 | block: *Scope.Block, | 6097 | block: *Block, |
| 5710 | range_set: *RangeSet, | 6098 | range_set: *RangeSet, |
| 5711 | item_ref: Zir.Inst.Ref, | 6099 | item_ref: Zir.Inst.Ref, |
| 5712 | operand_ty: Type, | 6100 | operand_ty: Type, |
| ... | @@ -5720,25 +6108,24 @@ fn validateSwitchItem( | ... | @@ -5720,25 +6108,24 @@ fn validateSwitchItem( |
| 5720 | | 6108 | |
| 5721 | fn validateSwitchItemEnum( | 6109 | fn validateSwitchItemEnum( |
| 5722 | sema: *Sema, | 6110 | sema: *Sema, |
| 5723 | block: *Scope.Block, | 6111 | block: *Block, |
| 5724 | seen_fields: []?Module.SwitchProngSrc, | 6112 | seen_fields: []?Module.SwitchProngSrc, |
| 5725 | item_ref: Zir.Inst.Ref, | 6113 | item_ref: Zir.Inst.Ref, |
| 5726 | src_node_offset: i32, | 6114 | src_node_offset: i32, |
| 5727 | switch_prong_src: Module.SwitchProngSrc, | 6115 | switch_prong_src: Module.SwitchProngSrc, |
| 5728 | ) CompileError!void { | 6116 | ) CompileError!void { |
| 5729 | const mod = sema.mod; | | |
| 5730 | const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); | 6117 | const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); |
| 5731 | const field_index = item_tv.ty.enumTagFieldIndex(item_tv.val) orelse { | 6118 | const field_index = item_tv.ty.enumTagFieldIndex(item_tv.val) orelse { |
| 5732 | const msg = msg: { | 6119 | const msg = msg: { |
| 5733 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); | 6120 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); |
| 5734 | const msg = try mod.errMsg( | 6121 | const msg = try sema.errMsg( |
| 5735 | &block.base, | 6122 | block, |
| 5736 | src, | 6123 | src, |
| 5737 | "enum '{}' has no tag with value '{}'", | 6124 | "enum '{}' has no tag with value '{}'", |
| 5738 | .{ item_tv.ty, item_tv.val }, | 6125 | .{ item_tv.ty, item_tv.val }, |
| 5739 | ); | 6126 | ); |
| 5740 | errdefer msg.destroy(sema.gpa); | 6127 | errdefer msg.destroy(sema.gpa); |
| 5741 | try mod.errNoteNonLazy( | 6128 | try sema.mod.errNoteNonLazy( |
| 5742 | item_tv.ty.declSrcLoc(), | 6129 | item_tv.ty.declSrcLoc(), |
| 5743 | msg, | 6130 | msg, |
| 5744 | "enum declared here", | 6131 | "enum declared here", |
| ... | @@ -5746,7 +6133,7 @@ fn validateSwitchItemEnum( | ... | @@ -5746,7 +6133,7 @@ fn validateSwitchItemEnum( |
| 5746 | ); | 6133 | ); |
| 5747 | break :msg msg; | 6134 | break :msg msg; |
| 5748 | }; | 6135 | }; |
| 5749 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 6136 | return sema.failWithOwnedErrorMsg(msg); |
| 5750 | }; | 6137 | }; |
| 5751 | const maybe_prev_src = seen_fields[field_index]; | 6138 | const maybe_prev_src = seen_fields[field_index]; |
| 5752 | seen_fields[field_index] = switch_prong_src; | 6139 | seen_fields[field_index] = switch_prong_src; |
| ... | @@ -5755,26 +6142,25 @@ fn validateSwitchItemEnum( | ... | @@ -5755,26 +6142,25 @@ fn validateSwitchItemEnum( |
| 5755 | | 6142 | |
| 5756 | fn validateSwitchDupe( | 6143 | fn validateSwitchDupe( |
| 5757 | sema: *Sema, | 6144 | sema: *Sema, |
| 5758 | block: *Scope.Block, | 6145 | block: *Block, |
| 5759 | maybe_prev_src: ?Module.SwitchProngSrc, | 6146 | maybe_prev_src: ?Module.SwitchProngSrc, |
| 5760 | switch_prong_src: Module.SwitchProngSrc, | 6147 | switch_prong_src: Module.SwitchProngSrc, |
| 5761 | src_node_offset: i32, | 6148 | src_node_offset: i32, |
| 5762 | ) CompileError!void { | 6149 | ) CompileError!void { |
| 5763 | const prev_prong_src = maybe_prev_src orelse return; | 6150 | const prev_prong_src = maybe_prev_src orelse return; |
| 5764 | const mod = sema.mod; | | |
| 5765 | const gpa = sema.gpa; | 6151 | const gpa = sema.gpa; |
| 5766 | const src = switch_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); | 6152 | const src = switch_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5767 | const prev_src = prev_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); | 6153 | const prev_src = prev_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5768 | const msg = msg: { | 6154 | const msg = msg: { |
| 5769 | const msg = try mod.errMsg( | 6155 | const msg = try sema.errMsg( |
| 5770 | &block.base, | 6156 | block, |
| 5771 | src, | 6157 | src, |
| 5772 | "duplicate switch value", | 6158 | "duplicate switch value", |
| 5773 | .{}, | 6159 | .{}, |
| 5774 | ); | 6160 | ); |
| 5775 | errdefer msg.destroy(sema.gpa); | 6161 | errdefer msg.destroy(sema.gpa); |
| 5776 | try mod.errNote( | 6162 | try sema.errNote( |
| 5777 | &block.base, | 6163 | block, |
| 5778 | prev_src, | 6164 | prev_src, |
| 5779 | msg, | 6165 | msg, |
| 5780 | "previous value here", | 6166 | "previous value here", |
| ... | @@ -5782,12 +6168,12 @@ fn validateSwitchDupe( | ... | @@ -5782,12 +6168,12 @@ fn validateSwitchDupe( |
| 5782 | ); | 6168 | ); |
| 5783 | break :msg msg; | 6169 | break :msg msg; |
| 5784 | }; | 6170 | }; |
| 5785 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 6171 | return sema.failWithOwnedErrorMsg(msg); |
| 5786 | } | 6172 | } |
| 5787 | | 6173 | |
| 5788 | fn validateSwitchItemBool( | 6174 | fn validateSwitchItemBool( |
| 5789 | sema: *Sema, | 6175 | sema: *Sema, |
| 5790 | block: *Scope.Block, | 6176 | block: *Block, |
| 5791 | true_count: *u8, | 6177 | true_count: *u8, |
| 5792 | false_count: *u8, | 6178 | false_count: *u8, |
| 5793 | item_ref: Zir.Inst.Ref, | 6179 | item_ref: Zir.Inst.Ref, |
| ... | @@ -5802,7 +6188,7 @@ fn validateSwitchItemBool( | ... | @@ -5802,7 +6188,7 @@ fn validateSwitchItemBool( |
| 5802 | } | 6188 | } |
| 5803 | if (true_count.* + false_count.* > 2) { | 6189 | if (true_count.* + false_count.* > 2) { |
| 5804 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); | 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,7 +6196,7 @@ const ValueSrcMap = std.HashMap(Value, Module.SwitchProngSrc, Value.HashContext, |
| 5810 | | 6196 | |
| 5811 | fn validateSwitchItemSparse( | 6197 | fn validateSwitchItemSparse( |
| 5812 | sema: *Sema, | 6198 | sema: *Sema, |
| 5813 | block: *Scope.Block, | 6199 | block: *Block, |
| 5814 | seen_values: *ValueSrcMap, | 6200 | seen_values: *ValueSrcMap, |
| 5815 | item_ref: Zir.Inst.Ref, | 6201 | item_ref: Zir.Inst.Ref, |
| 5816 | src_node_offset: i32, | 6202 | src_node_offset: i32, |
| ... | @@ -5823,7 +6209,7 @@ fn validateSwitchItemSparse( | ... | @@ -5823,7 +6209,7 @@ fn validateSwitchItemSparse( |
| 5823 | | 6209 | |
| 5824 | fn validateSwitchNoRange( | 6210 | fn validateSwitchNoRange( |
| 5825 | sema: *Sema, | 6211 | sema: *Sema, |
| 5826 | block: *Scope.Block, | 6212 | block: *Block, |
| 5827 | ranges_len: u32, | 6213 | ranges_len: u32, |
| 5828 | operand_ty: Type, | 6214 | operand_ty: Type, |
| 5829 | src_node_offset: i32, | 6215 | src_node_offset: i32, |
| ... | @@ -5835,15 +6221,15 @@ fn validateSwitchNoRange( | ... | @@ -5835,15 +6221,15 @@ fn validateSwitchNoRange( |
| 5835 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; | 6221 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; |
| 5836 | | 6222 | |
| 5837 | const msg = msg: { | 6223 | const msg = msg: { |
| 5838 | const msg = try sema.mod.errMsg( | 6224 | const msg = try sema.errMsg( |
| 5839 | &block.base, | 6225 | block, |
| 5840 | operand_src, | 6226 | operand_src, |
| 5841 | "ranges not allowed when switching on type '{}'", | 6227 | "ranges not allowed when switching on type '{}'", |
| 5842 | .{operand_ty}, | 6228 | .{operand_ty}, |
| 5843 | ); | 6229 | ); |
| 5844 | errdefer msg.destroy(sema.gpa); | 6230 | errdefer msg.destroy(sema.gpa); |
| 5845 | try sema.mod.errNote( | 6231 | try sema.errNote( |
| 5846 | &block.base, | 6232 | block, |
| 5847 | range_src, | 6233 | range_src, |
| 5848 | msg, | 6234 | msg, |
| 5849 | "range here", | 6235 | "range here", |
| ... | @@ -5851,19 +6237,19 @@ fn validateSwitchNoRange( | ... | @@ -5851,19 +6237,19 @@ fn validateSwitchNoRange( |
| 5851 | ); | 6237 | ); |
| 5852 | break :msg msg; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 6244 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5859 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 6245 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5860 | _ = extra; | 6246 | _ = extra; |
| 5861 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 6253 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5868 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 6254 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5869 | const src = inst_data.src(); | 6255 | const src = inst_data.src(); |
| ... | @@ -5871,23 +6257,22 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -5871,23 +6257,22 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 5871 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 6257 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 5872 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 6258 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 5873 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs); | 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( | 6261 | const namespace = container_type.getNamespace() orelse return sema.fail( |
| 5877 | &block.base, | 6262 | block, |
| 5878 | lhs_src, | 6263 | lhs_src, |
| 5879 | "expected struct, enum, union, or opaque, found '{}'", | 6264 | "expected struct, enum, union, or opaque, found '{}'", |
| 5880 | .{container_type}, | 6265 | .{container_type}, |
| 5881 | ); | 6266 | ); |
| 5882 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { | 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 | return Air.Inst.Ref.bool_true; | 6269 | return Air.Inst.Ref.bool_true; |
| 5885 | } | 6270 | } |
| 5886 | } | 6271 | } |
| 5887 | return Air.Inst.Ref.bool_false; | 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 | const tracy = trace(@src()); | 6276 | const tracy = trace(@src()); |
| 5892 | defer tracy.end(); | 6277 | defer tracy.end(); |
| 5893 | | 6278 | |
| ... | @@ -5898,29 +6283,29 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5898,29 +6283,29 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 5898 | | 6283 | |
| 5899 | const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) { | 6284 | const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) { |
| 5900 | error.ImportOutsidePkgPath => { | 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 | else => { | 6288 | else => { |
| 5904 | // TODO: these errors are file system errors; make sure an update() will | 6289 | // TODO: these errors are file system errors; make sure an update() will |
| 5905 | // retry this and not cache the file system error, which may be transient. | 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 | try mod.semaFile(result.file); | 6294 | try mod.semaFile(result.file); |
| 5910 | const file_root_decl = result.file.root_decl.?; | 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 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); | 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 | _ = block; | 6301 | _ = block; |
| 5917 | _ = inst; | 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 | fn zirShl( | 6306 | fn zirShl( |
| 5922 | sema: *Sema, | 6307 | sema: *Sema, |
| 5923 | block: *Scope.Block, | 6308 | block: *Block, |
| 5924 | inst: Zir.Inst.Index, | 6309 | inst: Zir.Inst.Index, |
| 5925 | air_tag: Air.Inst.Tag, | 6310 | air_tag: Air.Inst.Tag, |
| 5926 | ) CompileError!Air.Inst.Ref { | 6311 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -5952,8 +6337,8 @@ fn zirShl( | ... | @@ -5952,8 +6337,8 @@ fn zirShl( |
| 5952 | } | 6337 | } |
| 5953 | const val = try lhs_val.shl(rhs_val, sema.arena); | 6338 | const val = try lhs_val.shl(rhs_val, sema.arena); |
| 5954 | switch (air_tag) { | 6339 | switch (air_tag) { |
| 5955 | .shl_exact => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_exact", .{}), | 6340 | .shl_exact => return sema.fail(block, 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", .{}), | 6341 | .shl_sat => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_sat", .{}), |
| 5957 | .shl => {}, | 6342 | .shl => {}, |
| 5958 | else => unreachable, | 6343 | else => unreachable, |
| 5959 | } | 6344 | } |
| ... | @@ -5971,7 +6356,7 @@ fn zirShl( | ... | @@ -5971,7 +6356,7 @@ fn zirShl( |
| 5971 | return block.addBinOp(air_tag, lhs, rhs); | 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 | const tracy = trace(@src()); | 6360 | const tracy = trace(@src()); |
| 5976 | defer tracy.end(); | 6361 | defer tracy.end(); |
| 5977 | | 6362 | |
| ... | @@ -6004,7 +6389,7 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -6004,7 +6389,7 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 6004 | | 6389 | |
| 6005 | fn zirBitwise( | 6390 | fn zirBitwise( |
| 6006 | sema: *Sema, | 6391 | sema: *Sema, |
| 6007 | block: *Scope.Block, | 6392 | block: *Block, |
| 6008 | inst: Zir.Inst.Index, | 6393 | inst: Zir.Inst.Index, |
| 6009 | air_tag: Air.Inst.Tag, | 6394 | air_tag: Air.Inst.Tag, |
| 6010 | ) CompileError!Air.Inst.Ref { | 6395 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -6035,14 +6420,14 @@ fn zirBitwise( | ... | @@ -6035,14 +6420,14 @@ fn zirBitwise( |
| 6035 | | 6420 | |
| 6036 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { | 6421 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { |
| 6037 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { | 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 | lhs_ty.arrayLen(), | 6424 | lhs_ty.arrayLen(), |
| 6040 | rhs_ty.arrayLen(), | 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 | } else if (lhs_ty.zigTypeTag() == .Vector or rhs_ty.zigTypeTag() == .Vector) { | 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 | lhs_ty, | 6431 | lhs_ty, |
| 6047 | rhs_ty, | 6432 | rhs_ty, |
| 6048 | }); | 6433 | }); |
| ... | @@ -6051,7 +6436,7 @@ fn zirBitwise( | ... | @@ -6051,7 +6436,7 @@ fn zirBitwise( |
| 6051 | const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt; | 6436 | const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt; |
| 6052 | | 6437 | |
| 6053 | if (!is_int) { | 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 | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { | 6442 | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { |
| ... | @@ -6070,15 +6455,15 @@ fn zirBitwise( | ... | @@ -6070,15 +6455,15 @@ fn zirBitwise( |
| 6070 | return block.addBinOp(air_tag, casted_lhs, casted_rhs); | 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 | const tracy = trace(@src()); | 6459 | const tracy = trace(@src()); |
| 6075 | defer tracy.end(); | 6460 | defer tracy.end(); |
| 6076 | | 6461 | |
| 6077 | _ = inst; | 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 | const tracy = trace(@src()); | 6467 | const tracy = trace(@src()); |
| 6083 | defer tracy.end(); | 6468 | defer tracy.end(); |
| 6084 | | 6469 | |
| ... | @@ -6092,11 +6477,11 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6092,11 +6477,11 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6092 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 6477 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 6093 | | 6478 | |
| 6094 | const lhs_info = getArrayCatInfo(lhs_ty) orelse | 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 | const rhs_info = getArrayCatInfo(rhs_ty) orelse | 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 | if (!lhs_info.elem_type.eql(rhs_info.elem_type)) { | 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 | // When there is a sentinel mismatch, no sentinel on the result. The type system | 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,10 +6527,10 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6142 | else | 6527 | else |
| 6143 | sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(ty, val)); | 6528 | sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(ty, val)); |
| 6144 | } else { | 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 | } else { | 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,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 | const tracy = trace(@src()); | 6551 | const tracy = trace(@src()); |
| 6167 | defer tracy.end(); | 6552 | defer tracy.end(); |
| 6168 | | 6553 | |
| ... | @@ -6176,9 +6561,9 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6176,9 +6561,9 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6176 | // In `**` rhs has to be comptime-known, but lhs can be runtime-known | 6561 | // In `**` rhs has to be comptime-known, but lhs can be runtime-known |
| 6177 | const tomulby = try sema.resolveInt(block, rhs_src, extra.rhs, Type.initTag(.usize)); | 6562 | const tomulby = try sema.resolveInt(block, rhs_src, extra.rhs, Type.initTag(.usize)); |
| 6178 | const mulinfo = getArrayCatInfo(lhs_ty) orelse | 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 | if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| { | 6567 | if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| { |
| 6183 | var anon_decl = try block.startAnonDecl(); | 6568 | var anon_decl = try block.startAnonDecl(); |
| 6184 | defer anon_decl.deinit(); | 6569 | defer anon_decl.deinit(); |
| ... | @@ -6211,12 +6596,12 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6211,12 +6596,12 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6211 | return sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(final_ty, val)); | 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 | fn zirNegate( | 6602 | fn zirNegate( |
| 6218 | sema: *Sema, | 6603 | sema: *Sema, |
| 6219 | block: *Scope.Block, | 6604 | block: *Block, |
| 6220 | inst: Zir.Inst.Index, | 6605 | inst: Zir.Inst.Index, |
| 6221 | tag_override: Zir.Inst.Tag, | 6606 | tag_override: Zir.Inst.Tag, |
| 6222 | ) CompileError!Air.Inst.Ref { | 6607 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -6235,7 +6620,7 @@ fn zirNegate( | ... | @@ -6235,7 +6620,7 @@ fn zirNegate( |
| 6235 | | 6620 | |
| 6236 | fn zirArithmetic( | 6621 | fn zirArithmetic( |
| 6237 | sema: *Sema, | 6622 | sema: *Sema, |
| 6238 | block: *Scope.Block, | 6623 | block: *Block, |
| 6239 | inst: Zir.Inst.Index, | 6624 | inst: Zir.Inst.Index, |
| 6240 | zir_tag: Zir.Inst.Tag, | 6625 | zir_tag: Zir.Inst.Tag, |
| 6241 | ) CompileError!Air.Inst.Ref { | 6626 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -6255,7 +6640,7 @@ fn zirArithmetic( | ... | @@ -6255,7 +6640,7 @@ fn zirArithmetic( |
| 6255 | | 6640 | |
| 6256 | fn zirOverflowArithmetic( | 6641 | fn zirOverflowArithmetic( |
| 6257 | sema: *Sema, | 6642 | sema: *Sema, |
| 6258 | block: *Scope.Block, | 6643 | block: *Block, |
| 6259 | extended: Zir.Inst.Extended.InstData, | 6644 | extended: Zir.Inst.Extended.InstData, |
| 6260 | ) CompileError!Air.Inst.Ref { | 6645 | ) CompileError!Air.Inst.Ref { |
| 6261 | const tracy = trace(@src()); | 6646 | const tracy = trace(@src()); |
| ... | @@ -6264,12 +6649,12 @@ fn zirOverflowArithmetic( | ... | @@ -6264,12 +6649,12 @@ fn zirOverflowArithmetic( |
| 6264 | const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data; | 6649 | const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data; |
| 6265 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | fn analyzeArithmetic( | 6655 | fn analyzeArithmetic( |
| 6271 | sema: *Sema, | 6656 | sema: *Sema, |
| 6272 | block: *Scope.Block, | 6657 | block: *Block, |
| 6273 | /// TODO performance investigation: make this comptime? | 6658 | /// TODO performance investigation: make this comptime? |
| 6274 | zir_tag: Zir.Inst.Tag, | 6659 | zir_tag: Zir.Inst.Tag, |
| 6275 | lhs: Air.Inst.Ref, | 6660 | lhs: Air.Inst.Ref, |
| ... | @@ -6284,13 +6669,13 @@ fn analyzeArithmetic( | ... | @@ -6284,13 +6669,13 @@ fn analyzeArithmetic( |
| 6284 | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(); | 6669 | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(); |
| 6285 | if (lhs_zig_ty_tag == .Vector and rhs_zig_ty_tag == .Vector) { | 6670 | if (lhs_zig_ty_tag == .Vector and rhs_zig_ty_tag == .Vector) { |
| 6286 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { | 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 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), | 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 | } else if (lhs_zig_ty_tag == .Vector or rhs_zig_ty_tag == .Vector) { | 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 | lhs_ty, rhs_ty, | 6679 | lhs_ty, rhs_ty, |
| 6295 | }); | 6680 | }); |
| 6296 | } | 6681 | } |
| ... | @@ -6302,8 +6687,8 @@ fn analyzeArithmetic( | ... | @@ -6302,8 +6687,8 @@ fn analyzeArithmetic( |
| 6302 | const air_tag: Air.Inst.Tag = switch (zir_tag) { | 6687 | const air_tag: Air.Inst.Tag = switch (zir_tag) { |
| 6303 | .add => .ptr_add, | 6688 | .add => .ptr_add, |
| 6304 | .sub => .ptr_sub, | 6689 | .sub => .ptr_sub, |
| 6305 | else => return sema.mod.fail( | 6690 | else => return sema.fail( |
| 6306 | &block.base, | 6691 | block, |
| 6307 | op_src, | 6692 | op_src, |
| 6308 | "invalid pointer arithmetic operand: '{s}''", | 6693 | "invalid pointer arithmetic operand: '{s}''", |
| 6309 | .{@tagName(zir_tag)}, | 6694 | .{@tagName(zir_tag)}, |
| ... | @@ -6317,7 +6702,7 @@ fn analyzeArithmetic( | ... | @@ -6317,7 +6702,7 @@ fn analyzeArithmetic( |
| 6317 | if (try sema.resolveDefinedValue(block, rhs_src, casted_rhs)) |rhs_val| { | 6702 | if (try sema.resolveDefinedValue(block, rhs_src, casted_rhs)) |rhs_val| { |
| 6318 | _ = lhs_val; | 6703 | _ = lhs_val; |
| 6319 | _ = rhs_val; | 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 | } else { | 6706 | } else { |
| 6322 | break :runtime_src rhs_src; | 6707 | break :runtime_src rhs_src; |
| 6323 | } | 6708 | } |
| ... | @@ -6348,7 +6733,7 @@ fn analyzeArithmetic( | ... | @@ -6348,7 +6733,7 @@ fn analyzeArithmetic( |
| 6348 | const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat; | 6733 | const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat; |
| 6349 | | 6734 | |
| 6350 | if (!is_int and !(is_float and floatOpAllowed(zir_tag))) { | 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 | @tagName(lhs_zig_ty_tag), @tagName(rhs_zig_ty_tag), | 6737 | @tagName(lhs_zig_ty_tag), @tagName(rhs_zig_ty_tag), |
| 6353 | }); | 6738 | }); |
| 6354 | } | 6739 | } |
| ... | @@ -6930,7 +7315,7 @@ fn analyzeArithmetic( | ... | @@ -6930,7 +7315,7 @@ fn analyzeArithmetic( |
| 6930 | return block.addBinOp(rs.air_tag, casted_lhs, casted_rhs); | 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 | const tracy = trace(@src()); | 7319 | const tracy = trace(@src()); |
| 6935 | defer tracy.end(); | 7320 | defer tracy.end(); |
| 6936 | | 7321 | |
| ... | @@ -6943,7 +7328,7 @@ fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -6943,7 +7328,7 @@ fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError! |
| 6943 | | 7328 | |
| 6944 | fn zirAsm( | 7329 | fn zirAsm( |
| 6945 | sema: *Sema, | 7330 | sema: *Sema, |
| 6946 | block: *Scope.Block, | 7331 | block: *Block, |
| 6947 | extended: Zir.Inst.Extended.InstData, | 7332 | extended: Zir.Inst.Extended.InstData, |
| 6948 | inst: Zir.Inst.Index, | 7333 | inst: Zir.Inst.Index, |
| 6949 | ) CompileError!Air.Inst.Ref { | 7334 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -6958,7 +7343,7 @@ fn zirAsm( | ... | @@ -6958,7 +7343,7 @@ fn zirAsm( |
| 6958 | const clobbers_len = @truncate(u5, extended.small >> 10); | 7343 | const clobbers_len = @truncate(u5, extended.small >> 10); |
| 6959 | | 7344 | |
| 6960 | if (outputs_len > 1) { | 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 | var extra_i = extra.end; | 7349 | var extra_i = extra.end; |
| ... | @@ -6973,7 +7358,7 @@ fn zirAsm( | ... | @@ -6973,7 +7358,7 @@ fn zirAsm( |
| 6973 | output_type_bits >>= 1; | 7358 | output_type_bits >>= 1; |
| 6974 | | 7359 | |
| 6975 | if (!is_type) { | 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 | const constraint = sema.code.nullTerminatedString(output.data.constraint); | 7364 | const constraint = sema.code.nullTerminatedString(output.data.constraint); |
| ... | @@ -7022,7 +7407,7 @@ fn zirAsm( | ... | @@ -7022,7 +7407,7 @@ fn zirAsm( |
| 7022 | /// Only called for equality operators. See also `zirCmp`. | 7407 | /// Only called for equality operators. See also `zirCmp`. |
| 7023 | fn zirCmpEq( | 7408 | fn zirCmpEq( |
| 7024 | sema: *Sema, | 7409 | sema: *Sema, |
| 7025 | block: *Scope.Block, | 7410 | block: *Block, |
| 7026 | inst: Zir.Inst.Index, | 7411 | inst: Zir.Inst.Index, |
| 7027 | op: std.math.CompareOperator, | 7412 | op: std.math.CompareOperator, |
| 7028 | air_tag: Air.Inst.Tag, | 7413 | air_tag: Air.Inst.Tag, |
| ... | @@ -7030,7 +7415,6 @@ fn zirCmpEq( | ... | @@ -7030,7 +7415,6 @@ fn zirCmpEq( |
| 7030 | const tracy = trace(@src()); | 7415 | const tracy = trace(@src()); |
| 7031 | defer tracy.end(); | 7416 | defer tracy.end(); |
| 7032 | | 7417 | |
| 7033 | const mod = sema.mod; | | |
| 7034 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 7418 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 7035 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 7419 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 7036 | const src: LazySrcLoc = inst_data.src(); | 7420 | const src: LazySrcLoc = inst_data.src(); |
| ... | @@ -7059,11 +7443,11 @@ fn zirCmpEq( | ... | @@ -7059,11 +7443,11 @@ fn zirCmpEq( |
| 7059 | return sema.analyzeIsNull(block, src, opt_operand, op == .neq); | 7443 | return sema.analyzeIsNull(block, src, opt_operand, op == .neq); |
| 7060 | } | 7444 | } |
| 7061 | if (((lhs_ty_tag == .Null and rhs_ty.isCPtr()) or (rhs_ty_tag == .Null and lhs_ty.isCPtr()))) { | 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 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { | 7448 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { |
| 7065 | const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty; | 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 | if (lhs_ty_tag == .EnumLiteral and rhs_ty_tag == .Union) { | 7452 | if (lhs_ty_tag == .EnumLiteral and rhs_ty_tag == .Union) { |
| 7069 | return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op); | 7453 | return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op); |
| ... | @@ -7112,7 +7496,7 @@ fn zirCmpEq( | ... | @@ -7112,7 +7496,7 @@ fn zirCmpEq( |
| 7112 | | 7496 | |
| 7113 | fn analyzeCmpUnionTag( | 7497 | fn analyzeCmpUnionTag( |
| 7114 | sema: *Sema, | 7498 | sema: *Sema, |
| 7115 | block: *Scope.Block, | 7499 | block: *Block, |
| 7116 | un: Air.Inst.Ref, | 7500 | un: Air.Inst.Ref, |
| 7117 | un_src: LazySrcLoc, | 7501 | un_src: LazySrcLoc, |
| 7118 | tag: Air.Inst.Ref, | 7502 | tag: Air.Inst.Ref, |
| ... | @@ -7122,7 +7506,7 @@ fn analyzeCmpUnionTag( | ... | @@ -7122,7 +7506,7 @@ fn analyzeCmpUnionTag( |
| 7122 | const union_ty = sema.typeOf(un); | 7506 | const union_ty = sema.typeOf(un); |
| 7123 | const union_tag_ty = union_ty.unionTagType() orelse { | 7507 | const union_tag_ty = union_ty.unionTagType() orelse { |
| 7124 | // TODO note at declaration site that says "union foo is not tagged" | 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 | // Coerce both the union and the tag to the union's tag type, and then execute the | 7511 | // Coerce both the union and the tag to the union's tag type, and then execute the |
| 7128 | // enum comparison codepath. | 7512 | // enum comparison codepath. |
| ... | @@ -7135,7 +7519,7 @@ fn analyzeCmpUnionTag( | ... | @@ -7135,7 +7519,7 @@ fn analyzeCmpUnionTag( |
| 7135 | /// Only called for non-equality operators. See also `zirCmpEq`. | 7519 | /// Only called for non-equality operators. See also `zirCmpEq`. |
| 7136 | fn zirCmp( | 7520 | fn zirCmp( |
| 7137 | sema: *Sema, | 7521 | sema: *Sema, |
| 7138 | block: *Scope.Block, | 7522 | block: *Block, |
| 7139 | inst: Zir.Inst.Index, | 7523 | inst: Zir.Inst.Index, |
| 7140 | op: std.math.CompareOperator, | 7524 | op: std.math.CompareOperator, |
| 7141 | ) CompileError!Air.Inst.Ref { | 7525 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -7154,7 +7538,7 @@ fn zirCmp( | ... | @@ -7154,7 +7538,7 @@ fn zirCmp( |
| 7154 | | 7538 | |
| 7155 | fn analyzeCmp( | 7539 | fn analyzeCmp( |
| 7156 | sema: *Sema, | 7540 | sema: *Sema, |
| 7157 | block: *Scope.Block, | 7541 | block: *Block, |
| 7158 | src: LazySrcLoc, | 7542 | src: LazySrcLoc, |
| 7159 | lhs: Air.Inst.Ref, | 7543 | lhs: Air.Inst.Ref, |
| 7160 | rhs: Air.Inst.Ref, | 7544 | rhs: Air.Inst.Ref, |
| ... | @@ -7174,7 +7558,7 @@ fn analyzeCmp( | ... | @@ -7174,7 +7558,7 @@ fn analyzeCmp( |
| 7174 | const instructions = &[_]Air.Inst.Ref{ lhs, rhs }; | 7558 | const instructions = &[_]Air.Inst.Ref{ lhs, rhs }; |
| 7175 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]LazySrcLoc{ lhs_src, rhs_src } }); | 7559 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]LazySrcLoc{ lhs_src, rhs_src } }); |
| 7176 | if (!resolved_type.isSelfComparable(is_equality_cmp)) { | 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 | @tagName(op), resolved_type, | 7562 | @tagName(op), resolved_type, |
| 7179 | }); | 7563 | }); |
| 7180 | } | 7564 | } |
| ... | @@ -7185,7 +7569,7 @@ fn analyzeCmp( | ... | @@ -7185,7 +7569,7 @@ fn analyzeCmp( |
| 7185 | | 7569 | |
| 7186 | fn cmpSelf( | 7570 | fn cmpSelf( |
| 7187 | sema: *Sema, | 7571 | sema: *Sema, |
| 7188 | block: *Scope.Block, | 7572 | block: *Block, |
| 7189 | casted_lhs: Air.Inst.Ref, | 7573 | casted_lhs: Air.Inst.Ref, |
| 7190 | casted_rhs: Air.Inst.Ref, | 7574 | casted_rhs: Air.Inst.Ref, |
| 7191 | op: std.math.CompareOperator, | 7575 | op: std.math.CompareOperator, |
| ... | @@ -7243,7 +7627,7 @@ fn cmpSelf( | ... | @@ -7243,7 +7627,7 @@ fn cmpSelf( |
| 7243 | /// cmp_neq(x, true ) => not(x) | 7627 | /// cmp_neq(x, true ) => not(x) |
| 7244 | fn runtimeBoolCmp( | 7628 | fn runtimeBoolCmp( |
| 7245 | sema: *Sema, | 7629 | sema: *Sema, |
| 7246 | block: *Scope.Block, | 7630 | block: *Block, |
| 7247 | op: std.math.CompareOperator, | 7631 | op: std.math.CompareOperator, |
| 7248 | lhs: Air.Inst.Ref, | 7632 | lhs: Air.Inst.Ref, |
| 7249 | rhs: bool, | 7633 | rhs: bool, |
| ... | @@ -7257,7 +7641,7 @@ fn runtimeBoolCmp( | ... | @@ -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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 7645 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7262 | const src = inst_data.src(); | 7646 | const src = inst_data.src(); |
| 7263 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +7655,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7271 | .Null, | 7655 | .Null, |
| 7272 | .BoundFn, | 7656 | .BoundFn, |
| 7273 | .Opaque, | 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 | .Type, | 7659 | .Type, |
| 7276 | .EnumLiteral, | 7660 | .EnumLiteral, |
| 7277 | .ComptimeFloat, | 7661 | .ComptimeFloat, |
| ... | @@ -7298,7 +7682,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -7298,7 +7682,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7298 | return sema.addIntUnsigned(Type.initTag(.comptime_int), abi_size); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 7686 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7303 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 7687 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 7304 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); | 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,17 +7693,17 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 7309 | | 7693 | |
| 7310 | fn zirThis( | 7694 | fn zirThis( |
| 7311 | sema: *Sema, | 7695 | sema: *Sema, |
| 7312 | block: *Scope.Block, | 7696 | block: *Block, |
| 7313 | extended: Zir.Inst.Extended.InstData, | 7697 | extended: Zir.Inst.Extended.InstData, |
| 7314 | ) CompileError!Air.Inst.Ref { | 7698 | ) CompileError!Air.Inst.Ref { |
| 7315 | const this_decl = block.base.namespace().getDecl(); | 7699 | const this_decl = block.namespace.getDecl(); |
| 7316 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 7700 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 7317 | return sema.analyzeDeclVal(block, src, this_decl); | 7701 | return sema.analyzeDeclVal(block, src, this_decl); |
| 7318 | } | 7702 | } |
| 7319 | | 7703 | |
| 7320 | fn zirClosureCapture( | 7704 | fn zirClosureCapture( |
| 7321 | sema: *Sema, | 7705 | sema: *Sema, |
| 7322 | block: *Scope.Block, | 7706 | block: *Block, |
| 7323 | inst: Zir.Inst.Index, | 7707 | inst: Zir.Inst.Index, |
| 7324 | ) CompileError!void { | 7708 | ) CompileError!void { |
| 7325 | // TODO: Compile error when closed over values are modified | 7709 | // TODO: Compile error when closed over values are modified |
| ... | @@ -7333,7 +7717,7 @@ fn zirClosureCapture( | ... | @@ -7333,7 +7717,7 @@ fn zirClosureCapture( |
| 7333 | | 7717 | |
| 7334 | fn zirClosureGet( | 7718 | fn zirClosureGet( |
| 7335 | sema: *Sema, | 7719 | sema: *Sema, |
| 7336 | block: *Scope.Block, | 7720 | block: *Block, |
| 7337 | inst: Zir.Inst.Index, | 7721 | inst: Zir.Inst.Index, |
| 7338 | ) CompileError!Air.Inst.Ref { | 7722 | ) CompileError!Air.Inst.Ref { |
| 7339 | // TODO CLOSURE: Test this with inline functions | 7723 | // TODO CLOSURE: Test this with inline functions |
| ... | @@ -7355,23 +7739,23 @@ fn zirClosureGet( | ... | @@ -7355,23 +7739,23 @@ fn zirClosureGet( |
| 7355 | | 7739 | |
| 7356 | fn zirRetAddr( | 7740 | fn zirRetAddr( |
| 7357 | sema: *Sema, | 7741 | sema: *Sema, |
| 7358 | block: *Scope.Block, | 7742 | block: *Block, |
| 7359 | extended: Zir.Inst.Extended.InstData, | 7743 | extended: Zir.Inst.Extended.InstData, |
| 7360 | ) CompileError!Air.Inst.Ref { | 7744 | ) CompileError!Air.Inst.Ref { |
| 7361 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirBuiltinSrc( | 7749 | fn zirBuiltinSrc( |
| 7366 | sema: *Sema, | 7750 | sema: *Sema, |
| 7367 | block: *Scope.Block, | 7751 | block: *Block, |
| 7368 | extended: Zir.Inst.Extended.InstData, | 7752 | extended: Zir.Inst.Extended.InstData, |
| 7369 | ) CompileError!Air.Inst.Ref { | 7753 | ) CompileError!Air.Inst.Ref { |
| 7370 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 7759 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7376 | const src = inst_data.src(); | 7760 | const src = inst_data.src(); |
| 7377 | const ty = try sema.resolveType(block, src, inst_data.operand); | 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,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 | @tagName(t), | 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 | _ = block; | 7964 | _ = block; |
| 7581 | const zir_datas = sema.code.instructions.items(.data); | 7965 | const zir_datas = sema.code.instructions.items(.data); |
| 7582 | const inst_data = zir_datas[inst].un_node; | 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,7 +7969,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7585 | return sema.addType(operand_ty); | 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 | _ = block; | 7973 | _ = block; |
| 7590 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 7974 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7591 | const operand_ptr = sema.resolveInst(inst_data.operand); | 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,7 +7977,7 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 7593 | return sema.addType(elem_ty); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 7981 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7598 | const src = inst_data.src(); | 7982 | const src = inst_data.src(); |
| 7599 | const operand = sema.resolveInst(inst_data.operand); | 7983 | const operand = sema.resolveInst(inst_data.operand); |
| ... | @@ -7601,14 +7985,14 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) | ... | @@ -7601,14 +7985,14 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 7601 | return sema.log2IntType(block, operand_ty, src); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 7989 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 7606 | const src = inst_data.src(); | 7990 | const src = inst_data.src(); |
| 7607 | const operand = try sema.resolveType(block, src, inst_data.operand); | 7991 | const operand = try sema.resolveType(block, src, inst_data.operand); |
| 7608 | return sema.log2IntType(block, operand, src); | 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 | switch (operand.zigTypeTag()) { | 7996 | switch (operand.zigTypeTag()) { |
| 7613 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, | 7997 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, |
| 7614 | .Int => { | 7998 | .Int => { |
| ... | @@ -7620,8 +8004,8 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) | ... | @@ -7620,8 +8004,8 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) |
| 7620 | const res = try Module.makeIntType(sema.arena, .unsigned, count); | 8004 | const res = try Module.makeIntType(sema.arena, .unsigned, count); |
| 7621 | return sema.addType(res); | 8005 | return sema.addType(res); |
| 7622 | }, | 8006 | }, |
| 7623 | else => return sema.mod.fail( | 8007 | else => return sema.fail( |
| 7624 | &block.base, | 8008 | block, |
| 7625 | src, | 8009 | src, |
| 7626 | "bit shifting operation expected integer type, found '{}'", | 8010 | "bit shifting operation expected integer type, found '{}'", |
| 7627 | .{operand}, | 8011 | .{operand}, |
| ... | @@ -7631,7 +8015,7 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) | ... | @@ -7631,7 +8015,7 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) |
| 7631 | | 8015 | |
| 7632 | fn zirTypeofPeer( | 8016 | fn zirTypeofPeer( |
| 7633 | sema: *Sema, | 8017 | sema: *Sema, |
| 7634 | block: *Scope.Block, | 8018 | block: *Block, |
| 7635 | extended: Zir.Inst.Extended.InstData, | 8019 | extended: Zir.Inst.Extended.InstData, |
| 7636 | ) CompileError!Air.Inst.Ref { | 8020 | ) CompileError!Air.Inst.Ref { |
| 7637 | const tracy = trace(@src()); | 8021 | const tracy = trace(@src()); |
| ... | @@ -7652,7 +8036,7 @@ fn zirTypeofPeer( | ... | @@ -7652,7 +8036,7 @@ fn zirTypeofPeer( |
| 7652 | return sema.addType(result_type); | 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 | const tracy = trace(@src()); | 8040 | const tracy = trace(@src()); |
| 7657 | defer tracy.end(); | 8041 | defer tracy.end(); |
| 7658 | | 8042 | |
| ... | @@ -7676,7 +8060,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -7676,7 +8060,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 7676 | | 8060 | |
| 7677 | fn zirBoolBr( | 8061 | fn zirBoolBr( |
| 7678 | sema: *Sema, | 8062 | sema: *Sema, |
| 7679 | parent_block: *Scope.Block, | 8063 | parent_block: *Block, |
| 7680 | inst: Zir.Inst.Index, | 8064 | inst: Zir.Inst.Index, |
| 7681 | is_bool_or: bool, | 8065 | is_bool_or: bool, |
| 7682 | ) CompileError!Air.Inst.Ref { | 8066 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -7762,7 +8146,7 @@ fn zirBoolBr( | ... | @@ -7762,7 +8146,7 @@ fn zirBoolBr( |
| 7762 | | 8146 | |
| 7763 | fn zirIsNonNull( | 8147 | fn zirIsNonNull( |
| 7764 | sema: *Sema, | 8148 | sema: *Sema, |
| 7765 | block: *Scope.Block, | 8149 | block: *Block, |
| 7766 | inst: Zir.Inst.Index, | 8150 | inst: Zir.Inst.Index, |
| 7767 | ) CompileError!Air.Inst.Ref { | 8151 | ) CompileError!Air.Inst.Ref { |
| 7768 | const tracy = trace(@src()); | 8152 | const tracy = trace(@src()); |
| ... | @@ -7776,7 +8160,7 @@ fn zirIsNonNull( | ... | @@ -7776,7 +8160,7 @@ fn zirIsNonNull( |
| 7776 | | 8160 | |
| 7777 | fn zirIsNonNullPtr( | 8161 | fn zirIsNonNullPtr( |
| 7778 | sema: *Sema, | 8162 | sema: *Sema, |
| 7779 | block: *Scope.Block, | 8163 | block: *Block, |
| 7780 | inst: Zir.Inst.Index, | 8164 | inst: Zir.Inst.Index, |
| 7781 | ) CompileError!Air.Inst.Ref { | 8165 | ) CompileError!Air.Inst.Ref { |
| 7782 | const tracy = trace(@src()); | 8166 | const tracy = trace(@src()); |
| ... | @@ -7789,7 +8173,7 @@ fn zirIsNonNullPtr( | ... | @@ -7789,7 +8173,7 @@ fn zirIsNonNullPtr( |
| 7789 | return sema.analyzeIsNull(block, src, loaded, true); | 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 | const tracy = trace(@src()); | 8177 | const tracy = trace(@src()); |
| 7794 | defer tracy.end(); | 8178 | defer tracy.end(); |
| 7795 | | 8179 | |
| ... | @@ -7798,7 +8182,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -7798,7 +8182,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 7798 | return sema.analyzeIsNonErr(block, inst_data.src(), operand); | 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 | const tracy = trace(@src()); | 8186 | const tracy = trace(@src()); |
| 7803 | defer tracy.end(); | 8187 | defer tracy.end(); |
| 7804 | | 8188 | |
| ... | @@ -7811,7 +8195,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -7811,7 +8195,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 7811 | | 8195 | |
| 7812 | fn zirCondbr( | 8196 | fn zirCondbr( |
| 7813 | sema: *Sema, | 8197 | sema: *Sema, |
| 7814 | parent_block: *Scope.Block, | 8198 | parent_block: *Block, |
| 7815 | inst: Zir.Inst.Index, | 8199 | inst: Zir.Inst.Index, |
| 7816 | ) CompileError!Zir.Inst.Index { | 8200 | ) CompileError!Zir.Inst.Index { |
| 7817 | const tracy = trace(@src()); | 8201 | const tracy = trace(@src()); |
| ... | @@ -7866,7 +8250,7 @@ fn zirCondbr( | ... | @@ -7866,7 +8250,7 @@ fn zirCondbr( |
| 7866 | return always_noreturn; | 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 | const tracy = trace(@src()); | 8254 | const tracy = trace(@src()); |
| 7871 | defer tracy.end(); | 8255 | defer tracy.end(); |
| 7872 | | 8256 | |
| ... | @@ -7885,7 +8269,7 @@ fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -7885,7 +8269,7 @@ fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 7885 | | 8269 | |
| 7886 | fn zirRetErrValue( | 8270 | fn zirRetErrValue( |
| 7887 | sema: *Sema, | 8271 | sema: *Sema, |
| 7888 | block: *Scope.Block, | 8272 | block: *Block, |
| 7889 | inst: Zir.Inst.Index, | 8273 | inst: Zir.Inst.Index, |
| 7890 | ) CompileError!Zir.Inst.Index { | 8274 | ) CompileError!Zir.Inst.Index { |
| 7891 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 8275 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| ... | @@ -7909,7 +8293,7 @@ fn zirRetErrValue( | ... | @@ -7909,7 +8293,7 @@ fn zirRetErrValue( |
| 7909 | | 8293 | |
| 7910 | fn zirRetCoerce( | 8294 | fn zirRetCoerce( |
| 7911 | sema: *Sema, | 8295 | sema: *Sema, |
| 7912 | block: *Scope.Block, | 8296 | block: *Block, |
| 7913 | inst: Zir.Inst.Index, | 8297 | inst: Zir.Inst.Index, |
| 7914 | ) CompileError!Zir.Inst.Index { | 8298 | ) CompileError!Zir.Inst.Index { |
| 7915 | const tracy = trace(@src()); | 8299 | const tracy = trace(@src()); |
| ... | @@ -7922,7 +8306,7 @@ fn zirRetCoerce( | ... | @@ -7922,7 +8306,7 @@ fn zirRetCoerce( |
| 7922 | return sema.analyzeRet(block, operand, src, true); | 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 | const tracy = trace(@src()); | 8310 | const tracy = trace(@src()); |
| 7927 | defer tracy.end(); | 8311 | defer tracy.end(); |
| 7928 | | 8312 | |
| ... | @@ -7937,7 +8321,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -7937,7 +8321,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 7937 | return sema.analyzeRet(block, operand, src, false); | 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 | const tracy = trace(@src()); | 8325 | const tracy = trace(@src()); |
| 7942 | defer tracy.end(); | 8326 | defer tracy.end(); |
| 7943 | | 8327 | |
| ... | @@ -7954,7 +8338,7 @@ fn zirRetLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -7954,7 +8338,7 @@ fn zirRetLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 7954 | | 8338 | |
| 7955 | fn analyzeRet( | 8339 | fn analyzeRet( |
| 7956 | sema: *Sema, | 8340 | sema: *Sema, |
| 7957 | block: *Scope.Block, | 8341 | block: *Block, |
| 7958 | uncasted_operand: Air.Inst.Ref, | 8342 | uncasted_operand: Air.Inst.Ref, |
| 7959 | src: LazySrcLoc, | 8343 | src: LazySrcLoc, |
| 7960 | need_coercion: bool, | 8344 | need_coercion: bool, |
| ... | @@ -7987,7 +8371,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) 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 | const tracy = trace(@src()); | 8375 | const tracy = trace(@src()); |
| 7992 | defer tracy.end(); | 8376 | defer tracy.end(); |
| 7993 | | 8377 | |
| ... | @@ -8004,7 +8388,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp | ... | @@ -8004,7 +8388,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp |
| 8004 | return sema.addType(ty); | 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 | const tracy = trace(@src()); | 8392 | const tracy = trace(@src()); |
| 8009 | defer tracy.end(); | 8393 | defer tracy.end(); |
| 8010 | | 8394 | |
| ... | @@ -8045,7 +8429,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -8045,7 +8429,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8045 | } else 0; | 8429 | } else 0; |
| 8046 | | 8430 | |
| 8047 | if (bit_end != 0 and bit_start >= bit_end * 8) | 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 | const elem_type = try sema.resolveType(block, .unneeded, extra.data.elem_type); | 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,7 +8448,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8064 | return sema.addType(ty); | 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 | const tracy = trace(@src()); | 8452 | const tracy = trace(@src()); |
| 8069 | defer tracy.end(); | 8453 | defer tracy.end(); |
| 8070 | | 8454 | |
| ... | @@ -8075,14 +8459,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co | ... | @@ -8075,14 +8459,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 8075 | return sema.addConstant(struct_type, Value.initTag(.empty_struct_value)); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8463 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8080 | const src = inst_data.src(); | 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 { | 8468 | fn zirStructInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8085 | const mod = sema.mod; | | |
| 8086 | const gpa = sema.gpa; | 8469 | const gpa = sema.gpa; |
| 8087 | const zir_datas = sema.code.instructions.items(.data); | 8470 | const zir_datas = sema.code.instructions.items(.data); |
| 8088 | const inst_data = zir_datas[inst].pl_node; | 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,12 +8509,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8126 | const other_field_type_data = zir_datas[other_field_type].pl_node; | 8509 | const other_field_type_data = zir_datas[other_field_type].pl_node; |
| 8127 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node }; | 8510 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node }; |
| 8128 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 8515 | break :msg msg; |
| 8133 | }; | 8516 | }; |
| 8134 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 8517 | return sema.failWithOwnedErrorMsg(msg); |
| 8135 | } | 8518 | } |
| 8136 | found_fields[field_index] = item.data.field_type; | 8519 | found_fields[field_index] = item.data.field_type; |
| 8137 | field_inits[field_index] = sema.resolveInst(item.data.init); | 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,9 +8532,9 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8149 | const template = "missing struct field: {s}"; | 8532 | const template = "missing struct field: {s}"; |
| 8150 | const args = .{field_name}; | 8533 | const args = .{field_name}; |
| 8151 | if (root_msg) |msg| { | 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 | } else { | 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 | } else { | 8539 | } else { |
| 8157 | field_inits[i] = try sema.addConstant(field.ty, field.default_val); | 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,17 +8543,17 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8160 | if (root_msg) |msg| { | 8543 | if (root_msg) |msg| { |
| 8161 | const fqn = try struct_obj.getFullyQualifiedName(gpa); | 8544 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 8162 | defer gpa.free(fqn); | 8545 | defer gpa.free(fqn); |
| 8163 | try mod.errNoteNonLazy( | 8546 | try sema.mod.errNoteNonLazy( |
| 8164 | struct_obj.srcLoc(), | 8547 | struct_obj.srcLoc(), |
| 8165 | msg, | 8548 | msg, |
| 8166 | "struct '{s}' declared here", | 8549 | "struct '{s}' declared here", |
| 8167 | .{fqn}, | 8550 | .{fqn}, |
| 8168 | ); | 8551 | ); |
| 8169 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 8552 | return sema.failWithOwnedErrorMsg(msg); |
| 8170 | } | 8553 | } |
| 8171 | | 8554 | |
| 8172 | if (is_ref) { | 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 | const is_comptime = for (field_inits) |field_init| { | 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,12 +8570,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8187 | return sema.addConstant(resolved_ty, try Value.Tag.@"struct".create(sema.arena, values)); | 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 | } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| { | 8574 | } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| { |
| 8192 | const union_obj = union_payload.data; | 8575 | const union_obj = union_payload.data; |
| 8193 | | 8576 | |
| 8194 | if (extra.data.fields_len != 1) { | 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 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); | 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,7 +8588,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8205 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | 8588 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); |
| 8206 | | 8589 | |
| 8207 | if (is_ref) { | 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 | const init_inst = sema.resolveInst(item.data.init); | 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,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 | unreachable; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8610 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8228 | const src = inst_data.src(); | 8611 | const src = inst_data.src(); |
| 8229 | | 8612 | |
| 8230 | _ = is_ref; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8618 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8236 | const src = inst_data.src(); | 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,10 +8632,13 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8249 | var anon_decl = try block.startAnonDecl(); | 8632 | var anon_decl = try block.startAnonDecl(); |
| 8250 | defer anon_decl.deinit(); | 8633 | defer anon_decl.deinit(); |
| 8251 | assert(!(resolved_args.len == 0)); | 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 | const buf = try anon_decl.arena().alloc(Value, resolved_args.len); | 8639 | const buf = try anon_decl.arena().alloc(Value, resolved_args.len); |
| 8254 | for (resolved_args) |arg, i| { | 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 | const val = try Value.Tag.array.create(anon_decl.arena(), buf); | 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,21 +8666,21 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8280 | try sema.analyzeLoad(block, .unneeded, alloc, .unneeded); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8670 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8285 | const src = inst_data.src(); | 8671 | const src = inst_data.src(); |
| 8286 | | 8672 | |
| 8287 | _ = is_ref; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8678 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8293 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8684 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8299 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; | 8685 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 8300 | const src = inst_data.src(); | 8686 | const src = inst_data.src(); |
| ... | @@ -8314,7 +8700,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -8314,7 +8700,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8314 | return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name); | 8700 | return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name); |
| 8315 | return sema.addType(field.ty); | 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 | resolved_ty, | 8704 | resolved_ty, |
| 8319 | }), | 8705 | }), |
| 8320 | } | 8706 | } |
| ... | @@ -8322,32 +8708,32 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -8322,32 +8708,32 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8322 | | 8708 | |
| 8323 | fn zirErrorReturnTrace( | 8709 | fn zirErrorReturnTrace( |
| 8324 | sema: *Sema, | 8710 | sema: *Sema, |
| 8325 | block: *Scope.Block, | 8711 | block: *Block, |
| 8326 | extended: Zir.Inst.Extended.InstData, | 8712 | extended: Zir.Inst.Extended.InstData, |
| 8327 | ) CompileError!Air.Inst.Ref { | 8713 | ) CompileError!Air.Inst.Ref { |
| 8328 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirFrame( | 8718 | fn zirFrame( |
| 8333 | sema: *Sema, | 8719 | sema: *Sema, |
| 8334 | block: *Scope.Block, | 8720 | block: *Block, |
| 8335 | extended: Zir.Inst.Extended.InstData, | 8721 | extended: Zir.Inst.Extended.InstData, |
| 8336 | ) CompileError!Air.Inst.Ref { | 8722 | ) CompileError!Air.Inst.Ref { |
| 8337 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirFrameAddress( | 8727 | fn zirFrameAddress( |
| 8342 | sema: *Sema, | 8728 | sema: *Sema, |
| 8343 | block: *Scope.Block, | 8729 | block: *Block, |
| 8344 | extended: Zir.Inst.Extended.InstData, | 8730 | extended: Zir.Inst.Extended.InstData, |
| 8345 | ) CompileError!Air.Inst.Ref { | 8731 | ) CompileError!Air.Inst.Ref { |
| 8346 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8737 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8352 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8738 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8353 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); | 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,7 +8742,7 @@ fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8356 | return sema.addIntUnsigned(Type.comptime_int, abi_align); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8746 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8361 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8747 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8362 | const operand = sema.resolveInst(inst_data.operand); | 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,31 +8754,31 @@ fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8368 | return block.addUnOp(.bool_to_int, operand); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8758 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8373 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8764 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8379 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8770 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8385 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8776 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8391 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8782 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8397 | const src = inst_data.src(); | 8783 | const src = inst_data.src(); |
| 8398 | const type_info_ty = try sema.getBuiltinType(block, src, "TypeInfo"); | 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,55 +8808,55 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 8422 | }; | 8808 | }; |
| 8423 | return sema.addType(ty); | 8809 | return sema.addType(ty); |
| 8424 | }, | 8810 | }, |
| 8425 | .Float => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Float", .{}), | 8811 | .Float => return sema.fail(block, src, "TODO: Sema.zirReify for Float", .{}), |
| 8426 | .Pointer => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Pointer", .{}), | 8812 | .Pointer => return sema.fail(block, src, "TODO: Sema.zirReify for Pointer", .{}), |
| 8427 | .Array => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Array", .{}), | 8813 | .Array => return sema.fail(block, src, "TODO: Sema.zirReify for Array", .{}), |
| 8428 | .Struct => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Struct", .{}), | 8814 | .Struct => return sema.fail(block, src, "TODO: Sema.zirReify for Struct", .{}), |
| 8429 | .ComptimeFloat => return Air.Inst.Ref.comptime_float_type, | 8815 | .ComptimeFloat => return Air.Inst.Ref.comptime_float_type, |
| 8430 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, | 8816 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, |
| 8431 | .Undefined => return Air.Inst.Ref.undefined_type, | 8817 | .Undefined => return Air.Inst.Ref.undefined_type, |
| 8432 | .Null => return Air.Inst.Ref.null_type, | 8818 | .Null => return Air.Inst.Ref.null_type, |
| 8433 | .Optional => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Optional", .{}), | 8819 | .Optional => return sema.fail(block, src, "TODO: Sema.zirReify for Optional", .{}), |
| 8434 | .ErrorUnion => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorUnion", .{}), | 8820 | .ErrorUnion => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorUnion", .{}), |
| 8435 | .ErrorSet => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorSet", .{}), | 8821 | .ErrorSet => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorSet", .{}), |
| 8436 | .Enum => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Enum", .{}), | 8822 | .Enum => return sema.fail(block, src, "TODO: Sema.zirReify for Enum", .{}), |
| 8437 | .Union => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Union", .{}), | 8823 | .Union => return sema.fail(block, src, "TODO: Sema.zirReify for Union", .{}), |
| 8438 | .Fn => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Fn", .{}), | 8824 | .Fn => return sema.fail(block, src, "TODO: Sema.zirReify for Fn", .{}), |
| 8439 | .BoundFn => @panic("TODO delete BoundFn from the language"), | 8825 | .BoundFn => @panic("TODO delete BoundFn from the language"), |
| 8440 | .Opaque => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Opaque", .{}), | 8826 | .Opaque => return sema.fail(block, src, "TODO: Sema.zirReify for Opaque", .{}), |
| 8441 | .Frame => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Frame", .{}), | 8827 | .Frame => return sema.fail(block, src, "TODO: Sema.zirReify for Frame", .{}), |
| 8442 | .AnyFrame => return Air.Inst.Ref.anyframe_type, | 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 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8835 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8450 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8841 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8456 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8847 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8462 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8853 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8468 | const src = inst_data.src(); | 8854 | const src = inst_data.src(); |
| 8469 | // TODO don't forget the safety check! | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8860 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8475 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8861 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8476 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +8878,7 @@ fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 8492 | return block.addTyOp(.int_to_float, dest_ty, operand); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8882 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8497 | const src = inst_data.src(); | 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,15 +8891,15 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8505 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8891 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8506 | const type_res = try sema.resolveType(block, src, extra.lhs); | 8892 | const type_res = try sema.resolveType(block, src, extra.lhs); |
| 8507 | if (type_res.zigTypeTag() != .Pointer) | 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 | const ptr_align = type_res.ptrAlignment(sema.mod.getTarget()); | 8895 | const ptr_align = type_res.ptrAlignment(sema.mod.getTarget()); |
| 8510 | | 8896 | |
| 8511 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { | 8897 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| 8512 | const addr = val.toUnsignedInt(); | 8898 | const addr = val.toUnsignedInt(); |
| 8513 | if (!type_res.isAllowzeroPtr() and addr == 0) | 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 | if (addr != 0 and addr % ptr_align != 0) | 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 | const val_payload = try sema.arena.create(Value.Payload.U64); | 8904 | const val_payload = try sema.arena.create(Value.Payload.U64); |
| 8519 | val_payload.* = .{ | 8905 | val_payload.* = .{ |
| ... | @@ -8548,13 +8934,13 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8548,13 +8934,13 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8548 | return block.addTyOp(.bitcast, type_res, operand_coerced); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8938 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8553 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8944 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8559 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8945 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8560 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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,12 +8949,12 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8563 | const operand = sema.resolveInst(extra.rhs); | 8949 | const operand = sema.resolveInst(extra.rhs); |
| 8564 | const operand_ty = sema.typeOf(operand); | 8950 | const operand_ty = sema.typeOf(operand); |
| 8565 | if (operand_ty.zigTypeTag() != .Pointer) { | 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 | @tagName(operand_ty.zigTypeTag()), operand_ty, | 8953 | @tagName(operand_ty.zigTypeTag()), operand_ty, |
| 8568 | }); | 8954 | }); |
| 8569 | } | 8955 | } |
| 8570 | if (dest_ty.zigTypeTag() != .Pointer) { | 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 | @tagName(dest_ty.zigTypeTag()), dest_ty, | 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,7 +8964,7 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8578 | return block.addTyOp(.bitcast, dest_ty, operand); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8968 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8583 | const src = inst_data.src(); | 8969 | const src = inst_data.src(); |
| 8584 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +8973,6 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8587 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); | 8973 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 8588 | const operand = sema.resolveInst(extra.rhs); | 8974 | const operand = sema.resolveInst(extra.rhs); |
| 8589 | const operand_ty = sema.typeOf(operand); | 8975 | const operand_ty = sema.typeOf(operand); |
| 8590 | const mod = sema.mod; | | |
| 8591 | const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_ty); | 8976 | const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_ty); |
| 8592 | const src_is_comptime_int = try sema.checkIntType(block, operand_src, operand_ty); | 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,7 +8980,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8595 | return sema.coerce(block, dest_ty, operand, operand_src); | 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 | const src_info = operand_ty.intInfo(target); | 8984 | const src_info = operand_ty.intInfo(target); |
| 8600 | const dest_info = dest_ty.intInfo(target); | 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,28 +8990,28 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8605 | | 8990 | |
| 8606 | if (!src_is_comptime_int) { | 8991 | if (!src_is_comptime_int) { |
| 8607 | if (src_info.signedness != dest_info.signedness) { | 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 | @tagName(dest_info.signedness), operand_ty, | 8994 | @tagName(dest_info.signedness), operand_ty, |
| 8610 | }); | 8995 | }); |
| 8611 | } | 8996 | } |
| 8612 | if (src_info.bits > 0 and src_info.bits < dest_info.bits) { | 8997 | if (src_info.bits > 0 and src_info.bits < dest_info.bits) { |
| 8613 | const msg = msg: { | 8998 | const msg = msg: { |
| 8614 | const msg = try mod.errMsg( | 8999 | const msg = try sema.errMsg( |
| 8615 | &block.base, | 9000 | block, |
| 8616 | src, | 9001 | src, |
| 8617 | "destination type '{}' has more bits than source type '{}'", | 9002 | "destination type '{}' has more bits than source type '{}'", |
| 8618 | .{ dest_ty, operand_ty }, | 9003 | .{ dest_ty, operand_ty }, |
| 8619 | ); | 9004 | ); |
| 8620 | errdefer msg.destroy(mod.gpa); | 9005 | errdefer msg.destroy(sema.gpa); |
| 8621 | try mod.errNote(&block.base, dest_ty_src, msg, "destination type has {d} bits", .{ | 9006 | try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{ |
| 8622 | dest_info.bits, | 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 | src_info.bits, | 9010 | src_info.bits, |
| 8626 | }); | 9011 | }); |
| 8627 | break :msg msg; | 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,13 +9024,13 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8639 | return block.addTyOp(.trunc, dest_ty, operand); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9028 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8644 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9034 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8650 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 9035 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8651 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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,7 +9038,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8653 | const operand_ty = sema.typeOf(operand); | 9038 | const operand_ty = sema.typeOf(operand); |
| 8654 | // TODO implement support for vectors | 9039 | // TODO implement support for vectors |
| 8655 | if (operand_ty.zigTypeTag() != .Int) { | 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 | operand_ty, | 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,7 +9057,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8672 | return block.addTyOp(.clz, result_ty, operand); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9061 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8677 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 9062 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8678 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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,7 +9065,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8680 | const operand_ty = sema.typeOf(operand); | 9065 | const operand_ty = sema.typeOf(operand); |
| 8681 | // TODO implement support for vectors | 9066 | // TODO implement support for vectors |
| 8682 | if (operand_ty.zigTypeTag() != .Int) { | 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 | operand_ty, | 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,85 +9077,85 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8692 | | 9077 | |
| 8693 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | 9078 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 8694 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 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 | } else operand_src; | 9081 | } else operand_src; |
| 8697 | | 9082 | |
| 8698 | try sema.requireRuntimeBlock(block, runtime_src); | 9083 | try sema.requireRuntimeBlock(block, runtime_src); |
| 8699 | return block.addTyOp(.ctz, result_ty, operand); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9088 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8704 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9094 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8710 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9100 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8716 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9106 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8722 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9112 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8728 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9118 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8734 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9124 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8740 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9130 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8746 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9136 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8752 | const src = inst_data.src(); | 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 | /// Returns `true` if the type was a comptime_int. | 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 | switch (ty.zigTypeTag()) { | 9143 | switch (ty.zigTypeTag()) { |
| 8759 | .ComptimeInt => return true, | 9144 | .ComptimeInt => return true, |
| 8760 | .Int => return false, | 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 | fn checkFloatType( | 9150 | fn checkFloatType( |
| 8766 | sema: *Sema, | 9151 | sema: *Sema, |
| 8767 | block: *Scope.Block, | 9152 | block: *Block, |
| 8768 | ty_src: LazySrcLoc, | 9153 | ty_src: LazySrcLoc, |
| 8769 | ty: Type, | 9154 | ty: Type, |
| 8770 | ) CompileError!void { | 9155 | ) CompileError!void { |
| 8771 | switch (ty.zigTypeTag()) { | 9156 | switch (ty.zigTypeTag()) { |
| 8772 | .ComptimeFloat, .Float => {}, | 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 | ty, | 9159 | ty, |
| 8775 | }), | 9160 | }), |
| 8776 | } | 9161 | } |
| ... | @@ -8778,7 +9163,7 @@ fn checkFloatType( | ... | @@ -8778,7 +9163,7 @@ fn checkFloatType( |
| 8778 | | 9163 | |
| 8779 | fn checkAtomicOperandType( | 9164 | fn checkAtomicOperandType( |
| 8780 | sema: *Sema, | 9165 | sema: *Sema, |
| 8781 | block: *Scope.Block, | 9166 | block: *Block, |
| 8782 | ty_src: LazySrcLoc, | 9167 | ty_src: LazySrcLoc, |
| 8783 | ty: Type, | 9168 | ty: Type, |
| 8784 | ) CompileError!void { | 9169 | ) CompileError!void { |
| ... | @@ -8791,8 +9176,8 @@ fn checkAtomicOperandType( | ... | @@ -8791,8 +9176,8 @@ fn checkAtomicOperandType( |
| 8791 | .Float => { | 9176 | .Float => { |
| 8792 | const bit_count = ty.floatBits(target); | 9177 | const bit_count = ty.floatBits(target); |
| 8793 | if (bit_count > max_atomic_bits) { | 9178 | if (bit_count > max_atomic_bits) { |
| 8794 | return sema.mod.fail( | 9179 | return sema.fail( |
| 8795 | &block.base, | 9180 | block, |
| 8796 | ty_src, | 9181 | ty_src, |
| 8797 | "expected {d}-bit float type or smaller; found {d}-bit float type", | 9182 | "expected {d}-bit float type or smaller; found {d}-bit float type", |
| 8798 | .{ max_atomic_bits, bit_count }, | 9183 | .{ max_atomic_bits, bit_count }, |
| ... | @@ -8804,8 +9189,8 @@ fn checkAtomicOperandType( | ... | @@ -8804,8 +9189,8 @@ fn checkAtomicOperandType( |
| 8804 | else => { | 9189 | else => { |
| 8805 | if (ty.isPtrAtRuntime()) return; | 9190 | if (ty.isPtrAtRuntime()) return; |
| 8806 | | 9191 | |
| 8807 | return sema.mod.fail( | 9192 | return sema.fail( |
| 8808 | &block.base, | 9193 | block, |
| 8809 | ty_src, | 9194 | ty_src, |
| 8810 | "expected bool, integer, float, enum, or pointer type; found {}", | 9195 | "expected bool, integer, float, enum, or pointer type; found {}", |
| 8811 | .{ty}, | 9196 | .{ty}, |
| ... | @@ -8814,8 +9199,8 @@ fn checkAtomicOperandType( | ... | @@ -8814,8 +9199,8 @@ fn checkAtomicOperandType( |
| 8814 | }; | 9199 | }; |
| 8815 | const bit_count = int_ty.intInfo(target).bits; | 9200 | const bit_count = int_ty.intInfo(target).bits; |
| 8816 | if (bit_count > max_atomic_bits) { | 9201 | if (bit_count > max_atomic_bits) { |
| 8817 | return sema.mod.fail( | 9202 | return sema.fail( |
| 8818 | &block.base, | 9203 | block, |
| 8819 | ty_src, | 9204 | ty_src, |
| 8820 | "expected {d}-bit integer type or smaller; found {d}-bit integer type", | 9205 | "expected {d}-bit integer type or smaller; found {d}-bit integer type", |
| 8821 | .{ max_atomic_bits, bit_count }, | 9206 | .{ max_atomic_bits, bit_count }, |
| ... | @@ -8825,7 +9210,7 @@ fn checkAtomicOperandType( | ... | @@ -8825,7 +9210,7 @@ fn checkAtomicOperandType( |
| 8825 | | 9210 | |
| 8826 | fn resolveExportOptions( | 9211 | fn resolveExportOptions( |
| 8827 | sema: *Sema, | 9212 | sema: *Sema, |
| 8828 | block: *Scope.Block, | 9213 | block: *Block, |
| 8829 | src: LazySrcLoc, | 9214 | src: LazySrcLoc, |
| 8830 | zir_ref: Zir.Inst.Ref, | 9215 | zir_ref: Zir.Inst.Ref, |
| 8831 | ) CompileError!std.builtin.ExportOptions { | 9216 | ) CompileError!std.builtin.ExportOptions { |
| ... | @@ -8839,7 +9224,7 @@ fn resolveExportOptions( | ... | @@ -8839,7 +9224,7 @@ fn resolveExportOptions( |
| 8839 | const linkage_index = struct_obj.fields.getIndex("linkage").?; | 9224 | const linkage_index = struct_obj.fields.getIndex("linkage").?; |
| 8840 | const section_index = struct_obj.fields.getIndex("section").?; | 9225 | const section_index = struct_obj.fields.getIndex("section").?; |
| 8841 | if (!fields[section_index].isNull()) { | 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 | return std.builtin.ExportOptions{ | 9229 | return std.builtin.ExportOptions{ |
| 8845 | .name = try fields[name_index].toAllocatedBytes(sema.arena), | 9230 | .name = try fields[name_index].toAllocatedBytes(sema.arena), |
| ... | @@ -8850,7 +9235,7 @@ fn resolveExportOptions( | ... | @@ -8850,7 +9235,7 @@ fn resolveExportOptions( |
| 8850 | | 9235 | |
| 8851 | fn resolveAtomicOrder( | 9236 | fn resolveAtomicOrder( |
| 8852 | sema: *Sema, | 9237 | sema: *Sema, |
| 8853 | block: *Scope.Block, | 9238 | block: *Block, |
| 8854 | src: LazySrcLoc, | 9239 | src: LazySrcLoc, |
| 8855 | zir_ref: Zir.Inst.Ref, | 9240 | zir_ref: Zir.Inst.Ref, |
| 8856 | ) CompileError!std.builtin.AtomicOrder { | 9241 | ) CompileError!std.builtin.AtomicOrder { |
| ... | @@ -8863,7 +9248,7 @@ fn resolveAtomicOrder( | ... | @@ -8863,7 +9248,7 @@ fn resolveAtomicOrder( |
| 8863 | | 9248 | |
| 8864 | fn resolveAtomicRmwOp( | 9249 | fn resolveAtomicRmwOp( |
| 8865 | sema: *Sema, | 9250 | sema: *Sema, |
| 8866 | block: *Scope.Block, | 9251 | block: *Block, |
| 8867 | src: LazySrcLoc, | 9252 | src: LazySrcLoc, |
| 8868 | zir_ref: Zir.Inst.Ref, | 9253 | zir_ref: Zir.Inst.Ref, |
| 8869 | ) CompileError!std.builtin.AtomicRmwOp { | 9254 | ) CompileError!std.builtin.AtomicRmwOp { |
| ... | @@ -8876,11 +9261,10 @@ fn resolveAtomicRmwOp( | ... | @@ -8876,11 +9261,10 @@ fn resolveAtomicRmwOp( |
| 8876 | | 9261 | |
| 8877 | fn zirCmpxchg( | 9262 | fn zirCmpxchg( |
| 8878 | sema: *Sema, | 9263 | sema: *Sema, |
| 8879 | block: *Scope.Block, | 9264 | block: *Block, |
| 8880 | inst: Zir.Inst.Index, | 9265 | inst: Zir.Inst.Index, |
| 8881 | air_tag: Air.Inst.Tag, | 9266 | air_tag: Air.Inst.Tag, |
| 8882 | ) CompileError!Air.Inst.Ref { | 9267 | ) CompileError!Air.Inst.Ref { |
| 8883 | const mod = sema.mod; | | |
| 8884 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9268 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8885 | const extra = sema.code.extraData(Zir.Inst.Cmpxchg, inst_data.payload_index).data; | 9269 | const extra = sema.code.extraData(Zir.Inst.Cmpxchg, inst_data.payload_index).data; |
| 8886 | const src = inst_data.src(); | 9270 | const src = inst_data.src(); |
| ... | @@ -8896,8 +9280,8 @@ fn zirCmpxchg( | ... | @@ -8896,8 +9280,8 @@ fn zirCmpxchg( |
| 8896 | const elem_ty = sema.typeOf(ptr).elemType(); | 9280 | const elem_ty = sema.typeOf(ptr).elemType(); |
| 8897 | try sema.checkAtomicOperandType(block, elem_ty_src, elem_ty); | 9281 | try sema.checkAtomicOperandType(block, elem_ty_src, elem_ty); |
| 8898 | if (elem_ty.zigTypeTag() == .Float) { | 9282 | if (elem_ty.zigTypeTag() == .Float) { |
| 8899 | return mod.fail( | 9283 | return sema.fail( |
| 8900 | &block.base, | 9284 | block, |
| 8901 | elem_ty_src, | 9285 | elem_ty_src, |
| 8902 | "expected bool, integer, enum, or pointer type; found '{}'", | 9286 | "expected bool, integer, enum, or pointer type; found '{}'", |
| 8903 | .{elem_ty}, | 9287 | .{elem_ty}, |
| ... | @@ -8909,16 +9293,16 @@ fn zirCmpxchg( | ... | @@ -8909,16 +9293,16 @@ fn zirCmpxchg( |
| 8909 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order); | 9293 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order); |
| 8910 | | 9294 | |
| 8911 | if (@enumToInt(success_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { | 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 | if (@enumToInt(failure_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { | 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 | if (@enumToInt(failure_order) > @enumToInt(success_order)) { | 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 | if (failure_order == .Release or failure_order == .AcqRel) { | 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 | const result_ty = try Module.optionalType(sema.arena, elem_ty); | 9308 | const result_ty = try Module.optionalType(sema.arena, elem_ty); |
| ... | @@ -8965,31 +9349,31 @@ fn zirCmpxchg( | ... | @@ -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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9353 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8970 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9359 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8976 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9365 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8982 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9371 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8988 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9377 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8994 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 9378 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8995 | // zig fmt: off | 9379 | // zig fmt: off |
| ... | @@ -9004,8 +9388,8 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile | ... | @@ -9004,8 +9388,8 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 9004 | | 9388 | |
| 9005 | switch (order) { | 9389 | switch (order) { |
| 9006 | .Release, .AcqRel => { | 9390 | .Release, .AcqRel => { |
| 9007 | return sema.mod.fail( | 9391 | return sema.fail( |
| 9008 | &block.base, | 9392 | block, |
| 9009 | order_src, | 9393 | order_src, |
| 9010 | "@atomicLoad atomic ordering must not be Release or AcqRel", | 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,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 { | 9421 | fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9038 | const mod = sema.mod; | | |
| 9039 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9422 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9040 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; | 9423 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 9041 | const src = inst_data.src(); | 9424 | const src = inst_data.src(); |
| ... | @@ -9053,14 +9436,14 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -9053,14 +9436,14 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9053 | | 9436 | |
| 9054 | switch (operand_ty.zigTypeTag()) { | 9437 | switch (operand_ty.zigTypeTag()) { |
| 9055 | .Enum => if (op != .Xchg) { | 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 | .Bool => if (op != .Xchg) { | 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 | .Float => switch (op) { | 9444 | .Float => switch (op) { |
| 9062 | .Xchg, .Add, .Sub => {}, | 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 | else => {}, | 9448 | else => {}, |
| 9066 | } | 9449 | } |
| ... | @@ -9068,7 +9451,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -9068,7 +9451,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9068 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); | 9451 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); |
| 9069 | | 9452 | |
| 9070 | if (order == .Unordered) { | 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 | // special case zero bit types | 9457 | // special case zero bit types |
| ... | @@ -9113,7 +9496,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9500 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9118 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; | 9501 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 9119 | const src = inst_data.src(); | 9502 | const src = inst_data.src(); |
| ... | @@ -9131,8 +9514,8 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -9131,8 +9514,8 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9131 | | 9514 | |
| 9132 | const air_tag: Air.Inst.Tag = switch (order) { | 9515 | const air_tag: Air.Inst.Tag = switch (order) { |
| 9133 | .Acquire, .AcqRel => { | 9516 | .Acquire, .AcqRel => { |
| 9134 | return sema.mod.fail( | 9517 | return sema.fail( |
| 9135 | &block.base, | 9518 | block, |
| 9136 | order_src, | 9519 | order_src, |
| 9137 | "@atomicStore atomic ordering must not be Acquire or AcqRel", | 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,37 +9530,37 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9147 | return sema.storePtr2(block, src, ptr, ptr_src, operand, operand_src, air_tag); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9534 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9152 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9540 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9158 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9546 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9164 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9552 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9170 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9558 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9176 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9564 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9182 | const extra = sema.code.extraData(Zir.Inst.Memcpy, inst_data.payload_index).data; | 9565 | const extra = sema.code.extraData(Zir.Inst.Memcpy, inst_data.payload_index).data; |
| 9183 | const src = inst_data.src(); | 9566 | const src = inst_data.src(); |
| ... | @@ -9188,16 +9571,16 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -9188,16 +9571,16 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9188 | const dest_ptr_ty = sema.typeOf(dest_ptr); | 9571 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9189 | | 9572 | |
| 9190 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { | 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 | if (dest_ptr_ty.isConstPtr()) { | 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 | const uncasted_src_ptr = sema.resolveInst(extra.source); | 9580 | const uncasted_src_ptr = sema.resolveInst(extra.source); |
| 9198 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); | 9581 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); |
| 9199 | if (uncasted_src_ptr_ty.zigTypeTag() != .Pointer) { | 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 | uncasted_src_ptr_ty, | 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,7 +9607,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9224 | _ = dest_ptr_val; | 9607 | _ = dest_ptr_val; |
| 9225 | _ = src_ptr_val; | 9608 | _ = src_ptr_val; |
| 9226 | _ = len_val; | 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 | } else break :rs len_src; | 9611 | } else break :rs len_src; |
| 9229 | } else break :rs src_src; | 9612 | } else break :rs src_src; |
| 9230 | } else dest_src; | 9613 | } else dest_src; |
| ... | @@ -9242,7 +9625,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9629 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9247 | const extra = sema.code.extraData(Zir.Inst.Memset, inst_data.payload_index).data; | 9630 | const extra = sema.code.extraData(Zir.Inst.Memset, inst_data.payload_index).data; |
| 9248 | const src = inst_data.src(); | 9631 | const src = inst_data.src(); |
| ... | @@ -9252,10 +9635,10 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -9252,10 +9635,10 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9252 | const dest_ptr = sema.resolveInst(extra.dest); | 9635 | const dest_ptr = sema.resolveInst(extra.dest); |
| 9253 | const dest_ptr_ty = sema.typeOf(dest_ptr); | 9636 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9254 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { | 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 | if (dest_ptr_ty.isConstPtr()) { | 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 | const elem_ty = dest_ptr_ty.elemType2(); | 9643 | const elem_ty = dest_ptr_ty.elemType2(); |
| 9261 | const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src); | 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,7 +9653,7 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9270 | _ = ptr_val; | 9653 | _ = ptr_val; |
| 9271 | _ = len_val; | 9654 | _ = len_val; |
| 9272 | _ = val; | 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 | } else break :rs value_src; | 9657 | } else break :rs value_src; |
| 9275 | } else break :rs len_src; | 9658 | } else break :rs len_src; |
| 9276 | } else dest_src; | 9659 | } else dest_src; |
| ... | @@ -9288,27 +9671,27 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9675 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9293 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9681 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9299 | const src = inst_data.src(); | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9687 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9305 | const src = inst_data.src(); | 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 | fn zirAwait( | 9692 | fn zirAwait( |
| 9310 | sema: *Sema, | 9693 | sema: *Sema, |
| 9311 | block: *Scope.Block, | 9694 | block: *Block, |
| 9312 | inst: Zir.Inst.Index, | 9695 | inst: Zir.Inst.Index, |
| 9313 | is_nosuspend: bool, | 9696 | is_nosuspend: bool, |
| 9314 | ) CompileError!Air.Inst.Ref { | 9697 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -9316,12 +9699,12 @@ fn zirAwait( | ... | @@ -9316,12 +9699,12 @@ fn zirAwait( |
| 9316 | const src = inst_data.src(); | 9699 | const src = inst_data.src(); |
| 9317 | | 9700 | |
| 9318 | _ = is_nosuspend; | 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 | fn zirVarExtended( | 9705 | fn zirVarExtended( |
| 9323 | sema: *Sema, | 9706 | sema: *Sema, |
| 9324 | block: *Scope.Block, | 9707 | block: *Block, |
| 9325 | extended: Zir.Inst.Extended.InstData, | 9708 | extended: Zir.Inst.Extended.InstData, |
| 9326 | ) CompileError!Air.Inst.Ref { | 9709 | ) CompileError!Air.Inst.Ref { |
| 9327 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); | 9710 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| ... | @@ -9376,7 +9759,7 @@ fn zirVarExtended( | ... | @@ -9376,7 +9759,7 @@ fn zirVarExtended( |
| 9376 | if (lib_name != null) { | 9759 | if (lib_name != null) { |
| 9377 | // Look at the sema code for functions which has this logic, it just needs to | 9760 | // Look at the sema code for functions which has this logic, it just needs to |
| 9378 | // be extracted and shared by both var and func | 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 | const new_var = try sema.gpa.create(Module.Var); | 9765 | const new_var = try sema.gpa.create(Module.Var); |
| ... | @@ -9396,7 +9779,7 @@ fn zirVarExtended( | ... | @@ -9396,7 +9779,7 @@ fn zirVarExtended( |
| 9396 | | 9779 | |
| 9397 | fn zirFuncExtended( | 9780 | fn zirFuncExtended( |
| 9398 | sema: *Sema, | 9781 | sema: *Sema, |
| 9399 | block: *Scope.Block, | 9782 | block: *Block, |
| 9400 | extended: Zir.Inst.Extended.InstData, | 9783 | extended: Zir.Inst.Extended.InstData, |
| 9401 | inst: Zir.Inst.Index, | 9784 | inst: Zir.Inst.Index, |
| 9402 | ) CompileError!Air.Inst.Ref { | 9785 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -9463,7 +9846,7 @@ fn zirFuncExtended( | ... | @@ -9463,7 +9846,7 @@ fn zirFuncExtended( |
| 9463 | | 9846 | |
| 9464 | fn zirCUndef( | 9847 | fn zirCUndef( |
| 9465 | sema: *Sema, | 9848 | sema: *Sema, |
| 9466 | block: *Scope.Block, | 9849 | block: *Block, |
| 9467 | extended: Zir.Inst.Extended.InstData, | 9850 | extended: Zir.Inst.Extended.InstData, |
| 9468 | ) CompileError!Air.Inst.Ref { | 9851 | ) CompileError!Air.Inst.Ref { |
| 9469 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 9852 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | @@ -9476,7 +9859,7 @@ fn zirCUndef( | ... | @@ -9476,7 +9859,7 @@ fn zirCUndef( |
| 9476 | | 9859 | |
| 9477 | fn zirCInclude( | 9860 | fn zirCInclude( |
| 9478 | sema: *Sema, | 9861 | sema: *Sema, |
| 9479 | block: *Scope.Block, | 9862 | block: *Block, |
| 9480 | extended: Zir.Inst.Extended.InstData, | 9863 | extended: Zir.Inst.Extended.InstData, |
| 9481 | ) CompileError!Air.Inst.Ref { | 9864 | ) CompileError!Air.Inst.Ref { |
| 9482 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 9865 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | @@ -9489,7 +9872,7 @@ fn zirCInclude( | ... | @@ -9489,7 +9872,7 @@ fn zirCInclude( |
| 9489 | | 9872 | |
| 9490 | fn zirCDefine( | 9873 | fn zirCDefine( |
| 9491 | sema: *Sema, | 9874 | sema: *Sema, |
| 9492 | block: *Scope.Block, | 9875 | block: *Block, |
| 9493 | extended: Zir.Inst.Extended.InstData, | 9876 | extended: Zir.Inst.Extended.InstData, |
| 9494 | ) CompileError!Air.Inst.Ref { | 9877 | ) CompileError!Air.Inst.Ref { |
| 9495 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 9878 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| ... | @@ -9507,41 +9890,41 @@ fn zirCDefine( | ... | @@ -9507,41 +9890,41 @@ fn zirCDefine( |
| 9507 | | 9890 | |
| 9508 | fn zirWasmMemorySize( | 9891 | fn zirWasmMemorySize( |
| 9509 | sema: *Sema, | 9892 | sema: *Sema, |
| 9510 | block: *Scope.Block, | 9893 | block: *Block, |
| 9511 | extended: Zir.Inst.Extended.InstData, | 9894 | extended: Zir.Inst.Extended.InstData, |
| 9512 | ) CompileError!Air.Inst.Ref { | 9895 | ) CompileError!Air.Inst.Ref { |
| 9513 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 9896 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 9514 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | fn zirWasmMemoryGrow( | 9901 | fn zirWasmMemoryGrow( |
| 9519 | sema: *Sema, | 9902 | sema: *Sema, |
| 9520 | block: *Scope.Block, | 9903 | block: *Block, |
| 9521 | extended: Zir.Inst.Extended.InstData, | 9904 | extended: Zir.Inst.Extended.InstData, |
| 9522 | ) CompileError!Air.Inst.Ref { | 9905 | ) CompileError!Air.Inst.Ref { |
| 9523 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 9906 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9524 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | fn zirBuiltinExtern( | 9911 | fn zirBuiltinExtern( |
| 9529 | sema: *Sema, | 9912 | sema: *Sema, |
| 9530 | block: *Scope.Block, | 9913 | block: *Block, |
| 9531 | extended: Zir.Inst.Extended.InstData, | 9914 | extended: Zir.Inst.Extended.InstData, |
| 9532 | ) CompileError!Air.Inst.Ref { | 9915 | ) CompileError!Air.Inst.Ref { |
| 9533 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 9916 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9534 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | if (sema.func == null) { | 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 | if (block.is_comptime) { | 9928 | if (block.is_comptime) { |
| 9546 | return sema.failWithNeededComptime(block, src); | 9929 | return sema.failWithNeededComptime(block, src); |
| 9547 | } | 9930 | } |
| ... | @@ -9551,7 +9934,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void | ... | @@ -9551,7 +9934,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void |
| 9551 | /// Emit a compile error if type cannot be used for a runtime variable. | 9934 | /// Emit a compile error if type cannot be used for a runtime variable. |
| 9552 | fn validateVarType( | 9935 | fn validateVarType( |
| 9553 | sema: *Sema, | 9936 | sema: *Sema, |
| 9554 | block: *Scope.Block, | 9937 | block: *Block, |
| 9555 | src: LazySrcLoc, | 9938 | src: LazySrcLoc, |
| 9556 | var_ty: Type, | 9939 | var_ty: Type, |
| 9557 | is_extern: bool, | 9940 | is_extern: bool, |
| ... | @@ -9595,7 +9978,7 @@ fn validateVarType( | ... | @@ -9595,7 +9978,7 @@ fn validateVarType( |
| 9595 | }, | 9978 | }, |
| 9596 | } else unreachable; // TODO should not need else unreachable | 9979 | } else unreachable; // TODO should not need else unreachable |
| 9597 | if (!ok) { | 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,17 +9993,18 @@ pub const PanicId = enum { |
| 9610 | | 9993 | |
| 9611 | fn addSafetyCheck( | 9994 | fn addSafetyCheck( |
| 9612 | sema: *Sema, | 9995 | sema: *Sema, |
| 9613 | parent_block: *Scope.Block, | 9996 | parent_block: *Block, |
| 9614 | ok: Air.Inst.Ref, | 9997 | ok: Air.Inst.Ref, |
| 9615 | panic_id: PanicId, | 9998 | panic_id: PanicId, |
| 9616 | ) !void { | 9999 | ) !void { |
| 9617 | const gpa = sema.gpa; | 10000 | const gpa = sema.gpa; |
| 9618 | | 10001 | |
| 9619 | var fail_block: Scope.Block = .{ | 10002 | var fail_block: Block = .{ |
| 9620 | .parent = parent_block, | 10003 | .parent = parent_block, |
| 9621 | .sema = sema, | 10004 | .sema = sema, |
| 9622 | .wip_capture_scope = parent_block.wip_capture_scope, | | |
| 9623 | .src_decl = parent_block.src_decl, | 10005 | .src_decl = parent_block.src_decl, |
| | 10006 | .namespace = parent_block.namespace, |
| | 10007 | .wip_capture_scope = parent_block.wip_capture_scope, |
| 9624 | .instructions = .{}, | 10008 | .instructions = .{}, |
| 9625 | .inlining = parent_block.inlining, | 10009 | .inlining = parent_block.inlining, |
| 9626 | .is_comptime = parent_block.is_comptime, | 10010 | .is_comptime = parent_block.is_comptime, |
| ... | @@ -9679,7 +10063,7 @@ fn addSafetyCheck( | ... | @@ -9679,7 +10063,7 @@ fn addSafetyCheck( |
| 9679 | | 10063 | |
| 9680 | fn panicWithMsg( | 10064 | fn panicWithMsg( |
| 9681 | sema: *Sema, | 10065 | sema: *Sema, |
| 9682 | block: *Scope.Block, | 10066 | block: *Block, |
| 9683 | src: LazySrcLoc, | 10067 | src: LazySrcLoc, |
| 9684 | msg_inst: Air.Inst.Ref, | 10068 | msg_inst: Air.Inst.Ref, |
| 9685 | ) !Zir.Inst.Index { | 10069 | ) !Zir.Inst.Index { |
| ... | @@ -9699,7 +10083,7 @@ fn panicWithMsg( | ... | @@ -9699,7 +10083,7 @@ fn panicWithMsg( |
| 9699 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 10083 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 9700 | const ptr_stack_trace_ty = try Type.ptr(arena, .{ | 10084 | const ptr_stack_trace_ty = try Type.ptr(arena, .{ |
| 9701 | .pointee_type = stack_trace_ty, | 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 | const null_stack_trace = try sema.addConstant( | 10088 | const null_stack_trace = try sema.addConstant( |
| 9705 | try Module.optionalType(arena, ptr_stack_trace_ty), | 10089 | try Module.optionalType(arena, ptr_stack_trace_ty), |
| ... | @@ -9713,7 +10097,7 @@ fn panicWithMsg( | ... | @@ -9713,7 +10097,7 @@ fn panicWithMsg( |
| 9713 | | 10097 | |
| 9714 | fn safetyPanic( | 10098 | fn safetyPanic( |
| 9715 | sema: *Sema, | 10099 | sema: *Sema, |
| 9716 | block: *Scope.Block, | 10100 | block: *Block, |
| 9717 | src: LazySrcLoc, | 10101 | src: LazySrcLoc, |
| 9718 | panic_id: PanicId, | 10102 | panic_id: PanicId, |
| 9719 | ) CompileError!Zir.Inst.Index { | 10103 | ) CompileError!Zir.Inst.Index { |
| ... | @@ -9741,17 +10125,17 @@ fn safetyPanic( | ... | @@ -9741,17 +10125,17 @@ fn safetyPanic( |
| 9741 | return sema.panicWithMsg(block, src, casted_msg_inst); | 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 | sema.branch_count += 1; | 10129 | sema.branch_count += 1; |
| 9746 | if (sema.branch_count > sema.branch_quota) { | 10130 | if (sema.branch_count > sema.branch_quota) { |
| 9747 | // TODO show the "called from here" stack | 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 | fn fieldVal( | 10136 | fn fieldVal( |
| 9753 | sema: *Sema, | 10137 | sema: *Sema, |
| 9754 | block: *Scope.Block, | 10138 | block: *Block, |
| 9755 | src: LazySrcLoc, | 10139 | src: LazySrcLoc, |
| 9756 | object: Air.Inst.Ref, | 10140 | object: Air.Inst.Ref, |
| 9757 | field_name: []const u8, | 10141 | field_name: []const u8, |
| ... | @@ -9760,7 +10144,6 @@ fn fieldVal( | ... | @@ -9760,7 +10144,6 @@ fn fieldVal( |
| 9760 | // When editing this function, note that there is corresponding logic to be edited | 10144 | // When editing this function, note that there is corresponding logic to be edited |
| 9761 | // in `fieldPtr`. This function takes a value and returns a value. | 10145 | // in `fieldPtr`. This function takes a value and returns a value. |
| 9762 | | 10146 | |
| 9763 | const mod = sema.mod; | | |
| 9764 | const arena = sema.arena; | 10147 | const arena = sema.arena; |
| 9765 | const object_src = src; // TODO better source location | 10148 | const object_src = src; // TODO better source location |
| 9766 | const object_ty = sema.typeOf(object); | 10149 | const object_ty = sema.typeOf(object); |
| ... | @@ -9773,8 +10156,8 @@ fn fieldVal( | ... | @@ -9773,8 +10156,8 @@ fn fieldVal( |
| 9773 | try Value.Tag.int_u64.create(arena, object_ty.arrayLen()), | 10156 | try Value.Tag.int_u64.create(arena, object_ty.arrayLen()), |
| 9774 | ); | 10157 | ); |
| 9775 | } else { | 10158 | } else { |
| 9776 | return mod.fail( | 10159 | return sema.fail( |
| 9777 | &block.base, | 10160 | block, |
| 9778 | field_name_src, | 10161 | field_name_src, |
| 9779 | "no member named '{s}' in '{}'", | 10162 | "no member named '{s}' in '{}'", |
| 9780 | .{ field_name, object_ty }, | 10163 | .{ field_name, object_ty }, |
| ... | @@ -9788,8 +10171,8 @@ fn fieldVal( | ... | @@ -9788,8 +10171,8 @@ fn fieldVal( |
| 9788 | const result_ty = object_ty.slicePtrFieldType(buf); | 10171 | const result_ty = object_ty.slicePtrFieldType(buf); |
| 9789 | if (try sema.resolveMaybeUndefVal(block, object_src, object)) |val| { | 10172 | if (try sema.resolveMaybeUndefVal(block, object_src, object)) |val| { |
| 9790 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 10173 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 9791 | return mod.fail( | 10174 | return sema.fail( |
| 9792 | &block.base, | 10175 | block, |
| 9793 | field_name_src, | 10176 | field_name_src, |
| 9794 | "TODO implement comptime slice ptr", | 10177 | "TODO implement comptime slice ptr", |
| 9795 | .{}, | 10178 | .{}, |
| ... | @@ -9809,8 +10192,8 @@ fn fieldVal( | ... | @@ -9809,8 +10192,8 @@ fn fieldVal( |
| 9809 | try sema.requireRuntimeBlock(block, src); | 10192 | try sema.requireRuntimeBlock(block, src); |
| 9810 | return block.addTyOp(.slice_len, result_ty, object); | 10193 | return block.addTyOp(.slice_len, result_ty, object); |
| 9811 | } else { | 10194 | } else { |
| 9812 | return mod.fail( | 10195 | return sema.fail( |
| 9813 | &block.base, | 10196 | block, |
| 9814 | field_name_src, | 10197 | field_name_src, |
| 9815 | "no member named '{s}' in '{}'", | 10198 | "no member named '{s}' in '{}'", |
| 9816 | .{ field_name, object_ty }, | 10199 | .{ field_name, object_ty }, |
| ... | @@ -9827,8 +10210,8 @@ fn fieldVal( | ... | @@ -9827,8 +10210,8 @@ fn fieldVal( |
| 9827 | try Value.Tag.int_u64.create(arena, ptr_child.arrayLen()), | 10210 | try Value.Tag.int_u64.create(arena, ptr_child.arrayLen()), |
| 9828 | ); | 10211 | ); |
| 9829 | } else { | 10212 | } else { |
| 9830 | return mod.fail( | 10213 | return sema.fail( |
| 9831 | &block.base, | 10214 | block, |
| 9832 | field_name_src, | 10215 | field_name_src, |
| 9833 | "no member named '{s}' in '{}'", | 10216 | "no member named '{s}' in '{}'", |
| 9834 | .{ field_name, object_ty }, | 10217 | .{ field_name, object_ty }, |
| ... | @@ -9865,10 +10248,10 @@ fn fieldVal( | ... | @@ -9865,10 +10248,10 @@ fn fieldVal( |
| 9865 | break :blk name; | 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 | field_name, child_type, | 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 | return sema.addConstant( | 10256 | return sema.addConstant( |
| 9874 | try child_type.copy(arena), | 10257 | try child_type.copy(arena), |
| ... | @@ -9888,7 +10271,7 @@ fn fieldVal( | ... | @@ -9888,7 +10271,7 @@ fn fieldVal( |
| 9888 | .Union => "union", | 10271 | .Union => "union", |
| 9889 | else => unreachable, | 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 | kw_name, child_type, field_name, | 10275 | kw_name, child_type, field_name, |
| 9893 | }); | 10276 | }); |
| 9894 | }, | 10277 | }, |
| ... | @@ -9900,14 +10283,14 @@ fn fieldVal( | ... | @@ -9900,14 +10283,14 @@ fn fieldVal( |
| 9900 | } | 10283 | } |
| 9901 | const field_index = child_type.enumFieldIndex(field_name) orelse { | 10284 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 9902 | const msg = msg: { | 10285 | const msg = msg: { |
| 9903 | const msg = try mod.errMsg( | 10286 | const msg = try sema.errMsg( |
| 9904 | &block.base, | 10287 | block, |
| 9905 | src, | 10288 | src, |
| 9906 | "enum '{}' has no member named '{s}'", | 10289 | "enum '{}' has no member named '{s}'", |
| 9907 | .{ child_type, field_name }, | 10290 | .{ child_type, field_name }, |
| 9908 | ); | 10291 | ); |
| 9909 | errdefer msg.destroy(sema.gpa); | 10292 | errdefer msg.destroy(sema.gpa); |
| 9910 | try mod.errNoteNonLazy( | 10293 | try sema.mod.errNoteNonLazy( |
| 9911 | child_type.declSrcLoc(), | 10294 | child_type.declSrcLoc(), |
| 9912 | msg, | 10295 | msg, |
| 9913 | "enum declared here", | 10296 | "enum declared here", |
| ... | @@ -9915,25 +10298,25 @@ fn fieldVal( | ... | @@ -9915,25 +10298,25 @@ fn fieldVal( |
| 9915 | ); | 10298 | ); |
| 9916 | break :msg msg; | 10299 | break :msg msg; |
| 9917 | }; | 10300 | }; |
| 9918 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 10301 | return sema.failWithOwnedErrorMsg(msg); |
| 9919 | }; | 10302 | }; |
| 9920 | const field_index_u32 = @intCast(u32, field_index); | 10303 | const field_index_u32 = @intCast(u32, field_index); |
| 9921 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32); | 10304 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32); |
| 9922 | return sema.addConstant(try child_type.copy(arena), enum_val); | 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 | .Struct => return sema.structFieldVal(block, src, object, field_name, field_name_src, object_ty), | 10310 | .Struct => return sema.structFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9928 | .Union => return sema.unionFieldVal(block, src, object, field_name, field_name_src, object_ty), | 10311 | .Union => return sema.unionFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9929 | else => {}, | 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 | fn fieldPtr( | 10317 | fn fieldPtr( |
| 9935 | sema: *Sema, | 10318 | sema: *Sema, |
| 9936 | block: *Scope.Block, | 10319 | block: *Block, |
| 9937 | src: LazySrcLoc, | 10320 | src: LazySrcLoc, |
| 9938 | object_ptr: Air.Inst.Ref, | 10321 | object_ptr: Air.Inst.Ref, |
| 9939 | field_name: []const u8, | 10322 | field_name: []const u8, |
| ... | @@ -9942,12 +10325,11 @@ fn fieldPtr( | ... | @@ -9942,12 +10325,11 @@ fn fieldPtr( |
| 9942 | // When editing this function, note that there is corresponding logic to be edited | 10325 | // When editing this function, note that there is corresponding logic to be edited |
| 9943 | // in `fieldVal`. This function takes a pointer and returns a pointer. | 10326 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 9944 | | 10327 | |
| 9945 | const mod = sema.mod; | | |
| 9946 | const object_ptr_src = src; // TODO better source location | 10328 | const object_ptr_src = src; // TODO better source location |
| 9947 | const object_ptr_ty = sema.typeOf(object_ptr); | 10329 | const object_ptr_ty = sema.typeOf(object_ptr); |
| 9948 | const object_ty = switch (object_ptr_ty.zigTypeTag()) { | 10330 | const object_ty = switch (object_ptr_ty.zigTypeTag()) { |
| 9949 | .Pointer => object_ptr_ty.elemType(), | 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 | switch (object_ty.zigTypeTag()) { | 10334 | switch (object_ty.zigTypeTag()) { |
| 9953 | .Array => { | 10335 | .Array => { |
| ... | @@ -9959,8 +10341,8 @@ fn fieldPtr( | ... | @@ -9959,8 +10341,8 @@ fn fieldPtr( |
| 9959 | try Value.Tag.int_u64.create(anon_decl.arena(), object_ty.arrayLen()), | 10341 | try Value.Tag.int_u64.create(anon_decl.arena(), object_ty.arrayLen()), |
| 9960 | )); | 10342 | )); |
| 9961 | } else { | 10343 | } else { |
| 9962 | return mod.fail( | 10344 | return sema.fail( |
| 9963 | &block.base, | 10345 | block, |
| 9964 | field_name_src, | 10346 | field_name_src, |
| 9965 | "no member named '{s}' in '{}'", | 10347 | "no member named '{s}' in '{}'", |
| 9966 | .{ field_name, object_ty }, | 10348 | .{ field_name, object_ty }, |
| ... | @@ -9977,22 +10359,22 @@ fn fieldPtr( | ... | @@ -9977,22 +10359,22 @@ fn fieldPtr( |
| 9977 | // the runtime value to it, and then return the `alloc`. | 10359 | // the runtime value to it, and then return the `alloc`. |
| 9978 | // In both cases the pointer should be const. | 10360 | // In both cases the pointer should be const. |
| 9979 | if (mem.eql(u8, field_name, "ptr")) { | 10361 | if (mem.eql(u8, field_name, "ptr")) { |
| 9980 | return mod.fail( | 10362 | return sema.fail( |
| 9981 | &block.base, | 10363 | block, |
| 9982 | field_name_src, | 10364 | field_name_src, |
| 9983 | "TODO: implement reference to 'ptr' field of slice '{}'", | 10365 | "TODO: implement reference to 'ptr' field of slice '{}'", |
| 9984 | .{object_ty}, | 10366 | .{object_ty}, |
| 9985 | ); | 10367 | ); |
| 9986 | } else if (mem.eql(u8, field_name, "len")) { | 10368 | } else if (mem.eql(u8, field_name, "len")) { |
| 9987 | return mod.fail( | 10369 | return sema.fail( |
| 9988 | &block.base, | 10370 | block, |
| 9989 | field_name_src, | 10371 | field_name_src, |
| 9990 | "TODO: implement reference to 'len' field of slice '{}'", | 10372 | "TODO: implement reference to 'len' field of slice '{}'", |
| 9991 | .{object_ty}, | 10373 | .{object_ty}, |
| 9992 | ); | 10374 | ); |
| 9993 | } else { | 10375 | } else { |
| 9994 | return mod.fail( | 10376 | return sema.fail( |
| 9995 | &block.base, | 10377 | block, |
| 9996 | field_name_src, | 10378 | field_name_src, |
| 9997 | "no member named '{s}' in '{}'", | 10379 | "no member named '{s}' in '{}'", |
| 9998 | .{ field_name, object_ty }, | 10380 | .{ field_name, object_ty }, |
| ... | @@ -10011,8 +10393,8 @@ fn fieldPtr( | ... | @@ -10011,8 +10393,8 @@ fn fieldPtr( |
| 10011 | try Value.Tag.int_u64.create(anon_decl.arena(), ptr_child.arrayLen()), | 10393 | try Value.Tag.int_u64.create(anon_decl.arena(), ptr_child.arrayLen()), |
| 10012 | )); | 10394 | )); |
| 10013 | } else { | 10395 | } else { |
| 10014 | return mod.fail( | 10396 | return sema.fail( |
| 10015 | &block.base, | 10397 | block, |
| 10016 | field_name_src, | 10398 | field_name_src, |
| 10017 | "no member named '{s}' in '{}'", | 10399 | "no member named '{s}' in '{}'", |
| 10018 | .{ field_name, object_ty }, | 10400 | .{ field_name, object_ty }, |
| ... | @@ -10051,10 +10433,10 @@ fn fieldPtr( | ... | @@ -10051,10 +10433,10 @@ fn fieldPtr( |
| 10051 | break :blk name; | 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 | field_name, child_type, | 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 | var anon_decl = try block.startAnonDecl(); | 10441 | var anon_decl = try block.startAnonDecl(); |
| 10060 | defer anon_decl.deinit(); | 10442 | defer anon_decl.deinit(); |
| ... | @@ -10076,7 +10458,7 @@ fn fieldPtr( | ... | @@ -10076,7 +10458,7 @@ fn fieldPtr( |
| 10076 | .Union => "union", | 10458 | .Union => "union", |
| 10077 | else => unreachable, | 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 | kw_name, child_type, field_name, | 10462 | kw_name, child_type, field_name, |
| 10081 | }); | 10463 | }); |
| 10082 | }, | 10464 | }, |
| ... | @@ -10088,14 +10470,14 @@ fn fieldPtr( | ... | @@ -10088,14 +10470,14 @@ fn fieldPtr( |
| 10088 | } | 10470 | } |
| 10089 | const field_index = child_type.enumFieldIndex(field_name) orelse { | 10471 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 10090 | const msg = msg: { | 10472 | const msg = msg: { |
| 10091 | const msg = try mod.errMsg( | 10473 | const msg = try sema.errMsg( |
| 10092 | &block.base, | 10474 | block, |
| 10093 | src, | 10475 | src, |
| 10094 | "enum '{}' has no member named '{s}'", | 10476 | "enum '{}' has no member named '{s}'", |
| 10095 | .{ child_type, field_name }, | 10477 | .{ child_type, field_name }, |
| 10096 | ); | 10478 | ); |
| 10097 | errdefer msg.destroy(sema.gpa); | 10479 | errdefer msg.destroy(sema.gpa); |
| 10098 | try mod.errNoteNonLazy( | 10480 | try sema.mod.errNoteNonLazy( |
| 10099 | child_type.declSrcLoc(), | 10481 | child_type.declSrcLoc(), |
| 10100 | msg, | 10482 | msg, |
| 10101 | "enum declared here", | 10483 | "enum declared here", |
| ... | @@ -10103,7 +10485,7 @@ fn fieldPtr( | ... | @@ -10103,7 +10485,7 @@ fn fieldPtr( |
| 10103 | ); | 10485 | ); |
| 10104 | break :msg msg; | 10486 | break :msg msg; |
| 10105 | }; | 10487 | }; |
| 10106 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 10488 | return sema.failWithOwnedErrorMsg(msg); |
| 10107 | }; | 10489 | }; |
| 10108 | const field_index_u32 = @intCast(u32, field_index); | 10490 | const field_index_u32 = @intCast(u32, field_index); |
| 10109 | var anon_decl = try block.startAnonDecl(); | 10491 | var anon_decl = try block.startAnonDecl(); |
| ... | @@ -10113,19 +10495,19 @@ fn fieldPtr( | ... | @@ -10113,19 +10495,19 @@ fn fieldPtr( |
| 10113 | try Value.Tag.enum_field_index.create(anon_decl.arena(), field_index_u32), | 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 | .Struct => return sema.structFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), | 10501 | .Struct => return sema.structFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10120 | .Union => return sema.unionFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), | 10502 | .Union => return sema.unionFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10121 | else => {}, | 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 | fn fieldCallBind( | 10508 | fn fieldCallBind( |
| 10127 | sema: *Sema, | 10509 | sema: *Sema, |
| 10128 | block: *Scope.Block, | 10510 | block: *Block, |
| 10129 | src: LazySrcLoc, | 10511 | src: LazySrcLoc, |
| 10130 | raw_ptr: Air.Inst.Ref, | 10512 | raw_ptr: Air.Inst.Ref, |
| 10131 | field_name: []const u8, | 10513 | field_name: []const u8, |
| ... | @@ -10134,13 +10516,12 @@ fn fieldCallBind( | ... | @@ -10134,13 +10516,12 @@ fn fieldCallBind( |
| 10134 | // When editing this function, note that there is corresponding logic to be edited | 10516 | // When editing this function, note that there is corresponding logic to be edited |
| 10135 | // in `fieldVal`. This function takes a pointer and returns a pointer. | 10517 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 10136 | | 10518 | |
| 10137 | const mod = sema.mod; | | |
| 10138 | const raw_ptr_src = src; // TODO better source location | 10519 | const raw_ptr_src = src; // TODO better source location |
| 10139 | const raw_ptr_ty = sema.typeOf(raw_ptr); | 10520 | const raw_ptr_ty = sema.typeOf(raw_ptr); |
| 10140 | const inner_ty = if (raw_ptr_ty.zigTypeTag() == .Pointer and raw_ptr_ty.ptrSize() == .One) | 10521 | const inner_ty = if (raw_ptr_ty.zigTypeTag() == .Pointer and raw_ptr_ty.ptrSize() == .One) |
| 10141 | raw_ptr_ty.childType() | 10522 | raw_ptr_ty.childType() |
| 10142 | else | 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 | // Optionally dereference a second pointer to get the concrete type. | 10526 | // Optionally dereference a second pointer to get the concrete type. |
| 10146 | const is_double_ptr = inner_ty.zigTypeTag() == .Pointer and inner_ty.ptrSize() == .One; | 10527 | const is_double_ptr = inner_ty.zigTypeTag() == .Pointer and inner_ty.ptrSize() == .One; |
| ... | @@ -10209,7 +10590,7 @@ fn fieldCallBind( | ... | @@ -10209,7 +10590,7 @@ fn fieldCallBind( |
| 10209 | }; | 10590 | }; |
| 10210 | return sema.analyzeLoad(block, src, ptr_inst, src); | 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 | .Type => { | 10594 | .Type => { |
| 10214 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); | 10595 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); |
| 10215 | return sema.fieldVal(block, src, namespace, field_name, field_name_src); | 10596 | return sema.fieldVal(block, src, namespace, field_name, field_name_src); |
| ... | @@ -10262,29 +10643,28 @@ fn fieldCallBind( | ... | @@ -10262,29 +10643,28 @@ fn fieldCallBind( |
| 10262 | else => {}, | 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 | fn namespaceLookup( | 10649 | fn namespaceLookup( |
| 10269 | sema: *Sema, | 10650 | sema: *Sema, |
| 10270 | block: *Scope.Block, | 10651 | block: *Block, |
| 10271 | src: LazySrcLoc, | 10652 | src: LazySrcLoc, |
| 10272 | namespace: *Scope.Namespace, | 10653 | namespace: *Namespace, |
| 10273 | decl_name: []const u8, | 10654 | decl_name: []const u8, |
| 10274 | ) CompileError!?*Decl { | 10655 | ) CompileError!?*Decl { |
| 10275 | const mod = sema.mod; | | |
| 10276 | const gpa = sema.gpa; | 10656 | const gpa = sema.gpa; |
| 10277 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { | 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 | const msg = msg: { | 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 | decl_name, | 10661 | decl_name, |
| 10282 | }); | 10662 | }); |
| 10283 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 10665 | break :msg msg; |
| 10286 | }; | 10666 | }; |
| 10287 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 10667 | return sema.failWithOwnedErrorMsg(msg); |
| 10288 | } | 10668 | } |
| 10289 | return decl; | 10669 | return decl; |
| 10290 | } | 10670 | } |
| ... | @@ -10293,9 +10673,9 @@ fn namespaceLookup( | ... | @@ -10293,9 +10673,9 @@ fn namespaceLookup( |
| 10293 | | 10673 | |
| 10294 | fn namespaceLookupRef( | 10674 | fn namespaceLookupRef( |
| 10295 | sema: *Sema, | 10675 | sema: *Sema, |
| 10296 | block: *Scope.Block, | 10676 | block: *Block, |
| 10297 | src: LazySrcLoc, | 10677 | src: LazySrcLoc, |
| 10298 | namespace: *Scope.Namespace, | 10678 | namespace: *Namespace, |
| 10299 | decl_name: []const u8, | 10679 | decl_name: []const u8, |
| 10300 | ) CompileError!?Air.Inst.Ref { | 10680 | ) CompileError!?Air.Inst.Ref { |
| 10301 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; | 10681 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| ... | @@ -10304,7 +10684,7 @@ fn namespaceLookupRef( | ... | @@ -10304,7 +10684,7 @@ fn namespaceLookupRef( |
| 10304 | | 10684 | |
| 10305 | fn structFieldPtr( | 10685 | fn structFieldPtr( |
| 10306 | sema: *Sema, | 10686 | sema: *Sema, |
| 10307 | block: *Scope.Block, | 10687 | block: *Block, |
| 10308 | src: LazySrcLoc, | 10688 | src: LazySrcLoc, |
| 10309 | struct_ptr: Air.Inst.Ref, | 10689 | struct_ptr: Air.Inst.Ref, |
| 10310 | field_name: []const u8, | 10690 | field_name: []const u8, |
| ... | @@ -10344,7 +10724,7 @@ fn structFieldPtr( | ... | @@ -10344,7 +10724,7 @@ fn structFieldPtr( |
| 10344 | | 10724 | |
| 10345 | fn structFieldVal( | 10725 | fn structFieldVal( |
| 10346 | sema: *Sema, | 10726 | sema: *Sema, |
| 10347 | block: *Scope.Block, | 10727 | block: *Block, |
| 10348 | src: LazySrcLoc, | 10728 | src: LazySrcLoc, |
| 10349 | struct_byval: Air.Inst.Ref, | 10729 | struct_byval: Air.Inst.Ref, |
| 10350 | field_name: []const u8, | 10730 | field_name: []const u8, |
| ... | @@ -10382,7 +10762,7 @@ fn structFieldVal( | ... | @@ -10382,7 +10762,7 @@ fn structFieldVal( |
| 10382 | | 10762 | |
| 10383 | fn unionFieldPtr( | 10763 | fn unionFieldPtr( |
| 10384 | sema: *Sema, | 10764 | sema: *Sema, |
| 10385 | block: *Scope.Block, | 10765 | block: *Block, |
| 10386 | src: LazySrcLoc, | 10766 | src: LazySrcLoc, |
| 10387 | union_ptr: Air.Inst.Ref, | 10767 | union_ptr: Air.Inst.Ref, |
| 10388 | field_name: []const u8, | 10768 | field_name: []const u8, |
| ... | @@ -10424,7 +10804,7 @@ fn unionFieldPtr( | ... | @@ -10424,7 +10804,7 @@ fn unionFieldPtr( |
| 10424 | | 10804 | |
| 10425 | fn unionFieldVal( | 10805 | fn unionFieldVal( |
| 10426 | sema: *Sema, | 10806 | sema: *Sema, |
| 10427 | block: *Scope.Block, | 10807 | block: *Block, |
| 10428 | src: LazySrcLoc, | 10808 | src: LazySrcLoc, |
| 10429 | union_byval: Air.Inst.Ref, | 10809 | union_byval: Air.Inst.Ref, |
| 10430 | field_name: []const u8, | 10810 | field_name: []const u8, |
| ... | @@ -10450,12 +10830,12 @@ fn unionFieldVal( | ... | @@ -10450,12 +10830,12 @@ fn unionFieldVal( |
| 10450 | } | 10830 | } |
| 10451 | | 10831 | |
| 10452 | try sema.requireRuntimeBlock(block, src); | 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 | fn elemPtr( | 10836 | fn elemPtr( |
| 10457 | sema: *Sema, | 10837 | sema: *Sema, |
| 10458 | block: *Scope.Block, | 10838 | block: *Block, |
| 10459 | src: LazySrcLoc, | 10839 | src: LazySrcLoc, |
| 10460 | array_ptr: Air.Inst.Ref, | 10840 | array_ptr: Air.Inst.Ref, |
| 10461 | elem_index: Air.Inst.Ref, | 10841 | elem_index: Air.Inst.Ref, |
| ... | @@ -10465,10 +10845,10 @@ fn elemPtr( | ... | @@ -10465,10 +10845,10 @@ fn elemPtr( |
| 10465 | const array_ptr_ty = sema.typeOf(array_ptr); | 10845 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 10466 | const array_ty = switch (array_ptr_ty.zigTypeTag()) { | 10846 | const array_ty = switch (array_ptr_ty.zigTypeTag()) { |
| 10467 | .Pointer => array_ptr_ty.elemType(), | 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 | if (!array_ty.isIndexable()) { | 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 | if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) { | 10853 | if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) { |
| 10474 | // we have to deref the ptr operand to get the actual array pointer | 10854 | // we have to deref the ptr operand to get the actual array pointer |
| ... | @@ -10479,12 +10859,12 @@ fn elemPtr( | ... | @@ -10479,12 +10859,12 @@ fn elemPtr( |
| 10479 | return sema.elemPtrArray(block, src, array_ptr, elem_index, elem_index_src); | 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 | fn elemVal( | 10865 | fn elemVal( |
| 10486 | sema: *Sema, | 10866 | sema: *Sema, |
| 10487 | block: *Scope.Block, | 10867 | block: *Block, |
| 10488 | src: LazySrcLoc, | 10868 | src: LazySrcLoc, |
| 10489 | array_maybe_ptr: Air.Inst.Ref, | 10869 | array_maybe_ptr: Air.Inst.Ref, |
| 10490 | elem_index: Air.Inst.Ref, | 10870 | elem_index: Air.Inst.Ref, |
| ... | @@ -10497,7 +10877,7 @@ fn elemVal( | ... | @@ -10497,7 +10877,7 @@ fn elemVal( |
| 10497 | .Slice => { | 10877 | .Slice => { |
| 10498 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |slice_val| { | 10878 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |slice_val| { |
| 10499 | _ = slice_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10882 | try sema.requireRuntimeBlock(block, src); |
| 10503 | return block.addBinOp(.slice_elem_val, array_maybe_ptr, elem_index); | 10883 | return block.addBinOp(.slice_elem_val, array_maybe_ptr, elem_index); |
| ... | @@ -10505,7 +10885,7 @@ fn elemVal( | ... | @@ -10505,7 +10885,7 @@ fn elemVal( |
| 10505 | .Many, .C => { | 10885 | .Many, .C => { |
| 10506 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |ptr_val| { | 10886 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |ptr_val| { |
| 10507 | _ = ptr_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10890 | try sema.requireRuntimeBlock(block, src); |
| 10511 | return block.addBinOp(.ptr_elem_val, array_maybe_ptr, elem_index); | 10891 | return block.addBinOp(.ptr_elem_val, array_maybe_ptr, elem_index); |
| ... | @@ -10520,7 +10900,7 @@ fn elemVal( | ... | @@ -10520,7 +10900,7 @@ fn elemVal( |
| 10520 | const slice = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); | 10900 | const slice = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10521 | if (try sema.resolveDefinedValue(block, src, slice)) |slice_val| { | 10901 | if (try sema.resolveDefinedValue(block, src, slice)) |slice_val| { |
| 10522 | _ = slice_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10905 | try sema.requireRuntimeBlock(block, src); |
| 10526 | return block.addBinOp(.slice_elem_val, slice, elem_index); | 10906 | return block.addBinOp(.slice_elem_val, slice, elem_index); |
| ... | @@ -10534,7 +10914,7 @@ fn elemVal( | ... | @@ -10534,7 +10914,7 @@ fn elemVal( |
| 10534 | const ptr = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); | 10914 | const ptr = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10535 | if (try sema.resolveDefinedValue(block, src, ptr)) |ptr_val| { | 10915 | if (try sema.resolveDefinedValue(block, src, ptr)) |ptr_val| { |
| 10536 | _ = ptr_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10919 | try sema.requireRuntimeBlock(block, src); |
| 10540 | return block.addBinOp(.ptr_elem_val, ptr, elem_index); | 10920 | return block.addBinOp(.ptr_elem_val, ptr, elem_index); |
| ... | @@ -10542,8 +10922,8 @@ fn elemVal( | ... | @@ -10542,8 +10922,8 @@ fn elemVal( |
| 10542 | try sema.requireRuntimeBlock(block, src); | 10922 | try sema.requireRuntimeBlock(block, src); |
| 10543 | return block.addBinOp(.ptr_ptr_elem_val, array_maybe_ptr, elem_index); | 10923 | return block.addBinOp(.ptr_ptr_elem_val, array_maybe_ptr, elem_index); |
| 10544 | }, | 10924 | }, |
| 10545 | .One => return sema.mod.fail( | 10925 | .One => return sema.fail( |
| 10546 | &block.base, | 10926 | block, |
| 10547 | array_ptr_src, | 10927 | array_ptr_src, |
| 10548 | "expected pointer, found '{}'", | 10928 | "expected pointer, found '{}'", |
| 10549 | .{indexable_ty.elemType()}, | 10929 | .{indexable_ty.elemType()}, |
| ... | @@ -10553,8 +10933,8 @@ fn elemVal( | ... | @@ -10553,8 +10933,8 @@ fn elemVal( |
| 10553 | const ptr = try sema.elemPtr(block, src, array_maybe_ptr, elem_index, elem_index_src); | 10933 | const ptr = try sema.elemPtr(block, src, array_maybe_ptr, elem_index, elem_index_src); |
| 10554 | return sema.analyzeLoad(block, src, ptr, elem_index_src); | 10934 | return sema.analyzeLoad(block, src, ptr, elem_index_src); |
| 10555 | }, | 10935 | }, |
| 10556 | else => return sema.mod.fail( | 10936 | else => return sema.fail( |
| 10557 | &block.base, | 10937 | block, |
| 10558 | array_ptr_src, | 10938 | array_ptr_src, |
| 10559 | "expected pointer, found '{}'", | 10939 | "expected pointer, found '{}'", |
| 10560 | .{indexable_ty}, | 10940 | .{indexable_ty}, |
| ... | @@ -10562,8 +10942,8 @@ fn elemVal( | ... | @@ -10562,8 +10942,8 @@ fn elemVal( |
| 10562 | } | 10942 | } |
| 10563 | }, | 10943 | }, |
| 10564 | }, | 10944 | }, |
| 10565 | else => return sema.mod.fail( | 10945 | else => return sema.fail( |
| 10566 | &block.base, | 10946 | block, |
| 10567 | array_ptr_src, | 10947 | array_ptr_src, |
| 10568 | "expected pointer, found '{}'", | 10948 | "expected pointer, found '{}'", |
| 10569 | .{maybe_ptr_ty}, | 10949 | .{maybe_ptr_ty}, |
| ... | @@ -10573,7 +10953,7 @@ fn elemVal( | ... | @@ -10573,7 +10953,7 @@ fn elemVal( |
| 10573 | | 10953 | |
| 10574 | fn elemPtrArray( | 10954 | fn elemPtrArray( |
| 10575 | sema: *Sema, | 10955 | sema: *Sema, |
| 10576 | block: *Scope.Block, | 10956 | block: *Block, |
| 10577 | src: LazySrcLoc, | 10957 | src: LazySrcLoc, |
| 10578 | array_ptr: Air.Inst.Ref, | 10958 | array_ptr: Air.Inst.Ref, |
| 10579 | elem_index: Air.Inst.Ref, | 10959 | elem_index: Air.Inst.Ref, |
| ... | @@ -10613,7 +10993,7 @@ fn elemPtrArray( | ... | @@ -10613,7 +10993,7 @@ fn elemPtrArray( |
| 10613 | | 10993 | |
| 10614 | fn coerce( | 10994 | fn coerce( |
| 10615 | sema: *Sema, | 10995 | sema: *Sema, |
| 10616 | block: *Scope.Block, | 10996 | block: *Block, |
| 10617 | dest_type_unresolved: Type, | 10997 | dest_type_unresolved: Type, |
| 10618 | inst: Air.Inst.Ref, | 10998 | inst: Air.Inst.Ref, |
| 10619 | inst_src: LazySrcLoc, | 10999 | inst_src: LazySrcLoc, |
| ... | @@ -10631,10 +11011,10 @@ fn coerce( | ... | @@ -10631,10 +11011,10 @@ fn coerce( |
| 10631 | if (dest_type.eql(inst_ty)) | 11011 | if (dest_type.eql(inst_ty)) |
| 10632 | return inst; | 11012 | return inst; |
| 10633 | | 11013 | |
| 10634 | const mod = sema.mod; | | |
| 10635 | const arena = sema.arena; | 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 | if (in_memory_result == .ok) { | 11018 | if (in_memory_result == .ok) { |
| 10639 | return sema.bitcast(block, dest_type, inst, inst_src); | 11019 | return sema.bitcast(block, dest_type, inst, inst_src); |
| 10640 | } | 11020 | } |
| ... | @@ -10651,8 +11031,6 @@ fn coerce( | ... | @@ -10651,8 +11031,6 @@ fn coerce( |
| 10651 | if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some| | 11031 | if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some| |
| 10652 | return some; | 11032 | return some; |
| 10653 | | 11033 | |
| 10654 | const target = mod.getTarget(); | | |
| 10655 | | | |
| 10656 | switch (dest_type.zigTypeTag()) { | 11034 | switch (dest_type.zigTypeTag()) { |
| 10657 | .Optional => { | 11035 | .Optional => { |
| 10658 | // null to ?T | 11036 | // null to ?T |
| ... | @@ -10679,7 +11057,7 @@ fn coerce( | ... | @@ -10679,7 +11057,7 @@ fn coerce( |
| 10679 | if (inst_ty.ptrAddressSpace() != dest_type.ptrAddressSpace()) break :src_array_ptr; | 11057 | if (inst_ty.ptrAddressSpace() != dest_type.ptrAddressSpace()) break :src_array_ptr; |
| 10680 | | 11058 | |
| 10681 | const dst_elem_type = dest_type.elemType(); | 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 | .ok => {}, | 11061 | .ok => {}, |
| 10684 | .no_match => break :src_array_ptr, | 11062 | .no_match => break :src_array_ptr, |
| 10685 | } | 11063 | } |
| ... | @@ -10748,14 +11126,14 @@ fn coerce( | ... | @@ -10748,14 +11126,14 @@ fn coerce( |
| 10748 | const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type); | 11126 | const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type); |
| 10749 | const field_index = resolved_dest_type.enumFieldIndex(bytes) orelse { | 11127 | const field_index = resolved_dest_type.enumFieldIndex(bytes) orelse { |
| 10750 | const msg = msg: { | 11128 | const msg = msg: { |
| 10751 | const msg = try mod.errMsg( | 11129 | const msg = try sema.errMsg( |
| 10752 | &block.base, | 11130 | block, |
| 10753 | inst_src, | 11131 | inst_src, |
| 10754 | "enum '{}' has no field named '{s}'", | 11132 | "enum '{}' has no field named '{s}'", |
| 10755 | .{ resolved_dest_type, bytes }, | 11133 | .{ resolved_dest_type, bytes }, |
| 10756 | ); | 11134 | ); |
| 10757 | errdefer msg.destroy(sema.gpa); | 11135 | errdefer msg.destroy(sema.gpa); |
| 10758 | try mod.errNoteNonLazy( | 11136 | try sema.mod.errNoteNonLazy( |
| 10759 | resolved_dest_type.declSrcLoc(), | 11137 | resolved_dest_type.declSrcLoc(), |
| 10760 | msg, | 11138 | msg, |
| 10761 | "enum declared here", | 11139 | "enum declared here", |
| ... | @@ -10763,7 +11141,7 @@ fn coerce( | ... | @@ -10763,7 +11141,7 @@ fn coerce( |
| 10763 | ); | 11141 | ); |
| 10764 | break :msg msg; | 11142 | break :msg msg; |
| 10765 | }; | 11143 | }; |
| 10766 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 11144 | return sema.failWithOwnedErrorMsg(msg); |
| 10767 | }; | 11145 | }; |
| 10768 | return sema.addConstant( | 11146 | return sema.addConstant( |
| 10769 | resolved_dest_type, | 11147 | resolved_dest_type, |
| ... | @@ -10786,7 +11164,7 @@ fn coerce( | ... | @@ -10786,7 +11164,7 @@ fn coerce( |
| 10786 | else => {}, | 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 | const InMemoryCoercionResult = enum { | 11170 | const InMemoryCoercionResult = enum { |
| ... | @@ -10887,7 +11265,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type, dest_is_mut: bool, tar | ... | @@ -10887,7 +11265,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type, dest_is_mut: bool, tar |
| 10887 | | 11265 | |
| 10888 | fn coerceNum( | 11266 | fn coerceNum( |
| 10889 | sema: *Sema, | 11267 | sema: *Sema, |
| 10890 | block: *Scope.Block, | 11268 | block: *Block, |
| 10891 | dest_type: Type, | 11269 | dest_type: Type, |
| 10892 | inst: Air.Inst.Ref, | 11270 | inst: Air.Inst.Ref, |
| 10893 | inst_src: LazySrcLoc, | 11271 | inst_src: LazySrcLoc, |
| ... | @@ -10903,13 +11281,13 @@ fn coerceNum( | ... | @@ -10903,13 +11281,13 @@ fn coerceNum( |
| 10903 | .ComptimeInt, .Int => switch (src_zig_tag) { | 11281 | .ComptimeInt, .Int => switch (src_zig_tag) { |
| 10904 | .Float, .ComptimeFloat => { | 11282 | .Float, .ComptimeFloat => { |
| 10905 | if (val.floatHasFraction()) { | 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 | .Int, .ComptimeInt => { | 11288 | .Int, .ComptimeInt => { |
| 10911 | if (!val.intFitsInType(dest_type, target)) { | 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 | return try sema.addConstant(dest_type, val); | 11292 | return try sema.addConstant(dest_type, val); |
| 10915 | }, | 11293 | }, |
| ... | @@ -10923,8 +11301,8 @@ fn coerceNum( | ... | @@ -10923,8 +11301,8 @@ fn coerceNum( |
| 10923 | .Float => { | 11301 | .Float => { |
| 10924 | const result_val = try val.floatCast(sema.arena, dest_type); | 11302 | const result_val = try val.floatCast(sema.arena, dest_type); |
| 10925 | if (!val.eql(result_val, dest_type)) { | 11303 | if (!val.eql(result_val, dest_type)) { |
| 10926 | return sema.mod.fail( | 11304 | return sema.fail( |
| 10927 | &block.base, | 11305 | block, |
| 10928 | inst_src, | 11306 | inst_src, |
| 10929 | "type {} cannot represent float value {}", | 11307 | "type {} cannot represent float value {}", |
| 10930 | .{ dest_type, val }, | 11308 | .{ dest_type, val }, |
| ... | @@ -10937,8 +11315,8 @@ fn coerceNum( | ... | @@ -10937,8 +11315,8 @@ fn coerceNum( |
| 10937 | // TODO implement this compile error | 11315 | // TODO implement this compile error |
| 10938 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); | 11316 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); |
| 10939 | //if (!int_again_val.eql(val, inst_ty)) { | 11317 | //if (!int_again_val.eql(val, inst_ty)) { |
| 10940 | // return sema.mod.fail( | 11318 | // return sema.fail( |
| 10941 | // &block.base, | 11319 | // block, |
| 10942 | // inst_src, | 11320 | // inst_src, |
| 10943 | // "type {} cannot represent integer value {}", | 11321 | // "type {} cannot represent integer value {}", |
| 10944 | // .{ dest_type, val }, | 11322 | // .{ dest_type, val }, |
| ... | @@ -10955,13 +11333,13 @@ fn coerceNum( | ... | @@ -10955,13 +11333,13 @@ fn coerceNum( |
| 10955 | | 11333 | |
| 10956 | fn coerceVarArgParam( | 11334 | fn coerceVarArgParam( |
| 10957 | sema: *Sema, | 11335 | sema: *Sema, |
| 10958 | block: *Scope.Block, | 11336 | block: *Block, |
| 10959 | inst: Air.Inst.Ref, | 11337 | inst: Air.Inst.Ref, |
| 10960 | inst_src: LazySrcLoc, | 11338 | inst_src: LazySrcLoc, |
| 10961 | ) !Air.Inst.Ref { | 11339 | ) !Air.Inst.Ref { |
| 10962 | const inst_ty = sema.typeOf(inst); | 11340 | const inst_ty = sema.typeOf(inst); |
| 10963 | switch (inst_ty.zigTypeTag()) { | 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 | else => {}, | 11343 | else => {}, |
| 10966 | } | 11344 | } |
| 10967 | // TODO implement more of this function. | 11345 | // TODO implement more of this function. |
| ... | @@ -10971,17 +11349,17 @@ fn coerceVarArgParam( | ... | @@ -10971,17 +11349,17 @@ fn coerceVarArgParam( |
| 10971 | // TODO migrate callsites to use storePtr2 instead. | 11349 | // TODO migrate callsites to use storePtr2 instead. |
| 10972 | fn storePtr( | 11350 | fn storePtr( |
| 10973 | sema: *Sema, | 11351 | sema: *Sema, |
| 10974 | block: *Scope.Block, | 11352 | block: *Block, |
| 10975 | src: LazySrcLoc, | 11353 | src: LazySrcLoc, |
| 10976 | ptr: Air.Inst.Ref, | 11354 | ptr: Air.Inst.Ref, |
| 10977 | uncasted_operand: Air.Inst.Ref, | 11355 | uncasted_operand: Air.Inst.Ref, |
| 10978 | ) !void { | 11356 | ) CompileError!void { |
| 10979 | return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store); | 11357 | return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store); |
| 10980 | } | 11358 | } |
| 10981 | | 11359 | |
| 10982 | fn storePtr2( | 11360 | fn storePtr2( |
| 10983 | sema: *Sema, | 11361 | sema: *Sema, |
| 10984 | block: *Scope.Block, | 11362 | block: *Block, |
| 10985 | src: LazySrcLoc, | 11363 | src: LazySrcLoc, |
| 10986 | ptr: Air.Inst.Ref, | 11364 | ptr: Air.Inst.Ref, |
| 10987 | ptr_src: LazySrcLoc, | 11365 | ptr_src: LazySrcLoc, |
| ... | @@ -10991,7 +11369,7 @@ fn storePtr2( | ... | @@ -10991,7 +11369,7 @@ fn storePtr2( |
| 10991 | ) !void { | 11369 | ) !void { |
| 10992 | const ptr_ty = sema.typeOf(ptr); | 11370 | const ptr_ty = sema.typeOf(ptr); |
| 10993 | if (ptr_ty.isConstPtr()) | 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 | const elem_ty = ptr_ty.elemType(); | 11374 | const elem_ty = ptr_ty.elemType(); |
| 10997 | const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src); | 11375 | const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src); |
| ... | @@ -11000,7 +11378,7 @@ fn storePtr2( | ... | @@ -11000,7 +11378,7 @@ fn storePtr2( |
| 11000 | | 11378 | |
| 11001 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { | 11379 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 11002 | const operand_val = (try sema.resolveMaybeUndefVal(block, operand_src, operand)) orelse | 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 | if (ptr_val.tag() == .decl_ref_mut) { | 11382 | if (ptr_val.tag() == .decl_ref_mut) { |
| 11005 | try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty); | 11383 | try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty); |
| 11006 | return; | 11384 | return; |
| ... | @@ -11018,7 +11396,7 @@ fn storePtr2( | ... | @@ -11018,7 +11396,7 @@ fn storePtr2( |
| 11018 | /// assert the store must be done at comptime. | 11396 | /// assert the store must be done at comptime. |
| 11019 | fn storePtrVal( | 11397 | fn storePtrVal( |
| 11020 | sema: *Sema, | 11398 | sema: *Sema, |
| 11021 | block: *Scope.Block, | 11399 | block: *Block, |
| 11022 | src: LazySrcLoc, | 11400 | src: LazySrcLoc, |
| 11023 | ptr_val: Value, | 11401 | ptr_val: Value, |
| 11024 | operand_val: Value, | 11402 | operand_val: Value, |
| ... | @@ -11028,21 +11406,21 @@ fn storePtrVal( | ... | @@ -11028,21 +11406,21 @@ fn storePtrVal( |
| 11028 | if (decl_ref_mut.data.runtime_index < block.runtime_index) { | 11406 | if (decl_ref_mut.data.runtime_index < block.runtime_index) { |
| 11029 | if (block.runtime_cond) |cond_src| { | 11407 | if (block.runtime_cond) |cond_src| { |
| 11030 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 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 | break :msg msg; | 11412 | break :msg msg; |
| 11035 | }; | 11413 | }; |
| 11036 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 11414 | return sema.failWithOwnedErrorMsg(msg); |
| 11037 | } | 11415 | } |
| 11038 | if (block.runtime_loop) |loop_src| { | 11416 | if (block.runtime_loop) |loop_src| { |
| 11039 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 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 | break :msg msg; | 11421 | break :msg msg; |
| 11044 | }; | 11422 | }; |
| 11045 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 11423 | return sema.failWithOwnedErrorMsg(msg); |
| 11046 | } | 11424 | } |
| 11047 | unreachable; | 11425 | unreachable; |
| 11048 | } | 11426 | } |
| ... | @@ -11063,7 +11441,7 @@ fn storePtrVal( | ... | @@ -11063,7 +11441,7 @@ fn storePtrVal( |
| 11063 | | 11441 | |
| 11064 | fn bitcast( | 11442 | fn bitcast( |
| 11065 | sema: *Sema, | 11443 | sema: *Sema, |
| 11066 | block: *Scope.Block, | 11444 | block: *Block, |
| 11067 | dest_type: Type, | 11445 | dest_type: Type, |
| 11068 | inst: Air.Inst.Ref, | 11446 | inst: Air.Inst.Ref, |
| 11069 | inst_src: LazySrcLoc, | 11447 | inst_src: LazySrcLoc, |
| ... | @@ -11079,7 +11457,7 @@ fn bitcast( | ... | @@ -11079,7 +11457,7 @@ fn bitcast( |
| 11079 | | 11457 | |
| 11080 | fn coerceArrayPtrToSlice( | 11458 | fn coerceArrayPtrToSlice( |
| 11081 | sema: *Sema, | 11459 | sema: *Sema, |
| 11082 | block: *Scope.Block, | 11460 | block: *Block, |
| 11083 | dest_type: Type, | 11461 | dest_type: Type, |
| 11084 | inst: Air.Inst.Ref, | 11462 | inst: Air.Inst.Ref, |
| 11085 | inst_src: LazySrcLoc, | 11463 | inst_src: LazySrcLoc, |
| ... | @@ -11094,7 +11472,7 @@ fn coerceArrayPtrToSlice( | ... | @@ -11094,7 +11472,7 @@ fn coerceArrayPtrToSlice( |
| 11094 | | 11472 | |
| 11095 | fn coerceArrayPtrToMany( | 11473 | fn coerceArrayPtrToMany( |
| 11096 | sema: *Sema, | 11474 | sema: *Sema, |
| 11097 | block: *Scope.Block, | 11475 | block: *Block, |
| 11098 | dest_type: Type, | 11476 | dest_type: Type, |
| 11099 | inst: Air.Inst.Ref, | 11477 | inst: Air.Inst.Ref, |
| 11100 | inst_src: LazySrcLoc, | 11478 | inst_src: LazySrcLoc, |
| ... | @@ -11109,7 +11487,7 @@ fn coerceArrayPtrToMany( | ... | @@ -11109,7 +11487,7 @@ fn coerceArrayPtrToMany( |
| 11109 | | 11487 | |
| 11110 | fn analyzeDeclVal( | 11488 | fn analyzeDeclVal( |
| 11111 | sema: *Sema, | 11489 | sema: *Sema, |
| 11112 | block: *Scope.Block, | 11490 | block: *Block, |
| 11113 | src: LazySrcLoc, | 11491 | src: LazySrcLoc, |
| 11114 | decl: *Decl, | 11492 | decl: *Decl, |
| 11115 | ) CompileError!Air.Inst.Ref { | 11493 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -11163,7 +11541,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { | ... | @@ -11163,7 +11541,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { |
| 11163 | | 11541 | |
| 11164 | fn analyzeRef( | 11542 | fn analyzeRef( |
| 11165 | sema: *Sema, | 11543 | sema: *Sema, |
| 11166 | block: *Scope.Block, | 11544 | block: *Block, |
| 11167 | src: LazySrcLoc, | 11545 | src: LazySrcLoc, |
| 11168 | operand: Air.Inst.Ref, | 11546 | operand: Air.Inst.Ref, |
| 11169 | ) CompileError!Air.Inst.Ref { | 11547 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -11198,7 +11576,7 @@ fn analyzeRef( | ... | @@ -11198,7 +11576,7 @@ fn analyzeRef( |
| 11198 | | 11576 | |
| 11199 | fn analyzeLoad( | 11577 | fn analyzeLoad( |
| 11200 | sema: *Sema, | 11578 | sema: *Sema, |
| 11201 | block: *Scope.Block, | 11579 | block: *Block, |
| 11202 | src: LazySrcLoc, | 11580 | src: LazySrcLoc, |
| 11203 | ptr: Air.Inst.Ref, | 11581 | ptr: Air.Inst.Ref, |
| 11204 | ptr_src: LazySrcLoc, | 11582 | ptr_src: LazySrcLoc, |
| ... | @@ -11206,7 +11584,7 @@ fn analyzeLoad( | ... | @@ -11206,7 +11584,7 @@ fn analyzeLoad( |
| 11206 | const ptr_ty = sema.typeOf(ptr); | 11584 | const ptr_ty = sema.typeOf(ptr); |
| 11207 | const elem_ty = switch (ptr_ty.zigTypeTag()) { | 11585 | const elem_ty = switch (ptr_ty.zigTypeTag()) { |
| 11208 | .Pointer => ptr_ty.elemType(), | 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 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { | 11589 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { |
| 11212 | if (try ptr_val.pointerDeref(sema.arena)) |elem_val| { | 11590 | if (try ptr_val.pointerDeref(sema.arena)) |elem_val| { |
| ... | @@ -11220,7 +11598,7 @@ fn analyzeLoad( | ... | @@ -11220,7 +11598,7 @@ fn analyzeLoad( |
| 11220 | | 11598 | |
| 11221 | fn analyzeSliceLen( | 11599 | fn analyzeSliceLen( |
| 11222 | sema: *Sema, | 11600 | sema: *Sema, |
| 11223 | block: *Scope.Block, | 11601 | block: *Block, |
| 11224 | src: LazySrcLoc, | 11602 | src: LazySrcLoc, |
| 11225 | slice_inst: Air.Inst.Ref, | 11603 | slice_inst: Air.Inst.Ref, |
| 11226 | ) CompileError!Air.Inst.Ref { | 11604 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -11228,7 +11606,7 @@ fn analyzeSliceLen( | ... | @@ -11228,7 +11606,7 @@ fn analyzeSliceLen( |
| 11228 | if (slice_val.isUndef()) { | 11606 | if (slice_val.isUndef()) { |
| 11229 | return sema.addConstUndef(Type.initTag(.usize)); | 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 | try sema.requireRuntimeBlock(block, src); | 11611 | try sema.requireRuntimeBlock(block, src); |
| 11234 | return block.addTyOp(.slice_len, Type.initTag(.usize), slice_inst); | 11612 | return block.addTyOp(.slice_len, Type.initTag(.usize), slice_inst); |
| ... | @@ -11236,7 +11614,7 @@ fn analyzeSliceLen( | ... | @@ -11236,7 +11614,7 @@ fn analyzeSliceLen( |
| 11236 | | 11614 | |
| 11237 | fn analyzeIsNull( | 11615 | fn analyzeIsNull( |
| 11238 | sema: *Sema, | 11616 | sema: *Sema, |
| 11239 | block: *Scope.Block, | 11617 | block: *Block, |
| 11240 | src: LazySrcLoc, | 11618 | src: LazySrcLoc, |
| 11241 | operand: Air.Inst.Ref, | 11619 | operand: Air.Inst.Ref, |
| 11242 | invert_logic: bool, | 11620 | invert_logic: bool, |
| ... | @@ -11261,7 +11639,7 @@ fn analyzeIsNull( | ... | @@ -11261,7 +11639,7 @@ fn analyzeIsNull( |
| 11261 | | 11639 | |
| 11262 | fn analyzeIsNonErr( | 11640 | fn analyzeIsNonErr( |
| 11263 | sema: *Sema, | 11641 | sema: *Sema, |
| 11264 | block: *Scope.Block, | 11642 | block: *Block, |
| 11265 | src: LazySrcLoc, | 11643 | src: LazySrcLoc, |
| 11266 | operand: Air.Inst.Ref, | 11644 | operand: Air.Inst.Ref, |
| 11267 | ) CompileError!Air.Inst.Ref { | 11645 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -11287,7 +11665,7 @@ fn analyzeIsNonErr( | ... | @@ -11287,7 +11665,7 @@ fn analyzeIsNonErr( |
| 11287 | | 11665 | |
| 11288 | fn analyzeSlice( | 11666 | fn analyzeSlice( |
| 11289 | sema: *Sema, | 11667 | sema: *Sema, |
| 11290 | block: *Scope.Block, | 11668 | block: *Block, |
| 11291 | src: LazySrcLoc, | 11669 | src: LazySrcLoc, |
| 11292 | array_ptr: Air.Inst.Ref, | 11670 | array_ptr: Air.Inst.Ref, |
| 11293 | start: Air.Inst.Ref, | 11671 | start: Air.Inst.Ref, |
| ... | @@ -11298,7 +11676,7 @@ fn analyzeSlice( | ... | @@ -11298,7 +11676,7 @@ fn analyzeSlice( |
| 11298 | const array_ptr_ty = sema.typeOf(array_ptr); | 11676 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 11299 | const ptr_child = switch (array_ptr_ty.zigTypeTag()) { | 11677 | const ptr_child = switch (array_ptr_ty.zigTypeTag()) { |
| 11300 | .Pointer => array_ptr_ty.elemType(), | 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 | var array_type = ptr_child; | 11682 | var array_type = ptr_child; |
| ... | @@ -11311,11 +11689,11 @@ fn analyzeSlice( | ... | @@ -11311,11 +11689,11 @@ fn analyzeSlice( |
| 11311 | break :blk ptr_child.elemType().elemType(); | 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 | break :blk ptr_child.elemType(); | 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 | const slice_sentinel = if (sentinel_opt != .none) blk: { | 11699 | const slice_sentinel = if (sentinel_opt != .none) blk: { |
| ... | @@ -11331,7 +11709,7 @@ fn analyzeSlice( | ... | @@ -11331,7 +11709,7 @@ fn analyzeSlice( |
| 11331 | const start_u64 = start_val.toUnsignedInt(); | 11709 | const start_u64 = start_val.toUnsignedInt(); |
| 11332 | const end_u64 = end_val.toUnsignedInt(); | 11710 | const end_u64 = end_val.toUnsignedInt(); |
| 11333 | if (start_u64 > end_u64) { | 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 | const len = end_u64 - start_u64; | 11715 | const len = end_u64 - start_u64; |
| ... | @@ -11356,13 +11734,13 @@ fn analyzeSlice( | ... | @@ -11356,13 +11734,13 @@ fn analyzeSlice( |
| 11356 | }); | 11734 | }); |
| 11357 | _ = return_type; | 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 | /// Asserts that lhs and rhs types are both numeric. | 11740 | /// Asserts that lhs and rhs types are both numeric. |
| 11363 | fn cmpNumeric( | 11741 | fn cmpNumeric( |
| 11364 | sema: *Sema, | 11742 | sema: *Sema, |
| 11365 | block: *Scope.Block, | 11743 | block: *Block, |
| 11366 | src: LazySrcLoc, | 11744 | src: LazySrcLoc, |
| 11367 | lhs: Air.Inst.Ref, | 11745 | lhs: Air.Inst.Ref, |
| 11368 | rhs: Air.Inst.Ref, | 11746 | rhs: Air.Inst.Ref, |
| ... | @@ -11381,13 +11759,13 @@ fn cmpNumeric( | ... | @@ -11381,13 +11759,13 @@ fn cmpNumeric( |
| 11381 | | 11759 | |
| 11382 | if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) { | 11760 | if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) { |
| 11383 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { | 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 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), | 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 | } else if (lhs_ty_tag == .Vector or rhs_ty_tag == .Vector) { | 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 | lhs_ty, rhs_ty, | 11769 | lhs_ty, rhs_ty, |
| 11392 | }); | 11770 | }); |
| 11393 | } | 11771 | } |
| ... | @@ -11537,7 +11915,7 @@ fn cmpNumeric( | ... | @@ -11537,7 +11915,7 @@ fn cmpNumeric( |
| 11537 | const dest_type = if (dest_float_type) |ft| ft else blk: { | 11915 | const dest_type = if (dest_float_type) |ft| ft else blk: { |
| 11538 | const max_bits = std.math.max(lhs_bits, rhs_bits); | 11916 | const max_bits = std.math.max(lhs_bits, rhs_bits); |
| 11539 | const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) { | 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 | const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; | 11920 | const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; |
| 11543 | break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); | 11921 | break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); |
| ... | @@ -11550,7 +11928,7 @@ fn cmpNumeric( | ... | @@ -11550,7 +11928,7 @@ fn cmpNumeric( |
| 11550 | | 11928 | |
| 11551 | fn wrapOptional( | 11929 | fn wrapOptional( |
| 11552 | sema: *Sema, | 11930 | sema: *Sema, |
| 11553 | block: *Scope.Block, | 11931 | block: *Block, |
| 11554 | dest_type: Type, | 11932 | dest_type: Type, |
| 11555 | inst: Air.Inst.Ref, | 11933 | inst: Air.Inst.Ref, |
| 11556 | inst_src: LazySrcLoc, | 11934 | inst_src: LazySrcLoc, |
| ... | @@ -11565,7 +11943,7 @@ fn wrapOptional( | ... | @@ -11565,7 +11943,7 @@ fn wrapOptional( |
| 11565 | | 11943 | |
| 11566 | fn wrapErrorUnion( | 11944 | fn wrapErrorUnion( |
| 11567 | sema: *Sema, | 11945 | sema: *Sema, |
| 11568 | block: *Scope.Block, | 11946 | block: *Block, |
| 11569 | dest_type: Type, | 11947 | dest_type: Type, |
| 11570 | inst: Air.Inst.Ref, | 11948 | inst: Air.Inst.Ref, |
| 11571 | inst_src: LazySrcLoc, | 11949 | inst_src: LazySrcLoc, |
| ... | @@ -11584,8 +11962,8 @@ fn wrapErrorUnion( | ... | @@ -11584,8 +11962,8 @@ fn wrapErrorUnion( |
| 11584 | const expected_name = val.castTag(.@"error").?.data.name; | 11962 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11585 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; | 11963 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; |
| 11586 | if (!mem.eql(u8, expected_name, n)) { | 11964 | if (!mem.eql(u8, expected_name, n)) { |
| 11587 | return sema.mod.fail( | 11965 | return sema.fail( |
| 11588 | &block.base, | 11966 | block, |
| 11589 | inst_src, | 11967 | inst_src, |
| 11590 | "expected type '{}', found type '{}'", | 11968 | "expected type '{}', found type '{}'", |
| 11591 | .{ dest_err_set_ty, inst_ty }, | 11969 | .{ dest_err_set_ty, inst_ty }, |
| ... | @@ -11602,8 +11980,8 @@ fn wrapErrorUnion( | ... | @@ -11602,8 +11980,8 @@ fn wrapErrorUnion( |
| 11602 | if (mem.eql(u8, expected_name, name)) break true; | 11980 | if (mem.eql(u8, expected_name, name)) break true; |
| 11603 | } else false; | 11981 | } else false; |
| 11604 | if (!found) { | 11982 | if (!found) { |
| 11605 | return sema.mod.fail( | 11983 | return sema.fail( |
| 11606 | &block.base, | 11984 | block, |
| 11607 | inst_src, | 11985 | inst_src, |
| 11608 | "expected type '{}', found type '{}'", | 11986 | "expected type '{}', found type '{}'", |
| 11609 | .{ dest_err_set_ty, inst_ty }, | 11987 | .{ dest_err_set_ty, inst_ty }, |
| ... | @@ -11614,8 +11992,8 @@ fn wrapErrorUnion( | ... | @@ -11614,8 +11992,8 @@ fn wrapErrorUnion( |
| 11614 | const expected_name = val.castTag(.@"error").?.data.name; | 11992 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11615 | const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map; | 11993 | const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map; |
| 11616 | if (!map.contains(expected_name)) { | 11994 | if (!map.contains(expected_name)) { |
| 11617 | return sema.mod.fail( | 11995 | return sema.fail( |
| 11618 | &block.base, | 11996 | block, |
| 11619 | inst_src, | 11997 | inst_src, |
| 11620 | "expected type '{}', found type '{}'", | 11998 | "expected type '{}', found type '{}'", |
| 11621 | .{ dest_err_set_ty, inst_ty }, | 11999 | .{ dest_err_set_ty, inst_ty }, |
| ... | @@ -11641,7 +12019,7 @@ fn wrapErrorUnion( | ... | @@ -11641,7 +12019,7 @@ fn wrapErrorUnion( |
| 11641 | | 12019 | |
| 11642 | fn unionToTag( | 12020 | fn unionToTag( |
| 11643 | sema: *Sema, | 12021 | sema: *Sema, |
| 11644 | block: *Scope.Block, | 12022 | block: *Block, |
| 11645 | dest_type: Type, | 12023 | dest_type: Type, |
| 11646 | un: Air.Inst.Ref, | 12024 | un: Air.Inst.Ref, |
| 11647 | un_src: LazySrcLoc, | 12025 | un_src: LazySrcLoc, |
| ... | @@ -11655,7 +12033,7 @@ fn unionToTag( | ... | @@ -11655,7 +12033,7 @@ fn unionToTag( |
| 11655 | | 12033 | |
| 11656 | fn resolvePeerTypes( | 12034 | fn resolvePeerTypes( |
| 11657 | sema: *Sema, | 12035 | sema: *Sema, |
| 11658 | block: *Scope.Block, | 12036 | block: *Block, |
| 11659 | src: LazySrcLoc, | 12037 | src: LazySrcLoc, |
| 11660 | instructions: []Air.Inst.Ref, | 12038 | instructions: []Air.Inst.Ref, |
| 11661 | candidate_srcs: Module.PeerTypeCandidateSrc, | 12039 | candidate_srcs: Module.PeerTypeCandidateSrc, |
| ... | @@ -11750,18 +12128,18 @@ fn resolvePeerTypes( | ... | @@ -11750,18 +12128,18 @@ fn resolvePeerTypes( |
| 11750 | ); | 12128 | ); |
| 11751 | | 12129 | |
| 11752 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 12132 | errdefer msg.destroy(sema.gpa); |
| 11755 | | 12133 | |
| 11756 | if (chosen_src) |src_loc| | 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 | if (candidate_src) |src_loc| | 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 | break :msg msg; | 12140 | break :msg msg; |
| 11763 | }; | 12141 | }; |
| 11764 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 12142 | return sema.failWithOwnedErrorMsg(msg); |
| 11765 | } | 12143 | } |
| 11766 | | 12144 | |
| 11767 | return sema.typeOf(chosen); | 12145 | return sema.typeOf(chosen); |
| ... | @@ -11769,7 +12147,7 @@ fn resolvePeerTypes( | ... | @@ -11769,7 +12147,7 @@ fn resolvePeerTypes( |
| 11769 | | 12147 | |
| 11770 | pub fn resolveTypeLayout( | 12148 | pub fn resolveTypeLayout( |
| 11771 | sema: *Sema, | 12149 | sema: *Sema, |
| 11772 | block: *Scope.Block, | 12150 | block: *Block, |
| 11773 | src: LazySrcLoc, | 12151 | src: LazySrcLoc, |
| 11774 | ty: Type, | 12152 | ty: Type, |
| 11775 | ) CompileError!void { | 12153 | ) CompileError!void { |
| ... | @@ -11780,7 +12158,7 @@ pub fn resolveTypeLayout( | ... | @@ -11780,7 +12158,7 @@ pub fn resolveTypeLayout( |
| 11780 | switch (struct_obj.status) { | 12158 | switch (struct_obj.status) { |
| 11781 | .none, .have_field_types => {}, | 12159 | .none, .have_field_types => {}, |
| 11782 | .field_types_wip, .layout_wip => { | 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 | .have_layout => return, | 12163 | .have_layout => return, |
| 11786 | } | 12164 | } |
| ... | @@ -11794,78 +12172,23 @@ pub fn resolveTypeLayout( | ... | @@ -11794,78 +12172,23 @@ pub fn resolveTypeLayout( |
| 11794 | } | 12172 | } |
| 11795 | } | 12173 | } |
| 11796 | | 12174 | |
| 11797 | pub fn resolvePendingTypes(sema: *Sema, block: *Scope.Block) !void { | 12175 | fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type { |
| 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 { | | |
| 11809 | switch (ty.tag()) { | 12176 | switch (ty.tag()) { |
| 11810 | .@"struct" => { | 12177 | .@"struct" => { |
| 11811 | const struct_obj = ty.castTag(.@"struct").?.data; | 12178 | const struct_obj = ty.castTag(.@"struct").?.data; |
| 11812 | if (struct_obj.owner_decl.namespace != sema.owner_decl.namespace) return; | | |
| 11813 | switch (struct_obj.status) { | 12179 | switch (struct_obj.status) { |
| 11814 | .none => {}, | 12180 | .none => {}, |
| 11815 | .field_types_wip => { | 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 | struct_obj.status = .field_types_wip; | 12187 | struct_obj.status = .field_types_wip; |
| 11829 | try sema.analyzeStructFields(block, struct_obj); | 12188 | try semaStructFields(sema.mod, struct_obj); |
| 11830 | struct_obj.status = .have_field_types; | 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; | 12191 | return ty; |
| 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 | } | | |
| 11869 | }, | 12192 | }, |
| 11870 | .type_info => return sema.resolveBuiltinTypeFields(block, src, "TypeInfo"), | 12193 | .type_info => return sema.resolveBuiltinTypeFields(block, src, "TypeInfo"), |
| 11871 | .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"), | 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,12 +12204,18 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11881 | .@"union", .union_tagged => { | 12204 | .@"union", .union_tagged => { |
| 11882 | const union_obj = ty.cast(Type.Payload.Union).?.data; | 12205 | const union_obj = ty.cast(Type.Payload.Union).?.data; |
| 11883 | switch (union_obj.status) { | 12206 | switch (union_obj.status) { |
| 11884 | .none => unreachable, | 12207 | .none => {}, |
| 11885 | .field_types_wip => { | 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 | .have_field_types, .have_layout, .layout_wip => return ty, | 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 | else => return ty, | 12220 | else => return ty, |
| 11892 | } | 12221 | } |
| ... | @@ -11894,7 +12223,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type | ... | @@ -11894,7 +12223,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11894 | | 12223 | |
| 11895 | fn resolveBuiltinTypeFields( | 12224 | fn resolveBuiltinTypeFields( |
| 11896 | sema: *Sema, | 12225 | sema: *Sema, |
| 11897 | block: *Scope.Block, | 12226 | block: *Block, |
| 11898 | src: LazySrcLoc, | 12227 | src: LazySrcLoc, |
| 11899 | name: []const u8, | 12228 | name: []const u8, |
| 11900 | ) CompileError!Type { | 12229 | ) CompileError!Type { |
| ... | @@ -11902,16 +12231,16 @@ fn resolveBuiltinTypeFields( | ... | @@ -11902,16 +12231,16 @@ fn resolveBuiltinTypeFields( |
| 11902 | return sema.resolveTypeFields(block, src, resolved_ty); | 12231 | return sema.resolveTypeFields(block, src, resolved_ty); |
| 11903 | } | 12232 | } |
| 11904 | | 12233 | |
| 11905 | fn analyzeStructFields( | 12234 | fn semaStructFields( |
| 11906 | sema: *Sema, | 12235 | mod: *Module, |
| 11907 | block: *Scope.Block, | | |
| 11908 | struct_obj: *Module.Struct, | 12236 | struct_obj: *Module.Struct, |
| 11909 | ) CompileError!void { | 12237 | ) CompileError!void { |
| 11910 | const tracy = trace(@src()); | 12238 | const tracy = trace(@src()); |
| 11911 | defer tracy.end(); | 12239 | defer tracy.end(); |
| 11912 | | 12240 | |
| 11913 | const gpa = sema.gpa; | 12241 | const gpa = mod.gpa; |
| 11914 | const zir = sema.code; | 12242 | const decl = struct_obj.owner_decl; |
| | 12243 | const zir = struct_obj.namespace.file_scope.zir; |
| 11915 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; | 12244 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| 11916 | assert(extended.opcode == .struct_decl); | 12245 | assert(extended.opcode == .struct_decl); |
| 11917 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); | 12246 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); |
| ... | @@ -11950,15 +12279,51 @@ fn analyzeStructFields( | ... | @@ -11950,15 +12279,51 @@ fn analyzeStructFields( |
| 11950 | } | 12279 | } |
| 11951 | extra_index += body.len; | 12280 | extra_index += body.len; |
| 11952 | | 12281 | |
| 11953 | var decl_arena = struct_obj.owner_decl.value_arena.?.promote(gpa); | 12282 | var decl_arena = decl.value_arena.?.promote(gpa); |
| 11954 | defer struct_obj.owner_decl.value_arena.?.* = decl_arena.state; | 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 | if (body.len != 0) { | 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 | const bits_per_field = 4; | 12327 | const bits_per_field = 4; |
| 11963 | const fields_per_u32 = 32 / bits_per_field; | 12328 | const fields_per_u32 = 32 / bits_per_field; |
| 11964 | const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable; | 12329 | const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable; |
| ... | @@ -11995,7 +12360,7 @@ fn analyzeStructFields( | ... | @@ -11995,7 +12360,7 @@ fn analyzeStructFields( |
| 11995 | // TODO: if we need to report an error here, use a source location | 12360 | // TODO: if we need to report an error here, use a source location |
| 11996 | // that points to this type expression rather than the struct. | 12361 | // that points to this type expression rather than the struct. |
| 11997 | // But only resolve the source location if we need to emit a compile error. | 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 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); | 12365 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 12001 | assert(!gop.found_existing); | 12366 | assert(!gop.found_existing); |
| ... | @@ -12013,7 +12378,7 @@ fn analyzeStructFields( | ... | @@ -12013,7 +12378,7 @@ fn analyzeStructFields( |
| 12013 | // TODO: if we need to report an error here, use a source location | 12378 | // TODO: if we need to report an error here, use a source location |
| 12014 | // that points to this alignment expression rather than the struct. | 12379 | // that points to this alignment expression rather than the struct. |
| 12015 | // But only resolve the source location if we need to emit a compile error. | 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 | gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator); | 12382 | gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator); |
| 12018 | } | 12383 | } |
| 12019 | if (has_default) { | 12384 | if (has_default) { |
| ... | @@ -12023,23 +12388,23 @@ fn analyzeStructFields( | ... | @@ -12023,23 +12388,23 @@ fn analyzeStructFields( |
| 12023 | // TODO: if we need to report an error here, use a source location | 12388 | // TODO: if we need to report an error here, use a source location |
| 12024 | // that points to this default value expression rather than the struct. | 12389 | // that points to this default value expression rather than the struct. |
| 12025 | // But only resolve the source location if we need to emit a compile error. | 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 | 12391 | const default_val = (try sema.resolveMaybeUndefVal(&block_scope, src, default_inst)) orelse |
| 12027 | return sema.failWithNeededComptime(block, src); | 12392 | return sema.failWithNeededComptime(&block_scope, src); |
| 12028 | gop.value_ptr.default_val = try default_val.copy(&decl_arena.allocator); | 12393 | gop.value_ptr.default_val = try default_val.copy(&decl_arena.allocator); |
| 12029 | } | 12394 | } |
| 12030 | } | 12395 | } |
| 12031 | } | 12396 | } |
| 12032 | | 12397 | |
| 12033 | fn analyzeUnionFields( | 12398 | fn semaUnionFields( |
| 12034 | sema: *Sema, | 12399 | mod: *Module, |
| 12035 | block: *Scope.Block, | | |
| 12036 | union_obj: *Module.Union, | 12400 | union_obj: *Module.Union, |
| 12037 | ) CompileError!void { | 12401 | ) CompileError!void { |
| 12038 | const tracy = trace(@src()); | 12402 | const tracy = trace(@src()); |
| 12039 | defer tracy.end(); | 12403 | defer tracy.end(); |
| 12040 | | 12404 | |
| 12041 | const gpa = sema.gpa; | 12405 | const gpa = mod.gpa; |
| 12042 | const zir = sema.code; | 12406 | const decl = union_obj.owner_decl; |
| | 12407 | const zir = union_obj.namespace.file_scope.zir; |
| 12043 | const extended = zir.instructions.items(.data)[union_obj.zir_index].extended; | 12408 | const extended = zir.instructions.items(.data)[union_obj.zir_index].extended; |
| 12044 | assert(extended.opcode == .union_decl); | 12409 | assert(extended.opcode == .union_decl); |
| 12045 | const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small); | 12410 | const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small); |
| ... | @@ -12087,20 +12452,57 @@ fn analyzeUnionFields( | ... | @@ -12087,20 +12452,57 @@ fn analyzeUnionFields( |
| 12087 | var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa); | 12452 | var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa); |
| 12088 | defer union_obj.owner_decl.value_arena.?.* = decl_arena.state; | 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 | if (body.len != 0) { | 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 | var int_tag_ty: Type = undefined; | 12497 | var int_tag_ty: Type = undefined; |
| 12096 | var enum_field_names: ?*Module.EnumNumbered.NameMap = null; | 12498 | var enum_field_names: ?*Module.EnumNumbered.NameMap = null; |
| 12097 | var enum_value_map: ?*Module.EnumNumbered.ValueMap = null; | 12499 | var enum_value_map: ?*Module.EnumNumbered.ValueMap = null; |
| 12098 | if (tag_type_ref != .none) { | 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 | if (small.auto_enum_tag) { | 12502 | if (small.auto_enum_tag) { |
| 12101 | // The provided type is an integer type and we must construct the enum tag type here. | 12503 | // The provided type is an integer type and we must construct the enum tag type here. |
| 12102 | int_tag_ty = provided_ty; | 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 | enum_field_names = &union_obj.tag_ty.castTag(.enum_numbered).?.data.fields; | 12506 | enum_field_names = &union_obj.tag_ty.castTag(.enum_numbered).?.data.fields; |
| 12105 | enum_value_map = &union_obj.tag_ty.castTag(.enum_numbered).?.data.values; | 12507 | enum_value_map = &union_obj.tag_ty.castTag(.enum_numbered).?.data.values; |
| 12106 | } else { | 12508 | } else { |
| ... | @@ -12111,7 +12513,7 @@ fn analyzeUnionFields( | ... | @@ -12111,7 +12513,7 @@ fn analyzeUnionFields( |
| 12111 | // If auto_enum_tag is false, this is an untagged union. However, for semantic analysis | 12513 | // If auto_enum_tag is false, this is an untagged union. However, for semantic analysis |
| 12112 | // purposes, we still auto-generate an enum tag type the same way. That the union is | 12514 | // purposes, we still auto-generate an enum tag type the same way. That the union is |
| 12113 | // untagged is represented by the Type tag (union vs union_tagged). | 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 | enum_field_names = &union_obj.tag_ty.castTag(.enum_simple).?.data.fields; | 12517 | enum_field_names = &union_obj.tag_ty.castTag(.enum_simple).?.data.fields; |
| 12116 | } | 12518 | } |
| 12117 | | 12519 | |
| ... | @@ -12160,8 +12562,8 @@ fn analyzeUnionFields( | ... | @@ -12160,8 +12562,8 @@ fn analyzeUnionFields( |
| 12160 | | 12562 | |
| 12161 | if (enum_value_map) |map| { | 12563 | if (enum_value_map) |map| { |
| 12162 | const tag_src = src; // TODO better source location | 12564 | const tag_src = src; // TODO better source location |
| 12163 | const coerced = try sema.coerce(block, int_tag_ty, tag_ref, tag_src); | 12565 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); |
| 12164 | const val = try sema.resolveConstValue(block, tag_src, coerced); | 12566 | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced); |
| 12165 | map.putAssumeCapacityContext(val, {}, .{ .ty = int_tag_ty }); | 12567 | map.putAssumeCapacityContext(val, {}, .{ .ty = int_tag_ty }); |
| 12166 | } | 12568 | } |
| 12167 | | 12569 | |
| ... | @@ -12177,7 +12579,7 @@ fn analyzeUnionFields( | ... | @@ -12177,7 +12579,7 @@ fn analyzeUnionFields( |
| 12177 | // TODO: if we need to report an error here, use a source location | 12579 | // TODO: if we need to report an error here, use a source location |
| 12178 | // that points to this type expression rather than the union. | 12580 | // that points to this type expression rather than the union. |
| 12179 | // But only resolve the source location if we need to emit a compile error. | 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 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); | 12584 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); |
| 12183 | assert(!gop.found_existing); | 12585 | assert(!gop.found_existing); |
| ... | @@ -12190,7 +12592,7 @@ fn analyzeUnionFields( | ... | @@ -12190,7 +12592,7 @@ fn analyzeUnionFields( |
| 12190 | // TODO: if we need to report an error here, use a source location | 12592 | // TODO: if we need to report an error here, use a source location |
| 12191 | // that points to this alignment expression rather than the struct. | 12593 | // that points to this alignment expression rather than the struct. |
| 12192 | // But only resolve the source location if we need to emit a compile error. | 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 | gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator); | 12596 | gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator); |
| 12195 | } else { | 12597 | } else { |
| 12196 | gop.value_ptr.abi_align = Value.initTag(.abi_align_default); | 12598 | gop.value_ptr.abi_align = Value.initTag(.abi_align_default); |
| ... | @@ -12200,7 +12602,7 @@ fn analyzeUnionFields( | ... | @@ -12200,7 +12602,7 @@ fn analyzeUnionFields( |
| 12200 | | 12602 | |
| 12201 | fn generateUnionTagTypeNumbered( | 12603 | fn generateUnionTagTypeNumbered( |
| 12202 | sema: *Sema, | 12604 | sema: *Sema, |
| 12203 | block: *Scope.Block, | 12605 | block: *Block, |
| 12204 | fields_len: u32, | 12606 | fields_len: u32, |
| 12205 | int_ty: Type, | 12607 | int_ty: Type, |
| 12206 | ) !Type { | 12608 | ) !Type { |
| ... | @@ -12218,12 +12620,12 @@ fn generateUnionTagTypeNumbered( | ... | @@ -12218,12 +12620,12 @@ fn generateUnionTagTypeNumbered( |
| 12218 | const enum_ty = Type.initPayload(&enum_ty_payload.base); | 12620 | const enum_ty = Type.initPayload(&enum_ty_payload.base); |
| 12219 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); | 12621 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); |
| 12220 | // TODO better type name | 12622 | // TODO better type name |
| 12221 | const new_decl = try mod.createAnonymousDecl(&block.base, .{ | 12623 | const new_decl = try mod.createAnonymousDecl(block, .{ |
| 12222 | .ty = Type.initTag(.type), | 12624 | .ty = Type.initTag(.type), |
| 12223 | .val = enum_val, | 12625 | .val = enum_val, |
| 12224 | }); | 12626 | }); |
| 12225 | new_decl.owns_tv = true; | 12627 | new_decl.owns_tv = true; |
| 12226 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 12628 | errdefer mod.abortAnonDecl(new_decl); |
| 12227 | | 12629 | |
| 12228 | enum_obj.* = .{ | 12630 | enum_obj.* = .{ |
| 12229 | .owner_decl = new_decl, | 12631 | .owner_decl = new_decl, |
| ... | @@ -12239,7 +12641,7 @@ fn generateUnionTagTypeNumbered( | ... | @@ -12239,7 +12641,7 @@ fn generateUnionTagTypeNumbered( |
| 12239 | return enum_ty; | 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 | const mod = sema.mod; | 12645 | const mod = sema.mod; |
| 12244 | | 12646 | |
| 12245 | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); | 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,12 +12656,12 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) |
| 12254 | const enum_ty = Type.initPayload(&enum_ty_payload.base); | 12656 | const enum_ty = Type.initPayload(&enum_ty_payload.base); |
| 12255 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); | 12657 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); |
| 12256 | // TODO better type name | 12658 | // TODO better type name |
| 12257 | const new_decl = try mod.createAnonymousDecl(&block.base, .{ | 12659 | const new_decl = try mod.createAnonymousDecl(block, .{ |
| 12258 | .ty = Type.initTag(.type), | 12660 | .ty = Type.initTag(.type), |
| 12259 | .val = enum_val, | 12661 | .val = enum_val, |
| 12260 | }); | 12662 | }); |
| 12261 | new_decl.owns_tv = true; | 12663 | new_decl.owns_tv = true; |
| 12262 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 12664 | errdefer mod.abortAnonDecl(new_decl); |
| 12263 | | 12665 | |
| 12264 | enum_obj.* = .{ | 12666 | enum_obj.* = .{ |
| 12265 | .owner_decl = new_decl, | 12667 | .owner_decl = new_decl, |
| ... | @@ -12274,7 +12676,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) | ... | @@ -12274,7 +12676,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) |
| 12274 | | 12676 | |
| 12275 | fn getBuiltin( | 12677 | fn getBuiltin( |
| 12276 | sema: *Sema, | 12678 | sema: *Sema, |
| 12277 | block: *Scope.Block, | 12679 | block: *Block, |
| 12278 | src: LazySrcLoc, | 12680 | src: LazySrcLoc, |
| 12279 | name: []const u8, | 12681 | name: []const u8, |
| 12280 | ) CompileError!Air.Inst.Ref { | 12682 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -12284,7 +12686,7 @@ fn getBuiltin( | ... | @@ -12284,7 +12686,7 @@ fn getBuiltin( |
| 12284 | const opt_builtin_inst = try sema.namespaceLookupRef( | 12686 | const opt_builtin_inst = try sema.namespaceLookupRef( |
| 12285 | block, | 12687 | block, |
| 12286 | src, | 12688 | src, |
| 12287 | std_file.root_decl.?.namespace, | 12689 | std_file.root_decl.?.src_namespace, |
| 12288 | "builtin", | 12690 | "builtin", |
| 12289 | ); | 12691 | ); |
| 12290 | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src); | 12692 | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src); |
| ... | @@ -12300,7 +12702,7 @@ fn getBuiltin( | ... | @@ -12300,7 +12702,7 @@ fn getBuiltin( |
| 12300 | | 12702 | |
| 12301 | fn getBuiltinType( | 12703 | fn getBuiltinType( |
| 12302 | sema: *Sema, | 12704 | sema: *Sema, |
| 12303 | block: *Scope.Block, | 12705 | block: *Block, |
| 12304 | src: LazySrcLoc, | 12706 | src: LazySrcLoc, |
| 12305 | name: []const u8, | 12707 | name: []const u8, |
| 12306 | ) CompileError!Type { | 12708 | ) CompileError!Type { |
| ... | @@ -12314,7 +12716,7 @@ fn getBuiltinType( | ... | @@ -12314,7 +12716,7 @@ fn getBuiltinType( |
| 12314 | /// that the types are already resolved. | 12716 | /// that the types are already resolved. |
| 12315 | fn typeHasOnePossibleValue( | 12717 | fn typeHasOnePossibleValue( |
| 12316 | sema: *Sema, | 12718 | sema: *Sema, |
| 12317 | block: *Scope.Block, | 12719 | block: *Block, |
| 12318 | src: LazySrcLoc, | 12720 | src: LazySrcLoc, |
| 12319 | starting_type: Type, | 12721 | starting_type: Type, |
| 12320 | ) CompileError!?Value { | 12722 | ) CompileError!?Value { |
| ... | @@ -12477,8 +12879,8 @@ fn typeHasOnePossibleValue( | ... | @@ -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 { | 12882 | fn getAstTree(sema: *Sema, block: *Block) CompileError!*const std.zig.Ast { |
| 12481 | return block.src_decl.namespace.file_scope.getTree(sema.gpa) catch |err| { | 12883 | return block.namespace.file_scope.getTree(sema.gpa) catch |err| { |
| 12482 | log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); | 12884 | log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); |
| 12483 | return error.AnalysisFail; | 12885 | return error.AnalysisFail; |
| 12484 | }; | 12886 | }; |
| ... | @@ -12667,7 +13069,7 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { | ... | @@ -12667,7 +13069,7 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { |
| 12667 | | 13069 | |
| 12668 | fn isComptimeKnown( | 13070 | fn isComptimeKnown( |
| 12669 | sema: *Sema, | 13071 | sema: *Sema, |
| 12670 | block: *Scope.Block, | 13072 | block: *Block, |
| 12671 | src: LazySrcLoc, | 13073 | src: LazySrcLoc, |
| 12672 | inst: Air.Inst.Ref, | 13074 | inst: Air.Inst.Ref, |
| 12673 | ) !bool { | 13075 | ) !bool { |
| ... | @@ -12676,7 +13078,7 @@ fn isComptimeKnown( | ... | @@ -12676,7 +13078,7 @@ fn isComptimeKnown( |
| 12676 | | 13078 | |
| 12677 | fn analyzeComptimeAlloc( | 13079 | fn analyzeComptimeAlloc( |
| 12678 | sema: *Sema, | 13080 | sema: *Sema, |
| 12679 | block: *Scope.Block, | 13081 | block: *Block, |
| 12680 | var_type: Type, | 13082 | var_type: Type, |
| 12681 | ) CompileError!Air.Inst.Ref { | 13083 | ) CompileError!Air.Inst.Ref { |
| 12682 | const ptr_type = try Type.ptr(sema.arena, .{ | 13084 | const ptr_type = try Type.ptr(sema.arena, .{ |
| ... | @@ -12719,7 +13121,7 @@ pub const AddressSpaceContext = enum { | ... | @@ -12719,7 +13121,7 @@ pub const AddressSpaceContext = enum { |
| 12719 | | 13121 | |
| 12720 | pub fn analyzeAddrspace( | 13122 | pub fn analyzeAddrspace( |
| 12721 | sema: *Sema, | 13123 | sema: *Sema, |
| 12722 | block: *Scope.Block, | 13124 | block: *Block, |
| 12723 | src: LazySrcLoc, | 13125 | src: LazySrcLoc, |
| 12724 | zir_ref: Zir.Inst.Ref, | 13126 | zir_ref: Zir.Inst.Ref, |
| 12725 | ctx: AddressSpaceContext, | 13127 | ctx: AddressSpaceContext, |
| ... | @@ -12743,8 +13145,8 @@ pub fn analyzeAddrspace( | ... | @@ -12743,8 +13145,8 @@ pub fn analyzeAddrspace( |
| 12743 | .pointer => "pointers", | 13145 | .pointer => "pointers", |
| 12744 | }; | 13146 | }; |
| 12745 | | 13147 | |
| 12746 | return sema.mod.fail( | 13148 | return sema.fail( |
| 12747 | &block.base, | 13149 | block, |
| 12748 | src, | 13150 | src, |
| 12749 | "{s} with address space '{s}' are not supported on {s}", | 13151 | "{s} with address space '{s}' are not supported on {s}", |
| 12750 | .{ entity, @tagName(address_space), arch.genericName() }, | 13152 | .{ entity, @tagName(address_space), arch.genericName() }, |