public suspend fun acquire ( )

/**
 * Acquires a permit from this semaphore, suspending until one is available.
 * All suspending acquirers are processed in first-in-first-out (FIFO) order.
 *
 * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled while this
 * suspending function is waiting, this function immediately resumes with [CancellationException].
 * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled
 * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details.
 * This function releases the semaphore if it was already acquired by this function before the [CancellationException]
 * was thrown.
 *
 * Note that this function does not check for cancellation when it does not suspend.
 * Use [CoroutineScope.isActive] or [CoroutineScope.ensureActive] to periodically
 * check for cancellation in tight loops if needed.
 *
 * Use [tryAcquire] to try to acquire a permit of this semaphore without suspension.
 */


public fun tryAcquire ( ) : Boolean

/**
 * Tries to acquire a permit from this semaphore without suspension.
 *
 * @return `true` if a permit was acquired, `false` otherwise.
 */


public fun release ( )

/**
 * Releases a permit, returning it into this semaphore. Resumes the first
 * suspending acquirer if there is one at the point of invocation.
 * Throws [IllegalStateException] if the number of [release] invocations is greater than the number of preceding [acquire].
 */


@ Suppress ( "<STR_LIT:FunctionName>" ) <EOL> public fun Semaphore ( permits : Int , acquiredPermits : Int = <NUM_LIT:0> ) : Semaphore

= SemaphoreImpl ( permits , acquiredPermits )

/**
 * Creates new [Semaphore] instance.
 * @param permits the number of permits available in this semaphore.
 * @param acquiredPermits the number of already acquired permits,
 * should be between `0` and `permits` (inclusively).
 */


@ OptIn ( ExperimentalContracts :: class ) <EOL> public suspend inline fun < T > Semaphore . withPermit ( action : ( ) -> T ) : T

{ <EOL> contract { <EOL> callsInPlace ( action , InvocationKind . EXACTLY_ONCE ) <EOL> } <EOL> acquire ( ) <EOL> return try { <EOL> action ( ) <EOL> } finally { <EOL> release ( ) <EOL> } <EOL> }

/**
 * Executes the given [action], acquiring a permit from this semaphore at the beginning
 * and releasing it after the [action] is completed.
 *
 * @return the return value of the [action].
 */


{ <EOL> while ( true ) { <EOL> val p = _availablePermits . getAndDecrement ( ) <EOL> if ( p > permits ) continue <EOL> return p <EOL> } <EOL> }

/**
 * Decrements the number of available permits
 * and ensures that it is not greater than [permits]
 * at the point of decrement. The last may happen
 * due to an incorrect `release()` call without
 * a preceding `acquire()`.
 */


private fun coerceAvailablePermitsAtMaximum ( )

{ <EOL> while ( true ) { <EOL> val cur = _availablePermits . value <EOL> if ( cur <= permits ) break <EOL> if ( _availablePermits . compareAndSet ( cur , permits ) ) break <EOL> } <EOL> }

/**
 * Changes the number of available permits to
 * [permits] if it became greater due to an
 * incorrect [release] call.
 */


private fun addAcquireToQueue ( waiter : Waiter ) : Boolean

{ <EOL> val curTail = this . tail . value <EOL> val enqIdx = enqIdx . getAndIncrement ( ) <EOL> val createNewSegment = :: createSegment <EOL> val segment = this . tail . findSegmentAndMoveForward ( id = enqIdx / SEGMENT_SIZE , startFrom = curTail , createNewSegment = createNewSegment ) . segment <EOL> val i = ( enqIdx % SEGMENT_SIZE ) . toInt ( ) <EOL> if ( segment . cas ( i , null , waiter ) ) { <EOL> waiter . invokeOnCancellation ( segment , i ) <EOL> return true <EOL> } <EOL> if ( segment . cas ( i , PERMIT , TAKEN ) ) { <EOL> when ( waiter ) { <EOL> is CancellableContinuation < * > -> { <EOL> waiter as CancellableContinuation < Unit > <EOL> waiter . resume ( Unit , onCancellationRelease ) <EOL> } <EOL> is SelectInstance < * > -> { <EOL> waiter . selectInRegistrationPhase ( Unit ) <EOL> } <EOL> else -> error ( "<STR_LIT>" ) <EOL> } <EOL> return true <EOL> } <EOL> assert { segment . get ( i ) === BROKEN } <EOL> return false <EOL> }

