Skip to main content

Module linear

Module linear 

Source
Expand description

Linear type system for resource management in TensorLogic.

This module implements linear types (also known as affine types), where values must be used exactly once. This is crucial for:

  • Memory management: Ensuring tensors are properly deallocated
  • In-place operations: Tracking when tensors can be mutated safely
  • Resource tracking: Managing GPU memory, file handles, etc.
  • Side effect control: Ensuring operations execute in the correct order

§Examples

use tensorlogic_ir::linear::{LinearType, Multiplicity, LinearContext};

// Linear type: must be used exactly once
let tensor_handle = LinearType::linear("TensorHandle");

// Unrestricted type: can be used multiple times
let int_type = LinearType::unrestricted("Int");

// Check multiplicity constraints
let mut ctx = LinearContext::new();
ctx.bind("x", tensor_handle);
assert!(ctx.is_linear("x"));

§Multiplicity System

  • Linear (1): Must be used exactly once
  • Affine (0..1): Must be used at most once
  • Relevant (1..): Must be used at least once
  • Unrestricted (0..): Can be used any number of times

Structs§

LinearContext
Linear typing context for tracking variable usage.
LinearResource
Linear resource with capabilities.
LinearType
Linear type: type with multiplicity constraints.
LinearityChecker
Linearity checker for expressions.
Usage
Usage tracking for linear variables.

Enums§

Capability
Capability: describes what operations are allowed on a linear resource.
Multiplicity
Multiplicity: how many times a value can be used.