-
Notifications
You must be signed in to change notification settings - Fork 18
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
Rework completely PE and lower2cff #95
Comments
Right now, people looking for a quick fix can implement such algorithms by managing the stack manually (creating a local mutable array for it). That's however clearly not a long term solution. |
The |
There is also a subtle problem with the partial evaluator as it is now, which I thought might be of interest if you are working on this. The criteria of the partial evaluator that determine when to perform inlining/specialization are incorrect. The problem lies in bool eval(size_t i, bool lower2cff) {
// the only higher order parameter that is allowed is a single 1st-order fn-parameter of a top-level continuation
// all other parameters need specialization (lower2cff)
auto order = callee_->param(i)->order();
if (lower2cff)
if(order >= 2 || (order == 1
&& (!callee_->param(i)->type()->isa<FnType>()
|| (!callee_->is_returning() || (!is_top_level(callee_)))))) {
DLOG("bad param({}) {} of continuation {}", i, callee_->param(i), callee_);
return true;
}
return (!callee_->is_external() && callee_->num_uses() == 1) || is_one(instantiate(filter(i)));
} The condition fn @f(i: i32) -> () {
fn g() -> () {
println(i)
}
($g)()
}
// ...
for i in unroll(0, 10) {
f(i)
} The resulting code should generate 10 different In general, the condition should be: (i.e. this optimization is only valid for basic blocks) |
Right now, there is the PE phase that does partial evaluation and lower2cff at the same time. This has some issues, as pointed out before with issue #93. However, even with a fix for that, there is a more fundamental problem here. Consider the following code:
The function
something
uses a predicate functionpred
, which at the call site in functionboom
happens to be an anonymous function capturingn
, a parameter fromboom
. Now the problem is thatsomething
can be specialized to that predicate without any issue (with the fix for issue #93), but it then makes it depend on the parametern
(because the predicate refers ton
). No amount of specialization can solve that problem: What we need to do is to lift the functionsomething
from its scope after specialization, which means adding a parameter that takes a value forn
. In order to do this, it makes sense to decouple PE from lower2cff (even though some code can be shared), since lower2cff requires more work.Right now, this example hangs on both
master
andpe_fix
. Note that this example is in no way contrived or rare. Such a pattern happens for every divide and conquer algorithm out there (it was encountered while coding a version of the quick sort algorithm).The text was updated successfully, but these errors were encountered: