From 9d93b2ccf11f584320a2c5209dd2d94705167695 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Thu, 8 Dec 2022 19:52:05 +0200 Subject: [PATCH] Eliminate `BoundFn` type from the language Closes #9484 --- doc/langref.html.in | 7 +------ lib/std/builtin.zig | 1 - lib/std/hash/auto_hash.zig | 2 +- lib/std/mem.zig | 1 - lib/std/meta/trait.zig | 1 - lib/std/testing.zig | 1 - src/Autodoc.zig | 1 - src/Sema.zig | 14 -------------- src/arch/aarch64/CodeGen.zig | 1 - src/arch/aarch64/abi.zig | 1 - src/arch/arm/CodeGen.zig | 1 - src/arch/arm/abi.zig | 1 - src/arch/riscv64/abi.zig | 1 - src/arch/wasm/CodeGen.zig | 1 - src/arch/wasm/abi.zig | 1 - src/arch/x86_64/CodeGen.zig | 1 - src/arch/x86_64/abi.zig | 1 - src/codegen/c.zig | 4 ---- src/codegen/llvm.zig | 6 ------ src/codegen/spirv.zig | 2 -- src/type.zig | 2 -- src/value.zig | 2 -- test/behavior/type_info.zig | 2 +- 23 files changed, 3 insertions(+), 52 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index e8f2770bbf80bcb5d00c53d8621a920bb8a1b6aa..e79d5fbfc7603ceb7445f73771c94aeb09cb2f77 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -9366,12 +9366,7 @@ test "integer truncation" {
  • {#link|union#}
  • - For these types, {#syntax#}@Type{#endsyntax#} is not available: -

    - + {#syntax#}@Type{#endsyntax#} is not available for {#link|Functions#}. {#header_close#} {#header_open|@typeInfo#}
    {#syntax#}@typeInfo(comptime T: type) std.builtin.Type{#endsyntax#}
    diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index fac5819b381b65d44dac3e9b0a1276251f3cb0eb..4ee9d4306bb9fe65a4104ad194912389bd9293f0 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -210,7 +210,6 @@ pub const Type = union(enum) { Enum: Enum, Union: Union, Fn: Fn, - BoundFn: Fn, Opaque: Opaque, Frame: Frame, AnyFrame: AnyFrame, diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index 56cb4c726cea678436988d9970e06c99d9923108..76cbab8698a66828f1eeb06d01a2abd3dbbad087 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -101,7 +101,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { .Bool => hash(hasher, @boolToInt(key), strat), .Enum => hash(hasher, @enumToInt(key), strat), .ErrorSet => hash(hasher, @errorToInt(key), strat), - .AnyFrame, .BoundFn, .Fn => hash(hasher, @ptrToInt(key), strat), + .AnyFrame, .Fn => hash(hasher, @ptrToInt(key), strat), .Pointer => @call(.{ .modifier = .always_inline }, hashPointer, .{ hasher, key, strat }), diff --git a/lib/std/mem.zig b/lib/std/mem.zig index c0385f6e98dbc955a9aa8f9388f3b3e0dd3c4458..a020c9b7e0cba0011689fccf1826b8a59e0c1c84 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -308,7 +308,6 @@ pub fn zeroes(comptime T: type) T { .ErrorUnion, .ErrorSet, .Fn, - .BoundFn, .Type, .NoReturn, .Undefined, diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index 51cc3638fbc63d233280c745d3d2edd0a0ffe3cd..2e9c2165f715412c0e495797820e00a87743b616 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -549,7 +549,6 @@ pub fn hasUniqueRepresentation(comptime T: type) bool { else => return false, // TODO can we know if it's true for some of these types ? .AnyFrame, - .BoundFn, .Enum, .ErrorSet, .Fn, diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 6882a19f1da3eb2a127b31bb66973fc729db78a1..3bb3d6e14b0ca1e185fe07684d70b2a6691286b5 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -46,7 +46,6 @@ pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void { switch (@typeInfo(@TypeOf(actual))) { .NoReturn, - .BoundFn, .Opaque, .Frame, .AnyFrame, diff --git a/src/Autodoc.zig b/src/Autodoc.zig index 10fc336a41ee9b70bcb28ab398fceba7047cc327..55ff0484828080a1526f2fb57cfc4c779fd7c58c 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -607,7 +607,6 @@ const DocData = struct { is_test: bool = false, is_extern: bool = false, }, - BoundFn: struct { name: []const u8 }, Opaque: struct { name: []const u8, src: usize, // index into astNodes diff --git a/src/Sema.zig b/src/Sema.zig index c38ef626e6a7b013300e7896ad789e9c008a0d45..7109a3c385842a4bb7b0deccbd6fe05f06a07aaf 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9275,7 +9275,6 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air dest_ty.fmt(sema.mod), container, }); }, - .BoundFn => @panic("TODO remove this type from the language and compiler"), .Array, .Bool, @@ -9339,7 +9338,6 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air operand_ty.fmt(sema.mod), container, }); }, - .BoundFn => @panic("TODO remove this type from the language and compiler"), .Array, .Bool, @@ -9777,7 +9775,6 @@ fn zirSwitchCond( .Undefined, .Null, .Optional, - .BoundFn, .Opaque, .Vector, .Frame, @@ -10361,7 +10358,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError .Undefined, .Null, .Optional, - .BoundFn, .Opaque, .Vector, .Frame, @@ -14833,7 +14829,6 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. .NoReturn, .Undefined, .Null, - .BoundFn, .Opaque, => return sema.fail(block, operand_src, "no size available for type '{}'", .{ty.fmt(sema.mod)}), @@ -14877,7 +14872,6 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A .NoReturn, .Undefined, .Null, - .BoundFn, .Opaque, => return sema.fail(block, operand_src, "no size available for type '{}'", .{operand_ty.fmt(sema.mod)}), @@ -15908,7 +15902,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai }), ); }, - .BoundFn => @panic("TODO remove this type from the language and compiler"), .Frame => return sema.failWithUseOfAsync(block, src), .AnyFrame => return sema.failWithUseOfAsync(block, src), } @@ -18609,7 +18602,6 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in const ty = try Type.Tag.function.create(sema.arena, fn_info); return sema.addType(ty); }, - .BoundFn => @panic("TODO delete BoundFn from the language"), .Frame => return sema.failWithUseOfAsync(block, src), } } @@ -21790,7 +21782,6 @@ fn validateRunTimeType( .Enum => return !(try sema.typeRequiresComptime(ty)), - .BoundFn, .ComptimeFloat, .ComptimeInt, .EnumLiteral, @@ -21876,7 +21867,6 @@ fn explainWhyTypeIsComptimeInner( try mod.errNoteNonLazy(src_loc, msg, "types are not available at runtime", .{}); }, - .BoundFn, .ComptimeFloat, .ComptimeInt, .EnumLiteral, @@ -21986,7 +21976,6 @@ fn validateExternType( .Null, .ErrorUnion, .ErrorSet, - .BoundFn, .Frame, => return false, .Void => return position == .union_field or position == .ret_ty, @@ -22058,7 +22047,6 @@ fn explainWhyTypeIsNotExtern( .Null, .ErrorUnion, .ErrorSet, - .BoundFn, .Frame, => return, @@ -22116,7 +22104,6 @@ fn validatePackedType(ty: Type) bool { .Null, .ErrorUnion, .ErrorSet, - .BoundFn, .Frame, .NoReturn, .Opaque, @@ -22158,7 +22145,6 @@ fn explainWhyTypeIsNotPacked( .EnumLiteral, .Undefined, .Null, - .BoundFn, .Frame, .NoReturn, .Opaque, diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 4d541c4da7573e3829266ab214b106d8fa09f072..2edc6cb7f9c2770391537229aad23ca6bbc9ce85 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -6200,7 +6200,6 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { .NoReturn => unreachable, .Undefined => unreachable, .Null => unreachable, - .BoundFn => unreachable, .Opaque => unreachable, else => {}, diff --git a/src/arch/aarch64/abi.zig b/src/arch/aarch64/abi.zig index e83cc0444ac43e16fc3ff50afc7e4162b4ca4e17..9b5cacc98eccf852bb894130fcbc34a4909e3dd4 100644 --- a/src/arch/aarch64/abi.zig +++ b/src/arch/aarch64/abi.zig @@ -64,7 +64,6 @@ pub fn classifyType(ty: Type, target: std.Target) Class { .ComptimeInt, .Undefined, .Null, - .BoundFn, .Fn, .Opaque, .EnumLiteral, diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 257255e00cfa0ded0d42a40248b96d5883864639..6125ef191462c72f3221ce807eed19471f641259 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -6156,7 +6156,6 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { .NoReturn => unreachable, .Undefined => unreachable, .Null => unreachable, - .BoundFn => unreachable, .Opaque => unreachable, else => {}, diff --git a/src/arch/arm/abi.zig b/src/arch/arm/abi.zig index 13424fd9fa9bd4c3be76a76f710b8df5d86b5b54..8b9ec45e24dc38eab9194c8526c6bd68d8fad82c 100644 --- a/src/arch/arm/abi.zig +++ b/src/arch/arm/abi.zig @@ -105,7 +105,6 @@ pub fn classifyType(ty: Type, target: std.Target, ctx: Context) Class { .ComptimeInt, .Undefined, .Null, - .BoundFn, .Fn, .Opaque, .EnumLiteral, diff --git a/src/arch/riscv64/abi.zig b/src/arch/riscv64/abi.zig index 8a560f4596d040c2dbfb9e72d43725d959d3ae0c..26286a1e22717a209eeeee0ab8ae74bcbf6cd0a6 100644 --- a/src/arch/riscv64/abi.zig +++ b/src/arch/riscv64/abi.zig @@ -63,7 +63,6 @@ pub fn classifyType(ty: Type, target: std.Target) Class { .ComptimeInt, .Undefined, .Null, - .BoundFn, .Fn, .Opaque, .EnumLiteral, diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index d4e3559006b09e97a881cab477a87f2e884db367..faed432a384d84decccc412fec0b6408cb73455e 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1599,7 +1599,6 @@ fn isByRef(ty: Type, target: std.Target) bool { .EnumLiteral, .Undefined, .Null, - .BoundFn, .Opaque, => unreachable, diff --git a/src/arch/wasm/abi.zig b/src/arch/wasm/abi.zig index de3cf64ea37a22fee1fc3bca54e910a3814a2cfa..4692f65dd17ae6db99d27f26f1b8e30dbc450402 100644 --- a/src/arch/wasm/abi.zig +++ b/src/arch/wasm/abi.zig @@ -80,7 +80,6 @@ pub fn classifyType(ty: Type, target: Target) [2]Class { .ComptimeInt, .Undefined, .Null, - .BoundFn, .Fn, .Opaque, .EnumLiteral, diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index baafdc9d1fe402e16b729a8ee8450628f0ae283b..cd36642b03f02a8ac4d4eba0a683463f839b6a1d 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -6942,7 +6942,6 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { .NoReturn => unreachable, .Undefined => unreachable, .Null => unreachable, - .BoundFn => unreachable, .Opaque => unreachable, else => {}, diff --git a/src/arch/x86_64/abi.zig b/src/arch/x86_64/abi.zig index aa53da8169c6f6fbdbf153e08915a93cb05a47c9..393d4db3d57297b954b85a95bd2e617f43ccf945 100644 --- a/src/arch/x86_64/abi.zig +++ b/src/arch/x86_64/abi.zig @@ -52,7 +52,6 @@ pub fn classifyWindows(ty: Type, target: Target) Class { .ComptimeInt, .Undefined, .Null, - .BoundFn, .Fn, .Opaque, .EnumLiteral, diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 1fd9539730715e8acb7a5c7d39c455a8621d69ee..364d8f586d3b00cac95abffdac0b85ae3d24d5fe 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -866,7 +866,6 @@ pub const DeclGen = struct { .NoReturn, .Undefined, .Null, - .BoundFn, .Opaque, => unreachable, @@ -1320,7 +1319,6 @@ pub const DeclGen = struct { .NoReturn => unreachable, .Undefined => unreachable, .Null => unreachable, - .BoundFn => unreachable, .Opaque => unreachable, .Frame, @@ -2050,8 +2048,6 @@ pub const DeclGen = struct { .ComptimeInt, .Type, => unreachable, // must be const or comptime - - .BoundFn => unreachable, // this type will be deleted from the language } } diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 4115a4870ea3f8731b929afd65f5111bee1f2983..7d70a5166664499dcdf38baaed34ae6943d3be11 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2341,8 +2341,6 @@ pub const Object = struct { .Null => unreachable, .EnumLiteral => unreachable, - .BoundFn => @panic("TODO remove BoundFn from the language"), - .Frame => @panic("TODO implement lowerDebugType for Frame types"), .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"), } @@ -3095,8 +3093,6 @@ pub const DeclGen = struct { .Null => unreachable, .EnumLiteral => unreachable, - .BoundFn => @panic("TODO remove BoundFn from the language"), - .Frame => @panic("TODO implement llvmType for Frame types"), .AnyFrame => @panic("TODO implement llvmType for AnyFrame types"), } @@ -3896,7 +3892,6 @@ pub const DeclGen = struct { .NoReturn => unreachable, .Undefined => unreachable, .Null => unreachable, - .BoundFn => unreachable, .Opaque => unreachable, .Frame, @@ -10792,7 +10787,6 @@ fn isByRef(ty: Type) bool { .EnumLiteral, .Undefined, .Null, - .BoundFn, .Opaque, => unreachable, diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index bd0c8bc53c1525879b71c7f57805ef8365732aaf..4db3b34b1eb418567e2ecd081501caef3a0b86df 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -538,8 +538,6 @@ pub const DeclGen = struct { .Type, => unreachable, // Must be comptime. - .BoundFn => unreachable, // this type will be deleted from the language. - else => |tag| return self.todo("Implement zig type '{}'", .{tag}), }; } diff --git a/src/type.zig b/src/type.zig index 1aefa8f7a1c77ddf58b1cb7271b57db6618704fb..e64f310d794f3e2d185a3d268fd5a37e45dda099 100644 --- a/src/type.zig +++ b/src/type.zig @@ -185,7 +185,6 @@ pub const Type = extern union { .Void, .ErrorSet, .Fn, - .BoundFn, .Opaque, .AnyFrame, .Enum, @@ -4074,7 +4073,6 @@ pub const Type = extern union { => return true, .Opaque => return is_extern, - .BoundFn, .ComptimeFloat, .ComptimeInt, .EnumLiteral, diff --git a/src/value.zig b/src/value.zig index d3035946f9800c4cbc8e61c690730450e52f50e6..dc0b150abcd8be889204a7e63808598bb6dbc295 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2419,7 +2419,6 @@ pub const Value = extern union { if (val.tag() == .runtime_value) return; switch (zig_ty_tag) { - .BoundFn => unreachable, // TODO remove this from the language .Opaque => unreachable, // Cannot hash opaque types .Void, @@ -2566,7 +2565,6 @@ pub const Value = extern union { if (val.tag() == .runtime_value) return; switch (ty.zigTypeTag()) { - .BoundFn => unreachable, // TODO remove this from the language .Opaque => unreachable, // Cannot hash opaque types .Void, .NoReturn, diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index c0aaa2cfa715d938f0e5ede387b86797476ab880..568ea4e3459060f18af0a809f010ce4dd233a3fa 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -252,7 +252,7 @@ fn testUnion() !void { try expect(typeinfo_info == .Union); try expect(typeinfo_info.Union.layout == .Auto); try expect(typeinfo_info.Union.tag_type.? == TypeId); - try expect(typeinfo_info.Union.fields.len == 25); + try expect(typeinfo_info.Union.fields.len == 24); try expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); try expect(typeinfo_info.Union.decls.len == 22); -- 2.54.0