From 946a1418fec1801479ea60d5aa11ffe5fdae4973 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 5 Dec 2020 21:52:50 +0200 Subject: [PATCH] Revert "autofree: handle tmp vars in for loops" This reverts commit 1d6c604664cd85bd9b9cfcc1ad704fd53dce7908. --- vlib/v/ast/ast.v | 3 +-- vlib/v/gen/cgen.v | 7 +------ vlib/v/parser/for.v | 3 --- vlib/v/tests/valgrind/1.strings_and_arrays.v | 5 ----- 4 files changed, 2 insertions(+), 16 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index a73584429c..f3f81f25ea 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -369,9 +369,8 @@ pub mut: pos token.Position is_used bool is_changed bool // to detect mutable vars that are never changed - // (for setting the position after the or block for autofree) is_or bool // `x := foo() or { ... }` - is_tmp bool // for tmp for loop vars, so that autofree can skip them + // (for setting the position after the or block for autofree) } // used for smartcasting only diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index c40b5523de..c872b82e26 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2100,14 +2100,9 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int continue } if obj.is_or { + g.writeln('// skipping `or{}` var "$obj.name"') // Skip vars inited with the `or {}`, since they are generated // after the or block in C. - g.writeln('// skipping `or{}` var "$obj.name"') - continue - } - if obj.is_tmp { - // Skip for loop vars - g.writeln('// skipping tmp var "$obj.name"') continue } // if var.typ == 0 { diff --git a/vlib/v/parser/for.v b/vlib/v/parser/for.v index c441ce80f8..6b70ac40e6 100644 --- a/vlib/v/parser/for.v +++ b/vlib/v/parser/for.v @@ -105,7 +105,6 @@ fn (mut p Parser) for_stmt() ast.Stmt { name: key_var_name typ: table.int_type pos: key_var_pos - is_tmp: true }) } else if p.scope.known_var(val_var_name) { p.error('redefinition of value iteration variable `$val_var_name`') @@ -131,7 +130,6 @@ fn (mut p Parser) for_stmt() ast.Stmt { name: val_var_name typ: table.int_type pos: val_var_pos - is_tmp: true }) if key_var_name.len > 0 { p.error_with_pos('cannot declare index variable with range `for`', key_var_pos) @@ -143,7 +141,6 @@ fn (mut p Parser) for_stmt() ast.Stmt { name: val_var_name pos: val_var_pos is_mut: val_is_mut - is_tmp: true }) } p.inside_for = false diff --git a/vlib/v/tests/valgrind/1.strings_and_arrays.v b/vlib/v/tests/valgrind/1.strings_and_arrays.v index f8b17e01f8..32f83224b7 100644 --- a/vlib/v/tests/valgrind/1.strings_and_arrays.v +++ b/vlib/v/tests/valgrind/1.strings_and_arrays.v @@ -291,11 +291,6 @@ fn free_before_break() { continue } } - x := ['1', '2', '3'] - for n in x { - f := 'f' - println('$n => $f') - } } struct User {