<commit_before>//
// Abstract distribution class
//
class Distribution {
  def newArithmeticDomain(param rank: int, type idxType, param stridable: bool) {
    compilerError("arithmetic domains not supported by this distribution");
  }

  def newAssociativeDomain(type idxType) {
    compilerError("associative domains not supported by this distribution");
  }

  def newEnumeratedDomain(type idxType) {
    compilerError("enumerated domains not supported by this distribution");
  }

  def newOpaqueDomain(type idxType) {
    compilerError("opaque domains not supported by this distribution");
  }

  def newSparseDomain(param rank: int, type idxType, dom: _domain) {
    compilerError("opaque domains not supported by this distribution");
  }
}


pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, param rank: int, type idxType = int(32),
                       param stridable: bool = false) type
  return new _domain(rank, dist.newArithmeticDomain(rank, idxType, stridable));

pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, type idxType) type
 where !__primitive("isEnumType", idxType) && idxType != opaque
  return new _domain(1, dist.newAssociativeDomain(idxType));

pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, type idxType) type
 where __primitive("isEnumType", idxType)
  return new _domain(1, dist.newEnumeratedDomain(idxType));

pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, type idxType) type
 where idxType == opaque
  return new _domain(1, dist.newOpaqueDomain(idxType));

pragma "has runtime type"
def chpl_buildSparseDomainRuntimeType(dist, dom: _domain) type
  return new _domain(dom.rank, dist.newSparseDomain(dom.rank, dom._value.idxType, dom));

def chpl_convertValueToRuntimeType(dom: _domain) type
 where dom._value:BaseDenseArithmeticDomain
  return chpl_buildDomainRuntimeType(dom._value.dist, dom._value.rank,
                            dom._value.idxType, dom._value.stridable);

def chpl_convertValueToRuntimeType(dom: _domain) type
 where dom._value:BaseSparseArithmeticDomain
  return chpl_buildSparseDomainRuntimeType(dom._value.dist, dom._value.parentDom);

def chpl_convertValueToRuntimeType(dom: _domain) type
where !dom._value:BaseArithmeticDomain
  return chpl_buildDomainRuntimeType(dom._value.dist, dom._value.idxType);


pragma "has runtime type"
def chpl_buildArrayRuntimeType(dom: _domain, type eltType) type
  return dom.buildArray(eltType);

def chpl_convertValueToRuntimeType(arr: _array) type<commit_msg>Fixed a bug in the implementation of domain runtime types for opaque domains.  Opaque domains require extra handling because the idxType passed to the chpl_buildDomainRuntimeType function is not the same as the idxType of opaque domains.  This results in two distinct runtime types for the same array, and possible type mismatches in the generated code.  Fixed this issue by creating a wrapper version of chpl_buildDomainRuntimeType that looks for opaque and calls the function on _OpaqueIndex.<commit_after>//
// Abstract distribution class
//
class Distribution {
  def newArithmeticDomain(param rank: int, type idxType, param stridable: bool) {
    compilerError("arithmetic domains not supported by this distribution");
  }

  def newAssociativeDomain(type idxType) {
    compilerError("associative domains not supported by this distribution");
  }

  def newEnumeratedDomain(type idxType) {
    compilerError("enumerated domains not supported by this distribution");
  }

  def newOpaqueDomain(type idxType) {
    compilerError("opaque domains not supported by this distribution");
  }

  def newSparseDomain(param rank: int, type idxType, dom: _domain) {
    compilerError("opaque domains not supported by this distribution");
  }
}


pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, param rank: int, type idxType = int(32),
                       param stridable: bool = false) type
  return new _domain(rank, dist.newArithmeticDomain(rank, idxType, stridable));

pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, type idxType) type
 where !__primitive("isEnumType", idxType) && idxType != opaque && idxType != _OpaqueIndex
  return new _domain(1, dist.newAssociativeDomain(idxType));

pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, type idxType) type
 where __primitive("isEnumType", idxType)
  return new _domain(1, dist.newEnumeratedDomain(idxType));

pragma "has runtime type"
def chpl_buildDomainRuntimeType(dist, type idxType) type
 where idxType == _OpaqueIndex
  return new _domain(1, dist.newOpaqueDomain(idxType));

// This function has no 'has runtime type' pragma since the idxType of
// opaque domains is _OpaqueIndex, not opaque.
def chpl_buildDomainRuntimeType(dist, type idxType) type
 where idxType == opaque
  return chpl_buildDomainRuntimeType(dist, _OpaqueIndex);

pragma "has runtime type"
def chpl_buildSparseDomainRuntimeType(dist, dom: _domain) type
  return new _domain(dom.rank, dist.newSparseDomain(dom.rank, dom._value.idxType, dom));

def chpl_convertValueToRuntimeType(dom: _domain) type
 where dom._value:BaseDenseArithmeticDomain
  return chpl_buildDomainRuntimeType(dom._value.dist, dom._value.rank,
                            dom._value.idxType, dom._value.stridable);

def chpl_convertValueToRuntimeType(dom: _domain) type
 where dom._value:BaseSparseArithmeticDomain
  return chpl_buildSparseDomainRuntimeType(dom._value.dist, dom._value.parentDom);

def chpl_convertValueToRuntimeType(dom: _domain) type
where !dom._value:BaseArithmeticDomain
  return chpl_buildDomainRuntimeType(dom._value.dist, dom._value.idxType);


pragma "has runtime type"
def chpl_buildArrayRuntimeType(dom: _domain, type eltType) type
  return dom.buildArray(eltType);

def chpl_convertValueToRuntimeType(arr: _array) type
{'fraction_non_alphanumeric': 0.0792693434430467, 'fraction_numerical': 0.0017232465965879718, 'mean_word_length': 5.499440089585666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3810178', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1654, 'n_words': 504}