|
| 1 | +/* |
| 2 | + * Souffle - A Datalog Compiler |
| 3 | + * Copyright (c) 2026 The Souffle Developers. All rights reserved |
| 4 | + * Licensed under the Universal Permissive License v 1.0 as shown at: |
| 5 | + * - https://opensource.org/licenses/UPL |
| 6 | + * - <souffle root>/licenses/SOUFFLE-UPL.txt |
| 7 | + */ |
| 8 | + |
| 9 | +/************************************************************************ |
| 10 | + * |
| 11 | + * @file sips_metric_test.cpp |
| 12 | + * |
| 13 | + * Tests souffle's SIPS cost metrics. |
| 14 | + * |
| 15 | + ***********************************************************************/ |
| 16 | + |
| 17 | +#include "tests/test.h" |
| 18 | + |
| 19 | +#include "Global.h" |
| 20 | +#include "ast/Program.h" |
| 21 | +#include "ast/QualifiedName.h" |
| 22 | +#include "ast/TranslationUnit.h" |
| 23 | +#include "ast2ram/utility/SipsMetric.h" |
| 24 | +#include "parser/ParserDriver.h" |
| 25 | +#include "reports/DebugReport.h" |
| 26 | +#include "reports/ErrorReport.h" |
| 27 | +#include <string> |
| 28 | +#include <vector> |
| 29 | + |
| 30 | +namespace souffle::ast { |
| 31 | + |
| 32 | +namespace test { |
| 33 | + |
| 34 | +TEST(SipsMetric, LeastFreeVarsCountsUnboundVariables) { |
| 35 | + Global glb; |
| 36 | + ErrorReport e; |
| 37 | + DebugReport d(glb); |
| 38 | + |
| 39 | + Own<TranslationUnit> tu = ParserDriver::parseTranslationUnit(glb, |
| 40 | + R"( |
| 41 | + .decl seed(x:number) |
| 42 | + .decl low(z:number, w:number) |
| 43 | + .decl high(x:number, y:number) |
| 44 | + .decl result(y:number, z:number, w:number) |
| 45 | +
|
| 46 | + result(y, z, w) :- seed(x), low(z, w), high(x, y). |
| 47 | + )", |
| 48 | + e, d); |
| 49 | + |
| 50 | + auto* clause = tu->getProgram().getClauses(QualifiedName::fromString("result"))[0]; |
| 51 | + LeastFreeVarsSips sips(*tu); |
| 52 | + |
| 53 | + EXPECT_EQ(std::vector<std::size_t>({0, 2, 1}), sips.getReordering(clause, {"seed", "low", "high"})); |
| 54 | +} |
| 55 | + |
| 56 | +} // namespace test |
| 57 | +} // namespace souffle::ast |
0 commit comments