Deprecate inline for in favour of #unroll for

This commit is contained in:
gingerBill
2021-02-23 14:45:15 +00:00
parent 657c0ac4f5
commit a1693c0184
7 changed files with 27 additions and 47 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ default_hash_ptr :: inline proc "contextless" (data: rawptr, size: int) -> uintp
_default_hasher_const :: inline proc "contextless" (data: rawptr, seed: uintptr, $N: uint) -> uintptr where N <= 16 {
h := u64(seed) + 0xcbf29ce484222325;
p := uintptr(data);
inline for _ in 0..<N {
#unroll for _ in 0..<N {
b := u64((^byte)(p)^);
h = (h ~ b) * 0x100000001b3;
p += 1;
+8 -8
View File
@@ -1491,25 +1491,25 @@ quaternions :: proc() {
}
}
inline_for_statement :: proc() {
fmt.println("\n#inline for statements");
unroll_for_statement :: proc() {
fmt.println("\n#'#unroll for' statements");
// 'inline for' works the same as if the 'inline' prefix did not
// '#unroll for' works the same as if the 'inline' prefix did not
// exist but these ranged loops are explicitly unrolled which can
// be very very useful for certain optimizations
fmt.println("Ranges");
inline for x, i in 1..<4 {
#unroll for x, i in 1..<4 {
fmt.println(x, i);
}
fmt.println("Strings");
inline for r, i in "Hello, 世界" {
#unroll for r, i in "Hello, 世界" {
fmt.println(r, i);
}
fmt.println("Arrays");
inline for elem, idx in ([4]int{1, 4, 9, 16}) {
#unroll for elem, idx in ([4]int{1, 4, 9, 16}) {
fmt.println(elem, idx);
}
@@ -1521,7 +1521,7 @@ inline_for_statement :: proc() {
D,
};
fmt.println("Enum types");
inline for elem, idx in Foo_Enum {
#unroll for elem, idx in Foo_Enum {
fmt.println(elem, idx);
}
}
@@ -1991,7 +1991,7 @@ main :: proc() {
deferred_procedure_associations();
reflection();
quaternions();
inline_for_statement();
unroll_for_statement();
where_clauses();
foreign_system();
ranged_fields_for_array_compound_literals();
+8 -8
View File
@@ -1491,25 +1491,25 @@ quaternions :: proc() {
}
}
inline_for_statement :: proc() {
fmt.println("\n#inline for statements")
unroll_for_statement :: proc() {
fmt.println("\n#'#unroll for' statements")
// 'inline for' works the same as if the 'inline' prefix did not
// '#unroll for' works the same as if the 'inline' prefix did not
// exist but these ranged loops are explicitly unrolled which can
// be very very useful for certain optimizations
fmt.println("Ranges")
inline for x, i in 1..<4 {
#unroll for x, i in 1..<4 {
fmt.println(x, i)
}
fmt.println("Strings")
inline for r, i in "Hello, 世界" {
#unroll for r, i in "Hello, 世界" {
fmt.println(r, i)
}
fmt.println("Arrays")
inline for elem, idx in ([4]int{1, 4, 9, 16}) {
#unroll for elem, idx in ([4]int{1, 4, 9, 16}) {
fmt.println(elem, idx)
}
@@ -1521,7 +1521,7 @@ inline_for_statement :: proc() {
D,
}
fmt.println("Enum types")
inline for elem, idx in Foo_Enum {
#unroll for elem, idx in Foo_Enum {
fmt.println(elem, idx)
}
}
@@ -1991,7 +1991,7 @@ main :: proc() {
deferred_procedure_associations()
reflection()
quaternions()
inline_for_statement()
unroll_for_statement()
where_clauses()
foreign_system()
ranged_fields_for_array_compound_literals()
+5 -5
View File
@@ -731,11 +731,11 @@ void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
if (val0 == nullptr) {
gbString s = expr_to_string(operand.expr);
gbString t = type_to_string(operand.type);
error(operand.expr, "Cannot iterate over '%s' of type '%s' in an 'inline for' statement", s, t);
error(operand.expr, "Cannot iterate over '%s' of type '%s' in an '#unroll for' statement", s, t);
gb_string_free(t);
gb_string_free(s);
} else if (operand.mode != Addressing_Constant) {
error(operand.expr, "An 'inline for' expression must be known at compile time");
error(operand.expr, "An '#unroll for' expression must be known at compile time");
}
}
@@ -793,7 +793,7 @@ void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
}
// NOTE(bill): Minimize the amount of nesting of an 'inline for'
// NOTE(bill): Minimize the amount of nesting of an '#unroll for'
i64 prev_inline_for_depth = ctx->inline_for_depth;
defer (ctx->inline_for_depth = prev_inline_for_depth);
{
@@ -806,9 +806,9 @@ void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
if (ctx->inline_for_depth >= MAX_INLINE_FOR_DEPTH && prev_inline_for_depth < MAX_INLINE_FOR_DEPTH) {
if (prev_inline_for_depth > 0) {
error(node, "Nested 'inline for' loop cannot be inlined as it exceeds the maximum inline for depth (%lld levels >= %lld maximum levels)", v, MAX_INLINE_FOR_DEPTH);
error(node, "Nested '#unroll for' loop cannot be inlined as it exceeds the maximum '#unroll for' depth (%lld levels >= %lld maximum levels)", v, MAX_INLINE_FOR_DEPTH);
} else {
error(node, "'inline for' loop cannot be inlined as it exceeds the maximum inline for depth (%lld levels >= %lld maximum levels)", v, MAX_INLINE_FOR_DEPTH);
error(node, "'#unroll for' loop cannot be inlined as it exceeds the maximum '#unroll for' depth (%lld levels >= %lld maximum levels)", v, MAX_INLINE_FOR_DEPTH);
}
error_line("\tUse a normal 'for' loop instead by removing the 'inline' prefix\n");
ctx->inline_for_depth = MAX_INLINE_FOR_DEPTH;
+1 -1
View File
@@ -11021,7 +11021,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
}
break;
default:
GB_PANIC("Invalid inline for type");
GB_PANIC("Invalid '#unroll for' type");
break;
}
}
+1 -1
View File
@@ -3764,7 +3764,7 @@ void lb_build_inline_range_stmt(lbProcedure *p, AstInlineRangeStmt *rs) {
}
break;
default:
GB_PANIC("Invalid inline for type");
GB_PANIC("Invalid '#unroll for' type");
break;
}
}
+3 -23
View File
@@ -2066,29 +2066,6 @@ Ast *parse_operand(AstFile *f, bool lhs) {
syntax_error(token, "Expected a least 1 argument in a procedure group");
}
return ast_proc_group(f, token, open, close, args);
} else if (f->curr_token.kind == Token_OpenBracket) { // ProcGroup
Token open = expect_token(f, Token_OpenBracket);
warning(open, "Procedure groups using [] are now deprecated, please use {} instead");
auto args = array_make<Ast *>(heap_allocator());
while (f->curr_token.kind != Token_CloseBracket &&
f->curr_token.kind != Token_EOF) {
Ast *elem = parse_expr(f, false);
array_add(&args, elem);
if (!allow_token(f, Token_Comma)) {
break;
}
}
Token close = expect_token(f, Token_CloseBracket);
if (args.count == 0) {
syntax_error(token, "Expected a least 1 argument in a procedure group");
}
return ast_proc_group(f, token, open, close, args);
}
@@ -4297,6 +4274,9 @@ Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind clo
Ast *parse_unrolled_for_loop(AstFile *f, Token inline_token) {
if (inline_token.kind == Token_inline) {
syntax_warning(inline_token, "'inline for' is deprecated in favour of `#unroll for'");
}
Token for_token = expect_token(f, Token_for);
Ast *val0 = nullptr;
Ast *val1 = nullptr;