mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Require object feature ids, mantle keys and settings ids to be the owning module's id or below it
Object feature ids and mantle keys a module registers must now equal its module id or start with it and '/', the rule stage ids already follow, instead of only sharing its namespace. A settings type named in when(...) needs a feature id that at least one module naming it owns in the same sense, so another module may still condition on it, as moss can on iris:snow. ModuleInfo.ownsId states the rule; stageIdPrefix becomes idPrefix since it now prefixes more than stages. Errors name the module and its origin and suggest an owned id.
This commit is contained in:
1 parent
77e4ab4710
commit
d5aad57ad9
10 files changed
+113
-61
No files matched your search
@@ -8,7 +8,7 @@ import com.volmit.object.ObjectGeneratorFactory;
|
||||
/** Host implementation collects non-stage registrations before loading pack configuration.
|
||||
* Feature IDs must be unique. JSON fields must be unique per attachment target, including the
|
||||
* settings types stages name in {@code when(...)}. Feature IDs and mantle keys a module registers
|
||||
* use the namespace of its module id.
|
||||
* are its module id or start with it and {@code /}, such as {@code iris:snow} or {@code iris:snow/depth}.
|
||||
*/
|
||||
public interface FeatureRegistry {
|
||||
/** Registers a layer before pack loading. Null arguments throw NullPointerException;
|
||||
|
||||
@@ -8,7 +8,8 @@ import java.util.Objects;
|
||||
/** Module identity. Every stage a module defines has an id that starts with the module id and
|
||||
* {@code /}, such as {@code iris:stilt/fill} for module {@code iris:stilt}, so a module id has no
|
||||
* {@code /} of its own: {@code iris:stilt/extra} would own stages under {@code iris:stilt}'s path.
|
||||
* Settings ids and mantle keys the module registers use its namespace. The name is for
|
||||
* Settings ids, object feature ids and mantle keys the module owns are its id or start with it and
|
||||
* {@code /}, such as {@code iris:stilt} or {@code iris:stilt/depth}. The name is for
|
||||
* people, for example in load logs; the id is what the host and other modules match on. Name and
|
||||
* version must fit on one log line, so they reject control characters such as line breaks.
|
||||
*
|
||||
@@ -51,15 +52,22 @@ public record ModuleInfo(ResourceId id, String name, String version, List<Packag
|
||||
|
||||
/** Whether {@code stageId} may name a stage of this module: it starts with this module's id and '/'. */
|
||||
public boolean ownsStage(ResourceId stageId) {
|
||||
return stageId.namespace().equals(id.namespace()) && stageId.path().startsWith(stagePrefix());
|
||||
return stageId.namespace().equals(id.namespace()) && stageId.path().startsWith(childPathPrefix());
|
||||
}
|
||||
|
||||
/** What every stage id of this module starts with, such as {@code iris:stilt/}. */
|
||||
public String stageIdPrefix() {
|
||||
return id.namespace() + ":" + stagePrefix();
|
||||
/** Whether {@code featureId} may name settings, an object generator or a mantle layer of this
|
||||
* module: it is this module's id or starts with it and '/'.
|
||||
*/
|
||||
public boolean ownsId(ResourceId featureId) {
|
||||
return featureId.equals(id) || ownsStage(featureId);
|
||||
}
|
||||
|
||||
private String stagePrefix() {
|
||||
/** What every stage id of this module, and every other id below it, starts with, such as {@code iris:stilt/}. */
|
||||
public String idPrefix() {
|
||||
return id.namespace() + ":" + childPathPrefix();
|
||||
}
|
||||
|
||||
private String childPathPrefix() {
|
||||
return id.path() + STAGE_SEPARATOR;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ import java.util.Set;
|
||||
/** Reference host registry. Single-threaded registration ends with freeze(); the catalog is
|
||||
* immutable. IDs are unique across feature kinds; JSON fields are unique per attachment target.
|
||||
* Pass existing host JSON fields to reserve them before modules register. Modules register through
|
||||
* {@link #register(DiscoveredModule)}; object feature ids and mantle keys must use the registering
|
||||
* module's namespace. A failed registration leaves the registry unchanged. A failed module callback
|
||||
* {@link #register(DiscoveredModule)}; object feature ids and mantle keys must be the registering
|
||||
* module's id or start with it and '/' ({@link com.volmit.ModuleInfo#ownsId}). A failed registration leaves the registry unchanged. A failed module callback
|
||||
* invalidates the host's whole build. This does not decode JSON, discover modules or instantiate
|
||||
* settings.
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
ObjectGeneratorFactory<F> factory) {
|
||||
checkOpen();
|
||||
var descriptor = FeatureDescriptor.of(featureType);
|
||||
requireModuleNamespace("Object generator settings " + featureType.getName() + " with feature id", descriptor.id());
|
||||
requireOwnedId("Object generator settings " + featureType.getName() + " with feature id", descriptor.id());
|
||||
var registration = new ObjectRegistration<>(descriptor, factory);
|
||||
claim(descriptor);
|
||||
objects.put(featureType, registration);
|
||||
@@ -73,7 +73,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
checkOpen();
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(codec, "codec");
|
||||
requireModuleNamespace("Mantle layer", ResourceId.parse(key.id()));
|
||||
requireOwnedId("Mantle layer", ResourceId.parse(key.id()));
|
||||
|
||||
var registration = new MantleRegistration<>(key, lifetime, codec, codec.version());
|
||||
if (mantle.putIfAbsent(key.id(), registration) != null) {
|
||||
@@ -99,14 +99,14 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
private void requireModuleNamespace(String registration, ResourceId id) {
|
||||
private void requireOwnedId(String registration, ResourceId id) {
|
||||
if (registering == null) {
|
||||
throw new IllegalStateException(registration + " " + id + " registered outside IrisModule.register");
|
||||
}
|
||||
var namespace = registering.info().id().namespace();
|
||||
if (id.namespace().equals(namespace)) return;
|
||||
throw new IllegalArgumentException(registration + " " + id + " must use namespace '" + namespace
|
||||
+ "' of its registering module " + registering);
|
||||
var info = registering.info();
|
||||
if (info.ownsId(id)) return;
|
||||
throw new IllegalArgumentException(registration + " " + id + " must be " + info.id() + " or start with "
|
||||
+ info.idPrefix() + ", the id of its registering module " + registering);
|
||||
}
|
||||
|
||||
private void reserveHostFields(Map<FeatureAttachment.Target, Set<String>> reservedFields) {
|
||||
|
||||
@@ -26,7 +26,8 @@ import java.util.stream.Collectors;
|
||||
* discard the whole builder: it may hold a partial module. Errors about one module name its origin.
|
||||
*
|
||||
* <p>A module defines only stages whose ids start with its own id and '/', and a settings type
|
||||
* named in {@code when(...)} must have a feature id in the namespace of a module that names it.
|
||||
* named in {@code when(...)} must have a feature id that at least one module naming it owns: that
|
||||
* module's id, or one starting with it and '/'.
|
||||
*/
|
||||
public final class StageGraphBuilder implements StageGraph {
|
||||
private final Map<ResourceId, StageDeclaration> declarations = new HashMap<>();
|
||||
@@ -65,8 +66,8 @@ public final class StageGraphBuilder implements StageGraph {
|
||||
return GraphResolver.resolve(pipeline, declarations.values());
|
||||
}
|
||||
|
||||
/** Settings types named by when(...), ordered by feature id. Fails if a type's feature id is not
|
||||
* in the namespace of any module that names it: some module of that namespace must own it.
|
||||
/** Settings types named by when(...), ordered by feature id. Fails if no module that names a type
|
||||
* owns its feature id ({@link com.volmit.ModuleInfo#ownsId}).
|
||||
*/
|
||||
public List<Class<? extends IrisFeature>> settingsTypes() {
|
||||
var uses = settingsUses();
|
||||
@@ -104,17 +105,22 @@ public final class StageGraphBuilder implements StageGraph {
|
||||
|
||||
private void requireSettingsOwner(SettingsUse use) {
|
||||
var settings = use.settings();
|
||||
var namers = use.namers();
|
||||
var namespace = settings.id().namespace();
|
||||
if (namers.stream().anyMatch(module -> module.namespace().equals(namespace))) return;
|
||||
var namers = use.namers().stream().map(modules::get).toList();
|
||||
if (namers.stream().anyMatch(module -> module.info().ownsId(settings.id()))) return;
|
||||
var example = namers.getFirst().info();
|
||||
throw new IllegalArgumentException("Settings type " + settings.type().getName() + " has feature id "
|
||||
+ settings.id() + ", but no module of namespace '" + namespace + "' names it in when(...); it is named by "
|
||||
+ describeModules(namers) + ". A feature id uses the namespace of the module that owns the settings");
|
||||
+ settings.id() + ", which none of the modules naming it in when(...) owns: " + describeModules(namers)
|
||||
+ ". A feature id is the id of the module that owns the settings, such as " + example.id()
|
||||
+ ", or starts with it and '/', such as " + example.idPrefix() + lastSegment(settings.id()));
|
||||
}
|
||||
|
||||
private String describeModules(SortedSet<ResourceId> moduleIds) {
|
||||
return moduleIds.stream()
|
||||
.map(modules::get)
|
||||
private static String lastSegment(ResourceId id) {
|
||||
var path = id.path();
|
||||
return path.substring(path.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
private static String describeModules(List<DiscoveredModule> modules) {
|
||||
return modules.stream()
|
||||
.map(DiscoveredModule::toString)
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
@@ -144,7 +150,7 @@ public final class StageGraphBuilder implements StageGraph {
|
||||
private static void requireOwnedStageId(Stage<?> stage, DiscoveredModule discovered) {
|
||||
var info = discovered.info();
|
||||
if (info.ownsStage(stage.id())) return;
|
||||
throw new IllegalArgumentException("Stage " + stage + " must start with " + info.stageIdPrefix()
|
||||
throw new IllegalArgumentException("Stage " + stage + " must start with " + info.idPrefix()
|
||||
+ ", the id of its defining module " + discovered);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.volmit.resource.ResourceId;
|
||||
import java.util.Objects;
|
||||
|
||||
/** A unit of pipeline work, declared as a constant by the module that defines it.
|
||||
* The id is namespaced and its namespace must match the defining module. Identity is this
|
||||
* The id starts with the defining module's id and '/', such as {@code iris:stilt/fill}. Identity is this
|
||||
* declaration object: other modules require or read the owner's constant, never a copy.
|
||||
* The output type is Void for stages that only act; otherwise dependents read it through
|
||||
* {@link StageContext#output(Stage)}. Block stages accumulate their output across the pass.
|
||||
|
||||
@@ -14,7 +14,10 @@ public interface StageDefinition<C extends StageContext, O> {
|
||||
|
||||
StageDefinition<C, O> softBefore(StageRef... stages);
|
||||
|
||||
/** Activates the stage only where the given feature settings are configured. */
|
||||
/** Activates the stage only where the given feature settings are configured. At least one module
|
||||
* naming the type must own its feature id: the id is that module's id or starts with it and '/'.
|
||||
* Other modules may name it too, such as moss conditioning on {@code iris:snow}.
|
||||
*/
|
||||
<S extends IrisFeature> ConditionalStageDefinition<C, S, O> when(Class<S> settingsType);
|
||||
|
||||
/** Body for a stage without output. */
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.volmit.stage;
|
||||
|
||||
/** Collects the stages a module defines during {@code IrisModule.install}. Each define call must
|
||||
* end with exactly one body (run, produce or accumulate). The graph is resolved once at pack load:
|
||||
* missing requirements, cycles, duplicate definitions, foreign namespaces and cross-pipeline
|
||||
* edges are load errors. Bodies are shared by concurrent invocations and must not capture
|
||||
* missing requirements, cycles, duplicate definitions, stage ids outside the module's id and
|
||||
* cross-pipeline edges are load errors. Bodies are shared by concurrent invocations and must not capture
|
||||
* invocation state; everything per-invocation arrives through the context and outputs.
|
||||
*/
|
||||
public interface StageGraph {
|
||||
|
||||
Reference in new issue
Block a user