/**
 * Returns `false` if the received permit cannot be used and the calling operation should restart.
 */


abstract fun asReversed ( ) : HeaderInfo ?

/**
 * Returns a copy of this [HeaderInfo] with the values reversed.
 * I.e., first and last are swapped, step is negated.
 * Returns null if the iterable cannot be iterated in reverse.
 */


fun matchIterable ( expression : E ) : Boolean

/** Returns true if the handler can build a [HeaderInfo] from the iterable expression. */


fun matchIteratorCall ( call : IrCall ) : Boolean

= true

/**
 * Matches the `iterator()` call that produced the iterable; if the call matches (or the matcher is null),
 * the handler can build a [HeaderInfo] from the iterable.
 */


fun build ( expression : E , data : D , scopeOwner : IrSymbol ) : HeaderInfo ?

/** Builds a [HeaderInfo] from the expression. */


override fun visitCall ( expression : IrCall , data : IrCall ? ) : HeaderInfo ?

{ <EOL> val callHeaderInfo = callHandlers . firstNotNullOfOrNull { it . handle ( expression , data , null , scopeOwnerSymbol ( ) ) } <EOL> if ( callHeaderInfo != null ) <EOL> return callHeaderInfo <EOL> val progressionType = ProgressionType . fromIrType ( expression . type , symbols , allowUnsignedBounds ) <EOL> val progressionHeaderInfo = <EOL> progressionType ? . run { progressionHandlers . firstNotNullOfOrNull { it . handle ( expression , data , this , scopeOwnerSymbol ( ) ) } } <EOL> return progressionHeaderInfo ? : super . visitCall ( expression , data ) <EOL> }

/** Builds a [HeaderInfo] for iterable expressions that are calls (e.g., `.reversed()`, `.indices`. */


override fun visitExpression ( expression : IrExpression , data : IrCall ? ) : HeaderInfo ?

{ <EOL> return expressionHandlers . firstNotNullOfOrNull { it . handle ( expression , data , null , scopeOwnerSymbol ( ) ) } <EOL> ? : super . visitExpression ( expression , data ) <EOL> }

/** Builds a [HeaderInfo] for iterable expressions not handled in [visitCall]. */


@ Deprecated ( "<STR_LIT>" ) <EOL> fun GradleRunner . withEnvironment ( build : MutableMap < String , String ? > . ( ) -> Unit ) : GradleRunner

{ <EOL> val env = environment ? : mutableMapOf ( ) <EOL> env . build ( ) <EOL> return withEnvironment ( env ) <EOL> }

/** Edit environment variables in the Gradle Runner */


fun GradleRunner . addArguments ( vararg arguments : String ) : GradleRunner

= <EOL> withArguments ( this @ addArguments . arguments + arguments )

/**
 * Helper function to _append_ [arguments] to any existing
 * [GradleRunner arguments][GradleRunner.getArguments].
 */


internal fun < T : Task , R : Any > TaskCollection < T > . implementing ( kclass : KClass < R > ) : TaskCollection < T >

= <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> withType ( kclass . java as Class < T > )

/**
 * Filters a [TaskCollection] by type that is not a subtype of [Task] (for use with interfaces)
 *
 * TODO properly express within the type system? The result should be a TaskCollection<T & R>
 */


@ Test <EOL> fun `test Android compilations visible in whenEvaluated` ( )

{ <EOL> project . applyGradleBuiltInPlugins ( ) <EOL> val kotlin = project . applyMultiplatformPlugin ( ) <EOL> var triggered = false <EOL> project . whenEvaluated { <EOL> val androidCompilations = kotlin . targets . getByName ( "<STR_LIT>" ) . compilations <EOL> assertTrue { androidCompilations . isNotEmpty ( ) } <EOL> assertFalse ( triggered , "<STR_LIT>" ) <EOL> triggered = true <EOL> } <EOL> project . applyAndroidLibraryPlugin ( ) <EOL> kotlin . androidTarget ( ) <EOL> project . evaluate ( ) <EOL> assertTrue { triggered } <EOL> }

/**
 * Check that the `whenEvaluated` actions that are scheduled before the Android plugin is applied get triggered only after the actions
 * done in the Android plugin's afterEvaluate phase
 */


override fun invokeOnTimeout ( timeMillis : Long , block : Runnable , context : CoroutineContext ) : DisposableHandle

= <EOL> scheduleInvokeOnTimeout ( timeMillis , block )

/**
 * All event loops are using DefaultExecutor#invokeOnTimeout to avoid livelock on
 * ```
 * runBlocking(eventLoop) { withTimeout { while(isActive) { ... } } }
 * ```
 *
 * Livelock is possible only if `runBlocking` is called on internal default executed (which is used by default [delay]),
 * but it's not exposed as public API.
 */


public fun LayerPlotContext . facetGridX ( x : ColumnReference < * > , scalesSharing : ScalesSharing ? = null , order : OrderDirection = OrderDirection . ASCENDING , format : String ? = null )

{ <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> val xColName = datasetHandler . takeColumn ( x . name ( ) ) <EOL> plotFeatures [ FacetGridFeature . FEATURE_NAME ] = <EOL> FacetGridFeature ( xColName , null , scalesSharing , order , OrderDirection . ASCENDING , format , null ) <EOL> }

/**
 * Splits data by a variable across X.
 * For each data subset creates a plot panel and lays out panels as grid.
 *
 * @param x Variable which defines columns of the facet grid.
 * @param scalesSharing Specifies whether scales are shared across all facets.
 * @param order Specifies the ordering direction of columns
 * @param format Specifies the format pattern for displaying faceting values in columns.
 *
 * Format pattern in the format parameters can be just a number format (like "d") or
 * a string template where a number format is surrounded by curly braces: "{d} cylinders".
 * Note: the "$" must be escaped as "\$"
 *
 * Examples:
 * ".2f" -> "12.45"
 * "Score: {.2f}" -> "Score: 12.45"
 * "'Score: {}' "-> "Score: 12.454789"
 */


public fun LayerPlotContext . facetGridY ( y : ColumnReference < * > , scalesSharing : ScalesSharing ? = null , order : OrderDirection = OrderDirection . ASCENDING , format : String ? = null )

{ <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> val yColName = datasetHandler . takeColumn ( y . name ( ) ) <EOL> plotFeatures [ FacetGridFeature . FEATURE_NAME ] = <EOL> FacetGridFeature ( null , yColName , scalesSharing , OrderDirection . ASCENDING , order , null , format ) <EOL> }

/**
 * Splits data by a variable across Y.
 * For each data subset creates a plot panel and lays out panels as grid.
 *
 * @param y variable which defines rows of the facet grid.
 * @param scalesSharing specifies whether scales are shared across all facets.
 * @param order specifies the ordering direction of rows
 * @param format specifies the format pattern for displaying faceting values in rows.
 *
 * Format pattern in the format parameters can be just a number format (like "d") or
 * a string template where the number format is surrounded by curly braces: "{d} cylinders".
 * Note: the "$" must be escaped as "\$"
 *
 * Examples:
 * ".2f" -> "12.45"
 * "Score: {.2f}" -> "Score: 12.45"
 * "'Score: {}' "-> "Score: 12.454789"
 */


@ Suppress ( "<STR_LIT>" ) <EOL> public fun LayerPlotContext . facetGrid ( x : ColumnReference < * > , y : ColumnReference < * > , scalesSharing : ScalesSharing ? = null , xOrder : OrderDirection = OrderDirection . ASCENDING , yOrder : OrderDirection = OrderDirection . ASCENDING , xFormat : String ? = null , yFormat : String ? = null )

{ <EOL> val xColName = datasetHandler . takeColumn ( x . name ( ) ) <EOL> val yColName = datasetHandler . takeColumn ( y . name ( ) ) <EOL> plotFeatures [ FacetGridFeature . FEATURE_NAME ] = <EOL> FacetGridFeature ( xColName , yColName , scalesSharing , xOrder , yOrder , xFormat , yFormat ) <EOL> }

