Skip to content
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

avm2: Add support for sparse arrays #15491

Closed
wants to merge 0 commits into from
Closed

Conversation

jarca0123
Copy link
Contributor

@jarca0123 jarca0123 commented Mar 8, 2024

This attempts to implement sparse arrays. There are (as of creating this pull request) big caveats:

  • dense arrays are turned into sparse arrays only if they go beyond current array length and conditions for conversion into sparse arrays from avmplus aren't implemented dense arrays do not implement m_denseStart from avmplus, this might need a custom Vec
  • it uses BTreeMap, when it probably would be more "correct" to use the DynamicMap implementation
  • I have no idea if splice works

It does pass tests and also fixes some known failures.

@jarca0123 jarca0123 marked this pull request as draft March 9, 2024 17:13
@jarca0123 jarca0123 marked this pull request as ready for review March 10, 2024 14:15
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
@jarca0123 jarca0123 marked this pull request as draft March 13, 2024 14:24
@jarca0123 jarca0123 marked this pull request as ready for review March 14, 2024 15:54
@Lord-McSweeney
Copy link
Collaborator

The uses of ArrayStorage::XXX(something, ..) and ArrayStorage::XXX(something, _something_else) can all be replaced with ArrayStorage::XXX(something, _)

@Lord-McSweeney
Copy link
Collaborator

Lord-McSweeney commented Mar 17, 2024

Not blocking, but I just realized that several places in ArrayObject do name.parse<usize>() or name.parse<u32>(), but should instead do something like name.parse::<u32>().ok().filter(|s| *s != 4294967295)

@danielhjacobs danielhjacobs added the waiting-on-review Waiting on review from a Ruffle team member label Mar 21, 2024
@danielhjacobs danielhjacobs added the A-avm2 Area: AVM2 (ActionScript 3) label Mar 21, 2024
Copy link
Member

@kmeisthax kmeisthax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading through most of the array code my main concern is just documenting what the usize parameters do, since that was the biggest thing I was confused about. That's the only thing I feel needs to be fixed before I can merge this.

The splice code seemed straightforward once I puzzled out what it was doing, and it's probably correct. I'm a bit iffy about "drop to splice" as an API but it shouldn't impact correctness in this case. (Remember that memory leaks are safe and that Drop doesn't always run!)

index_back: usize,
}

pub struct ArrayStorageMutableIterator<'a, 'gc> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading the rest of the code correctly, the Mutable variants of the array storage iterator exist primarily so the splice iterators can call into their next/prev methods? It seems awkward, but I'm not aware of a more elegant way to do this...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exists because I don't know how to implement it without a mutable iterator 😅

core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
@Lord-McSweeney Lord-McSweeney added waiting-on-author Waiting on the PR author to make the requested changes and removed waiting-on-review Waiting on review from a Ruffle team member labels Apr 10, 2024
@Lord-McSweeney Lord-McSweeney added waiting-on-review Waiting on review from a Ruffle team member and removed waiting-on-author Waiting on the PR author to make the requested changes labels Apr 16, 2024
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
core/src/avm2/array.rs Outdated Show resolved Hide resolved
@Lord-McSweeney Lord-McSweeney added waiting-on-author Waiting on the PR author to make the requested changes waiting-on-review Waiting on review from a Ruffle team member and removed waiting-on-review Waiting on review from a Ruffle team member waiting-on-author Waiting on the PR author to make the requested changes labels Apr 18, 2024
@Lord-McSweeney Lord-McSweeney added waiting-on-author Waiting on the PR author to make the requested changes and removed waiting-on-review Waiting on review from a Ruffle team member labels Apr 19, 2024
storage,
occupied_count,
} => {
if storage.len() < (item + 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be item >= storage.len()


/// Convert the array storage to a sparse representation.
fn convert_to_sparse(&mut self) {
match self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be rewritten without the match? Would be a bit shorter

if let ArrayStorage::Dense { storage, .. } = self {


/// Convert the array to a sparse representation if it meets the criteria.
fn maybe_convert_to_sparse(&mut self) {
match self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

/// Convert the array to a dense representation if it meets the criteria.
fn maybe_convert_to_dense(&mut self) {
match self {
ArrayStorage::Dense { .. } => {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@adrian17 adrian17 closed this Apr 20, 2024
@danielhjacobs danielhjacobs removed the waiting-on-author Waiting on the PR author to make the requested changes label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-avm2 Area: AVM2 (ActionScript 3)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants