authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-06 15:56:46+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-06 14:51:20-07:00
log3e2defd36c0bf90a0604a7618f57beaa4077139c
tree1563d8f360905a5200d19c613203c98d76b33992
parentb300eecb9da8f9ea0baffe737eb595df3c12381f

stage2: add a helpful error for when async is used


2 files changed, 33 insertions(+), 14 deletions(-)

src/AstGen.zig+6-1
...@@ -859,7 +859,12 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr...@@ -859,7 +859,12 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr
859 },859 },
860 .enum_literal => return simpleStrTok(gz, rl, main_tokens[node], node, .enum_literal),860 .enum_literal => return simpleStrTok(gz, rl, main_tokens[node], node, .enum_literal),
861 .error_value => return simpleStrTok(gz, rl, node_datas[node].rhs, node, .error_value),861 .error_value => return simpleStrTok(gz, rl, node_datas[node].rhs, node, .error_value),
862 .anyframe_literal => return rvalue(gz, rl, .anyframe_type, node),862 // TODO restore this when implementing https://github.com/ziglang/zig/issues/6025
863 // .anyframe_literal => return rvalue(gz, rl, .anyframe_type, node),
864 .anyframe_literal => {
865 const result = try gz.addUnNode(.anyframe_type, .void_type, node);
866 return rvalue(gz, rl, result, node);
867 },
863 .anyframe_type => {868 .anyframe_type => {
864 const return_type = try typeExpr(gz, scope, node_datas[node].rhs);869 const return_type = try typeExpr(gz, scope, node_datas[node].rhs);
865 const result = try gz.addUnNode(.anyframe_type, return_type, node);870 const result = try gz.addUnNode(.anyframe_type, return_type, node);
src/Sema.zig+27-13
...@@ -1828,6 +1828,17 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS...@@ -1828,6 +1828,17 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS
1828 return sema.failWithOwnedErrorMsg(msg);1828 return sema.failWithOwnedErrorMsg(msg);
1829}1829}
18301830
1831fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
1832 const msg = msg: {
1833 const msg = try sema.errMsg(block, src, "async has not been implemented in the self-hosted compiler yet", .{});
1834 errdefer msg.destroy(sema.gpa);
1835
1836 try sema.errNote(block, src, msg, "to use async enable the stage1 compiler with either '-fstage1' or by setting '.use_stage1 = true` in your 'build.zig' script", .{});
1837 break :msg msg;
1838 };
1839 return sema.failWithOwnedErrorMsg(msg);
1840}
1841
1831/// We don't return a pointer to the new error note because the pointer1842/// We don't return a pointer to the new error note because the pointer
1832/// becomes invalid when you add another one.1843/// becomes invalid when you add another one.
1833fn errNote(1844fn errNote(
...@@ -4776,7 +4787,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -4776,7 +4787,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
4776fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4787fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4777 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4788 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4778 const src = inst_data.src();4789 const src = inst_data.src();
4779 return sema.fail(parent_block, src, "TODO: implement Sema.zirSuspendBlock", .{});4790 return sema.failWithUseOfAsync(parent_block, src);
4780}4791}
47814792
4782fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4793fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -5613,7 +5624,7 @@ fn analyzeCall(...@@ -5613,7 +5624,7 @@ fn analyzeCall(
5613 .never_inline => Air.Inst.Tag.call_never_inline,5624 .never_inline => Air.Inst.Tag.call_never_inline,
5614 .always_tail => Air.Inst.Tag.call_always_tail,5625 .always_tail => Air.Inst.Tag.call_always_tail,
56155626
5616 .async_kw => return sema.fail(block, call_src, "TODO implement async call", .{}),5627 .async_kw => return sema.failWithUseOfAsync(block, call_src),
5617 };5628 };
56185629
5619 if (modifier == .never_inline and func_ty_info.cc == .Inline) {5630 if (modifier == .never_inline and func_ty_info.cc == .Inline) {
...@@ -6657,6 +6668,9 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -6657,6 +6668,9 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
6657 defer tracy.end();6668 defer tracy.end();
66586669
6659 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6670 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6671 if (true) {
6672 return sema.failWithUseOfAsync(block, inst_data.src());
6673 }
6660 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };6674 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };
6661 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);6675 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
6662 const anyframe_type = try Type.Tag.anyframe_T.create(sema.arena, return_type);6676 const anyframe_type = try Type.Tag.anyframe_T.create(sema.arena, return_type);
...@@ -14141,8 +14155,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14141,8 +14155,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14141 );14155 );
14142 },14156 },
14143 .BoundFn => @panic("TODO remove this type from the language and compiler"),14157 .BoundFn => @panic("TODO remove this type from the language and compiler"),
14144 .Frame => return sema.fail(block, src, "TODO: implement zirTypeInfo for Frame", .{}),14158 .Frame => return sema.failWithUseOfAsync(block, src),
14145 .AnyFrame => return sema.fail(block, src, "TODO: implement zirTypeInfo for AnyFrame", .{}),14159 .AnyFrame => return sema.failWithUseOfAsync(block, src),
14146 }14160 }
14147}14161}
1414814162
...@@ -15787,7 +15801,7 @@ fn zirFrame(...@@ -15787,7 +15801,7 @@ fn zirFrame(
15787 extended: Zir.Inst.Extended.InstData,15801 extended: Zir.Inst.Extended.InstData,
15788) CompileError!Air.Inst.Ref {15802) CompileError!Air.Inst.Ref {
15789 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));15803 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
15790 return sema.fail(block, src, "TODO: Sema.zirFrame", .{});15804 return sema.failWithUseOfAsync(block, src);
15791}15805}
1579215806
15793fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15807fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -15976,7 +15990,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -15976,7 +15990,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
15976 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,15990 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
15977 .Undefined => return Air.Inst.Ref.undefined_type,15991 .Undefined => return Air.Inst.Ref.undefined_type,
15978 .Null => return Air.Inst.Ref.null_type,15992 .Null => return Air.Inst.Ref.null_type,
15979 .AnyFrame => return Air.Inst.Ref.anyframe_type,15993 .AnyFrame => return sema.failWithUseOfAsync(block, src),
15980 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,15994 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
15981 .Int => {15995 .Int => {
15982 const struct_val = union_val.val.castTag(.aggregate).?.data;15996 const struct_val = union_val.val.castTag(.aggregate).?.data;
...@@ -16628,7 +16642,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -16628,7 +16642,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
16628 return sema.addType(ty);16642 return sema.addType(ty);
16629 },16643 },
16630 .BoundFn => @panic("TODO delete BoundFn from the language"),16644 .BoundFn => @panic("TODO delete BoundFn from the language"),
16631 .Frame => @panic("TODO implement https://github.com/ziglang/zig/issues/10710"),16645 .Frame => return sema.failWithUseOfAsync(block, src),
16632 }16646 }
16633}16647}
1663416648
...@@ -16830,13 +16844,13 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16830,13 +16844,13 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16830fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16844fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
16831 const inst_data = sema.code.instructions.items(.data)[inst].un_node;16845 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
16832 const src = inst_data.src();16846 const src = inst_data.src();
16833 return sema.fail(block, src, "TODO: Sema.zirFrameType", .{});16847 return sema.failWithUseOfAsync(block, src);
16834}16848}
1683516849
16836fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16850fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
16837 const inst_data = sema.code.instructions.items(.data)[inst].un_node;16851 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
16838 const src = inst_data.src();16852 const src = inst_data.src();
16839 return sema.fail(block, src, "TODO: Sema.zirFrameSize", .{});16853 return sema.failWithUseOfAsync(block, src);
16840}16854}
1684116855
16842fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16856fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -19067,13 +19081,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -19067,13 +19081,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
19067fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {19081fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19068 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;19082 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19069 const src = inst_data.src();19083 const src = inst_data.src();
19070 return sema.fail(block, src, "TODO: Sema.zirBuiltinAsyncCall", .{});19084 return sema.failWithUseOfAsync(block, src);
19071}19085}
1907219086
19073fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {19087fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19074 const inst_data = sema.code.instructions.items(.data)[inst].un_node;19088 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
19075 const src = inst_data.src();19089 const src = inst_data.src();
19076 return sema.fail(block, src, "TODO: Sema.zirResume", .{});19090 return sema.failWithUseOfAsync(block, src);
19077}19091}
1907819092
19079fn zirAwait(19093fn zirAwait(
...@@ -19084,7 +19098,7 @@ fn zirAwait(...@@ -19084,7 +19098,7 @@ fn zirAwait(
19084 const inst_data = sema.code.instructions.items(.data)[inst].un_node;19098 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
19085 const src = inst_data.src();19099 const src = inst_data.src();
1908619100
19087 return sema.fail(block, src, "TODO: Sema.zirAwait", .{});19101 return sema.failWithUseOfAsync(block, src);
19088}19102}
1908919103
19090fn zirAwaitNosuspend(19104fn zirAwaitNosuspend(
...@@ -19095,7 +19109,7 @@ fn zirAwaitNosuspend(...@@ -19095,7 +19109,7 @@ fn zirAwaitNosuspend(
19095 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;19109 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
19096 const src = LazySrcLoc.nodeOffset(extra.node);19110 const src = LazySrcLoc.nodeOffset(extra.node);
1909719111
19098 return sema.fail(block, src, "TODO: Sema.zirAwaitNosuspend", .{});19112 return sema.failWithUseOfAsync(block, src);
19099}19113}
1910019114
19101fn zirVarExtended(19115fn zirVarExtended(