View Source cure_pipe_optimizer (cure v0.7.0)
Optimizations specifically for pipe operator chains.
This module provides compile-time optimizations for pipe operator usage, focusing on eliminating redundant wrapping/unwrapping and inlining simple pipe chains when type information proves they cannot fail.
Summary
Functions
Check if a pipe chain can be inlined to direct function calls.
Determine if a pipe chain is provably error-free.
Statistics about pipe operator optimizations applied.
Optimize a pipe operator chain based on type information.
Functions
Check if a pipe chain can be inlined to direct function calls.
A pipe chain can be inlined if:
- All functions in the chain are pure (no side effects)
- Type information proves no errors can occur
- The chain is short enough (to avoid code bloat)
Arguments
PipeChain- Pipe operator chain expressionTypeEnv- Type environment for analysis
Returns
true- Can be inlinedfalse- Should keep monadic pipe
Determine if a pipe chain is provably error-free.
A pipe chain is error-free if type analysis proves that:
- No function in the chain can return Error
- All type constraints are satisfied
- No runtime exceptions can occur
Arguments
PipeChain- Pipe operator chain expressionTypeEnv- Type environment for type checking
Returns
true- Provably error-freefalse- May produce errors
Statistics about pipe operator optimizations applied.
Optimize a pipe operator chain based on type information.
This function analyzes a pipe chain and applies optimizations:
- Eliminate redundant Ok wrapping/unwrapping
- Inline error-free chains to direct function calls
- Specialize monomorphic pipe operations
Arguments
PipeExpr- Binary operation expression with '|>' operatorTypeEnv- Type environment for type inference
Returns
{ok, OptimizedExpr, Stats}- Optimized expression with statistics{unchanged, PipeExpr, Stats}- No optimization applied with statistics