// Souffle - A Datalog Compiler
// Copyright (c) 2017, 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

// Tests valid cyclic inlining.

// Though the precedence graph contains the cycle {b, c, d, e},
// no cycle exists that consists solely of inlined relations,
// and so this program is valid.

.decl a(x:number)
.input a()

.decl b(x:number) inline
.decl c(x:number)
.decl d(x:number) inline
.decl e(x:number)

.decl f(x:number)
.output f()

f(x) :- d(x).
d(x) :- c(x).
c(x) :- b(x).
b(x) :- e(x).
e(x) :- d(x).
b(x) :- a(x).

//
// ungrounded positive testcase for inlining
// (See issue #1956)
//
.decl a2(x: number, y: number) inline
.decl b2(x: number, y: number)
.decl c2(x: number, y: number)
a2(x, y) :- x = y.
b2(1,2).
c2(x, y) :- b2(x, y), !a2(x, y).
.output c2

//
// tests constraints in the head of an inlined relation
// (See issue #1966)
//

.decl A3(x:number, y:number) inline
A3(x,x) :- true.

.decl B3,C3(x:number, y:number)
B3(1,2).
C3(x,y) :- B3(x,y), !A3(x,y).
.output C3

