 ///
 /// - Note: When SourceElement and TargetElement are both bridged verbatim, type
 ///   checking is deferred until elements are actually accessed.
-@inlinable // FIXME(sil-serialize-all)
+@inlinable //for performance reasons
 public func _arrayForceCast<SourceElement, TargetElement>(
   _ source: Array<SourceElement>
 ) -> Array<TargetElement> {

  return source.map { $0 as! TargetElement }
}

@_fixed_layout
@usableFromInline
internal struct _UnwrappingFailed : Error {
  @inlinable
  internal init() {}
}

extension Optional {
  @inlinable // FIXME(sil-serialize-all)
  internal func unwrappedOrError() throws -> Wrapped {
    if let x = self { return x }
    throw _UnwrappingFailed()
  }
}

/// Called by the casting machinery.
@_silgen_name("_swift_arrayDownCastConditionalIndirect")
internal func _arrayDownCastConditionalIndirect<SourceValue, TargetValue>(

/// return `nil` if any element fails to convert.
///
/// - Complexity: O(n), because each element must be checked.
@inlinable //for performance reasons
public func _arrayConditionalCast<SourceElement, TargetElement>(
  _ source: [SourceElement]
) -> [TargetElement]? {
  var successfulCasts = ContiguousArray<TargetElement>()
  successfulCasts.reserveCapacity(source.count)
  for element in source {
    if let casted = element as? TargetElement {
      successfulCasts.append(casted)
    } else {
      return nil
    }
  }
  return Array(successfulCasts)
}
