@ JvmOverloads <EOL> inline fun withSpark ( props : Map < String , Any > = emptyMap ( ) , master : String = SparkConf ( ) . get ( "<STR_LIT>" , "<STR_LIT>" ) , appName : String = "<STR_LIT>" , logLevel : SparkLogLevel = ERROR , func : KSparkSession . ( ) -> Unit , )

{ <EOL> val builder = SparkSession <EOL> . builder ( ) <EOL> . master ( master ) <EOL> . appName ( appName ) <EOL> . apply { <EOL> props . forEach { <EOL> when ( val value = it . value ) { <EOL> is String -> config ( it . key , value ) <EOL> is Boolean -> config ( it . key , value ) <EOL> is Long -> config ( it . key , value ) <EOL> is Double -> config ( it . key , value ) <EOL> else -> throw IllegalArgumentException ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> } <EOL> withSpark ( builder , logLevel , func ) <EOL> }

/**
 * Wrapper for spark creation which allows setting different spark params.
 *
 * @param props spark options, value types are runtime-checked for type-correctness
 * @param master Sets the Spark master URL to connect to, such as "local" to run locally, "local[4]" to
 * run locally with 4 cores, or "spark://master:7077" to run on a Spark standalone cluster. By default, it
 * tries to get the system value "spark.master", otherwise it uses "local[*]"
 * @param appName Sets a name for the application, which will be shown in the Spark web UI.
 * If no application name is set, a randomly generated name will be used.
 * @param logLevel Control our logLevel. This overrides any user-defined log settings.
 * @param func function which will be executed in context of [KSparkSession] (it means that `this` inside block will point to [KSparkSession])
 */


@ JvmOverloads <EOL> inline fun withSpark ( builder : Builder , logLevel : SparkLogLevel = ERROR , func : KSparkSession . ( ) -> Unit )

{ <EOL> builder <EOL> . getOrCreate ( ) <EOL> . apply { <EOL> KSparkSession ( this ) . apply { <EOL> sparkContext . setLogLevel ( logLevel ) <EOL> func ( ) <EOL> spark . stop ( ) <EOL> } <EOL> } <EOL> }

/**
 * Wrapper for spark creation which allows setting different spark params.
 *
 * @param builder A [SparkSession.Builder] object, configured how you want.
 * @param logLevel Control our logLevel. This overrides any user-defined log settings.
 * @param func function which will be executed in context of [KSparkSession] (it means that `this` inside block will point to [KSparkSession])
 */


@ JvmOverloads <EOL> inline fun withSpark ( sparkConf : SparkConf , logLevel : SparkLogLevel = ERROR , func : KSparkSession . ( ) -> Unit )

{ <EOL> withSpark ( builder = SparkSession . builder ( ) . config ( sparkConf ) , logLevel = logLevel , func = func , ) <EOL> }

/**
 * Wrapper for spark creation which copies params from [sparkConf].
 *
 * @param sparkConf Sets a list of config options based on this.
 * @param logLevel Control our logLevel. This overrides any user-defined log settings.
 * @param func function which will be executed in context of [KSparkSession] (it means that `this` inside block will point to [KSparkSession])
 */


@ JvmOverloads <EOL> fun withSparkStreaming ( batchDuration : Duration = Durations . seconds ( <NUM_LIT:1L> ) , checkpointPath : String ? = null , hadoopConf : Configuration = SparkHadoopUtil . get ( ) . conf ( ) , createOnError : Boolean = false , props : Map < String , Any > = emptyMap ( ) , master : String = SparkConf ( ) . get ( "<STR_LIT>" , "<STR_LIT>" ) , appName : String = "<STR_LIT>" , timeout : Long = - <NUM_LIT:1L> , startStreamingContext : Boolean = true , func : KSparkStreamingSession . ( ) -> Unit , )

{ <EOL> var kSparkStreamingSession : KSparkStreamingSession ? = null <EOL> val creatingFunc = { <EOL> val sc = SparkConf ( ) <EOL> . setAppName ( appName ) <EOL> . setMaster ( master ) <EOL> . setAll ( props . map { ( key , value ) -> key X value . toString ( ) } . asScalaIterable ( ) ) <EOL> val ssc = JavaStreamingContext ( sc , batchDuration ) <EOL> ssc . checkpoint ( checkpointPath ) <EOL> kSparkStreamingSession = KSparkStreamingSession ( ssc ) <EOL> func ( kSparkStreamingSession ! ! ) <EOL> ssc <EOL> } <EOL> val ssc = when { <EOL> checkpointPath != null -> <EOL> JavaStreamingContext . getOrCreate ( checkpointPath , creatingFunc , hadoopConf , createOnError ) <EOL> else -> creatingFunc ( ) <EOL> } <EOL> if ( startStreamingContext ) { <EOL> ssc . start ( ) <EOL> kSparkStreamingSession ? . invokeRunAfterStart ( ) <EOL> } <EOL> ssc . awaitTerminationOrTimeout ( timeout ) <EOL> ssc . stop ( ) <EOL> }

/**
 * Wrapper for spark streaming creation. `spark: SparkSession` and `ssc: JavaStreamingContext` are provided, started,
 * awaited, and stopped automatically.
 * The use of a checkpoint directory is optional.
 * If checkpoint data exists in the provided `checkpointPath`, then StreamingContext will be
 * recreated from the checkpoint data. If the data does not exist, then the provided factory
 * will be used to create a JavaStreamingContext.
 *
 * @param batchDuration The time interval at which streaming data will be divided into batches. Defaults to 1
 * second.
 * @param checkpointPath If checkpoint data exists in the provided `checkpointPath`, then StreamingContext will be
 * recreated from the checkpoint data. If the data does not exist (or `null` is provided),
 * then the streaming context will be built using the other provided parameters.
 * @param hadoopConf Only used if [checkpointPath] is given. Hadoop configuration if necessary for reading from
 * any HDFS compatible file system.
 * @param createOnError Only used if [checkpointPath] is given. Whether to create a new JavaStreamingContext if
 * there is an error in reading checkpoint data.
 * @param props Spark options, value types are runtime-checked for type-correctness.
 * @param master Sets the Spark master URL to connect to, such as "local" to run locally, "local[4]" to
 * run locally with 4 cores, or "spark://master:7077" to run on a Spark standalone cluster.
 * By default, it tries to get the system value "spark.master", otherwise it uses "local[*]".
 * @param appName Sets a name for the application, which will be shown in the Spark web UI.
 * If no application name is set, a randomly generated name will be used.
 * @param timeout The time in milliseconds to wait for the stream to terminate without input. -1 by default,
 * this means no timeout.
 * @param startStreamingContext Defaults to `true`. If set to `false`, then the streaming context will not be started.
 * @param func Function which will be executed in context of [KSparkStreamingSession] (it means that
 * `this` inside block will point to [KSparkStreamingSession])
 */


inline fun < reified T > SparkSession . broadcast ( value : T ) : Broadcast < T >

= try { <EOL> sparkContext . broadcast ( value , encoder < T > ( ) . clsTag ( ) ) <EOL> } catch ( e : ClassNotFoundException ) { <EOL> JavaSparkContext ( sparkContext ) . broadcast ( value ) <EOL> }

/**
 * Broadcast a read-only variable to the cluster, returning a
 * [org.apache.spark.broadcast.Broadcast] object for reading it in distributed functions.
 * The variable will be sent to each cluster only once.
 *
 * @param value value to broadcast to the Spark nodes
 * @return `Broadcast` object, a read-only variable cached on each machine
 */


@ Deprecated ( "<STR_LIT>" , ReplaceWith ( "<STR_LIT>" ) , DeprecationLevel . WARNING ) <EOL> inline fun < reified T > SparkContext . broadcast ( value : T ) : Broadcast < T >

= try { <EOL> broadcast ( value , encoder < T > ( ) . clsTag ( ) ) <EOL> } catch ( e : ClassNotFoundException ) { <EOL> JavaSparkContext ( this ) . broadcast ( value ) <EOL> }

/**
 * Broadcast a read-only variable to the cluster, returning a
 * [org.apache.spark.broadcast.Broadcast] object for reading it in distributed functions.
 * The variable will be sent to each cluster only once.
 *
 * @param value value to broadcast to the Spark nodes
 * @return `Broadcast` object, a read-only variable cached on each machine
 * @see broadcast
 */


operator fun < T > Product1 < T > . component1 ( ) : T

= this . _1 ( )

/**
 *
 * This file provides the operator functions to destructuring for Scala classes implementing ProductX, like Tuples.
 *
 * This means you can type `val (a, b, c, d) = yourTuple` to unpack its values,
 * similar to how [Pair], [Triple] and other data classes work in Kotlin.
 *
 */


@ PublishedApi <EOL> internal inline fun < R > processAllDirectives ( ignoreDirectives : List < ValueDirective < TargetBackend > > , processDirective : ( ValueDirective < TargetBackend > , SuppressionResult ) -> R , ) : R ?

{ <EOL> val modules = testServices . moduleStructure . modules <EOL> for ( ignoreDirective in ignoreDirectives ) { <EOL> val suppressionResult = modules <EOL> . map { failuresInModuleAreIgnored ( it , ignoreDirective ) } <EOL> . firstOrNull { it . testMuted } <EOL> ? : continue <EOL> return processDirective ( ignoreDirective , suppressionResult ) <EOL> } <EOL> return null <EOL> }

/**
 * Finds the first directive from [ignoreDirectives] that mutes this test on the current backend, and
 * runs [processDirective] for that directive.
 *
 * Returns whatever [processDirective] returns, or `null` if this test will not be muted.
 */


@ PublishedApi <EOL> internal fun processMutedTest ( failed : Boolean , directive : ValueDirective < TargetBackend > , suppressionResult : SuppressionResult , ) : AssertionError ?

{ <EOL> if ( failed ) return null <EOL> val firstModule = testServices . moduleStructure . modules . first ( ) <EOL> val targetBackend = testServices . defaultsProvider . defaultTargetBackend ? : firstModule . targetBackend <EOL> val message = buildString { <EOL> append ( "<STR_LIT>" ) <EOL> targetBackend ? . name ? . let { <EOL> append ( it ) <EOL> append ( "<STR_LIT>" ) <EOL> } <EOL> append ( directive . name ) <EOL> append ( "<STR_LIT>" ) <EOL> append ( firstModule . frontendKind ) <EOL> assert ( suppressionResult . testMuted ) <EOL> suppressionResult . matchedBackend ? . let { <EOL> append ( "<STR_LIT>" ) <EOL> append ( it ) <EOL> } <EOL> } <EOL> return AssertionError ( message ) <EOL> }

/**
 * Returns `null` if [failed] is `true`, otherwise returns an [AssertionError] with a message reminding to remove [directive]
 * from the test to unmute it.
 */


inline fun < reified ExpectedError : Throwable > checkMuted ( ignoreDirectives : List < ValueDirective < TargetBackend > > , block : ( ) -> Unit , )

{ <EOL> val expectedError : ExpectedError ? = try { <EOL> block ( ) <EOL> null <EOL> } catch ( e : Throwable ) { <EOL> e as? ExpectedError ? : throw e <EOL> } <EOL> processAllDirectives < Unit > ( ignoreDirectives ) { ignoreDirective , suppressionResult -> <EOL> processMutedTest ( failed = expectedError != null , ignoreDirective , suppressionResult ) ? . let { throw it } <EOL> return <EOL> } <EOL> expectedError ? . let { throw it } <EOL> }

/**
 * Runs [block]. If this test has been muted by one of [ignoreDirectives] **and** [block] returns without throwing an exception,
 * throws an [AssertionError] reminding you to unmute the test.
 *
 * If this test has been muted by one of [ignoreDirectives] **and** [block] throws an exception of type [ExpectedError],
 * catches that exception and returns normally.
 *
 * If [block] throws an exception of some other type, rethrows it.
 *
 * If this test hasn't been muted **and** [block] throws any exception, rethrows that exception as well.
 */


private fun ContentPage . findConstructorsWithBriefs ( ) : List < ContentNode >

{ <EOL> val constructorsTable = this . content . dfs { <EOL> it is ContentTable && it . dci . kind == ContentKind . Constructors <EOL> } as ContentTable <EOL> val constructorsWithBriefs = constructorsTable . dfs { <EOL> it is ContentGroup && it . dci . kind == ContentKind . SourceSetDependentHint <EOL> } ? . children <EOL> assertNotNull ( constructorsWithBriefs , "<STR_LIT>" ) <EOL> return constructorsWithBriefs <EOL> }

/**
 * All constructors are merged in one block (like overloaded functions).
 * That leads to the structure where content block (`constructorsWithBriefs`) consist of plain list
 * of constructors and briefs. In that list constructor is above, brief is below.
 */


fun isSubtypeOfClass ( state : TypeCheckerState , typeConstructor : TypeConstructorMarker , superConstructor : TypeConstructorMarker ) : Boolean

{ <EOL> if ( typeConstructor == superConstructor ) return true <EOL> with ( state . typeSystemContext ) { <EOL> for ( superType in typeConstructor . supertypes ( ) ) { <EOL> if ( isSubtypeOfClass ( state , superType . typeConstructor ( ) , superConstructor ) ) { <EOL> return true <EOL> } <EOL> } <EOL> } <EOL> return false <EOL> }

/**
 * It matches class types but ignores their type parameters
 *
 * Consider the following example:
 *
 * ```
 * abstract class Foo<T>
 * class FooBar : Foo<Any>()
 * ```
 *
 * In this case `isSubtypeOfClass` returns `true` for `FooBar` and `Foo<T>` input arguments
 * But `isSubtypeOf` returns `false` for the same input arguments
 */


private fun selectOnlyPureKotlinSupertypes ( state : TypeCheckerState , supertypes : List < SimpleTypeMarker > ) : List < SimpleTypeMarker >

= with ( state . typeSystemContext ) { <EOL> if ( supertypes . size < <NUM_LIT:2> ) return supertypes <EOL> val allPureSupertypes = supertypes . filter { <EOL> it . asArgumentList ( ) . all ( this ) { it . getType ( ) . asFlexibleType ( ) == null } <EOL> } <EOL> return if ( allPureSupertypes . isNotEmpty ( ) ) allPureSupertypes else supertypes <EOL> }

/**
 * If we have several paths to some interface, we should prefer pure kotlin path.
 * Example:
 *
 * class MyList : AbstractList<String>(), MutableList<String>
 *
 * We should see `String` in `get` function and others, also MyList is not subtype of MutableList<String?>
 *
 * More tests: javaAndKotlinSuperType & purelyImplementedCollection folder
 */


/**
 * [I.<caret_1>length] is unresolved
 * [String.<caret_2>length] is resolved
 */


private fun makeMutable ( buffer : Array < Any ? > ? ) : Array < Any ? >

{ <EOL> if ( buffer == null ) { <EOL> return mutableBuffer ( ) <EOL> } <EOL> if ( isMutable ( buffer ) ) { <EOL> return buffer <EOL> } <EOL> return buffer . copyInto ( mutableBuffer ( ) , endIndex = buffer . size . coerceAtMost ( MAX_BUFFER_SIZE ) ) <EOL> }

/**
 * Checks if [buffer] is mutable and returns it or its mutable copy.
 */


private fun pushFilledTail ( root : Array < Any ? > ? , filledTail : Array < Any ? > , newTail : Array < Any ? > )

= when { <EOL> size shr LOG_MAX_BUFFER_SIZE > <NUM_LIT:1> shl rootShift -> { <EOL> this . root = pushTail ( mutableBufferWith ( root ) , filledTail , rootShift + LOG_MAX_BUFFER_SIZE ) <EOL> this . tail = newTail <EOL> this . rootShift += LOG_MAX_BUFFER_SIZE <EOL> this . size += <NUM_LIT:1> <EOL> } <EOL> root == null -> { <EOL> this . root = filledTail <EOL> this . tail = newTail <EOL> this . size += <NUM_LIT:1> <EOL> } <EOL> else -> { <EOL> this . root = pushTail ( root , filledTail , rootShift ) <EOL> this . tail = newTail <EOL> this . size += <NUM_LIT:1> <EOL> } <EOL> }

/**
 * Appends the specified entirely filled [tail] as a leaf buffer to the next free position in the [root] trie.
 */


private fun pushTail ( root : Array < Any ? > ? , tail : Array < Any ? > , shift : Int ) : Array < Any ? >

{ <EOL> val index = indexSegment ( size - <NUM_LIT:1> , shift ) <EOL> val mutableRoot = makeMutable ( root ) <EOL> if ( shift == LOG_MAX_BUFFER_SIZE ) { <EOL> mutableRoot [ index ] = tail <EOL> } else { <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> mutableRoot [ index ] = pushTail ( mutableRoot [ index ] as Array < Any ? > ? , tail , shift - LOG_MAX_BUFFER_SIZE ) <EOL> } <EOL> return mutableRoot <EOL> }

/**
 * Appends the specified entirely filled [tail] as a leaf buffer to the next free position in the [root] trie.
 * The trie must not be filled entirely.
 */


private fun pushBuffersIncreasingHeightIfNeeded ( root : Array < Any ? > ? , rootSize : Int , buffers : Array < Array < Any ? > > ) : Array < Any ? >

{ <EOL> val buffersIterator = buffers . iterator ( ) <EOL> var mutableRoot = when { <EOL> rootSize shr LOG_MAX_BUFFER_SIZE < <NUM_LIT:1> shl rootShift -> <EOL> pushBuffers ( root , rootSize , rootShift , buffersIterator ) <EOL> else -> <EOL> makeMutable ( root ) <EOL> } <EOL> while ( buffersIterator . hasNext ( ) ) { <EOL> rootShift += LOG_MAX_BUFFER_SIZE <EOL> mutableRoot = mutableBufferWith ( mutableRoot ) <EOL> pushBuffers ( mutableRoot , <NUM_LIT:1> shl rootShift , rootShift , buffersIterator ) <EOL> } <EOL> return mutableRoot <EOL> }

/**
 * Adds all buffers from [buffers] as leaf nodes to the [root].
 * If the [root] has less available leaves for the buffers, height of the trie is increased.
 *
 * Returns root of the resulting trie.
 */


private fun pushBuffers ( root : Array < Any ? > ? , rootSize : Int , shift : Int , buffersIterator : Iterator < Array < Any ? > > ) : Array < Any ? >

{ <EOL> check ( buffersIterator . hasNext ( ) ) <EOL> check ( shift >= <NUM_LIT:0> ) <EOL> if ( shift == <NUM_LIT:0> ) { <EOL> return buffersIterator . next ( ) <EOL> } <EOL> val mutableRoot = makeMutable ( root ) <EOL> var index = indexSegment ( rootSize , shift ) <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> mutableRoot [ index ] = <EOL> pushBuffers ( mutableRoot [ index ] as Array < Any ? > ? , rootSize , shift - LOG_MAX_BUFFER_SIZE , buffersIterator ) <EOL> while ( ++ index < MAX_BUFFER_SIZE && buffersIterator . hasNext ( ) ) { <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> mutableRoot [ index ] = <EOL> pushBuffers ( mutableRoot [ index ] as Array < Any ? > ? , <NUM_LIT:0> , shift - LOG_MAX_BUFFER_SIZE , buffersIterator ) <EOL> } <EOL> return mutableRoot <EOL> }

/**
 * Adds buffers from the [buffersIterator] as leaf nodes.
 * As the result [root] is entirely filled, or all buffers are added.
 *
 * Returns the resulting root.
 */


private fun insertIntoRoot ( root : Array < Any ? > , shift : Int , index : Int , element : Any ? , elementCarry : ObjectRef ) : Array < Any ? >

{ <EOL> val bufferIndex = indexSegment ( index , shift ) <EOL> if ( shift == <NUM_LIT:0> ) { <EOL> elementCarry . value = root [ MAX_BUFFER_SIZE_MINUS_ONE ] <EOL> val mutableRoot = root . copyInto ( makeMutable ( root ) , bufferIndex + <NUM_LIT:1> , bufferIndex , MAX_BUFFER_SIZE_MINUS_ONE ) <EOL> mutableRoot [ bufferIndex ] = element <EOL> return mutableRoot <EOL> } <EOL> val mutableRoot = makeMutable ( root ) <EOL> val lowerLevelShift = shift - LOG_MAX_BUFFER_SIZE <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> mutableRoot [ bufferIndex ] = <EOL> insertIntoRoot ( mutableRoot [ bufferIndex ] as Array < Any ? > , lowerLevelShift , index , element , elementCarry ) <EOL> for ( i in bufferIndex + <NUM_LIT:1> until MAX_BUFFER_SIZE ) { <EOL> if ( mutableRoot [ i ] == null ) break <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> mutableRoot [ i ] = <EOL> insertIntoRoot ( mutableRoot [ i ] as Array < Any ? > , lowerLevelShift , <NUM_LIT:0> , elementCarry . value , elementCarry ) <EOL> } <EOL> return mutableRoot <EOL> }

/**
 * Insert the specified [element] into the [root] trie at the specified trie [index].
 *
 * [elementCarry] contains the last element of this trie that was popped out by the insertion operation.
 *
 * @return new root trie or this modified trie, if it's already mutable
 */


private fun insertIntoRoot ( elements : Collection < E > , index : Int , rightShift : Int , buffers : Array < Array < Any ? > ? > , nullBuffers : Int , nextBuffer : Array < Any ? > )

{ <EOL> checkNotNull ( root ) <EOL> val startLeafIndex = index shr LOG_MAX_BUFFER_SIZE <EOL> val startLeaf = shiftLeafBuffers ( startLeafIndex , rightShift , buffers , nullBuffers , nextBuffer ) <EOL> val lastLeafIndex = ( rootSize ( ) shr LOG_MAX_BUFFER_SIZE ) - <NUM_LIT:1> <EOL> val newNullBuffers = nullBuffers - ( lastLeafIndex - startLeafIndex ) <EOL> val newNextBuffer = if ( newNullBuffers < nullBuffers ) buffers [ newNullBuffers ] ! ! else nextBuffer <EOL> splitToBuffers ( elements , index , startLeaf , MAX_BUFFER_SIZE , buffers , newNullBuffers , newNextBuffer ) <EOL> }

/**
 * Inserts the [elements] into the [root] at the given [index].
 *
 * Affected elements are copied to the [buffers] split into [nullBuffers] buffers.
 * Elements that do not fit [nullBuffers] buffers are copied to the [nextBuffer].
 */


private fun shiftLeafBuffers ( startLeafIndex : Int , rightShift : Int , buffers : Array < Array < Any ? > ? > , nullBuffers : Int , nextBuffer : Array < Any ? > ) : Array < Any ? >

{ <EOL> checkNotNull ( root ) <EOL> val leafCount = rootSize ( ) shr LOG_MAX_BUFFER_SIZE <EOL> val leafBufferIterator = leafBufferIterator ( leafCount ) <EOL> var bufferIndex = nullBuffers <EOL> var buffer = nextBuffer <EOL> while ( leafBufferIterator . previousIndex ( ) != startLeafIndex ) { <EOL> val currentBuffer = leafBufferIterator . previous ( ) <EOL> currentBuffer . copyInto ( buffer , <NUM_LIT:0> , MAX_BUFFER_SIZE - rightShift , MAX_BUFFER_SIZE ) <EOL> buffer = makeMutableShiftingRight ( currentBuffer , rightShift ) <EOL> buffers [ -- bufferIndex ] = buffer <EOL> } <EOL> return leafBufferIterator . previous ( ) <EOL> }

/**
 * Shifts elements in the [root] to the right by the given [rightShift] position starting from the end.
 *
 * Shifting stops when elements of the leaf at [startLeafIndex] are reached.
 * Last elements whose indexes become bigger than [rootSize] are copied to the [nextBuffer].
 * Shifted leaves are stored in the [buffers] starting from the given [nullBuffers] index.
 *
 * Returns leaf at the [startLeafIndex].
 */


private fun splitToBuffers ( elements : Collection < E > , index : Int , startBuffer : Array < Any ? > , startBufferSize : Int , buffers : Array < Array < Any ? > ? > , nullBuffers : Int , nextBuffer : Array < Any ? > )

{ <EOL> check ( nullBuffers >= <NUM_LIT:1> ) <EOL> val firstBuffer = makeMutable ( startBuffer ) <EOL> buffers [ <NUM_LIT:0> ] = firstBuffer <EOL> var newNextBuffer = nextBuffer <EOL> var newNullBuffers = nullBuffers <EOL> val startBufferStartIndex = index and MAX_BUFFER_SIZE_MINUS_ONE <EOL> val endBufferEndIndex = ( index + elements . size - <NUM_LIT:1> ) and MAX_BUFFER_SIZE_MINUS_ONE <EOL> val elementsToShift = startBufferSize - startBufferStartIndex <EOL> if ( endBufferEndIndex + elementsToShift < MAX_BUFFER_SIZE ) { <EOL> firstBuffer . copyInto ( newNextBuffer , endBufferEndIndex + <NUM_LIT:1> , startBufferStartIndex , startBufferSize ) <EOL> } else { <EOL> val toCopyToLast = endBufferEndIndex + elementsToShift - MAX_BUFFER_SIZE + <NUM_LIT:1> <EOL> if ( nullBuffers == <NUM_LIT:1> ) { <EOL> newNextBuffer = firstBuffer <EOL> } else { <EOL> newNextBuffer = mutableBuffer ( ) <EOL> buffers [ -- newNullBuffers ] = newNextBuffer <EOL> } <EOL> firstBuffer . copyInto ( nextBuffer , <NUM_LIT:0> , startBufferSize - toCopyToLast , startBufferSize ) <EOL> firstBuffer . copyInto ( newNextBuffer , endBufferEndIndex + <NUM_LIT:1> , startBufferStartIndex , startBufferSize - toCopyToLast ) <EOL> } <EOL> val elementsIterator = elements . iterator ( ) <EOL> copyToBuffer ( firstBuffer , startBufferStartIndex , elementsIterator ) <EOL> for ( i in <NUM_LIT:1> until newNullBuffers ) { <EOL> buffers [ i ] = copyToBuffer ( mutableBuffer ( ) , <NUM_LIT:0> , elementsIterator ) <EOL> } <EOL> copyToBuffer ( newNextBuffer , <NUM_LIT:0> , elementsIterator ) <EOL> }

/**
 * Inserts [elements] into [startBuffer] of size [startBufferSize] and splits the result into [nullBuffers] buffers.
 *
 * Elements that do not fit [nullBuffers] buffers are copied to the [nextBuffer].
 */


private fun removeFromRootAt ( root : Array < Any ? > , shift : Int , index : Int , tailCarry : ObjectRef ) : Array < Any ? >

{ <EOL> val bufferIndex = indexSegment ( index , shift ) <EOL> if ( shift == <NUM_LIT:0> ) { <EOL> val removedElement = root [ bufferIndex ] <EOL> val mutableRoot = root . copyInto ( makeMutable ( root ) , bufferIndex , bufferIndex + <NUM_LIT:1> , MAX_BUFFER_SIZE ) <EOL> mutableRoot [ MAX_BUFFER_SIZE - <NUM_LIT:1> ] = tailCarry . value <EOL> tailCarry . value = removedElement <EOL> return mutableRoot <EOL> } <EOL> var bufferLastIndex = MAX_BUFFER_SIZE_MINUS_ONE <EOL> if ( root [ bufferLastIndex ] == null ) { <EOL> bufferLastIndex = indexSegment ( rootSize ( ) - <NUM_LIT:1> , shift ) <EOL> } <EOL> val mutableRoot = makeMutable ( root ) <EOL> val lowerLevelShift = shift - LOG_MAX_BUFFER_SIZE <EOL> for ( i in bufferLastIndex downTo bufferIndex + <NUM_LIT:1> ) { <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> mutableRoot [ i ] = removeFromRootAt ( mutableRoot [ i ] as Array < Any ? > , lowerLevelShift , <NUM_LIT:0> , tailCarry ) <EOL> } <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> mutableRoot [ bufferIndex ] = <EOL> removeFromRootAt ( mutableRoot [ bufferIndex ] as Array < Any ? > , lowerLevelShift , index , tailCarry ) <EOL> return mutableRoot <EOL> }

/**
 * Removes element from trie at the specified trie [index].
 *
 * [tailCarry] on input contains the first element of the adjacent trie to fill the last vacant element with.
 * [tailCarry] on output contains the first element of this trie.
 *
 * @return the new root of the trie.
 */


private fun pullLastBufferFromRoot ( root : Array < Any ? > ? , rootSize : Int , shift : Int )

{ <EOL> if ( shift == <NUM_LIT:0> ) { <EOL> this . root = null <EOL> this . tail = root ? : emptyArray ( ) <EOL> this . size = rootSize <EOL> this . rootShift = shift <EOL> return <EOL> } <EOL> val tailCarry = ObjectRef ( null ) <EOL> val newRoot = pullLastBuffer ( root ! ! , shift , rootSize , tailCarry ) ! ! <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> this . tail = tailCarry . value as Array < Any ? > <EOL> this . size = rootSize <EOL> if ( newRoot [ <NUM_LIT:1> ] == null ) { <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> this . root = newRoot [ <NUM_LIT:0> ] as Array < Any ? > ? <EOL> this . rootShift = shift - LOG_MAX_BUFFER_SIZE <EOL> } else { <EOL> this . root = newRoot <EOL> this . rootShift = shift <EOL> } <EOL> }

/**
 * Extracts the last entirely filled leaf buffer from the trie of this vector and makes it a tail in this
 *
 * Used when there are no elements left in current tail.
 *
 * Requires the trie to contain at least one leaf buffer.
 */


private fun pullLastBuffer ( root : Array < Any ? > , shift : Int , rootSize : Int , tailCarry : ObjectRef ) : Array < Any ? > ?

{ <EOL> val bufferIndex = indexSegment ( rootSize - <NUM_LIT:1> , shift ) <EOL> val newBufferAtIndex = if ( shift == LOG_MAX_BUFFER_SIZE ) { <EOL> tailCarry . value = root [ bufferIndex ] <EOL> null <EOL> } else { <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> pullLastBuffer ( root [ bufferIndex ] as Array < Any ? > , shift - LOG_MAX_BUFFER_SIZE , rootSize , tailCarry ) <EOL> } <EOL> if ( newBufferAtIndex == null && bufferIndex == <NUM_LIT:0> ) { <EOL> return null <EOL> } <EOL> val mutableRoot = makeMutable ( root ) <EOL> mutableRoot [ bufferIndex ] = newBufferAtIndex <EOL> return mutableRoot <EOL> }

/**
 * Extracts the last leaf buffer from trie and returns new trie without it or `null` if there's no more leaf elements in this trie.
 *
 * [tailCarry] on output contains the extracted leaf buffer.
 */


private fun retainFirst ( root : Array < Any ? > , size : Int ) : Array < Any ? > ?

{ <EOL> check ( size and MAX_BUFFER_SIZE_MINUS_ONE == <NUM_LIT:0> ) <EOL> if ( size == <NUM_LIT:0> ) { <EOL> rootShift = <NUM_LIT:0> <EOL> return null <EOL> } <EOL> val lastIndex = size - <NUM_LIT:1> <EOL> var newRoot = root <EOL> while ( lastIndex shr rootShift == <NUM_LIT:0> ) { <EOL> rootShift -= LOG_MAX_BUFFER_SIZE <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> newRoot = newRoot [ <NUM_LIT:0> ] as Array < Any ? > <EOL> } <EOL> return nullifyAfter ( newRoot , lastIndex , rootShift ) <EOL> }

/**
 * Retains first [size] elements of the [root].
 *
 * If the height of the root is bigger than needed to store [size] elements, it's decreased.
 */


private fun nullifyAfter ( root : Array < Any ? > , index : Int , shift : Int ) : Array < Any ? >

{ <EOL> check ( shift >= <NUM_LIT:0> ) <EOL> if ( shift == <NUM_LIT:0> ) { <EOL> return root <EOL> } <EOL> val lastIndex = indexSegment ( index , shift ) <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> val newChild = nullifyAfter ( root [ lastIndex ] as Array < Any ? > , index , shift - LOG_MAX_BUFFER_SIZE ) <EOL> var newRoot = root <EOL> if ( lastIndex < MAX_BUFFER_SIZE_MINUS_ONE && newRoot [ lastIndex + <NUM_LIT:1> ] != null ) { <EOL> if ( isMutable ( newRoot ) ) { <EOL> newRoot . fill ( null , lastIndex + <NUM_LIT:1> , MAX_BUFFER_SIZE ) <EOL> } <EOL> newRoot = newRoot . copyInto ( mutableBuffer ( ) , <NUM_LIT:0> , <NUM_LIT:0> , lastIndex + <NUM_LIT:1> ) <EOL> } <EOL> if ( newChild !== newRoot [ lastIndex ] ) { <EOL> newRoot = makeMutable ( newRoot ) <EOL> newRoot [ lastIndex ] = newChild <EOL> } <EOL> return newRoot <EOL> }

/**
 * Nullifies nodes cells after the specified [index].
 *
 * Used to prevent memory leaks after reusing nodes.
 */


private fun removeAllFromTail ( predicate : ( E ) -> Boolean , tailSize : Int , bufferRef : ObjectRef ) : Int

{ <EOL> val newTailSize = removeAll ( predicate , tail , tailSize , bufferRef ) <EOL> if ( newTailSize == tailSize ) { <EOL> assert ( bufferRef . value === tail ) <EOL> return tailSize <EOL> } <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> val newTail = bufferRef . value as Array < Any ? > <EOL> newTail . fill ( null , newTailSize , tailSize ) <EOL> tail = newTail <EOL> size -= tailSize - newTailSize <EOL> return newTailSize <EOL> }

/**
 * Copies elements of the [tail] buffer of size [tailSize] that do not match the given [predicate] to a new buffer.
 *
 * If the [tail] is mutable, it is reused to store non-matching elements.
 * If non of the elements match the [predicate], no buffers are created and elements are not copied.
 * [bufferRef] stores the newly created buffer, or the [tail] if a new buffer was not created.
 *
 * Returns the filled size of the buffer stored in the [bufferRef].
 */


private fun removeAll ( predicate : ( E ) -> Boolean , buffer : Array < Any ? > , bufferSize : Int , bufferRef : ObjectRef ) : Int

{ <EOL> var newBuffer = buffer <EOL> var newBufferSize = bufferSize <EOL> var anyRemoved = false <EOL> for ( index in <NUM_LIT:0> until bufferSize ) { <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> val element = buffer [ index ] as E <EOL> if ( predicate ( element ) ) { <EOL> if ( ! anyRemoved ) { <EOL> newBuffer = makeMutable ( buffer ) <EOL> newBufferSize = index <EOL> anyRemoved = true <EOL> } <EOL> } else if ( anyRemoved ) { <EOL> newBuffer [ newBufferSize ++ ] = element <EOL> } <EOL> } <EOL> bufferRef . value = newBuffer <EOL> return newBufferSize <EOL> }

/**
 * Copies elements of the given [buffer] of size [bufferSize] that do not match the given [predicate] to a new buffer.
 *
 * If the [buffer] is mutable, it is reused to store non-matching elements.
 * If non of the elements match the [predicate], no buffers are created and elements are not copied.
 * [bufferRef] stores the newly created buffer, or the [buffer] if a new buffer was not created.
 *
 * Returns the filled size of the buffer stored in the [bufferRef].
 */


private fun recyclableRemoveAll ( predicate : ( E ) -> Boolean , buffer : Array < Any ? > , bufferSize : Int , toBufferSize : Int , bufferRef : ObjectRef , recyclableBuffers : MutableList < Array < Any ? > > , buffers : MutableList < Array < Any ? > > ) : Int

{ <EOL> if ( isMutable ( buffer ) ) { <EOL> recyclableBuffers . add ( buffer ) <EOL> } <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> val toBuffer = bufferRef . value as Array < Any ? > <EOL> var newToBuffer = toBuffer <EOL> var newToBufferSize = toBufferSize <EOL> for ( index in <NUM_LIT:0> until bufferSize ) { <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> val element = buffer [ index ] as E <EOL> if ( ! predicate ( element ) ) { <EOL> if ( newToBufferSize == MAX_BUFFER_SIZE ) { <EOL> newToBuffer = if ( recyclableBuffers . isNotEmpty ( ) ) { <EOL> recyclableBuffers . removeAt ( recyclableBuffers . size - <NUM_LIT:1> ) <EOL> } else { <EOL> mutableBuffer ( ) <EOL> } <EOL> newToBufferSize = <NUM_LIT:0> <EOL> } <EOL> newToBuffer [ newToBufferSize ++ ] = element <EOL> } <EOL> } <EOL> bufferRef . value = newToBuffer <EOL> if ( toBuffer !== bufferRef . value ) { <EOL> buffers . add ( toBuffer ) <EOL> } <EOL> return newToBufferSize <EOL> }

/**
 * Copied elements of the given [buffer] of size [bufferSize] that do not match the given [predicate]
 * to the buffer stored in the given [bufferRef] starting at [toBufferSize].
 *
 * If the buffer gets filled entirely, it is added to [buffers] and a new buffer is created or
 * reused from the [recyclableBuffers] to hold the rest of the non-matching elements.
 * [bufferRef] stores the newly created buffer if a new buffer was created.
 *
 * Returns the filled size of the buffer stored in the [bufferRef].
 */


@ PublishedApi <EOL> internal fun getProgressionLastElement ( start : Int , end : Int , step : Int ) : Int

= when { <EOL> step > <NUM_LIT:0> -> if ( start >= end ) end else end - differenceModulo ( end , start , step ) <EOL> step < <NUM_LIT:0> -> if ( start <= end ) end else end + differenceModulo ( start , end , - step ) <EOL> else -> throw kotlin . IllegalArgumentException ( "<STR_LIT>" ) <EOL> }

/**
 * Calculates the final element of a bounded arithmetic progression, i.e. the last element of the progression which is in the range
 * from [start] to [end] in case of a positive [step], or from [end] to [start] in case of a negative
 * [step].
 *
 * No validation on passed parameters is performed. The given parameters should satisfy the condition:
 *
 * - either `step > 0` and `start <= end`,
 * - or `step < 0` and `start >= end`.
 *
 * @param start first element of the progression
 * @param end ending bound for the progression
 * @param step increment, or difference of successive elements in the progression
 * @return the final element of the progression
 * @suppress
 */


@ PublishedApi <EOL> internal fun getProgressionLastElement ( start : Long , end : Long , step : Long ) : Long


private fun mergeStdlibParts ( outputFile : File , wrapperFile : File , baseDir : File , inputPaths : List < File > )

{ <EOL> val program = JsProgram ( ) <EOL> fun File . makeRelativeIfNecessary ( ) : String = canonicalFile . toRelativeString ( baseDir ) <EOL> val wrapper = parse ( wrapperFile . readText ( ) , ThrowExceptionOnErrorReporter , program . scope , wrapperFile . makeRelativeIfNecessary ( ) ) <EOL> ? : error ( "<STR_LIT>" ) <EOL> val insertionPlace = wrapper . createInsertionPlace ( ) <EOL> val allFiles = mutableListOf < File > ( ) <EOL> inputPaths . forEach { collectFiles ( it , allFiles ) } <EOL> for ( file in allFiles ) { <EOL> val statements = parse ( file . readText ( ) , ThrowExceptionOnErrorReporter , program . scope , file . makeRelativeIfNecessary ( ) ) <EOL> ? : error ( "<STR_LIT>" ) <EOL> val block = JsBlock ( statements ) <EOL> block . fixForwardNameReferences ( ) <EOL> val sourceMapFile = File ( file . parent , file . name + "<STR_LIT>" ) <EOL> if ( sourceMapFile . exists ( ) ) { <EOL> when ( val sourceMapParse = SourceMapParser . parse ( sourceMapFile ) ) { <EOL> is SourceMapError -> { <EOL> System . err . println ( "<STR_LIT>" ) <EOL> exitProcess ( <NUM_LIT:1> ) <EOL> } <EOL> is SourceMapSuccess -> { <EOL> val sourceMap = sourceMapParse . value <EOL> val remapper = SourceMapLocationRemapper ( sourceMap ) <EOL> remapper . remap ( block ) <EOL> } <EOL> } <EOL> } <EOL> insertionPlace . statements += statements <EOL> } <EOL> program . globalBlock . statements += wrapper <EOL> val sourceMapFile = File ( outputFile . parentFile , outputFile . name + "<STR_LIT>" ) <EOL> val textOutput = TextOutputImpl ( ) <EOL> val sourceMapBuilder = SourceMap3Builder ( outputFile , textOutput :: getColumn , "<STR_LIT>" ) <EOL> val consumer = SourceMapBuilderConsumer ( File ( "<STR_LIT:.>" ) , sourceMapBuilder , SourceFilePathResolver ( mutableListOf ( ) ) , provideCurrentModuleContent = true , provideExternalModuleContent = true ) <EOL> program . globalBlock . accept ( JsToStringGenerationVisitor ( textOutput , consumer ) ) <EOL> val sourceMapContent = sourceMapBuilder . build ( ) <EOL> val programText = textOutput . toString ( ) <EOL> outputFile . writeText ( programText + "<STR_LIT>" ) <EOL> val sourceMapJson = parseJson ( sourceMapContent ) <EOL> val sources = ( sourceMapJson as JsonObject ) . properties [ "<STR_LIT>" ] as JsonArray <EOL> sourceMapJson . properties [ "<STR_LIT>" ] = JsonArray ( * sources . elements . map { sourcePath -> <EOL> val sourceFile = File ( ( sourcePath as JsonString ) . value ) <EOL> if ( sourceFile . exists ( ) ) { <EOL> JsonString ( sourceFile . readText ( ) ) <EOL> } else { <EOL> JsonNull <EOL> } <EOL> } . toTypedArray ( ) ) <EOL> sourceMapFile . writeText ( sourceMapJson . toString ( ) ) <EOL> }

/**
 * Combines several JS input files, that comprise Kotlin JS Standard Library,
 * into a single JS module.
 * The source maps of these files are combined into a single source map.
 */


public abstract fun build ( tf : Ops , input : Operand < Float > , isTraining : Operand < Boolean > , numberOfLosses : Operand < Float > ? <EOL> ) : Operand < Float >

/**
 * Extend this function to define variables in the layer and compute layer output.
 *
 * @param [tf] TensorFlow graph API for building operations.
 * @param [input] Layer input.
 * @param [isTraining] TensorFlow operand for switching between training and inference modes.
 * @param [numberOfLosses] TensorFlow operand for batch size data.
 */


public open fun build ( tf : Ops , input : List < Operand < Float > > , isTraining : Operand < Boolean > , numberOfLosses : Operand < Float > ? <EOL> ) : Operand < Float >

{ <EOL> return build ( tf , input . first ( ) , isTraining , numberOfLosses ) <EOL> }

/**
 * Extend this function to define variables in the layer and compute layer output.
 *
 * NOTE: This function should be overridden for layers with multiple inputs.
 * NOTE: Used in Functional API
 *
 * @param [input] Layer input list.
 * @param [isTraining] TensorFlow operand for switching between training and inference modes.
 * @param [numberOfLosses] TensorFlow operand for batch size data.
 */


public operator fun invoke ( vararg layers : Layer ) : Layer

{ <EOL> inboundLayers = layers . toMutableList ( ) <EOL> return this <EOL> }

/** Important part of functional API. It takes [layers] as input and saves them to the [inboundLayers] of the given layer. */


internal suspend fun KotlinSourceSetTree . Companion . orNull ( compilation : KotlinCompilation < * > )

= <EOL> compilation . sourceSetTreeClassifier . classify ( compilation )

/**
 * Returns the [KotlinSourceSetTree] of a given [KotlinCompilation]:
 * Uses the [sourceSetTreeClassifier] under the hood.
 * See [KotlinSourceSetTreeClassifier]
 */


fun handleElementRename ( ktReference : KtReference , newElementName : String ) : PsiElement ?

/**
 * See [com.intellij.psi.PsiReference.handleElementRename].
 */


fun bindToElement ( ktReference : KtReference , element : PsiElement ) : PsiElement

/**
 * See [com.intellij.psi.PsiReference.bindToElement].
 */


public fun < T > yMin ( column : ColumnReference < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_MIN , column . name ( ) , null ) <EOL> }

/**
 * Maps the `yMin` aesthetic to a data column specified by a [ColumnReference].
 *
 * @param column the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun < T > yMin ( column : KProperty < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_MIN , column . name , null ) <EOL> }

/**
 * Maps the `yMin` aesthetic to a data column specified by a [KProperty].
 *
 * @param column the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun yMin ( column : String ) : PositionalMapping < Any ? >

{ <EOL> return addPositionalMapping ( Y_MIN , column , null ) <EOL> }

/**
 * Maps the `yMin` aesthetic to a data column specified by a [String].
 *
 * @param column the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun < T > yMin ( values : Iterable < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_MIN , values . toList ( ) , null , null ) <EOL> }

/**
 * Maps the `yMin` aesthetic to iterable of values.
 *
 * @param values the iterable of values to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun < T > yMin ( values : DataColumn < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_MIN , values , null ) <EOL> }

/**
 * Maps the `yMin` aesthetic to a data column.
 *
 * @param values the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public operator fun get ( index : Int ) : UInt

= storage [ index ] . toUInt ( )

/**
 * Returns the array element at the given [index]. This method can be called using the index operator.
 *
 * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException] except in Kotlin/JS
 * where the behavior is unspecified.
 */


public operator fun set ( index : Int , value : UInt )

{ <EOL> storage [ index ] = value . toInt ( ) <EOL> }

/**
 * Sets the element at the given [index] to the given [value]. This method can be called using the index operator.
 *
 * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException] except in Kotlin/JS
 * where the behavior is unspecified.
 */


public override operator fun iterator ( ) : kotlin . collections . Iterator < UInt >

= Iterator ( storage )

/** Creates an iterator over the elements of the array. */


@ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> @ ExperimentalUnsignedTypes <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun UIntArray ( size : Int , init : ( Int ) -> UInt ) : UIntArray

{ <EOL> return UIntArray ( IntArray ( size ) { index -> init ( index ) . toInt ( ) } ) <EOL> }

/**
 * Creates a new array of the specified [size], where each element is calculated by calling the specified
 * [init] function.
 *
 * The function [init] is called for each array element sequentially starting from the first one.
 * It should return the value for an array element given its index.
 */


public fun close ( ) : Unit

/**
 * Closes this resource.
 *
 * This function may throw, thus it is strongly recommended to use the [use] function instead,
 * which closes this resource correctly whether an exception is thrown or not.
 *
 * Implementers of this interface should pay increased attention to cases where the close operation may fail.
 * It is recommended that all underlying resources are closed and the resource internally is marked as closed
 * before throwing an exception. Such a strategy ensures that the resources are released in a timely manner,
 * and avoids many problems that could come up when the resource wraps, or is wrapped, by another resource.
 *
 * Note that calling this function more than once may have some visible side effect.
 * However, implementers of this interface are strongly recommended to make this function idempotent.
 */


@ Suppress ( "<STR_LIT>" ) <EOL> @ SinceKotlin ( "<STR_LIT:2.0>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public expect inline fun AutoCloseable ( crossinline closeAction : ( ) -> Unit ) : AutoCloseable

/**
 * Returns an [AutoCloseable] instance that executes the specified [closeAction]
 * upon invocation of its [`close()`][AutoCloseable.close] function.
 *
 * This function allows specifying custom cleanup actions for resources.
 *
 * Note that each invocation of the `close()` function on the returned `AutoCloseable` instance executes the [closeAction].
 * Therefore, implementers are strongly recommended to make the [closeAction] idempotent, or to prevent multiple invocations.
 *
 * Example:
 *
 * ```kotlin
 * val autoCloseable = AutoCloseable {
 * // Cleanup action, e.g., closing a file or releasing a network connection
 * Logger.log("Releasing the network connection.")
 * networkConnection.release()
 * }
 *
 * // Now you can pass the autoCloseable to a function or use it directly.
 * autoCloseable.use {
 * // Use the connection, which will be automatically released when this scope finishes.
 * val content = networkConnection.readContent()
 * Logger.log("Network connection content: $content")
 * }
 * ```
 *
 * @See AutoCloseable.use
 */


@ Suppress ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> @ SinceKotlin ( "<STR_LIT:2.0>" ) <EOL> @ WasExperimental ( ExperimentalStdlibApi :: class ) <EOL> @ kotlin . internal . InlineOnly <EOL> public expect inline fun < T : AutoCloseable ? , R > T . use ( block : ( T ) -> R ) : R

{ <EOL> contract { <EOL> callsInPlace ( block , InvocationKind . EXACTLY_ONCE ) <EOL> } <EOL> error ( "<STR_LIT>" ) <EOL> }

/**
 * Executes the given [block] function on this resource and then closes it down correctly whether an exception
 * is thrown or not.
 *
 * In case if the resource is being closed due to an exception occurred in [block], and the closing also fails with an exception,
 * the latter is added to the [suppressed][Throwable.addSuppressed] exceptions of the former.
 *
 * @param block a function to process this [AutoCloseable] resource.
 * @return the result of [block] function invoked on this resource.
 */


public fun complete ( value : T ) : Boolean

/**
 * Completes this deferred value with a given [value]. The result is `true` if this deferred was
 * completed as a result of this invocation and `false` otherwise (if it was already completed).
 *
 * Subsequent invocations of this function have no effect and always produce `false`.
 *
 * This function transitions this deferred into _completed_ state if it was not completed or cancelled yet.
 * However, if this deferred has children, then it transitions into _completing_ state and becomes _complete_
 * once all its children are [complete][isCompleted]. See [Job] for details.
 */


public fun completeExceptionally ( exception : Throwable ) : Boolean

/**
 * Completes this deferred value exceptionally with a given [exception]. The result is `true` if this deferred was
 * completed as a result of this invocation and `false` otherwise (if it was already completed).
 *
 * Subsequent invocations of this function have no effect and always produce `false`.
 *
 * This function transitions this deferred into _cancelled_ state if it was not completed or cancelled yet.
 * However, that if this deferred has children, then it transitions into _cancelling_ state and becomes _cancelled_
 * once all its children are [complete][isCompleted]. See [Job] for details.
 */


public fun < T > CompletableDeferred < T > . completeWith ( result : Result < T > ) : Boolean

= <EOL> result . fold ( { complete ( it ) } , { completeExceptionally ( it ) } )

/**
 * Completes this deferred value with the value or exception in the given [result]. Returns `true` if this deferred
 * was completed as a result of this invocation and `false` otherwise (if it was already completed).
 *
 * Subsequent invocations of this function have no effect and always produce `false`.
 *
 * This function transitions this deferred in the same ways described by [CompletableDeferred.complete] and
 * [CompletableDeferred.completeExceptionally].
 */


@ Suppress ( "<STR_LIT:FunctionName>" ) <EOL> public fun < T > CompletableDeferred ( parent : Job ? = null ) : CompletableDeferred < T >

= CompletableDeferredImpl ( parent )

/**
 * Creates a [CompletableDeferred] in an _active_ state.
 * It is optionally a child of a [parent] job.
 */


@ Suppress ( "<STR_LIT:FunctionName>" ) <EOL> public fun < T > CompletableDeferred ( value : T ) : CompletableDeferred < T >

= CompletableDeferredImpl < T > ( null ) . apply { complete ( value ) }

/**
 * Creates an already _completed_ [CompletableDeferred] with a given [value].
 */


public fun koverXmlReportName ( variant : String ) : String

{ <EOL> return xmlReportTaskName ( variant ) <EOL> }

/**
 * Name of the XML report generation task for [variant] Kover report variant.
 */


public fun koverHtmlReportName ( variant : String ) : String

{ <EOL> return htmlReportTaskName ( variant ) <EOL> }

/**
 * Name of the HTML report generation task for [variant] Kover report variant.
 */


public fun koverBinaryReportName ( variant : String ) : String

{ <EOL> return binaryReportTaskName ( variant ) <EOL> }

/**
 * Name of the binary report generation task for [variant] Kover report variant.
 */


public fun koverVerifyName ( variant : String ) : String

{ <EOL> return verifyTaskName ( variant ) <EOL> }

/**
 * Name of the verification task for [variant] Kover report variant.
 */


public fun koverLogName ( variant : String ) : String

{ <EOL> return logTaskName ( variant ) <EOL> }

/**
 * Name of the coverage logging task for [variant] Kover report variant.
 */


@ ObsoleteDescriptorBasedAPI <EOL> override fun referenceClass ( declaration : ClassDescriptor ) : IrClassSymbol

{ <EOL> val irBuiltIns = this@SymbolTableWithBuiltInsDeduplication . irBuiltIns ? : return super . referenceClass ( declaration ) <EOL> val builtInDescriptor = irBuiltIns . findBuiltInClassDescriptor ( declaration ) <EOL> if ( builtInDescriptor != null ) { <EOL> return super . referenceClass ( builtInDescriptor ) <EOL> } <EOL> return super . referenceClass ( declaration ) <EOL> }

/**
 * Gets or creates the [IrClassSymbol] for [declaration], or for the built-in descriptor with the same name if [declaration] is a
 * duplicate built-in.
 *
 * Note that not all built-in symbols may have been bound or created by the time [irBuiltIns] has been bound. However, [referenceClass]
 * will create a symbol in such a case (via `super.referenceClass`) and [org.jetbrains.kotlin.ir.util.DeclarationStubGenerator] will
 * create a stub for the symbol if [referenceClass] was invoked from the stub generator.
 */


fun < T : Any > sort ( a : KtNDArray < T > , axis : Int = - <NUM_LIT:1> , kind : KindSort ? = null ) : KtNDArray < T >

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a , axis , kind ? . str ? : None . none ) )

