diff --git a/doc/langref.md b/doc/langref.md index e1948d20ad..c8cc3c588b 100644 --- a/doc/langref.md +++ b/doc/langref.md @@ -68,11 +68,11 @@ CompilerFnExpr : token(NumberSign) token(Symbol) token(LParen) Expression token( CompilerFnType : token(NumberSign) token(Symbol) token(LParen) Type token(RParen) -PointerType : token(Ampersand) option(token(Const)) option(token(Restrict)) Type +PointerType : token(Ampersand) option(token(Const)) option(token(NoAlias)) Type MaybeType : token(Question) Type -ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(Restrict)) Type +ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(NoAlias)) Type Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace) diff --git a/doc/vim/syntax/zig.vim b/doc/vim/syntax/zig.vim index c505a7e58c..5cc0aca16d 100644 --- a/doc/vim/syntax/zig.vim +++ b/doc/vim/syntax/zig.vim @@ -8,7 +8,7 @@ if exists("b:current_syntax") endif syn keyword zigOperator as -syn keyword zigStorage const var extern volatile export pub restrict +syn keyword zigStorage const var extern volatile export pub noalias syn keyword zigStructure struct enum type syn keyword zigStatement goto break return continue asm syn keyword zigConditional if else match diff --git a/src/analyze.cpp b/src/analyze.cpp index 3f4462be71..141492689a 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -135,8 +135,8 @@ static TypeTableEntry *get_number_literal_type_unsigned(CodeGen *g, uint64_t x) return g->num_lit_types[get_number_literal_kind_unsigned(x)]; } -TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_restrict) { - TypeTableEntry **parent_pointer = &child_type->pointer_parent[(is_const ? 1 : 0)][(is_restrict ? 1 : 0)]; +TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_noalias) { + TypeTableEntry **parent_pointer = &child_type->pointer_parent[(is_const ? 1 : 0)][(is_noalias ? 1 : 0)]; if (*parent_pointer) { return *parent_pointer; } else { @@ -151,7 +151,7 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool entry->size_in_bits, entry->align_in_bits, buf_ptr(&entry->name)); entry->data.pointer.child_type = child_type; entry->data.pointer.is_const = is_const; - entry->data.pointer.is_restrict = is_restrict; + entry->data.pointer.is_noalias = is_noalias; *parent_pointer = entry; return entry; @@ -240,9 +240,9 @@ static TypeTableEntry *get_array_type(CodeGen *g, ImportTableEntry *import, } static TypeTableEntry *get_unknown_size_array_type(CodeGen *g, ImportTableEntry *import, - TypeTableEntry *child_type, bool is_const, bool is_restrict) + TypeTableEntry *child_type, bool is_const, bool is_noalias) { - TypeTableEntry **parent_pointer = &child_type->unknown_size_array_parent[(is_const ? 1 : 0)][(is_restrict ? 1 : 0)]; + TypeTableEntry **parent_pointer = &child_type->unknown_size_array_parent[(is_const ? 1 : 0)][(is_noalias ? 1 : 0)]; if (*parent_pointer) { return *parent_pointer; } else { @@ -252,7 +252,7 @@ static TypeTableEntry *get_unknown_size_array_type(CodeGen *g, ImportTableEntry buf_appendf(&entry->name, "[]%s", buf_ptr(&child_type->name)); entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&entry->name)); - TypeTableEntry *pointer_type = get_pointer_to_type(g, child_type, is_const, is_restrict); + TypeTableEntry *pointer_type = get_pointer_to_type(g, child_type, is_const, is_noalias); unsigned element_count = 2; LLVMTypeRef element_types[] = { @@ -428,7 +428,7 @@ static TypeTableEntry *eval_const_expr(CodeGen *g, BlockContext *context, } static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry *import, - BlockContext *context, bool restrict_allowed) + BlockContext *context, bool noalias_allowed) { assert(node->type == NodeTypeType); alloc_codegen_node(node); @@ -449,13 +449,13 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry } case AstNodeTypeTypePointer: { - bool use_restrict = false; - if (node->data.type.is_restrict) { - if (!restrict_allowed) { + bool use_noalias = false; + if (node->data.type.is_noalias) { + if (!noalias_allowed) { add_node_error(g, node, - buf_create_from_str("invalid restrict qualifier")); + buf_create_from_str("invalid noalias qualifier")); } else { - use_restrict = true; + use_noalias = true; } } @@ -471,7 +471,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry type_node->entry = child_type; return child_type; } else { - type_node->entry = get_pointer_to_type(g, child_type, node->data.type.is_const, use_restrict); + type_node->entry = get_pointer_to_type(g, child_type, node->data.type.is_const, use_noalias); return type_node->entry; } } @@ -479,13 +479,13 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry { AstNode *size_node = node->data.type.array_size; - bool use_restrict = false; - if (node->data.type.is_restrict) { - if (!restrict_allowed || size_node) { + bool use_noalias = false; + if (node->data.type.is_noalias) { + if (!noalias_allowed || size_node) { add_node_error(g, node, - buf_create_from_str("invalid restrict qualifier")); + buf_create_from_str("invalid noalias qualifier")); } else { - use_restrict = true; + use_noalias = true; } } @@ -524,7 +524,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry return type_node->entry; } else { type_node->entry = get_unknown_size_array_type(g, import, child_type, - node->data.type.is_const, use_restrict); + node->data.type.is_const, use_noalias); return type_node->entry; } @@ -1221,7 +1221,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, BlockContext *cont return expected_type; } - // implicit non-const to const and ignore restrict + // implicit non-const to const and ignore noalias if (expected_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer && (!actual_type->data.pointer.is_const || expected_type->data.pointer.is_const)) diff --git a/src/analyze.hpp b/src/analyze.hpp index 8785a4c616..37d1a49d3f 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -23,7 +23,7 @@ struct StructValExprNode; struct TypeTableEntryPointer { TypeTableEntry *child_type; bool is_const; - bool is_restrict; + bool is_noalias; }; struct TypeTableEntryInt { @@ -98,8 +98,8 @@ struct TypeTableEntry { } data; // use these fields to make sure we don't duplicate type table entries for the same type - TypeTableEntry *pointer_parent[2][2]; // 0 - const. 1 - restrict - TypeTableEntry *unknown_size_array_parent[2][2]; // 0 - const. 1 - restrict + TypeTableEntry *pointer_parent[2][2]; // 0 - const. 1 - noalias + TypeTableEntry *unknown_size_array_parent[2][2]; // 0 - const. 1 - noalias HashMap arrays_by_size; TypeTableEntry *maybe_parent; @@ -391,7 +391,7 @@ void semantic_analyze(CodeGen *g); void add_node_error(CodeGen *g, AstNode *node, Buf *msg); void alloc_codegen_node(AstNode *node); TypeTableEntry *new_type_table_entry(TypeTableEntryId id); -TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_restrict); +TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_noalias); VariableTableEntry *find_variable(BlockContext *context, Buf *name); BlockContext *new_block_context(AstNode *node, BlockContext *parent); diff --git a/src/codegen.cpp b/src/codegen.cpp index b23757bee3..6c7aaca341 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1840,7 +1840,7 @@ static void do_code_gen(CodeGen *g) { TypeTableEntry *param_type = fn_proto_type_from_type_node(g, type_node); LLVMValueRef argument_val = LLVMGetParam(fn, gen_param_index); if (param_type->id == TypeTableEntryIdPointer && - param_type->data.pointer.is_restrict) + param_type->data.pointer.is_noalias) { LLVMAddAttribute(argument_val, LLVMNoAliasAttribute); } else if (param_type->id == TypeTableEntryIdPointer && diff --git a/src/parser.cpp b/src/parser.cpp index 828a2f6406..567d5a9c0c 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -225,8 +225,8 @@ void ast_print(AstNode *node, int indent) { case AstNodeTypeTypePointer: { const char *const_or_mut_str = node->data.type.is_const ? "const " : ""; - const char *restrict_or_not_str = node->data.type.is_restrict ? "restrict " : ""; - fprintf(stderr, "%s%s PointerType\n", const_or_mut_str, restrict_or_not_str); + const char *noalias_or_not_str = node->data.type.is_noalias ? "noalias " : ""; + fprintf(stderr, "%s%s PointerType\n", const_or_mut_str, noalias_or_not_str); ast_print(node->data.type.child_type, indent + 2); break; @@ -234,8 +234,8 @@ void ast_print(AstNode *node, int indent) { case AstNodeTypeTypeArray: { const char *const_or_mut_str = node->data.type.is_const ? "const " : ""; - const char *restrict_or_not_str = node->data.type.is_restrict ? "restrict " : ""; - fprintf(stderr, "%s%s ArrayType\n", const_or_mut_str, restrict_or_not_str); + const char *noalias_or_not_str = node->data.type.is_noalias ? "noalias " : ""; + fprintf(stderr, "%s%s ArrayType\n", const_or_mut_str, noalias_or_not_str); if (node->data.type.array_size) ast_print(node->data.type.array_size, indent + 2); ast_print(node->data.type.child_type, indent + 2); @@ -1024,12 +1024,12 @@ static void ast_parse_type_assume_amp(ParseContext *pc, int *token_index, AstNod node->data.type.is_const = true; *token_index += 1; first_type_token = &pc->tokens->at(*token_index); - if (first_type_token->id == TokenIdKeywordRestrict) { - node->data.type.is_restrict = true; + if (first_type_token->id == TokenIdKeywordNoAlias) { + node->data.type.is_noalias = true; *token_index += 1; } - } else if (first_type_token->id == TokenIdKeywordRestrict) { - node->data.type.is_restrict = true; + } else if (first_type_token->id == TokenIdKeywordNoAlias) { + node->data.type.is_noalias = true; *token_index += 1; } @@ -1088,8 +1088,8 @@ static AstNode *ast_parse_compiler_fn_call(ParseContext *pc, int *token_index, b /* Type : token(Symbol) | token(Unreachable) | token(Void) | PointerType | ArrayType | MaybeType | CompilerFnExpr -PointerType : token(Ampersand) option(token(Const)) option(token(Restrict)) Type -ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(Restrict)) Type +PointerType : token(Ampersand) option(token(Const)) option(token(NoAlias)) Type +ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(NoAlias)) Type */ static AstNode *ast_parse_type(ParseContext *pc, int *token_index) { Token *token = &pc->tokens->at(*token_index); @@ -1140,13 +1140,13 @@ static AstNode *ast_parse_type(ParseContext *pc, int *token_index) { node->data.type.is_const = true; Token *next_tok = &pc->tokens->at(*token_index); - if (next_tok->id == TokenIdKeywordRestrict) { + if (next_tok->id == TokenIdKeywordNoAlias) { *token_index += 1; - node->data.type.is_restrict = true; + node->data.type.is_noalias = true; } - } else if (const_tok->id == TokenIdKeywordRestrict) { + } else if (const_tok->id == TokenIdKeywordNoAlias) { *token_index += 1; - node->data.type.is_restrict = true; + node->data.type.is_noalias = true; } node->data.type.child_type = ast_parse_type(pc, token_index); diff --git a/src/parser.hpp b/src/parser.hpp index 4f7bed03b5..46ef69db02 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -110,7 +110,7 @@ struct AstNodeType { AstNode *child_type; AstNode *array_size; // can be null bool is_const; - bool is_restrict; + bool is_noalias; AstNode *compiler_expr; }; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 6abaa8448a..a9b09df46a 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -243,8 +243,8 @@ static void end_token(Tokenize *t) { t->cur_tok->id = TokenIdKeywordBreak; } else if (mem_eql_str(token_mem, token_len, "null")) { t->cur_tok->id = TokenIdKeywordNull; - } else if (mem_eql_str(token_mem, token_len, "restrict")) { - t->cur_tok->id = TokenIdKeywordRestrict; + } else if (mem_eql_str(token_mem, token_len, "noalias")) { + t->cur_tok->id = TokenIdKeywordNoAlias; } t->cur_tok = nullptr; @@ -1025,7 +1025,7 @@ static const char * token_name(Token *token) { case TokenIdKeywordContinue: return "Continue"; case TokenIdKeywordBreak: return "Break"; case TokenIdKeywordNull: return "Null"; - case TokenIdKeywordRestrict: return "Restrict"; + case TokenIdKeywordNoAlias: return "NoAlias"; case TokenIdLParen: return "LParen"; case TokenIdRParen: return "RParen"; case TokenIdComma: return "Comma"; diff --git a/src/tokenizer.hpp b/src/tokenizer.hpp index dc1da63a7b..a7b7a77138 100644 --- a/src/tokenizer.hpp +++ b/src/tokenizer.hpp @@ -36,7 +36,7 @@ enum TokenId { TokenIdKeywordContinue, TokenIdKeywordBreak, TokenIdKeywordNull, - TokenIdKeywordRestrict, + TokenIdKeywordNoAlias, TokenIdLParen, TokenIdRParen, TokenIdComma, diff --git a/std/builtin.zig b/std/builtin.zig index b57c440c07..eaaee2d6fa 100644 --- a/std/builtin.zig +++ b/std/builtin.zig @@ -10,7 +10,7 @@ export fn memset(dest: &u8, c: u8, n: usize) -> &u8 { return dest; } -export fn memcpy(dest: &restrict u8, src: &const restrict u8, n: usize) -> &u8 { +export fn memcpy(dest: &noalias u8, src: &const noalias u8, n: usize) -> &u8 { var index : #typeof(n) = 0; while (index != n) { dest[index] = src[index];