-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add Cell::update #49727
Add Cell::update #49727
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Here are a few more real-word examples of the In this repository (click to expand):src/libarena/lib.rs
147: self.ptr.set(self.ptr.get().offset(1));
543: self.count.set(self.count.get() + 1);
src/test/run-pass/resource-assign-is-not-copy.rs
20: self.i.set(self.i.get() + 1);
src/test/run-pass/vec-slice-drop.rs
20: self.x.set(self.x.get() + 1);
src/test/run-pass/traits-conditional-model-fn.rs
33: self.counter.set(self.counter.get() + arg);
45: self.counter.set(self.counter.get() + arg);
src/test/run-pass/overloaded-autoderef-count.rs
39: self.count_imm.set(self.count_imm.get() + 1);
src/test/run-pass/issue-16492.rs
32: self.state.set(self.state.get()+1);
src/test/run-pass/option-unwrap.rs
19: self.x.set(self.x.get() - 1);
src/test/run-pass/dynamic-drop.rs
53: self.cur_ops.set(self.cur_ops.get() + 1);
76: self.1.cur_ops.set(self.1.cur_ops.get()+1);
src/test/run-pass/packed-struct-drop-aligned.rs
27: self.drop_count.set(self.drop_count.get() + 1);
src/test/run-pass/overloaded-deref-count.rs
40: self.count_imm.set(self.count_imm.get() + 1);
src/test/run-pass/resource-destruct.rs
19: println!("Hello!"); self.i.set(self.i.get() - 1);
src/test/run-pass/issue-979.rs
19: self.b.set(self.b.get() + 1);
src/test/run-pass/init-res-into-things.rs
26: self.i.set(self.i.get() + 1)
src/test/pretty/block-disambig.rs
60: match true { true => { } _ => { } } regs.set(regs.get() + 1);
src/liballoc/tests/slice.rs
1407: self.version.set(self.version.get() + 1);
1408: other.version.set(other.version.get() + 1);
src/librustc_typeck/check/_match.rs
610: self.diverges.set(self.diverges.get() | Diverges::Always);
src/librustc_typeck/check/mod.rs
3601: self.diverges.set(self.diverges.get() | Diverges::Always);
3610: self.diverges.set(self.diverges.get() | old_diverges);
3611: self.has_errors.set(self.has_errors.get() | old_has_errors);
4362: self.diverges.set(self.diverges.get() | old_diverges);
4363: self.has_errors.set(self.has_errors.get() | old_has_errors);
src/librustc/util/common.rs
237: accu.set(duration + accu.get());
384: self.set(self.get() + 1);
src/librustc/session/mod.rs
899: self.print_fuel.set(self.print_fuel.get() + 1); In Servo (click to expand):work $ cd servo/
components/layout_thread/lib.rs
1632: self.generation.set(self.generation.get() + 1);
components/script/timers.rs
250: self.suspension_offset.set(self.suspension_offset.get() + additional_offset);
components/script/dom/webglshader.rs
190: self.attached_counter.set(self.attached_counter.get() + 1);
195: self.attached_counter.set(self.attached_counter.get() - 1);
components/script/dom/window.rs
1580: self.pending_reflow_count.set(self.pending_reflow_count.get() + 1);
components/script/dom/node.rs
257: self.children_count.set(self.children_count.get() + 1);
297: self.children_count.set(self.children_count.get() - 1);
components/script/dom/htmllinkelement.rs
295: self.request_generation_id.set(self.request_generation_id.get().increment());
319: self.pending_loads.set(self.pending_loads.get() + 1)
328: self.pending_loads.set(self.pending_loads.get() - 1);
components/script/dom/htmlmediaelement.rs
680: self.generation_id.set(self.generation_id.get() + 1);
components/script/dom/htmlstyleelement.rs
202: self.pending_loads.set(self.pending_loads.get() + 1)
211: self.pending_loads.set(self.pending_loads.get() - 1);
components/script/dom/htmlimageelement.rs
603: self.generation.set(self.generation.get() + 1);
components/script/dom/document.rs
551: self.dom_count.set(self.dom_count.get() + 1);
556: self.dom_count.set(self.dom_count.get() - 1);
1384: count_cell.set(count_cell.get() + 1);
1390: count_cell.set(count_cell.get() - 1);
1507: self.spurious_animation_frames.set(self.spurious_animation_frames.get() + 1)
components/gfx/tests/font_context.rs
87: self.find_font_count.set(self.find_font_count.get() + 1); |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Thanks for this PR! The triage team will make sure @cramertj (or someone else from @rust-lang/libs) reviews this. |
r? @SimonSapin (someone from libs) |
Looks good to me. @stjepang, could you open a tracking issue and point the |
Ping from triage @stjepang! There is some action needed on your part. |
Done - I've clarified the docs and opened a tracking issue: #50186. |
Perfect, thanks! @bors: r+ rollup |
📌 Commit 29e9de8 has been approved by |
Add Cell::update This commit adds a new method `Cell::update`, which applies a function to the value inside the cell. Previously discussed in: rust-lang/rfcs#2171 ### Motivation Updating `Cell`s is currently a bit verbose. Here are several real examples (taken from rustc and crossbeam): ```rust self.print_fuel.set(self.print_fuel.get() + 1); self.diverges.set(self.diverges.get() | Diverges::Always); let guard_count = self.guard_count.get(); self.guard_count.set(guard_count.checked_add(1).unwrap()); if guard_count == 0 { // ... } ``` With the addition of the new method `Cell::update`, this code can be simplified to: ```rust self.print_fuel.update(|x| x + 1); self.diverges.update(|x| x | Diverges::Always); if self.guard_count.update(|x| x.checked_add(1).unwrap()) == 1 { // ... } ``` ### Unresolved questions 1. Should we return the old value instead of the new value (like in `fetch_add` and `fetch_update`)? 2. Should the return type simply be `()`? 3. Naming: `update` vs `modify` vs `mutate` etc. cc @SimonSapin
Rollup of 11 pull requests Successful merges: - #49461 (std: Child::kill() returns error if process has already exited) - #49727 (Add Cell::update) - #49812 (Fix revision support for UI tests.) - #49829 (Add doc links to `std::os` extension traits) - #49906 (Stabilize `std::hint::unreachable_unchecked`.) - #49970 (Deprecate Read::chars and char::decode_utf8) - #49985 (don't see issue #0) - #50118 (fix search bar bug) - #50139 (encourage descriptive issue titles) - #50174 (Use FxHashMap in syntax_pos::symbol::Interner::intern.) - #50185 (core: Fix overflow in `int::mod_euc` when `self < 0 && rhs == MIN`) Failed merges:
Related conversation on a similar PR (for (Wasn't sure if this kind of comment is more suitable for the PR or the tracking issue) |
In general, merged or closed PRs are considered done and are not a great place to have further conversations. This is why we have tracking issues :) |
@SimonSapin Ah, I didn't notice that this was merged! |
This commit adds a new method
Cell::update
, which applies a function to the value inside the cell.Previously discussed in: rust-lang/rfcs#2171
Motivation
Updating
Cell
s is currently a bit verbose. Here are several real examples (taken from rustc and crossbeam):With the addition of the new method
Cell::update
, this code can be simplified to:Unresolved questions
fetch_add
andfetch_update
)?()
?update
vsmodify
vsmutate
etc.cc @SimonSapin