/**
 * Return a sorted copy of an array.
 *
 * @param a array to be sorted.
 * @param axis along which to sort.
 * @param kind sorting algorithm. see [KindSort].
 * @return [KtNDArray] of the same type and shape as [a].
 * @see argSort
 * @see lexSort
 * @see searchSorted
 * @see partition
 */


fun < T : Any > lexSort ( keys : Array < KtNDArray < T > > , axis : Int = - <NUM_LIT:1> ) : KtNDArray < Long >

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( keys , axis ) )

/**
 * Perform an indirect stable sort using a sequence of keys.
 *
 * @param keys the k different 'columns' to be sorted.
 * @param axis axis to be indirectly sorted.
 * @return [KtNDArray] of indeces that sort the keys along the specified axis.
 * @see argSort
 * @see sort
 */


fun < T : Any > argSort ( a : KtNDArray < T > , axis : Int = - <NUM_LIT:1> , kind : KindSort ? = null ) : KtNDArray < Long >

/**
 * Returns the indices that would sort an array.
 *
 * @param a array to sort
 * @param axis along which to sort. The default is the last index (-1).
 * @param kind sorting algorithm. The default is `quicksort`.
 * @return [KtNDArray] of indices that sort [a] along the specified [axis].
 * @see sort
 * @see lexSort
 * @see argPartition
 */


