Remove registerHeldType

Built-in module types are no longer held by Iris's own classes: object
placements are iris:objects settings, so every type they hold is reached
from a registered feature. FeatureRegistry.registerHeldType,
HeldTypeRegistration, FeatureCatalog.heldTypes and SchemaSource.heldType
go, with the held example module and its schema tests.
This commit is contained in:
piexel committed 2026-10-27 01:43:50 +01:00
1 parent 217cff620c
commit 398f3879ae
12 files changed
+6 -167

No files matched your search

@@ -18,7 +18,6 @@ import java.util.stream.Collectors;
* nothing depends on discovery. Factory, codec, validator, hook and provider implementations must themselves obey their
* concurrency contracts.
*/
@SuppressWarnings("removal") // held types are transitional, until the cut-over
public final class FeatureCatalog {
/** Services are asked for on the generation hot path, so each type's annotation is read once. */
private static final ClassValue<Providers> SERVICE_PROVIDERS = new ClassValue<>() {
@@ -37,7 +36,6 @@ public final class FeatureCatalog {
private final Map<Class<?>, ObjectRegistration<?>> objects;
private final Map<String, MantleRegistration<?>> mantle;
private final List<ResourceKindRegistration> resourceKinds;
private final List<HeldTypeRegistration> heldTypes;
private final List<ValidatorRegistration> validators;
private final List<LifecycleRegistration> lifecycles;
private final Map<Class<?>, List<ServiceRegistration>> registrationsByService;
@@ -48,7 +46,6 @@ public final class FeatureCatalog {
Map<Class<?>, ObjectRegistration<?>> objects,
Map<String, MantleRegistration<?>> mantle,
Collection<ResourceKindRegistration> resourceKinds,
Collection<HeldTypeRegistration> heldTypes,
List<ValidatorRegistration> validators,
List<LifecycleRegistration> lifecycles,
List<ServiceRegistration> services) {
@@ -56,7 +53,6 @@ public final class FeatureCatalog {
this.objects = Map.copyOf(objects);
this.mantle = Map.copyOf(mantle);
this.resourceKinds = sorted(resourceKinds, registration -> registration.kind().id());
this.heldTypes = sorted(heldTypes, registration -> registration.type().getName());
this.validators = inModuleOrder(validators, ValidatorRegistration::module);
this.lifecycles = inModuleOrder(lifecycles, LifecycleRegistration::module);
this.registrationsByService = byService(inModuleOrder(services, ServiceRegistration::module));
@@ -81,15 +77,6 @@ public final class FeatureCatalog {
return resourceKinds;
}
/** The classes built-in modules described because Iris's own classes hold them, by class name.
*
* @deprecated Transitional, until the cut-over; see {@link com.volmit.FeatureRegistry#registerHeldType}.
*/
@Deprecated(forRemoval = true)
public List<HeldTypeRegistration> heldTypes() {
return heldTypes;
}
/** The validators modules registered, by module id, each module's in the order it registered them. */
public List<ValidatorRegistration> validators() {
return validators;
@@ -1,20 +0,0 @@
package com.volmit.host;
import java.util.Objects;
/** A class of a built-in module that Iris's own classes hold, and the module that registered it.
*
* @deprecated Transitional, until the cut-over; see {@link com.volmit.FeatureRegistry#registerHeldType}.
*/
@Deprecated(forRemoval = true)
public record HeldTypeRegistration(Class<?> type, DiscoveredModule module) {
public HeldTypeRegistration {
Objects.requireNonNull(type, "type");
Objects.requireNonNull(module, "module");
}
@Override
public String toString() {
return "held type " + type.getName() + " of module " + module;
}
}
@@ -33,7 +33,6 @@ import java.util.Set;
* invalidates the host's whole build. This does not decode JSON, discover modules or instantiate
* settings.
*/
@SuppressWarnings("removal") // held types are transitional, until the cut-over
public final class ModuleRegistry implements FeatureRegistry {
private final Map<Class<?>, FeatureDescriptor<?>> settings = new HashMap<>();
private final Map<Class<?>, ObjectRegistration<?>> objects = new HashMap<>();
@@ -43,7 +42,6 @@ public final class ModuleRegistry implements FeatureRegistry {
private final Set<Class<?>> registeredByOwner = new HashSet<>();
private final Map<KeyAtTarget, KeyClaimant> keyClaimants = new HashMap<>();
private final Map<ResourceId, ResourceKindRegistration> resourceKinds = new HashMap<>();
private final Map<Class<?>, HeldTypeRegistration> heldTypes = new HashMap<>();
private final List<ValidatorRegistration> validators = new ArrayList<>();
private final List<LifecycleRegistration> lifecycles = new ArrayList<>();
private final List<ServiceRegistration> services = new ArrayList<>();
@@ -120,20 +118,6 @@ public final class ModuleRegistry implements FeatureRegistry {
registeredByOwner.add(settingsType);
}
/** @deprecated Transitional, until the cut-over; see {@link FeatureRegistry#registerHeldType}. */
@Override
@Deprecated(forRemoval = true)
public void registerHeldType(Class<?> type) {
checkOpen();
Objects.requireNonNull(type, "type");
requireRegistering("Held type " + type.getName());
if (registering.source() != DiscoveredModule.Source.HOST && type.getClassLoader() == registering.module().getClass().getClassLoader()) {
throw new IllegalArgumentException("Held type " + type.getName() + " of module " + registering + " is a class of the pack module's"
+ " own jar; only a class the host loads, such as one of an exposed package, can be held by Iris's own classes");
}
heldTypes.putIfAbsent(type, new HeldTypeRegistration(type, registering));
}
@Override
public <T> void registerResourceKind(ResourceKind<T> kind) {
checkOpen();
@@ -200,8 +184,7 @@ public final class ModuleRegistry implements FeatureRegistry {
public FeatureCatalog freeze() {
if (catalog == null) {
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), heldTypes.values(),
validators, lifecycles, services);
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators, lifecycles, services);
}
return catalog;
}
@@ -24,7 +24,7 @@ import java.util.stream.Stream;
* naming a kind nobody has, a class without a usable no-argument constructor, a snippet name used twice, a pack
* class's snippet name outside its module's path, or a pack module's resource kind read into a host type.
*/
@SuppressWarnings("removal") // held types and host kinds are transitional, until the cut-over
@SuppressWarnings("removal") // host kinds are transitional, until the cut-over
final class PackSchemaBuilder {
private static final Pattern SNIPPET_NAME = Pattern.compile("[a-z0-9_.-]+(/[a-z0-9_.-]+)*");
private static final Pattern RELATIVE_SEGMENT = Pattern.compile("(^|/)\\.\\.?(/|$)");
@@ -48,7 +48,6 @@ final class PackSchemaBuilder {
private PackSchema describe(FeatureCatalog catalog) {
var features = catalogued(catalog).map(this::draft).toList();
var resources = catalog.resourceKinds().stream().map(this::describe).toList();
catalog.heldTypes().forEach(this::draft);
requireUniqueSnippets();
var types = completeTypes();
return new PackSchema(features.stream().map(feature -> feature.complete(types)).toList(), resources,
@@ -99,10 +98,6 @@ final class PackSchemaBuilder {
return Stream.concat(settings, objects).sorted(Comparator.comparing(catalogued -> catalogued.descriptor().id()));
}
private void draft(HeldTypeRegistration held) {
drafts.settings(SchemaSource.heldType(held));
}
private FeatureDraft draft(Catalogued catalogued) {
var owner = ownerOf(catalogued.descriptor());
drafts.settings(SchemaSource.settings(catalogued.descriptor(), owner));
@@ -7,7 +7,6 @@ import com.volmit.resource.ResourceKind;
* @param subject what reached the class, such as {@code settings example:flora}
* @param type the class the subject is read into
*/
@SuppressWarnings("removal") // held types are transitional, until the cut-over
record SchemaSource(String subject, Class<?> type, DiscoveredModule module) {
static SchemaSource settings(FeatureDescriptor<?> feature, DiscoveredModule module) {
return new SchemaSource("settings " + feature.id(), feature.type(), module);
@@ -17,10 +16,6 @@ record SchemaSource(String subject, Class<?> type, DiscoveredModule module) {
return new SchemaSource("resource kind " + kind.id(), kind.type(), module);
}
static SchemaSource heldType(HeldTypeRegistration held) {
return new SchemaSource("held type " + held.type().getName(), held.type(), held.module());
}
@Override
public String toString() {
return subject + " (module " + module + ")";
@@ -1,19 +0,0 @@
package com.volmit.example.held;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.config.Snippet;
@Snippet("clamp")
@Desc("Limits a placement by height")
public final class ClampSettings {
@MinNumber(-2048)
@MaxNumber(2048)
@Desc("The lowest height")
private int minimumHeight = -2048;
public int minimumHeight() {
return minimumHeight;
}
}
@@ -1,19 +0,0 @@
package com.volmit.example.held;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.ModuleSetup;
/** A built-in module whose settings class is held by a class of the host, not by a feature. */
public final class HeldModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:held", "Held", "test");
}
@Override
public void setup(ModuleSetup setup) {
setup.registry().registerHeldType(ClampSettings.class);
setup.registry().registerHeldType(ClampSettings.class);
}
}
@@ -4,8 +4,6 @@ import com.volmit.config.Level;
import com.volmit.config.Reference;
import com.volmit.example.chunk.GrassModule;
import com.volmit.example.chunk.TerrainModule;
import com.volmit.example.held.ClampSettings;
import com.volmit.example.held.HeldModule;
import com.volmit.example.hosttypes.Palette;
import com.volmit.example.placement.PlacementModules;
import com.volmit.example.terrain.LayersModule;
@@ -364,43 +362,6 @@ class PackSchemaTest {
assertThrows(IllegalArgumentException.class, () -> NO_BUILT_INS.describingHostTypesIn("not a package"));
}
@Test
void builtInModulesDescribeTheClassesTheHostsClassesHold() {
var schema = schemaOf(pack("held"), ModuleHost.of(List.<com.volmit.IrisModule>of(new HeldModule())));
assertEquals(List.of(), schema.features());
assertEquals(new ObjectType(ClampSettings.class.getName(), "Limits a placement by height", Optional.of("clamp"),
List.of(new SchemaOption("minimumHeight", new IntegerKind(), "The lowest height", false, OptionalDouble.of(-2048),
OptionalDouble.of(2048), OptionalInt.empty(), Optional.of(-2048L)))), schema.type(ClampSettings.class.getName()));
assertEquals(List.of(ClampSettings.class.getName()), schema.snippets().stream().map(ObjectType::name).toList());
}
@Test
void packModulesCannotRegisterHeldTypes() {
var jar = module("pack.flora.FloraModule", FLORA,
NO_MEMBERS, "registry.registerHeldType(pack.flora.Clamp.class);")
.source("pack.flora.Clamp", "package pack.flora; public final class Clamp { private int minimum; }");
var pack = pack("held-by-pack");
jar.writeInto(pack, "flora.jar");
var failure = assertThrows(ModuleLoadException.class, () -> LoadedPack.load(pack, NO_BUILT_INS));
assertTrue(failure.getMessage().contains("Held type pack.flora.Clamp") && failure.getMessage().contains("own jar"),
failure.getMessage());
}
@Test
void packModulesMayDescribeAHostClassOfAnExposedPackage() {
var jar = module("pack.flora.FloraModule", FLORA,
NO_MEMBERS, "registry.registerHeldType(com.volmit.example.held.ClampSettings.class);")
.compileAgainstHostOf(ClampSettings.class);
var pack = pack("held-exposed");
jar.writeInto(pack, "flora.jar");
var schema = LoadedPack.load(pack, NO_BUILT_INS.exposing("com.volmit.example.held")).schema();
assertEquals("Limits a placement by height", schema.type(ClampSettings.class.getName()).description());
}
@Test
void packModulesCannotUseHostTypes() {
var host = NO_BUILT_INS.exposing(HOST_TYPES).describingHostTypesIn(HOST_TYPES);