/**
 * Splits data by two faceting variables across X and Y.
 * For each data subset creates a plot panel and lays out panels as grid.
 * The grid columns are defined by X faceting variable, and rows are defined by Y faceting variable.
 *
 * @param x variable which defines columns of the facet grid.
 * @param y variable which defines rows of the facet grid.
 * @param scalesSharing specifies whether scales are shared across all facets.
 * @param xOrder specifies the ordering direction of columns
 * @param yOrder specifies the ordering direction of rows
 * @param xFormat specifies the format pattern for displaying faceting values in columns.
 * @param yFormat specifies the format pattern for displaying faceting values in rows.
 *
 * Format pattern in the xFormat/yFormat parameters can be just a number format (like "d") or
 * a string template where the number format is surrounded by curly braces: "{d} cylinders".
 * Note: the "$" must be escaped as "\$"
 *
 * Examples:
 * ".2f" -> "12.45"
 * "Score: {.2f}" -> "Score: 12.45"
 * "'Score: {}' "-> "Score: 12.454789"
 */


public fun LayerPlotContext . facetWrap ( nCol : Int ? = null , nRow : Int ? = null , scalesSharing : ScalesSharing = ScalesSharing . FIXED , direction : Direction = Direction . HORIZONTAL , block : FacetWrapContext . ( ) -> Unit )

{ <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> plotFeatures [ FacetWrapFeature . FEATURE_NAME ] = <EOL> FacetWrapContext ( ) . apply ( block ) . toFeature ( datasetHandler , nCol , nRow , scalesSharing , direction ) <EOL> }

/**
 * Splits data by one or more faceting variables.
 * For each data subset creates a plot panel and lays out panels according to the `
 * nCol`, `nRow` and `direction` settings.
 *
 * Opens a [FacetWrapContext]. [FacetWrapContext.facets] is defined in this context. This method adds
 * a new facet to a given variable.
 *
 * ```
 * facetWrap(nRow = 3, scalesSharing = ScalesSharing.FREE_X) {
 * facet(col1)
 * facet(col2, OrderDirection.DESCENDING)
 * facet(col3, format = {.2f})
 * }
 * ```
 *
 * @param nCol number of columns.
 * @param nRow number of rows.
 * @param scalesSharing specifies whether scales are shared across all facets.
 * @param direction direction of the facet.
 */


abstract fun produceAdditionalFiles ( globalDirectives : RegisteredDirectives , module : TestModule ) : List < TestFile >

/**
 * Note that you can not use [testServices.moduleStructure] here because it's not initialized yet
 */


internal fun SymbolTable . referenceUndiscoveredExpectSymbols ( files : Collection < KtFile > , bindingContext : BindingContext )

{ <EOL> val visitor = UndiscoveredExpectVisitor ( this , bindingContext ) <EOL> files . forEach ( visitor :: visitKtFile ) <EOL> }

/**
 * [referenceUndiscoveredExpectSymbols] ensures that `actual` symbols declared in any of the given [files] have an associated `expect`
 * symbol in the symbol table. During lowering, an `expect` symbol may be referenced from an `actual` symbol via _descriptors_, so unbound
 * symbols may occur if the `expect` symbol isn't otherwise included in the symbol table and stubbed before lowering.
 *
 * Undiscovered `expect` symbols are not normally an issue when the source code containing the `expect` declarations is contained in the
 * files to compile, but in cases such as the IDE bytecode tool window, such a source file won't be included in [files].
 */


actual fun inv ( n : Int , mat : FloatArray , lda : Int ) : Int

= mat . usePinned { <EOL> inverse_matrix_float ( n , it . addressOf ( <NUM_LIT:0> ) , lda ) <EOL> }

/**
 * @param n number of rows and columns of the matrix [mat]
 * @param mat square matrix
 * @param lda first dimension of the matrix [mat]
 * @return int:
 * = 0 - successful exit
 * < 0 - if number = -i, the i-th argument had an illegal value
 * > 0 if number = i, U(i,i) is exactly zero; the matrix is singular and its inverse could not be computed.
 */


