diff --git a/content/changelog.mdx b/content/changelog.mdx index 9924808..57a51dd 100644 --- a/content/changelog.mdx +++ b/content/changelog.mdx @@ -11,6 +11,7 @@ releases can be downloaded from [GitHub](https://github.com/burnlang/burn/releas ## Unreleased +- Local variables that only hold a parameter, another variable, or a field or element of one now borrow their value instead of counting a reference, when nothing can free it while they are used ([memory](./language/memory.mdx#what-the-compiler-does)). Loops over arrays of objects and strings and walks over linked structures no longer touch reference counts; the compiler's own code does 8.5% fewer of them and builds faster. - The compiler rejects memory hazards that used to compile, each with a suggested fix ([memory](./language/memory.mdx#what-the-compiler-rejects)): adding to or removing from an array or map inside a `for` loop over it, using an array, map or object while an `async fun` it was given to may still be changing it, and async functions that change globals or read global arrays, maps and objects. ## 26.1.0-experimental-9 diff --git a/content/language/memory.mdx b/content/language/memory.mdx index c1448fa..436361a 100644 --- a/content/language/memory.mdx +++ b/content/language/memory.mdx @@ -34,6 +34,9 @@ lets go, the object is freed, and so are the objects only it owned. The compiler keeps the bookkeeping cheap: - Passing a value to a function costs nothing: the caller keeps owning it, and the function borrows it. +- A local variable that only ever holds a parameter, another variable, or a field or element of one borrows its value + the same way, as long as nothing can free that value while the variable is used. `for p in points`, walking a + linked list with `cur = cur.next` and `var first = items[0]` count nothing. - Returning a local variable hands it to the caller instead of copying. - Numbers, bools and enums are not objects and are never counted. - String literals are part of the program and are never freed.