authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-17 22:34:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-17 22:34:06-07:00
log29daf10639149bd023db0be4e04eaf154dce0f83
tree13dc178febddc98b4cc72b6a4f341b796a2a008e
parent5a2620fcca55813d87000f3018e70509b1d325e0

stage2: fix a couple more compilation errors


4 files changed, 32 insertions(+), 46 deletions(-)

lib/std/zig/ast.zig+2-2
......@@ -2054,7 +2054,7 @@ pub const full = struct {
20542054 return null;
20552055 }
20562056 const param_type = it.fn_proto.ast.params[it.param_i];
2057 var tok_i = tree.firstToken(param_type) - 1;
2057 var tok_i = it.tree.firstToken(param_type) - 1;
20582058 while (true) : (tok_i -= 1) switch (token_tags[tok_i]) {
20592059 .colon => continue,
20602060 .identifier => name_token = tok_i,
......@@ -2063,7 +2063,7 @@ pub const full = struct {
20632063 else => break,
20642064 };
20652065 it.param_i += 1;
2066 it.tok_i = tree.lastToken(param_type) + 1;
2066 it.tok_i = it.tree.lastToken(param_type) + 1;
20672067 it.tok_flag = true;
20682068 return Param{
20692069 .first_doc_comment = first_doc_comment,
src/Module.zig+19-20
......@@ -1223,19 +1223,6 @@ fn astgenAndSemaFn(
12231223 .{},
12241224 );
12251225 }
1226 const opt_cc: ?*zir.Inst = if (fn_proto.ast.callconv_expr != 0) cc: {
1227 // TODO instead of enum literal type, this needs to be the
1228 // std.builtin.CallingConvention enum. We need to implement importing other files
1229 // and enums in order to fix this.
1230 const src = token_starts[tree.firstToken(fn_proto.ast.callconv_expr)];
1231 const enum_lit_ty = try astgen.addZIRInstConst(mod, &fn_type_scope.base, src, .{
1232 .ty = Type.initTag(.type),
1233 .val = Value.initTag(.enum_literal_type),
1234 });
1235 break :cc try astgen.comptimeExpr(mod, &fn_type_scope.base, .{
1236 .ty = enum_lit_ty,
1237 }, fn_proto.ast.callconv_expr);
1238 } else null;
12391226
12401227 const maybe_bang = tree.firstToken(fn_proto.ast.return_type) - 1;
12411228 if (token_tags[maybe_bang] == .bang) {
......@@ -1247,13 +1234,24 @@ fn astgenAndSemaFn(
12471234 type_type_rl,
12481235 fn_proto.ast.return_type,
12491236 );
1250 const fn_type_inst = if (opt_cc) |cc|
1251 try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type_cc, .{
1237 const fn_type_inst = if (fn_proto.ast.callconv_expr != 0) cc: {
1238 // TODO instead of enum literal type, this needs to be the
1239 // std.builtin.CallingConvention enum. We need to implement importing other files
1240 // and enums in order to fix this.
1241 const src = token_starts[tree.firstToken(fn_proto.ast.callconv_expr)];
1242 const enum_lit_ty = try astgen.addZIRInstConst(mod, &fn_type_scope.base, src, .{
1243 .ty = Type.initTag(.type),
1244 .val = Value.initTag(.enum_literal_type),
1245 });
1246 const cc = try astgen.comptimeExpr(mod, &fn_type_scope.base, .{
1247 .ty = enum_lit_ty,
1248 }, fn_proto.ast.callconv_expr);
1249 break :cc try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type_cc, .{
12521250 .return_type = return_type_inst,
12531251 .param_types = param_types,
12541252 .cc = cc,
1255 })
1256 else
1253 });
1254 } else
12571255 try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type, .{
12581256 .return_type = return_type_inst,
12591257 .param_types = param_types,
......@@ -1362,13 +1360,13 @@ fn astgenAndSemaFn(
13621360 params_scope = &sub_scope.base;
13631361 }
13641362
1365 try astgen.expr(mod, params_scope, .none, body_node);
1363 _ = try astgen.expr(mod, params_scope, .none, body_node);
13661364
13671365 if (gen_scope.instructions.items.len == 0 or
13681366 !gen_scope.instructions.items[gen_scope.instructions.items.len - 1].tag.isNoReturn())
13691367 {
13701368 const src = token_starts[tree.lastToken(body_node)];
1371 _ = try astgen.addZIRNoOp(mod, &gen_scope.base, src, .returnvoid);
1369 _ = try astgen.addZIRNoOp(mod, &gen_scope.base, src, .return_void);
13721370 }
13731371
13741372 if (std.builtin.mode == .Debug and mod.comp.verbose_ir) {
......@@ -1542,6 +1540,7 @@ fn astgenAndSemaVarDecl(
15421540 .decl = decl,
15431541 .arena = &gen_scope_arena.allocator,
15441542 .parent = &decl.container.base,
1543 .force_comptime = true,
15451544 };
15461545 defer gen_scope.instructions.deinit(mod.gpa);
15471546
......@@ -1600,7 +1599,7 @@ fn astgenAndSemaVarDecl(
16001599 } else if (!is_extern) {
16011600 return mod.failTok(
16021601 &block_scope.base,
1603 tree.firstToken(var_decl),
1602 var_decl.ast.mut_token,
16041603 "variables must be initialized",
16051604 .{},
16061605 );
src/astgen.zig+2-15
......@@ -539,6 +539,7 @@ pub fn comptimeExpr(
539539 }
540540
541541 const tree = parent_scope.tree();
542 const token_starts = tree.tokens.items(.start);
542543
543544 // Make a scope to collect generated instructions in the sub-expression.
544545 var block_scope: Scope.GenZIR = .{
......@@ -693,7 +694,7 @@ pub fn blockExpr(
693694 rl: ResultLoc,
694695 block_node: ast.Node.Index,
695696 statements: []const ast.Node.Index,
696) InnerError!void {
697) InnerError!*zir.Inst {
697698 const tracy = trace(@src());
698699 defer tracy.end();
699700
......@@ -1174,20 +1175,6 @@ fn negation(
11741175 return addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);
11751176}
11761177
1177fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir.Inst {
1178 const tree = scope.tree();
1179 const src = token_starts[node.op_token];
1180 return ptrSliceType(mod, scope, src, &node.ptr_info, node.rhs, switch (tree.token_ids[node.op_token]) {
1181 .Asterisk, .AsteriskAsterisk => .One,
1182 // TODO stage1 type inference bug
1183 .LBracket => @as(std.builtin.TypeInfo.Pointer.Size, switch (tree.token_ids[node.op_token + 2]) {
1184 .identifier => .C,
1185 else => .Many,
1186 }),
1187 else => unreachable,
1188 });
1189}
1190
11911178fn ptrSliceType(mod: *Module, scope: *Scope, src: usize, ptr_info: *ast.PtrInfo, rhs: *ast.Node, size: std.builtin.TypeInfo.Pointer.Size) InnerError!*zir.Inst {
11921179 const simple = ptr_info.allowzero_token == null and
11931180 ptr_info.align_info == null and
src/zir_sema.zig+9-9
......@@ -981,8 +981,8 @@ fn zirCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst {
981981 const ret_type = func.ty.fnReturnType();
982982
983983 const b = try mod.requireFunctionBlock(scope, inst.base.src);
984 const is_comptime_call = b.is_comptime or inst.kw_args.modifier == .compile_time;
985 const is_inline_call = is_comptime_call or inst.kw_args.modifier == .always_inline or
984 const is_comptime_call = b.is_comptime or inst.positionals.modifier == .compile_time;
985 const is_inline_call = is_comptime_call or inst.positionals.modifier == .always_inline or
986986 func.ty.fnCallingConvention() == .Inline;
987987 if (is_inline_call) {
988988 const func_val = try mod.resolveConstValue(scope, func);
......@@ -1668,13 +1668,13 @@ fn zirSwitchBr(mod: *Module, scope: *Scope, inst: *zir.Inst.SwitchBr, ref: bool)
16681668
16691669fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.SwitchBr) InnerError!void {
16701670 // validate usage of '_' prongs
1671 if (inst.kw_args.special_prong == .underscore and target.ty.zigTypeTag() != .Enum) {
1671 if (inst.positionals.special_prong == .underscore and target.ty.zigTypeTag() != .Enum) {
16721672 return mod.fail(scope, inst.base.src, "'_' prong only allowed when switching on non-exhaustive enums", .{});
16731673 // TODO notes "'_' prong here" inst.positionals.cases[last].src
16741674 }
16751675
16761676 // check that target type supports ranges
1677 if (inst.kw_args.range) |range_inst| {
1677 if (inst.positionals.range) |range_inst| {
16781678 switch (target.ty.zigTypeTag()) {
16791679 .Int, .ComptimeInt => {},
16801680 else => {
......@@ -1725,14 +1725,14 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw
17251725 const start = try target.ty.minInt(&arena, mod.getTarget());
17261726 const end = try target.ty.maxInt(&arena, mod.getTarget());
17271727 if (try range_set.spans(start, end)) {
1728 if (inst.kw_args.special_prong == .@"else") {
1728 if (inst.positionals.special_prong == .@"else") {
17291729 return mod.fail(scope, inst.base.src, "unreachable else prong, all cases already handled", .{});
17301730 }
17311731 return;
17321732 }
17331733 }
17341734
1735 if (inst.kw_args.special_prong != .@"else") {
1735 if (inst.positionals.special_prong != .@"else") {
17361736 return mod.fail(scope, inst.base.src, "switch must handle all possibilities", .{});
17371737 }
17381738 },
......@@ -1752,15 +1752,15 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw
17521752 return mod.fail(scope, item.src, "duplicate switch value", .{});
17531753 }
17541754 }
1755 if ((true_count + false_count < 2) and inst.kw_args.special_prong != .@"else") {
1755 if ((true_count + false_count < 2) and inst.positionals.special_prong != .@"else") {
17561756 return mod.fail(scope, inst.base.src, "switch must handle all possibilities", .{});
17571757 }
1758 if ((true_count + false_count == 2) and inst.kw_args.special_prong == .@"else") {
1758 if ((true_count + false_count == 2) and inst.positionals.special_prong == .@"else") {
17591759 return mod.fail(scope, inst.base.src, "unreachable else prong, all cases already handled", .{});
17601760 }
17611761 },
17621762 .EnumLiteral, .Void, .Fn, .Pointer, .Type => {
1763 if (inst.kw_args.special_prong != .@"else") {
1763 if (inst.positionals.special_prong != .@"else") {
17641764 return mod.fail(scope, inst.base.src, "else prong required when switching on type '{}'", .{target.ty});
17651765 }
17661766