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 <vector>
|
2013-12-09 22:56:48 +00:00
|
|
|
#include "util/thread.h"
|
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"
|
2013-09-13 15:55:09 +00:00
|
|
|
#include "library/arith/arith.h"
|
2013-12-29 10:44:49 +00:00
|
|
|
#include "frontends/lean/frontend.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-12-13 00:33:31 +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-12-30 21:35:37 +00:00
|
|
|
environment env; init_full_frontend(env);
|
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-12-13 00:33:31 +00:00
|
|
|
environment env2 = env->mk_child();
|
2013-09-07 06:40:47 +00:00
|
|
|
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);
|
2013-12-09 22:56:48 +00:00
|
|
|
std::vector<thread> ts;
|
2013-07-26 05:33:13 +00:00
|
|
|
|
2013-12-09 22:56:48 +00:00
|
|
|
#if !defined(__APPLE__) && defined(LEAN_MULTI_THREAD)
|
2013-07-26 05:33:13 +00:00
|
|
|
for (unsigned i = 0; i < 8; i++) {
|
2013-12-09 22:56:48 +00:00
|
|
|
ts.push_back(thread([&](){ save_stack_info(); mk(a); }));
|
2013-07-26 05:33:13 +00:00
|
|
|
}
|
|
|
|
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() {
|
2013-12-01 20:42:32 +00:00
|
|
|
save_stack_info();
|
2013-07-26 05:33:13 +00:00
|
|
|
tst1();
|
|
|
|
return 0;
|
|
|
|
}
|