fun < T : Any > msort ( a : KtNDArray < T > ) : KtNDArray < T >

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a ) )

/**
 * Return of an array sorted along the first axis.
 *
 * @param a array to be sorted.
 * @return [KtNDArray] of the same type and shape as [a].
 * @see sort
 */


fun < T : Any > argPartition ( a : KtNDArray < T > , kth : Int , axis : Int = - <NUM_LIT:1> , kind : String = "<STR_LIT>" ) : KtNDArray < Long >

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a , kth , axis , kind ) )

/**
 * Perform an indirect partition along the given axis using the algorithm specified by the kind keyword.
 *
 * @param a array to sort.
 * @param kth element index to partition by.
 * @param axis along which to sort. Th default is the last axis (-1).
 * @param kind selection algorithm. Default is `introselect`.
 * @return [KtNDArray] of indices that partition [a] along the specified axis.
 * @see partition
 * @see argSort
 */


fun < T : Number > argMax ( a : KtNDArray < T > ) : Long

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a ) , kClass = Long :: class )

/**
 * Returns the index of the maximum value along the flattened array.
 *
 * @param a input array.
 * @return index of type [Long].
 * @see argMin
 */


fun < T : Number > argMax ( a : KtNDArray < T > , axis : Int ) : KtNDArray < Long >

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a , axis ) )

