diff --git a/doc/docgen.zig b/doc/docgen.zig index a2b4e8501c..eee4c45369 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -321,6 +321,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { var header_stack_size: usize = 0; var last_action = Action.Open; + var last_columns: ?u8 = null; var toc_buf = try std.Buffer.initSize(allocator, 0); defer toc_buf.deinit(); @@ -361,7 +362,23 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { _ = try eatToken(tokenizer, Token.Id.Separator); const content_token = try eatToken(tokenizer, Token.Id.TagContent); const content = tokenizer.buffer[content_token.start..content_token.end]; - _ = try eatToken(tokenizer, Token.Id.BracketClose); + var columns: ?u8 = null; + while (true) { + const bracket_tok = tokenizer.next(); + switch (bracket_tok.id) { + .BracketClose => break, + .Separator => continue, + .TagContent => { + const param = tokenizer.buffer[bracket_tok.start..bracket_tok.end]; + if (mem.eql(u8, param, "3col")) { + columns = 3; + } else { + return parseError(tokenizer, bracket_tok, "unrecognized header_open param: {}", param); + } + }, + else => return parseError(tokenizer, bracket_tok, "invalid header_open token"), + } + } header_stack_size += 1; @@ -381,10 +398,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { if (last_action == Action.Open) { try toc.writeByte('\n'); try toc.writeByteNTimes(' ', header_stack_size * 4); - try toc.write("
Builtin functions are provided by the compiler and are prefixed with @.
The {#syntax#}comptime{#endsyntax#} keyword on a parameter means that the parameter must be known
@@ -7232,6 +7232,9 @@ fn add(a: i32, b: i32) i32 { return a + b; }
This function returns an integer type with the given signness and bit count. The maximum
bit count for an integer type is {#syntax#}65535{#endsyntax#}.
+ Deprecated. Use {#link|@Type#}. +
{#header_close#} {#header_open|@memberCount#} @@ -7871,6 +7874,57 @@ test "integer truncation" { {#header_close#} + {#header_open|@Type#} +{#syntax#}@Type(comptime info: @import("builtin").TypeInfo) type{#endsyntax#}
+ + This function is the inverse of {#link|@typeInfo#}. It reifies type information + into a {#syntax#}type{#endsyntax#}. +
++ It is available for the following types: +
++ For these types it is a + TODO in the compiler to implement: +
++ For these types, {#syntax#}@Type{#endsyntax#} is not available. + There is an open proposal to allow unions and structs. +
+{#syntax#}@typeId(comptime T: type) @import("builtin").TypeId{#endsyntax#}
diff --git a/src/all_types.hpp b/src/all_types.hpp
index 1a97cf2814..03559ccf12 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -54,6 +54,14 @@ enum PtrLen {
PtrLenC,
};
+// This one corresponds to the builtin.zig enum.
+enum BuiltinPtrSize {
+ BuiltinPtrSizeOne,
+ BuiltinPtrSizeMany,
+ BuiltinPtrSizeSlice,
+ BuiltinPtrSizeC,
+};
+
enum UndefAllowed {
UndefOk,
UndefBad,
@@ -1534,6 +1542,7 @@ enum BuiltinFnId {
BuiltinFnIdMemberName,
BuiltinFnIdField,
BuiltinFnIdTypeInfo,
+ BuiltinFnIdType,
BuiltinFnIdHasField,
BuiltinFnIdTypeof,
BuiltinFnIdAddWithOverflow,
@@ -2436,6 +2445,7 @@ enum IrInstructionId {
IrInstructionIdByteOffsetOf,
IrInstructionIdBitOffsetOf,
IrInstructionIdTypeInfo,
+ IrInstructionIdType,
IrInstructionIdHasField,
IrInstructionIdTypeId,
IrInstructionIdSetEvalBranchQuota,
@@ -3472,6 +3482,12 @@ struct IrInstructionTypeInfo {
IrInstruction *type_value;
};
+struct IrInstructionType {
+ IrInstruction base;
+
+ IrInstruction *type_info;
+};
+
struct IrInstructionHasField {
IrInstruction base;
diff --git a/src/codegen.cpp b/src/codegen.cpp
index d1499592d2..13fb0d625d 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -5770,6 +5770,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
case IrInstructionIdByteOffsetOf:
case IrInstructionIdBitOffsetOf:
case IrInstructionIdTypeInfo:
+ case IrInstructionIdType:
case IrInstructionIdHasField:
case IrInstructionIdTypeId:
case IrInstructionIdSetEvalBranchQuota:
@@ -7597,6 +7598,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2);
create_builtin_fn(g, BuiltinFnIdField, "field", 2);
create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);
+ create_builtin_fn(g, BuiltinFnIdType, "Type", 1);
create_builtin_fn(g, BuiltinFnIdHasField, "hasField", 2);
create_builtin_fn(g, BuiltinFnIdTypeof, "typeOf", 1); // TODO rename to TypeOf
create_builtin_fn(g, BuiltinFnIdAddWithOverflow, "addWithOverflow", 4);
@@ -8159,20 +8161,25 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
" };\n"
" };\n"
"};\n\n");
- assert(ContainerLayoutAuto == 0);
- assert(ContainerLayoutExtern == 1);
- assert(ContainerLayoutPacked == 2);
+ static_assert(ContainerLayoutAuto == 0, "");
+ static_assert(ContainerLayoutExtern == 1, "");
+ static_assert(ContainerLayoutPacked == 2, "");
- assert(CallingConventionUnspecified == 0);
- assert(CallingConventionC == 1);
- assert(CallingConventionCold == 2);
- assert(CallingConventionNaked == 3);
- assert(CallingConventionStdcall == 4);
- assert(CallingConventionAsync == 5);
+ static_assert(CallingConventionUnspecified == 0, "");
+ static_assert(CallingConventionC == 1, "");
+ static_assert(CallingConventionCold == 2, "");
+ static_assert(CallingConventionNaked == 3, "");
+ static_assert(CallingConventionStdcall == 4, "");
+ static_assert(CallingConventionAsync == 5, "");
- assert(FnInlineAuto == 0);
- assert(FnInlineAlways == 1);
- assert(FnInlineNever == 2);
+ static_assert(FnInlineAuto == 0, "");
+ static_assert(FnInlineAlways == 1, "");
+ static_assert(FnInlineNever == 2, "");
+
+ static_assert(BuiltinPtrSizeOne == 0, "");
+ static_assert(BuiltinPtrSizeMany == 1, "");
+ static_assert(BuiltinPtrSizeSlice == 2, "");
+ static_assert(BuiltinPtrSizeC == 3, "");
}
{
buf_appendf(contents,
diff --git a/src/ir.cpp b/src/ir.cpp
index 7415a2dd6b..9547b1ec61 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -912,6 +912,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) {
return IrInstructionIdTypeInfo;
}
+static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) {
+ return IrInstructionIdType;
+}
+
static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) {
return IrInstructionIdHasField;
}
@@ -2907,6 +2911,15 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *
return &instruction->base;
}
+static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_info) {
+ IrInstructionType *instruction = ir_build_instruction