-
Notifications
You must be signed in to change notification settings - Fork 225
Lattice support #2438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Lattice support #2438
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
20ec1b4
implement automatic lubs in RAM
julienhenry e894d56
support lattice definitions
julienhenry eb105c1
updated test
julienhenry 27d4454
clang-format
julienhenry 8266c49
Merge branch 'souffle-lang:master' into lattice_support
julienhenry 2bf174d
clang-format
julienhenry f1d063d
clang-format Engine.cpp
julienhenry 51bcbb5
clang-format again... Engine.cpp
julienhenry ee12706
update comment
julienhenry cdb9fda
newlines of populate-deps.yml
julienhenry 1dcf759
Merge branch 'lattice_support' of github.com:julienhenry/souffle into…
julienhenry 5816f80
bug fix
julienhenry babf511
fix
julienhenry c64d9e2
fix test
julienhenry 6d1b341
for some reason clang-format behaves differently on my machine
julienhenry 00d1d15
implement correct semantics for lattice arguments
julienhenry 3e64067
clang-format
julienhenry f9a5a62
review comments
julienhenry cbc25df
tests
julienhenry 7571422
update tests
julienhenry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * 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 | ||
| */ | ||
|
|
||
| #include "ast/Lattice.h" | ||
| #include "souffle/utility/MiscUtil.h" | ||
| #include "souffle/utility/StreamUtil.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| namespace souffle::ast { | ||
|
|
||
| std::optional<LatticeOperator> latticeOperatorFromString(const std::string& str) { | ||
| if (str == "Bottom") return Bottom; | ||
| if (str == "Top") return Top; | ||
| if (str == "Lub") return Lub; | ||
| if (str == "Glb") return Glb; | ||
| if (str == "Leq") return Leq; | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::string latticeOperatorToString(const LatticeOperator op) { | ||
| switch (op) { | ||
| case Bottom: return "Bottom"; | ||
| case Top: return "Top"; | ||
| case Lub: return "Lub"; | ||
| case Glb: return "Glb"; | ||
| case Leq: return "Leq"; | ||
| default: assert(false && "unknown lattice operator"); | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| Lattice::Lattice(QualifiedName name, std::map<LatticeOperator, Own<ast::Argument>> ops, SrcLocation loc) | ||
| : Node(std::move(loc)), name(std::move(name)), operators(std::move(ops)) {} | ||
|
|
||
| void Lattice::setQualifiedName(QualifiedName name) { | ||
| this->name = std::move(name); | ||
| } | ||
|
|
||
| const std::map<LatticeOperator, const ast::Argument*> Lattice::getOperators() const { | ||
| std::map<LatticeOperator, const ast::Argument*> ops; | ||
| for (const auto& [op, arg] : operators) { | ||
| ops.emplace(std::make_pair(op, arg.get())); | ||
| } | ||
| return ops; | ||
| } | ||
|
|
||
| bool Lattice::hasGlb() const { | ||
| return operators.count(Glb) > 0; | ||
| } | ||
|
|
||
| bool Lattice::hasLub() const { | ||
| return operators.count(Lub) > 0; | ||
| } | ||
|
|
||
| bool Lattice::hasBottom() const { | ||
| return operators.count(Bottom) > 0; | ||
| } | ||
|
|
||
| bool Lattice::hasTop() const { | ||
| return operators.count(Top) > 0; | ||
| } | ||
|
|
||
| const ast::Argument* Lattice::getLub() const { | ||
| return operators.at(Lub).get(); | ||
| } | ||
|
|
||
| const ast::Argument* Lattice::getGlb() const { | ||
| return operators.at(Glb).get(); | ||
| } | ||
|
|
||
| const ast::Argument* Lattice::getBottom() const { | ||
| return operators.at(Bottom).get(); | ||
| } | ||
|
|
||
| const ast::Argument* Lattice::getTop() const { | ||
| return operators.at(Top).get(); | ||
| } | ||
|
|
||
| void Lattice::print(std::ostream& os) const { | ||
| os << ".lattice " << getQualifiedName() << " {\n "; | ||
| bool first = true; | ||
| for (const auto& [op, arg] : operators) { | ||
| if (!first) { | ||
| os << ",\n "; | ||
| } | ||
| os << latticeOperatorToString(op) << " -> " << *arg; | ||
| first = false; | ||
| } | ||
| os << "\n}"; | ||
| } | ||
|
|
||
| bool Lattice::equal(const Node& node) const { | ||
| const auto& other = asAssert<Lattice>(node); | ||
| return getQualifiedName() == other.getQualifiedName() && equal_targets(operators, other.operators); | ||
| } | ||
|
|
||
| Lattice* Lattice::cloning() const { | ||
| return new Lattice(getQualifiedName(), clone(operators), getSrcLoc()); | ||
| } | ||
|
|
||
| } // namespace souffle::ast |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * 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 | ||
| */ | ||
|
|
||
| /************************************************************************ | ||
| * | ||
| * @file Lattice.h | ||
| * | ||
| * Defines the Lattice class | ||
| * | ||
| ***********************************************************************/ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "ast/Argument.h" | ||
| #include "ast/Node.h" | ||
| #include "ast/QualifiedName.h" | ||
| #include "parser/SrcLocation.h" | ||
|
|
||
| #include <map> | ||
| #include <optional> | ||
|
|
||
| namespace souffle::ast { | ||
|
|
||
| enum LatticeOperator { Bottom = 0, Top, Lub, Glb, Leq }; | ||
|
|
||
| std::optional<LatticeOperator> latticeOperatorFromString(const std::string& str); | ||
|
|
||
| /** | ||
| * @class Lattice | ||
| * @brief An class to define Lattice attributes for a type | ||
| */ | ||
| class Lattice : public Node { | ||
| public: | ||
| Lattice(QualifiedName name, std::map<LatticeOperator, Own<ast::Argument>> operators, | ||
| SrcLocation loc = {}); | ||
|
|
||
| /** Return type name */ | ||
| const QualifiedName& getQualifiedName() const { | ||
| return name; | ||
| } | ||
|
|
||
| /** Set type name */ | ||
| void setQualifiedName(QualifiedName name); | ||
|
|
||
| const std::map<LatticeOperator, const ast::Argument*> getOperators() const; | ||
|
|
||
| bool hasGlb() const; | ||
| bool hasLub() const; | ||
| bool hasBottom() const; | ||
| bool hasTop() const; | ||
|
|
||
| const ast::Argument* getLub() const; | ||
| const ast::Argument* getGlb() const; | ||
| const ast::Argument* getBottom() const; | ||
| const ast::Argument* getTop() const; | ||
|
|
||
| protected: | ||
| void print(std::ostream& os) const override; | ||
|
|
||
| private: | ||
| bool equal(const Node& node) const override; | ||
|
|
||
| Lattice* cloning() const override; | ||
|
|
||
| private: | ||
| /** type name */ | ||
| QualifiedName name; | ||
|
|
||
| const std::map<LatticeOperator, Own<ast::Argument>> operators; | ||
| }; | ||
|
|
||
| } // namespace souffle::ast |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.