/**
 * Returns the indices of the maximum values along an axis.
 *
 * @param a input array.
 * @param axis indices along the specified axis.
 * @return [KtNDArray] of indices into the array. It has the same shape as [a] with the dimension along axis removed.
 * @see argMin
 */


fun < T : Number > nanArgMax ( a : KtNDArray < T > ) : Long

/**
 * Return the indices of the maximum values in the specified axis ignoring [Double.NaN].
 *
 * @param a input data.
 * @return index value.
 * @see argMax
 * @see nanArgMin
 */


fun < T : Number > nanArgMax ( a : KtNDArray < T > , axis : Int ) : KtNDArray < Long >

/**
 * @param axis along which to operate.
 * @return An [KtNDArray] of indices.
 */


fun < T : Number > argMin ( a : KtNDArray < T > ) : Long

/**
 * Returns the index of the maximum value along the flattened array.
 *
 * @param a input array.
 * @return index of type [Long].
 * @see argMax
 */


fun < T : Number > argMin ( a : KtNDArray < T > , axis : Int ) : KtNDArray < Long >

/**
 * Returns the indices of the minimum values along an axis.
 *
 * @param a input array.
 * @param axis indices along the specified axis.
 * @return [KtNDArray] of indices into the array. It has the same shape as [a] with the dimension along axis removed.
 * @see argMax
 */


