AstModuleLoader class

Lookup-only module resolver for pre-parsed AST bundles.

AstModuleLoader implements ModuleContext to resolve import directives against a pre-loaded map of modules. It performs no file I/O and no source code parsing — all modules must already exist in the bundle.

Module Resolution Order

When loadModule is called with a URI:

  1. Cache — return if already loaded
  2. dart:* — register the corresponding stdlib and return empty module
  3. Bridged libraries — register native bridges and return empty module
  4. Bundle modules — look up in modules, process AST → environment
  5. Error — throw if URI not found anywhere

Usage

Typically created internally by D4rtRunner.executeBundle — not constructed directly in user code.

final loader = AstModuleLoader(
  modules: bundle.modules,
  globalEnvironment: env,
  runner: runner,
);
Implemented types

Constructors

AstModuleLoader({required Map<String, SCompilationUnit> modules, required Environment globalEnvironment, required D4rtRunner runner, Map<String, Environment>? sharedBridgedModuleEnvironments, Environment? sharedModuleEnclosing, void onBridgedModuleEnvBuilt()?})
Creates an AstModuleLoader for resolving imports from a bundle.

Properties

currentLibrary Uri?
The current library URI being executed.
getter/setter pairoverride
globalEnvironment Environment
The global environment shared across all modules.
final
hashCode int
The hash code for this object.
no setterinherited
loadedModuleCount int
Step #3 (retention) — number of bundle modules currently loaded and cached in _moduleCache (each holds an SCompilationUnit AST). Read-only introspection so D4rtRunner can assert prior runs' ASTs are not accumulated. Bridged-module envs (no user AST) are not counted.
no setter
modules Map<String, SCompilationUnit>
Pre-parsed modules from the bundle, keyed by URI string.
final
onBridgedModuleEnvBuilt → void Function()?
Invoked once each time a bridged-module env is actually built (cache miss). Lets the runner expose a debug build counter for the reuse unit test.
final
runner D4rtRunner
The D4rtRunner that owns this loader — used for bridge lookups and permission checks.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sharedBridgedModuleEnvironments Map<String, Environment>?
Optional process-global cache of bridged-module environments keyed by module URI, shared across every execution that has the same allowed-set signature (PERF step #2). When supplied, _tryLoadBridgedModule reuses an already-built module env instead of re-registering the ~982-class flutter bridge surface on every run. null for legacy (empty allowed-set) instances, which keep the per-loader _bridgedModuleEnvironments cache.
final
sharedModuleEnclosing Environment?
Enclosing environment for entries built into sharedBridgedModuleEnvironments. Must be the shared warm parent (not the per-execution global environment), so a cached module env is safe to reuse across executions. null falls back to globalEnvironment.
final

Methods

checkPermission(dynamic operation) bool
Checks if a permission is granted for the given operation.
override
loadModule(Uri uri, {Set<String>? showNames, Set<String>? hideNames}) LoadedModule
Loads a module from the given URI.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
releaseLoadedModules() → void
Step #3 (retention) — drops the per-loader parsed-module cache so a finished run's SCompilationUnit graph becomes collectable. Only the per-loader _moduleCache is cleared; the process-global shared bridge caches (sharedBridgedModuleEnvironments et al.) are untouched. A subsequent execute rebuilds the loader and re-populates the cache.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited