-
Notifications
You must be signed in to change notification settings - Fork 982
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
bump rust version #4985
bump rust version #4985
Conversation
8d52ee4
to
28e41bc
Compare
3147491
to
d494999
Compare
34fee96
to
17b482a
Compare
efadb3d
to
df077fb
Compare
7644cf1
to
2b491f7
Compare
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.
Kudos! This is a huge amount of work. The main thing I'd like to see addressed are a couple comments and the clone in store_get_scoped
. Other than that, I think it's ready to merge, but I am no wasm expert, and it would be great for @leoyvens to look at this, too.
)? | ||
// This is not great in a hot path but otherwise the self ref would not | ||
// be released for the next block. Would be good to find a better pattern here. | ||
.map(|e| e.into_owned()); |
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 change builds for me without requiring a clone:
.map(|e| e.into_owned()); | |
let block_state = &mut self.as_mut().ctx.state; | |
let entity_option = | |
host_exports.store_get(block_state, entity_type.clone(), id.clone(), gas, scope)?; |
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.
it compiles but breaks the tests because of the runtime borrow checking so I had to put it back
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.
I found a way around the clone, but it's ugly as hell. The clone basically undoes PR #4624. Do we really need interior mutability for WasmInstanceContext
? Can't we get away with just plain &mut
as we used to?
diff --git a/graph/src/runtime/wasm/module/context.rs b/graph/src/runtime/wasm/module/context.rs
index cc3733214..6502209c3 100644
--- a/graph/src/runtime/wasm/module/context.rs
+++ b/graph/src/runtime/wasm/module/context.rs
@@ -140,6 +140,11 @@ impl WasmInstanceContext {
scope: GetScope,
) -> Result<AscPtr<AscEntity>, HostExportError> {
let host_exports = self.as_ref().ctx.host_exports.cheap_clone();
+ let instrument = self.as_ref().ctx.instrument;
+ let host_metrics = self.as_ref().host_metrics.cheap_clone();
+ let debug_fork = self.as_ref().ctx.debug_fork.cheap_clone();
+ let logger = self.as_ref().ctx.logger.cheap_clone();
+
let _timer = self
.as_ref()
.host_metrics
@@ -150,37 +155,29 @@ impl WasmInstanceContext {
let entity_type: String =
asc_get(&read_store, self.as_mut().asc_heap_mut(), entity_ptr, gas)?;
let id: String = asc_get(&read_store, self.as_mut().asc_heap_mut(), id_ptr, gas)?;
+ let (mut heap_mut, mut state_mut) = RefMut::map_split(
+ self.as_mut(),
+ |WasmInstanceContextInner { ctx, asc_heap, .. }| {
+ (asc_heap.as_mut().unwrap(), &mut ctx.state)
+ },
+ );
let entity_option = host_exports
- .store_get(
- &mut self.as_mut().ctx.state,
- entity_type.clone(),
- id.clone(),
- gas,
- scope,
- )?
+ .store_get(&mut state_mut, entity_type.clone(), id.clone(), gas, scope)?
// This is not great in a hot path but otherwise the self ref would not
// be released for the next block. Would be good to find a better pattern here.
.map(|e| e.into_owned());
- if self.as_ref().ctx.instrument {
- debug!(self.as_ref().ctx.logger, "store_get";
+ if instrument {
+ debug!(logger, "store_get";
"type" => &entity_type,
"id" => &id,
"found" => entity_option.is_some());
}
- let host_metrics = self.as_ref().host_metrics.cheap_clone();
- let debug_fork = self.as_ref().ctx.debug_fork.cheap_clone();
let ret = match entity_option {
Some(entity) => {
let _section = host_metrics.stopwatch.start_section("store_get_asc_new");
- // let entity = entity.to_owned().sorted_ref();
- asc_new(
- store,
- self.as_mut().asc_heap_mut(),
- &entity.sorted_ref(),
- gas,
- )?
+ asc_new(store, &mut *heap_mut, &entity.sorted_ref(), gas)?
}
None => match &debug_fork {
Some(fork) => {
@@ -194,12 +191,7 @@ impl WasmInstanceContext {
Some(entity) => {
let _section =
host_metrics.stopwatch.start_section("store_get_asc_new");
- let entity = asc_new(
- store,
- self.as_mut().asc_heap_mut(),
- &entity.sorted(),
- gas,
- )?;
+ let entity = asc_new(store, &mut *heap_mut, &entity.sorted(), gas)?;
self.store_set(store, gas, entity_ptr, id_ptr, entity)?;
entity
}
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.
Even removing the RefCell this borrow conflict persisted (but now at compile time). I fixed it by switching from Cow
to Arc
.
Is there any protection here against a mapping maxing out a CPU by running an infinite loop? |
That will be added on a following PR, that's why the comments were disabled |
451e1b1
to
b579f0b
Compare
We might not want to rollout, and surely not release, without some type of protection against that in place. It's preferable that master is always in a state which we'd be comfortable releasing. |
b579f0b
to
9d1e28d
Compare
Agreed, yet this is a specific case for which I proposed we make an exception since the fix should be shortly along but should not be added in this PR, first because of the need to maintain the PR open in the meantime and second we are not going to release before the protection is in place so that's not an issue as discussed and agreed by the team |
32e9cf7
to
6a79cb9
Compare
You can put the fix in a separate PR that's based on this branch, the fix doesn't need to be blocked on this being merged. |
08fb392
to
e66c884
Compare
Taking a look at the use of interior mutability in The fundamental issue seems to be that when trying to call One way around a double mutable borrow would be the interior mutability, but a more idiomatic solution might be: I experimented with that here and it seemed possible. It also seems to avoid changing the definition of the |
To be able to keep the crate separation, we might in And then in |
The above might not quite work, unless we also either:
So there are some details we need to hash out, but I'm happy to pair on this |
e66c884
to
146d07c
Compare
3e70677
to
69bc719
Compare
This is ready for another review, all comments addressed. I'll run it on an integration cluster. |
This has been running in the integration cluster for a few days, no discrepancies. |
370fcba
to
a15b1b5
Compare
The crux is in the definition of `WasmInstanceContext`, an how it implements both `wasmtime::AsContext` and our `AscHeap`.
c1736d2
to
0f051c9
Compare
No description provided.