-
Notifications
You must be signed in to change notification settings - Fork 3
Amt
Important
This page is under development. AMT is Kairo's core memory safety mechanism and its documentation will be comprehensive once the implementation is finalized.
AMT is a compile-time analysis pass that tracks pointer lifetimes, determines ownership, and automatically promotes pointers to the appropriate smart pointer type. It provides memory safety without requiring lifetime annotations from the programmer.
Key concepts that will be covered on this page:
- Full-program analysis model how AMT tracks pointer provenance across function boundaries
- Smart pointer promotion when and how
*Tis promoted tostd::Unique<*T>,std::Shared<*T>, orstd::Weak<*T> - Compile errors vs automatic fixes when AMT can resolve an issue silently and when it must reject the program
- Allocator integration
std::create<T>(),std::alloc<T>(), custom allocators, and how AMT interacts with allocation strategies -
fn op deleteand automatic destructor insertion - Cross-translation-unit analysis via
.ksummaryartifacts - Interaction with unsafe blocks how
unsafe { }suspends AMT and howforget!()drops pointers from tracking - Interaction with C/C++ interop smart pointer mapping between Kairo's
AMT types and C++
std::unique_ptr,std::shared_ptr,std::weak_ptr
See Pointers for pointer types and Ownership for the ownership model that AMT enforces.
fn op delete (self) defines custom destruction. If not defined, compiler generates fn op delete (self) = default. If any member has a deleted destructor, the whole object requires unsafe to use.
Allocator system:
class MyAllocator impl std::Allocator {
fn allocate(self, size: usize) -> *u8
fn deallocate(self, ptr: *u8, size: usize)
}
@set_allocator(MyAllocator)
std::create<T> uses the active allocator. Everything in std that allocates goes through it. delete x[0] calls T's op delete first, then the allocator's deallocation. Considering future granularity: @set_allocator_for(T, MyAllocator), @set_collection_allocator(MyAllocator), etc. undecided.
-
fn op delete (self)custom destruction,= default,= deletebehavior -
std::Allocatorinterface withallocate/deallocate -
@set_allocator(MyAllocator)global allocator override -
delete x[0]explicit deletion callingT'sop deletethen allocator's dealloc -
std::create<T>uses the active allocator - Future granularity:
@set_allocator_for(T, ...),@set_collection_allocator(...)undecided
This wiki mirrors the language reference at kairolang.org/docs. To edit a page, edit the source at kairo-web/src/content/docs/language changes sync automatically.
Start here: Primitives
1. Fundamentals
2. Functions & Control Flow
3. Types
4. Modules & Metaprogramming
5. Memory & Safety
6. Interop & Concurrency