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

Vec is missing INDEX_GET protocol and support for range indexing #460

Open
jasal82 opened this issue Mar 24, 2023 · 4 comments
Open

Vec is missing INDEX_GET protocol and support for range indexing #460

jasal82 opened this issue Mar 24, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@jasal82
Copy link

jasal82 commented Mar 24, 2023

Vec indexing is inconsistent. For example, indexing a single item in a vector works fine:

let v = [0, 1, 2];
let item = v[1];

Obtaining slices into the vector fails, however:

let slice = v[1..];
// fails with 'the index get operation `Vec[Range]` is not supported'

For String types, on the other hand, this works as expected. I have a patch for Rune ready that I can contribute.

@jasal82
Copy link
Author

jasal82 commented Mar 24, 2023

There's one thing that confuses me and needs to be clarified for the patch: Even after removing both get and Protocol::INDEX_GET instance functions from Vec's native module declaration I can still do let item = v[1] in the Rune script, which is completely unexpected.

@udoprog udoprog added the enhancement New feature or request label Mar 24, 2023
@udoprog
Copy link
Collaborator

udoprog commented Mar 24, 2023

Vector indexing by a number is an internal Vm operation. Range indexing could probably also go there.

@jasal82
Copy link
Author

jasal82 commented Mar 24, 2023

Ok I understand. Intuitively I would think that neither the integer nor the range indexing should be an internal Vm operation because if there are instance functions in the native modules (like get()) which are just another frontend to the indexing you have to implement the operations twice.

@udoprog
Copy link
Collaborator

udoprog commented Mar 25, 2023

Hm, Vm operation exists because it accelerates the operation. We avoid additional dispatch to the external function which involves a bit of stack mangling.

I'd be open to being able to disable internal acceleration maybe it could be done through a feature flag, but then you'd run the risk of feature parity. All though disabling it completely should probably be supported at some point for folks that really wants a completely bare virtual machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants