//! Shared Radiance language types. /// Ownership and safety class for pointer-like types. export union PointerClass: Copy { /// Owned pointer, eg. `*T`. Owned, /// Reference, borrowed pointer, eg. `&T`. Ref, /// Reference retained by one resolved lexical region. Region(*unsafe Region), /// Unsafe, raw pointer, eg. `*unsafe T`. Unsafe, } /// Source construct that introduces a region identity. export union RegionOrigin: Copy { /// Caller-supplied declaration parameter. Parameter, /// Concrete region delimited by a lexical block. Block, } /// Semantic identity and ancestry of a source region. export record Region: Copy { /// Globally unique AST node ID of the region declaration. id: u32, /// Source construct that supplies the region lifetime. origin: RegionOrigin, /// Source spelling used in diagnostics. name: *[u8], /// Proven enclosing region, if one is declared. parent: ?*unsafe Region, } /// Return whether a pointer class denotes checked borrowed storage. export fn isReference(class: PointerClass) -> bool { match class { case PointerClass::Ref, PointerClass::Region(_) => return true, else => return false, } } /// Return whether a region is equal to, or contains, another region. /// Parent links must form an acyclic graph within one resolver. export unsafe fn regionContains(parent: *unsafe Region, child: *unsafe Region) -> bool { let mut current: ?*unsafe Region = child; while let region = current { if region.id == parent.id { return true; } set current = region.parent; } return false; }