authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-08 23:48:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-08 23:48:24-07:00
log0c24ed8a818dddc1c77a41c07815b036a94279ca
tree7df54df324e797d2fd06cf12dc7d377a528cec41
parentb7dd88ad68aab5b6bc8321431d1a53b343b2dd37

rename `restrict` to `noalias`


10 files changed, 48 insertions(+), 48 deletions(-)

doc/langref.md+2-2
......@@ -68,11 +68,11 @@ CompilerFnExpr : token(NumberSign) token(Symbol) token(LParen) Expression token(
6868
6969CompilerFnType : token(NumberSign) token(Symbol) token(LParen) Type token(RParen)
7070
71PointerType : token(Ampersand) option(token(Const)) option(token(Restrict)) Type
71PointerType : token(Ampersand) option(token(Const)) option(token(NoAlias)) Type
7272
7373MaybeType : token(Question) Type
7474
75ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(Restrict)) Type
75ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(NoAlias)) Type
7676
7777Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace)
7878
doc/vim/syntax/zig.vim+1-1
......@@ -8,7 +8,7 @@ if exists("b:current_syntax")
88endif
99
1010syn keyword zigOperator as
11syn keyword zigStorage const var extern volatile export pub restrict
11syn keyword zigStorage const var extern volatile export pub noalias
1212syn keyword zigStructure struct enum type
1313syn keyword zigStatement goto break return continue asm
1414syn keyword zigConditional if else match
src/analyze.cpp+20-20
......@@ -135,8 +135,8 @@ static TypeTableEntry *get_number_literal_type_unsigned(CodeGen *g, uint64_t x)
135135 return g->num_lit_types[get_number_literal_kind_unsigned(x)];
136136}
137137
138TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_restrict) {
139 TypeTableEntry **parent_pointer = &child_type->pointer_parent[(is_const ? 1 : 0)][(is_restrict ? 1 : 0)];
138TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_noalias) {
139 TypeTableEntry **parent_pointer = &child_type->pointer_parent[(is_const ? 1 : 0)][(is_noalias ? 1 : 0)];
140140 if (*parent_pointer) {
141141 return *parent_pointer;
142142 } else {
......@@ -151,7 +151,7 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool
151151 entry->size_in_bits, entry->align_in_bits, buf_ptr(&entry->name));
152152 entry->data.pointer.child_type = child_type;
153153 entry->data.pointer.is_const = is_const;
154 entry->data.pointer.is_restrict = is_restrict;
154 entry->data.pointer.is_noalias = is_noalias;
155155
156156 *parent_pointer = entry;
157157 return entry;
......@@ -240,9 +240,9 @@ static TypeTableEntry *get_array_type(CodeGen *g, ImportTableEntry *import,
240240}
241241
242242static TypeTableEntry *get_unknown_size_array_type(CodeGen *g, ImportTableEntry *import,
243 TypeTableEntry *child_type, bool is_const, bool is_restrict)
243 TypeTableEntry *child_type, bool is_const, bool is_noalias)
244244{
245 TypeTableEntry **parent_pointer = &child_type->unknown_size_array_parent[(is_const ? 1 : 0)][(is_restrict ? 1 : 0)];
245 TypeTableEntry **parent_pointer = &child_type->unknown_size_array_parent[(is_const ? 1 : 0)][(is_noalias ? 1 : 0)];
246246 if (*parent_pointer) {
247247 return *parent_pointer;
248248 } else {
......@@ -252,7 +252,7 @@ static TypeTableEntry *get_unknown_size_array_type(CodeGen *g, ImportTableEntry
252252 buf_appendf(&entry->name, "[]%s", buf_ptr(&child_type->name));
253253 entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&entry->name));
254254
255 TypeTableEntry *pointer_type = get_pointer_to_type(g, child_type, is_const, is_restrict);
255 TypeTableEntry *pointer_type = get_pointer_to_type(g, child_type, is_const, is_noalias);
256256
257257 unsigned element_count = 2;
258258 LLVMTypeRef element_types[] = {
......@@ -428,7 +428,7 @@ static TypeTableEntry *eval_const_expr(CodeGen *g, BlockContext *context,
428428}
429429
430430static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry *import,
431 BlockContext *context, bool restrict_allowed)
431 BlockContext *context, bool noalias_allowed)
432432{
433433 assert(node->type == NodeTypeType);
434434 alloc_codegen_node(node);
......@@ -449,13 +449,13 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry
449449 }
450450 case AstNodeTypeTypePointer:
451451 {
452 bool use_restrict = false;
453 if (node->data.type.is_restrict) {
454 if (!restrict_allowed) {
452 bool use_noalias = false;
453 if (node->data.type.is_noalias) {
454 if (!noalias_allowed) {
455455 add_node_error(g, node,
456 buf_create_from_str("invalid restrict qualifier"));
456 buf_create_from_str("invalid noalias qualifier"));
457457 } else {
458 use_restrict = true;
458 use_noalias = true;
459459 }
460460 }
461461
......@@ -471,7 +471,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry
471471 type_node->entry = child_type;
472472 return child_type;
473473 } else {
474 type_node->entry = get_pointer_to_type(g, child_type, node->data.type.is_const, use_restrict);
474 type_node->entry = get_pointer_to_type(g, child_type, node->data.type.is_const, use_noalias);
475475 return type_node->entry;
476476 }
477477 }
......@@ -479,13 +479,13 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry
479479 {
480480 AstNode *size_node = node->data.type.array_size;
481481
482 bool use_restrict = false;
483 if (node->data.type.is_restrict) {
484 if (!restrict_allowed || size_node) {
482 bool use_noalias = false;
483 if (node->data.type.is_noalias) {
484 if (!noalias_allowed || size_node) {
485485 add_node_error(g, node,
486 buf_create_from_str("invalid restrict qualifier"));
486 buf_create_from_str("invalid noalias qualifier"));
487487 } else {
488 use_restrict = true;
488 use_noalias = true;
489489 }
490490 }
491491
......@@ -524,7 +524,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node, ImportTableEntry
524524 return type_node->entry;
525525 } else {
526526 type_node->entry = get_unknown_size_array_type(g, import, child_type,
527 node->data.type.is_const, use_restrict);
527 node->data.type.is_const, use_noalias);
528528 return type_node->entry;
529529 }
530530
......@@ -1221,7 +1221,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, BlockContext *cont
12211221 return expected_type;
12221222 }
12231223
1224 // implicit non-const to const and ignore restrict
1224 // implicit non-const to const and ignore noalias
12251225 if (expected_type->id == TypeTableEntryIdPointer &&
12261226 actual_type->id == TypeTableEntryIdPointer &&
12271227 (!actual_type->data.pointer.is_const || expected_type->data.pointer.is_const))
src/analyze.hpp+4-4
......@@ -23,7 +23,7 @@ struct StructValExprNode;
2323struct TypeTableEntryPointer {
2424 TypeTableEntry *child_type;
2525 bool is_const;
26 bool is_restrict;
26 bool is_noalias;
2727};
2828
2929struct TypeTableEntryInt {
......@@ -98,8 +98,8 @@ struct TypeTableEntry {
9898 } data;
9999
100100 // use these fields to make sure we don't duplicate type table entries for the same type
101 TypeTableEntry *pointer_parent[2][2]; // 0 - const. 1 - restrict
102 TypeTableEntry *unknown_size_array_parent[2][2]; // 0 - const. 1 - restrict
101 TypeTableEntry *pointer_parent[2][2]; // 0 - const. 1 - noalias
102 TypeTableEntry *unknown_size_array_parent[2][2]; // 0 - const. 1 - noalias
103103 HashMap<uint64_t, TypeTableEntry *, uint64_hash, uint64_eq> arrays_by_size;
104104 TypeTableEntry *maybe_parent;
105105
......@@ -391,7 +391,7 @@ void semantic_analyze(CodeGen *g);
391391void add_node_error(CodeGen *g, AstNode *node, Buf *msg);
392392void alloc_codegen_node(AstNode *node);
393393TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
394TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_restrict);
394TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const, bool is_noalias);
395395VariableTableEntry *find_variable(BlockContext *context, Buf *name);
396396BlockContext *new_block_context(AstNode *node, BlockContext *parent);
397397
src/codegen.cpp+1-1
......@@ -1840,7 +1840,7 @@ static void do_code_gen(CodeGen *g) {
18401840 TypeTableEntry *param_type = fn_proto_type_from_type_node(g, type_node);
18411841 LLVMValueRef argument_val = LLVMGetParam(fn, gen_param_index);
18421842 if (param_type->id == TypeTableEntryIdPointer &&
1843 param_type->data.pointer.is_restrict)
1843 param_type->data.pointer.is_noalias)
18441844 {
18451845 LLVMAddAttribute(argument_val, LLVMNoAliasAttribute);
18461846 } else if (param_type->id == TypeTableEntryIdPointer &&
src/parser.cpp+14-14
......@@ -225,8 +225,8 @@ void ast_print(AstNode *node, int indent) {
225225 case AstNodeTypeTypePointer:
226226 {
227227 const char *const_or_mut_str = node->data.type.is_const ? "const " : "";
228 const char *restrict_or_not_str = node->data.type.is_restrict ? "restrict " : "";
229 fprintf(stderr, "%s%s PointerType\n", const_or_mut_str, restrict_or_not_str);
228 const char *noalias_or_not_str = node->data.type.is_noalias ? "noalias " : "";
229 fprintf(stderr, "%s%s PointerType\n", const_or_mut_str, noalias_or_not_str);
230230
231231 ast_print(node->data.type.child_type, indent + 2);
232232 break;
......@@ -234,8 +234,8 @@ void ast_print(AstNode *node, int indent) {
234234 case AstNodeTypeTypeArray:
235235 {
236236 const char *const_or_mut_str = node->data.type.is_const ? "const " : "";
237 const char *restrict_or_not_str = node->data.type.is_restrict ? "restrict " : "";
238 fprintf(stderr, "%s%s ArrayType\n", const_or_mut_str, restrict_or_not_str);
237 const char *noalias_or_not_str = node->data.type.is_noalias ? "noalias " : "";
238 fprintf(stderr, "%s%s ArrayType\n", const_or_mut_str, noalias_or_not_str);
239239 if (node->data.type.array_size)
240240 ast_print(node->data.type.array_size, indent + 2);
241241 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
10241024 node->data.type.is_const = true;
10251025 *token_index += 1;
10261026 first_type_token = &pc->tokens->at(*token_index);
1027 if (first_type_token->id == TokenIdKeywordRestrict) {
1028 node->data.type.is_restrict = true;
1027 if (first_type_token->id == TokenIdKeywordNoAlias) {
1028 node->data.type.is_noalias = true;
10291029 *token_index += 1;
10301030 }
1031 } else if (first_type_token->id == TokenIdKeywordRestrict) {
1032 node->data.type.is_restrict = true;
1031 } else if (first_type_token->id == TokenIdKeywordNoAlias) {
1032 node->data.type.is_noalias = true;
10331033 *token_index += 1;
10341034 }
10351035
......@@ -1088,8 +1088,8 @@ static AstNode *ast_parse_compiler_fn_call(ParseContext *pc, int *token_index, b
10881088
10891089/*
10901090Type : token(Symbol) | token(Unreachable) | token(Void) | PointerType | ArrayType | MaybeType | CompilerFnExpr
1091PointerType : token(Ampersand) option(token(Const)) option(token(Restrict)) Type
1092ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(Restrict)) Type
1091PointerType : token(Ampersand) option(token(Const)) option(token(NoAlias)) Type
1092ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) option(token(NoAlias)) Type
10931093*/
10941094static AstNode *ast_parse_type(ParseContext *pc, int *token_index) {
10951095 Token *token = &pc->tokens->at(*token_index);
......@@ -1140,13 +1140,13 @@ static AstNode *ast_parse_type(ParseContext *pc, int *token_index) {
11401140 node->data.type.is_const = true;
11411141
11421142 Token *next_tok = &pc->tokens->at(*token_index);
1143 if (next_tok->id == TokenIdKeywordRestrict) {
1143 if (next_tok->id == TokenIdKeywordNoAlias) {
11441144 *token_index += 1;
1145 node->data.type.is_restrict = true;
1145 node->data.type.is_noalias = true;
11461146 }
1147 } else if (const_tok->id == TokenIdKeywordRestrict) {
1147 } else if (const_tok->id == TokenIdKeywordNoAlias) {
11481148 *token_index += 1;
1149 node->data.type.is_restrict = true;
1149 node->data.type.is_noalias = true;
11501150 }
11511151
11521152 node->data.type.child_type = ast_parse_type(pc, token_index);
src/parser.hpp+1-1
......@@ -110,7 +110,7 @@ struct AstNodeType {
110110 AstNode *child_type;
111111 AstNode *array_size; // can be null
112112 bool is_const;
113 bool is_restrict;
113 bool is_noalias;
114114 AstNode *compiler_expr;
115115};
116116
src/tokenizer.cpp+3-3
......@@ -243,8 +243,8 @@ static void end_token(Tokenize *t) {
243243 t->cur_tok->id = TokenIdKeywordBreak;
244244 } else if (mem_eql_str(token_mem, token_len, "null")) {
245245 t->cur_tok->id = TokenIdKeywordNull;
246 } else if (mem_eql_str(token_mem, token_len, "restrict")) {
247 t->cur_tok->id = TokenIdKeywordRestrict;
246 } else if (mem_eql_str(token_mem, token_len, "noalias")) {
247 t->cur_tok->id = TokenIdKeywordNoAlias;
248248 }
249249
250250 t->cur_tok = nullptr;
......@@ -1025,7 +1025,7 @@ static const char * token_name(Token *token) {
10251025 case TokenIdKeywordContinue: return "Continue";
10261026 case TokenIdKeywordBreak: return "Break";
10271027 case TokenIdKeywordNull: return "Null";
1028 case TokenIdKeywordRestrict: return "Restrict";
1028 case TokenIdKeywordNoAlias: return "NoAlias";
10291029 case TokenIdLParen: return "LParen";
10301030 case TokenIdRParen: return "RParen";
10311031 case TokenIdComma: return "Comma";
src/tokenizer.hpp+1-1
......@@ -36,7 +36,7 @@ enum TokenId {
3636 TokenIdKeywordContinue,
3737 TokenIdKeywordBreak,
3838 TokenIdKeywordNull,
39 TokenIdKeywordRestrict,
39 TokenIdKeywordNoAlias,
4040 TokenIdLParen,
4141 TokenIdRParen,
4242 TokenIdComma,
std/builtin.zig+1-1
......@@ -10,7 +10,7 @@ export fn memset(dest: &u8, c: u8, n: usize) -> &u8 {
1010 return dest;
1111}
1212
13export fn memcpy(dest: &restrict u8, src: &const restrict u8, n: usize) -> &u8 {
13export fn memcpy(dest: &noalias u8, src: &const noalias u8, n: usize) -> &u8 {
1414 var index : #typeof(n) = 0;
1515 while (index != n) {
1616 dest[index] = src[index];