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>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
|
|
|
#include "kernel/expr.h"
|
|
|
|
#include "kernel/free_vars.h"
|
|
|
|
#include "kernel/abstract.h"
|
|
|
|
#include "kernel/normalizer.h"
|
|
|
|
#include "library/max_sharing.h"
|
|
|
|
#include "library/deep_copy.h"
|
|
|
|
#include "library/import_all/import_all.h"
|
2013-09-13 15:55:09 +00:00
|
|
|
#include "library/arith/arith.h"
|
2013-07-26 05:33:13 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
2013-09-07 06:40:47 +00:00
|
|
|
expr norm(expr const & e, environment & env) {
|
2013-08-06 18:27:14 +00:00
|
|
|
env.add_var("a", Int);
|
|
|
|
env.add_var("b", Int);
|
|
|
|
env.add_var("f", Int >> (Int >> Int));
|
|
|
|
env.add_var("h", Int >> (Int >> Int));
|
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) {
|
2013-09-07 06:40:47 +00:00
|
|
|
environment env = mk_toplevel();
|
2013-08-06 18:27:14 +00:00
|
|
|
expr b = Const("b");
|
2013-07-26 05:33:13 +00:00
|
|
|
for (unsigned i = 0; i < 100; i++) {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr h = Const("h");
|
2013-07-26 05:33:13 +00:00
|
|
|
h = h(a);
|
|
|
|
for (unsigned j = 0; j < 100; j++)
|
2013-08-06 18:27:14 +00:00
|
|
|
h = mk_app(h, b);
|
2013-07-26 05:33:13 +00:00
|
|
|
h = max_sharing(h);
|
|
|
|
lean_assert(closed(h));
|
2013-09-07 06:40:47 +00:00
|
|
|
environment env2 = env.mk_child();
|
|
|
|
h = norm(h, env2);
|
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() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr a = Const("a");
|
|
|
|
expr f = Const("f");
|
2013-07-26 05:33:13 +00:00
|
|
|
a = f(a, a);
|
|
|
|
std::vector<std::thread> ts;
|
|
|
|
|
2013-08-12 21:57:24 +00:00
|
|
|
#ifndef __APPLE__
|
2013-07-26 05:33:13 +00:00
|
|
|
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";
|
|
|
|
}
|
2013-09-04 11:43:55 +00:00
|
|
|
#else
|
|
|
|
mk(a);
|
2013-08-12 21:57:24 +00:00
|
|
|
#endif
|
2013-07-26 05:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
tst1();
|
|
|
|
return 0;
|
|
|
|
}
|