You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
If the root variable is a shared ref then any path starting at that root variable will be captured by ref or copied (in case the path is Copy and the closure is a move closure)
We will never have a borrow conflict if we reduce the precision
In the case where the path would've been captured by ref, truncating to the root variable and capturing the root variable will result in capture of the same size or maybe cheaper.
It's cheaper in case of function pointers. Right now the way preicse capture analysis would capture f: &F works is we caputre &*f which ends up capturing a fat pointer which is two words. Before precise capture we'd capture &f which is a thin pointer and a single word.
In the case where the path would've been copied, truncating to the root variable can possibly result increase in size compared to precise capture.
eg: Consider x: &T, x.y: u8 then it's cheaper to copy x.y is cheaper than copying x
The text was updated successfully, but these errors were encountered:
arora-aman
changed the title
Size Optimization: Capture Root varaiable if it's a sharef ref
Size Optimization: Capture root varaiable if it's a sharef ref
Jun 16, 2021
I kind of a had a side thought that I realize won't work, but want to document it as well.
A simpler way would be to just say that if the root variable is a shared ref,
a) If it's a non-move closure we capture the root variable
b) If it's a move closure we look through all precise captures and check if sum of the sizes is more than capturing the root variable and if true we capture the root variable.
Problem with this approach is we don't know the size of all types until we reach codegen (might need monomorphism).
Initial thoughts:
If the root variable is a shared ref then any path starting at that root variable will be captured by ref or copied (in case the path is Copy and the closure is a move closure)
We will never have a borrow conflict if we reduce the precision
In the case where the path would've been captured by ref, truncating to the root variable and capturing the root variable will result in capture of the same size or maybe cheaper.
f: &F
works is we caputre&*f
which ends up capturing a fat pointer which is two words. Before precise capture we'd capture&f
which is a thin pointer and a single word.In the case where the path would've been copied, truncating to the root variable can possibly result increase in size compared to precise capture.
x: &T
,x.y: u8
then it's cheaper to copyx.y
is cheaper than copyingx
The text was updated successfully, but these errors were encountered: