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
859859 },
860860 .enum_literal => return simpleStrTok(gz, rl, main_tokens[node], node, .enum_literal),
861861 .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 },
863868 .anyframe_type => {
864869 const return_type = try typeExpr(gz, scope, node_datas[node].rhs);
865870 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
18281828 return sema.failWithOwnedErrorMsg(msg);
18291829}
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
18311842/// We don't return a pointer to the new error note because the pointer
18321843/// becomes invalid when you add another one.
18331844fn errNote(
......@@ -4776,7 +4787,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
47764787fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
47774788 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
47784789 const src = inst_data.src();
4779 return sema.fail(parent_block, src, "TODO: implement Sema.zirSuspendBlock", .{});
4790 return sema.failWithUseOfAsync(parent_block, src);
47804791}
47814792
47824793fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -5613,7 +5624,7 @@ fn analyzeCall(
56135624 .never_inline => Air.Inst.Tag.call_never_inline,
56145625 .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),
56175628 };
56185629
56195630 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
66576668 defer tracy.end();
66586669
66596670 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6671 if (true) {
6672 return sema.failWithUseOfAsync(block, inst_data.src());
6673 }
66606674 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };
66616675 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
66626676 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
1414114155 );
1414214156 },
1414314157 .BoundFn => @panic("TODO remove this type from the language and compiler"),
14144 .Frame => return sema.fail(block, src, "TODO: implement zirTypeInfo for Frame", .{}),
14145 .AnyFrame => return sema.fail(block, src, "TODO: implement zirTypeInfo for AnyFrame", .{}),
14158 .Frame => return sema.failWithUseOfAsync(block, src),
14159 .AnyFrame => return sema.failWithUseOfAsync(block, src),
1414614160 }
1414714161}
1414814162
......@@ -15787,7 +15801,7 @@ fn zirFrame(
1578715801 extended: Zir.Inst.Extended.InstData,
1578815802) CompileError!Air.Inst.Ref {
1578915803 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
15790 return sema.fail(block, src, "TODO: Sema.zirFrame", .{});
15804 return sema.failWithUseOfAsync(block, src);
1579115805}
1579215806
1579315807fn 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
1597615990 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
1597715991 .Undefined => return Air.Inst.Ref.undefined_type,
1597815992 .Null => return Air.Inst.Ref.null_type,
15979 .AnyFrame => return Air.Inst.Ref.anyframe_type,
15993 .AnyFrame => return sema.failWithUseOfAsync(block, src),
1598015994 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
1598115995 .Int => {
1598215996 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
1662816642 return sema.addType(ty);
1662916643 },
1663016644 .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),
1663216646 }
1663316647}
1663416648
......@@ -16830,13 +16844,13 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1683016844fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1683116845 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1683216846 const src = inst_data.src();
16833 return sema.fail(block, src, "TODO: Sema.zirFrameType", .{});
16847 return sema.failWithUseOfAsync(block, src);
1683416848}
1683516849
1683616850fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1683716851 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1683816852 const src = inst_data.src();
16839 return sema.fail(block, src, "TODO: Sema.zirFrameSize", .{});
16853 return sema.failWithUseOfAsync(block, src);
1684016854}
1684116855
1684216856fn 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
1906719081fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1906819082 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1906919083 const src = inst_data.src();
19070 return sema.fail(block, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
19084 return sema.failWithUseOfAsync(block, src);
1907119085}
1907219086
1907319087fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1907419088 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1907519089 const src = inst_data.src();
19076 return sema.fail(block, src, "TODO: Sema.zirResume", .{});
19090 return sema.failWithUseOfAsync(block, src);
1907719091}
1907819092
1907919093fn zirAwait(
......@@ -19084,7 +19098,7 @@ fn zirAwait(
1908419098 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1908519099 const src = inst_data.src();
1908619100
19087 return sema.fail(block, src, "TODO: Sema.zirAwait", .{});
19101 return sema.failWithUseOfAsync(block, src);
1908819102}
1908919103
1909019104fn zirAwaitNosuspend(
......@@ -19095,7 +19109,7 @@ fn zirAwaitNosuspend(
1909519109 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1909619110 const src = LazySrcLoc.nodeOffset(extra.node);
1909719111
19098 return sema.fail(block, src, "TODO: Sema.zirAwaitNosuspend", .{});
19112 return sema.failWithUseOfAsync(block, src);
1909919113}
1910019114
1910119115fn zirVarExtended(