From aaf3ca335d3362e1c28a81d67063d4d84a73154c Mon Sep 17 00:00:00 2001 From: Aleksandr Kirsanov Date: Fri, 10 May 2024 15:56:11 +0300 Subject: [PATCH] [FunC] Deprecate pragma allow-post-modification All tests pass: it does not affect hashes (since modifying variables in a single expression was an error) --- .../tests/allow_post_modification.fc | 2 -- crypto/func/func.cpp | 2 +- crypto/func/func.h | 2 +- crypto/func/gen-abscode.cpp | 27 +++++++------------ crypto/func/parse-func.cpp | 6 ----- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/crypto/func/auto-tests/tests/allow_post_modification.fc b/crypto/func/auto-tests/tests/allow_post_modification.fc index 36a31031..02bfc7ae 100644 --- a/crypto/func/auto-tests/tests/allow_post_modification.fc +++ b/crypto/func/auto-tests/tests/allow_post_modification.fc @@ -1,5 +1,3 @@ -#pragma allow-post-modification; - forall X -> tuple unsafe_tuple(X x) asm "NOP"; (int, int) inc(int x, int y) { diff --git a/crypto/func/func.cpp b/crypto/func/func.cpp index 7847184f..e3e871b4 100644 --- a/crypto/func/func.cpp +++ b/crypto/func/func.cpp @@ -347,6 +347,7 @@ int func_proceed(const std::vector &sources, std::ostream &outs, st funC::define_keywords(); funC::define_builtins(); + pragma_allow_post_modification.always_on_and_deprecated("0.5.0"); int ok = 0, proc = 0; try { @@ -365,7 +366,6 @@ int func_proceed(const std::vector &sources, std::ostream &outs, st if (!proc) { throw src::Fatal{"no source files, no output"}; } - pragma_allow_post_modification.check_enable_in_libs(); pragma_compute_asm_ltr.check_enable_in_libs(); pragma_remove_unused_functions.check_enable_in_libs(); return funC::generate_output(outs, errs); diff --git a/crypto/func/func.h b/crypto/func/func.h index 14064189..d0fddef6 100644 --- a/crypto/func/func.h +++ b/crypto/func/func.h @@ -686,7 +686,7 @@ typedef std::vector FormalArgList; struct AsmOpList; struct CodeBlob { - enum { _AllowPostModification = 1, _ComputeAsmLtr = 2, _ForbidImpure = 4 }; + enum { _ComputeAsmLtr = 2, _ForbidImpure = 4 }; int var_cnt, in_var_cnt, op_cnt; TypeExpr* ret_type; std::string name; diff --git a/crypto/func/gen-abscode.cpp b/crypto/func/gen-abscode.cpp index 5e8a8761..52ba33cd 100644 --- a/crypto/func/gen-abscode.cpp +++ b/crypto/func/gen-abscode.cpp @@ -286,24 +286,17 @@ std::vector pre_compile_tensor(const std::vector args, CodeBl res_lists[i] = args[i]->pre_compile(code, lval_globs); for (size_t j = 0; j < res_lists[i].size(); ++j) { TmpVar& var = code.vars.at(res_lists[i][j]); - if (code.flags & CodeBlob::_AllowPostModification) { - if (!lval_globs && (var.cls & TmpVar::_Named)) { - Op *op = &code.emplace_back(nullptr, Op::_Let, std::vector(), std::vector()); - op->set_disabled(); - var.on_modification.push_back([modified_vars, i, j, op, done = false](const SrcLocation &here) mutable { - if (!done) { - done = true; - modified_vars->push_back({i, j, op}); - } - }); - } else { - var.on_modification.push_back([](const SrcLocation &) { - }); - } + if (!lval_globs && (var.cls & TmpVar::_Named)) { + Op *op = &code.emplace_back(nullptr, Op::_Let, std::vector(), std::vector()); + op->set_disabled(); + var.on_modification.push_back([modified_vars, i, j, op, done = false](const SrcLocation &here) mutable { + if (!done) { + done = true; + modified_vars->push_back({i, j, op}); + } + }); } else { - var.on_modification.push_back([name = var.to_string()](const SrcLocation &here) { - throw src::ParseError{here, PSTRING() << "Modifying local variable " << name - << " after using it in the same expression"}; + var.on_modification.push_back([](const SrcLocation &) { }); } } diff --git a/crypto/func/parse-func.cpp b/crypto/func/parse-func.cpp index b06933db..6573df70 100644 --- a/crypto/func/parse-func.cpp +++ b/crypto/func/parse-func.cpp @@ -266,9 +266,6 @@ void parse_const_decl(Lexer& lex) { } lex.next(); CodeBlob code; - if (pragma_allow_post_modification.enabled()) { - code.flags |= CodeBlob::_AllowPostModification; - } if (pragma_compute_asm_ltr.enabled()) { code.flags |= CodeBlob::_ComputeAsmLtr; } @@ -1219,9 +1216,6 @@ blk_fl::val parse_stmt(Lexer& lex, CodeBlob& code) { CodeBlob* parse_func_body(Lexer& lex, FormalArgList arg_list, TypeExpr* ret_type, bool marked_as_pure) { lex.expect('{'); CodeBlob* blob = new CodeBlob{ret_type}; - if (pragma_allow_post_modification.enabled()) { - blob->flags |= CodeBlob::_AllowPostModification; - } if (pragma_compute_asm_ltr.enabled()) { blob->flags |= CodeBlob::_ComputeAsmLtr; }