fun < T : Number > nanArgMin ( a : KtNDArray < T > ) : Long

/**
 * Return the indices of the minimum values in the specified axis ignoring [Double.NaN].
 *
 * @param a input data.
 * @return Index value.
 * @see nanArgMax
 * @see argMin
 */


fun < T : Number > nanArgMin ( a : KtNDArray < T > , axis : Int ) : KtNDArray < Long >


fun < T : Any > nonZero ( a : KtNDArray < T > ) : Array < Any >

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a ) , kClass = Array < Any > :: class )

/**
 * Return the indices of the elements that are non-zero.
 *
 * @param a input array.
 * @return [Array] of indices of elements that are non-zero.
 * @see flatNoneZero
 * @see countNonZero
 */


fun < T : Number > flatNoneZero ( a : KtNDArray < T > ) : KtNDArray < Long >

/**
 * Return indices that are non-zero in the flattened version of [a].
 *
 * @param a input data.
 * @return [KtNDArray]
 * @see nonZero
 * @see ravel
 */


fun < T : Number > searchSorted ( a : KtNDArray < T > , v : T , side : Side = Side . LEFT ) : Long

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a , v , side . str ) , kClass = Long :: class )

/**
 * Find indices where elements should be inserted to maintain order.
 *
 * @param a input 1-D [KtNDArray].
 * @param v value to insert into [a].
 * @param side If *left*, the index of the first suitable location found is given.
 * If *right*, return the last such index.
 * If there is no suitable index, return either 0 or N (where N is the length of [a]).
 * @return index
 * @see sort
 */


fun < T : Number > searchSorted ( a : KtNDArray < T > , v : KtNDArray < T > , side : Side = Side . LEFT ) : KtNDArray < Long >

= <EOL> callFunc ( nameMethod = arrayOf ( "<STR_LIT>" ) , args = arrayOf ( a , v , side . str ) )

/**
 * @param v [KtNDArray] of values to insert into [a].
 * @return [KtNDArray] of insertion points with the same shape as v.
 */


fun < T : Any > countNonZero ( a : KtNDArray < T > ) : Long

/**
 * Counts the number of non-zero values in the array [a].
 * @param a inpud array.
 * @return Number of [Long] of non-zero values in the array.
 * @see nonZero
 */


fun < T : Any > countNonZero ( a : KtNDArray < T > , axis : Int ) : KtNDArray < Long >

/**
 * Counts the number of non-zero values in the array [a] along a given axis.
 * @param a inpud array.
 * @param axis along which to count non-zeros.
 * @return Number of [KtNDArray] of non-zeros values in the array along a given axis.
 * @see nonZero
 */


override fun isSynthetic ( documentable : Documentable , sourceSet : DokkaConfiguration . DokkaSourceSet ) : Boolean

{ <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> val extra = ( documentable as? WithExtraProperties < Documentable > ) ? . extra <EOL> val isInherited = extra ? . get ( InheritedMember ) ? . inheritedFrom ? . get ( sourceSet ) != null <EOL> val isSynthesized = documentable . getPsi ( sourceSet ) == null <EOL> return isInherited || isSynthesized <EOL> }

/**
 * Currently, it's used only for [org.jetbrains.dokka.base.transformers.documentables.ReportUndocumentedTransformer]
 *
 * For so-called fake-ovveride declarations - we have [InheritedMember] extra.
 * For synthesized declaration - we do not have PSI source.
 *
 * @see org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin.SOURCE_MEMBER_GENERATED
 */


fun acceptsField ( result : FieldValue ) : Boolean

/**
 * Returns true if this renderer accepts [result], false otherwise
 */


fun accepts ( value : Any ? ) : Boolean

/**
 * Returns true if this renderer accepts [value], false otherwise
 */


fun precompile ( methodName : String , paramName : String , ) : Code ?

/**
 * Returns method code for rendering
 *
 * @param methodName Precompiled method name
 * @param paramName Name for result value parameter
 * @return Method code if renderer may be precompiled, null otherwise
 */


= withSpark { <EOL> val random = udf ( nondeterministic = true ) { -> Math . random ( ) } <EOL> udf . register ( "<STR_LIT>" , random ) <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> val plusOne = udf { x : Int -> x + <NUM_LIT:1> } <EOL> udf . register ( "<STR_LIT>" , plusOne ) <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> udf . register ( "<STR_LIT>" ) { str : String , int : Int -> str . length + int } <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> udf . register ( "<STR_LIT>" ) { n : Long -> n > <NUM_LIT:5> } <EOL> spark . range ( <NUM_LIT:1> , <NUM_LIT:10> ) . createOrReplaceTempView ( "<STR_LIT:test>" ) <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> }

/**
 * https://spark.apache.org/docs/latest/sql-ref-functions-udf-scalar.html
 * adapted directly for Kotlin:
 * */


= withSpark { <EOL> val plusOne = udf { x : Int -> x + <NUM_LIT:1> } <EOL> udf . register ( "<STR_LIT>" , plusOne ) <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> val plusOneNamed = udf ( "<STR_LIT>" ) { x : Int -> x + <NUM_LIT:1> } <EOL> udf . register ( plusOneNamed ) <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> udf . register ( "<STR_LIT>" , plusOneNamed ) <EOL> udf . register ( plusOneNamed . withName ( "<STR_LIT>" ) ) <EOL> val plusOneFinal by udf { x : Int -> x + <NUM_LIT:1> } <EOL> plusOneFinal . register ( ) <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> }

