Skip to content
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

avoid sortedness errors with polymorphically let-bound constants #544

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Kernel/Signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Signature::Symbol::Symbol(const vstring& nm, unsigned arity, bool interpreted, b
_skipCongruence(0),
_tuple(0),
_computable(1),
_letBound(0),
_prox(NOT_PROXY),
_comb(NOT_COMB)
{
Expand Down
6 changes: 6 additions & 0 deletions Kernel/Signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class Signature
unsigned _tuple : 1;
/** if allowed in answer literals */
unsigned _computable : 1;
/** name that is bound by a $let-binder */
unsigned _letBound : 1;
/** proxy type */
Proxy _prox;
/** combinator type */
Expand Down Expand Up @@ -195,6 +197,8 @@ class Signature
void markTermAlgebraDest() { _termAlgebraDest=1; }
/** mark the symbol as uncomputable and hence not allowed in answer literals */
void markUncomputable() { _computable = 0; }
/** mark the symbol as let-bound */
void markLetBound() { _letBound = 1; }

/** return true iff symbol is marked as skip for the purpose of symbol elimination */
bool skip() const { return _skip; }
Expand Down Expand Up @@ -245,6 +249,8 @@ class Signature
inline bool termAlgebraDest() const { return _termAlgebraDest; }
/** Return true iff symbol is considered computable */
inline bool computable() const { return _computable; }
/** if bound by a $let-binder */
inline bool letBound() const { return _letBound; }

/** Increase the usage count of this symbol **/
inline void incUsageCnt(){ _usageCount++; }
Expand Down
22 changes: 21 additions & 1 deletion Kernel/SortHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,27 @@ TermList SortHelper::getResultSort(const Term* t)
getTypeSub(t, subst);
Signature::Symbol* sym = env.signature->getFunction(t->functor());
TermList result = sym->fnType()->result();
ASS(!subst.isEmpty() || (result.isTerm() && (result.term()->isSuper() || result.term()->ground())));

/*
either
1. the substitution is non-empty
2. the result is ground (or $tType)
3. t is let-bound: consider the following TFF1

% polymorphic constant
tff(c_type, type, c: !>[A: $tType]: A).
% some polymorphic predicate, not important
tff(p_type, type, p: !>[A: $tType]: A > $o).

% let-bind a polymorphic identity function
tff(bug, axiom, ![A: $tType]: $let(id: A > A, id(X) := X, p(A, id(c(A))))).
% note that type of id is A > A, *not* !>[A: $tType]: A > A.
*/
ASS(
!subst.isEmpty() ||
(result.isTerm() && (result.term()->isSuper() || result.term()->ground())) ||
sym->letBound()
)
return SubstHelper::apply(result, subst);
}

Expand Down
14 changes: 7 additions & 7 deletions Parse/TPTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2345,18 +2345,18 @@ void TPTP::endLetTypes()
unsigned arity = type->arity();
bool isPredicate = type->isPredicateType();

unsigned symbol = isPredicate
unsigned functor = isPredicate
? env.signature->addFreshPredicate(arity, name.c_str())
: env.signature->addFreshFunction(arity, name.c_str());
Signature::Symbol *symbol = isPredicate
? env.signature->getPredicate(functor)
: env.signature->getFunction(functor);

if (isPredicate) {
env.signature->getPredicate(symbol)->setType(type);
} else {
env.signature->getFunction(symbol)->setType(type);
}
symbol->setType(type);
symbol->markLetBound();

LetSymbolName symbolName(name, arity);
LetSymbolReference symbolReference(symbol, isPredicate);
LetSymbolReference symbolReference(functor, isPredicate);

LetSymbols scope = _letTypedSymbols.pop();

Expand Down