Skip to main content

TypeResolver

Trait TypeResolver 

Source
pub trait TypeResolver<E> {
    // Required methods
    fn source_manager(&self) -> Arc<dyn SourceManager> ;
    fn resolve_local_failed(&self, err: SymbolResolutionError) -> E;
    fn get_type(
        &mut self,
        context: SourceSpan,
        gid: GlobalItemIndex,
    ) -> Result<Option<TypeTemplate>, E>;
    fn get_local_type(
        &mut self,
        context: SourceSpan,
        id: ItemIndex,
    ) -> Result<Option<TypeTemplate>, E>;
    fn resolve_type_ref(
        &mut self,
        ty: Span<&Path>,
    ) -> Result<SymbolResolution, E>;
    fn finalize(
        &mut self,
        context: SourceSpan,
        template: TypeTemplate,
    ) -> Result<Type, E>;

    // Provided method
    fn resolve(&mut self, ty: &TypeExpr) -> Result<Option<Type>, E> { ... }
}
Expand description

Abstracts over resolving an item to a concrete Type, using one of:

Since type resolution happens in two different contexts during assembly, this abstraction allows us to share more of the resolution logic in both places.

NOTE: Most methods of this trait take a mutable reference to the resolver, so that the resolver can mutate its own state as necessary during resolution (e.g. to manage a cache, or other side table-like data structures).

Required Methods§

Source

fn source_manager(&self) -> Arc<dyn SourceManager>

Source

fn resolve_local_failed(&self, err: SymbolResolutionError) -> E

Should be called by consumers of this resolver to convert a SymbolResolutionError to the error type used by the TypeResolver implementation.

Source

fn get_type( &mut self, context: SourceSpan, gid: GlobalItemIndex, ) -> Result<Option<TypeTemplate>, E>

Resolve the item given by gid to a type template.

This yields a template rather than a Type because a declaration may be part of a recursive group that is still being resolved, in which case the only thing that can be produced for it is a back-reference. Nothing becomes a Type until the whole group is known; see Self::finalize.

Source

fn get_local_type( &mut self, context: SourceSpan, id: ItemIndex, ) -> Result<Option<TypeTemplate>, E>

Resolve the item in the current module given by id to a type template.

Source

fn resolve_type_ref(&mut self, ty: Span<&Path>) -> Result<SymbolResolution, E>

Attempt to resolve a symbol path, given by a TypeExpr::Ref, to an item

Source

fn finalize( &mut self, context: SourceSpan, template: TypeTemplate, ) -> Result<Type, E>

Materialize a template as a concrete Type, building any recursive group it takes part in.

Provided Methods§

Source

fn resolve(&mut self, ty: &TypeExpr) -> Result<Option<Type>, E>

Resolve a TypeExpr to a concrete Type

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§