/**
 * Shows how Kotlin's UDF wrappers can carry a name which saves you time and errors.
 */


= withSpark { <EOL> fun plusOne ( x : Int ) = x + <NUM_LIT:1> <EOL> val plusOneUDF : NamedUserDefinedFunction1 < Int , Int > = udf ( :: plusOne ) <EOL> udf . register ( :: plusOne ) <EOL> spark . sql ( "<STR_LIT>" ) . show ( ) <EOL> val minusOneUDF : NamedUserDefinedFunction1 < Int , Int > = udf ( :: minusOne ) <EOL> udf ( "<STR_LIT>" , :: minusOne ) <EOL> }

/**
 * Shows how UDFs can be created from normal functions as well.
 */


= withSpark { <EOL> data class User ( val name : String , val age : Int ? ) <EOL> val ds : Dataset < User > = dsOf ( User ( "<STR_LIT:A>" , null ) , User ( "<STR_LIT:B>" , <NUM_LIT:23> ) , User ( "<STR_LIT:C>" , <NUM_LIT> ) , User ( "<STR_LIT:D>" , <NUM_LIT> ) , ) . showDS ( ) <EOL> val replaceMissingAge = udf { age : Int ? , value : Int -> age ? : value } <EOL> val result1 : Dataset < Tuple2 < String , Int > > = ds . select ( col ( User :: name ) , replaceMissingAge ( col ( User :: age ) , typedLit ( - <NUM_LIT:1> ) ) ) . showDS ( ) <EOL> val toJson by udf { age : Int , name : String , pets : Seq < String > -> <EOL> """<STR_LIT>""" <EOL> } <EOL> val df : Dataset < Row > = dfOf ( colNames = arrayOf ( "<STR_LIT:name>" , "<STR_LIT:age>" , "<STR_LIT>" ) , t ( "<STR_LIT:Alice>" , <NUM_LIT:12> , emptyList ( ) ) , t ( "<STR_LIT>" , <NUM_LIT> , listOf ( "<STR_LIT>" , "<STR_LIT>" ) ) , t ( "<STR_LIT>" , <NUM_LIT> , listOf ( "<STR_LIT>" ) ) , ) . showDS ( ) <EOL> val result2 = df . select ( toJson ( col < _ , Int > ( "<STR_LIT:age>" ) , col < _ , String > ( "<STR_LIT:name>" ) , col < Row , List < String > > ( "<STR_LIT>" ) . asSeq ( ) , ) ) . showDS ( truncate = false ) <EOL> }

/**
 * Shows how UDFs in Kotlin carry typing information, which allows you to do
 * typesafe column operations with them.
 */


= withSpark { <EOL> val ds : Dataset < Employee > = dsOf ( Employee ( "<STR_LIT>" , <NUM_LIT> ) , Employee ( "<STR_LIT>" , <NUM_LIT> ) , Employee ( "<STR_LIT>" , <NUM_LIT> ) , Employee ( "<STR_LIT>" , <NUM_LIT> ) , ) . showDS ( ) <EOL> val averageSalary : TypedColumn < Employee , Double > = MyAverage . toColumn ( ) . name ( "<STR_LIT>" ) <EOL> val result1 : Dataset < Double > = ds . select ( averageSalary ) <EOL> . showDS ( ) <EOL> val myAverage = aggregatorOf < Long , Average , Double > ( zero = { Average ( <NUM_LIT:0L> , <NUM_LIT:0L> ) } , reduce = { buffer , it -> <EOL> buffer . sum += it <EOL> buffer . count += <NUM_LIT:1> <EOL> buffer <EOL> } , merge = { buffer , it -> <EOL> buffer . sum += it . sum <EOL> buffer . count += it . count <EOL> buffer <EOL> } , finish = { it . sum . toDouble ( ) / it . count } , ) <EOL> val myAverageUdf = udaf ( "<STR_LIT>" , myAverage ) . register ( ) <EOL> ds . createOrReplaceTempView ( "<STR_LIT>" ) <EOL> spark . sql ( """<STR_LIT>""" ) <EOL> . showDS ( ) <EOL> val result2 : Dataset < Double > = ds . select ( myAverageUdf ( col ( Employee :: salary ) ) . name ( "<STR_LIT>" ) ) . showDS ( ) <EOL> val udaf : UserDefinedFunction1 < Long , Double > = udaf ( zero = { Average ( <NUM_LIT:0L> , <NUM_LIT:0L> ) } , reduce = { buffer , it -> <EOL> buffer . sum += it <EOL> buffer . count += <NUM_LIT:1> <EOL> buffer <EOL> } , merge = { buffer , it -> <EOL> buffer . sum += it . sum <EOL> buffer . count += it . count <EOL> buffer <EOL> } , finish = { it . sum . toDouble ( ) / it . count } , ) <EOL> val registeredUdaf : NamedUserDefinedFunction1 < Long , Double > = udf . register ( name = "<STR_LIT>" , zero = { Average ( <NUM_LIT:0L> , <NUM_LIT:0L> ) } , reduce = { buffer , it -> <EOL> buffer . sum += it <EOL> buffer . count += <NUM_LIT:1> <EOL> buffer <EOL> } , merge = { buffer , it -> <EOL> buffer . sum += it . sum <EOL> buffer . count += it . count <EOL> buffer <EOL> } , finish = { it . sum . toDouble ( ) / it . count } , ) <EOL> }

/**
 * Shows how UDAFs can be used from Kotlin.
 */


= withSpark { <EOL> fun sumOf ( vararg double : Double ) : Double = double . sum ( ) <EOL> val sumUDF = udf . register ( :: sumOf ) <EOL> data class Values ( val v1 : Double , val v2 : Double , val v3 : Double , val v4 : Double ) <EOL> val ds = dsOf ( Values ( <NUM_LIT:1.0> , <NUM_LIT:2.0> , <NUM_LIT:3.0> , <NUM_LIT> ) , Values ( <NUM_LIT> , <NUM_LIT:3.0> , <NUM_LIT:2.0> , <NUM_LIT:1.0> ) , Values ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ) . showDS ( ) <EOL> ds . createOrReplaceTempView ( "<STR_LIT>" ) <EOL> spark . sql ( """<STR_LIT>""" ) <EOL> . showDS ( ) <EOL> val result = ds . select ( sumUDF ( col ( Values :: v1 ) , col ( Values :: v4 ) ) , sumUDF ( ) , sumUDF ( col ( Values :: v1 ) , col ( Values :: v2 ) , col ( Values :: v3 ) , col ( Values :: v4 ) ) , ) . showDS ( ) <EOL> udf . register ( "<STR_LIT>" ) { strings : Array < String > -> strings . joinToString ( separator = "<STR_LIT:->" ) } <EOL> spark . sql ( """<STR_LIT>""" ) <EOL> . showDS ( ) <EOL> }

/**
 * Shows the new and unique vararg UDFs the Kotlin Spark API has to offer and how to use them.
 */


fun analyzeSpecialSerializers ( session : FirSession , annotations : List < FirAnnotation > ) : FirClassSymbol < * > ?

= when { <EOL> annotations . hasAnnotation ( SerializationAnnotations . contextualClassId , session ) || <EOL> annotations . hasAnnotation ( SerializationAnnotations . contextualOnPropertyClassId , session ) -> { <EOL> session . dependencySerializationInfoProvider . getClassFromSerializationPackage ( SpecialBuiltins . Names . contextSerializer ) <EOL> } <EOL> annotations . hasAnnotation ( SerializationAnnotations . polymorphicClassId , session ) -> { <EOL> session . dependencySerializationInfoProvider . getClassFromSerializationPackage ( SpecialBuiltins . Names . polymorphicSerializer ) <EOL> } <EOL> else -> null <EOL> }

/**
 * Returns class descriptor for ContextSerializer or PolymorphicSerializer
 * if [annotations] contains @Contextual or @Polymorphic annotation
 */


abstract fun irGet ( startOffset : Int , endOffset : Int , valueDeclaration : IrValueDeclaration ) : IrExpression ?

/**
 * @return the expression to get the value for given declaration, or `null` if [IrGetValue] should be used.
 */


public fun KtDeclaration . getOriginalDeclaration ( ) : KtDeclaration ?

= <EOL> withValidityAssertion { analysisSession . originalPsiProvider . getOriginalDeclaration ( this ) }

/**
 * If [KtDeclaration] is a non-local declaration in a fake file analyzed in dependent session, returns the original declaration
 * for [this]. Otherwise, returns `null`.
 */


public fun KtFile . getOriginalKtFile ( ) : KtFile ?

= <EOL> withValidityAssertion { analysisSession . originalPsiProvider . getOriginalKtFile ( this ) }

/**
 * If [this] is a fake file analyzed in dependent session, returns the original file for [this]. Otherwise, returns `null`.
 */


public fun KtDeclaration . recordOriginalDeclaration ( declaration : KtDeclaration )

{ <EOL> withValidityAssertion { analysisSession . originalPsiProvider . recordOriginalDeclaration ( this , declaration ) } <EOL> }

/**
 * Records [declaration] as an original declaration for [this].
 */


public fun KtFile . recordOriginalKtFile ( file : KtFile )

{ <EOL> withValidityAssertion { analysisSession . originalPsiProvider . recordOriginalKtFile ( this , file ) } <EOL> }

/**
 * Records [file] as an original file for [this].
 */


private fun processValue ( value : Any ? , fieldType : JavaType ) : Any ?

{ <EOL> if ( fieldType !is JavaPrimitiveType || fieldType . type == null || value !is Int ) return value <EOL> return when ( fieldType . type ) { <EOL> PrimitiveType . BOOLEAN -> { <EOL> when ( value ) { <EOL> <NUM_LIT:0> -> false <EOL> <NUM_LIT:1> -> true <EOL> else -> value <EOL> } <EOL> } <EOL> PrimitiveType . CHAR -> value . toChar ( ) <EOL> else -> value <EOL> } <EOL> }

/**
 * All the int-like values (including Char/Boolean) come in visitor as Integer instances
 */


fun getForSplitPaths ( bottom : List < File > , top : List < File > ) : ClassLoader

{ <EOL> return if ( bottom . isEmpty ( ) || top . isEmpty ( ) ) { <EOL> getForClassPath ( bottom + top ) <EOL> } else { <EOL> val key = makeKey ( bottom + top ) <EOL> cache . getOrPut ( key ) { <EOL> val parent = getForClassPath ( top ) <EOL> makeClassLoader ( makeKey ( bottom ) , parent ) <EOL> } <EOL> } <EOL> }

/**
 * Gets or creates [ClassLoader] from [bottom] + [top] files.
 * When creating new [ClassLoader] it tries to get [top] from cache first and then create new ClassLoader from [bottom] files,
 * providing [top] [ClassLoader] as parent.
 * Useful when you have internal and external artifacts and internal ones can be references from other internal artefacts only.
 * So you can safely cache [ClassLoader] from external artifacts and use it for internal ones.
 */


public suspend fun < T > withTimeout ( timeMillis : Long , block : suspend CoroutineScope . ( ) -> T ) : T

{ <EOL> contract { <EOL> callsInPlace ( block , InvocationKind . EXACTLY_ONCE ) <EOL> } <EOL> if ( timeMillis <= <NUM_LIT:0L> ) throw TimeoutCancellationException ( "<STR_LIT>" ) <EOL> return suspendCoroutineUninterceptedOrReturn { uCont -> <EOL> setupTimeout ( TimeoutCoroutine ( timeMillis , uCont ) , block ) <EOL> } <EOL> }

/**
 * Runs a given suspending [block] of code inside a coroutine with a specified [timeout][timeMillis] and throws
 * a [TimeoutCancellationException] if the timeout was exceeded.
 * If the given [timeMillis] is non-positive, [TimeoutCancellationException] is thrown immediately.
 *
 * The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
 * the cancellable suspending function inside the block throws a [TimeoutCancellationException].
 *
 * The sibling function that does not throw an exception on timeout is [withTimeoutOrNull].
 * Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
 *
 * **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
 * even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
 * resource inside the [block] that needs closing or release outside the block.
 * See the
 * [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
 * section of the coroutines guide for details.
 *
 * > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
 *
 * @param timeMillis timeout time in milliseconds.
 */


public suspend fun < T > withTimeout ( timeout : Duration , block : suspend CoroutineScope . ( ) -> T ) : T

