2013-07-26 05:33:13 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
|
|
|
#include "expr.h"
|
|
|
|
#include "max_sharing.h"
|
|
|
|
#include "free_vars.h"
|
|
|
|
#include "deep_copy.h"
|
|
|
|
#include "abstract.h"
|
|
|
|
#include "normalize.h"
|
2013-08-05 03:52:14 +00:00
|
|
|
#include "arith.h"
|
2013-07-26 05:33:13 +00:00
|
|
|
#include "test.h"
|
|
|
|
using namespace lean;
|
|
|
|
|
2013-07-30 07:25:19 +00:00
|
|
|
expr normalize(expr const & e) {
|
|
|
|
environment env;
|
2013-08-05 03:52:14 +00:00
|
|
|
env.add_fact("a", int_type());
|
|
|
|
env.add_fact("b", int_type());
|
|
|
|
env.add_fact("f", arrow(int_type(), arrow(int_type(), int_type())));
|
|
|
|
env.add_fact("h", arrow(int_type(), arrow(int_type(), int_type())));
|
2013-07-30 07:25:19 +00:00
|
|
|
return normalize(e, env);
|
|
|
|
}
|
|
|
|
|
2013-07-26 05:33:13 +00:00
|
|
|
static void mk(expr const & a) {
|
|
|
|
expr b = constant("b");
|
|
|
|
for (unsigned i = 0; i < 100; i++) {
|
|
|
|
expr h = constant("h");
|
|
|
|
h = h(a);
|
|
|
|
for (unsigned j = 0; j < 100; j++)
|
|
|
|
h = app(h, b);
|
|
|
|
h = max_sharing(h);
|
|
|
|
lean_assert(closed(h));
|
|
|
|
h = normalize(h);
|
2013-08-03 19:20:01 +00:00
|
|
|
h = abstract(h, a);
|
2013-07-26 05:33:13 +00:00
|
|
|
lean_assert(!closed(h));
|
|
|
|
h = deep_copy(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tst1() {
|
|
|
|
expr a = constant("a");
|
|
|
|
expr f = constant("f");
|
|
|
|
a = f(a, a);
|
|
|
|
std::vector<std::thread> ts;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 8; i++) {
|
|
|
|
ts.push_back(std::thread([&](){ mk(a); }));
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < 8; i++) {
|
|
|
|
ts[i].join();
|
|
|
|
std::cout << "finished " << i << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
tst1();
|
|
|
|
return 0;
|
|
|
|
}
|