Skip to content

Eliminate BoundFn type from the language #13821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,6 @@ set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig")

set(ZIG_WASM2C_SOURCES
"${CMAKE_SOURCE_DIR}/stage1/wasm2c.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/huf_decompress.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/zstd_ddict.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/zstd_decompress.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/zstd_decompress_block.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/entropy_common.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/error_private.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/fse_decompress.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/pool.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/xxhash.c"
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/zstd_common.c"
)
set(ZIG_CPP_SOURCES
# These are planned to stay even when we are self-hosted.
Expand Down Expand Up @@ -738,21 +728,19 @@ else()
endif()
endif()

set(ZIG1_WASM_ZST_SOURCE "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst")
set(ZIG1_WASM_MODULE "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm")
set(ZIG1_C_SOURCE "${CMAKE_BINARY_DIR}/zig1.c")
set(ZIG2_C_SOURCE "${CMAKE_BINARY_DIR}/zig2.c")
set(ZIG_COMPILER_RT_C_SOURCE "${CMAKE_BINARY_DIR}/compiler_rt.c")

add_executable(zig-wasm2c ${ZIG_WASM2C_SOURCES})
set_target_properties(zig-wasm2c PROPERTIES COMPILE_FLAGS "${ZIG_WASM2C_COMPILE_FLAGS}")
target_include_directories(zig-wasm2c PUBLIC "${CMAKE_SOURCE_DIR}/stage1/zstd/lib")
target_compile_definitions(zig-wasm2c PRIVATE ZSTD_DISABLE_ASM)

add_custom_command(
OUTPUT "${ZIG1_C_SOURCE}"
COMMAND zig-wasm2c "${ZIG1_WASM_ZST_SOURCE}" "${ZIG1_C_SOURCE}"
DEPENDS zig-wasm2c "${ZIG1_WASM_ZST_SOURCE}"
COMMENT STATUS "Converting ${ZIG1_WASM_ZST_SOURCE} to ${ZIG1_C_SOURCE}"
COMMAND zig-wasm2c "${ZIG1_WASM_MODULE}" "${ZIG1_C_SOURCE}"
DEPENDS zig-wasm2c "${ZIG1_WASM_MODULE}"
COMMENT STATUS "Converting ${ZIG1_WASM_MODULE} to ${ZIG1_C_SOURCE}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)

Expand All @@ -764,8 +752,6 @@ if(MSVC)
else()
target_link_libraries(zig1 LINK_PUBLIC m)
endif()
target_include_directories(zig1 PUBLIC "${CMAKE_SOURCE_DIR}/stage1/zstd/lib")
target_compile_definitions(zig1 PRIVATE ZSTD_DISABLE_ASM)

set(BUILD_ZIG2_ARGS
"${CMAKE_SOURCE_DIR}/lib"
Expand Down
13 changes: 2 additions & 11 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,8 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void {
run_opt.addArg("-o");
run_opt.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });

const run_zstd = b.addSystemCommand(&.{ "zstd", "-19", "-f" });
run_zstd.step.dependOn(&run_opt.step);
run_zstd.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });
run_zstd.addArg("-o");
run_zstd.addFileSourceArg(.{ .path = "stage1/zig1.wasm.zst" });

const cleanup = b.addRemoveDirTree("stage1/zig1.wasm");
cleanup.step.dependOn(&run_zstd.step);

const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm.zst");
update_zig1_step.dependOn(&cleanup.step);
const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm");
update_zig1_step.dependOn(&run_opt.step);
}