{ <EOL> contract { <EOL> callsInPlace ( block , InvocationKind . EXACTLY_ONCE ) <EOL> } <EOL> return withTimeout ( timeout . toDelayMillis ( ) , block ) <EOL> }

/**
 * Runs a given suspending [block] of code inside a coroutine with the specified [timeout] and throws
 * a [TimeoutCancellationException] if the timeout was exceeded.
 * If the given [timeout] is non-positive, [TimeoutCancellationException] is thrown immediately.
 *
 * The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
 * the cancellable suspending function inside the block throws a [TimeoutCancellationException].
 *
 * The sibling function that does not throw an exception on timeout is [withTimeoutOrNull].
 * Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
 *
 * **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
 * even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
 * resource inside the [block] that needs closing or release outside the block.
 * See the
 * [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
 * section of the coroutines guide for details.
 *
 * > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
 */


public suspend fun < T > withTimeoutOrNull ( timeMillis : Long , block : suspend CoroutineScope . ( ) -> T ) : T ?

{ <EOL> if ( timeMillis <= <NUM_LIT:0L> ) return null <EOL> var coroutine : TimeoutCoroutine < T ? , T ? > ? = null <EOL> try { <EOL> return suspendCoroutineUninterceptedOrReturn { uCont -> <EOL> val timeoutCoroutine = TimeoutCoroutine ( timeMillis , uCont ) <EOL> coroutine = timeoutCoroutine <EOL> setupTimeout < T ? , T ? > ( timeoutCoroutine , block ) <EOL> } <EOL> } catch ( e : TimeoutCancellationException ) { <EOL> if ( e . coroutine === coroutine ) { <EOL> return null <EOL> } <EOL> throw e <EOL> } <EOL> }

/**
 * Runs a given suspending block of code inside a coroutine with a specified [timeout][timeMillis] and returns
 * `null` if this timeout was exceeded.
 * If the given [timeMillis] is non-positive, `null` is returned immediately.
 *
 * The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
 * cancellable suspending function inside the block throws a [TimeoutCancellationException].
 *
 * The sibling function that throws an exception on timeout is [withTimeout].
 * Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
 *
 * **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
 * even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
 * resource inside the [block] that needs closing or release outside the block.
 * See the
 * [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
 * section of the coroutines guide for details.
 *
 * > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
 *
 * @param timeMillis timeout time in milliseconds.
 */


public suspend fun < T > withTimeoutOrNull ( timeout : Duration , block : suspend CoroutineScope . ( ) -> T ) : T ?

= <EOL> withTimeoutOrNull ( timeout . toDelayMillis ( ) , block )

/**
 * Runs a given suspending block of code inside a coroutine with the specified [timeout] and returns
 * `null` if this timeout was exceeded.
 * If the given [timeout] is non-positive, `null` is returned immediately.
 *
 * The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
 * cancellable suspending function inside the block throws a [TimeoutCancellationException].
 *
 * The sibling function that throws an exception on timeout is [withTimeout].
 * Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
 *
 * **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
 * even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
 * resource inside the [block] that needs closing or release outside the block.
 * See the
 * [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
 * section of the coroutines guide for details.
 *
 * > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
 */


inline fun IrGeneratorWithScope . irBlock ( expression : IrExpression , origin : IrStatementOrigin ? = null , resultType : IrType ? = expression . type , body : IrBlockBuilder . ( ) -> Unit )

= <EOL> this . irBlock ( expression . startOffset , expression . endOffset , origin , resultType , body )

/**
 * Builds [IrBlock] to be used instead of given expression.
 */


fun visit ( visitor : LLFirResolveTargetVisitor )

{ <EOL> if ( target is FirFile ) { <EOL> visitor . performAction ( target ) <EOL> } <EOL> goToTarget ( visitor ) <EOL> }

/**
 * Visit [path], [target] and optionally its subgraph.
 * Each nested declaration will be wrapped with corresponding [LLFirResolveTargetVisitor.withFile],
 * [LLFirResolveTargetVisitor.withRegularClass] and [LLFirResolveTargetVisitor.withScript] recursively.
 */


protected abstract fun visitTargetElement ( element : FirElementWithResolveState , visitor : LLFirResolveTargetVisitor , )

/**
 * [element] with [FirFile] will be processed before.
 */


fun forEachTarget ( action : ( FirElementWithResolveState ) -> Unit )

{ <EOL> visit ( object : LLFirResolveTargetVisitor { <EOL> override fun performAction ( element : FirElementWithResolveState ) { <EOL> action ( element ) <EOL> } <EOL> } ) <EOL> }

/**
 * Executions the [action] for each target that this [LLFirResolveTarget] represents.
 */


override fun atomicMove ( source : Path , destination : Path )

