Document what pack modules can see and the class checks

Modules compile against the API compileOnly, never ship it, and can use
only the API, the JDK and their own pack's jars. Describe the pack
loader's parent, the resource rule, the reserved com.volmit. prefix, the
load-time class reference check and its limits, and the new errors.
This commit is contained in:
piexel committed 2026-10-05 18:26:27 +02:00
1 parent 1553959cf4
commit b7b3993a8d
3 files changed
+96 -22

No files matched your search

+8 -2
View File
@@ -28,6 +28,10 @@ types that carry them and lists what the Iris adapter still owes.
Stage bodies hold no invocation state. Everything per placement or chunk travels through the
context, outputs and accumulators.
Modules compile against the API `compileOnly` and never ship it. At runtime they can use only the
API (`com.volmit.*`), the JDK and the classes in their own pack's jars; anything else fails the
pack load, naming the jar and the classes.
There is no API version gating. Packs ship their module jars, so their compatibility with the
running Iris is the pack publisher's responsibility.
@@ -47,8 +51,10 @@ running Iris is the pack publisher's responsibility.
`LoadedModules.load`, and close `PackModules` only after nothing built from it is in use.
- Route `System.Logger` output (logger `com.volmit.host.PackModules`) to the server log, so the
per-pack module summary is visible.
- Make built-in modules visible to the loader that defines the API, or pack jars cannot require
their stages.
- 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.
- Pack jars see only `com.volmit.` classes of that loader. Built-in modules whose stages packs may
require must be in such a package on that loader, or pack jars cannot require their stages.
## Open
+56 -12
View File
@@ -52,20 +52,23 @@ which jar a broken provider came from. The rejected alternatives:
1. Lists regular files ending in `.jar` in `<pack>/modules`, sorted by file name. A missing
directory means no modules.
2. Reads each jar's entry point file and its class names. Comments (`#`) and blank lines are
ignored; zero or more than one entry class name fails.
3. Fails if a class is in two jars, naming the class and both jars. Nothing has been defined yet.
4. Creates one `URLClassLoader` for all jars of the pack, parent = the loader of `IrisModule`.
5. Loads each entry class, checks that it implements `IrisModule` and comes from its own jar,
2. 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. A class in a `com.volmit.` package
fails, naming the jar and the first such class.
3. Fails if a class is in two jars, naming the class and both jars.
4. Fails if a class uses a class that is not in the API, the JDK or a jar of the pack, listing
each referencing and referenced class per jar. Nothing has been defined up to here.
5. Creates one `URLClassLoader` for all jars of the pack, parent = `ApiAndJdkClassLoader`.
6. 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()`.
6. Logs one INFO summary of the pack's modules.
7. Logs one INFO summary of the pack's modules.
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
from each other, and built-in modules visible to the API's loader are visible to every pack. 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 3 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 others require.
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 3 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
others require.
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
@@ -73,9 +76,50 @@ the highest `META-INF/versions/N` that the running JDK selects; a versioned copy
jar therefore clashes with the plain class in another. In a jar without that manifest attribute the
loader never reads `META-INF/versions`, so those entries are skipped.
### What a module can see
Modules depend only on the Iris API. They compile against it `compileOnly` and never ship it,
because Iris provides it at runtime; in production it is shaded into the Iris plugin jar. The
loader that defines the API therefore also sees Iris internals and the libraries Iris bundles, so
it is not the pack loader's parent. `ApiAndJdkClassLoader` is: it delegates every class in a
package starting with `com.volmit.` (`API_PACKAGE_PREFIX`) to the API's loader and everything else
to the platform class loader, which holds the JDK. A module can use only the API, the JDK and the
classes of its own pack's jars. The api/host split is deferred, so `com.volmit.host` is visible
too.
Resources follow the same rule by path: `com/volmit/...` from the API's loader, everything else
from the platform loader, then the pack's jars. A class and its class file come from the same
place, and a pack never sees Iris's own resources such as `plugin.yml` or its service files.
The pack loader asks its parent first, so a packaged copy of an API class would be silently
replaced by the host's, and a module class in a `com.volmit.` package could be replaced by a
later API class of the same name. Step 2 rejects both; the prefix belongs to the API. A module
class that shares a name with an Iris internal is harmless, because the pack loader cannot see
Iris internals. A module class that shares a name with a JDK class is replaced by the JDK's; that
is not checked.
Step 4 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
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. A class counts
as present when the pack has it or the parent has its class file, so nothing is loaded or
initialized by the check. Annotations and generic signatures are left out: the JVM never resolves
them while linking, and reflection skips an annotation whose type is missing, so a `compileOnly`
annotation library such as JetBrains annotations needs nothing at runtime.
The check is stricter than the JVM, which resolves a class only when code first uses it. A
shaded library with optional dependencies that are absent from the pack is therefore rejected,
even if those code paths would never run; the jar must leave such classes out or ship the
dependency. In exchange, a missing class shows up at load, with the jar and both class names,
instead of as a `NoClassDefFoundError` during install or generation. A missing `com.volmit.`
class means the jar was built against a different API, and the error says so.
There is no version gating. Packs ship their module jars and Iris never downloads any, so whether
a jar works with the running Iris is the pack publisher's responsibility. An incompatible jar
fails with a linkage error at load, install or run time.
a jar works with the running Iris is the pack publisher's responsibility. The class check catches
API classes that no longer exist. It does not check methods and fields: a jar built against an API
whose methods have changed fails with a linkage error, which `LoadedModules.load` 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.
Closing `PackModules` closes the loader. Classes loaded before that keep working, so the host
must drop `LoadedModules` and everything else built from the pack first.
+32 -8
View File
@@ -56,8 +56,16 @@ modules/moss.jar
```
`info()` gives the module id, display name and version. The id's namespace is the namespace of
every stage the module defines; the name is what logs show. A class may appear in only one jar of
a pack, so shaded libraries need relocating.
every stage the module defines; the name is what logs show. Names and versions must fit on one
line: line breaks and other control characters are rejected.
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 only the Iris API (`com.volmit.*`),
the JDK and the classes in its pack's module jars. Iris internals and the libraries Iris bundles
are hidden, so a library the module needs goes inside one of the pack's jars. A class may appear
in only one jar of a pack, so two jars that shade the same library must relocate it. The
`com.volmit.` package prefix belongs to the API: module classes, and the libraries they shade,
must not use it.
Iris never downloads modules and does not check which API version a jar was built for. A pack
ships its module jars, and keeping them compatible with the Iris version it targets is the pack
@@ -81,9 +89,20 @@ try (var pack = PackModules.load(packRoot)) {
`PackModules.load` reads one entry point per jar, in jar file name order, and loads every jar
of the pack through one class loader. Closing it closes that loader. A pack without a `modules`
directory has no modules. Errors name the jar: no entry point, several entry points, a class that
is also in another jar of the pack (both jars are named), or an entry class that cannot be loaded,
is not an `IrisModule`, is not in that jar, or fails to construct.
directory has no modules. Errors name the jar: no entry point, several entry points, a
`com.volmit.` class in the jar, a class that is also in another jar of the pack (both jars are
named), a class that uses a class outside the API, the JDK and the pack's jars, or an entry class
that cannot be loaded, is not an `IrisModule`, is not in that jar, or fails to construct. All
checks before the last run before any class of the pack is defined:
```
Module jar modules/alpha.jar contains Iris API class com.volmit.FeatureAttachment and 130 more; Iris provides the API at runtime, so mark the Iris API dependency compileOnly (Maven: provided) and keep module classes out of com.volmit.*
Module jar modules/moss.jar uses classes that are not in the Iris API, the JDK or the pack's module jars:
com.example.moss.MossModule -> com.google.gson.Gson
com.example.moss.MossSettings -> art.arcane.iris.engine.object.IrisBiome
A module can use only the Iris API, the JDK and the classes in its pack's module jars; ship any library it needs inside a module jar of the pack.
```
A successful load logs one INFO summary through `System.Logger`:
@@ -98,7 +117,9 @@ 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(...)`
together with geometry and mantle registrations, and resolves both pipelines. Graph errors
(missing requirement, cycle, foreign namespace, duplicate, cross-pipeline edge) fail here, at
pack load. Duplicate module ids and foreign namespaces also name the jar or "host classpath".
pack load. Duplicate module ids and foreign namespaces also name the jar or "host classpath", and
so does a module that fails to link a class while installing, such as a jar built against an API
whose methods have since changed.
`describe()` prints the order, owners, edge kinds, fused block passes and the stage pairs that
have no path between them.
@@ -128,8 +149,11 @@ invocations and must not keep views or mutable state.
The tests cover graph resolution and every error path, fusion, activation cascade, outputs,
rejection and rollback, and install-order determinism. `PackModulesTest` compiles real module
jars into a temporary pack and loads them, including every jar error and duplicate classes in
plain and multi-release jars. `PackModulesSummaryTest` checks the log text. The example ports in
jars into a temporary pack and loads them, including every jar error, duplicate classes in plain
and multi-release jars, API classes in a jar, references outside the pack, references that must
still load (arrays, the JDK, other pack jars, missing annotation types) and linkage errors during
install. `ApiAndJdkClassLoaderTest` checks what the pack loader's parent shows.
`PackModulesSummaryTest` checks the log text. The example ports in
`src/test/java/com/volmit/example` rebuild preparation, anchoring, block writes, stilt and snow
as separate modules, add a third-party moss module, and add a two-module chunk pipeline. There is
no Minecraft integration or production storage in these tests.