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

polymorphic accessors #273

Open
Araq opened this issue Dec 24, 2024 · 5 comments
Open

polymorphic accessors #273

Araq opened this issue Dec 24, 2024 · 5 comments

Comments

@Araq
Copy link
Member

Araq commented Dec 24, 2024

An accessor is polymorphic if it has the signature proc access(c: Container; ...): var T where Container does not have the var in the signature, if then later the call is used to mutate we have to check that the first parameter of the call access(first, ...) was mutable to begin with.

In the ABI such a parameter would always become var implicitly tough. In other words, it eventually always becomes a pointer,
so that no two versions of the proc need to be generated.

This also allows us to omit "overloading based on var-ness" entirely. (Though for backwards compat we will still need it.)

@SirOlaf
Copy link
Contributor

SirOlaf commented Dec 30, 2024

How would this interact with ref types, access into a different parameter and things like global variables? I assume this isn’t the entire design you have in mind as the description sounds far too trivial to deal with every scenario.

@Araq
Copy link
Member Author

Araq commented Dec 30, 2024

I don't understand your question, [] exists and becomes "polymorphic" but []= exists too and is like before. Also a [] which does not return var T doesn't allow for mutability at all. (This is important for copy-on-write strings.)

@SirOlaf
Copy link
Contributor

SirOlaf commented Dec 30, 2024

Nevermind, tested and it and points to https://nim-lang.github.io/Nim/var_t_return.html

@planetis-m
Copy link

Will this scheme work with copy on write types?

@Araq
Copy link
Member Author

Araq commented Jan 3, 2025

Can't see why not, make the [] not return a var and the []= copy since it's a write.

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

No branches or pull requests

3 participants