Skip to content

Commit 6e0de1d

Browse files
jacobly0andrewrk
authored andcommitted
InternPool: port most of value tags
1 parent 5555bdc commit 6e0de1d

34 files changed

+5236
-6010
lines changed

lib/std/array_list.zig

+44
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,28 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
459459
return self.items[prev_len..][0..n];
460460
}
461461

462+
/// Resize the array, adding `n` new elements, which have `undefined` values.
463+
/// The return value is a slice pointing to the newly allocated elements.
464+
/// The returned pointer becomes invalid when the list is resized.
465+
/// Resizes list if `self.capacity` is not large enough.
466+
pub fn addManyAsSlice(self: *Self, n: usize) Allocator.Error![]T {
467+
const prev_len = self.items.len;
468+
try self.resize(self.items.len + n);
469+
return self.items[prev_len..][0..n];
470+
}
471+
472+
/// Resize the array, adding `n` new elements, which have `undefined` values.
473+
/// The return value is a slice pointing to the newly allocated elements.
474+
/// Asserts that there is already space for the new item without allocating more.
475+
/// **Does not** invalidate element pointers.
476+
/// The returned pointer becomes invalid when the list is resized.
477+
pub fn addManyAsSliceAssumeCapacity(self: *Self, n: usize) []T {
478+
assert(self.items.len + n <= self.capacity);
479+
const prev_len = self.items.len;
480+
self.items.len += n;
481+
return self.items[prev_len..][0..n];
482+
}
483+
462484
/// Remove and return the last element from the list.
463485
/// Asserts the list has at least one item.
464486
/// Invalidates pointers to the removed element.
@@ -949,6 +971,28 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
949971
return self.items[prev_len..][0..n];
950972
}
951973

974+
/// Resize the array, adding `n` new elements, which have `undefined` values.
975+
/// The return value is a slice pointing to the newly allocated elements.
976+
/// The returned pointer becomes invalid when the list is resized.
977+
/// Resizes list if `self.capacity` is not large enough.
978+
pub fn addManyAsSlice(self: *Self, allocator: Allocator, n: usize) Allocator.Error![]T {
979+
const prev_len = self.items.len;
980+
try self.resize(allocator, self.items.len + n);
981+
return self.items[prev_len..][0..n];
982+
}
983+
984+
/// Resize the array, adding `n` new elements, which have `undefined` values.
985+
/// The return value is a slice pointing to the newly allocated elements.
986+
/// Asserts that there is already space for the new item without allocating more.
987+
/// **Does not** invalidate element pointers.
988+
/// The returned pointer becomes invalid when the list is resized.
989+
pub fn addManyAsSliceAssumeCapacity(self: *Self, n: usize) []T {
990+
assert(self.items.len + n <= self.capacity);
991+
const prev_len = self.items.len;
992+
self.items.len += n;
993+
return self.items[prev_len..][0..n];
994+
}
995+
952996
/// Remove and return the last element from the list.
953997
/// Asserts the list has at least one item.
954998
/// Invalidates pointers to last element.

src/Air.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,8 @@ pub const Inst = struct {
901901
manyptr_const_u8_type = @enumToInt(InternPool.Index.manyptr_const_u8_type),
902902
manyptr_const_u8_sentinel_0_type = @enumToInt(InternPool.Index.manyptr_const_u8_sentinel_0_type),
903903
single_const_pointer_to_comptime_int_type = @enumToInt(InternPool.Index.single_const_pointer_to_comptime_int_type),
904-
const_slice_u8_type = @enumToInt(InternPool.Index.const_slice_u8_type),
905-
const_slice_u8_sentinel_0_type = @enumToInt(InternPool.Index.const_slice_u8_sentinel_0_type),
904+
slice_const_u8_type = @enumToInt(InternPool.Index.slice_const_u8_type),
905+
slice_const_u8_sentinel_0_type = @enumToInt(InternPool.Index.slice_const_u8_sentinel_0_type),
906906
anyerror_void_error_union_type = @enumToInt(InternPool.Index.anyerror_void_error_union_type),
907907
generic_poison_type = @enumToInt(InternPool.Index.generic_poison_type),
908908
inferred_alloc_const_type = @enumToInt(InternPool.Index.inferred_alloc_const_type),
@@ -1382,7 +1382,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
13821382

13831383
.bool_to_int => return Type.u1,
13841384

1385-
.tag_name, .error_name => return Type.const_slice_u8_sentinel_0,
1385+
.tag_name, .error_name => return Type.slice_const_u8_sentinel_0,
13861386

13871387
.call, .call_always_tail, .call_never_tail, .call_never_inline => {
13881388
const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip);

src/AstGen.zig

+15-15
Original file line numberDiff line numberDiff line change
@@ -3934,7 +3934,7 @@ fn fnDecl(
39343934
var section_gz = decl_gz.makeSubBlock(params_scope);
39353935
defer section_gz.unstack();
39363936
const section_ref: Zir.Inst.Ref = if (fn_proto.ast.section_expr == 0) .none else inst: {
3937-
const inst = try expr(&decl_gz, params_scope, .{ .rl = .{ .coerced_ty = .const_slice_u8_type } }, fn_proto.ast.section_expr);
3937+
const inst = try expr(&decl_gz, params_scope, .{ .rl = .{ .coerced_ty = .slice_const_u8_type } }, fn_proto.ast.section_expr);
39383938
if (section_gz.instructionsSlice().len == 0) {
39393939
// In this case we will send a len=0 body which can be encoded more efficiently.
39403940
break :inst inst;
@@ -4137,7 +4137,7 @@ fn globalVarDecl(
41374137
break :inst try expr(&block_scope, &block_scope.base, .{ .rl = .{ .ty = .address_space_type } }, var_decl.ast.addrspace_node);
41384138
};
41394139
const section_inst: Zir.Inst.Ref = if (var_decl.ast.section_node == 0) .none else inst: {
4140-
break :inst try comptimeExpr(&block_scope, &block_scope.base, .{ .rl = .{ .ty = .const_slice_u8_type } }, var_decl.ast.section_node);
4140+
break :inst try comptimeExpr(&block_scope, &block_scope.base, .{ .rl = .{ .ty = .slice_const_u8_type } }, var_decl.ast.section_node);
41414141
};
41424142
const has_section_or_addrspace = section_inst != .none or addrspace_inst != .none;
41434143
wip_members.nextDecl(is_pub, is_export, align_inst != .none, has_section_or_addrspace);
@@ -7878,7 +7878,7 @@ fn unionInit(
78787878
params: []const Ast.Node.Index,
78797879
) InnerError!Zir.Inst.Ref {
78807880
const union_type = try typeExpr(gz, scope, params[0]);
7881-
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[1]);
7881+
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[1]);
78827882
const field_type = try gz.addPlNode(.field_type_ref, params[1], Zir.Inst.FieldTypeRef{
78837883
.container_type = union_type,
78847884
.field_name = field_name,
@@ -8100,12 +8100,12 @@ fn builtinCall(
81008100
if (ri.rl == .ref) {
81018101
return gz.addPlNode(.field_ptr_named, node, Zir.Inst.FieldNamed{
81028102
.lhs = try expr(gz, scope, .{ .rl = .ref }, params[0]),
8103-
.field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[1]),
8103+
.field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[1]),
81048104
});
81058105
}
81068106
const result = try gz.addPlNode(.field_val_named, node, Zir.Inst.FieldNamed{
81078107
.lhs = try expr(gz, scope, .{ .rl = .none }, params[0]),
8108-
.field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[1]),
8108+
.field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[1]),
81098109
});
81108110
return rvalue(gz, ri, result, node);
81118111
},
@@ -8271,11 +8271,11 @@ fn builtinCall(
82718271
.align_of => return simpleUnOpType(gz, scope, ri, node, params[0], .align_of),
82728272

82738273
.ptr_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .ptr_to_int),
8274-
.compile_error => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[0], .compile_error),
8274+
.compile_error => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .compile_error),
82758275
.set_eval_branch_quota => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .set_eval_branch_quota),
82768276
.enum_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .enum_to_int),
82778277
.bool_to_int => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .bool_to_int),
8278-
.embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[0], .embed_file),
8278+
.embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .embed_file),
82798279
.error_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .anyerror_type } }, params[0], .error_name),
82808280
.set_runtime_safety => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_runtime_safety),
82818281
.sqrt => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .sqrt),
@@ -8334,7 +8334,7 @@ fn builtinCall(
83348334
},
83358335
.panic => {
83368336
try emitDbgNode(gz, node);
8337-
return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[0], .panic);
8337+
return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .panic);
83388338
},
83398339
.trap => {
83408340
try emitDbgNode(gz, node);
@@ -8450,7 +8450,7 @@ fn builtinCall(
84508450
},
84518451
.c_define => {
84528452
if (!gz.c_import) return gz.astgen.failNode(node, "C define valid only inside C import block", .{});
8453-
const name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[0]);
8453+
const name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0]);
84548454
const value = try comptimeExpr(gz, scope, .{ .rl = .none }, params[1]);
84558455
const result = try gz.addExtendedPayload(.c_define, Zir.Inst.BinNode{
84568456
.node = gz.nodeIndexToRelative(node),
@@ -8546,7 +8546,7 @@ fn builtinCall(
85468546
},
85478547
.field_parent_ptr => {
85488548
const parent_type = try typeExpr(gz, scope, params[0]);
8549-
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[1]);
8549+
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[1]);
85508550
const result = try gz.addPlNode(.field_parent_ptr, node, Zir.Inst.FieldParentPtr{
85518551
.parent_type = parent_type,
85528552
.field_name = field_name,
@@ -8701,7 +8701,7 @@ fn hasDeclOrField(
87018701
tag: Zir.Inst.Tag,
87028702
) InnerError!Zir.Inst.Ref {
87038703
const container_type = try typeExpr(gz, scope, lhs_node);
8704-
const name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, rhs_node);
8704+
const name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, rhs_node);
87058705
const result = try gz.addPlNode(tag, node, Zir.Inst.Bin{
87068706
.lhs = container_type,
87078707
.rhs = name,
@@ -8851,7 +8851,7 @@ fn simpleCBuiltin(
88518851
) InnerError!Zir.Inst.Ref {
88528852
const name: []const u8 = if (tag == .c_undef) "C undef" else "C include";
88538853
if (!gz.c_import) return gz.astgen.failNode(node, "{s} valid only inside C import block", .{name});
8854-
const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, operand_node);
8854+
const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, operand_node);
88558855
_ = try gz.addExtendedPayload(tag, Zir.Inst.UnNode{
88568856
.node = gz.nodeIndexToRelative(node),
88578857
.operand = operand,
@@ -8869,7 +8869,7 @@ fn offsetOf(
88698869
tag: Zir.Inst.Tag,
88708870
) InnerError!Zir.Inst.Ref {
88718871
const type_inst = try typeExpr(gz, scope, lhs_node);
8872-
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .const_slice_u8_type } }, rhs_node);
8872+
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, rhs_node);
88738873
const result = try gz.addPlNode(tag, node, Zir.Inst.Bin{
88748874
.lhs = type_inst,
88758875
.rhs = field_name,
@@ -10317,8 +10317,8 @@ fn rvalue(
1031710317
as_ty | @enumToInt(Zir.Inst.Ref.manyptr_const_u8_type),
1031810318
as_ty | @enumToInt(Zir.Inst.Ref.manyptr_const_u8_sentinel_0_type),
1031910319
as_ty | @enumToInt(Zir.Inst.Ref.single_const_pointer_to_comptime_int_type),
10320-
as_ty | @enumToInt(Zir.Inst.Ref.const_slice_u8_type),
10321-
as_ty | @enumToInt(Zir.Inst.Ref.const_slice_u8_sentinel_0_type),
10320+
as_ty | @enumToInt(Zir.Inst.Ref.slice_const_u8_type),
10321+
as_ty | @enumToInt(Zir.Inst.Ref.slice_const_u8_sentinel_0_type),
1032210322
as_ty | @enumToInt(Zir.Inst.Ref.anyerror_void_error_union_type),
1032310323
as_ty | @enumToInt(Zir.Inst.Ref.generic_poison_type),
1032410324
as_ty | @enumToInt(Zir.Inst.Ref.empty_struct_type),

src/Compilation.zig

+3-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const Job = union(enum) {
226226
/// Write the constant value for a Decl to the output file.
227227
codegen_decl: Module.Decl.Index,
228228
/// Write the machine code for a function to the output file.
229-
codegen_func: *Module.Fn,
229+
codegen_func: Module.Fn.Index,
230230
/// Render the .h file snippet for the Decl.
231231
emit_h_decl: Module.Decl.Index,
232232
/// The Decl needs to be analyzed and possibly export itself.
@@ -3208,7 +3208,8 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v
32083208
// Tests are always emitted in test binaries. The decl_refs are created by
32093209
// Module.populateTestFunctions, but this will not queue body analysis, so do
32103210
// that now.
3211-
try module.ensureFuncBodyAnalysisQueued(decl.val.castTag(.function).?.data);
3211+
const func_index = module.intern_pool.indexToFunc(decl.val.ip_index).unwrap().?;
3212+
try module.ensureFuncBodyAnalysisQueued(func_index);
32123213
}
32133214
},
32143215
.update_embed_file => |embed_file| {

0 commit comments

Comments
 (0)