code: public static Variable upcastToGeneratedBuilder(
        SourceBuilder code, Datatype datatype, String builder) {
      return code.scope().computeIfAbsent(Declaration.UPCAST, () -> {
        Variable base = new Variable("base");
        code.addLine(UPCAST_COMMENT)
            .addLine("%s %s = %s;", datatype.getGeneratedBuilder(), base, builder);
        return base;
      });
    }
docs: Upcasts a Builder instance to the generated superclass, to allow access to private fields.
  
  <p>Reuses an existing upcast instance if one was already declared in this scope.
  
  @param code the {@link SourceBuilder} to add the declaration to
  @param datatype metadata about the user type the builder is being generated for
  @param builder the Builder instance to upcast
  @returns a variable holding the upcasted instance