{ <EOL> val sourcePreOpen = PreOpens . findPreopen ( source ) <EOL> val destPreOpen = PreOpens . findPreopen ( destination ) <EOL> withScopedMemoryAllocator { allocator -> <EOL> val ( sourceBuffer , sourceBufferLength ) = allocator . storeString ( source . path ) <EOL> val ( destBuffer , destBufferLength ) = allocator . storeString ( destination . path ) <EOL> val res = Errno ( path_rename ( oldFd = sourcePreOpen . fd , oldPathPtr = sourceBuffer . address . toInt ( ) , oldPathLen = sourceBufferLength , newFd = destPreOpen . fd , newPathPtr = destBuffer . address . toInt ( ) , newPathLen = destBufferLength ) ) <EOL> when ( res ) { <EOL> Errno . success -> return <EOL> Errno . noent -> throw FileNotFoundException ( "<STR_LIT>" + "<STR_LIT>" ) <EOL> else -> throw IOException ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * The move is not atomic (well, we don't know what kind of move it is), but there are no
 * alternatives.
 */


override fun resolve ( path : Path ) : Path

{ <EOL> val absolutePath = if ( path . isAbsolute ) { <EOL> path <EOL> } else { <EOL> Path ( PreOpens . roots . first ( ) , path . path ) <EOL> } <EOL> val resolvedPath = resolvePathImpl ( absolutePath , <NUM_LIT:0> ) <EOL> ? : throw FileNotFoundException ( "<STR_LIT>" ) <EOL> check ( resolvedPath . isAbsolute ) { <EOL> "<STR_LIT>" <EOL> } <EOL> val normalizedPath = resolvedPath . normalized ( ) <EOL> if ( ! exists ( normalizedPath ) ) throw FileNotFoundException ( "<STR_LIT>" ) <EOL> return normalizedPath <EOL> }

/**
 * Returns an absolute path to the same file or directory the [path] is pointing to.
 * All symbolic links are solved, extra path separators and references to current (`.`) or
 * parent (`..`) directories are removed.
 * If the [path] is a relative path then it'll be resolved against current working directory.
 * If there is no file or directory to which the [path] is pointing to then [FileNotFoundException] will be thrown.
 *
 * The behavior of this method differs from other platforms as the resolution
 * may not fail if there is no filesystem-node (file, directory, symlink, etc.) corresponding
 * to some interior path. This allows successfully resolving paths like `/a/b/c/../../d/e` when
 * pre-opened directories are `/a/b/c` and `/a/d/e`.
 *
 * @param path the path to resolve.
 * @return a resolved path.
 * @throws FileNotFoundException if there is no file or directory corresponding to the specified path.
 */


{ <EOL> if ( catches . isEmpty ( ) ) return null <EOL> val firstCatch = catches . first ( ) <EOL> val catchParameter = firstCatch . catchParameter <EOL> val parameterDescriptor = BindingUtils . getDescriptorForElement ( bindingContext ( ) , catchParameter ! ! ) <EOL> val parameterName = context ( ) . getNameForDescriptor ( parameterDescriptor ) . ident <EOL> val jsCatch = JsCatch ( context ( ) . scope ( ) , parameterName ) <EOL> val parameterRef = jsCatch . parameter . name . makeRef ( ) <EOL> val catchContext = context ( ) . innerContextWithAliased ( parameterDescriptor , parameterRef ) <EOL> jsCatch . body = JsBlock ( translateCatches ( catchContext , parameterRef , catches . iterator ( ) ) ) <EOL> return jsCatch <EOL> }

/**
 * In JavaScript there is no multiple catches, so we translate
 * multiple catch to single catch with instanceof checks for
 * every catch clause.
 *
 * For example this code:
 * try {
 * ...
 * } catch(e: NullPointerException) {
 * ...
 * } catch(e: RuntimeException) {
 * ...
 * }
 *
 * is translated to the following JsCode
 *
 * try {
 * ...
 * } catch(e) {
 * if (e instanceof NullPointerException) {
 * ...
 * } else {
 * if (e instanceof RuntimeException) {
 * ...
 * } else throw e;
 * }
 * }
 */


public fun < K , V > mapOfNotNull ( vararg mapping : Pair < K ? , V ? > ) : Map < K , V >

{ <EOL> return buildMap { <EOL> mapping . forEach { ( k , v ) -> <EOL> if ( k != null && v != null ) { <EOL> put ( k , v ) <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * Create a new read-only map from a list of pairs, if both values in the pair are not null.
 *
 * @param [mapping] pairs of keys and values to put into the map
 * @return map with the provided keys and values, excluding nulls
 * @see kotlin.collections.mapOf(Pair[])
 */


inline fun < T > withExceptionPrettifier ( disabled : Boolean = false , action : ( ) -> T ) : T

{ <EOL> if ( disabled ) { <EOL> return action ( ) <EOL> } <EOL> return try { <EOL> action ( ) <EOL> } catch ( throwable : Throwable ) { <EOL> val prettifiers = listOf ( ClangModulesDisabledPrettifier , ) <EOL> throw prettifiers . firstOrNull { it . matches ( throwable ) } ? . prettify ( throwable ) ? : throwable <EOL> } <EOL> }

/**
 * Wraps invocation of [action] into exception handler and makes messages of supported exceptions more user-friendly.
 * Can be optionally [disabled] which is useful when one want to find the root cause of the prettified exception.
 */


public fun write ( source : Buffer , byteCount : Long )

/**
 * Removes [byteCount] bytes from [source] and appends them to this sink.
 *
 * @param source the source to read data from.
 * @param byteCount the number of bytes to write.
 *
 * @throws IllegalArgumentException when the [source]'s size is below [byteCount] or [byteCount] is negative.
 * @throws IllegalStateException when the sink is closed.
 */


public fun flush ( )

/**
 * Pushes all buffered bytes to their final destination.
 *
 * @throws IllegalStateException when the sink is closed.
 */


override fun close ( )

/**
 * Pushes all buffered bytes to their final destination and releases the resources held by this
 * sink. It is an error to write a closed sink. It is safe to close a sink more than once.
 */


= withSpark { <EOL> val groupIndices = getAllPossibleGroups ( listSize = <NUM_LIT:10> , groupSize = <NUM_LIT:4> ) <EOL> . sort ( "<STR_LIT:value>" ) <EOL> groupIndices . showDS ( numRows = groupIndices . count ( ) . toInt ( ) ) <EOL> }

/**
 * Gets all the possible, unique, non repeating groups of indices for a list.
 *
 * Example by Jolanrensen.
 */


fun KSparkSession . getAllPossibleGroups ( listSize : Int , groupSize : Int , ) : Dataset < IntArray >

{ <EOL> val indices = ( <NUM_LIT:0> until listSize ) . toList ( ) . toRDD ( ) <EOL> if ( groupSize == <NUM_LIT:1> ) { <EOL> return indices <EOL> . mapPartitions { <EOL> it . map { intArrayOf ( it ) } <EOL> } <EOL> . toDS ( ) <EOL> } <EOL> val keys = indices . mapPartitions { <EOL> it . transformAsSequence { <EOL> flatMap { listIndex -> <EOL> ( <NUM_LIT:0> until groupSize ) . asSequence ( ) . flatMap { dimension -> <EOL> addTuples ( groupSize = groupSize , value = listIndex , listSize = listSize , skipDimension = dimension , ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> val allPossibleGroups = keys . aggregateByKey ( zeroValue = IntArray ( groupSize ) { - <NUM_LIT:1> } , seqFunc = { base : IntArray , listIndex : Int -> <EOL> base [ base . indexOfFirst { it < <NUM_LIT:0> } ] = listIndex <EOL> base <EOL> } , combFunc = { a : IntArray , b : IntArray -> <EOL> var j = <NUM_LIT:0> <EOL> for ( i in a . indices ) { <EOL> if ( a [ i ] < <NUM_LIT:0> ) { <EOL> while ( b [ j ] < <NUM_LIT:0> ) { <EOL> j ++ <EOL> if ( j == b . size ) return@aggregateByKey a <EOL> } <EOL> a [ i ] = b [ j ] <EOL> j ++ <EOL> } <EOL> } <EOL> a <EOL> } , ) <EOL> . values ( ) <EOL> return allPossibleGroups . toDS ( ) <EOL> }

/**
 * Get all the possible, unique, non repeating groups (of size [groupSize]) of indices for a list of
 * size [listSize].
 *
 *
 * The workload is evenly distributed by [listSize] and [groupSize]
 *
 * @param listSize the size of the list for which to calculate the indices
 * @param groupSize the size of a group of indices
 * @return all the possible, unique non repeating groups of indices
 */


private fun getTupleValue ( indexTuple : List < Int > , listSize : Int ) : Int

= <EOL> indexTuple . indices . sumOf { <EOL> indexTuple [ it ] * listSize . toDouble ( ) . pow ( it ) . toInt ( ) <EOL> }

/**
 * Simple method to give each index of x dimensions a unique number.
 *
 * @param indexTuple IntArray (can be seen as Tuple) of size x with all values < listSize. The index for which to return the number
 * @param listSize The size of the list, aka the max width, height etc. of the table
 * @return the unique number for this [indexTuple]
 */


private fun addTuples ( groupSize : Int , value : Int , listSize : Int , skipDimension : Int , ) : List < Tuple2 < Int , Int > >

{ <EOL> fun recursiveCall ( currentDimension : Int = <NUM_LIT:0> , indexTuple : List < Int > = emptyList ( ) , ) : List < Tuple2 < Int , Int > > = when { <EOL> currentDimension >= groupSize -> <EOL> if ( isValidIndexTuple ( indexTuple ) ) <EOL> listOf ( getTupleValue ( indexTuple , listSize ) X value ) <EOL> else <EOL> emptyList ( ) <EOL> currentDimension == skipDimension -> <EOL> recursiveCall ( currentDimension = currentDimension + <NUM_LIT:1> , indexTuple = indexTuple + value , ) <EOL> else -> <EOL> ( <NUM_LIT:0> until listSize ) . flatMap { i -> <EOL> recursiveCall ( currentDimension = currentDimension + <NUM_LIT:1> , indexTuple = indexTuple + i , ) <EOL> } <EOL> } <EOL> return recursiveCall ( ) <EOL> }

/**
 * Recursive method that for [skipDimension] loops over all the other dimensions and returns all results from
 * [getTupleValue] as key and [value] as value.
 * In the end, the return value will have, for each key in the table below, a value for the key's column, row etc.
 *
 *
 * This is an example for 2D. The letters will be int indices as well (a = 0, b = 1, ..., [listSize]), but help for clarification.
 * The numbers we don't want are filtered out using [isValidIndexTuple].
 * The actual value of the number in the table comes from [getTupleValue].
 *
 *
 *
 *
 * - a b c d e f g h i j
 * --------------------------------
 * a| - 1 2 3 4 5 6 7 8 9
 * b| - - 12 13 14 15 16 17 18 19
 * c| - - - 23 24 25 26 27 28 29
 * d| - - - - 34 35 36 37 38 39
 * e| - - - - - 45 46 47 48 49
 * f| - - - - - - 56 57 58 59
 * g| - - - - - - - 67 68 69
 * h| - - - - - - - - 78 79
 * i| - - - - - - - - - 89
 * j| - - - - - - - - - -
 *
 *
 * @param groupSize the size of index tuples to form
 * @param value the current index to work from (can be seen as a letter in the table above)
 * @param listSize the size of the list to make
 * @param skipDimension the current dimension that will have a set value [value] while looping over the other dimensions
 */


{ <EOL> _builder . clearSourceDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinSourceDependencyProto source_dependency = 1;</code>
 */


fun hasSourceDependency ( ) : kotlin . Boolean

{ <EOL> return _builder . hasSourceDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinSourceDependencyProto source_dependency = 1;</code>
 * @return Whether the sourceDependency field is set.
 */


{ <EOL> _builder . clearResolvedBinaryDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinResolvedBinaryDependencyProto resolved_binary_dependency = 2;</code>
 */


fun hasResolvedBinaryDependency ( ) : kotlin . Boolean

{ <EOL> return _builder . hasResolvedBinaryDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinResolvedBinaryDependencyProto resolved_binary_dependency = 2;</code>
 * @return Whether the resolvedBinaryDependency field is set.
 */


{ <EOL> _builder . clearUnresolvedBinaryDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinUnresolvedBinaryDependencyProto unresolved_binary_dependency = 3;</code>
 */


fun hasUnresolvedBinaryDependency ( ) : kotlin . Boolean

{ <EOL> return _builder . hasUnresolvedBinaryDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinUnresolvedBinaryDependencyProto unresolved_binary_dependency = 3;</code>
 * @return Whether the unresolvedBinaryDependency field is set.
 */


{ <EOL> _builder . clearProjectArtifactDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinProjectArtifactDependencyProto project_artifact_dependency = 4;</code>
 */


fun hasProjectArtifactDependency ( ) : kotlin . Boolean

{ <EOL> return _builder . hasProjectArtifactDependency ( ) <EOL> }

/**
 * <code>.org.jetbrains.kotlin.gradle.idea.proto.generated.tcs.IdeaKotlinProjectArtifactDependencyProto project_artifact_dependency = 4;</code>
 * @return Whether the projectArtifactDependency field is set.
 */


public actual fun String ? . toBoolean ( ) : Boolean

= this != null && this . lowercase ( ) == "<STR_LIT:true>"

/**
 * Returns `true` if the contents of this string is equal to the word "true", ignoring case, and `false` otherwise.
 *
 * There are also strict versions of the function available on non-nullable String, [toBooleanStrict] and [toBooleanStrictOrNull].
 */


public actual fun String . toByte ( ) : Byte

= toByteOrNull ( ) ? : numberFormatError ( this )

/**
 * Parses the string as a signed [Byte] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 */


public actual fun String . toByte ( radix : Int ) : Byte

= toByteOrNull ( radix ) ? : numberFormatError ( this )

/**
 * Parses the string as a signed [Byte] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
 */


public actual fun String . toShort ( ) : Short

= toShortOrNull ( ) ? : numberFormatError ( this )

/**
 * Parses the string as a [Short] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 */


public actual fun String . toShort ( radix : Int ) : Short

= toShortOrNull ( radix ) ? : numberFormatError ( this )

/**
 * Parses the string as a [Short] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
 */


public actual fun String . toInt ( ) : Int

= toIntOrNull ( ) ? : numberFormatError ( this )

/**
 * Parses the string as an [Int] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 */


public actual fun String . toInt ( radix : Int ) : Int

= toIntOrNull ( radix ) ? : numberFormatError ( this )

/**
 * Parses the string as an [Int] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
 */


public actual fun String . toLong ( ) : Long

= toLongOrNull ( ) ? : numberFormatError ( this )

/**
 * Parses the string as a [Long] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 */


public actual fun String . toLong ( radix : Int ) : Long

= toLongOrNull ( radix ) ? : numberFormatError ( this )

/**
 * Parses the string as a [Long] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
 */


public actual fun String . toDouble ( ) : Double

= kotlin . text . parseDouble ( this )

/**
 * Parses the string as a [Double] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 */


public actual fun String . toFloat ( ) : Float

= wasm_f32_demote_f64 ( toDouble ( ) )

/**
 * Parses the string as a [Float] number and returns the result.
 * @throws NumberFormatException if the string is not a valid representation of a number.
 */


public actual fun String . toFloatOrNull ( ) : Float ?

= toDoubleOrNull ( ) ? . let { wasm_f32_demote_f64 ( it ) }

/**
 * Parses the string as a [Float] number and returns the result
 * or `null` if the string is not a valid representation of a number.
 */


public actual fun String . toDoubleOrNull ( ) : Double ?

{ <EOL> try { <EOL> return toDouble ( ) <EOL> } catch ( e : NumberFormatException ) { <EOL> return null <EOL> } <EOL> }

/**
 * Parses the string as a [Double] number and returns the result
 * or `null` if the string is not a valid representation of a number.
 */


@ SinceKotlin ( "<STR_LIT:1.2>" ) <EOL> public actual fun Byte . toString ( radix : Int ) : String

= this . toInt ( ) . toString ( radix )

/**
 * Returns a string representation of this [Byte] value in the specified [radix].
 *
 * @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
 */


@ SinceKotlin ( "<STR_LIT:1.2>" ) <EOL> public actual fun Short . toString ( radix : Int ) : String

= this . toInt ( ) . toString ( radix )

/**
 * Returns a string representation of this [Short] value in the specified [radix].
 *
 * @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
 */


@ SinceKotlin ( "<STR_LIT:1.2>" ) <EOL> public actual fun Int . toString ( radix : Int ) : String

{ <EOL> val isNegative = this < <NUM_LIT:0> <EOL> val absValue = if ( isNegative ) - this else this <EOL> val absValueString = uintToString ( absValue , checkRadix ( radix ) ) <EOL> return if ( isNegative ) "<STR_LIT>" else absValueString <EOL> }

/**
 * Returns a string representation of this [Int] value in the specified [radix].
 *
 * @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
 */


@ SinceKotlin ( "<STR_LIT:1.2>" ) <EOL> public actual fun Long . toString ( radix : Int ) : String

{ <EOL> val isNegative = this < <NUM_LIT:0> <EOL> val absValue = if ( isNegative ) - this else this <EOL> val absValueString = ulongToString ( absValue , checkRadix ( radix ) ) <EOL> return if ( isNegative ) "<STR_LIT>" else absValueString <EOL> }

/**
 * Returns a string representation of this [Long] value in the specified [radix].
 *
 * @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
 */


protected fun addToClassStorage ( classProtoData : ClassProtoData , srcFile : File ? )

{ <EOL> val ( proto , nameResolver ) = classProtoData <EOL> val supertypes = proto . supertypes ( TypeTable ( proto . typeTable ) ) <EOL> val parents = supertypes . map { nameResolver . getClassId ( it . className ) . asSingleFqName ( ) } <EOL> . filter { it . asString ( ) != "<STR_LIT:kotlin.Any>" } <EOL> . toSet ( ) <EOL> val child = nameResolver . getClassId ( proto . fqName ) . asSingleFqName ( ) <EOL> parents . forEach { subtypesMap . append ( it , child ) } <EOL> val removedSupertypes = supertypesMap [ child ] . orEmpty ( ) . filter { it !in parents } <EOL> removedSupertypes . forEach { subtypesMap . removeValues ( it , setOf ( child ) ) } <EOL> supertypesMap [ child ] = parents <EOL> srcFile ? . let { classFqNameToSourceMap [ child ] = it } <EOL> classAttributesMap [ child ] = ICClassesAttributes ( ProtoBuf . Modality . SEALED == Flags . MODALITY . get ( proto . flags ) ) <EOL> }

/**
 * Updates class storage based on the given class proto.
 *
 * The `srcFile` argument may be `null` (e.g., if we are processing .class files in jars where source files are not available).
 */


{ <EOL> _builder . clearGroup ( ) <EOL> }


{ <EOL> return _builder . hasGroup ( ) <EOL> }

/**
 * optional string group = 1;
 * @return Whether the group field is set.
 */


{ <EOL> _builder . clearName ( ) <EOL> }


{ <EOL> return _builder . hasName ( ) <EOL> }

/**
 * optional string name = 2;
 * @return Whether the name field is set.
 */


{ <EOL> _builder . clearVersion ( ) <EOL> }


{ <EOL> return _builder . hasVersion ( ) <EOL> }

/**
 * optional string version = 3;
 * @return Whether the version field is set.
 */


@ OptIn ( DelicateCoroutinesApi :: class , ExperimentalCoroutinesApi :: class ) <EOL> override fun translateClassDescriptor ( descriptor : ClassDescriptor , sourceSet : DokkaSourceSet ) : DClasslike

{ <EOL> val driInfo = DRI . from ( descriptor . parents . first ( ) ) . withEmptyInfo ( ) <EOL> val javadocParser = <EOL> if ( sourceSet . analysisPlatform == Platform . jvm ) <EOL> JavadocParser ( docCommentParsers = context . plugin < JavaAnalysisPlugin > ( ) . query { docCommentParsers } , docCommentFinder = context . plugin < JavaAnalysisPlugin > ( ) . docCommentFinder ) <EOL> else null <EOL> return newSingleThreadContext ( "<STR_LIT>" ) . use { coroutineContext -> <EOL> runBlocking ( coroutineContext ) { <EOL> DokkaDescriptorVisitor ( sourceSet , kdocFinder , kotlinAnalysis [ sourceSet ] , context . logger , javadocParser ) <EOL> . visitClassDescriptor ( descriptor , driInfo ) <EOL> } <EOL> } <EOL> }

/**
 * Implementation note: it runs in a separated single thread due to existing support of coroutines (see #2936)
 */