Skip to content

Standard library nondeterministic / excluded module coverage

Generated 2026-05-22. Companion to the deterministic-group document (20260522-stdlib-deterministic-module-coverage.md). Covers modules where folding to Constant[T] is principally impossible or of little practical value.


SymbolMeaning
🚫Out of scope (side-effecting / nondeterministic / negligible precision gain)
🔲Limited precision uplift potential (return-value refinements, etc.)
🔷RBS provides sufficient precision

Modules in this group meet at least one of the following:

  1. Side effects: modifies the filesystem, network, or OS process.
  2. Nondeterminism: returns different output on each call with the same arguments (random numbers, timestamps, etc.).
  3. Return value is untyped: Marshal.load — return type is statically unknown even with literal input.
  4. Negligible folding benefit: computation is deterministic but the constant value has no practical use in type inference (Base64 / Digest).

SecureRandom.methods - Module.methods → 12 methods (Ruby 4.0.5): :alphanumeric, :base64, :bytes, :gen_random, :hex, :rand, :random_bytes, :random_number, :urlsafe_base64, :uuid, :uuid_v4, :uuid_v7

Exclusion reason: Reads from the OS random source, so every call returns a different value. hex(n) return type is String (could add non-empty-string refinement), uuid / uuid_v4 / uuid_v7 return type is already String in RBS.

MethodReturn typeStatusNotes
hex(n)String (hex)🚫Nondeterministic. RBS says String.
base64(n)String🚫Nondeterministic.
urlsafe_base64(n)String🚫Nondeterministic.
random_bytes(n) / bytes(n)String (binary)🚫Nondeterministic.
gen_random(n)String🚫Nondeterministic (internal implementation).
rand / random_numberFloat|Integer🚫Nondeterministic.
uuid / uuid_v4String🚫Nondeterministic.
uuid_v7String🚫Nondeterministic (includes timestamp component).
alphanumeric(n)String🚫Nondeterministic.

Random.methods - Class.methods → 7 methods: :bytes, :new_seed, :rand, :random_number, :seed, :srand, :urandom

Exclusion reason: Class methods depend on global random state. Random.new(seed) instances are deterministic with a fixed seed, but instance method precision uplift is out of scope for ConstantFolding (carries instance state).

MethodStatusNotes
rand / random_number🚫Global random.
bytes(n)🚫Nondeterministic.
srand(seed)🚫Side effect (modifies global state).
seed / new_seed🚫Nondeterministic.
urandom(n)🚫OS random source.

FileUtils.methods - Module.methods → 57 methods (representative sample).

Exclusion reason: Dedicated to filesystem side effects. Return values are operation target paths or nil — no meaningful precision uplift.

CategoryExample methodsStatus
File copy / movecp, cp_r, mv, install🚫
File deletionrm, rm_f, rm_r, rm_rf🚫
Directory operationsmkdir, mkdir_p, rmdir🚫
Linksln, ln_s, ln_sf, ln_sr🚫
Permissionschmod, chmod_R, chown, chown_R🚫
Comparisoncmp / compare_file, identical?🚫
Utilitiespwd / getwd, cd / chdir, touch🚫
Metadatacommands, options, options_of, have_option?🚫

Marshal.methods - Module.methods:dump, :load, :restore

Exclusion reason (user decision): dump is deterministic (same object → same byte sequence), but there is no practical use for the resulting binary string as a literal type. load / restore reconstructs arbitrary Ruby objects from binary, so the return type is untyped (not statically inferrable). Despite being deterministic, Marshal offers no practical benefit for type inference.

MethodStatusNotes
dump(obj)🚫Deterministic but no use case for the return (binary String) as a constant.
load(str) / restore(str)🚫Return type is untyped.

GC.methods - Module.methods → 20 methods.

Exclusion reason: GC operations return runtime state (heap usage, object count, etc.). Values vary by execution environment and timing even for the same code.

CategoryExample methodsStatus
Statisticscount, stat, stat_heap, total_time🚫
GC execution / controlstart, compact, disable, enable🚫
Configurationconfig, measure_total_time, stress🚫
Verificationverify_compaction_references, verify_internal_consistency🚫

Demoted to a bundled gem in Ruby 4.0 (requires require "base64"). Base64.methods - Module.methods:decode64, :encode64, :strict_decode64, :strict_encode64, :urlsafe_decode64, :urlsafe_encode64

Exclusion reason (why not in the deterministic group):

AspectDetail
Determinism✓ Same input always produces same output
Constant-folding benefit✗ No practical use for encode64("hello")"aGVsbG8=\n" as a constant in type inference
Return type precision△ Always String (already in RBS). Could add non-empty-string refinement but impact is small
Bundled gem issueRequires require "base64" (Ruby 4.0+). Receiver type recognition depends on gem availability

Future promotion condition: If a dedicated non-empty-string / base64-string refinement is introduced, consider moving to the deterministic group and attaching refinements to strict_encode64 / urlsafe_encode64.

MethodStatusNotes
encode64(str)🚫Deterministic. No folding benefit. Notable for including newlines (\n).
strict_encode64(str)🚫No-newline variant. Same.
urlsafe_encode64(str)🚫URL-safe variant. Same.
decode64(str)🚫Decoding. Returns binary String.
strict_decode64(str)🚫Strict variant. ArgumentError on invalid input.
urlsafe_decode64(str)🚫URL-safe variant. Same.

Digest.methods - Module.methods:hexencode (only 1 function at the module level). In practice, Digest::MD5.hexdigest(str) / Digest::SHA256.hexdigest(str) etc. class methods are the targets.

Exclusion reason (why not in the deterministic group):

AspectDetail
Determinism✓ Cryptographic hash functions are deterministic
Constant-folding benefit✗ Actual hash values for test literal inputs have no type inference use
Return type precisionhexdigest → fixed-length hex string (MD5: 32 chars, SHA256: 64 chars). Could attach a dedicated hex-string / md5-hex-string refinement
Return lengthVaries by digest algorithm. Generic refinement loses length information

Future promotion condition: If length-bearing refinements like hex-string / md5-hex-string / sha256-hex-string are added to imported-built-in-types.md, consider moving to the deterministic group and attaching refinements.

Method / ClassStatusNotes
Digest.hexencode(str)🚫Converts input string to hex representation. No folding benefit.
Digest::MD5.hexdigest(str)🚫32-char hex string. Deterministic but value is not used.
Digest::SHA1.hexdigest(str)🚫40-char hex string. Same.
Digest::SHA256.hexdigest(str)🚫64-char hex string. Same.
Digest::SHA512.hexdigest(str)🚫128-char hex string. Same.
Digest::*#digest(str) (binary)🚫Binary string.
Digest::*#update / <<🚫Destructive state accumulation.

Summary: precision uplift scenarios for excluded groups

Section titled “Summary: precision uplift scenarios for excluded groups”

All currently 🚫, but some could be promoted under these scenarios:

ScenarioTargetsPrerequisites
non-empty-string refinement expansionSecureRandom.uuid, SecureRandom.hex(n > 0), Base64.encode64, Digest::*.hexdigestnon-empty-string is established as a refinement type with auto-attachment rules for return values
Dedicated hex-string refinementSecureRandom.hex, Digest::*.hexdigestNew refinement added to imported-built-in-types.md + length information
UUID string typeSecureRandom.uuid / uuid_v4 / uuid_v7uuid-string refinement (36 chars, specific format)

© 2026 TypedDuck. Licensed under CC BY-SA 4.0.