This is the beginning of a refactoring to make std::function the basis for oracles internally, not binary names.
node_traversal.h
node_value.cpp
node_value.h
+ oracle.h
oracle_caller.cpp
oracle_caller.h
sequence.cpp
struct DatatypeIndexTag
{
};
+ struct OracleIndexTag
+ {
+ };
} // namespace attr
typedef Attribute<attr::VarNameTag, std::string> VarNameAttr;
/** Mapping datatype types to the index of their datatype in node manager */
using DatatypeIndexAttr = Attribute<attr::DatatypeIndexTag, uint64_t>;
+/** Mapping oracle constant nodes to the index of their oracle in the node
+ * manager */
+using OracleIndexAttr = expr::Attribute<expr::attr::OracleIndexTag, uint64_t>;
+
} // namespace expr
} // namespace cvc5::internal
#include "expr/metakind.h"
#include "expr/node_manager.h"
#include "expr/node_manager_attributes.h"
+#include "expr/oracle.h"
#include "expr/skolem_manager.h"
#include "expr/type_checker.h"
#include "expr/type_properties.h"
d_rt_cache.d_children.clear();
d_rt_cache.d_data = dummy;
- // clear the datatypes
+ // clear the datatypes and oracles
d_dtypes.clear();
+ d_oracles.clear();
Assert(!d_attrManager->inGarbageCollection());
return usort;
}
+Node NodeManager::mkOracle(Oracle& o)
+{
+ Node n = NodeBuilder(this, kind::ORACLE);
+ n.setAttribute(TypeAttr(), builtinOperatorType());
+ n.setAttribute(TypeCheckedAttr(), true);
+ n.setAttribute(OracleIndexAttr(), d_oracles.size());
+ // we allocate a new oracle, to take ownership
+ d_oracles.push_back(std::unique_ptr<Oracle>(new Oracle(o.getFunction())));
+ return n;
+}
+
+const Oracle& NodeManager::getOracleFor(const Node& n) const
+{
+ Assert(n.getKind() == kind::ORACLE);
+ size_t index = n.getAttribute(OracleIndexAttr());
+ Assert(index < d_oracles.size());
+ return *d_oracles[index];
+}
+
Node NodeManager::mkVar(const std::string& name, const TypeNode& type)
{
Node n = NodeBuilder(this, kind::VARIABLE);
class BoundVarManager;
class DType;
+class Oracle;
class Rational;
namespace expr {
/** Make an unresolved datatype sort */
TypeNode mkUnresolvedDatatypeSort(const std::string& name, size_t arity = 0);
+ /**
+ * Make an oracle node. This returns a constant of kind ORACLE that stores
+ * the given method in an Oracle object. This Oracle can later be obtained by
+ * getOracleFor below.
+ */
+ Node mkOracle(Oracle& o);
+
+ /**
+ * Get the oracle for an oracle node n, which should have kind ORACLE.
+ */
+ const Oracle& getOracleFor(const Node& n) const;
+
private:
/**
* Make a set of types representing the given datatypes, which may
/** A list of datatypes owned by this node manager */
std::vector<std::unique_ptr<DType>> d_dtypes;
+ /** A list of oracles owned by this node manager */
+ std::vector<std::unique_ptr<Oracle>> d_oracles;
+
TupleTypeCache d_tt_cache;
RecTypeCache d_rt_cache;
}; /* class NodeManager */
--- /dev/null
+/******************************************************************************
+ * Top contributors (to current version):
+ * Andrew Reynolds
+ *
+ * This file is part of the cvc5 project.
+ *
+ * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+ * in the top-level source directory and their institutional affiliations.
+ * All rights reserved. See the file COPYING in the top-level source
+ * directory for licensing information.
+ * ****************************************************************************
+ *
+ * Oracle caller
+ */
+
+#include "cvc5_private.h"
+
+#ifndef CVC5__EXPR__ORACLE_H
+#define CVC5__EXPR__ORACLE_H
+
+#include <vector>
+
+#include "expr/node.h"
+
+namespace cvc5::internal {
+
+/**
+ * An oracle, which stores a function whose interface is from a vector of nodes
+ * to a vector of nodes. It is expected to serve as an oracle interface as
+ * described in Polgreen et al VMCAI 2022 and the SyGuS version 2.1 standard.
+ */
+class Oracle
+{
+ public:
+ /** Construct an oracle whose implementation is the given function. */
+ Oracle(std::function<std::vector<Node>(const std::vector<Node>&)> fn)
+ : d_fn(fn)
+ {
+ }
+ ~Oracle() {}
+ /** Run the function on the given input */
+ std::vector<Node> run(const std::vector<Node>& input) const
+ {
+ return d_fn(input);
+ }
+ /** Get the function for this oracle */
+ std::function<std::vector<Node>(const std::vector<Node>&)> getFunction() const
+ {
+ return d_fn;
+ }
+
+ private:
+ /** The function for this oracle */
+ std::function<std::vector<Node>(const std::vector<Node>&)> d_fn;
+};
+
+} // namespace cvc5::internal
+
+#endif /*CVC5__EXPR__ORACLE_H*/
variable INST_CONSTANT "instantiation constant"
+variable ORACLE "oracle"
+
sort BOUND_VAR_LIST_TYPE \
Cardinality::INTEGERS \
not-well-founded \