You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Something the spec hasn't touched is the notion of unsafe code with manual memory management.
I think it would also offer a great starting point for the compiler as an unsafe mode would essentially be a statically compiled subset of TypeScript with manual memory management. It would let us try out the viability of the type system where the concepts of the borrow checker could be applied on top of that.
functionmain(){unsafe{constfoo: string=""// allocate a dynamic string on the heapdeletefoo// delete allocation}}
So as an example, the standard library might include this implementation for an Array
structArrayItem<T>{value: Tnext: ArrayItem<T|null>}classArray<T>{private_items: ArrayItem<T>|nullconstructor(){this._items=null}destructor(){// traverse linked list and delete links}push(item: T){// create or add to linked list}pop(){}shift(){}unshift(){}}
constlist=newArray<string>()// ref to an arrayconsta="a"// ref to a dynamic stringconstb="b"// ref to a dynamic stringlist.push(a)// add ref to arraylist.push(b)// add ref to arraydeletelistdeleteadeleteb
Deleting the Array doesn't delete the items contained in the linked list when unsafe.
When using a borrow checker, the items pushed into the array would have ownership moved to the class. This means the array will be able to clean up all the references it owns - deleting the items and values in the array.
With unsafe, the array cannot know to delete the values - only the links.
This discussion was converted from issue #51 on February 17, 2023 23:06.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Something the spec hasn't touched is the notion of unsafe code with manual memory management.
I think it would also offer a great starting point for the compiler as an unsafe mode would essentially be a statically compiled subset of TypeScript with manual memory management. It would let us try out the viability of the type system where the concepts of the borrow checker could be applied on top of that.
So as an example, the standard library might include this implementation for an Array
Deleting the
Array
doesn't delete the items contained in the linked list whenunsafe
.When using a borrow checker, the items pushed into the array would have ownership moved to the class. This means the array will be able to clean up all the references it owns - deleting the items and values in the array.
With
unsafe
, the array cannot know to delete the values - only the links.Beta Was this translation helpful? Give feedback.
All reactions