Skip to content

Commit

Permalink
Hide internal classes generated docs
Browse files Browse the repository at this point in the history
Some of these could be made internal, but most could not.  The reason is
that UniFFI code needs to import them from other modules in order to
support external types.  This change mostly adds docstrings/annotations
to hide them from the generated docs.

For swift, this needed to behind an `#if` statement to keep
compatability with 5.5.  Maybe we can up the minimum version with the
next breaking release.
  • Loading branch information
bendk committed Oct 1, 2024
1 parent 305454d commit 3043009
Show file tree
Hide file tree
Showing 55 changed files with 268 additions and 17 deletions.
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/BooleanHelper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterBoolean: FfiConverter<Boolean, Byte> {
override fun lift(value: Byte): Boolean {
return value.toInt() != 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
override fun read(buf: ByteBuffer): ByteArray {
val len = buf.getInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ internal const val UNIFFI_CALLBACK_SUCCESS = 0
internal const val UNIFFI_CALLBACK_ERROR = 1
internal const val UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2

/**
* @suppress
*/
public abstract class FfiConverterCallbackInterface<CallbackInterface: Any>: FfiConverter<CallbackInterface, Long> {
internal val handleMap = UniffiHandleMap<CallbackInterface>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
{% include "Interface.kt" %}
{% include "CallbackInterfaceImpl.kt" %}

// The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object {{ ffi_converter_name }}: FfiConverterCallbackInterface<{{ interface_name }}>()
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public typealias {{ type_name }} = {{ concrete_type_name }}
{%- else %}
{%- endmatch %}

/**
* @suppress
*/
public object {{ ffi_converter_name }}: FfiConverter<{{ type_name }}, {{ ffi_type_name }}> {
override fun lift(value: {{ ffi_type_name }}): {{ type_name }} {
val builtinValue = {{ builtin|lift_fn }}(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterDuration: FfiConverterRustBuffer<java.time.Duration> {
override fun read(buf: ByteBuffer): java.time.Duration {
// Type mismatch (should be u64) but we check for overflow/underflow below
Expand Down
6 changes: 6 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/EnumTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ enum class {{ type_name }}(val value: {{ variant_discr_type|type_name(ci) }}) {
}
{% endmatch %}

/**
* @suppress
*/
public object {{ e|ffi_converter_name }}: FfiConverterRustBuffer<{{ type_name }}> {
override fun read(buf: ByteBuffer) = try {
{% if config.use_enum_entries() %}
Expand Down Expand Up @@ -84,6 +87,9 @@ sealed class {{ type_name }}{% if contains_object_references %}: Disposable {% e
companion object
}

/**
* @suppress
*/
public object {{ e|ffi_converter_name }} : FfiConverterRustBuffer<{{ type_name }}>{
override fun read(buf: ByteBuffer): {{ type_name }} {
return when(buf.getInt()) {
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/ErrorTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ sealed class {{ type_name }}: kotlin.Exception(){% if contains_object_references
}
{%- endif %}

/**
* @suppress
*/
public object {{ e|ffi_converter_name }} : FfiConverterRustBuffer<{{ type_name }}> {
override fun read(buf: ByteBuffer): {{ type_name }} {
{% if e.is_flat() %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// The FfiConverter interface handles converter types to and from the FFI
//
// All implementing objects should be public to support external types. When a
// type is external we need to import it's FfiConverter.
/**
* The FfiConverter interface handles converter types to and from the FFI
*
* All implementing objects should be public to support external types. When a
* type is external we need to import it's FfiConverter.
*
* @suppress
*/
public interface FfiConverter<KotlinType, FfiType> {
// Convert an FFI type to a Kotlin type
fun lift(value: FfiType): KotlinType
Expand Down Expand Up @@ -64,7 +68,11 @@ public interface FfiConverter<KotlinType, FfiType> {
}
}

// FfiConverter that uses `RustBuffer` as the FfiType
/**
* FfiConverter that uses `RustBuffer` as the FfiType
*
* @suppress
*/
public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/Float32Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterFloat: FfiConverter<Float, Float> {
override fun lift(value: Float): Float {
return value
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/Float64Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterDouble: FfiConverter<Double, Double> {
override fun lift(value: Double): Double {
return value
Expand Down
12 changes: 10 additions & 2 deletions uniffi_bindgen/src/bindings/kotlin/templates/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ internal open class UniffiRustCallStatus : Structure() {

class InternalException(message: String) : kotlin.Exception(message)

// Each top-level error class has a companion object that can lift the error from the call status's rust buffer
/**
* Each top-level error class has a companion object that can lift the error from the call status's rust buffer
*
* @suppress
*/
interface UniffiRustCallStatusErrorHandler<E> {
fun lift(error_buf: RustBuffer.ByValue): E;
}
Expand Down Expand Up @@ -73,7 +77,11 @@ private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustC
}
}

// UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
/**
* UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
*
* @suppress
*/
object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
override fun lift(error_buf: RustBuffer.ByValue): InternalException {
RustBuffer.free(error_buf)
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/Int16Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterShort: FfiConverter<Short, Short> {
override fun lift(value: Short): Short {
return value
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/Int32Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterInt: FfiConverter<Int, Int> {
override fun lift(value: Int): Int {
return value
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/Int64Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterLong: FfiConverter<Long, Long> {
override fun lift(value: Long): Long {
return value
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/Int8Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterByte: FfiConverter<Byte, Byte> {
override fun lift(value: Byte): Byte {
return value
Expand Down
4 changes: 4 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/MapTemplate.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{%- let key_type_name = key_type|type_name(ci) %}
{%- let value_type_name = value_type|type_name(ci) %}

/**
* @suppress
*/
public object {{ ffi_converter_name }}: FfiConverterRustBuffer<Map<{{ key_type_name }}, {{ value_type_name }}>> {
override fun read(buf: ByteBuffer): Map<{{ key_type_name }}, {{ value_type_name }}> {
val len = buf.getInt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

// The cleaner interface for Object finalization code to run.
// This is the entry point to any implementation that we're using.
//
// The cleaner registers objects and returns cleanables, so now we are
// defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
// different implmentations available at compile time.
/**
* The cleaner interface for Object finalization code to run.
* This is the entry point to any implementation that we're using.
*
* The cleaner registers objects and returns cleanables, so now we are
* defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
* different implmentations available at compile time.
*
* @suppress
*/
interface UniffiCleaner {
interface Cleanable {
fun clean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ open class {{ impl_class_name }}: Disposable, AutoCloseable, {{ interface_name }
{% include "CallbackInterfaceImpl.kt" %}
{%- endif %}

/**
* @suppress
*/
public object {{ ffi_converter_name }}: FfiConverter<{{ type_name }}, Pointer> {
{%- if obj.has_callback_interface() %}
internal val handleMap = UniffiHandleMap<{{ type_name }}>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{%- let inner_type_name = inner_type|type_name(ci) %}

/**
* @suppress
*/
public object {{ ffi_converter_name }}: FfiConverterRustBuffer<{{ inner_type_name }}?> {
override fun read(buf: ByteBuffer): {{ inner_type_name }}? {
if (buf.get().toInt() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class {{ type_name }} {
}
{%- endif %}

/**
* @suppress
*/
public object {{ rec|ffi_converter_name }}: FfiConverterRustBuffer<{{ type_name }}> {
override fun read(buf: ByteBuffer): {{ type_name }} {
{%- if rec.has_fields() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// A rust-owned buffer is represented by its capacity, its current length, and a
// pointer to the underlying data.

/**
* @suppress
*/
@Structure.FieldOrder("capacity", "len", "data")
open class RustBuffer : Structure() {
// Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
Expand Down Expand Up @@ -54,6 +57,8 @@ open class RustBuffer : Structure() {
* Required for callbacks taking in an out pointer.
*
* Size is the sum of all values in the struct.
*
* @suppress
*/
class RustBufferByReference : ByReference(16) {
/**
Expand Down Expand Up @@ -88,7 +93,7 @@ class RustBufferByReference : ByReference(16) {
// completeness.

@Structure.FieldOrder("len", "data")
open class ForeignBytes : Structure() {
internal open class ForeignBytes : Structure() {
@JvmField var len: Int = 0
@JvmField var data: Pointer? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{%- let inner_type_name = inner_type|type_name(ci) %}

/**
* @suppress
*/
public object {{ ffi_converter_name }}: FfiConverterRustBuffer<List<{{ inner_type_name }}>> {
override fun read(buf: ByteBuffer): List<{{ inner_type_name }}> {
val len = buf.getInt()
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/StringHelper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
// Note: we don't inherit from FfiConverterRustBuffer, because we use a
// special encoding when lowering/lifting. We can use `RustBuffer.len` to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterTimestamp: FfiConverterRustBuffer<java.time.Instant> {
override fun read(buf: ByteBuffer): java.time.Instant {
val seconds = buf.getLong()
Expand Down
9 changes: 8 additions & 1 deletion uniffi_bindgen/src/bindings/kotlin/templates/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ interface Disposable {
}
}

/**
* @suppress
*/
inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
try {
block(this)
Expand All @@ -30,7 +33,11 @@ inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
}
}

/** Used to instantiate an interface without an actual pointer, for fakes in tests, mostly. */
/**
* Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
*
* @suppress
* */
object NoPointer

{%- for type_ in ci.iter_types() %}
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/UInt16Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterUShort: FfiConverter<UShort, Short> {
override fun lift(value: Short): UShort {
return value.toUShort()
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/UInt32Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterUInt: FfiConverter<UInt, Int> {
override fun lift(value: Int): UInt {
return value.toUInt()
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/UInt64Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterULong: FfiConverter<ULong, Long> {
override fun lift(value: Long): ULong {
return value.toULong()
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/UInt8Helper.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @suppress
*/
public object FfiConverterUByte: FfiConverter<UByte, Byte> {
override fun lift(value: Byte): UByte {
return value.toUByte()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterBool : FfiConverter {
typealias FfiType = Int8
typealias SwiftType = Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,45 @@
{% include "CallbackInterfaceImpl.swift" %}

// FfiConverter protocol for callback interfaces
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct {{ ffi_converter_name }} {
fileprivate static var handleMap = UniffiHandleMap<{{ type_name }}>()
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
extension {{ ffi_converter_name }} : FfiConverter {
typealias SwiftType = {{ type_name }}
typealias FfiType = UInt64

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lift(_ handle: UInt64) throws -> SwiftType {
try handleMap.get(handle: handle)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
let handle: UInt64 = try readInt(&buf)
return try lift(handle)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lower(_ v: SwiftType) -> UInt64 {
return handleMap.insert(obj: v)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
writeInt(&buf, lower(v))
}
Expand Down
Loading

0 comments on commit 3043009

Please sign in to comment.