Document per-stage random streams, namespace ownership, LoadedPack and jar copies

README, DESIGN and CONTRACTS now describe: the per-stage random stream
contract and why java.util.Random; module-prefixed stage ids, module ids
without '/', reserved namespaces and settings/registration namespaces;
info() read once; LoadedPack and ModuleHost as the host entry point; and
loading from temporary jar copies with stale-copy cleanup.
This commit is contained in:
piexel committed 2026-10-05 21:40:37 +02:00
1 parent 333e2f6459
commit 1df8bb3808
3 files changed
+222 -64

No files matched your search

+21 -7
View File
@@ -8,7 +8,10 @@ types that carry them and lists what the Iris adapter still owes.
| Requirement | Contract | | Requirement | Contract |
| --- | --- | | --- | --- |
| Module identity and composition | `IrisModule`, `ModuleInfo` (with optional packages), `StageGraph` | | Module identity and composition | `IrisModule`, `ModuleInfo` (with optional packages), `StageGraph` |
| Module jars in a pack | `META-INF/services/com.volmit.IrisModule`, host `PackModules`, `DiscoveredModule`, `MissingClasses` | | Loading and unloading a pack | host `LoadedPack`, `ModuleHost` |
| Module jars in a pack | `META-INF/services/com.volmit.IrisModule`, host `PackModules` (jar copies), `DiscoveredModule`, `MissingClasses` |
| Namespace ownership | module-prefixed stage ids, `ModuleInfo.ownsStage`, `ModuleHost.reservingNamespaces` |
| Randomness independent of other modules | `StageContext.random()`, host `StageRandom`, invocation seed passed to the runners |
| Module-owned work and ordering | `Stage`, `StageRef`, stage definitions, `requires`/`softAfter`/`softBefore` | | Module-owned work and ordering | `Stage`, `StageRef`, stage definitions, `requires`/`softAfter`/`softBefore` |
| Activation by configuration | `when(settingsType)`, host `ConfiguredSettings` | | Activation by configuration | `when(settingsType)`, host `ConfiguredSettings` |
| Typed results between modules | stage outputs, `StageContext.output` | | Typed results between modules | stage outputs, `StageContext.output` |
@@ -26,7 +29,14 @@ types that carry them and lists what the Iris adapter still owes.
| Typed generation and persistent storage | `mantle` package | | Typed generation and persistent storage | `mantle` package |
Stage bodies hold no invocation state. Everything per placement or chunk travels through the Stage bodies hold no invocation state. Everything per placement or chunk travels through the
context, outputs and accumulators. context, outputs and accumulators. Each stage draws only from its own stream, derived from the
invocation seed and its id, so other modules never change its draws.
A module owns its id (`ns:name`, no `/`) and the stage ids below it (`ns:name/...`). Feature ids and
mantle keys it registers use its namespace; a settings type in `when(...)` uses the namespace of a
module that names it. Pack modules cannot use the namespaces the host reserves.
A pack load works on copies of the module jars, so the originals are never held open.
Modules compile against the API `compileOnly` and never ship it. At runtime they can use the API Modules compile against the API `compileOnly` and never ship it. At runtime they can use the API
(`com.volmit.*`), the host packages the host chooses to expose, the JDK and the classes in their (`com.volmit.*`), the host packages the host chooses to expose, the JDK and the classes in their
@@ -50,19 +60,24 @@ running Iris is the pack publisher's responsibility.
- Build `ConfiguredSettings` per placement and per chunk from decoded pack JSON, with explicit - Build `ConfiguredSettings` per placement and per chunk from decoded pack JSON, with explicit
precedence between dimension, region, biome and placement declarations. precedence between dimension, region, biome and placement declarations.
- Preserve pack field names and defaults, seed derivation, RNG draw order, coordinate - Preserve pack field names and defaults, seed derivation, RNG draw order, coordinate
conventions and iteration order where existing worlds must not change. conventions and iteration order where existing worlds must not change. Per-stage streams do not
reproduce Iris's current shared draws; matching them where worlds must stay the same is adapter
work inside the ported stages.
- Derive one seed per placement (world seed and the placement's stable identity) and per chunk
(world seed and chunk position) and pass it to `PlacementRunner.place` / `ChunkRunner.generate`.
- Prepare the full area a placement or chunk may read or write, including neighbors. Never clip. - Prepare the full area a placement or chunk may read or write, including neighbors. Never clip.
- Make placement edits atomic across blocks, block entities, markers and mantle in generation - Make placement edits atomic across blocks, block entities, markers and mantle in generation
storage. Abort chunk publication when any stage fails. storage. Abort chunk publication when any stage fails.
- Preserve unknown persisted mantle layers or fail explicitly. - Preserve unknown persisted mantle layers or fail explicitly.
- Load each pack's jars with `PackModules`, pass them with the built-in modules to - Build one `ModuleHost` at startup with the built-in modules, exposed packages, reserved JSON
`LoadedModules.load`, and close `PackModules` only after nothing built from it is in use. fields and `reservingNamespaces("iris")`. Load each pack with `LoadedPack.load(packRoot, host)`
and close it only after nothing built from it is in use.
- Route `System.Logger` output (logger `com.volmit.host.PackModules`) to the server log, so the - Route `System.Logger` output (logger `com.volmit.host.PackModules`) to the server log, so the
per-pack module summary and missing-classes warning are visible. per-pack module summary and missing-classes warning are visible.
- Provide the API at runtime from the plugin's class loader, for example by shading it into the - Provide the API at runtime from the plugin's class loader, for example by shading it into the
Iris plugin jar. Pack jars must not ship it. Iris plugin jar. Pack jars must not ship it.
- Pass the packages of built-in modules whose stages packs may require to - Pass the packages of built-in modules whose stages packs may require to
`PackModules.load(packRoot, exposedHostPackages)`. They must be on the loader that defines the `ModuleHost.exposing(...)`. They must be on the loader that defines the
API. Keep them narrow: everything in an exposed package and its subpackages becomes visible to API. Keep them narrow: everything in an exposed package and its subpackages becomes visible to
packs and is part of what packs can break on. Stage output types and settings types that pack packs and is part of what packs can break on. Stage output types and settings types that pack
code uses through those stages must be in exposed packages too. The API is always exposed. code uses through those stages must be in exposed packages too. The API is always exposed.
@@ -71,5 +86,4 @@ running Iris is the pack publisher's responsibility.
## Open ## Open
- Per-stage reach declarations, replacing the removed modifier radii. - Per-stage reach declarations, replacing the removed modifier radii.
- Per-stage RNG streams, so adding a module does not shift other modules' random draws.
- Terrain/biome providers, pack transformations, structure assembly and the runtime family. - Terrain/biome providers, pack transformations, structure assembly and the runtime family.
+122 -31
View File
@@ -1,7 +1,8 @@
# Iris API design # Iris API design
Status: pack module loading, the stage graph, both pipelines' reference executors, settings Status: pack module loading (`LoadedPack`), the stage graph, per-stage random streams, both
catalog, geometry, resources and typed storage contracts exist and are tested without the Iris pipelines' reference executors, settings catalog, geometry, resources and typed storage contracts
exist and are tested without the Iris
engine. Provider and runtime families at the end are design notes, not Java interfaces. engine. Provider and runtime families at the end are design notes, not Java interfaces.
## Model ## Model
@@ -37,6 +38,13 @@ The `IrisModule` implementation is the module's entry point. `info()` returns it
name, version and optional packages; there is no separate descriptor. A pack keeps its modules in name, version and optional packages; there is no separate descriptor. A pack keeps its modules in
`<pack>/modules/*.jar`, one module per jar. `<pack>/modules/*.jar`, one module per jar.
The host loads a pack with `LoadedPack.load(packRoot, host)`. `ModuleHost` is the host's fixed
configuration, built once and the same for every pack: built-in modules, exposed host packages,
reserved JSON fields and reserved namespaces. `LoadedPack` runs `PackModules.load` (below), then
`LoadedModules.load` on the built-ins followed by the pack's modules. If the second step fails it
closes the first before rethrowing, so a failed load leaves no class loader or jar copy behind.
`close()` closes the pack's class loader, then deletes its jar copies.
A jar names its entry class in `META-INF/services/com.volmit.IrisModule`, the provider format of A jar names its entry class in `META-INF/services/com.volmit.IrisModule`, the provider format of
`ServiceLoader`. The host reads that file from the jar itself rather than calling `ServiceLoader`. The host reads that file from the jar itself rather than calling
`ServiceLoader`, which would also return providers of parent class loaders and could not say `ServiceLoader`, which would also return providers of parent class loaders and could not say
@@ -54,29 +62,57 @@ API):
1. Validates the exposed packages. The API's package is always one of them. 1. Validates the exposed packages. The API's package is always one of them.
2. Lists regular files ending in `.jar` in `<pack>/modules`, sorted by file name. A missing 2. Lists regular files ending in `.jar` in `<pack>/modules`, sorted by file name. A missing
directory means no modules. directory means no modules.
3. Reads each jar's entry point file and its class files. Comments (`#`) and blank lines are 3. Copies them into a fresh temporary directory (see "Jar copies"). Every later step reads the
copies; messages name the originals.
4. Reads each jar's entry point file and its class files. Comments (`#`) and blank lines are
ignored; zero or more than one entry class name fails. ignored; zero or more than one entry class name fails.
4. Fails if a jar holds a class of an exposed package, naming the jar and the first such class. 5. Fails if a jar holds a class of an exposed package, naming the jar and the first such class.
5. Fails if a class is in two jars, naming the class and both jars. 6. Fails if a class is in two jars, naming the class and both jars.
6. Resolves every class each class uses (see below). A class that Iris has but hides, a class of a 7. Resolves every class each class uses (see below). A class that Iris has but hides, a class of a
JDK module packs cannot see or of a JDK package packs may not use, or a class missing from an JDK module packs cannot see or of a JDK package packs may not use, or a class missing from an
exposed package fails the load, listing exposed package fails the load, listing
each referencing and referenced class per jar and kind. Classes that nobody has are collected each referencing and referenced class per jar and kind. Classes that nobody has are collected
per jar. Nothing has been defined up to here. per jar. Nothing has been defined up to here.
7. Creates one `URLClassLoader` for all jars of the pack, parent = `ExposedHostClassLoader`. 8. Creates one `URLClassLoader` for all copies, parent = `ExposedHostClassLoader`.
8. Loads each entry class, checks that it implements `IrisModule` and comes from its own jar, 9. Loads each entry class, checks that it implements `IrisModule` and comes from its own jar,
instantiates it with the public no-argument constructor and calls `info()`. instantiates it with the public no-argument constructor and calls `info()`, once.
9. Drops each jar's missing classes that lie in the optional packages its module declares in 10. Drops each jar's missing classes that lie in the optional packages its module declares in
`info()`. `info()`.
10. Logs one INFO summary of the pack's modules, and one WARNING if any missing classes remain. 11. Logs one INFO summary of the pack's modules, and one WARNING if any missing classes remain.
Any failure after step 3 closes the loader, if it exists, and deletes the copies.
One loader per pack, not per jar, because `requires(...)` takes another module's stage constant. One loader per pack, not per jar, because `requires(...)` takes another module's stage constant.
A pack jar that requires a stage of another pack jar must see its classes. Packs stay isolated A pack jar that requires a stage of another pack jar must see its classes. Packs stay isolated
from each other. The cost is a shared class namespace: with two copies of a class, the loader from each other. The cost is a shared class namespace: with two copies of a class, the loader
would silently use the one first in file name order. Step 5 turns that into a load error, so two would silently use the one first in file name order. Step 6 turns that into a load error, so two
jars that shade the same library must relocate it, and shared code belongs in one module that the jars that shade the same library must relocate it, and shared code belongs in one module that the
others require. others require.
### Jar copies
A `URLClassLoader` keeps every jar it reads open until it closes. On Windows an open file cannot be
replaced, so a loaded pack would stop its module author from rebuilding a jar while studio runs.
The load therefore copies the jars first (`JarSnapshot`) and gives the class check and the loader
only the copies. The originals are closed again as soon as they are copied. This also means a load
works on one consistent set of jars: a jar rebuilt during the load affects the next load, not half
of this one.
Copies live in a new directory `iris-pack-modules-*` under `java.io.tmpdir`, named by their
original file name, next to an owner file holding a fixed header and the id of the process that made
it. Origins and messages always use the original path relative to the pack: the copy's path would
mean nothing to the author. When an entry class turns out to come from another jar of the pack, the
message names that jar's origin too.
A process that crashes never closes its packs, so its copies stay. A later load removes such a
directory only when it can show that this code made it and that nobody uses it: the name has the
prefix, the owner file has the header, its process no longer runs
(`ProcessHandle.of(pid)` finds no live process), and the directory holds nothing but the owner file
and `.jar` files. Directories of a process that still runs, including another server sharing the
temporary directory, are left alone; a reused process id can only keep a stale directory, never
remove a live one. A crash between creating the directory and writing the owner file leaves an
empty directory that is never removed, because nothing proves who made it.
The class check reads jars the way the loader does. `module-info.class` is ignored. A The class check reads jars the way the loader does. `module-info.class` is ignored. A
multi-release jar (`Multi-Release: true`) contributes each class once, under its base name, from multi-release jar (`Multi-Release: true`) contributes each class once, under its base name, from
the highest `META-INF/versions/N` that the running JDK selects; a versioned copy of a class in one the highest `META-INF/versions/N` that the running JDK selects; a versioned copy of a class in one
@@ -106,7 +142,7 @@ exports) count as not exported. The supported way to use Unsafe is `sun.misc.Uns
exports that package to every unnamed module, and then modules may use it. exports that package to every unnamed module, and then modules may use it.
The exposed packages (`ExposedPackages`) are the API's package, `com.volmit` (the package of The exposed packages (`ExposedPackages`) are the API's package, `com.volmit` (the package of
`IrisModule`), plus whatever the host passes to `PackModules.load`. The host decides those; the `IrisModule`), plus whatever the host passes to `ModuleHost.exposing` (and so to `PackModules.load`). The host decides those; the
intended use is the packages that hold built-in modules' stage constants, so that a pack jar can intended use is the packages that hold built-in modules' stage constants, so that a pack jar can
`requires(...)` a stage of the core engine or a built-in feature. A pack jar then links against `requires(...)` a stage of the core engine or a built-in feature. A pack jar then links against
the host's class and the same stage constant, which resolution requires: a copy would be a second the host's class and the same stage constant, which resolution requires: a copy would be a second
@@ -125,12 +161,12 @@ and its class file come from the same place, and a pack never sees Iris's own re
The pack loader asks its parent first, so a packaged copy of a host class would be silently The pack loader asks its parent first, so a packaged copy of a host class would be silently
replaced by the host's, and a module class in an exposed package could be replaced by a later host replaced by the host's, and a module class in an exposed package could be replaced by a later host
class of the same name. Step 4 rejects both; exposed packages belong to the host. For the API the class of the same name. Step 5 rejects both; exposed packages belong to the host. For the API the
message points at `compileOnly`, the usual cause. A module class that shares a name with a hidden message points at `compileOnly`, the usual cause. A module class that shares a name with a hidden
Iris internal is harmless, because the pack loader cannot see it. A module class that shares a name Iris internal is harmless, because the pack loader cannot see it. A module class that shares a name
with a JDK class is replaced by the JDK's; that is not checked. with a JDK class is replaced by the JDK's; that is not checked.
Step 6 reads every class file with the JDK's `java.lang.classfile` API. A class uses every class Step 7 reads every class file with the JDK's `java.lang.classfile` API. A class uses every class
in its constant pool (supertypes, and instantiated, cast, caught, called-on and class-literal in its constant pool (supertypes, and instantiated, cast, caught, called-on and class-literal
types) and every type in the descriptors of its own fields and methods and of the members and types) and every type in the descriptors of its own fields and methods and of the members and
call sites it uses. Arrays count as their element type; primitives do not count. Annotations and call sites it uses. Arrays count as their element type; primitives do not count. Annotations and
@@ -186,7 +222,7 @@ load reports as a broken entry point of the jar.
The declaration lives in the entry point because all module metadata does. That fixes its timing: The declaration lives in the entry point because all module metadata does. That fixes its timing:
`info()` exists only once the entry class is defined, after the reference check. This is safe `info()` exists only once the entry class is defined, after the reference check. This is safe
because the declaration only removes warnings. Every load error is decided in step 6, without it, because the declaration only removes warnings. Every load error is decided in step 7, without it,
so a declared package can never turn a hidden Iris class, an unavailable or non-exported JDK class so a declared package can never turn a hidden Iris class, an unavailable or non-exported JDK class
or a class missing from an exposed package into a pass. `missingClasses()` drops the excused classes instead or a class missing from an exposed package into a pass. `missingClasses()` drops the excused classes instead
of flagging them: it then says exactly what the warning says, and a class the author declared of flagging them: it then says exactly what the warning says, and a class the author declared
@@ -203,12 +239,33 @@ against an API whose methods have changed fails with a linkage error, which `Loa
reports with the module's jar when it happens during install, and which surfaces at generation reports with the module's jar when it happens during install, and which surfaces at generation
time when it happens only in a stage body. time when it happens only in a stage body.
Closing `PackModules` closes the loader. Classes loaded before that keep working, so the host Closing `PackModules` closes the loader and then deletes the copies. Classes loaded before that
must drop `LoadedModules` and everything else built from the pack first. keep working, so the host must drop everything built from the pack first.
Each module reaches `LoadedModules.load` as a `DiscoveredModule`: the module and its origin, the Each module reaches `LoadedModules.load` as a `DiscoveredModule`: the module, its `ModuleInfo` and
jar path relative to the pack or "host classpath" for built-ins. Duplicate module ids and foreign its origin, the jar path relative to the pack or "host classpath" for built-ins. `info()` is called
stage namespaces name the origin. Every jar error names the jar. exactly once, when the module is discovered (`DiscoveredModule.builtIn`, or step 9 for a jar), and
everything afterwards uses the stored value, so a module whose `info()` changes between calls cannot
give the host two answers. Errors about a module name its origin. Every jar error names the jar.
### Namespaces
A module owns its id: `ns:name`, with no `/` in the name. It may define only stages whose ids start
with its id and `/` (`iris:stilt/fill`), so no module can define stages under another module's
path, and a stage id names exactly one possible owner. A `/` in a module id would let `iris:stilt/x`
define stages under `iris:stilt`, so `ModuleInfo` rejects it.
Feature ids of geometry generators and mantle keys a module registers must use its namespace.
A settings type named in `when(...)` must have a feature id in the namespace of at least one module
that names it: its owner. Other modules may name it too, to run only where that setting is
configured. Checking against the module that names it alone would forbid that; checking nothing
would let any module claim a settings id in another namespace.
The host reserves namespaces for its own modules (`ModuleHost.reservingNamespaces("iris")`). A
module from a pack jar whose id uses a reserved namespace fails the load, naming the jar and the
namespace. Its stages, settings ids and mantle keys follow its namespace, so this one check keeps
pack modules out of reserved namespaces everywhere. Built-in modules, discovered with
`DiscoveredModule.builtIn`, may use them.
The load summary and the missing-classes warning go through The load summary and the missing-classes warning go through
`System.getLogger(PackModules.class.getName())`, so the host can route them with a `System.getLogger(PackModules.class.getName())`, so the host can route them with a
@@ -231,8 +288,8 @@ resolve time.
Rules enforced by `StageGraphBuilder` and the resolver: Rules enforced by `StageGraphBuilder` and the resolver:
1. The stage namespace must equal the defining module's namespace. A second definition of an id 1. The stage id must start with the defining module's id and `/`. A second definition of an id
fails and names both modules. Two modules with the same id fail. fails. Two modules with the same id fail.
2. `requires(stage...)` adds a REQUIRED edge. If the stage is not installed, loading fails with 2. `requires(stage...)` adds a REQUIRED edge. If the stage is not installed, loading fails with
both stage ids, the requiring module and the namespace the missing module should have. both stage ids, the requiring module and the namespace the missing module should have.
3. `softAfter(ref...)` and `softBefore(ref...)` add SOFT edges only when the referenced id is 3. `softAfter(ref...)` and `softBefore(ref...)` add SOFT edges only when the referenced id is
@@ -307,18 +364,50 @@ are ordered only by the tie-break, so they are where two modules can silently co
## Placement attempts ## Placement attempts
`PlacementRunner.place(request, edit, inputs, settings)` owns the edit. It runs active stages in `PlacementRunner.place(request, edit, inputs, invocationSeed, settings)` owns the edit. It runs active stages in
order, stops after the current stage or block once a stage calls `reject(reason)`, commits only order, stops after the current stage or block once a stage calls `reject(reason)`, commits only
when nothing rejected or threw, and closes the edit in every case. Stages receive a buffered when nothing rejected or threw, and closes the edit in every case. Stages receive a buffered
`PlacementAccess` view of the edit without commit or close, and it expires with the attempt. `PlacementAccess` view of the edit without commit or close, and it expires with the attempt.
All stages of one attempt share the host's `PlacementContext`, including one RNG, consumed in ## Random streams
resolved order. Adding a module therefore changes what later stages draw unless modules derive
their own streams. The example ports use the shared RNG like Iris does today. Every stage has its own random stream per invocation, `StageContext.random()`. There is no shared
stream: `InvocationContext` has no `random()`, and the host passes a `long` invocation seed to
`PlacementRunner.place` and `ChunkRunner.generate` instead of a generator stages could see. With one
shared stream, every draw of an earlier stage shifts what later stages get, so installing a module
would change other modules' output for the same seed.
The stream depends only on the invocation seed and the stage id (`StageRandom`):
1. `idHash` = 64-bit FNV-1a of the UTF-8 bytes of `namespace:path`, computed once per pack load;
2. `streamSeed` = `mix(mix(invocationSeed) ^ idHash)`, `mix` being the SplitMix64 finalizer
(Stafford variant 13);
3. the stream is `new java.util.Random(streamSeed)`, created when the stage first draws.
`mix` is a bijection, so a stage gets a different stream for every invocation seed, and in one
invocation stages with different id hashes get different streams. The hash and the mixer are written
out in IrisApi, not taken from `String.hashCode` or a JDK class whose output may change.
`java.util.Random` is the only JDK generator whose algorithm the Java SE specification fixes:
`nextInt()`, `nextInt(bound)`, `nextLong()`, `nextBoolean()`, `nextFloat()`, `nextDouble()`,
`nextGaussian()` and `nextBytes` give the same values on every JDK. `SplittableRandom` and the named
`RandomGeneratorFactory` algorithms such as `L64X128MixRandom` promise identical sequences only within
one program, so a JDK update could change worlds. The methods `Random` inherits from
`RandomGenerator`, such as `nextInt(origin, bound)` and `nextDouble(bound)`, and `nextExponential()`,
are not fixed either. `Random`'s 48-bit state and its synchronized updates are fine for world
generation, which Minecraft has done with it for years. A test pins the derivation to values
computed outside Java from this description.
A block stage gets one stream per placement and draws from it across the blocks of its pass in block
order. Fused block stages interleave per block, but each still draws only from its own stream. A
stage that never draws never creates its stream.
Object generators are not stages. `ObjectGenerationContext.random()` stays, seeded from the variant
seed the host chooses.
## Chunk invocations ## Chunk invocations
`ChunkRunner.generate(inputs, settings)` runs active chunk stages once each in resolved order. `ChunkRunner.generate(inputs, invocationSeed, settings)` runs active chunk stages once each in resolved order.
`GenerationContext.hunk(type)` returns the host-owned local volume of that value type, shared by `GenerationContext.hunk(type)` returns the host-owned local volume of that value type, shared by
all stages of the invocation. Hunk coordinates are local; samples and mantle coordinates are all stages of the invocation. Hunk coordinates are local; samples and mantle coordinates are
world blocks. The runner does no neighbor scheduling or rollback. A failed invocation must stop world blocks. The runner does no neighbor scheduling or rollback. A failed invocation must stop
@@ -327,7 +416,8 @@ the host from publishing the chunk.
## Settings, geometry and storage ## Settings, geometry and storage
Settings types implement `IrisFeature` and carry `@Feature` (namespaced id, display name, JSON Settings types implement `IrisFeature` and carry `@Feature` (namespaced id, display name, JSON
field, attachment targets). `when(type)` validates the annotation while the module installs. field, attachment targets). `when(type)` validates the annotation while the module installs. The id's
namespace must be that of a module naming the type (see Namespaces).
`LoadedModules.load` catalogs those types with geometry generator settings and rejects duplicate `LoadedModules.load` catalogs those types with geometry generator settings and rejects duplicate
ids and JSON field collisions per attachment target, including reserved host fields. ids and JSON field collisions per attachment target, including reserved host fields.
`OptionsMetadata` reads field metadata; it does not decode JSON. `OptionsMetadata` reads field metadata; it does not decode JSON.
@@ -346,8 +436,9 @@ Unknown persisted layers must be preserved or fail explicitly.
block adapters, storage and codecs. block adapters, storage and codecs.
- Reach. The old per-modifier `writeRadius` and `mantleRadius` are gone with the modifiers. The - Reach. The old per-modifier `writeRadius` and `mantleRadius` are gone with the modifiers. The
host must prepare the whole area a pipeline may touch. Per-stage reach is an open question. host must prepare the whole area a pipeline may touch. Per-stage reach is an open question.
- Legacy random compatibility. Seed offsets and draw order must be matched by the adapter where - Legacy random compatibility. Existing Iris features draw from shared, positional generators in a
existing worlds are promised to stay the same. fixed order. Where existing worlds are promised to stay the same, the adapter has to reproduce
those draws inside the ported stages; per-stage streams will not match them on their own.
- Real feature ports. The test examples are simplified slices, not parity ports. - Real feature ports. The test examples are simplified slices, not parity ports.
## Feature-family migration map ## Feature-family migration map
+79 -26
View File
@@ -32,16 +32,23 @@ public final class MossModule implements IrisModule {
- `Stage.placement`, `Stage.placementBlock` and `Stage.chunk` create stages for the placement - `Stage.placement`, `Stage.placementBlock` and `Stage.chunk` create stages for the placement
pipeline (once per attempt), the placement pipeline (once per object block) and the chunk pipeline (once per attempt), the placement pipeline (once per object block) and the chunk
pipeline. Pass an output class to give a stage a typed output. pipeline. Pass an output class to give a stage a typed output.
- A stage id uses the namespace of the module that defines it. Defining an id twice fails. - A stage id starts with the id of the module that defines it and `/`: module `example:moss`
defines `example:moss/spread`, never `example:other/...`. Module ids therefore contain no `/`.
Defining an id twice fails.
- `requires(...)` takes another module's stage constant. It orders, makes the output readable - `requires(...)` takes another module's stage constant. It orders, makes the output readable
and deactivates this stage wherever the requirement is inactive. and deactivates this stage wherever the requirement is inactive.
- `softAfter` and `softBefore` take ids and only order. There is no hard "before". - `softAfter` and `softBefore` take ids and only order. There is no hard "before".
- `run(...)` ends a stage without output, `produce(...)` a stage with output and - `run(...)` ends a stage without output, `produce(...)` a stage with output and
`accumulate(initial, collector)` a block stage whose accumulator becomes its output. `accumulate(initial, collector)` a block stage whose accumulator becomes its output.
- `ctx.output(stage)` works only for stages the current stage transitively requires. - `ctx.output(stage)` works only for stages the current stage transitively requires.
- `ctx.random()` is the stage's own random stream, derived from the invocation seed and the stage
id. Installing or removing other modules, or how much they draw, never changes what a stage
draws. A block stage has one stream per placement, drawn across the blocks of its pass.
`IrisModule.register(FeatureRegistry)` stays for non-stage contributions: geometry generators `IrisModule.register(FeatureRegistry)` stays for non-stage contributions: geometry generators
and mantle layers. and mantle layers. Their feature ids and mantle keys use the module's namespace. A settings type
named in `when(...)` needs a feature id in the namespace of a module that names it, so another
module may still condition its stages on it.
## Module jars ## Module jars
@@ -56,9 +63,17 @@ modules/moss.jar
``` ```
`info()` gives the module id, display name and version, and optionally the packages whose classes `info()` gives the module id, display name and version, and optionally the packages whose classes
the module expects may be missing (see below). The id's namespace is the namespace of every stage the module expects may be missing (see below). The host reads it once, when it finds the module.
the module defines; the name is what logs show. Names and versions must fit on one line: line Every stage id of the module starts with the module id and `/`; the name is what logs show. Names
breaks and other control characters are rejected. and versions must fit on one line: line breaks and other control characters are rejected.
The host reserves namespaces for its own modules, such as `iris`. A pack module whose id uses a
reserved namespace fails the load, and because stages, settings ids and mantle keys follow the
module's namespace, none of them can use it either:
```
Module iris:stilt from modules/stilt.jar uses reserved namespace 'iris', which only modules that ship with the host may use; give the module a namespace of its own, which its stages, settings ids and mantle keys then use too
```
A module compiles against the Iris API as `compileOnly` (Maven: `provided`) and never ships it; A module compiles against the Iris API as `compileOnly` (Maven: `provided`) and never ships it;
Iris provides the API at runtime. At runtime a module can use the Iris API (`com.volmit.*`), the Iris provides the API at runtime. At runtime a module can use the Iris API (`com.volmit.*`), the
@@ -102,24 +117,48 @@ publisher's job.
## Host side ## Host side
```java ```java
try (var pack = PackModules.load(packRoot, builtInPackages)) { // exposed besides the API // Once, at startup: the same for every pack.
var modules = new ArrayList<>(builtIns); // DiscoveredModule.builtIn(...) var host = ModuleHost.of(builtInModules)
modules.addAll(pack.modules()); .exposing("art.arcane.iris.engine.modules") // besides the API
var loaded = LoadedModules.load(modules, reservedHostFields); .reservingNamespaces("iris")
System.out.println(loaded.placement().describe()); .reservingFields(reservedHostFields);
var placer = new PlacementRunner(loaded.placement()); // Per pack.
PlacementOutcome outcome = placer.place(request, edit, inputs, ConfiguredSettings.of(stilt, snow)); try (var pack = LoadedPack.load(packRoot, host)) {
System.out.println(pack.placement().describe());
new ChunkRunner(loaded.chunk()).generate(generationContext, chunkSettings); var placer = new PlacementRunner(pack.placement());
} // drop everything built from the pack before it closes PlacementOutcome outcome = placer.place(request, edit, inputs, placementSeed, ConfiguredSettings.of(stilt, snow));
new ChunkRunner(pack.chunk()).generate(generationContext, chunkSeed, chunkSettings);
} // stop using the runners before the pack closes
``` ```
`PackModules.load(packRoot, exposedHostPackages)` exposes the API plus the given host packages, `ModuleHost` holds what the host passes to every pack load: built-in modules (their `info()` is read
each with its subpackages; `PackModules.load(packRoot)` exposes only the API. The host chooses once, here), the host packages pack modules may use, the JSON fields the host itself uses and the
those packages, such as the ones that hold built-in modules' stage constants. It reads one entry reserved namespaces. Package names and namespaces are checked when it is built. `LoadedPack.load`
point per jar, in jar file name order, and loads every jar of the pack through one class loader. loads the pack's jars, installs them after the built-ins, catalogs settings and registrations and
Closing it closes that loader. A pack without a `modules` directory has no modules. Errors name the resolves both pipelines. It returns a complete pack or throws with nothing left open. `close()`
releases the pack's class loader and its jar copies. `PackModules` and `LoadedModules`, which it
uses, stay available for tests and special cases.
The host derives one seed per placement or chunk, from the world seed and the placement's stable
identity or the chunk position, and passes it to the runner. Each stage's stream comes from that
seed and the stage id (`StageRandom` documents the derivation). Stages cannot reach a shared stream.
The load copies the pack's jars into a fresh temporary directory (`iris-pack-modules-*`) and reads,
checks and loads classes only from the copies. The originals are never held open, so a module author
can rebuild a jar while studio has the pack loaded, also on Windows, and a load sees one consistent
set of jars even if one is rebuilt meanwhile. Messages still name `modules/moss.jar`. The copies are
deleted when the pack closes or its load fails. A later load removes copies a crashed process left
behind, but only directories with this prefix and an owner file naming a process that has exited,
holding nothing but that file and jars.
Pack modules see the API plus the packages given to `ModuleHost.exposing(...)`, each with its
subpackages. The host chooses those packages, such as the ones that hold built-in modules' stage
constants. The load (`PackModules`, under `LoadedPack`) reads one entry point per jar, in jar file
name order, and loads every jar of the pack through one class loader. A pack without a `modules`
directory has no modules. Errors name the
jar: no entry point, several entry points, a class of an exposed package in the jar, a class that is jar: no entry point, several entry points, a class of an exposed package in the jar, a class that is
also in another jar of the pack (both jars are named), a class that uses a class Iris has but hides, also in another jar of the pack (both jars are named), a class that uses a class Iris has but hides,
a class of a JDK module modules cannot see, a class of a JDK package not exported to modules, a a class of a JDK module modules cannot see, a class of a JDK package not exported to modules, a
@@ -170,10 +209,16 @@ A pack without jars logs `Pack overworld uses no modules: no jars in its modules
`LoadedModules.load` installs every module, catalogs the settings types named in `when(...)` `LoadedModules.load` installs every module, catalogs the settings types named in `when(...)`
together with geometry and mantle registrations, and resolves both pipelines. Graph errors together with geometry and mantle registrations, and resolves both pipelines. Graph errors
(missing requirement, cycle, foreign namespace, duplicate, cross-pipeline edge) fail here, at (missing requirement, cycle, a stage outside its module's id, duplicate, cross-pipeline edge) fail
pack load. Duplicate module ids and foreign namespaces also name the jar or "host classpath", and here, at pack load, and so do reserved namespaces and feature ids or mantle keys outside the
so does a module that fails to link a class while installing, such as a jar built against an API module's namespace. Errors about one module name its jar or "host classpath", and so does a module
whose methods have since changed. that fails to link a class while installing, such as a jar built against an API whose methods have
since changed:
```
Stage iris:anchor/height must start with example:moss/, the id of its defining module example:moss from modules/moss.jar
Mantle layer iris:depth must use namespace 'example' of its registering module example:moss from modules/moss.jar
```
`describe()` prints the order, owners, edge kinds, fused block passes and the stage pairs that `describe()` prints the order, owners, edge kinds, fused block passes and the stage pairs that
have no path between them. have no path between them.
@@ -192,8 +237,8 @@ and closes the edit in every case. Stages get buffered `PlacementAccess` without
- The `mantle` package keeps namespaced typed layers, codecs, lifetimes and buffered edits. - The `mantle` package keeps namespaced typed layers, codecs, lifetimes and buffered edits.
- `IrisFeature`, `@Feature`, the config annotations and `OptionsMetadata` describe settings. - `IrisFeature`, `@Feature`, the config annotations and `OptionsMetadata` describe settings.
Invocation views expire when the invocation ends. Stage bodies are shared by concurrent Invocation views and random streams expire when the invocation ends. Stage bodies are shared by
invocations and must not keep views or mutable state. concurrent invocations and must not keep views, streams or mutable state.
## Validation ## Validation
@@ -202,7 +247,15 @@ invocations and must not keep views or mutable state.
``` ```
The tests cover graph resolution and every error path, fusion, activation cascade, outputs, The tests cover graph resolution and every error path, fusion, activation cascade, outputs,
rejection and rollback, and install-order determinism. `PackModulesTest` compiles real module rejection and rollback, install-order determinism, stage-id prefixes and settings, object and mantle
namespaces (`StageGraphTest`, `ModuleRegistryTest`), and per-stage random streams: inserting a module
that draws leaves the other stages' draws unchanged, block stages draw one stream across their pass,
and the derivation is pinned to values computed from its specification (`StageRandomTest`).
`DiscoveredModuleTest` checks that `info()` is read once. `LoadedPackTest` loads a pack with
built-ins and checks that a failed load and `close()` leave nothing open. `PackJarSnapshotTest` checks
that classes come from the copies, that the original can be replaced while loaded, that copies go
away on close and on failure, that errors name the original jar, and which leftover directories a
load removes. `PackModulesTest` compiles real module
jars into a temporary pack and loads them, including every jar error, duplicate classes in plain jars into a temporary pack and loads them, including every jar error, duplicate classes in plain
and multi-release jars, API and other exposed classes in a jar, hidden host classes, JDK classes and multi-release jars, API and other exposed classes in a jar, hidden host classes, JDK classes
outside the platform loader, non-exported JDK packages (`sun.misc.Unsafe` and `java.lang` still outside the platform loader, non-exported JDK packages (`sun.misc.Unsafe` and `java.lang` still