-
-
Notifications
You must be signed in to change notification settings - Fork 948
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
Change the semantics of exprs/for loops allocations strategy #1546
Conversation
This commit adjusts how exprs and for loops are handled within rsx. This is a breaking change in terms of codegen, but has slight semantic changes as well. Now, when exprs/for loops are allocated, they are given a temporary. The temporary is elided to the <'a> lifetime of the bump, to satisfy the borrow checker. This fixes issues with signals where exprs/for loops mapping vecs out of RefCells would be caught up without a temporary lifetime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes rsx slightly more forgiving and everything gets converted to Vnodes when the component is diffed anyway so it shouldn't have a large performance impact.
A very similar issue can happen with let statements in unterminated if blocks that could be worth addressing in this PR as well:
fn app(cx: Scope) -> Element {
let todos = use_ref(cx, || vec!["hi"]);
render! {
ul {
if let &[first] = todos.read().as_slice() {
rsx! { li { "single element: {first}" } }
}
}
}
}
This commit adjusts how rsx! works, making it more forgiving with signals. Notably, we add the temporaries to if chains too.
It technically worked before, apparently, but I've updated it to do the temporary coercion for both. I think there's no performance impact since the temporary should get merged during codegen. |
This commit adjusts how exprs and for loops are handled within rsx. This is a breaking change in terms of codegen, but has slight semantic changes as well.
Now, when exprs/for loops are allocated, they are given a temporary. The temporary is elided to the <'a> lifetime of the bump, to satisfy the borrow checker. This fixes issues with signals where exprs/for loops mapping vecs out of RefCells would be caught up without a temporary lifetime.
Specifically, before, this component could not compile:
The error we were getting is:
This is fixed now, fixing a major papercut of signals and the work being done in fermi to allow truly global state.
This works because we now do a codegen from
to