From: Andrew Reynolds Date: Tue, 10 Nov 2020 20:09:10 +0000 (-0600) Subject: Make mkGroundTerm deterministic (#5347) X-Git-Tag: cvc5-1.0.0~2620 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=032bee9200bf64af0851832c97ce20b87a6f8e0f;p=cvc5.git Make mkGroundTerm deterministic (#5347) This ensures mkGroundTerm is deterministic using attributes. This was uncovered by failures in the proof checker for datatypes. --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f89b4de3..1a06e9366 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -475,6 +475,7 @@ libcvc4_add_sources( theory/builtin/theory_builtin.h theory/builtin/theory_builtin_rewriter.cpp theory/builtin/theory_builtin_rewriter.h + theory/builtin/theory_builtin_type_rules.cpp theory/builtin/theory_builtin_type_rules.h theory/builtin/type_enumerator.cpp theory/builtin/type_enumerator.h diff --git a/src/theory/builtin/theory_builtin_type_rules.cpp b/src/theory/builtin/theory_builtin_type_rules.cpp new file mode 100644 index 000000000..59c1ecd65 --- /dev/null +++ b/src/theory/builtin/theory_builtin_type_rules.cpp @@ -0,0 +1,50 @@ +/********************* */ +/*! \file theory_builtin_type_rules.cpp + ** \verbatim + ** Top contributors (to current version): + ** Andrew Reynolds + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2020 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.\endverbatim + ** + ** \brief Type rules for the builtin theory + ** + ** Type rules for the builtin theory. + **/ + +#include "theory/builtin/theory_builtin_type_rules.h" + +#include "expr/attribute.h" + +namespace CVC4 { +namespace theory { +namespace builtin { + +/** + * Attribute for caching the ground term for each type. Maps TypeNode to the + * skolem to return for mkGroundTerm. + */ +struct GroundTermAttributeId +{ +}; +typedef expr::Attribute GroundTermAttribute; + +Node SortProperties::mkGroundTerm(TypeNode type) +{ + Assert(type.getKind() == kind::SORT_TYPE); + GroundTermAttribute gta; + if (type.hasAttribute(gta)) + { + return type.getAttribute(gta); + } + Node k = NodeManager::currentNM()->mkSkolem( + "groundTerm", type, "a ground term created for type " + type.toString()); + type.setAttribute(gta, k); + return k; +} + +} // namespace builtin +} // namespace theory +} // namespace CVC4 diff --git a/src/theory/builtin/theory_builtin_type_rules.h b/src/theory/builtin/theory_builtin_type_rules.h index 03dc7e415..1b251f8e0 100644 --- a/src/theory/builtin/theory_builtin_type_rules.h +++ b/src/theory/builtin/theory_builtin_type_rules.h @@ -199,10 +199,7 @@ class SortProperties { inline static bool isWellFounded(TypeNode type) { return true; } - inline static Node mkGroundTerm(TypeNode type) { - Assert(type.getKind() == kind::SORT_TYPE); - return NodeManager::currentNM()->mkSkolem("groundTerm", type, "a ground term created for type " + type.toString()); - } + static Node mkGroundTerm(TypeNode type); };/* class SortProperties */ class FunctionProperties {