Skip to content

Commit

Permalink
symbol concatenation with binary + (#2431)
Browse files Browse the repository at this point in the history
* dos2unix populate-deps.yml

* Introduce binary `+` symbol concatenation
  • Loading branch information
quentin committed Oct 11, 2023
1 parent 5449a78 commit da9e3c2
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 42 deletions.
80 changes: 40 additions & 40 deletions .github/workflows/populate-deps.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
name: Populate dependencies

on:
push:
branches: [ master ]
workflow_dispatch:

permissions:
contents: write

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VCPKG_FEATURE_FLAGS: dependencygraph

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Checkout vcpkg
run: |
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
git checkout 56954f1db97f38635782d5ad7cdfd45d2731c854
- name: Bootstrap vcpkg
working-directory: vcpkg
run: ./bootstrap-vcpkg.sh

# This will execute a dry-run, meaning that libraries will not be built and
# installed, but they will still be reported to the GitHub dependency graph.
# This step assumes `vcpkg` has been bootstrapped (run `./vcpkg/bootstrap-vcpkg`)
- name: Run vcpkg
run: ${{ github.workspace }}/vcpkg/vcpkg install --dry-run --debug

name: Populate dependencies

on:
push:
branches: [ master ]
workflow_dispatch:

permissions:
contents: write

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VCPKG_FEATURE_FLAGS: dependencygraph

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Checkout vcpkg
run: |
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
git checkout 56954f1db97f38635782d5ad7cdfd45d2731c854
- name: Bootstrap vcpkg
working-directory: vcpkg
run: ./bootstrap-vcpkg.sh

# This will execute a dry-run, meaning that libraries will not be built and
# installed, but they will still be reported to the GitHub dependency graph.
# This step assumes `vcpkg` has been bootstrapped (run `./vcpkg/bootstrap-vcpkg`)
- name: Run vcpkg
run: ${{ github.workspace }}/vcpkg/vcpkg install --dry-run --debug

4 changes: 4 additions & 0 deletions src/FunctorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ char const* functorOpNameLegacy(FunctorOp op) {
/** Binary Functor Operators */
case FunctorOp::ADD:
case FunctorOp::FADD:
case FunctorOp::SSADD:
case FunctorOp::UADD: return "+";
case FunctorOp::SUB:
case FunctorOp::USUB:
Expand Down Expand Up @@ -223,6 +224,9 @@ const std::vector<IntrinsicFunctorInfo> FUNCTOR_INTRINSICS = {
VARIADIC(CAT, Symbol),
OP_1(STRLEN, Symbol, Signed),
OP_3(SUBSTR, Symbol, Signed, Signed, Symbol, false),

{functorOpNameSymbol(FOp::SSADD), {TAttr::Symbol, TAttr::Symbol}, TAttr::Symbol, FOp::SSADD, false,
false},
};

template <typename F>
Expand Down
1 change: 1 addition & 0 deletions src/FunctorOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ enum class FunctorOp {
FMIN, // min of two floats
SMAX, // max of two symbols
SMIN, // min of two symbols
SSADD, // string-string concatenation

// Produces values within a numeric range. Format is `range(bgn, endExcl, step = 1)`.
// e.g. `range(0, 5)` produces the sequence `0, 1, 2, 3, 4`.
Expand Down
8 changes: 8 additions & 0 deletions src/interpreter/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,14 @@ RamDomain Engine::execute(const Node* node, Context& ctxt) {
case FunctorOp::URANGE:
case FunctorOp::FRANGE:
fatal("ICE: functor `%s` must map onto `NestedIntrinsicOperator`", cur.getOperator());

case FunctorOp::SSADD: {
auto sleft = execute(shadow.getChild(0), ctxt);
auto sright = execute(shadow.getChild(1), ctxt);
const std::string& strleft = getSymbolTable().decode(sleft);
const std::string& strright = getSymbolTable().decode(sright);
return getSymbolTable().encode(strleft + strright);
}
}

{UNREACHABLE_BAD_CASE_ANALYSIS}
Expand Down
33 changes: 31 additions & 2 deletions src/synthesiser/Synthesiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ void Synthesiser::emitCode(std::ostream& out, const Statement& stmt) {

// strings
case BinaryConstraintOp::MATCH: {
if (const StringConstant* str = dynamic_cast<const StringConstant*>(&rel.getLHS()); str) {
if (const StringConstant* str = as<StringConstant>(&rel.getLHS()); str) {
const auto& regex = synthesiser.compileRegex(str->getConstant());
if (regex) {
out << "std::regex_match(symTable.decode(";
Expand All @@ -1884,7 +1884,7 @@ void Synthesiser::emitCode(std::ostream& out, const Statement& stmt) {
break;
}
case BinaryConstraintOp::NOT_MATCH: {
if (const StringConstant* str = dynamic_cast<const StringConstant*>(&rel.getLHS()); str) {
if (const StringConstant* str = as<StringConstant>(&rel.getLHS()); str) {
const auto& regex = synthesiser.compileRegex(str->getConstant());
if (regex) {
out << "!std::regex_match(symTable.decode(";
Expand Down Expand Up @@ -2313,6 +2313,35 @@ void Synthesiser::emitCode(std::ostream& out, const Statement& stmt) {
case FunctorOp::URANGE:
case FunctorOp::FRANGE:
fatal("ICE: functor `%s` must map onto `NestedIntrinsicOperator`", op.getOperator());

case FunctorOp::SSADD: {
const StringConstant* lstr = as<StringConstant>(args[0]);
const StringConstant* rstr = as<StringConstant>(args[1]);
if (lstr && rstr) {
out << "RamSigned("
<< synthesiser.convertSymbol2Idx(lstr->getConstant() + rstr->getConstant())
<< ")";
} else {
out << "symTable.encode(";
if (lstr) {
out << "R\"_(" << lstr->getConstant() << ")_\"";
} else {
out << "symTable.decode(";
dispatch(*args[0], out);
out << ")";
}
out << " + ";
if (rstr) {
out << "R\"_(" << rstr->getConstant() << ")_\"";
} else {
out << "symTable.decode(";
dispatch(*args[1], out);
out << ")";
}
out << ")";
}
break;
}
}
PRINT_END_COMMENT(out);

Expand Down
1 change: 1 addition & 0 deletions tests/evaluation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ positive_test(subtype2)
positive_test(subtype)
positive_test(sum-aggregate)
positive_test(sum-aggregate2)
positive_test(symbol_operations)
positive_test(term)
positive_test(unpacking)
positive_test(unsigned_operations)
Expand Down
9 changes: 9 additions & 0 deletions tests/evaluation/symbol_operations/Add.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pre--post
pre-(a)
pre-(b)
(a)-post
(b)-post
(b)(a)(a)
(a)(b)(b)
one:1, pi:3.140000

23 changes: 23 additions & 0 deletions tests/evaluation/symbol_operations/symbol_operations.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Souffle - A Datalog Compiler
// Copyright (c) 2023, The Souffle Developers. All rights reserved
// Licensed under the Universal Permissive License v 1.0 as shown at:
// - https://opensource.org/licenses/UPL
// - <souffle root>/licenses/SOUFFLE-UPL.txt

.decl Add(s:symbol)
Add("pre-" + "-post").
Add("pre-" + s) :- some_symbol(s).
Add(s + "-post") :- some_symbol(s).
Add(s1 + s2 + s3) :-
some_symbol(s1),
some_symbol(s2),
some_symbol(s3),
s1 != s2,
s1 != s3.
Add("one:" + to_string(1) + ", pi:" + to_string(3.14) + "\n").

.decl some_symbol(s:symbol)
some_symbol("(a)").
some_symbol("(b)").

.output Add()
Empty file.
Empty file.

0 comments on commit da9e3c2

Please sign in to comment.