Skip to content

Commit

Permalink
Document transitions for module names and introduce enum
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon authored and andrykonchin committed Jan 17, 2025
1 parent 16938ef commit af551fa
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/org/truffleruby/core/module/ModuleFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,34 @@ public static void debugModuleChain(RubyModule module) {

private final PrependMarker start;

/**
* <pre>
* Naming modules is complicated, we try to summarize the transitions here.
* fully named (simple): module M; end -> module with givenBaseName="M" hasFullName=true
* fully named (nested): module N; module M; end; end -> module with name="N::M" hasFullName=true
* anonymous: Module.new -> #name is nil, #inspect is #<Module:0x...>
* nested-anonymous: m = Module.new; module m::N; end -> givenBaseName="N" hasFullName=false hasPartialName=true #name is "#<Module:0x...>::N"
*
* Transitions:
* * anonymous to nested-anonymous, by constant assignment
* * anonymous/nested-anonymous to full, by constant assignment (for anonymous), or lexical parent gets fully named (for nested-anonymous)
* * temporary to full, by constant assignment or lexical parent gets fully named
* * anonymous/nested-anonymous to temporary, by set_temporary_name("...") or set_temporary_name(nil)
* * temporary to temporary, by set_temporary_name("...") or set_temporary_name(nil)
* They form a lattice/total order, as it's never possible to go back from a transition
*
* Note there is no temporary to anonymous/nested-anonymous, it just stays temporary in that case.
* </pre>
*/

private final RubyModule lexicalParent;
/** Module (or class) own explicitly specified name */
/** Module (or class) own explicitly specified name: either `class Foo` or `module Foo` or a core module/class */
public final String givenBaseName;

/** Means whether a fully qualified name (with parent lexical scope names) is already set */
private boolean hasFullName = false;
/** Either fully qualified name or lazily evaluated anonymous name */
/** Either fully qualified name or lazily evaluated anonymous name, or temporary name */
private String name = null;
/** Same as {@link #name} except null if {@link #hasPartialName()} */
private ImmutableRubyString rubyStringName;
/** A temporary name assigned to an anonymous module */
private String temporaryName = null;
Expand Down

0 comments on commit af551fa

Please sign in to comment.