Repository navigation
Seed and tape Java and .NET ports - #43
Merged
Merged
Conversation
Both languages compile on the way to running, which is what a runner can join: neither has an environment variable that puts a different generator behind the one a program calls. Java ships a javaagent that rewrites the port's own call sites as each class loads -- Math.random, Random and ThreadLocalRandom become calls to a shim that returns the next tape value. Written against java.lang.classfile, standard since JDK 24, so the agent carries no bytecode library; it rewrites the port and leaves the JDK alone, so nothing is retransformed and no platform class is patched. It is the one shim that has to be built, which is what `make shims` is for. .NET declares a System.Random of its own and hands it to the compiler ahead of the real one, injected with an MSBuild targets file that reaches a single .cs file as readily as a .csproj. Replacing the class replaces Shuffle, GetItems and Random.Shared along with the draws, which makes it the widest of the shims. DOTNET_STARTUP_HOOKS was the obvious route and is a dead end: file-based apps build with startup hooks and dynamic code both switched off, so a detour library has nothing to detour with. The image grows a Temurin JDK and a .NET SDK, both pinned and checksummed like everything else in it, and the CI matrix installs the same two. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019f9gkZVUEo3jtv51GSb4vJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two more languages a script can be played against without editing the port.
Both compile on the way to running, which is what a runner can join: neither
has an environment variable that puts a different generator behind the one a
program calls, so the shim has to get in front of the compiler instead.
Java
runners/java.yamlloads a javaagent that rewrites the port's own call sitesas each class loads —
Math.random,RandomandThreadLocalRandombecomecalls to
prescript.Tape, which returns the next tape value and ignores thegenerator it was handed.
java.lang.classfile, standard since JDK 24, so the agentneeds no bytecode library.
and nothing is retransformed.
java.*/jdk.*modules, which mattersbecause
java rng.javacompiles in-process and javac's own classes wouldotherwise draw from the tape.
SecureRandom,SplittableRandom, or draws made from insidejava.base—Collections.shuffle(list, rnd)callsnextIntat a call sitethe agent never sees.
It is the one shim that is compiled rather than read, so
make shimsbuilds itand
.gitignorekeeps the jar out of the repository — a jar built from sourceshere is easier to trust than one that arrived with them.
.NET
runners/dotnet.yamlcompiles anamespace System { public class Random }intothe program ahead of the real one. The C# compiler prefers a type it is
compiling over the same type from a reference, so
new Random()binds to theshim with the port unchanged. The file is added to the compilation with
--property:CustomBeforeMicrosoftCommonTargets, which reaches a single.csfile as readily as a
.csproj.Replacing the class replaces
Shuffle,GetItemsandRandom.Sharedalongwith the draws, which makes it the widest of the shims. Separate assemblies
each get their own copy, so the draw sequence is shared through
AppDomain.SetData.DOTNET_STARTUP_HOOKSwas the obvious route and is a dead end: file-based appsbuild with
StartupHookSupportandIsDynamicCodeSupportedboth false, andHarmonyLib refuses CoreCLR 10 outright.
TERM: "dumb"is in the runner becauseSystem.Consoleotherwise writes terminfosmkxinto the transcript the firsttime a .NET program reads a key.
Around them
docker/Dockerfilegains a Temurin JDK 25 and .NET SDK 10.0.400, pinned andchecksummed like everything else, and reports both in
$PRESCRIPT_ENVIRONMENT.docker/run.shgains NuGet and .NET artifact cache volumes. Not~/.dotnet,which looks like the obvious one and breaks the SDK: it holds the first-run
sentinel, and the first run is also what creates
~/.local/share.make shimsbefore the suite.internal/playcovers both in seeded and taped mode, and a runner whose shimhas not been built now skips with a message rather than failing obscurely —
or fails outright under
PRESCRIPT_REQUIRE_RUNNERS, as in CI and the image.Verified with
make lint,PRESCRIPT_REQUIRE_RUNNERS=1 make test,make examples,make imageandmake docker_test.🤖 Generated with Claude Code
https://claude.ai/code/session_019f9gkZVUEo3jtv51GSb4vJ