| ... | ... | @@ -1274,11 +1274,77 @@ pub const Type = struct { |
| 1274 | 1274 | }; |
| 1275 | 1275 | return writer.print("{c}{d}", .{ sign_char, int_type.bits }); |
| 1276 | 1276 | }, |
| 1277 | | .ptr_type => @panic("TODO"), |
| 1278 | | .array_type => @panic("TODO"), |
| 1279 | | .vector_type => @panic("TODO"), |
| 1280 | | .opt_type => @panic("TODO"), |
| 1281 | | .error_union_type => @panic("TODO"), |
| 1277 | .ptr_type => { |
| 1278 | const info = ty.ptrInfo(mod); |
| 1279 | |
| 1280 | if (info.sentinel) |s| switch (info.size) { |
| 1281 | .One, .C => unreachable, |
| 1282 | .Many => try writer.print("[*:{}]", .{s.fmtValue(info.pointee_type, mod)}), |
| 1283 | .Slice => try writer.print("[:{}]", .{s.fmtValue(info.pointee_type, mod)}), |
| 1284 | } else switch (info.size) { |
| 1285 | .One => try writer.writeAll("*"), |
| 1286 | .Many => try writer.writeAll("[*]"), |
| 1287 | .C => try writer.writeAll("[*c]"), |
| 1288 | .Slice => try writer.writeAll("[]"), |
| 1289 | } |
| 1290 | if (info.@"align" != 0 or info.host_size != 0 or info.vector_index != .none) { |
| 1291 | if (info.@"align" != 0) { |
| 1292 | try writer.print("align({d}", .{info.@"align"}); |
| 1293 | } else { |
| 1294 | const alignment = info.pointee_type.abiAlignment(mod); |
| 1295 | try writer.print("align({d}", .{alignment}); |
| 1296 | } |
| 1297 | |
| 1298 | if (info.bit_offset != 0 or info.host_size != 0) { |
| 1299 | try writer.print(":{d}:{d}", .{ info.bit_offset, info.host_size }); |
| 1300 | } |
| 1301 | if (info.vector_index == .runtime) { |
| 1302 | try writer.writeAll(":?"); |
| 1303 | } else if (info.vector_index != .none) { |
| 1304 | try writer.print(":{d}", .{@enumToInt(info.vector_index)}); |
| 1305 | } |
| 1306 | try writer.writeAll(") "); |
| 1307 | } |
| 1308 | if (info.@"addrspace" != .generic) { |
| 1309 | try writer.print("addrspace(.{s}) ", .{@tagName(info.@"addrspace")}); |
| 1310 | } |
| 1311 | if (!info.mutable) try writer.writeAll("const "); |
| 1312 | if (info.@"volatile") try writer.writeAll("volatile "); |
| 1313 | if (info.@"allowzero" and info.size != .C) try writer.writeAll("allowzero "); |
| 1314 | |
| 1315 | try print(info.pointee_type, writer, mod); |
| 1316 | return; |
| 1317 | }, |
| 1318 | .array_type => |array_type| { |
| 1319 | if (array_type.sentinel == .none) { |
| 1320 | try writer.print("[{d}]", .{array_type.len}); |
| 1321 | try print(array_type.child.toType(), writer, mod); |
| 1322 | } else { |
| 1323 | try writer.print("[{d}:{}]", .{ |
| 1324 | array_type.len, |
| 1325 | array_type.sentinel.toValue().fmtValue(array_type.child.toType(), mod), |
| 1326 | }); |
| 1327 | try print(array_type.child.toType(), writer, mod); |
| 1328 | } |
| 1329 | return; |
| 1330 | }, |
| 1331 | .vector_type => |vector_type| { |
| 1332 | try writer.print("@Vector({d}, ", .{vector_type.len}); |
| 1333 | try print(vector_type.child.toType(), writer, mod); |
| 1334 | try writer.writeAll(")"); |
| 1335 | return; |
| 1336 | }, |
| 1337 | .opt_type => |child| { |
| 1338 | try writer.writeByte('?'); |
| 1339 | try print(child.toType(), writer, mod); |
| 1340 | return; |
| 1341 | }, |
| 1342 | .error_union_type => |error_union_type| { |
| 1343 | try print(error_union_type.error_set_type.toType(), writer, mod); |
| 1344 | try writer.writeByte('!'); |
| 1345 | try print(error_union_type.payload_type.toType(), writer, mod); |
| 1346 | return; |
| 1347 | }, |
| 1282 | 1348 | .simple_type => |s| return writer.writeAll(@tagName(s)), |
| 1283 | 1349 | .struct_type => @panic("TODO"), |
| 1284 | 1350 | .union_type => @panic("TODO"), |
| ... | ... | @@ -2055,8 +2121,8 @@ pub const Type = struct { |
| 2055 | 2121 | return AbiAlignmentAdvanced{ .scalar = alignment }; |
| 2056 | 2122 | }, |
| 2057 | 2123 | |
| 2058 | | .opt_type => @panic("TODO"), |
| 2059 | | .error_union_type => @panic("TODO"), |
| 2124 | .opt_type => return abiAlignmentAdvancedOptional(ty, mod, strat), |
| 2125 | .error_union_type => return abiAlignmentAdvancedErrorUnion(ty, mod, strat), |
| 2060 | 2126 | .simple_type => |t| switch (t) { |
| 2061 | 2127 | .bool, |
| 2062 | 2128 | .atomic_order, |
| ... | ... | @@ -2157,64 +2223,8 @@ pub const Type = struct { |
| 2157 | 2223 | |
| 2158 | 2224 | .array, .array_sentinel => return ty.childType(mod).abiAlignmentAdvanced(mod, strat), |
| 2159 | 2225 | |
| 2160 | | .optional => { |
| 2161 | | const child_type = ty.optionalChild(mod); |
| 2162 | | |
| 2163 | | switch (child_type.zigTypeTag(mod)) { |
| 2164 | | .Pointer => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) }, |
| 2165 | | .ErrorSet => return abiAlignmentAdvanced(Type.anyerror, mod, strat), |
| 2166 | | .NoReturn => return AbiAlignmentAdvanced{ .scalar = 0 }, |
| 2167 | | else => {}, |
| 2168 | | } |
| 2169 | | |
| 2170 | | switch (strat) { |
| 2171 | | .eager, .sema => { |
| 2172 | | if (!(child_type.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 2173 | | error.NeedLazy => return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(strat.lazy, ty) }, |
| 2174 | | else => |e| return e, |
| 2175 | | })) { |
| 2176 | | return AbiAlignmentAdvanced{ .scalar = 1 }; |
| 2177 | | } |
| 2178 | | return child_type.abiAlignmentAdvanced(mod, strat); |
| 2179 | | }, |
| 2180 | | .lazy => |arena| switch (try child_type.abiAlignmentAdvanced(mod, strat)) { |
| 2181 | | .scalar => |x| return AbiAlignmentAdvanced{ .scalar = @max(x, 1) }, |
| 2182 | | .val => return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) }, |
| 2183 | | }, |
| 2184 | | } |
| 2185 | | }, |
| 2186 | | |
| 2187 | | .error_union => { |
| 2188 | | // This code needs to be kept in sync with the equivalent switch prong |
| 2189 | | // in abiSizeAdvanced. |
| 2190 | | const data = ty.castTag(.error_union).?.data; |
| 2191 | | const code_align = abiAlignment(Type.anyerror, mod); |
| 2192 | | switch (strat) { |
| 2193 | | .eager, .sema => { |
| 2194 | | if (!(data.payload.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 2195 | | error.NeedLazy => return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(strat.lazy, ty) }, |
| 2196 | | else => |e| return e, |
| 2197 | | })) { |
| 2198 | | return AbiAlignmentAdvanced{ .scalar = code_align }; |
| 2199 | | } |
| 2200 | | return AbiAlignmentAdvanced{ .scalar = @max( |
| 2201 | | code_align, |
| 2202 | | (try data.payload.abiAlignmentAdvanced(mod, strat)).scalar, |
| 2203 | | ) }; |
| 2204 | | }, |
| 2205 | | .lazy => |arena| { |
| 2206 | | switch (try data.payload.abiAlignmentAdvanced(mod, strat)) { |
| 2207 | | .scalar => |payload_align| { |
| 2208 | | return AbiAlignmentAdvanced{ |
| 2209 | | .scalar = @max(code_align, payload_align), |
| 2210 | | }; |
| 2211 | | }, |
| 2212 | | .val => {}, |
| 2213 | | } |
| 2214 | | return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) }; |
| 2215 | | }, |
| 2216 | | } |
| 2217 | | }, |
| 2226 | .optional => return abiAlignmentAdvancedOptional(ty, mod, strat), |
| 2227 | .error_union => return abiAlignmentAdvancedErrorUnion(ty, mod, strat), |
| 2218 | 2228 | |
| 2219 | 2229 | .@"struct" => { |
| 2220 | 2230 | const struct_obj = ty.castTag(.@"struct").?.data; |
| ... | ... | @@ -2321,6 +2331,74 @@ pub const Type = struct { |
| 2321 | 2331 | } |
| 2322 | 2332 | } |
| 2323 | 2333 | |
| 2334 | fn abiAlignmentAdvancedErrorUnion( |
| 2335 | ty: Type, |
| 2336 | mod: *const Module, |
| 2337 | strat: AbiAlignmentAdvancedStrat, |
| 2338 | ) Module.CompileError!AbiAlignmentAdvanced { |
| 2339 | // This code needs to be kept in sync with the equivalent switch prong |
| 2340 | // in abiSizeAdvanced. |
| 2341 | const data = ty.castTag(.error_union).?.data; |
| 2342 | const code_align = abiAlignment(Type.anyerror, mod); |
| 2343 | switch (strat) { |
| 2344 | .eager, .sema => { |
| 2345 | if (!(data.payload.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 2346 | error.NeedLazy => return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(strat.lazy, ty) }, |
| 2347 | else => |e| return e, |
| 2348 | })) { |
| 2349 | return AbiAlignmentAdvanced{ .scalar = code_align }; |
| 2350 | } |
| 2351 | return AbiAlignmentAdvanced{ .scalar = @max( |
| 2352 | code_align, |
| 2353 | (try data.payload.abiAlignmentAdvanced(mod, strat)).scalar, |
| 2354 | ) }; |
| 2355 | }, |
| 2356 | .lazy => |arena| { |
| 2357 | switch (try data.payload.abiAlignmentAdvanced(mod, strat)) { |
| 2358 | .scalar => |payload_align| { |
| 2359 | return AbiAlignmentAdvanced{ |
| 2360 | .scalar = @max(code_align, payload_align), |
| 2361 | }; |
| 2362 | }, |
| 2363 | .val => {}, |
| 2364 | } |
| 2365 | return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) }; |
| 2366 | }, |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | fn abiAlignmentAdvancedOptional( |
| 2371 | ty: Type, |
| 2372 | mod: *const Module, |
| 2373 | strat: AbiAlignmentAdvancedStrat, |
| 2374 | ) Module.CompileError!AbiAlignmentAdvanced { |
| 2375 | const target = mod.getTarget(); |
| 2376 | const child_type = ty.optionalChild(mod); |
| 2377 | |
| 2378 | switch (child_type.zigTypeTag(mod)) { |
| 2379 | .Pointer => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) }, |
| 2380 | .ErrorSet => return abiAlignmentAdvanced(Type.anyerror, mod, strat), |
| 2381 | .NoReturn => return AbiAlignmentAdvanced{ .scalar = 0 }, |
| 2382 | else => {}, |
| 2383 | } |
| 2384 | |
| 2385 | switch (strat) { |
| 2386 | .eager, .sema => { |
| 2387 | if (!(child_type.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 2388 | error.NeedLazy => return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(strat.lazy, ty) }, |
| 2389 | else => |e| return e, |
| 2390 | })) { |
| 2391 | return AbiAlignmentAdvanced{ .scalar = 1 }; |
| 2392 | } |
| 2393 | return child_type.abiAlignmentAdvanced(mod, strat); |
| 2394 | }, |
| 2395 | .lazy => |arena| switch (try child_type.abiAlignmentAdvanced(mod, strat)) { |
| 2396 | .scalar => |x| return AbiAlignmentAdvanced{ .scalar = @max(x, 1) }, |
| 2397 | .val => return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) }, |
| 2398 | }, |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2324 | 2402 | pub fn abiAlignmentAdvancedUnion( |
| 2325 | 2403 | ty: Type, |
| 2326 | 2404 | mod: *const Module, |