actual fun solve ( n : Int , nrhs : Int , a : FloatArray , lda : Int , b : FloatArray , ldb : Int ) : Int

= b . usePinned { <EOL> solve_linear_system_float ( n , nrhs , a . toCValues ( ) , lda , it . addressOf ( <NUM_LIT:0> ) , ldb ) <EOL> }

/**
 * @param n
 * @param nrhs
 * @param a
 * @param lda
 * @param b
 * @param ldb
 * @return
 */


actual fun dotMM ( transA : Boolean , offsetA : Int , a : FloatArray , m : Int , k : Int , lda : Int , transB : Boolean , offsetB : Int , b : FloatArray , n : Int , ldb : Int , c : FloatArray )

= c . usePinned { <EOL> matrix_dot_float ( transA , offsetA , a . toCValues ( ) , lda , m , n , k , transB , offsetB , b . toCValues ( ) , ldb , it . addressOf ( <NUM_LIT:0> ) ) <EOL> }

/**
 * @param transA transposed matrix [a]
 * @param offsetA offset of the matrix [a]
 * @param a first matrix
 * @param m number of rows of the matrix [a] and of the matrix [c]
 * @param k number of columns of the matrix [a] and number of rows of the matrix [b]
 * @param lda first dimension of the matrix [a]
 * @param transB transposed matrix [b]
 * @param offsetB offset of the matrix [b]
 * @param b second matrix
 * @param n number of columns of the matrix [b] and of the matrix [c]
 * @param ldb first dimension of the matrix [b]
 * @param c matrix of result
 */


actual fun dotMV ( transA : Boolean , offsetA : Int , a : FloatArray , m : Int , n : Int , lda : Int , offsetX : Int , x : FloatArray , incX : Int , y : FloatArray )

{ <EOL> val aPin = a . pin ( ) <EOL> val xPin = x . pin ( ) <EOL> y . usePinned { <EOL> matrix_dot_vector_float ( transA , offsetA , aPin . addressOf ( <NUM_LIT:0> ) , lda , m , n , offsetX , xPin . addressOf ( <NUM_LIT:0> ) , incX , it . addressOf ( <NUM_LIT:0> ) ) <EOL> } <EOL> aPin . unpin ( ) <EOL> xPin . unpin ( ) <EOL> }

/**
 * @param transA transposed matrix [a]
 * @param offsetA offset of the matrix [a]
 * @param a first matrix
 * @param m number of rows of the matrix [a]
 * @param n number of columns of the matrix [a]
 * @param lda first dimension of the matrix [a]
 * @param x vector
 * @param y vector
 */


actual fun dotVV ( n : Int , offsetX : Int , x : FloatArray , incX : Int , offsetY : Int , y : FloatArray , incY : Int ) : Float

= <EOL> vector_dot_float ( n , offsetX , x . toCValues ( ) , incX , offsetY , y . toCValues ( ) , incY )

/**
 * @param n size of vectors
 * @param x first vector
 * @param incX stride of the vector [x]
 * @param y second vector
 * @param incY stride of the vector [y]
 */


inline fun collectSessionsAndPublishInvalidationEvent ( action : ( ) -> Unit )

{ <EOL> require ( invalidatedModules == null ) { <EOL> "<STR_LIT>" <EOL> } <EOL> invalidatedModules = mutableSetOf ( ) <EOL> try { <EOL> action ( ) <EOL> if ( invalidatedModules ? . isNotEmpty ( ) == true ) { <EOL> project . analysisMessageBus <EOL> . syncPublisher ( LLFirSessionInvalidationTopics . SESSION_INVALIDATION ) <EOL> . afterInvalidation ( invalidatedModules ! ! ) <EOL> } <EOL> } finally { <EOL> invalidatedModules = null <EOL> } <EOL> }

/**
 * Invokes [action] and collects all sessions which were invalidated during its execution. At the end, publishes a session invalidation
 * event if at least one session was invalidated.
 *
 * Invalidated sessions are tracked via [collectSession].
 *
 * Must be called in a write action.
 */