l0_backend_lifetime.py
Module: l0_backend_lifetime
Source: compiler/stage1_py/l0_backend_lifetime.py Language: Python
Symbols
Namespace l0_backend_lifetime
Class l0_backend_lifetime::ValueLifetime
ARC materialization, value retention/cleanup, and drop operations.
Member Data l0_backend_lifetime.ValueLifetime.convert
1
OwnershipConversion convert
Member Data l0_backend_lifetime.ValueLifetime.state
1
BackendState state
Function l0_backend_lifetime.ValueLifetime._is_unwrap_cast_from_place
1
bool l0_backend_lifetime.ValueLifetime._is_unwrap_cast_from_place(self, Expr expr)
Check if a cast expression still borrows from an existing owner.
Outer parentheses are ownership-transparent. Owner-producing ARC value-optional wraps are excluded.
Parameters:
expr: The expression to check.
Returns: True for non-owner-producing casts whose source is a place.
Function l0_backend_lifetime.ValueLifetime._needs_arc_temp
1
bool l0_backend_lifetime.ValueLifetime._needs_arc_temp(self, Expr expr)
Check if a non-place rvalue with ARC data needs temp materialization.
String literals are static constants and don’t need cleanup.
Parameters:
expr: The expression to check.
Returns: True if temp materialization is needed.
Function l0_backend_lifetime.ValueLifetime._should_materialize_arc_temp
1
bool l0_backend_lifetime.ValueLifetime._should_materialize_arc_temp(self, Expr expr, Type expr_type)
Check if an ARC expression should be hoisted to a cleanup temp.
Parameters:
expr: The expression to check.expr_type: The type of the expression.
Returns: True if the expression should be materialized into a temporary.
Function l0_backend_lifetime.ValueLifetime._materialize_arc_temp
1
str l0_backend_lifetime.ValueLifetime._materialize_arc_temp(self, str c_expr, Type expr_type)
Materialize an ARC rvalue into a scope-owned temporary for automatic cleanup.
Parameters:
c_expr: The C expression string.expr_type: The type of the expression.
Returns: The name of the generated temporary variable.
Function l0_backend_lifetime.ValueLifetime._emit_cleanup_at_scope_exit
1
None l0_backend_lifetime.ValueLifetime._emit_cleanup_at_scope_exit(self, ScopeContext scope)
Emit cleanup at scope exit.
Only cleans variables declared in THIS scope that have owned fields.
Parameters:
1
None l0_backend_lifetime.ValueLifetime._emit_value_cleanup(self, str c_expr, Type ty)
Emit cleanup code for a by-value variable before reassignment.
Similar to _emit_field_cleanup, but expects c_expr to be a direct value reference (not a pointer), so uses ‘.’ instead of ‘->’.
Parameters:
c_expr: C expression for the value (e.g., “x__v”, “obj.field”)ty: The type of the value being cleaned upFunction
l0_backend_lifetime.ValueLifetime._emit_struct_cleanup
1
None l0_backend_lifetime.ValueLifetime._emit_struct_cleanup(self, str c_ptr_expr, StructType struct_type)
Emit cleanup code for all owned fields in a struct.
Recursively handles nested structs (by-value fields).
Parameters:
c_ptr_expr: C expression evaluating to a pointer to the struct.struct_type: The struct type.Function
l0_backend_lifetime.ValueLifetime._emit_enum_cleanup
1
None l0_backend_lifetime.ValueLifetime._emit_enum_cleanup(self, str c_ptr_expr, EnumType enum_type)
Emit cleanup code for owned fields in an enum’s active variant.
Uses switch on tag to only clean up the fields that are actually present.
Parameters:
c_ptr_expr: C expression evaluating to a pointer to the enum.enum_type: The enum type.Function
l0_backend_lifetime.ValueLifetime._emit_retain_for_copied_value
1
None l0_backend_lifetime.ValueLifetime._emit_retain_for_copied_value(self, str c_expr, Type ty)
Emit retain operations for a copied owned value.
Used when copying from place expressions so source and destination own independent references.
Parameters:
c_expr: C expression evaluating to the value.ty: The type of the value.Function
l0_backend_lifetime.ValueLifetime._emit_copy_expr_with_retains
1
str l0_backend_lifetime.ValueLifetime._emit_copy_expr_with_retains(self, str c_expr, Type ty)
Materialize copied values in a temp and emit retain logic when needed.
Parameters:
c_expr: C expression evaluating to the value.ty: The type of the value.
Returns: The name of the temporary containing the copied and retained value.
Function l0_backend_lifetime.ValueLifetime._emit_drop
1
None l0_backend_lifetime.ValueLifetime._emit_drop(self, DropStmt stmt, str module_name)
Emit drop statement with automatic cleanup of owned fields.
For structs: releases all string fields. For enums: switches on tag, releases strings in active variant. Then calls the drop-finish helper to release the memory.
Parameters:
stmt: The DropStmt AST node.module_name: Name of current module.