New Issue: Add library routine for getting a class's dynamic type as a string

16916, “bradcray”, “Add library routine for getting a class’s dynamic type as a string”, “2021-01-08T01:38:59Z”

Within the code base, we have the ability to get the dynamic type of a class as a string, and this can be nice from a debugging / I/O perspective, however, it is not currently a user-facing feature. Doing so seems like a nice utility, where the hard questions are:

  • what should such a routine be called?
  • what module should it live in?

For example, a very trivial implementation might look like:

proc dynamicTypeAsString(expr) {
    return __primitive("class name by id",
                       __primitive("getcid", expr.borrow())
                      ):string;
}

and a more complex version might look like:

proc dynamicTypeAsString(expr, printClassMgmt = true) {
  var ret: string;

  if (isClass(expr)) {
    if (printClassMgmt) {
      if (isOwnedClass(expr)) {
        ret = "owned ";
      } else if (isBorrowedClass(expr)) {
        ret = "borrowed ";
      } else if (isSharedClass(expr)) {
        ret = "shared ";
      } else if (isUnmanagedClass(expr)) {
        ret = "unmanaged ";
      } else {
        halt("Unanticipated class management type in dynamicTypeAsString()");
      }
    }
    ret += __primitive("class name by id",
                       __primitive("getcid", expr.borrow())
                      ):string;
    return ret;
  } else {
    compilerError("dynamicTypeAsString() isn't currently implemented for non-classes");
  }
}

(where ultimately we might extend this to support non-class types as well? E.g., by printing out the static type for simple value types, information about arrays for arrays?)