fn addCompilerStep(b: *Builder) *std.build.LibExeObjStep {
Expand Down
7 changes: 1 addition & 6 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -9366,12 +9366,7 @@ test "integer truncation" {
<li>{#link|union#}</li>
</ul>
<p>
For these types, {#syntax#}@Type{#endsyntax#} is not available:
</p>
<ul>
<li>{#link|Functions#}</li>
<li>BoundFn</li>
</ul>
{#syntax#}@Type{#endsyntax#} is not available for {#link|Functions#}.
{#header_close#}
{#header_open|@typeInfo#}
<pre>{#syntax#}@typeInfo(comptime T: type) std.builtin.Type{#endsyntax#}</pre>
Expand Down
1 change: 0 additions & 1 deletion lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ pub const Type = union(enum) {
Enum: Enum,
Union: Union,
Fn: Fn,
BoundFn: Fn,
Opaque: Opaque,
Frame: Frame,
AnyFrame: AnyFrame,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/hash/auto_hash.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),

Expand Down
1 change: 0 additions & 1 deletion lib/std/mem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ pub fn zeroes(comptime T: type) T {
.ErrorUnion,
.ErrorSet,
.Fn,
.BoundFn,
.Type,
.NoReturn,
.Undefined,
Expand Down
1 change: 0 additions & 1 deletion lib/std/meta/trait.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion lib/std/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9098,6 +9098,8 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_
.always => return true,
.forward1 => node = node_datas[node].rhs,
}
// Missing builtin arg is not a parsing error, expect an error later.
if (node == 0) return false;
},

.builtin_call, .builtin_call_comma => {
Expand All @@ -9112,6 +9114,8 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_
.always => return true,
.forward1 => node = params[1],
}
// Missing builtin arg is not a parsing error, expect an error later.
if (node == 0) return false;
},
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Autodoc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -9777,7 +9775,6 @@ fn zirSwitchCond(
.Undefined,
.Null,
.Optional,
.BoundFn,
.Opaque,
.Vector,
.Frame,
Expand Down Expand Up @@ -10361,7 +10358,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
.Undefined,
.Null,
.Optional,
.BoundFn,
.Opaque,
.Vector,
.Frame,
Expand Down Expand Up @@ -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)}),

Expand Down Expand Up @@ -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)}),

Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -21790,7 +21782,6 @@ fn validateRunTimeType(

.Enum => return !(try sema.typeRequiresComptime(ty)),

.BoundFn,
.ComptimeFloat,
.ComptimeInt,
.EnumLiteral,
Expand Down Expand Up @@ -21876,7 +21867,6 @@ fn explainWhyTypeIsComptimeInner(
try mod.errNoteNonLazy(src_loc, msg, "types are not available at runtime", .{});
},

.BoundFn,
.ComptimeFloat,
.ComptimeInt,
.EnumLiteral,
Expand Down Expand Up @@ -21986,7 +21976,6 @@ fn validateExternType(
.Null,
.ErrorUnion,
.ErrorSet,
.BoundFn,
.Frame,
=> return false,
.Void => return position == .union_field or position == .ret_ty,
Expand Down Expand Up @@ -22058,7 +22047,6 @@ fn explainWhyTypeIsNotExtern(
.Null,
.ErrorUnion,
.ErrorSet,
.BoundFn,
.Frame,
=> return,

Expand Down Expand Up @@ -22116,7 +22104,6 @@ fn validatePackedType(ty: Type) bool {
.Null,
.ErrorUnion,
.ErrorSet,
.BoundFn,
.Frame,
.NoReturn,
.Opaque,
Expand Down Expand Up @@ -22158,7 +22145,6 @@ fn explainWhyTypeIsNotPacked(
.EnumLiteral,
.Undefined,
.Null,
.BoundFn,
.Frame,
.NoReturn,
.Opaque,
Expand Down
1 change: 0 additions & 1 deletion src/arch/aarch64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6200,7 +6200,6 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
.NoReturn => unreachable,
.Undefined => unreachable,
.Null => unreachable,
.BoundFn => unreachable,
.Opaque => unreachable,

else => {},
Expand Down
1 change: 0 additions & 1 deletion src/arch/aarch64/abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub fn classifyType(ty: Type, target: std.Target) Class {
.ComptimeInt,
.Undefined,
.Null,
.BoundFn,
.Fn,
.Opaque,
.EnumLiteral,
Expand Down
1 change: 0 additions & 1 deletion src/arch/arm/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6156,7 +6156,6 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
.NoReturn => unreachable,
.Undefined => unreachable,
.Null => unreachable,
.BoundFn => unreachable,
.Opaque => unreachable,

else => {},
Expand Down
1 change: 0 additions & 1 deletion src/arch/arm/abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ pub fn classifyType(ty: Type, target: std.Target, ctx: Context) Class {
.ComptimeInt,
.Undefined,
.Null,
.BoundFn,
.Fn,
.Opaque,
.EnumLiteral,
Expand Down
1 change: 0 additions & 1 deletion src/arch/riscv64/abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub fn classifyType(ty: Type, target: std.Target) Class {
.ComptimeInt,
.Undefined,
.Null,
.BoundFn,
.Fn,
.Opaque,
.EnumLiteral,
Expand Down
1 change: 0 additions & 1 deletion src/arch/wasm/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,6 @@ fn isByRef(ty: Type, target: std.Target) bool {
.EnumLiteral,
.Undefined,
.Null,
.BoundFn,
.Opaque,
=> unreachable,

Expand Down
1 change: 0 additions & 1 deletion src/arch/wasm/abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub fn classifyType(ty: Type, target: Target) [2]Class {
.ComptimeInt,
.Undefined,
.Null,
.BoundFn,
.Fn,
.Opaque,
.EnumLiteral,
Expand Down
1 change: 0 additions & 1 deletion src/arch/x86_64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6942,7 +6942,6 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
.NoReturn => unreachable,
.Undefined => unreachable,
.Null => unreachable,
.BoundFn => unreachable,
.Opaque => unreachable,

else => {},
Expand Down
1 change: 0 additions & 1 deletion src/arch/x86_64/abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub fn classifyWindows(ty: Type, target: Target) Class {
.ComptimeInt,
.Undefined,
.Null,
.BoundFn,
.Fn,
.Opaque,
.EnumLiteral,
Expand Down
4 changes: 0 additions & 4 deletions src/codegen/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@ pub const DeclGen = struct {
.NoReturn,
.Undefined,
.Null,
.BoundFn,
.Opaque,
=> unreachable,

Expand Down Expand Up @@ -1320,7 +1319,6 @@ pub const DeclGen = struct {
.NoReturn => unreachable,
.Undefined => unreachable,
.Null => unreachable,
.BoundFn => unreachable,
.Opaque => unreachable,

.Frame,
Expand Down Expand Up @@ -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
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down Expand Up @@ -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"),
}
Expand Down Expand Up @@ -3896,7 +3892,6 @@ pub const DeclGen = struct {
.NoReturn => unreachable,
.Undefined => unreachable,
.Null => unreachable,
.BoundFn => unreachable,
.Opaque => unreachable,

.Frame,
Expand Down Expand Up @@ -10792,7 +10787,6 @@ fn isByRef(ty: Type) bool {
.EnumLiteral,
.Undefined,
.Null,
.BoundFn,
.Opaque,
=> unreachable,

Expand Down
Loading