savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
154 stars 12 forks source link

BREAKING CHANGE: `IntoString` and `Inspect.into` no longer use `String'iso`. #426

Closed jemc closed 1 year ago

jemc commented 1 year ago

Prior to this change, the IntoString trait and its into_string method implemented to specify a string representation used a String'iso argument and were required to return the String'iso at the end. This used to be necessary to ensure that the final built string could remain isolated, and thus be sendable or made immutable. However, it caused extra burden on the implementation.

Now, that method takes a String'ref as the argument and returns None.

To obtain a String'iso, the caller can use the String.take_buffer method to extract the underlying buffer and lift it to an iso. This does not allocate a new underlying buffer and does not copy the data, so there is no copy cost to pay. The only cost is allocating the throwaway String wrapper object, but this is small (always 4 words) and in many cases can be potentially lifted to a stack allocation at the LLVM level, so there shouldn't be much performance downside to worry about

The builtin implementation of composed string literals (a.k.a. interpolated strings) does this take_buffer lift implicitly, so that such string literals will continue to return as String'iso.

The Inspect.into method (and the corresponding inspect_into method that some types may choose to implement) have been changed in the same way (now using String'ref instead of String'iso), and the same comments above apply to this other case of the same pattern shift.