mjdi docsv0.10.0latest
mjdi Known Limitations
This document describes behavior that the current Mojo compiler (1.2.0)
Source: mjdi/docs/known-limitations.md
This document describes behavior that the current Mojo compiler (1.2.0)
cannot express, what mjdi does instead, and every significant deviation from
the conceptual API in the product requirements. Items are verified against
mojo 1.2.0 (2016d0cd); see docs/technical-investigation.md for the
experiments backing each claim.
1. API deviations from the PRD's conceptual examples
-
Container[type_of(app_registry)]instead ofContainer[app_registry]. The registry is a compile-time value; a type parameter cannot bind a value directly, andtype_ofis the compiler-supported spelling for turning the value into its type. (Registry().register[T]()chaining is unchanged.) -
self.dep.value()instead ofself.dep.value. Mojo 1.2.0 has no@propertysupport (verified: "use of unknown declaration 'property'"), so the accessor is a method. The PRD accepts.value-style access for the initial release; the difference is one pair of parentheses. -
Injectable services must be default-constructible. Two-phase construction (
T()then reflective field population) requires it. Types that cannot be default-constructed use value/factory providers or acreateoverride. Arbitrary-argument reflective construction is not expressible in safe Mojo 1.2.0 (findings 19–22: tuple-splat into fixed- arity callees, pack concatenation,T.__init__as a function value, andfield_refon uninitializedoutparameters are all rejected). -
register_value[T]()takes no value. A compile-time registry cannot store runtime values; the value is supplied per container viacontainer.set_value[T](/docs/0.10.0/v). The PRD anticipated exactly this split (section 6.6). -
Factories default to transient; cached scopes are explicit. By default, factory providers (and their third-party spelling
use_provider) run per resolution. Since 0.4.0 an explicit scope parameter enables cached products:register_factory[T, make_t, provider_scope.singleton]()constructs once per container and hands out copies (requiresTto beCopyable, checked at registration);scopedcaches per scope and must be resolved through aScope.
2. Lifetime model under value semantics
- Singleton and scoped providers require
Copyable, and consumers receive copies of the canonical instance. Mojo's ownership rules make handing out a second reference to one owned instance impossible; the container caches one construction and copies it per resolution. Services withInjectfields that need singleton/scoped lifetimes must declareCopyable(with__init__(out self, *, copy: Self)), and their dependencies must be Copyable too —Inject[T].cloned()is provided for exactly this. - Singletons resolved through a scope are cached in that scope (not in the parent container). A scope owns its own registry-chain instance and cannot reference the parent's state safely; true container-level sharing would require reference semantics the compiler does not expose. Transient and scoped behaviors are unaffected.
- Lifecycle hooks are explicit-release, not destructor-based. Mojo
synthesizes destructors from field types, and mjdi deliberately does not
hook struct teardown (dropping a container or scope releases cached
instances through ordinary deinitialization, with no callback). Instead,
services that opt in via the
InjectableLifecycletrait receivepost_constructafter wiring andpre_destructwhen the application calls the explicit release paths —Scope.close_scope()andContainer.close(). This keeps release points auditable in application code and avoids relying on compiler teardown semantics; see Lifecycle hooks.
3. Compiler quirks that shaped mjdi (all verified)
These are behaviors of Mojo 1.2.0 that mjdi works around; they may change in later compilers, so the library isolates each workaround:
comptime ifconditions that reference the enclosing generic struct'sSelf, or type equality inside functions with multiple type parameters, can mis-evaluate (verified:comptime if U == Valueis false whilereflect[U].name()reportsValue). mjdi therefore:- routes cross-node checks through free-function helpers taking the chain
type as an explicit parameter (
chain_provides,chain_validate, ...), - performs duplicate and alias validation inside the container-construction
walk, where descriptors reference their own concrete
Self.T, - uses
comptime assert(reliable) instead ofcomptime ifwhere only a verdict is needed.
- routes cross-node checks through free-function helpers taking the chain
type as an explicit parameter (
- Runtime trait-instance dispatch is reliable even where comptime
dispatch is not, which is why the scoped-context check
(
ProviderContext.accepts_scoped) is an instance method answered at runtime. - Type equality is avoided entirely in hot paths. Dependency-type
extraction from
Inject[D]fields is done by the marker trait (the wrapper knows its ownT), never by unwrappingOptional/Variantstorage or comparing types.
4. Detection boundaries
- Struct-level circular dependencies are rejected by the Mojo compiler
itself at type-definition time (recursive struct definitions through
Injectfields cannot be laid out: "attempt to resolve a recursive reference"). mjdi's cycle walk (find_cycle_path) remains as defense in depth for graphs that become expressible through future indirection features; struct cycles in user code cannot reach it today. - Alias cycles are impossible by construction: aliases bind to class
providers only, so an alias chain has length one. Registration and
validation reject any other target. A depth-limited chain walk
(
chain_alias_path, budget 32) remains as defense in depth. - Factory-mediated cycles (a factory resolving a service that resolves the factory product) cannot be detected statically — factories are opaque at compile time — and will recurse at runtime. This is documented behavior, consistent with the PRD's runtime-validation fallback.
5. Ergonomics
resolveaccepts any registered type; class-provided types must conform toInjectable(checked at resolution with a clear diagnostic).- Singletons and scoped services hand out copies: observable state must live behind explicitly shared state (e.g., a value provider holding a shared handle), not in the service's own fields.
mojo testdoes not exist in Mojo 1.2.0; the test suite is a set of standalone programs driven byscripts/run_tests.sh.- Mojo 1.2.0 has no coverage instrumentation;
scripts/coverage_report.pymeasures API-surface coverage statically (gate: 95%; current: 100%).
6. Linear services (added in 0.6.0)
The linear-service feature works within these boundaries, each a direct consequence of the Mojo linear-type contract (see Linear services):
- Borrow-only visitors.
container.resolve[T](/docs/0.10.0/visitor)(the linear overload ofresolve) passes the service by immutable borrow to a thin (capture-free) visitor. The visitor cannot store, return, or transfer the service — that is the linear contract, not a library restriction. - Error-path destruction is explicit, not implicit. If the visitor
raises,
resolvedestroys the linear instance before re-raising (there is no implicitfinallypath for a linear type — mjdi callsdestroyin theexceptarm; pinned by the linear-resources tests). - Regular paths are closed by the compiler, not by mjdi diagnostics.
register,register_value,register_factory,register_alias,resolve[T], andInject[T]fields are bounded byMovable & Deinitable, and the class-provider/value-returning-resolve overloads carryMovable & Deinitablebounds; attempting them with a linear type produces the compiler's bound/conformance error before any mjdi message. Documented in Diagnostics → entry 24. - Annotation reflection surface. The
@__annotation/annotations()(comptime tuple) surface is verified byexperiments/exp7_annotations.mojo(matrix rows 30–33); if a future compiler changes the surface,mjdi/annotations.mojois the only module to adjust. - Movable-bound introspection.
scope_of[T]/kind_of[T]/provides[T]cannot be called with a linear type; useprovides_any[T]. - Third-party linear types cannot be registered: the contract requires annotating and conforming the struct, which only the type's owner can do. Wrap foreign resources in a linear service you control.
7. v0.8.0 additions (P1 enhancements)
- Tracing is a pull model. The lifecycle trace is a bounded in-memory log read by application/test code; a push-model callback/observer interface is not provided — the supported compiler cannot store capturing closures or stateful function values in comptime-parameterized containers safely. Documented in Lifecycle tracing.
- Per-provider cache statistics are not represented. Statistics are per-owner (container or scope); per-provider counters would require per-descriptor runtime state in every registry chain node, which the compiler cannot express. The per-service facts are observable through the trace (events carry service names). Documented in Cache statistics.
- Cross-container factory recursion is undetectable. Thin factory functions cannot capture the resolving container, so a factory cannot participate in a same-container cycle (which the P1-20 guard detects); a factory that constructs its own container whose resolution re-enters that factory recurses across containers, which would require mutable global state to detect — forbidden by design. Documented in Re-entrancy.
- Containers and scopes are single-threaded. The supported compiler ships no threading primitives, so no synchronization exists or is claimed; see Concurrency.
- Observability carries a small memory footprint when disabled. The trace log, statistics, and guard fields exist in every specialization (their code is comptime-gated away); the disabled container pays bytes, not operations. See Performance.
- Graph export does not validate. By design (P1-01): invalid graphs export with problems marked so tooling can display them before the composition root compiles. Documented in Graph export.
- The re-entrancy guard's cost is on by default. Measured ~7 ns per guarded resolution plus one reserved flag-list allocation per guarded container/scope construction — the accepted architectural justification for P1-20, with the one-parameter opt-out. See Performance.
8. v0.9.0 additions (P0 hardening) — the documented limits
- Destructor diagnostics are print-only (P0-03): the MJDI-D001/D002
unclosed-resource diagnostics run in
__deinit__, where Mojo cannot raise, cannot return a value, and cannot write into a surviving structure (verified byexperiments/exp10_deinit_diagnostics.mojo). They print to stdout at the owner's drop point and are verified by a golden-output check, not in-process assertions. There is no push-model callback for the same reason lifecycle tracing has none: the supported compiler cannot store capturing closures in the comptime-parameterized containers. - Destruction happens at last use: Mojo ends a value's lifetime at its last use, so an unclosed tracked container's diagnostic fires at that point, not at the end of the enclosing block. This is deterministic for a deterministic program and is documented in lifecycle safety diagnostics.
- No behavioral/branch coverage metric (P0-07): the compiler has no coverage instrumentation; the API-surface coverage gates are the only automatable coverage measure, and the inventory says so explicitly instead of faking a percentage.
- Emulated-platform evidence is not release evidence (P0-02): the release environment has no qemu-user binary, and even where emulation runs it cannot validate codegen-level behavior; the aarch64 tier stays ci-verified until a real-hardware run is recorded.
- Compiler diagnostics remain unstructured (P0-06): there is no stable compiler diagnostic channel, so the mjdi ID contract lives in the message text, with the limitations (ID at the end of the message, compiler notes around it, first-assert-wins reporting) documented in the validation output contract.