Module function_pointer_safety

Module function_pointer_safety 

Source
Expand description

Function Pointer Safety Analysis

This module implements safety checking for function pointers using type-level encoding with SafeFn<Sig> and UnsafeFn<Sig> wrapper types.

Key concepts:

  • SafeFn<Ret(Args...)> - holds a pointer to a @safe function, can be called safely
  • UnsafeFn<Ret(Args...)> - holds any function pointer, requires @unsafe to call
  • Raw function pointers require @unsafe to call

See docs/FUNCTION_POINTER_SAFETY_PLAN.md for the full design.

Structs§

SafeFnAssignmentCheck
Result of checking a SafeFn assignment

Functions§

check_function_pointer_safety
Check function pointer safety in a parsed function
check_raw_function_pointer_call
Check if a function call expression is through a raw function pointer Returns Some(error) if the call requires @unsafe
is_member_fn_wrapper_type
Check if a type is a member function pointer wrapper (safe or unsafe)
is_raw_function_pointer_type
Check if a type is a raw function pointer Matches patterns like: void ()(int), int ()(const char*, …), void (MyClass::*)(int)
is_raw_member_function_pointer_type
Check if a type is a raw member function pointer Matches patterns like: void (MyClass::)(int), int (Widget::)(double) const
is_safe_fn_call
Check if a function call is calling through a SafeFn or SafeMemFn wrapper
is_safe_fn_type
Check if a type is a SafeFn wrapper type
is_unsafe_fn_call_unsafe_method
Check if a function call is calling through an UnsafeFn or UnsafeMemFn wrapper
is_unsafe_fn_type
Check if a type is an UnsafeFn wrapper type