From 8ae5e115a4693ff33248278f5702614ff6f3abee Mon Sep 17 00:00:00 2001 From: Valentin David Date: Thu, 28 May 2020 15:34:15 +0200 Subject: Optimize variable flattening Verifying for variables (all used variables defined and no cycle) is much faster than flattening them. It also uses much less memory. Only `bst show -f "%{vars}"` requires to flatten all variables. For other cases we can improve performance by only checking rather than flattening. Also flattening very nested variables could lead to very long lists of empty strings. The memory usage for flattening could be a lot bigger than the resulting value. Force flattening and caching every variable definitions can improve intermediate memory consumption and only consume memory of the size of the result. Finally, an optimization allowed inifinite cycles leading to segmentation fault. This was solved by simplifying the code. --- tests/format/variables.py | 9 +++++++++ tests/format/variables/cyclic_variables/simple-cyclic.bst | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 tests/format/variables/cyclic_variables/simple-cyclic.bst (limited to 'tests') diff --git a/tests/format/variables.py b/tests/format/variables.py index 616dc20c1..c5e8eebad 100644 --- a/tests/format/variables.py +++ b/tests/format/variables.py @@ -61,6 +61,15 @@ def test_missing_variable(cli, datafiles, element): result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.UNRESOLVED_VARIABLE) +@pytest.mark.timeout(15, method="signal") +@pytest.mark.datafiles(os.path.join(DATA_DIR, "cyclic_variables")) +def test_simple_cyclic_variables(cli, datafiles): + print_warning("Performing cyclic test, if this test times out it will " + "exit the test sequence") + project = str(datafiles) + result = cli.run(project=project, silent=True, args=["build", "simple-cyclic.bst"]) + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.RECURSIVE_VARIABLE) + + @pytest.mark.timeout(15, method="signal") @pytest.mark.datafiles(os.path.join(DATA_DIR, "cyclic_variables")) def test_cyclic_variables(cli, datafiles): diff --git a/tests/format/variables/cyclic_variables/simple-cyclic.bst b/tests/format/variables/cyclic_variables/simple-cyclic.bst new file mode 100644 index 000000000..806e1f390 --- /dev/null +++ b/tests/format/variables/cyclic_variables/simple-cyclic.bst @@ -0,0 +1,5 @@ +kind: manual + +variables: + a: "%{b}" + b: "%{a}" -- cgit v1.2.1