authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-13 16:34:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-13 16:34:33-04:00
logc06a61e9bf93810174255474598cfeae785cfbd6
tree27d8f4262d8cd8c72c75e348e63e6c7d6a6ec0d4
parent7c3636aaa38e8efa77b73ba94362802517ea739e
signaturelock-open Commit is signed but in an unrecognized format.

remove `this`. add `@This()`.

closes #1283

55 files changed, 97 insertions(+), 266 deletions(-)

doc/langref.html.in+2-11
......@@ -478,13 +478,9 @@ pub fn main() void {
478478 <td><code>undefined</code></td>
479479 <td>used to leave a value unspecified</td>
480480 </tr>
481 <tr>
482 <td><code>this</code></td>
483 <td>refers to the thing in immediate scope</td>
484 </tr>
485481 </table>
486482 </div>
487 {#see_also|Optionals|this#}
483 {#see_also|Optionals#}
488484 {#header_close#}
489485 {#header_open|String Literals#}
490486 {#code_begin|test#}
......@@ -4186,11 +4182,6 @@ fn foo() void {}
41864182 {#code_end#}
41874183 {#header_close#}
41884184
4189 {#header_open|this#}
4190 <p>TODO: example of this referring to Self struct</p>
4191 <p>TODO: example of this referring to recursion function</p>
4192 <p>TODO: example of this referring to basic block for @setRuntimeSafety</p>
4193 {#header_close#}
41944185 {#header_open|comptime#}
41954186 <p>
41964187 Zig places importance on the concept of whether an expression is known at compile-time.
......@@ -7744,7 +7735,7 @@ ArrayType : "[" option(Expression) "]" option("align" "(" Expression option(":"
77447735
77457736GroupedExpression = "(" Expression ")"
77467737
7747KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "this" | "unreachable" | "suspend"
7738KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "unreachable" | "suspend"
77487739
77497740ErrorSetDecl = "error" "{" list(Symbol, ",") "}"
77507741
src-self-hosted/type.zig-12
......@@ -40,7 +40,6 @@ pub const Type = struct {
4040 Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp),
4141 Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp),
4242 Id.Namespace => @fieldParentPtr(Namespace, "base", base).destroy(comp),
43 Id.Block => @fieldParentPtr(Block, "base", base).destroy(comp),
4443 Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp),
4544 Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp),
4645 Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp),
......@@ -74,7 +73,6 @@ pub const Type = struct {
7473 Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context),
7574 Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context),
7675 Id.Namespace => unreachable,
77 Id.Block => unreachable,
7876 Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context),
7977 Id.ArgTuple => unreachable,
8078 Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context),
......@@ -90,7 +88,6 @@ pub const Type = struct {
9088 Id.Undefined,
9189 Id.Null,
9290 Id.Namespace,
93 Id.Block,
9491 Id.BoundFn,
9592 Id.ArgTuple,
9693 Id.Opaque,
......@@ -124,7 +121,6 @@ pub const Type = struct {
124121 Id.Undefined,
125122 Id.Null,
126123 Id.Namespace,
127 Id.Block,
128124 Id.BoundFn,
129125 Id.ArgTuple,
130126 Id.Opaque,
......@@ -1012,14 +1008,6 @@ pub const Type = struct {
10121008 }
10131009 };
10141010
1015 pub const Block = struct {
1016 base: Type,
1017
1018 pub fn destroy(self: *Block, comp: *Compilation) void {
1019 comp.gpa().destroy(self);
1020 }
1021 };
1022
10231011 pub const BoundFn = struct {
10241012 base: Type,
10251013
src/all_types.hpp+1-3
......@@ -283,7 +283,6 @@ struct ConstExprValue {
283283 ConstArrayValue x_array;
284284 ConstPtrValue x_ptr;
285285 ImportTableEntry *x_import;
286 Scope *x_block;
287286 ConstArgTuple x_arg_tuple;
288287
289288 // populated if special == ConstValSpecialRuntime
......@@ -413,7 +412,6 @@ enum NodeType {
413412 NodeTypeBoolLiteral,
414413 NodeTypeNullLiteral,
415414 NodeTypeUndefinedLiteral,
416 NodeTypeThisLiteral,
417415 NodeTypeUnreachable,
418416 NodeTypeIfBoolExpr,
419417 NodeTypeWhileExpr,
......@@ -1205,7 +1203,6 @@ enum ZigTypeId {
12051203 ZigTypeIdUnion,
12061204 ZigTypeIdFn,
12071205 ZigTypeIdNamespace,
1208 ZigTypeIdBlock,
12091206 ZigTypeIdBoundFn,
12101207 ZigTypeIdArgTuple,
12111208 ZigTypeIdOpaque,
......@@ -1413,6 +1410,7 @@ enum BuiltinFnId {
14131410 BuiltinFnIdSetEvalBranchQuota,
14141411 BuiltinFnIdAlignCast,
14151412 BuiltinFnIdOpaqueType,
1413 BuiltinFnIdThis,
14161414 BuiltinFnIdSetAlignStack,
14171415 BuiltinFnIdArgType,
14181416 BuiltinFnIdExport,
src/analyze.cpp+4-64
......@@ -246,7 +246,6 @@ AstNode *type_decl_node(ZigType *type_entry) {
246246 case ZigTypeIdErrorSet:
247247 case ZigTypeIdFn:
248248 case ZigTypeIdNamespace:
249 case ZigTypeIdBlock:
250249 case ZigTypeIdBoundFn:
251250 case ZigTypeIdArgTuple:
252251 case ZigTypeIdPromise:
......@@ -284,7 +283,6 @@ bool type_is_complete(ZigType *type_entry) {
284283 case ZigTypeIdErrorSet:
285284 case ZigTypeIdFn:
286285 case ZigTypeIdNamespace:
287 case ZigTypeIdBlock:
288286 case ZigTypeIdBoundFn:
289287 case ZigTypeIdArgTuple:
290288 case ZigTypeIdPromise:
......@@ -320,7 +318,6 @@ bool type_has_zero_bits_known(ZigType *type_entry) {
320318 case ZigTypeIdErrorSet:
321319 case ZigTypeIdFn:
322320 case ZigTypeIdNamespace:
323 case ZigTypeIdBlock:
324321 case ZigTypeIdBoundFn:
325322 case ZigTypeIdArgTuple:
326323 case ZigTypeIdOpaque:
......@@ -1414,7 +1411,6 @@ static bool type_allowed_in_packed_struct(ZigType *type_entry) {
14141411 case ZigTypeIdErrorUnion:
14151412 case ZigTypeIdErrorSet:
14161413 case ZigTypeIdNamespace:
1417 case ZigTypeIdBlock:
14181414 case ZigTypeIdBoundFn:
14191415 case ZigTypeIdArgTuple:
14201416 case ZigTypeIdOpaque:
......@@ -1455,7 +1451,6 @@ static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
14551451 case ZigTypeIdErrorUnion:
14561452 case ZigTypeIdErrorSet:
14571453 case ZigTypeIdNamespace:
1458 case ZigTypeIdBlock:
14591454 case ZigTypeIdBoundFn:
14601455 case ZigTypeIdArgTuple:
14611456 case ZigTypeIdPromise:
......@@ -1613,7 +1608,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
16131608 case ZigTypeIdComptimeFloat:
16141609 case ZigTypeIdComptimeInt:
16151610 case ZigTypeIdNamespace:
1616 case ZigTypeIdBlock:
16171611 case ZigTypeIdBoundFn:
16181612 case ZigTypeIdMetaType:
16191613 case ZigTypeIdVoid:
......@@ -1703,7 +1697,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
17031697 case ZigTypeIdComptimeFloat:
17041698 case ZigTypeIdComptimeInt:
17051699 case ZigTypeIdNamespace:
1706 case ZigTypeIdBlock:
17071700 case ZigTypeIdBoundFn:
17081701 case ZigTypeIdMetaType:
17091702 case ZigTypeIdUnreachable:
......@@ -3437,7 +3430,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
34373430 case NodeTypeBoolLiteral:
34383431 case NodeTypeNullLiteral:
34393432 case NodeTypeUndefinedLiteral:
3440 case NodeTypeThisLiteral:
34413433 case NodeTypeSymbol:
34423434 case NodeTypePrefixOpExpr:
34433435 case NodeTypePointerType:
......@@ -3497,7 +3489,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
34973489 case ZigTypeIdUnreachable:
34983490 case ZigTypeIdUndefined:
34993491 case ZigTypeIdNull:
3500 case ZigTypeIdBlock:
35013492 case ZigTypeIdArgTuple:
35023493 case ZigTypeIdOpaque:
35033494 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
......@@ -3798,34 +3789,6 @@ ZigFn *scope_fn_entry(Scope *scope) {
37983789 return nullptr;
37993790}
38003791
3801ZigFn *scope_get_fn_if_root(Scope *scope) {
3802 assert(scope);
3803 scope = scope->parent;
3804 while (scope) {
3805 switch (scope->id) {
3806 case ScopeIdBlock:
3807 return nullptr;
3808 case ScopeIdDecls:
3809 case ScopeIdDefer:
3810 case ScopeIdDeferExpr:
3811 case ScopeIdVarDecl:
3812 case ScopeIdCImport:
3813 case ScopeIdLoop:
3814 case ScopeIdSuspend:
3815 case ScopeIdCompTime:
3816 case ScopeIdCoroPrelude:
3817 case ScopeIdRuntime:
3818 scope = scope->parent;
3819 continue;
3820 case ScopeIdFnDef:
3821 ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
3822 return fn_scope->fn_entry;
3823 }
3824 zig_unreachable();
3825 }
3826 return nullptr;
3827}
3828
38293792TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {
38303793 assert(enum_type->id == ZigTypeIdEnum);
38313794 if (enum_type->data.enumeration.src_field_count == 0)
......@@ -3907,7 +3870,6 @@ static bool is_container(ZigType *type_entry) {
39073870 case ZigTypeIdErrorSet:
39083871 case ZigTypeIdFn:
39093872 case ZigTypeIdNamespace:
3910 case ZigTypeIdBlock:
39113873 case ZigTypeIdBoundFn:
39123874 case ZigTypeIdArgTuple:
39133875 case ZigTypeIdOpaque:
......@@ -3966,7 +3928,6 @@ void resolve_container_type(CodeGen *g, ZigType *type_entry) {
39663928 case ZigTypeIdErrorSet:
39673929 case ZigTypeIdFn:
39683930 case ZigTypeIdNamespace:
3969 case ZigTypeIdBlock:
39703931 case ZigTypeIdBoundFn:
39713932 case ZigTypeIdInvalid:
39723933 case ZigTypeIdArgTuple:
......@@ -4427,7 +4388,6 @@ bool handle_is_ptr(ZigType *type_entry) {
44274388 case ZigTypeIdUndefined:
44284389 case ZigTypeIdNull:
44294390 case ZigTypeIdNamespace:
4430 case ZigTypeIdBlock:
44314391 case ZigTypeIdBoundFn:
44324392 case ZigTypeIdArgTuple:
44334393 case ZigTypeIdOpaque:
......@@ -4842,8 +4802,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
48424802 return const_val->data.x_err_set->value ^ 2630160122;
48434803 case ZigTypeIdNamespace:
48444804 return hash_ptr(const_val->data.x_import);
4845 case ZigTypeIdBlock:
4846 return hash_ptr(const_val->data.x_block);
48474805 case ZigTypeIdBoundFn:
48484806 case ZigTypeIdInvalid:
48494807 case ZigTypeIdUnreachable:
......@@ -4904,7 +4862,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
49044862 case ZigTypeIdNamespace:
49054863 case ZigTypeIdBoundFn:
49064864 case ZigTypeIdFn:
4907 case ZigTypeIdBlock:
49084865 case ZigTypeIdOpaque:
49094866 case ZigTypeIdPromise:
49104867 case ZigTypeIdErrorSet:
......@@ -4971,7 +4928,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {
49714928 case ZigTypeIdNamespace:
49724929 case ZigTypeIdBoundFn:
49734930 case ZigTypeIdFn:
4974 case ZigTypeIdBlock:
49754931 case ZigTypeIdOpaque:
49764932 case ZigTypeIdPromise:
49774933 case ZigTypeIdErrorSet:
......@@ -5083,7 +5039,6 @@ bool type_requires_comptime(ZigType *type_entry) {
50835039 case ZigTypeIdNull:
50845040 case ZigTypeIdMetaType:
50855041 case ZigTypeIdNamespace:
5086 case ZigTypeIdBlock:
50875042 case ZigTypeIdBoundFn:
50885043 case ZigTypeIdArgTuple:
50895044 return true;
......@@ -5615,8 +5570,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
56155570 zig_panic("TODO");
56165571 case ZigTypeIdNamespace:
56175572 return a->data.x_import == b->data.x_import;
5618 case ZigTypeIdBlock:
5619 return a->data.x_block == b->data.x_block;
56205573 case ZigTypeIdArgTuple:
56215574 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&
56225575 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;
......@@ -5795,12 +5748,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
57955748 }
57965749 case ZigTypeIdPointer:
57975750 return render_const_val_ptr(g, buf, const_val, type_entry);
5798 case ZigTypeIdBlock:
5799 {
5800 AstNode *node = const_val->data.x_block->source_node;
5801 buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);
5802 return;
5803 }
58045751 case ZigTypeIdArray:
58055752 {
58065753 ZigType *child_type = type_entry->data.array.child_type;
......@@ -5980,7 +5927,6 @@ uint32_t type_id_hash(TypeId x) {
59805927 case ZigTypeIdUnion:
59815928 case ZigTypeIdFn:
59825929 case ZigTypeIdNamespace:
5983 case ZigTypeIdBlock:
59845930 case ZigTypeIdBoundFn:
59855931 case ZigTypeIdArgTuple:
59865932 case ZigTypeIdPromise:
......@@ -6027,7 +5973,6 @@ bool type_id_eql(TypeId a, TypeId b) {
60275973 case ZigTypeIdUnion:
60285974 case ZigTypeIdFn:
60295975 case ZigTypeIdNamespace:
6030 case ZigTypeIdBlock:
60315976 case ZigTypeIdBoundFn:
60325977 case ZigTypeIdArgTuple:
60335978 case ZigTypeIdOpaque:
......@@ -6153,7 +6098,6 @@ static const ZigTypeId all_type_ids[] = {
61536098 ZigTypeIdUnion,
61546099 ZigTypeIdFn,
61556100 ZigTypeIdNamespace,
6156 ZigTypeIdBlock,
61576101 ZigTypeIdBoundFn,
61586102 ZigTypeIdArgTuple,
61596103 ZigTypeIdOpaque,
......@@ -6215,16 +6159,14 @@ size_t type_id_index(ZigType *entry) {
62156159 return 18;
62166160 case ZigTypeIdNamespace:
62176161 return 19;
6218 case ZigTypeIdBlock:
6219 return 20;
62206162 case ZigTypeIdBoundFn:
6221 return 21;
6163 return 20;
62226164 case ZigTypeIdArgTuple:
6223 return 22;
6165 return 21;
62246166 case ZigTypeIdOpaque:
6225 return 23;
6167 return 22;
62266168 case ZigTypeIdPromise:
6227 return 24;
6169 return 23;
62286170 }
62296171 zig_unreachable();
62306172}
......@@ -6273,8 +6215,6 @@ const char *type_id_name(ZigTypeId id) {
62736215 return "Fn";
62746216 case ZigTypeIdNamespace:
62756217 return "Namespace";
6276 case ZigTypeIdBlock:
6277 return "Block";
62786218 case ZigTypeIdBoundFn:
62796219 return "BoundFn";
62806220 case ZigTypeIdArgTuple:
src/analyze.hpp-1
......@@ -87,7 +87,6 @@ ZigFn *create_fn(AstNode *proto_node);
8787ZigFn *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);
8888void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);
8989AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
90ZigFn *scope_get_fn_if_root(Scope *scope);
9190bool type_requires_comptime(ZigType *type_entry);
9291Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);
9392Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry);
src/ast_render.cpp-7
......@@ -193,8 +193,6 @@ static const char *node_type_str(NodeType node_type) {
193193 return "NullLiteral";
194194 case NodeTypeUndefinedLiteral:
195195 return "UndefinedLiteral";
196 case NodeTypeThisLiteral:
197 return "ThisLiteral";
198196 case NodeTypeIfBoolExpr:
199197 return "IfBoolExpr";
200198 case NodeTypeWhileExpr:
......@@ -897,11 +895,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
897895 }
898896 break;
899897 }
900 case NodeTypeThisLiteral:
901 {
902 fprintf(ar->f, "this");
903 break;
904 }
905898 case NodeTypeBoolLiteral:
906899 {
907900 const char *bool_str = node->data.bool_literal.value ? "true" : "false";
src/codegen.cpp+1-12
......@@ -5479,7 +5479,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
54795479 case ZigTypeIdErrorUnion:
54805480 case ZigTypeIdErrorSet:
54815481 case ZigTypeIdNamespace:
5482 case ZigTypeIdBlock:
54835482 case ZigTypeIdBoundFn:
54845483 case ZigTypeIdArgTuple:
54855484 case ZigTypeIdVoid:
......@@ -5954,7 +5953,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
59545953 case ZigTypeIdUndefined:
59555954 case ZigTypeIdNull:
59565955 case ZigTypeIdNamespace:
5957 case ZigTypeIdBlock:
59585956 case ZigTypeIdBoundFn:
59595957 case ZigTypeIdArgTuple:
59605958 case ZigTypeIdOpaque:
......@@ -6477,12 +6475,6 @@ static void define_builtin_types(CodeGen *g) {
64776475 entry->zero_bits = true;
64786476 g->builtin_types.entry_namespace = entry;
64796477 }
6480 {
6481 ZigType *entry = new_type_table_entry(ZigTypeIdBlock);
6482 buf_init_from_str(&entry->name, "(block)");
6483 entry->zero_bits = true;
6484 g->builtin_types.entry_block = entry;
6485 }
64866478 {
64876479 ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
64886480 buf_init_from_str(&entry->name, "comptime_float");
......@@ -6763,6 +6755,7 @@ static void define_builtin_fns(CodeGen *g) {
67636755 create_builtin_fn(g, BuiltinFnIdErrSetCast, "errSetCast", 2);
67646756 create_builtin_fn(g, BuiltinFnIdToBytes, "sliceToBytes", 1);
67656757 create_builtin_fn(g, BuiltinFnIdFromBytes, "bytesToSlice", 2);
6758 create_builtin_fn(g, BuiltinFnIdThis, "This", 0);
67666759}
67676760
67686761static const char *bool_to_str(bool b) {
......@@ -6944,7 +6937,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
69446937 " Union: Union,\n"
69456938 " Fn: Fn,\n"
69466939 " Namespace: void,\n"
6947 " Block: void,\n"
69486940 " BoundFn: Fn,\n"
69496941 " ArgTuple: void,\n"
69506942 " Opaque: void,\n"
......@@ -7589,7 +7581,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
75897581 case ZigTypeIdUndefined:
75907582 case ZigTypeIdNull:
75917583 case ZigTypeIdNamespace:
7592 case ZigTypeIdBlock:
75937584 case ZigTypeIdBoundFn:
75947585 case ZigTypeIdArgTuple:
75957586 case ZigTypeIdErrorUnion:
......@@ -7768,7 +7759,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
77687759 case ZigTypeIdMetaType:
77697760 case ZigTypeIdBoundFn:
77707761 case ZigTypeIdNamespace:
7771 case ZigTypeIdBlock:
77727762 case ZigTypeIdComptimeFloat:
77737763 case ZigTypeIdComptimeInt:
77747764 case ZigTypeIdUndefined:
......@@ -7921,7 +7911,6 @@ static void gen_h_file(CodeGen *g) {
79217911 case ZigTypeIdErrorUnion:
79227912 case ZigTypeIdErrorSet:
79237913 case ZigTypeIdNamespace:
7924 case ZigTypeIdBlock:
79257914 case ZigTypeIdBoundFn:
79267915 case ZigTypeIdArgTuple:
79277916 case ZigTypeIdOptional:
src/ir.cpp+20-61
......@@ -1029,12 +1029,6 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
10291029 return &const_instruction->base;
10301030}
10311031
1032static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
1033 IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry);
1034 ir_instruction_append(irb->current_basic_block, instruction);
1035 return instruction;
1036}
1037
10381032static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) {
10391033 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
10401034 const_instruction->base.value.type = irb->codegen->builtin_types.entry_namespace;
......@@ -1043,16 +1037,6 @@ static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNod
10431037 return &const_instruction->base;
10441038}
10451039
1046static IrInstruction *ir_build_const_scope(IrBuilder *irb, Scope *parent_scope, AstNode *source_node,
1047 Scope *target_scope)
1048{
1049 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, parent_scope, source_node);
1050 const_instruction->base.value.type = irb->codegen->builtin_types.entry_block;
1051 const_instruction->base.value.special = ConstValSpecialStatic;
1052 const_instruction->base.value.data.x_block = target_scope;
1053 return &const_instruction->base;
1054}
1055
10561040static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {
10571041 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
10581042 const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool;
......@@ -3892,6 +3876,21 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *
38923876 return ir_build_overflow_op(irb, scope, node, op, type_value, op1, op2, result_ptr, nullptr);
38933877}
38943878
3879static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *node) {
3880 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {
3881 if (it_scope->id == ScopeIdDecls) {
3882 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;
3883 ZigType *container_type = decls_scope->container_type;
3884 if (container_type != nullptr) {
3885 return ir_build_const_type(irb, orig_scope, node, container_type);
3886 } else {
3887 return ir_build_const_import(irb, orig_scope, node, decls_scope->import);
3888 }
3889 }
3890 }
3891 zig_unreachable();
3892}
3893
38953894static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {
38963895 assert(node->type == NodeTypeFnCallExpr);
38973896
......@@ -4830,6 +4829,11 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
48304829 IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node);
48314830 return ir_lval_wrap(irb, scope, opaque_type, lval);
48324831 }
4832 case BuiltinFnIdThis:
4833 {
4834 IrInstruction *this_inst = ir_gen_this(irb, scope, node);
4835 return ir_lval_wrap(irb, scope, this_inst, lval);
4836 }
48334837 case BuiltinFnIdSetAlignStack:
48344838 {
48354839 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
......@@ -5681,33 +5685,6 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
56815685 return ir_build_phi(irb, parent_scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
56825686}
56835687
5684static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
5685 assert(node->type == NodeTypeThisLiteral);
5686
5687 if (!scope->parent)
5688 return ir_build_const_import(irb, scope, node, node->owner);
5689
5690 ZigFn *fn_entry = scope_get_fn_if_root(scope);
5691 if (fn_entry)
5692 return ir_build_const_fn(irb, scope, node, fn_entry);
5693
5694 while (scope->id != ScopeIdBlock && scope->id != ScopeIdDecls) {
5695 scope = scope->parent;
5696 }
5697
5698 if (scope->id == ScopeIdDecls) {
5699 ScopeDecls *decls_scope = (ScopeDecls *)scope;
5700 ZigType *container_type = decls_scope->container_type;
5701 assert(container_type);
5702 return ir_build_const_type(irb, scope, node, container_type);
5703 }
5704
5705 if (scope->id == ScopeIdBlock)
5706 return ir_build_const_scope(irb, scope, node, scope);
5707
5708 zig_unreachable();
5709}
5710
57115688static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
57125689 assert(node->type == NodeTypeBoolLiteral);
57135690 return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value);
......@@ -7285,8 +7262,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
72857262
72867263 return ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
72877264 }
7288 case NodeTypeThisLiteral:
7289 return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval);
72907265 case NodeTypeBoolLiteral:
72917266 return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval);
72927267 case NodeTypeArrayType:
......@@ -11621,7 +11596,6 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op
1162111596 case ZigTypeIdFn:
1162211597 case ZigTypeIdOpaque:
1162311598 case ZigTypeIdNamespace:
11624 case ZigTypeIdBlock:
1162511599 case ZigTypeIdBoundFn:
1162611600 case ZigTypeIdArgTuple:
1162711601 case ZigTypeIdPromise:
......@@ -12822,7 +12796,6 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor
1282212796 case ZigTypeIdErrorUnion:
1282312797 case ZigTypeIdErrorSet:
1282412798 case ZigTypeIdNamespace:
12825 case ZigTypeIdBlock:
1282612799 case ZigTypeIdBoundFn:
1282712800 case ZigTypeIdArgTuple:
1282812801 case ZigTypeIdOpaque:
......@@ -12847,7 +12820,6 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor
1284712820 case ZigTypeIdErrorSet:
1284812821 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
1284912822 case ZigTypeIdNamespace:
12850 case ZigTypeIdBlock:
1285112823 case ZigTypeIdBoundFn:
1285212824 case ZigTypeIdArgTuple:
1285312825 case ZigTypeIdOpaque:
......@@ -13905,7 +13877,6 @@ static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instru
1390513877 case ZigTypeIdUnion:
1390613878 case ZigTypeIdFn:
1390713879 case ZigTypeIdNamespace:
13908 case ZigTypeIdBlock:
1390913880 case ZigTypeIdBoundFn:
1391013881 case ZigTypeIdArgTuple:
1391113882 case ZigTypeIdPromise:
......@@ -15263,7 +15234,6 @@ static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeO
1526315234 case ZigTypeIdUndefined:
1526415235 case ZigTypeIdNull:
1526515236 case ZigTypeIdNamespace:
15266 case ZigTypeIdBlock:
1526715237 case ZigTypeIdBoundFn:
1526815238 case ZigTypeIdMetaType:
1526915239 case ZigTypeIdVoid:
......@@ -15516,7 +15486,6 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1551615486 case ZigTypeIdUnreachable:
1551715487 case ZigTypeIdUndefined:
1551815488 case ZigTypeIdNull:
15519 case ZigTypeIdBlock:
1552015489 case ZigTypeIdArgTuple:
1552115490 case ZigTypeIdOpaque:
1552215491 ir_add_error_node(ira, slice_type_instruction->base.source_node,
......@@ -15627,7 +15596,6 @@ static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira,
1562715596 case ZigTypeIdUnreachable:
1562815597 case ZigTypeIdUndefined:
1562915598 case ZigTypeIdNull:
15630 case ZigTypeIdBlock:
1563115599 case ZigTypeIdArgTuple:
1563215600 case ZigTypeIdOpaque:
1563315601 ir_add_error_node(ira, array_type_instruction->base.source_node,
......@@ -15698,7 +15666,6 @@ static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira,
1569815666 case ZigTypeIdUnreachable:
1569915667 case ZigTypeIdUndefined:
1570015668 case ZigTypeIdNull:
15701 case ZigTypeIdBlock:
1570215669 case ZigTypeIdComptimeFloat:
1570315670 case ZigTypeIdComptimeInt:
1570415671 case ZigTypeIdBoundFn:
......@@ -16184,7 +16151,6 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1618416151 case ZigTypeIdUndefined:
1618516152 case ZigTypeIdNull:
1618616153 case ZigTypeIdOptional:
16187 case ZigTypeIdBlock:
1618816154 case ZigTypeIdBoundFn:
1618916155 case ZigTypeIdArgTuple:
1619016156 case ZigTypeIdOpaque:
......@@ -16705,7 +16671,6 @@ static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruc
1670516671 case ZigTypeIdUnion:
1670616672 case ZigTypeIdFn:
1670716673 case ZigTypeIdNamespace:
16708 case ZigTypeIdBlock:
1670916674 case ZigTypeIdBoundFn:
1671016675 case ZigTypeIdArgTuple:
1671116676 case ZigTypeIdOpaque:
......@@ -17368,7 +17333,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1736817333 case ZigTypeIdUndefined:
1736917334 case ZigTypeIdNull:
1737017335 case ZigTypeIdNamespace:
17371 case ZigTypeIdBlock:
1737217336 case ZigTypeIdArgTuple:
1737317337 case ZigTypeIdOpaque:
1737417338 *out = nullptr;
......@@ -19341,7 +19305,6 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli
1934119305 case ZigTypeIdUndefined:
1934219306 case ZigTypeIdNull:
1934319307 case ZigTypeIdNamespace:
19344 case ZigTypeIdBlock:
1934519308 case ZigTypeIdBoundFn:
1934619309 case ZigTypeIdArgTuple:
1934719310 case ZigTypeIdVoid:
......@@ -20102,7 +20065,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
2010220065 case ZigTypeIdBoundFn:
2010320066 case ZigTypeIdArgTuple:
2010420067 case ZigTypeIdNamespace:
20105 case ZigTypeIdBlock:
2010620068 case ZigTypeIdUnreachable:
2010720069 case ZigTypeIdComptimeFloat:
2010820070 case ZigTypeIdComptimeInt:
......@@ -20169,7 +20131,6 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
2016920131 case ZigTypeIdBoundFn:
2017020132 case ZigTypeIdArgTuple:
2017120133 case ZigTypeIdNamespace:
20172 case ZigTypeIdBlock:
2017320134 case ZigTypeIdUnreachable:
2017420135 case ZigTypeIdComptimeFloat:
2017520136 case ZigTypeIdComptimeInt:
......@@ -20249,7 +20210,6 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit
2024920210 case ZigTypeIdBoundFn:
2025020211 case ZigTypeIdArgTuple:
2025120212 case ZigTypeIdNamespace:
20252 case ZigTypeIdBlock:
2025320213 case ZigTypeIdUnreachable:
2025420214 case ZigTypeIdComptimeFloat:
2025520215 case ZigTypeIdComptimeInt:
......@@ -20275,7 +20235,6 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit
2027520235 case ZigTypeIdBoundFn:
2027620236 case ZigTypeIdArgTuple:
2027720237 case ZigTypeIdNamespace:
20278 case ZigTypeIdBlock:
2027920238 case ZigTypeIdUnreachable:
2028020239 case ZigTypeIdComptimeFloat:
2028120240 case ZigTypeIdComptimeInt:
src/parser.cpp+1-8
......@@ -700,7 +700,7 @@ static AstNode *ast_parse_comptime_expr(ParseContext *pc, size_t *token_index, b
700700
701701/*
702702PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ContainerDecl | ("continue" option(":" Symbol)) | ErrorSetDecl | PromiseType
703KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "this" | "unreachable" | "suspend"
703KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "unreachable" | "suspend"
704704ErrorSetDecl = "error" "{" list(Symbol, ",") "}"
705705*/
706706static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
......@@ -756,10 +756,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
756756 AstNode *node = ast_create_node(pc, NodeTypeUndefinedLiteral, token);
757757 *token_index += 1;
758758 return node;
759 } else if (token->id == TokenIdKeywordThis) {
760 AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token);
761 *token_index += 1;
762 return node;
763759 } else if (token->id == TokenIdKeywordUnreachable) {
764760 AstNode *node = ast_create_node(pc, NodeTypeUnreachable, token);
765761 *token_index += 1;
......@@ -3021,9 +3017,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
30213017 case NodeTypeUndefinedLiteral:
30223018 // none
30233019 break;
3024 case NodeTypeThisLiteral:
3025 // none
3026 break;
30273020 case NodeTypeIfBoolExpr:
30283021 visit_field(&node->data.if_bool_expr.condition, visit, context);
30293022 visit_field(&node->data.if_bool_expr.then_block, visit, context);
src/tokenizer.cpp-2
......@@ -146,7 +146,6 @@ static const struct ZigKeyword zig_keywords[] = {
146146 {"suspend", TokenIdKeywordSuspend},
147147 {"switch", TokenIdKeywordSwitch},
148148 {"test", TokenIdKeywordTest},
149 {"this", TokenIdKeywordThis},
150149 {"true", TokenIdKeywordTrue},
151150 {"try", TokenIdKeywordTry},
152151 {"undefined", TokenIdKeywordUndefined},
......@@ -1588,7 +1587,6 @@ const char * token_name(TokenId id) {
15881587 case TokenIdKeywordStruct: return "struct";
15891588 case TokenIdKeywordSwitch: return "switch";
15901589 case TokenIdKeywordTest: return "test";
1591 case TokenIdKeywordThis: return "this";
15921590 case TokenIdKeywordTrue: return "true";
15931591 case TokenIdKeywordTry: return "try";
15941592 case TokenIdKeywordUndefined: return "undefined";
src/tokenizer.hpp-1
......@@ -87,7 +87,6 @@ enum TokenId {
8787 TokenIdKeywordSuspend,
8888 TokenIdKeywordSwitch,
8989 TokenIdKeywordTest,
90 TokenIdKeywordThis,
9190 TokenIdKeywordTrue,
9291 TokenIdKeywordTry,
9392 TokenIdKeywordUndefined,
std/array_list.zig+1-1
......@@ -11,7 +11,7 @@ pub fn ArrayList(comptime T: type) type {
1111
1212pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
1313 return struct {
14 const Self = this;
14 const Self = @This();
1515
1616 /// Use toSlice instead of slicing this directly, because if you don't
1717 /// specify the end position of the slice, this will potentially give
std/atomic/int.zig+1-1
......@@ -6,7 +6,7 @@ pub fn Int(comptime T: type) type {
66 return struct {
77 unprotected_value: T,
88
9 pub const Self = this;
9 pub const Self = @This();
1010
1111 pub fn init(init_val: T) Self {
1212 return Self{ .unprotected_value = init_val };
std/atomic/queue.zig+1-1
......@@ -12,7 +12,7 @@ pub fn Queue(comptime T: type) type {
1212 tail: ?*Node,
1313 mutex: std.Mutex,
1414
15 pub const Self = this;
15 pub const Self = @This();
1616 pub const Node = std.LinkedList(T).Node;
1717
1818 pub fn init() Self {
std/atomic/stack.zig+1-1
......@@ -9,7 +9,7 @@ pub fn Stack(comptime T: type) type {
99 root: ?*Node,
1010 lock: u8,
1111
12 pub const Self = this;
12 pub const Self = @This();
1313
1414 pub const Node = struct {
1515 next: ?*Node,
std/build.zig+1-1
......@@ -1890,7 +1890,7 @@ const InstallArtifactStep = struct {
18901890 artifact: *LibExeObjStep,
18911891 dest_file: []const u8,
18921892
1893 const Self = this;
1893 const Self = @This();
18941894
18951895 pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {
18961896 const dest_dir = switch (artifact.kind) {
std/crypto/blake2.zig+2-2
......@@ -33,7 +33,7 @@ pub const Blake2s256 = Blake2s(256);
3333
3434fn Blake2s(comptime out_len: usize) type {
3535 return struct {
36 const Self = this;
36 const Self = @This();
3737 const block_length = 64;
3838 const digest_length = out_len / 8;
3939
......@@ -266,7 +266,7 @@ pub const Blake2b512 = Blake2b(512);
266266
267267fn Blake2b(comptime out_len: usize) type {
268268 return struct {
269 const Self = this;
269 const Self = @This();
270270 const block_length = 128;
271271 const digest_length = out_len / 8;
272272
std/crypto/hmac.zig+1-1
......@@ -9,7 +9,7 @@ pub const HmacSha256 = Hmac(crypto.Sha256);
99
1010pub fn Hmac(comptime Hash: type) type {
1111 return struct {
12 const Self = this;
12 const Self = @This();
1313 pub const mac_length = Hash.digest_length;
1414 pub const minimum_key_length = 0;
1515
std/crypto/md5.zig+1-1
......@@ -28,7 +28,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) RoundPar
2828}
2929
3030pub const Md5 = struct {
31 const Self = this;
31 const Self = @This();
3232 const block_length = 64;
3333 const digest_length = 16;
3434
std/crypto/poly1305.zig+1-1
......@@ -10,7 +10,7 @@ const readInt = std.mem.readInt;
1010const writeInt = std.mem.writeInt;
1111
1212pub const Poly1305 = struct {
13 const Self = this;
13 const Self = @This();
1414
1515 pub const mac_length = 16;
1616 pub const minimum_key_length = 32;
std/crypto/sha1.zig+1-1
......@@ -25,7 +25,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) RoundParam {
2525}
2626
2727pub const Sha1 = struct {
28 const Self = this;
28 const Self = @This();
2929 const block_length = 64;
3030 const digest_length = 20;
3131
std/crypto/sha2.zig+2-2
......@@ -77,7 +77,7 @@ pub const Sha256 = Sha2_32(Sha256Params);
7777
7878fn Sha2_32(comptime params: Sha2Params32) type {
7979 return struct {
80 const Self = this;
80 const Self = @This();
8181 const block_length = 64;
8282 const digest_length = params.out_len / 8;
8383
......@@ -418,7 +418,7 @@ pub const Sha512 = Sha2_64(Sha512Params);
418418
419419fn Sha2_64(comptime params: Sha2Params64) type {
420420 return struct {
421 const Self = this;
421 const Self = @This();
422422 const block_length = 128;
423423 const digest_length = params.out_len / 8;
424424
std/crypto/sha3.zig+1-1
......@@ -12,7 +12,7 @@ pub const Sha3_512 = Keccak(512, 0x06);
1212
1313fn Keccak(comptime bits: usize, comptime delim: u8) type {
1414 return struct {
15 const Self = this;
15 const Self = @This();
1616 const block_length = 200;
1717 const digest_length = bits / 8;
1818
std/event/channel.zig+1-1
......@@ -25,7 +25,7 @@ pub fn Channel(comptime T: type) type {
2525 buffer_index: usize,
2626 buffer_len: usize,
2727
28 const SelfChannel = this;
28 const SelfChannel = @This();
2929 const GetNode = struct {
3030 tick_node: *Loop.NextTickNode,
3131 data: Data,
std/event/fs.zig+1-1
......@@ -724,7 +724,7 @@ pub fn Watch(comptime V: type) type {
724724
725725 const FileToHandle = std.AutoHashMap([]const u8, promise);
726726
727 const Self = this;
727 const Self = @This();
728728
729729 pub const Event = struct {
730730 id: Id,
std/event/future.zig+1-1
......@@ -21,7 +21,7 @@ pub fn Future(comptime T: type) type {
2121 /// 2 - finished
2222 available: u8,
2323
24 const Self = this;
24 const Self = @This();
2525 const Queue = std.atomic.Queue(promise);
2626
2727 pub fn init(loop: *Loop) Self {
std/event/group.zig+1-1
......@@ -13,7 +13,7 @@ pub fn Group(comptime ReturnType: type) type {
1313 alloc_stack: Stack,
1414 lock: Lock,
1515
16 const Self = this;
16 const Self = @This();
1717
1818 const Error = switch (@typeInfo(ReturnType)) {
1919 builtin.TypeId.ErrorUnion => |payload| payload.error_set,
std/event/locked.zig+1-1
......@@ -10,7 +10,7 @@ pub fn Locked(comptime T: type) type {
1010 lock: Lock,
1111 private_data: T,
1212
13 const Self = this;
13 const Self = @This();
1414
1515 pub const HeldLock = struct {
1616 value: *T,
std/event/rwlocked.zig+1-1
......@@ -10,7 +10,7 @@ pub fn RwLocked(comptime T: type) type {
1010 lock: RwLock,
1111 locked_data: T,
1212
13 const Self = this;
13 const Self = @This();
1414
1515 pub const HeldReadLock = struct {
1616 value: *const T,
std/event/tcp.zig+1-1
......@@ -132,7 +132,7 @@ test "listen on a port, send bytes, receive bytes" {
132132 const MyServer = struct {
133133 tcp_server: Server,
134134
135 const Self = this;
135 const Self = @This();
136136 async<*mem.Allocator> fn handler(tcp_server: *Server, _addr: *const std.net.Address, _socket: *const std.os.File) void {
137137 const self = @fieldParentPtr(Self, "tcp_server", tcp_server);
138138 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733
std/fmt/index.zig+1-1
......@@ -1183,7 +1183,7 @@ test "fmt.format" {
11831183 //custom type format
11841184 {
11851185 const Vec2 = struct {
1186 const SelfType = this;
1186 const SelfType = @This();
11871187 x: f32,
11881188 y: f32,
11891189
std/hash/crc.zig+2-2
......@@ -20,7 +20,7 @@ pub const Crc32 = Crc32WithPoly(Polynomial.IEEE);
2020// slicing-by-8 crc32 implementation.
2121pub fn Crc32WithPoly(comptime poly: u32) type {
2222 return struct {
23 const Self = this;
23 const Self = @This();
2424 const lookup_tables = comptime block: {
2525 @setEvalBranchQuota(20000);
2626 var tables: [8][256]u32 = undefined;
......@@ -117,7 +117,7 @@ test "crc32 castagnoli" {
117117// half-byte lookup table implementation.
118118pub fn Crc32SmallWithPoly(comptime poly: u32) type {
119119 return struct {
120 const Self = this;
120 const Self = @This();
121121 const lookup_table = comptime block: {
122122 var table: [16]u32 = undefined;
123123
std/hash/fnv.zig+1-1
......@@ -13,7 +13,7 @@ pub const Fnv1a_128 = Fnv1a(u128, 0x1000000000000000000013b, 0x6c62272e07bb01426
1313
1414fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
1515 return struct {
16 const Self = this;
16 const Self = @This();
1717
1818 value: T,
1919
std/hash/siphash.zig+1-1
......@@ -25,7 +25,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
2525 debug.assert(c_rounds > 0 and d_rounds > 0);
2626
2727 return struct {
28 const Self = this;
28 const Self = @This();
2929 const digest_size = 64;
3030 const block_size = 64;
3131
std/hash_map.zig+1-3
......@@ -22,7 +22,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
2222 // this is used to detect bugs where a hashtable is edited while an iterator is running.
2323 modification_count: debug_u32,
2424
25 const Self = this;
25 const Self = @This();
2626
2727 pub const KV = struct {
2828 key: K,
......@@ -472,7 +472,6 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type
472472 builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng),
473473
474474 builtin.TypeId.Namespace,
475 builtin.TypeId.Block,
476475 builtin.TypeId.BoundFn,
477476 builtin.TypeId.ComptimeFloat,
478477 builtin.TypeId.ComptimeInt,
......@@ -517,7 +516,6 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool {
517516 builtin.TypeId.ComptimeFloat,
518517 builtin.TypeId.ComptimeInt,
519518 builtin.TypeId.Namespace,
520 builtin.TypeId.Block,
521519 builtin.TypeId.Promise,
522520 builtin.TypeId.Enum,
523521 builtin.TypeId.BoundFn,
std/heap.zig+1-1
......@@ -385,7 +385,7 @@ pub fn stackFallback(comptime size: usize, fallback_allocator: *Allocator) Stack
385385
386386pub fn StackFallbackAllocator(comptime size: usize) type {
387387 return struct {
388 const Self = this;
388 const Self = @This();
389389
390390 buffer: [size]u8,
391391 allocator: Allocator,
std/io.zig+6-6
......@@ -76,7 +76,7 @@ pub const FileOutStream = struct {
7676
7777pub fn InStream(comptime ReadError: type) type {
7878 return struct {
79 const Self = this;
79 const Self = @This();
8080 pub const Error = ReadError;
8181
8282 /// Return the number of bytes read. If the number read is smaller than buf.len, it
......@@ -218,7 +218,7 @@ pub fn InStream(comptime ReadError: type) type {
218218
219219pub fn OutStream(comptime WriteError: type) type {
220220 return struct {
221 const Self = this;
221 const Self = @This();
222222 pub const Error = WriteError;
223223
224224 writeFn: fn (self: *Self, bytes: []const u8) Error!void,
......@@ -291,7 +291,7 @@ pub fn BufferedInStream(comptime Error: type) type {
291291
292292pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type {
293293 return struct {
294 const Self = this;
294 const Self = @This();
295295 const Stream = InStream(Error);
296296
297297 pub stream: Stream,
......@@ -361,7 +361,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
361361/// This makes look-ahead style parsing much easier.
362362pub fn PeekStream(comptime buffer_size: usize, comptime InStreamError: type) type {
363363 return struct {
364 const Self = this;
364 const Self = @This();
365365 pub const Error = InStreamError;
366366 pub const Stream = InStream(Error);
367367
......@@ -424,7 +424,7 @@ pub fn PeekStream(comptime buffer_size: usize, comptime InStreamError: type) typ
424424}
425425
426426pub const SliceInStream = struct {
427 const Self = this;
427 const Self = @This();
428428 pub const Error = error{};
429429 pub const Stream = InStream(Error);
430430
......@@ -505,7 +505,7 @@ pub fn BufferedOutStream(comptime Error: type) type {
505505
506506pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamError: type) type {
507507 return struct {
508 const Self = this;
508 const Self = @This();
509509 pub const Stream = OutStream(Error);
510510 pub const Error = OutStreamError;
511511
std/lazy_init.zig+1-1
......@@ -18,7 +18,7 @@ fn LazyInit(comptime T: type) type {
1818 state: u8, // TODO make this an enum
1919 data: Data,
2020
21 const Self = this;
21 const Self = @This();
2222
2323 // TODO this isn't working for void, investigate and then remove this special case
2424 const Data = if (@sizeOf(T) == 0) u8 else T;
std/linked_list.zig+1-1
......@@ -7,7 +7,7 @@ const Allocator = mem.Allocator;
77/// Generic doubly linked list.
88pub fn LinkedList(comptime T: type) type {
99 return struct {
10 const Self = this;
10 const Self = @This();
1111
1212 /// Node inside the linked list wrapping the actual data.
1313 pub const Node = struct {
std/math/complex/index.zig+1-1
......@@ -25,7 +25,7 @@ pub const tan = @import("tan.zig").tan;
2525
2626pub fn Complex(comptime T: type) type {
2727 return struct {
28 const Self = this;
28 const Self = @This();
2929
3030 re: T,
3131 im: T,
std/mem.zig+1-1
......@@ -3,7 +3,7 @@ const debug = std.debug;
33const assert = debug.assert;
44const math = std.math;
55const builtin = @import("builtin");
6const mem = this;
6const mem = @This();
77
88pub const Allocator = struct {
99 pub const Error = error{OutOfMemory};
std/net.zig+1-1
......@@ -1,7 +1,7 @@
11const std = @import("index.zig");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const net = this;
4const net = @This();
55const posix = std.os.posix;
66const mem = std.mem;
77
std/os/index.zig+1-1
......@@ -6,7 +6,7 @@ const is_posix = switch (builtin.os) {
66 builtin.Os.linux, builtin.Os.macosx => true,
77 else => false,
88};
9const os = this;
9const os = @This();
1010
1111test "std.os" {
1212 _ = @import("child_process.zig");
std/segmented_list.zig+1-1
......@@ -75,7 +75,7 @@ const Allocator = std.mem.Allocator;
7575/// size is small. `prealloc_item_count` must be 0, or a power of 2.
7676pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type {
7777 return struct {
78 const Self = this;
78 const Self = @This();
7979 const prealloc_exp = blk: {
8080 // we don't use the prealloc_exp constant when prealloc_item_count is 0.
8181 assert(prealloc_item_count != 0);
std/zig/ast.zig+2-2
......@@ -231,7 +231,7 @@ pub const Error = union(enum) {
231231
232232 fn SingleTokenError(comptime msg: []const u8) type {
233233 return struct {
234 const ThisError = this;
234 const ThisError = @This();
235235
236236 token: TokenIndex,
237237
......@@ -244,7 +244,7 @@ pub const Error = union(enum) {
244244
245245 fn SimpleError(comptime msg: []const u8) type {
246246 return struct {
247 const ThisError = this;
247 const ThisError = @This();
248248
249249 token: TokenIndex,
250250
std/zig/parser_test.zig+1-1
......@@ -1354,7 +1354,7 @@ test "zig fmt: indexing" {
13541354test "zig fmt: struct declaration" {
13551355 try testCanonical(
13561356 \\const S = struct {
1357 \\ const Self = this;
1357 \\ const Self = @This();
13581358 \\ f1: u8,
13591359 \\ pub f3: u8,
13601360 \\
std/zig/render.zig+1-1
......@@ -20,7 +20,7 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(
2020
2121 // make a passthrough stream that checks whether something changed
2222 const MyStream = struct {
23 const MyStream = this;
23 const MyStream = @This();
2424 const StreamError = @typeOf(stream).Child.Error;
2525 const Stream = std.io.OutStream(StreamError);
2626
test/cases/cast.zig+2-2
......@@ -64,7 +64,7 @@ test "implicitly cast a container to a const pointer of it" {
6464
6565fn Struct(comptime T: type) type {
6666 return struct {
67 const Self = this;
67 const Self = @This();
6868 x: T,
6969
7070 fn pointer(self: *const Self) Self {
......@@ -106,7 +106,7 @@ const Enum = enum {
106106
107107test "implicitly cast indirect pointer to maybe-indirect pointer" {
108108 const S = struct {
109 const Self = this;
109 const Self = @This();
110110 x: u8,
111111 fn constConst(p: *const *const Self) u8 {
112112 return p.*.x;
test/cases/eval.zig+1-1
......@@ -628,7 +628,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
628628 const S = struct {
629629 a: u8,
630630
631 fn b(comptime s: this) u8 {
631 fn b(comptime s: @This()) u8 {
632632 return s.a;
633633 }
634634 };
test/cases/misc.zig-3
......@@ -510,9 +510,6 @@ test "@typeId" {
510510 assert(@typeId(AUnion) == Tid.Union);
511511 assert(@typeId(fn () void) == Tid.Fn);
512512 assert(@typeId(@typeOf(builtin)) == Tid.Namespace);
513 assert(@typeId(@typeOf(x: {
514 break :x this;
515 })) == Tid.Block);
516513 // TODO bound fn
517514 // TODO arg tuple
518515 // TODO opaque
test/cases/reflection.zig+1-1
......@@ -1,6 +1,6 @@
11const assert = @import("std").debug.assert;
22const mem = @import("std").mem;
3const reflection = this;
3const reflection = @This();
44
55test "reflection: array, pointer, optional, error union type child" {
66 comptime {
test/cases/struct.zig+2-2
......@@ -423,10 +423,10 @@ fn alloc(comptime T: type) []T {
423423
424424test "call method with mutable reference to struct with no fields" {
425425 const S = struct {
426 fn doC(s: *const this) bool {
426 fn doC(s: *const @This()) bool {
427427 return true;
428428 }
429 fn do(s: *this) bool {
429 fn do(s: *@This()) bool {
430430 return true;
431431 }
432432 };
test/cases/this.zig+2-11
......@@ -1,10 +1,10 @@
11const assert = @import("std").debug.assert;
22
3const module = this;
3const module = @This();
44
55fn Point(comptime T: type) type {
66 return struct {
7 const Self = this;
7 const Self = @This();
88 x: T,
99 y: T,
1010
......@@ -19,11 +19,6 @@ fn add(x: i32, y: i32) i32 {
1919 return x + y;
2020}
2121
22fn factorial(x: i32) i32 {
23 const selfFn = this;
24 return if (x == 0) 1 else x * selfFn(x - 1);
25}
26
2722test "this refer to module call private fn" {
2823 assert(module.add(1, 2) == 3);
2924}
......@@ -37,7 +32,3 @@ test "this refer to container" {
3732 assert(pt.x == 13);
3833 assert(pt.y == 35);
3934}
40
41test "this refer to fn" {
42 assert(factorial(5) == 120);
43}
test/cases/type_info.zig+2-2
......@@ -166,7 +166,7 @@ fn testUnion() void {
166166 assert(TypeId(typeinfo_info) == TypeId.Union);
167167 assert(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
168168 assert(typeinfo_info.Union.tag_type.? == TypeId);
169 assert(typeinfo_info.Union.fields.len == 25);
169 assert(typeinfo_info.Union.fields.len == 24);
170170 assert(typeinfo_info.Union.fields[4].enum_field != null);
171171 assert(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
172172 assert(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
......@@ -217,7 +217,7 @@ fn testStruct() void {
217217}
218218
219219const TestStruct = packed struct {
220 const Self = this;
220 const Self = @This();
221221
222222 fieldA: usize,
223223 fieldB: void,
test/compile_errors.zig+13-15
......@@ -3813,11 +3813,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38133813 \\ return struct {
38143814 \\ b: B(),
38153815 \\
3816 \\ const Self = this;
3816 \\ const Self = @This();
38173817 \\
38183818 \\ fn B() type {
38193819 \\ return struct {
3820 \\ const Self = this;
3820 \\ const Self = @This();
38213821 \\ };
38223822 \\ }
38233823 \\ };
......@@ -4314,12 +4314,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
43144314 \\ var a = undefined;
43154315 \\ var b = 1;
43164316 \\ var c = 1.0;
4317 \\ var d = this;
4318 \\ var e = null;
4319 \\ var f = opaque.*;
4320 \\ var g = i32;
4321 \\ var h = @import("std",);
4322 \\ var i = (Foo {}).bar;
4317 \\ var d = null;
4318 \\ var e = opaque.*;
4319 \\ var f = i32;
4320 \\ var g = @import("std",);
4321 \\ var h = (Foo {}).bar;
43234322 \\
43244323 \\ var z: noreturn = return;
43254324 \\}
......@@ -4332,13 +4331,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
43324331 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",
43334332 ".tmp_source.zig:8:4: error: variable of type 'comptime_int' must be const or comptime",
43344333 ".tmp_source.zig:9:4: error: variable of type 'comptime_float' must be const or comptime",
4335 ".tmp_source.zig:10:4: error: variable of type '(block)' must be const or comptime",
4336 ".tmp_source.zig:11:4: error: variable of type '(null)' must be const or comptime",
4337 ".tmp_source.zig:12:4: error: variable of type 'Opaque' not allowed",
4338 ".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime",
4339 ".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime",
4340 ".tmp_source.zig:15:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
4341 ".tmp_source.zig:17:4: error: unreachable code",
4334 ".tmp_source.zig:10:4: error: variable of type '(null)' must be const or comptime",
4335 ".tmp_source.zig:11:4: error: variable of type 'Opaque' not allowed",
4336 ".tmp_source.zig:12:4: error: variable of type 'type' must be const or comptime",
4337 ".tmp_source.zig:13:4: error: variable of type '(namespace)' must be const or comptime",
4338 ".tmp_source.zig:14:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
4339 ".tmp_source.zig:16:4: error: unreachable code",
43424340 );
43434341
43444342 cases.add(