timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

versioned containers (Tables etc) to enable caching #753

Closed timotheecour closed 3 years ago

timotheecour commented 3 years ago

proposal

add a read-only mutations: int field to containers like Tables, StringTableRef, to indicate the number of mutations that occurred in the container, and an accessor proc mutations*(self: Container): int to access it; the field simply gets incremented on each mutation (eg: Table.[]=)

example use case 1:

would simplify things like https://github.com/nim-lang/Nim/pull/18244 => allows caching a value and knowing how long you can hold on to it

example use case 2:

solve https://github.com/nim-lang/Nim/pull/18260 in a robust way, preventing mutating a table during iteration, instead of the following weaker test:

assert(len(t) == L, "the length of the table changed while iterating over it")

example use case 3:

allows user to tell whether a key help by pointer (eg via gePtr (https://github.com/nim-lang/Nim/pull/18253) or mitems.addr) is still valid at some later point

timotheecour commented 3 years ago

=> https://github.com/nim-lang/RFCs/issues/386