Skip to main content

ImportRegistry

Struct ImportRegistry 

Source
pub struct ImportRegistry {
    pub config_imports: HashMap<String, String>,
    /* private fields */
}
Expand description

Unified import registry. Built during IR lowering, used throughout expansion.

All insertions are idempotent — duplicates are impossible by design. The registry has three sections:

  1. Source imports — pre-populated from the user’s AST during lowering. Read-only after creation.
  2. Config imports — from macroforge.config.ts import statements. Name → module.
  3. Generated imports — accumulated during macro expansion via request_* methods.

Fields§

§config_imports: HashMap<String, String>

Config file imports (macroforge.config.ts import statements). Name → module.

Implementations§

Source§

impl ImportRegistry

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn from_module(module: &Module, source: &str) -> Self

Build from AST — extracts all import declarations from the module. Called during IR lowering in prepare_expansion_context.

Source

pub fn is_available(&self, name: &str) -> bool

Check if an identifier is available (in source OR already generated).

Source

pub fn is_type_only(&self, name: &str) -> bool

Check if a source import is type-only. Returns false if the import is not found.

Source

pub fn get_source(&self, name: &str) -> Option<&str>

Get import module for a source import.

Source

pub fn resolve_alias(&self, name: &str) -> Option<&str>

Resolve alias to original name. For import { Option as EffectOption }, resolve_alias("EffectOption")Some("Option").

Source

pub fn source_map(&self) -> &HashMap<String, SourceImport>

Get all source imports as a reference to the internal HashMap.

Source

pub fn source_modules(&self) -> HashMap<String, String>

Get source imports as a flat name→module HashMap (for backward-compat callers).

Source

pub fn aliases(&self) -> HashMap<String, String>

Get import aliases as a flat local→original HashMap (for backward-compat callers).

Source

pub fn source_import_entries(&self) -> Vec<SourceImportEntry>

Export source imports as serializable entries for cross-process transfer.

Source

pub fn install_source_imports(&mut self, entries: Vec<SourceImportEntry>)

Install source imports from serializable entries (for external macro processes).

Source

pub fn type_only_map(&self) -> HashMap<String, bool>

Get type-only tracking as a flat name→bool HashMap (for backward-compat callers).

Source

pub fn request_import( &mut self, local_name: &str, original_name: Option<&str>, module: &str, is_type_only: bool, )

General-purpose import request. Idempotent — skips if local_name already exists in source or generated imports.

This is the method TsStream import helpers delegate to.

Source

pub fn request_namespace_import( &mut self, namespace: &str, module: &str, alias: &str, )

Request a namespace import (e.g., import { DateTime as __mf_DateTime } from "effect").

No-op if namespace is already a value import in source. No-op if alias is already in generated.

Source

pub fn request_type_import(&mut self, name: &str, module: &str)

Request a type-only import (e.g., import type { Utc } from "effect/DateTime").

No-op if name is already in source or generated. Rejects dotted names (logs warning, returns early).

Source

pub fn generated_imports(&self) -> impl Iterator<Item = &GeneratedImport>

Get an iterator over generated imports.

Source

pub fn take_generated_imports(&mut self) -> Vec<GeneratedImport>

Take a snapshot of generated imports and clear them from the registry. Used by TsStream::into_result() to capture imports into MacroResult so they survive serialization across process boundaries.

Source

pub fn merge_imports(&mut self, imports: Vec<GeneratedImport>)

Merge a list of generated imports back into the registry. Used to restore imports from a MacroResult (e.g., from an external macro).

Source

pub fn emit_generated_imports(&self) -> String

Format all generated imports as TypeScript import lines.

Trait Implementations§

Source§

impl Clone for ImportRegistry

Source§

fn clone(&self) -> ImportRegistry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImportRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ImportRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ImportRegistry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ImportRegistry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> ImplicitClone for T
where T: Clone,

Source§

fn clone_quote_var(&self) -> Self

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Send for T
where T: ?Sized,

Source§

impl<T> Sync for T
where T: ?Sized,