pub struct SemaContext<'a> {Show 20 fields
pub rir: &'a Rir,
pub interner: &'a ThreadedRodeo,
pub structs: HashMap<Spur, StructId>,
pub enums: HashMap<Spur, EnumId>,
pub functions: &'a HashMap<Spur, FunctionInfo>,
pub methods: &'a HashMap<(StructId, Spur), MethodInfo>,
pub preview_features: PreviewFeatures,
pub builtin_string_id: Option<StructId>,
pub builtin_arch_id: Option<EnumId>,
pub builtin_os_id: Option<EnumId>,
pub builtin_typekind_id: Option<EnumId>,
pub target: Target,
pub inference_ctx: InferenceContext,
pub known: KnownSymbols,
pub type_pool: TypeInternPool,
pub module_registry: ModuleRegistry,
pub source_file_path: Option<String>,
pub file_paths: HashMap<FileId, String>,
pub param_arena: &'a ParamArena,
pub constants: &'a HashMap<Spur, ConstInfo>,
}Expand description
Context for semantic analysis, designed for parallel function analysis.
This struct contains all type information and declarations needed during
function body analysis. It is designed to be Send + Sync so it can be
shared across threads during parallel function analysis.
§Contents
- Struct and enum definitions (immutable)
- Function and method signatures (references to immutable data in Sema)
- Type intern pool (thread-safe, allows concurrent array interning)
- Pre-computed inference context (immutable)
- Built-in type IDs (immutable)
- Parameter arena for function/method parameter data (immutable after declaration gathering)
§Thread Safety
SemaContext is Send + Sync because:
- Most fields are immutable after construction
- The type intern pool uses
RwLockfor thread-safe mutations - References to RIR and interner are shared immutably
- References to functions/methods HashMaps are immutable after declaration gathering
- Reference to param_arena is immutable after declaration gathering
- ThreadedRodeo is designed to be thread-safe
Fields§
§rir: &'a RirReference to the RIR being analyzed.
interner: &'a ThreadedRodeoReference to the string interner.
structs: HashMap<Spur, StructId>Struct lookup: maps struct name symbol to StructId.
enums: HashMap<Spur, EnumId>Enum lookup: maps enum name symbol to EnumId.
functions: &'a HashMap<Spur, FunctionInfo>Function lookup: reference to Sema’s function map (immutable after declaration gathering).
methods: &'a HashMap<(StructId, Spur), MethodInfo>Method lookup: reference to Sema’s method map (immutable after declaration gathering). Uses (StructId, method_name) key to support anonymous struct methods.
preview_features: PreviewFeaturesEnabled preview features.
builtin_string_id: Option<StructId>StructId of the synthetic String type.
builtin_arch_id: Option<EnumId>EnumId of the synthetic Arch enum (for @target_arch intrinsic).
builtin_os_id: Option<EnumId>EnumId of the synthetic Os enum (for @target_os intrinsic).
builtin_typekind_id: Option<EnumId>EnumId of the synthetic TypeKind enum (for @typeInfo intrinsic).
target: TargetCompilation target (architecture + OS).
inference_ctx: InferenceContextPre-computed inference context for HM type inference.
known: KnownSymbolsPre-interned known symbols for fast comparison.
type_pool: TypeInternPoolType intern pool for unified type representation (ADR-0024 Phase 1).
During Phase 1, the pool coexists with the existing type registries.
It can be used for lookups but the canonical type representation
remains the old Type enum. Later phases will migrate to using
the pool exclusively.
module_registry: ModuleRegistryThread-safe module registry. Supports concurrent lookups and insertions during parallel analysis.
source_file_path: Option<String>Path to the current source file being compiled (single-file mode). Used for resolving relative imports when only one file is compiled.
file_paths: HashMap<FileId, String>Maps FileId to source file paths (multi-file mode). Used for resolving relative imports when multiple files are compiled.
param_arena: &'a ParamArenaReference to the parameter arena for accessing function/method parameter data.
Use param_arena.types(fn_info.params) to get parameter types, etc.
constants: &'a HashMap<Spur, ConstInfo>Constant lookup: reference to Sema’s constant map (immutable after declaration gathering).
Used for looking up const declarations like const x = @import("...").
Implementations§
Source§impl<'a> SemaContext<'a>
impl<'a> SemaContext<'a>
Sourcepub fn builtin_string_type(&self) -> Type
pub fn builtin_string_type(&self) -> Type
Get the builtin String type as a Type::Struct.
Sourcepub fn get_struct(&self, name: Spur) -> Option<StructId>
pub fn get_struct(&self, name: Spur) -> Option<StructId>
Look up a struct by name.
Sourcepub fn get_struct_def(&self, id: StructId) -> StructDef
pub fn get_struct_def(&self, id: StructId) -> StructDef
Get a struct definition by ID.
Sourcepub fn get_enum_def(&self, id: EnumId) -> EnumDef
pub fn get_enum_def(&self, id: EnumId) -> EnumDef
Get an enum definition by ID.
Sourcepub fn get_function(&self, name: Spur) -> Option<&FunctionInfo>
pub fn get_function(&self, name: Spur) -> Option<&FunctionInfo>
Look up a function by name.
Sourcepub fn get_method(
&self,
struct_id: StructId,
method_name: Spur,
) -> Option<&MethodInfo>
pub fn get_method( &self, struct_id: StructId, method_name: Spur, ) -> Option<&MethodInfo>
Look up a method by struct ID and method name.
Sourcepub fn get_constant(&self, name: Spur) -> Option<&ConstInfo>
pub fn get_constant(&self, name: Spur) -> Option<&ConstInfo>
Look up a constant by name.
Sourcepub fn get_array_type_def(&self, id: ArrayTypeId) -> (Type, u64)
pub fn get_array_type_def(&self, id: ArrayTypeId) -> (Type, u64)
Get an array type definition by ID.
Returns (element_type, length) for the array.
Sourcepub fn get_array_type(
&self,
element_type: Type,
length: u64,
) -> Option<ArrayTypeId>
pub fn get_array_type( &self, element_type: Type, length: u64, ) -> Option<ArrayTypeId>
Look up an array type by element type and length.
Sourcepub fn get_or_create_array_type(
&self,
element_type: Type,
length: u64,
) -> ArrayTypeId
pub fn get_or_create_array_type( &self, element_type: Type, length: u64, ) -> ArrayTypeId
Get or create an array type. Thread-safe.
Sourcepub fn get_or_create_ptr_const_type(&self, pointee_type: Type) -> PtrConstTypeId
pub fn get_or_create_ptr_const_type(&self, pointee_type: Type) -> PtrConstTypeId
Get or create a ptr const type. Thread-safe.
Sourcepub fn get_or_create_ptr_mut_type(&self, pointee_type: Type) -> PtrMutTypeId
pub fn get_or_create_ptr_mut_type(&self, pointee_type: Type) -> PtrMutTypeId
Get or create a ptr mut type. Thread-safe.
Sourcepub fn get_module(&self, import_path: &str) -> Option<ModuleId>
pub fn get_module(&self, import_path: &str) -> Option<ModuleId>
Look up a module by import path.
Sourcepub fn get_module_def(&self, id: ModuleId) -> ModuleDef
pub fn get_module_def(&self, id: ModuleId) -> ModuleDef
Get a module definition by ID.
Sourcepub fn get_or_create_module(
&self,
import_path: String,
file_path: String,
) -> (ModuleId, bool)
pub fn get_or_create_module( &self, import_path: String, file_path: String, ) -> (ModuleId, bool)
Get or create a module for the given import path and file path. Thread-safe.
Returns the ModuleId and whether it was newly created.
Sourcepub fn update_module_def(&self, id: ModuleId, def: ModuleDef)
pub fn update_module_def(&self, id: ModuleId, def: ModuleDef)
Update a module definition with populated declarations.
Sourcepub fn get_source_path(&self, span: Span) -> Option<&str>
pub fn get_source_path(&self, span: Span) -> Option<&str>
Get the source file path for a span.
Looks up the file path using the span’s file_id. Falls back to
source_file_path for single-file compilation mode.
Sourcepub fn get_file_path(&self, file_id: FileId) -> Option<&str>
pub fn get_file_path(&self, file_id: FileId) -> Option<&str>
Get the file path for a given FileId.
Sourcepub fn is_accessible(
&self,
accessing_file_id: FileId,
target_file_id: FileId,
is_pub: bool,
) -> bool
pub fn is_accessible( &self, accessing_file_id: FileId, target_file_id: FileId, is_pub: bool, ) -> bool
Check if the accessing file can see a private item from the target file.
Visibility rules (per ADR-0026):
pubitems are always accessible- Private items are accessible if the files are in the same directory module
Directory module membership includes:
- Files directly in the directory (e.g.,
utils/strings.gruelis inutils) - Facade files for the directory (e.g.,
_utils.gruelis inutilsmodule)
Returns true if the item is accessible.
Sourcepub fn format_type_name(&self, ty: Type) -> String
pub fn format_type_name(&self, ty: Type) -> String
Get a human-readable name for a type.
Sourcepub fn is_type_copy(&self, ty: Type) -> bool
pub fn is_type_copy(&self, ty: Type) -> bool
Check if a type is a Copy type.
Sourcepub fn abi_slot_count(&self, ty: Type) -> u32
pub fn abi_slot_count(&self, ty: Type) -> u32
Get the number of ABI slots required for a type.
Sourcepub fn field_slot_offset(&self, struct_id: StructId, field_index: usize) -> u32
pub fn field_slot_offset(&self, struct_id: StructId, field_index: usize) -> u32
Get the slot offset of a field within a struct.
Sourcepub fn type_to_infer_type(&self, ty: Type) -> InferType
pub fn type_to_infer_type(&self, ty: Type) -> InferType
Convert a concrete Type to InferType for use in constraint generation.
Sourcepub fn is_builtin_string(&self, ty: Type) -> bool
pub fn is_builtin_string(&self, ty: Type) -> bool
Check if a type is the builtin String type.
Sourcepub fn get_builtin_type_def(
&self,
struct_id: StructId,
) -> Option<&'static BuiltinTypeDef>
pub fn get_builtin_type_def( &self, struct_id: StructId, ) -> Option<&'static BuiltinTypeDef>
Get the builtin type definition for a struct if it’s a builtin type.
Sourcepub fn is_builtin_mutation_method(&self, method_name: &str) -> bool
pub fn is_builtin_mutation_method(&self, method_name: &str) -> bool
Check if a method name is a builtin mutation method.
Sourcepub fn builtin_air_type(&self, struct_id: StructId) -> Type
pub fn builtin_air_type(&self, struct_id: StructId) -> Type
Get the AIR output type for a builtin struct.
Sourcepub fn is_type_linear(&self, ty: Type) -> bool
pub fn is_type_linear(&self, ty: Type) -> bool
Check if a type is a linear type.
Sourcepub fn require_preview(
&self,
feature: PreviewFeature,
what: &str,
span: Span,
) -> CompileResult<()>
pub fn require_preview( &self, feature: PreviewFeature, what: &str, span: Span, ) -> CompileResult<()>
Check that a preview feature is enabled.
This is used to gate experimental features behind the --preview flag.
Returns an error with a helpful message if the feature is not enabled.
Sourcepub fn resolve_struct_through_module(
&self,
_module_ref: InstRef,
type_name: Spur,
span: Span,
) -> CompileResult<StructId>
pub fn resolve_struct_through_module( &self, _module_ref: InstRef, type_name: Spur, span: Span, ) -> CompileResult<StructId>
Resolve a struct type through a module reference.
Used for qualified struct literals like module.StructName { ... }.
The module_ref is an InstRef pointing to the result of an @import.
Checks visibility: private structs are only accessible from the same directory.
Sourcepub fn resolve_enum_through_module(
&self,
_module_ref: InstRef,
type_name: Spur,
span: Span,
) -> CompileResult<EnumId>
pub fn resolve_enum_through_module( &self, _module_ref: InstRef, type_name: Spur, span: Span, ) -> CompileResult<EnumId>
Resolve an enum type through a module reference.
Used for qualified enum paths like module.EnumName::Variant.
The module_ref is an InstRef pointing to the result of an @import.
Checks visibility: private enums are only accessible from the same directory.