-
Notifications
You must be signed in to change notification settings - Fork 15
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 try_*_get()
for each vector type, and fail more elegantly in Vector
element extraction
#503
base: main
Are you sure you want to change the base?
Conversation
…ing shown to the user `top_level_exec()` shows errors to the user if they occur at the top level, even if our calling code recovers from the error
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.
LGTM! Is it worth copying the tests from #499 ?
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.
LGTM!
I'm slightly worried about the performance overhead. This could be improved by:
- Detecting whether a vector is altrep or not on construction.
- If not altrep, get full vector slice and use that to index an element
- If altrep, use protected get, and this could be improved later on to retrieve regions so the protection would only happen once per region.
@@ -1264,3 +1264,86 @@ pub fn plain_binding_force_with_rollback(binding: &Binding) -> anyhow::Result<RO | |||
_ => Err(anyhow!("Unexpected binding type")), | |||
} | |||
} | |||
|
|||
#[cfg(test)] | |||
mod tests { |
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.
Nice!
|
||
// Small, should always pass with `success` | ||
let display = get_display_value("local({x = 1:1e3; names(x) = x; names(x)})"); | ||
assert!(success.is_match(display.as_str()) || failure.is_match(display.as_str())); |
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.
assert!(success.is_match(display.as_str()) || failure.is_match(display.as_str())); | |
assert!(success.is_match(display.as_str())); |
I'm not familiar with altrep but would this behave better than the |
Do we need to be worried about the variable and data viewer panes being confusing with altrep objects? Would it be possible for the formatting paths to use the |
Note to self to wait for #508 and rework this on top of that after it is merged |
It is completely up to the ALTREP class. The ALTREP author could decide that Using Otherwise it falls back to this: And FWIW, deferred strings can't provide a dataptr before it has fully materialized, so it would always fall back to the |
Closes #499 (alternative approach)
Addresses posit-dev/positron#4537
If we try and extract an element with
get_unchecked()
that causes an error in an ALTREPElt
method (including but not limited to an OOM error), we now log an error and returnerror_elt()
for that type, which is typically theNA
value for that type, but for raw vectors it is0
as anRbyte
.I considered propagating the error up through the return value of
get_unchecked()
but that was painful. We use it in so many places that don't expect it to fail that propagating an error through would be a huge ordeal that doesn't seem worth it for this somewhat rare case. I think logging an error + showingNA
or something like it is possibly the best we can do.I confirmed that
doesn't crash immediately anymore, but expanding
x
in the Variables pane hangs and causes a 5 second timeout. Something is definitely not right here because evenx <- 1:1e5
hangs for a long time onmain
when you try and expandx
in the Variables pane.