diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-02-17 22:34:06 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-02-17 22:34:06 -0700 |
| commit | 29daf10639149bd023db0be4e04eaf154dce0f83 (patch) | |
| tree | 13dc178febddc98b4cc72b6a4f341b796a2a008e /src | |
| parent | 5a2620fcca55813d87000f3018e70509b1d325e0 (diff) | |
| download | zig-29daf10639149bd023db0be4e04eaf154dce0f83.tar.gz zig-29daf10639149bd023db0be4e04eaf154dce0f83.zip | |
stage2: fix a couple more compilation errors
Diffstat (limited to 'src')
| -rw-r--r-- | src/Module.zig | 39 | ||||
| -rw-r--r-- | src/astgen.zig | 17 | ||||
| -rw-r--r-- | src/zir_sema.zig | 18 |
3 files changed, 30 insertions, 44 deletions
diff --git a/src/Module.zig b/src/Module.zig index 17084677d4..d2530d7df3 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1223,19 +1223,6 @@ fn astgenAndSemaFn( .{}, ); } - const opt_cc: ?*zir.Inst = if (fn_proto.ast.callconv_expr != 0) cc: { - // TODO instead of enum literal type, this needs to be the - // std.builtin.CallingConvention enum. We need to implement importing other files - // and enums in order to fix this. - const src = token_starts[tree.firstToken(fn_proto.ast.callconv_expr)]; - const enum_lit_ty = try astgen.addZIRInstConst(mod, &fn_type_scope.base, src, .{ - .ty = Type.initTag(.type), - .val = Value.initTag(.enum_literal_type), - }); - break :cc try astgen.comptimeExpr(mod, &fn_type_scope.base, .{ - .ty = enum_lit_ty, - }, fn_proto.ast.callconv_expr); - } else null; const maybe_bang = tree.firstToken(fn_proto.ast.return_type) - 1; if (token_tags[maybe_bang] == .bang) { @@ -1247,13 +1234,24 @@ fn astgenAndSemaFn( type_type_rl, fn_proto.ast.return_type, ); - const fn_type_inst = if (opt_cc) |cc| - try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type_cc, .{ + const fn_type_inst = if (fn_proto.ast.callconv_expr != 0) cc: { + // TODO instead of enum literal type, this needs to be the + // std.builtin.CallingConvention enum. We need to implement importing other files + // and enums in order to fix this. + const src = token_starts[tree.firstToken(fn_proto.ast.callconv_expr)]; + const enum_lit_ty = try astgen.addZIRInstConst(mod, &fn_type_scope.base, src, .{ + .ty = Type.initTag(.type), + .val = Value.initTag(.enum_literal_type), + }); + const cc = try astgen.comptimeExpr(mod, &fn_type_scope.base, .{ + .ty = enum_lit_ty, + }, fn_proto.ast.callconv_expr); + break :cc try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type_cc, .{ .return_type = return_type_inst, .param_types = param_types, .cc = cc, - }) - else + }); + } else try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type, .{ .return_type = return_type_inst, .param_types = param_types, @@ -1362,13 +1360,13 @@ fn astgenAndSemaFn( params_scope = &sub_scope.base; } - try astgen.expr(mod, params_scope, .none, body_node); + _ = try astgen.expr(mod, params_scope, .none, body_node); if (gen_scope.instructions.items.len == 0 or !gen_scope.instructions.items[gen_scope.instructions.items.len - 1].tag.isNoReturn()) { const src = token_starts[tree.lastToken(body_node)]; - _ = try astgen.addZIRNoOp(mod, &gen_scope.base, src, .returnvoid); + _ = try astgen.addZIRNoOp(mod, &gen_scope.base, src, .return_void); } if (std.builtin.mode == .Debug and mod.comp.verbose_ir) { @@ -1542,6 +1540,7 @@ fn astgenAndSemaVarDecl( .decl = decl, .arena = &gen_scope_arena.allocator, .parent = &decl.container.base, + .force_comptime = true, }; defer gen_scope.instructions.deinit(mod.gpa); @@ -1600,7 +1599,7 @@ fn astgenAndSemaVarDecl( } else if (!is_extern) { return mod.failTok( &block_scope.base, - tree.firstToken(var_decl), + var_decl.ast.mut_token, "variables must be initialized", .{}, ); diff --git a/src/astgen.zig b/src/astgen.zig index 125e9bceda..a018d58d2f 100644 --- a/src/astgen.zig +++ b/src/astgen.zig @@ -539,6 +539,7 @@ pub fn comptimeExpr( } const tree = parent_scope.tree(); + const token_starts = tree.tokens.items(.start); // Make a scope to collect generated instructions in the sub-expression. var block_scope: Scope.GenZIR = .{ @@ -693,7 +694,7 @@ pub fn blockExpr( rl: ResultLoc, block_node: ast.Node.Index, statements: []const ast.Node.Index, -) InnerError!void { +) InnerError!*zir.Inst { const tracy = trace(@src()); defer tracy.end(); @@ -1174,20 +1175,6 @@ fn negation( return addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs); } -fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir.Inst { - const tree = scope.tree(); - const src = token_starts[node.op_token]; - return ptrSliceType(mod, scope, src, &node.ptr_info, node.rhs, switch (tree.token_ids[node.op_token]) { - .Asterisk, .AsteriskAsterisk => .One, - // TODO stage1 type inference bug - .LBracket => @as(std.builtin.TypeInfo.Pointer.Size, switch (tree.token_ids[node.op_token + 2]) { - .identifier => .C, - else => .Many, - }), - else => unreachable, - }); -} - fn ptrSliceType(mod: *Module, scope: *Scope, src: usize, ptr_info: *ast.PtrInfo, rhs: *ast.Node, size: std.builtin.TypeInfo.Pointer.Size) InnerError!*zir.Inst { const simple = ptr_info.allowzero_token == null and ptr_info.align_info == null and diff --git a/src/zir_sema.zig b/src/zir_sema.zig index 1a2e99ded5..83d7113c9c 100644 --- a/src/zir_sema.zig +++ b/src/zir_sema.zig @@ -981,8 +981,8 @@ fn zirCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst { const ret_type = func.ty.fnReturnType(); const b = try mod.requireFunctionBlock(scope, inst.base.src); - const is_comptime_call = b.is_comptime or inst.kw_args.modifier == .compile_time; - const is_inline_call = is_comptime_call or inst.kw_args.modifier == .always_inline or + const is_comptime_call = b.is_comptime or inst.positionals.modifier == .compile_time; + const is_inline_call = is_comptime_call or inst.positionals.modifier == .always_inline or func.ty.fnCallingConvention() == .Inline; if (is_inline_call) { const func_val = try mod.resolveConstValue(scope, func); @@ -1668,13 +1668,13 @@ fn zirSwitchBr(mod: *Module, scope: *Scope, inst: *zir.Inst.SwitchBr, ref: bool) fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.SwitchBr) InnerError!void { // validate usage of '_' prongs - if (inst.kw_args.special_prong == .underscore and target.ty.zigTypeTag() != .Enum) { + if (inst.positionals.special_prong == .underscore and target.ty.zigTypeTag() != .Enum) { return mod.fail(scope, inst.base.src, "'_' prong only allowed when switching on non-exhaustive enums", .{}); // TODO notes "'_' prong here" inst.positionals.cases[last].src } // check that target type supports ranges - if (inst.kw_args.range) |range_inst| { + if (inst.positionals.range) |range_inst| { switch (target.ty.zigTypeTag()) { .Int, .ComptimeInt => {}, else => { @@ -1725,14 +1725,14 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw const start = try target.ty.minInt(&arena, mod.getTarget()); const end = try target.ty.maxInt(&arena, mod.getTarget()); if (try range_set.spans(start, end)) { - if (inst.kw_args.special_prong == .@"else") { + if (inst.positionals.special_prong == .@"else") { return mod.fail(scope, inst.base.src, "unreachable else prong, all cases already handled", .{}); } return; } } - if (inst.kw_args.special_prong != .@"else") { + if (inst.positionals.special_prong != .@"else") { return mod.fail(scope, inst.base.src, "switch must handle all possibilities", .{}); } }, @@ -1752,15 +1752,15 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw return mod.fail(scope, item.src, "duplicate switch value", .{}); } } - if ((true_count + false_count < 2) and inst.kw_args.special_prong != .@"else") { + if ((true_count + false_count < 2) and inst.positionals.special_prong != .@"else") { return mod.fail(scope, inst.base.src, "switch must handle all possibilities", .{}); } - if ((true_count + false_count == 2) and inst.kw_args.special_prong == .@"else") { + if ((true_count + false_count == 2) and inst.positionals.special_prong == .@"else") { return mod.fail(scope, inst.base.src, "unreachable else prong, all cases already handled", .{}); } }, .EnumLiteral, .Void, .Fn, .Pointer, .Type => { - if (inst.kw_args.special_prong != .@"else") { + if (inst.positionals.special_prong != .@"else") { return mod.fail(scope, inst.base.src, "else prong required when switching on type '{}'", .{target.ty}); } |
