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 e8f2770bbf..e79d5fbfc7 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 fac5819b38..4ee9d4306b 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 56cb4c726c..76cbab8698 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 c0385f6e98..a020c9b7e0 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 51cc3638fb..2e9c2165f7 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 6882a19f1d..3bb3d6e14b 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 10fc336a41..55ff048482 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 c38ef626e6..7109a3c385 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 4d541c4da7..2edc6cb7f9 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 e83cc0444a..9b5cacc98e 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 257255e00c..6125ef1914 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 13424fd9fa..8b9ec45e24 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 8a560f4596..26286a1e22 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 d4e3559006..faed432a38 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 de3cf64ea3..4692f65dd1 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 baafdc9d1f..cd36642b03 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 aa53da8169..393d4db3d5 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 1fd9539730..364d8f586d 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 4115a4870e..7d70a51666 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 bd0c8bc53c..4db3b34b1e 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 1aefa8f7a1..e64f310d79 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 d3035946f9..dc0b150abc 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 c0aaa2cfa7..568ea4e345 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);