/**
 * [<caret_1>one.two.ext]
 * [one.<caret_2>two.ext]
 *
 * [<caret_3>Foo.ext]
 * [one.two.<caret_4>Foo.ext]
 *
 * [<caret_5>one.two.Foo.ext]
 * [one.<caret_6>two.Foo.ext]
 */


@ Test <EOL> fun `should parse include description for a nested package in kotlin-jvm` ( )

{ <EOL> val testProject = kotlinJvmTestProject { <EOL> dokkaConfiguration { <EOL> kotlinSourceSet { <EOL> includes = setOf ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> ktFile ( pathFromSrc = "<STR_LIT>" ) { <EOL> + "<STR_LIT>" <EOL> } <EOL> mdFile ( pathFromProjectRoot = "<STR_LIT>" ) { <EOL> + """<STR_LIT>""" <EOL> } <EOL> } <EOL> testProject . useServices { context -> <EOL> val pckg = context . module . packages . single { it . name == "<STR_LIT>" } <EOL> val allPackageDocs = moduleAndPackageDocumentationReader . read ( pckg ) <EOL> assertEquals ( <NUM_LIT:1> , allPackageDocs . size ) <EOL> val sourceSetPackageDocs = allPackageDocs . entries . single ( ) . value <EOL> assertEquals ( <NUM_LIT:1> , sourceSetPackageDocs . children . size ) <EOL> val descriptionTag = sourceSetPackageDocs . children . single ( ) as Description <EOL> assertEquals ( <NUM_LIT:1> , descriptionTag . children . size ) <EOL> val paragraphTag = descriptionTag . children . single ( ) as P <EOL> assertEquals ( <NUM_LIT:3> , paragraphTag . children . size ) <EOL> val expectedParagraphChildren = listOf ( Text ( "<STR_LIT>" ) , CodeInline ( children = listOf ( Text ( "<STR_LIT>" ) ) ) , Text ( "<STR_LIT>" ) ) <EOL> assertEquals ( expectedParagraphChildren , paragraphTag . children ) <EOL> } <EOL> }


@ KtAnalysisApiInternals <EOL> fun ClassKind . toKtClassKind ( isCompanionObject : Boolean ) : KtClassKind

= when ( this ) { <EOL> ClassKind . INTERFACE -> KtClassKind . INTERFACE <EOL> ClassKind . ENUM_CLASS -> KtClassKind . ENUM_CLASS <EOL> ClassKind . ANNOTATION_CLASS -> KtClassKind . ANNOTATION_CLASS <EOL> ClassKind . CLASS -> KtClassKind . CLASS <EOL> ClassKind . OBJECT -> if ( isCompanionObject ) KtClassKind . COMPANION_OBJECT else KtClassKind . OBJECT <EOL> ClassKind . ENUM_ENTRY -> invalidEnumEntryAsClassKind ( ) <EOL> }


@ KtAnalysisApiInternals <EOL> fun invalidEnumEntryAsClassKind ( ) : Nothing

{ <EOL> error ( "<STR_LIT>" ) <EOL> }


{ <EOL> val a1 = Actor ( <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" ) <EOL> val a1c = a1 . copy ( ) <EOL> if ( a1c . id != a1 . id ) return "<STR_LIT>" <EOL> val a2 = Actor ( <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if ( a2 == a1 ) return "<STR_LIT>" <EOL> if ( a2 . hashCode ( ) == a1 . hashCode ( ) ) return "<STR_LIT>" <EOL> a1 . toString ( ) <EOL> return "<STR_LIT:OK>" <EOL> }


{ <EOL> val a = "<STR_LIT>" <EOL> if ( a !== a ) return "<STR_LIT:failU+00201>" <EOL> if ( a === a ) return "<STR_LIT:OK>" <EOL> return "<STR_LIT:failU+00202>" <EOL> }


@ Benchmark <EOL> fun singlePingPong ( )

= runBlocking { <EOL> runPingPongs ( <NUM_LIT:1> ) <EOL> }


@ Benchmark <EOL> fun coresCountPingPongs ( )

= runBlocking { <EOL> runPingPongs ( Runtime . getRuntime ( ) . availableProcessors ( ) ) <EOL> }


private suspend fun runPingPongs ( count : Int )

{ <EOL> val me = Channel < Letter > ( ) <EOL> repeat ( count ) { <EOL> val pong = pongActorCoroutine ( ) <EOL> val ping = pingActorCoroutine ( pong ) <EOL> ping . send ( Letter ( Start ( ) , me ) ) <EOL> } <EOL> repeat ( count ) { <EOL> me . receive ( ) <EOL> } <EOL> }


fun CoroutineScope . pingActorCoroutine ( pingChannel : SendChannel < PingPongActorBenchmark . Letter > , capacity : Int = <NUM_LIT:1> )

= <EOL> actor < PingPongActorBenchmark . Letter > ( capacity = capacity ) { <EOL> var initiator : SendChannel < PingPongActorBenchmark . Letter > ? = null <EOL> for ( letter in channel ) with ( letter ) { <EOL> when ( message ) { <EOL> is Start -> { <EOL> initiator = sender <EOL> pingChannel . send ( PingPongActorBenchmark . Letter ( Ball ( <NUM_LIT:0> ) , channel ) ) <EOL> } <EOL> is Ball -> { <EOL> pingChannel . send ( PingPongActorBenchmark . Letter ( Ball ( message . count + <NUM_LIT:1> ) , channel ) ) <EOL> } <EOL> is Stop -> { <EOL> initiator ! ! . send ( PingPongActorBenchmark . Letter ( Stop ( ) , channel ) ) <EOL> return@actor <EOL> } <EOL> else -> error ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }


fun CoroutineScope . pongActorCoroutine ( capacity : Int = <NUM_LIT:1> )

= <EOL> actor < PingPongActorBenchmark . Letter > ( capacity = capacity ) { <EOL> for ( letter in channel ) with ( letter ) { <EOL> when ( message ) { <EOL> is Ball -> { <EOL> if ( message . count >= N_MESSAGES ) { <EOL> sender . send ( PingPongActorBenchmark . Letter ( Stop ( ) , channel ) ) <EOL> return@actor <EOL> } else { <EOL> sender . send ( PingPongActorBenchmark . Letter ( Ball ( message . count + <NUM_LIT:1> ) , channel ) ) <EOL> } <EOL> } <EOL> else -> error ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }


{ <EOL> val ans1 = runCatching { <NUM_LIT:42> } <EOL> println ( ans1 ) <EOL> val ans2 = <NUM_LIT:42> . runCatching { this } <EOL> println ( ans2 ) <EOL> }


@ HtmlTagMarker <EOL> inline fun DATALIST . option ( classes : String ? = null , crossinline block : OPTION . ( ) -> Unit = { } ) : Unit

= OPTION ( attributesMapOf ( "<STR_LIT:class>" , classes ) , consumer ) . visit ( block )


@ HtmlTagMarker <EOL> fun DATALIST . option ( classes : String ? = null , content : String = "<STR_LIT>" ) : Unit

= OPTION ( attributesMapOf ( "<STR_LIT:class>" , classes ) , consumer ) . visit ( { + content } )


@ HtmlTagMarker <EOL> inline fun DETAILS . legend ( classes : String ? = null , crossinline block : LEGEND . ( ) -> Unit = { } ) : Unit

= LEGEND ( attributesMapOf ( "<STR_LIT:class>" , classes ) , consumer ) . visit ( block )


@ HtmlTagMarker <EOL> inline fun DL . dd ( classes : String ? = null , crossinline block : DD . ( ) -> Unit = { } ) : Unit

= DD ( attributesMapOf ( "<STR_LIT:class>" , classes ) , consumer ) . visit ( block )


@ HtmlTagMarker <EOL> inline fun DL . dt ( classes : String ? = null , crossinline block : DT . ( ) -> Unit = { } ) : Unit

= DT ( attributesMapOf ( "<STR_LIT:class>" , classes ) , consumer ) . visit ( block )


{ <EOL> super . setUp ( ) <EOL> configurationKind = ConfigurationKind . ALL <EOL> }


override fun updateConfiguration ( configuration : CompilerConfiguration )

{ <EOL> super . updateConfiguration ( configuration ) <EOL> if ( scriptDefinitions . isNotEmpty ( ) ) { <EOL> configureScriptDefinitions ( scriptDefinitions , configuration , this :: class . java . classLoader , MessageCollector . NONE , defaultJvmScriptingHostConfiguration ) <EOL> } <EOL> configuration . addJvmClasspathRoots ( additionalDependencies . orEmpty ( ) ) <EOL> loadScriptingPlugin ( configuration ) <EOL> }


override fun doMultiFileTest ( wholeFile : File , files : List < TestFile > )

{ <EOL> if ( files . size > <NUM_LIT:1> ) { <EOL> throw UnsupportedOperationException ( "<STR_LIT>" ) <EOL> } <EOL> if ( InTextDirectivesUtils . isIgnoredTarget ( backend , wholeFile ) ) { <EOL> println ( "<STR_LIT>" ) <EOL> return <EOL> } <EOL> val file = files . single ( ) <EOL> val content = file . content <EOL> scriptDefinitions = InTextDirectivesUtils . findListWithPrefixes ( content , "<STR_LIT>" ) <EOL> if ( scriptDefinitions . isNotEmpty ( ) ) { <EOL> additionalDependencies = <EOL> scriptCompilationClasspathFromContextOrStdlib ( "<STR_LIT>" , "<STR_LIT>" ) + <EOL> File ( TestScriptWithReceivers :: class . java . protectionDomain . codeSource . location . toURI ( ) . path ) + <EOL> with ( PathUtil . kotlinPathsForDistDirectory ) { <EOL> arrayOf ( KOTLIN_SCRIPTING_COMPILER_PLUGIN_JAR , KOTLIN_SCRIPTING_COMPILER_IMPL_JAR , KOTLIN_SCRIPTING_COMMON_JAR , KOTLIN_SCRIPTING_JVM_JAR ) . mapNotNull { File ( libPath , it ) . takeIf ( File :: exists ) } <EOL> } <EOL> } <EOL> createEnvironmentWithMockJdkAndIdeaAnnotations ( configurationKind , files , TestJdkKind . FULL_JDK ) <EOL> myFiles = CodegenTestFiles . create ( file . name , content , myEnvironment . project ) <EOL> try { <EOL> val scriptClass = generateClass ( myFiles . psiFile . script ! ! . fqName . asString ( ) ) <EOL> val receivers = InTextDirectivesUtils . findListWithPrefixes ( content , "<STR_LIT>" ) <EOL> val environmentVars = extractAllKeyValPairs ( content , "<STR_LIT>" ) <EOL> val scriptParams = InTextDirectivesUtils . findListWithPrefixes ( content , "<STR_LIT>" ) <EOL> val scriptInstance = runScript ( scriptClass , receivers , environmentVars , scriptParams ) <EOL> val expectedFields = extractAllKeyValPairs ( content , "<STR_LIT>" ) <EOL> checkExpectedFields ( expectedFields , scriptClass , scriptInstance ) <EOL> } catch ( e : Throwable ) { <EOL> printReport ( wholeFile ) <EOL> throw e <EOL> } <EOL> }


private fun extractAllKeyValPairs ( content : String , directive : String ) : Map < String , String >

= <EOL> InTextDirectivesUtils . findListWithPrefixes ( content , directive ) . associate { line -> <EOL> line . substringBefore ( '<CHAR_LIT>' ) to line . substringAfter ( '<CHAR_LIT>' ) <EOL> }


private fun runScript ( scriptClass : Class < * > , receivers : List < Any ? > , environmentVars : Map < String , Any ? > , scriptParams : List < Any > ) : Any ?

{ <EOL> val ctorParams = arrayListOf < Any ? > ( ) <EOL> ctorParams . addAll ( scriptParams ) <EOL> ctorParams . addAll ( receivers ) <EOL> ctorParams . addAll ( environmentVars . values ) <EOL> val constructor = scriptClass . constructors [ <NUM_LIT:0> ] <EOL> return constructor . newInstance ( * ctorParams . toTypedArray ( ) ) <EOL> }


private fun checkExpectedFields ( expectedFields : Map < String , Any ? > , scriptClass : Class < * > , scriptInstance : Any ? )

{ <EOL> Assert . assertFalse ( "<STR_LIT>" , expectedFields . isEmpty ( ) ) <EOL> for ( ( fieldName , expectedValue ) in expectedFields ) { <EOL> if ( expectedValue == "<STR_LIT>" ) { <EOL> try { <EOL> scriptClass . getDeclaredField ( fieldName ) <EOL> Assert . fail ( "<STR_LIT>" ) <EOL> } catch ( e : NoSuchFieldException ) { <EOL> continue <EOL> } <EOL> } <EOL> val field = scriptClass . getDeclaredField ( fieldName ) <EOL> field . isAccessible = true <EOL> val resultString = field . get ( scriptInstance ) ? . toString ( ) ? : "<STR_LIT:null>" <EOL> Assert . assertEquals ( "<STR_LIT>" , expectedValue , resultString ) <EOL> } <EOL> }


{ <EOL> val ( train , test ) = fashionMnist ( ) <EOL> val jsonConfigFile = getJSONConfigFile ( ) <EOL> val model = Sequential . loadModelConfiguration ( jsonConfigFile ) <EOL> model . use { <EOL> it . compile ( optimizer = Adam ( ) , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> it . logSummary ( ) <EOL> val hdfFile = getWeightsFile ( ) <EOL> it . loadWeights ( hdfFile ) <EOL> val accuracyBefore = it . evaluate ( dataset = test , batchSize = <NUM_LIT:100> ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> it . fit ( dataset = train , validationRate = <NUM_LIT> , epochs = <NUM_LIT:1> , trainBatchSize = <NUM_LIT> , validationBatchSize = <NUM_LIT:100> ) <EOL> val accuracyAfterTraining = it . evaluate ( dataset = test , batchSize = <NUM_LIT:100> ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }

/**
 * This example demonstrates the transfer learning concept:
 * - Weights are loaded from .h5 file, configuration is loaded from .json file.
 * - All model weights are not frozen, and can be changed during the training.
 * - No new layers are added.
 *
 * NOTE: Model and weights are resources in `examples` module.
 */


= additionalTraining ( )


protected abstract fun toResult ( key : K , value : V ) : R


override fun serialize ( encoder : Encoder , value : R )

{ <EOL> val structuredEncoder = encoder . beginStructure ( descriptor ) <EOL> structuredEncoder . encodeSerializableElement ( descriptor , <NUM_LIT:0> , keySerializer , value . key ) <EOL> structuredEncoder . encodeSerializableElement ( descriptor , <NUM_LIT:1> , valueSerializer , value . value ) <EOL> structuredEncoder . endStructure ( descriptor ) <EOL> }


override fun deserialize ( decoder : Decoder ) : R

= decoder . decodeStructure ( descriptor ) { <EOL> if ( decodeSequentially ( ) ) { <EOL> val key = decodeSerializableElement ( descriptor , <NUM_LIT:0> , keySerializer ) <EOL> val value = decodeSerializableElement ( descriptor , <NUM_LIT:1> , valueSerializer ) <EOL> return@decodeStructure toResult ( key , value ) <EOL> } <EOL> var key : Any ? = NULL <EOL> var value : Any ? = NULL <EOL> mainLoop @ while ( true ) { <EOL> when ( val idx = decodeElementIndex ( descriptor ) ) { <EOL> CompositeDecoder . DECODE_DONE -> { <EOL> break@mainLoop <EOL> } <EOL> <NUM_LIT:0> -> { <EOL> key = decodeSerializableElement ( descriptor , <NUM_LIT:0> , keySerializer ) <EOL> } <EOL> <NUM_LIT:1> -> { <EOL> value = decodeSerializableElement ( descriptor , <NUM_LIT:1> , valueSerializer ) <EOL> } <EOL> else -> throw SerializationException ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> if ( key === NULL ) throw SerializationException ( "<STR_LIT>" ) <EOL> if ( value === NULL ) throw SerializationException ( "<STR_LIT>" ) <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> return@decodeStructure toResult ( key as K , value as V ) <EOL> }


override fun toResult ( key : K , value : V ) : Map . Entry < K , V >

= MapEntry ( key , value )


override fun toResult ( key : K , value : V ) : Pair < K , V >

= key to value


override fun serialize ( encoder : Encoder , value : Triple < A , B , C > )

{ <EOL> val structuredEncoder = encoder . beginStructure ( descriptor ) <EOL> structuredEncoder . encodeSerializableElement ( descriptor , <NUM_LIT:0> , aSerializer , value . first ) <EOL> structuredEncoder . encodeSerializableElement ( descriptor , <NUM_LIT:1> , bSerializer , value . second ) <EOL> structuredEncoder . encodeSerializableElement ( descriptor , <NUM_LIT:2> , cSerializer , value . third ) <EOL> structuredEncoder . endStructure ( descriptor ) <EOL> }


override fun deserialize ( decoder : Decoder ) : Triple < A , B , C >

{ <EOL> val composite = decoder . beginStructure ( descriptor ) <EOL> if ( composite . decodeSequentially ( ) ) { <EOL> return decodeSequentially ( composite ) <EOL> } <EOL> return decodeStructure ( composite ) <EOL> }


private fun decodeSequentially ( composite : CompositeDecoder ) : Triple < A , B , C >

{ <EOL> val a = composite . decodeSerializableElement ( descriptor , <NUM_LIT:0> , aSerializer ) <EOL> val b = composite . decodeSerializableElement ( descriptor , <NUM_LIT:1> , bSerializer ) <EOL> val c = composite . decodeSerializableElement ( descriptor , <NUM_LIT:2> , cSerializer ) <EOL> composite . endStructure ( descriptor ) <EOL> return Triple ( a , b , c ) <EOL> }


private fun decodeStructure ( composite : CompositeDecoder ) : Triple < A , B , C >

{ <EOL> var a : Any ? = NULL <EOL> var b : Any ? = NULL <EOL> var c : Any ? = NULL <EOL> mainLoop @ while ( true ) { <EOL> when ( val index = composite . decodeElementIndex ( descriptor ) ) { <EOL> CompositeDecoder . DECODE_DONE -> { <EOL> break@mainLoop <EOL> } <EOL> <NUM_LIT:0> -> { <EOL> a = composite . decodeSerializableElement ( descriptor , <NUM_LIT:0> , aSerializer ) <EOL> } <EOL> <NUM_LIT:1> -> { <EOL> b = composite . decodeSerializableElement ( descriptor , <NUM_LIT:1> , bSerializer ) <EOL> } <EOL> <NUM_LIT:2> -> { <EOL> c = composite . decodeSerializableElement ( descriptor , <NUM_LIT:2> , cSerializer ) <EOL> } <EOL> else -> throw SerializationException ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> composite . endStructure ( descriptor ) <EOL> if ( a === NULL ) throw SerializationException ( "<STR_LIT>" ) <EOL> if ( b === NULL ) throw SerializationException ( "<STR_LIT>" ) <EOL> if ( c === NULL ) throw SerializationException ( "<STR_LIT>" ) <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> return Triple ( a as A , b as B , c as C ) <EOL> }


fun emit ( event : String , vararg args : Any ) : Boolean


fun emit ( event : Any , vararg args : Any ) : Boolean


override fun emit ( event : String , vararg args : Any ) : Boolean


override fun emit ( event : Any , vararg args : Any ) : Boolean


fun compute ( ) : Number


override fun compute ( ) : Number


= "<STR_LIT:OK>"


= Test . fn ( )


@ DisplayName ( "<STR_LIT>" ) <EOL> @ GradleTest <EOL> fun shouldNotUseExternalDependencies ( gradleVersion : GradleVersion )

{ <EOL> buildProjectWithDependencies ( gradleVersion ) { externalDependenciesText -> <EOL> assertEquals ( """<STR_LIT>""" . trimMargin ( ) , externalDependenciesText ) <EOL> } <EOL> }


@ DisplayName ( "<STR_LIT>" ) <EOL> @ GradleTest <EOL> fun shouldUseOldKtorAndCoroutinesExternalDependencies ( gradleVersion : GradleVersion )

{ <EOL> buildProjectWithDependencies ( gradleVersion , "<STR_LIT>" , "<STR_LIT>" ) { externalDependenciesText -> <EOL> assertNotNull ( externalDependenciesText ) <EOL> assertEquals ( """<STR_LIT>""" . trimIndent ( ) , externalDependenciesText ) <EOL> } <EOL> }


@ DisplayName ( "<STR_LIT>" ) <EOL> @ GradleTest <EOL> fun shouldUseKtorAndCoroutinesExternalDependencies ( gradleVersion : GradleVersion )

{ <EOL> buildProjectWithDependencies ( gradleVersion , "<STR_LIT>" , "<STR_LIT>" ) { externalDependenciesText -> <EOL> assertNotNull ( externalDependenciesText ) <EOL> assertEquals ( """<STR_LIT>""" . trimMargin ( ) , externalDependenciesText ) <EOL> } <EOL> }


private fun buildProjectWithDependencies ( gradleVersion : GradleVersion , vararg dependencies : String , externalDependenciesTextConsumer : ( externalDependenciesText : String ? ) -> Unit , )

{ <EOL> nativeProject ( "<STR_LIT>" , gradleVersion ) { <EOL> buildGradleKts . appendText ( """<STR_LIT>""" . trimMargin ( ) ) <EOL> build ( "<STR_LIT>" ) { <EOL> assertTasksExecuted ( "<STR_LIT>" ) <EOL> val externalDependenciesFile = findParameterInOutput ( "<STR_LIT>" , output ) ? . let ( :: File ) <EOL> val externalDependenciesText = if ( externalDependenciesFile ? . exists ( ) == true ) { <EOL> externalDependenciesFile . readText ( ) <EOL> . lineSequence ( ) <EOL> . map { line -> <EOL> if ( line . firstOrNull ( ) ? . isWhitespace ( ) == true ) "<STR_LIT>" else line <EOL> } <EOL> . joinToString ( "<STR_LIT:\n>" ) <EOL> } else null <EOL> externalDependenciesTextConsumer ( externalDependenciesText ) <EOL> } <EOL> } <EOL> }


override fun lower ( source : SourceSetModel ) : SourceSetModel

{ <EOL> return source . copy ( sources = source . sources . map { <EOL> if ( it . root . shortName == TSLIBROOT ) { <EOL> it . copy ( root = lower ( it . root ) ) <EOL> } else { <EOL> it <EOL> } <EOL> } ) <EOL> }


abstract override fun createPointer ( ) : KtSymbolPointer < KtPropertyAccessorSymbol >


abstract override fun createPointer ( ) : KtSymbolPointer < KtPropertyGetterSymbol >


abstract override fun createPointer ( ) : KtSymbolPointer < KtPropertySetterSymbol >


{ <EOL> sizeLong = size . toLong ( ) <EOL> intRange = <NUM_LIT:1> .. size <EOL> longRange = <NUM_LIT:1L> .. sizeLong <EOL> array = IntArray ( size ) <EOL> }


@ Benchmark fun arrayLoop ( bh : Blackhole )

{ <EOL> for ( i in array ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun arrayIndicesLoop ( bh : Blackhole )

{ <EOL> for ( i in array . indices ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun intRangeLiteralLoop ( bh : Blackhole )

{ <EOL> for ( i in <NUM_LIT:1> .. size ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun intRangeExpressionLoop ( bh : Blackhole )

{ <EOL> for ( i in intRange ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun longRangeLiteralLoop ( bh : Blackhole )

{ <EOL> for ( i in <NUM_LIT:1L> .. sizeLong ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun longRangeExpressionLoop ( bh : Blackhole )

{ <EOL> for ( i in longRange ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun intDownToLoop ( bh : Blackhole )

{ <EOL> for ( i in size downTo <NUM_LIT:1> ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun longDownToLoop ( bh : Blackhole )

{ <EOL> for ( i in sizeLong downTo <NUM_LIT:1L> ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun intUntilLoop ( bh : Blackhole )

{ <EOL> for ( i in <NUM_LIT:0> until size ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ Benchmark fun longUntilLoop ( bh : Blackhole )

{ <EOL> for ( i in <NUM_LIT:0L> until sizeLong ) { <EOL> bh . consume ( i ) <EOL> } <EOL> }


@ ObjCName ( "<STR_LIT>" ) <EOL> fun close ( )


override fun close ( )


{ <EOL> }


suspend fun emit ( value : T )


suspend fun collect ( collector : FlowCollector < T > )


public inline fun < T > flow ( crossinline block : suspend FlowCollector < T > . ( ) -> Unit )

= object : Flow < T > { <EOL> override suspend fun collect ( collector : FlowCollector < T > ) = collector . block ( ) <EOL> }


suspend inline fun < T > Flow < T > . collect ( crossinline action : suspend ( T ) -> Unit ) : Unit

= <EOL> collect ( object : FlowCollector < T > { <EOL> override suspend fun emit ( value : T ) = action ( value ) <EOL> } )


public inline fun < T , R > Flow < T > . transform ( crossinline transformer : suspend FlowCollector < R > . ( value : T ) -> Unit ) : Flow < R >

{ <EOL> return flow { <EOL> return@flow collect { value -> <EOL> return@collect transformer ( value ) <EOL> } <EOL> } <EOL> }


public inline fun < T , R > Flow < T > . map ( crossinline transformer : suspend ( value : T ) -> R ) : Flow < R >

= transform { value -> return@transform emit ( transformer ( value ) ) }


{ <EOL> flow < Int > { <EOL> emit ( <NUM_LIT:1> ) <EOL> } . map { it + <NUM_LIT:1> } <EOL> . collect { <EOL> } <EOL> }


actual fun < T > CoroutineScope . asyncWithDealy ( delay : Long , block : suspend ( ) -> T ) : Deferred < T >

{ <EOL> TODO ( "<STR_LIT:NotU+0020yetU+0020implemented>" ) <EOL> }

/**
 * JS actual implementation for `asyncWithDelay`
 */


public fun extractImages ( archivePath : String ) : Array < FloatArray >

{ <EOL> val archiveStream = DataInputStream ( GZIPInputStream ( FileInputStream ( archivePath ) ) ) <EOL> val magic = archiveStream . readInt ( ) <EOL> require ( IMAGE_ARCHIVE_MAGIC == magic ) { "<STR_LIT>" } <EOL> val imageCount = archiveStream . readInt ( ) <EOL> val imageRows = archiveStream . readInt ( ) <EOL> val imageCols = archiveStream . readInt ( ) <EOL> println ( String . format ( "<STR_LIT>" , imageCount , imageRows , imageCols , archivePath ) ) <EOL> val imageBuffer = ByteArray ( imageRows * imageCols ) <EOL> val images = Array ( imageCount ) { <EOL> archiveStream . readFully ( imageBuffer ) <EOL> toNormalizedVector ( imageBuffer ) <EOL> } <EOL> return images <EOL> }

/**
 * Extracts (Fashion) Mnist images from [archivePath].
 */


public fun extractLabels ( archivePath : String ) : FloatArray

{ <EOL> val archiveStream = DataInputStream ( GZIPInputStream ( FileInputStream ( archivePath ) ) ) <EOL> val magic = archiveStream . readInt ( ) <EOL> require ( LABEL_ARCHIVE_MAGIC == magic ) { "<STR_LIT>" } <EOL> val labelCount = archiveStream . readInt ( ) <EOL> println ( String . format ( "<STR_LIT>" , labelCount , archivePath ) ) <EOL> val labelBuffer = ByteArray ( labelCount ) <EOL> archiveStream . readFully ( labelBuffer ) <EOL> val floats = FloatArray ( labelCount ) <EOL> for ( i in <NUM_LIT:0> until labelCount ) { <EOL> floats [ i ] = <EOL> OnHeapDataset . convertByteToFloat ( labelBuffer [ i ] ) <EOL> } <EOL> return floats <EOL> }

/**
 * Extracts (Fashion) Mnist labels from [archivePath] with number of classes [numClasses].
 */


fun ResultValue . Error . renderError ( stream : PrintStream )

{ <EOL> var trace = error . stackTrace <EOL> val wrappingTrace = wrappingException ? . stackTrace <EOL> if ( wrappingException == null || trace . size < wrappingTrace ! ! . size ) { <EOL> error . printStackTrace ( stream ) <EOL> } else { <EOL> fun PrintStream . printTrace ( stackTrace : Array < StackTraceElement > , dropLastFrames : Int ) { <EOL> for ( element in stackTrace . dropLast ( dropLastFrames ) ) { <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> stream . println ( error ) <EOL> stream . printTrace ( trace , wrappingTrace . size ) <EOL> var current : Throwable ? = error . cause <EOL> var wrapping = error <EOL> val cyclesDetection = hashSetOf ( wrapping ) <EOL> while ( current != null && cyclesDetection . add ( current ) ) { <EOL> trace = current . stackTrace <EOL> val sameFramesCount = <EOL> trace . asList ( ) . asReversed ( ) . asSequence ( ) <EOL> . zip ( wrapping . stackTrace . asList ( ) . asReversed ( ) . asSequence ( ) ) <EOL> . takeWhile { it . first == it . second } <EOL> . count ( ) <EOL> stream . println ( "<STR_LIT>" ) <EOL> stream . printTrace ( trace , sameFramesCount ) <EOL> wrapping = current <EOL> current = current . cause <EOL> } <EOL> } <EOL> }


fun ResultValue . Error . renderError ( ) : String

= <EOL> ByteArrayOutputStream ( ) . use { os -> <EOL> val ps = PrintStream ( os ) <EOL> renderError ( ps ) <EOL> ps . flush ( ) <EOL> os . toString ( ) <EOL> }


{ <EOL> val x : String <EOL> run { <EOL> x = "<STR_LIT:OK>" <EOL> val y = x <EOL> } <EOL> return x <EOL> }


{ <EOL> val ( cifarImagesArchive , cifarLabelsArchive ) = cifar10Paths ( ) <EOL> val preprocessing = pipeline < BufferedImage > ( ) <EOL> . convert { colorMode = ColorMode . BGR } <EOL> . toFloatArray { } <EOL> . rescale { <EOL> scalingCoefficient = <NUM_LIT> <EOL> } <EOL> val y = extractCifar10LabelsAnsSort ( cifarLabelsArchive ) <EOL> val dataset = OnFlyImageDataset . create ( File ( cifarImagesArchive ) , y , preprocessing ) <EOL> val ( train , test ) = dataset . split ( TRAIN_TEST_SPLIT_RATIO ) <EOL> vgg11 . use { <EOL> it . compile ( optimizer = Adam ( ) , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> it . logSummary ( ) <EOL> val start = System . currentTimeMillis ( ) <EOL> it . fit ( dataset = train , epochs = EPOCHS , batchSize = TRAINING_BATCH_SIZE ) <EOL> println ( "<STR_LIT>" ) <EOL> it . save ( File ( PATH_TO_MODEL ) , writingMode = WritingMode . OVERRIDE ) <EOL> val accuracy = it . evaluate ( dataset = test , batchSize = TEST_BATCH_SIZE ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> val inferenceModel = TensorFlowInferenceModel . load ( File ( PATH_TO_MODEL ) ) <EOL> inferenceModel . use { <EOL> var accuracy = <NUM_LIT:0.0> <EOL> val amountOfTestSet = test . xSize ( ) <EOL> for ( imageId in <NUM_LIT:0> until amountOfTestSet ) { <EOL> val prediction = it . predict ( test . getX ( imageId ) ) <EOL> if ( prediction == test . getY ( imageId ) . toInt ( ) ) <EOL> accuracy += ( <NUM_LIT:1.0> / amountOfTestSet ) <EOL> } <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }


= vgg11OnCifar10ExportImport ( )


override fun ExtensionRegistrarContext . configurePlugin ( )

{ <EOL> if ( compilerConfiguration . getBoolean ( ScriptingConfigurationKeys . DISABLE_SCRIPTING_PLUGIN_OPTION ) ) return <EOL> configureScriptDefinitions ( compilerConfiguration , hostConfiguration , this :: class . java . classLoader ) <EOL> val definitionSources = compilerConfiguration . getList ( ScriptingConfigurationKeys . SCRIPT_DEFINITIONS_SOURCES ) <EOL> val definitions = compilerConfiguration . getList ( ScriptingConfigurationKeys . SCRIPT_DEFINITIONS ) <EOL> if ( definitionSources . isNotEmpty ( ) || definitions . isNotEmpty ( ) ) { <EOL> + FirScriptDefinitionProviderService . getFactory ( definitions , definitionSources ) <EOL> } <EOL> + FirScriptConfiguratorExtensionImpl . getFactory ( hostConfiguration ) <EOL> + FirScriptResolutionConfigurationExtensionImpl . getFactory ( hostConfiguration ) <EOL> + Fir2IrScriptConfiguratorExtensionImpl . getFactory ( hostConfiguration ) <EOL> }


@ BeforeEach <EOL> fun assumeCachesAreEnabled ( )

{ <EOL> Assumptions . assumeFalse ( testRunSettings . get < CacheMode > ( ) == CacheMode . WithoutCache ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT:simple>" ) <EOL> fun testSimple ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libKtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libKtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val modified = libKtCacheDir . lastModified ( ) <EOL> compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( libKtCacheDir . exists ( ) ) <EOL> assertEquals ( modified , libKtCacheDir . lastModified ( ) ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testModifiedFile ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libKtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libKtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val modified = libKtCacheDir . lastModified ( ) <EOL> val lib1 = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( libKtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified , libKtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testAddedFile ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libFile1KtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val modified = libFile1KtCacheDir . lastModified ( ) <EOL> val lib1 = compileLibrary ( "<STR_LIT:lib>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> assertEquals ( modified , libFile1KtCacheDir . lastModified ( ) ) <EOL> val libFile2KtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libFile2KtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testRemovedFile ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libFile1KtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> val libFile2KtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libFile2KtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val modified = libFile1KtCacheDir . lastModified ( ) <EOL> val lib1 = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> assertEquals ( modified , libFile1KtCacheDir . lastModified ( ) ) <EOL> assertFalse ( libFile2KtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testRenamedFile ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libKtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT:test>" ) <EOL> assertTrue ( libKtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val lib1 = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertFalse ( libKtCacheDir . exists ( ) ) <EOL> val changedLibKtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT:test>" ) <EOL> assertTrue ( changedLibKtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testRenamedPackage ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libKtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT:test>" ) <EOL> assertTrue ( libKtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val lib1 = compileLibrary ( "<STR_LIT:lib>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertFalse ( libKtCacheDir . exists ( ) ) <EOL> val changedLibKtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( changedLibKtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testChangedFileIndex ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libBKtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libBKtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val modified = libBKtCacheDir . lastModified ( ) <EOL> val lib1 = compileLibrary ( "<STR_LIT:lib>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( libBKtCacheDir . exists ( ) ) <EOL> assertEquals ( modified , libBKtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testChangedExternalDependencyVersion ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val externalLib = compileLibrary ( "<STR_LIT>" ) { <EOL> libraryVersion = "<STR_LIT:1.0>" <EOL> outputDir = "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val userLib = compileLibrary ( "<STR_LIT>" , externalLib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , externalLib , userLib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libFile1KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val modified = libFile1KtCacheDir . lastModified ( ) <EOL> val externalLib1 = compileLibrary ( "<STR_LIT>" ) { <EOL> libraryVersion = "<STR_LIT:1.1>" <EOL> outputDir = "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val userLib1 = compileLibrary ( "<STR_LIT>" , externalLib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , externalLib1 , userLib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified , libFile1KtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testChangedExternalDependency ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val externalLib = compileLibrary ( "<STR_LIT>" ) { <EOL> outputDir = "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val userLib = compileLibrary ( "<STR_LIT>" , externalLib ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , externalLib , userLib ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val libFile1KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> val libFile2KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> assertTrue ( libFile2KtCacheDir . exists ( ) ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val modified1 = libFile1KtCacheDir . lastModified ( ) <EOL> val modified2 = libFile2KtCacheDir . lastModified ( ) <EOL> val externalLib1 = compileLibrary ( "<STR_LIT>" ) { <EOL> outputDir = "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , externalLib1 , userLib ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> assertTrue ( libFile1KtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified1 , libFile1KtCacheDir . lastModified ( ) ) <EOL> assertTrue ( libFile2KtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified2 , libFile2KtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testFileDependencies1 ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib = compileLibrary ( "<STR_LIT:lib>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val file1KtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT:test>" ) <EOL> val file2KtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT:test>" ) <EOL> val file3KtCacheDir = getLibraryFileCache ( "<STR_LIT:lib>" , "<STR_LIT>" , "<STR_LIT:test>" ) <EOL> assertTrue ( file1KtCacheDir . exists ( ) ) <EOL> assertTrue ( file2KtCacheDir . exists ( ) ) <EOL> assertTrue ( file3KtCacheDir . exists ( ) ) <EOL> val modified1 = file1KtCacheDir . lastModified ( ) <EOL> val modified2 = file2KtCacheDir . lastModified ( ) <EOL> val modified3 = file3KtCacheDir . lastModified ( ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val lib1 = compileLibrary ( "<STR_LIT:lib>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main1 . executableFile . exists ( ) ) <EOL> assertTrue ( file1KtCacheDir . exists ( ) ) <EOL> assertTrue ( file2KtCacheDir . exists ( ) ) <EOL> assertTrue ( file3KtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified1 , file1KtCacheDir . lastModified ( ) ) <EOL> assertEquals ( modified2 , file2KtCacheDir . lastModified ( ) ) <EOL> assertNotEquals ( modified3 , file3KtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun testFileDependencies2 ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib1 = compileLibrary ( "<STR_LIT>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val lib2 = compileLibrary ( "<STR_LIT>" , lib1 ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib1 , lib2 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val lib1KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> val lib2File1KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> val lib2File2KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( lib1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2File1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2File2KtCacheDir . exists ( ) ) <EOL> val modified11 = lib1KtCacheDir . lastModified ( ) <EOL> val modified21 = lib2File1KtCacheDir . lastModified ( ) <EOL> val modified22 = lib2File2KtCacheDir . lastModified ( ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val lib11 = compileLibrary ( "<STR_LIT>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val lib21 = compileLibrary ( "<STR_LIT>" , lib11 ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib11 , lib21 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main1 . executableFile . exists ( ) ) <EOL> assertTrue ( lib1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2File1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2File2KtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified11 , lib1KtCacheDir . lastModified ( ) ) <EOL> assertEquals ( modified21 , lib2File1KtCacheDir . lastModified ( ) ) <EOL> assertNotEquals ( modified22 , lib2File2KtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun addMethodToOpenClass1 ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib1 = compileLibrary ( "<STR_LIT>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val lib2 = compileLibrary ( "<STR_LIT>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib1 , lib2 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val lib1KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> val lib2KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( lib1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2KtCacheDir . exists ( ) ) <EOL> val modified1 = lib1KtCacheDir . lastModified ( ) <EOL> val modified2 = lib2KtCacheDir . lastModified ( ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val lib11 = compileLibrary ( "<STR_LIT>" ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val lib21 = compileLibrary ( "<STR_LIT>" , lib11 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib11 , lib21 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main1 . executableFile . exists ( ) ) <EOL> assertTrue ( lib1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2KtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified1 , lib1KtCacheDir . lastModified ( ) ) <EOL> assertEquals ( modified2 , lib2KtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun addMethodToOpenClass2 ( )

= withRootDir ( File ( "<STR_LIT>" ) ) { <EOL> val lib1 = compileLibrary ( "<STR_LIT>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val lib2 = compileLibrary ( "<STR_LIT>" , lib1 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main = compileToExecutable ( "<STR_LIT:main>" , lib1 , lib2 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main . executableFile . exists ( ) ) <EOL> val lib1File1KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> val lib1File2KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> val lib2KtCacheDir = getLibraryFileCache ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> assertTrue ( lib1File1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib1File2KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2KtCacheDir . exists ( ) ) <EOL> val modified11 = lib1File1KtCacheDir . lastModified ( ) <EOL> val modified12 = lib1File2KtCacheDir . lastModified ( ) <EOL> val modified2 = lib2KtCacheDir . lastModified ( ) <EOL> runExecutableAndVerify ( main . testCase , main . testExecutable ) <EOL> val lib11 = compileLibrary ( "<STR_LIT>" ) { <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> "<STR_LIT>" copyTo "<STR_LIT>" <EOL> } <EOL> val lib21 = compileLibrary ( "<STR_LIT>" , lib11 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> val main1 = compileToExecutable ( "<STR_LIT:main>" , lib11 , lib21 ) { "<STR_LIT>" copyTo "<STR_LIT>" } <EOL> assertTrue ( main1 . executableFile . exists ( ) ) <EOL> assertTrue ( lib1File1KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib1File2KtCacheDir . exists ( ) ) <EOL> assertTrue ( lib2KtCacheDir . exists ( ) ) <EOL> assertNotEquals ( modified11 , lib1File1KtCacheDir . lastModified ( ) ) <EOL> assertNotEquals ( modified12 , lib1File2KtCacheDir . lastModified ( ) ) <EOL> assertEquals ( modified2 , lib2KtCacheDir . lastModified ( ) ) <EOL> runExecutableAndVerify ( main1 . testCase , main1 . testExecutable ) <EOL> }


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun addMethodToInterface1 ( )


@ Test <EOL> @ TestMetadata ( "<STR_LIT>" ) <EOL> fun addMethodToInterface2 ( )


private inline fun withRootDir ( rootDir : File , block : RootDirHolder . ( ) -> Unit )

= RootDirHolder ( rootDir ) . block ( )


inline fun compileLibrary ( targetSrc : String , vararg dependencies : TestCompilationArtifact . KLIB , block : LibraryBuilder . ( ) -> Unit )

= with ( LibraryBuilder ( this @ IncrementalCompilationTest , rootDir , targetSrc , dependencies . asList ( ) ) ) { <EOL> block ( ) <EOL> build ( ) <EOL> }


inline fun compileToExecutable ( targetSrc : String , vararg dependencies : TestCompilationArtifact . KLIB , block : ExecutableBuilder . ( ) -> Unit )

= with ( ExecutableBuilder ( this @ IncrementalCompilationTest , rootDir , targetSrc , false , dependencies . asList ( ) ) ) { <EOL> externalLibsDir . mkdirs ( ) <EOL> icCacheDir . mkdirs ( ) <EOL> autoCacheDir . mkdirs ( ) <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> block ( ) <EOL> build ( ) <EOL> }


private fun getLibraryFileCache ( libName : String , libFileRelativePath : String , fqName : String ) : File

{ <EOL> val libCacheDir = icCacheDir . resolve ( cacheFlavor ) . resolve ( "<STR_LIT>" ) <EOL> val fileId = cacheFileId ( fqName , buildDir . resolve ( libFileRelativePath ) . absolutePath ) <EOL> return libCacheDir . resolve ( fileId ) <EOL> }


private fun cacheFileId ( fqName : String , filePath : String )

= <EOL> "<STR_LIT>"


= <NUM_LIT:1>


{ <EOL> foo ( :: bar ) <EOL> }


override fun processAfterAllModules ( someAssertionWasFailed : Boolean )


override fun processModule ( module : TestModule , info : BinaryArtifacts . Js )

{ <EOL> val globalDirectives = testServices . moduleStructure . allDirectives <EOL> if ( JsEnvironmentConfigurationDirectives . SKIP_REGULAR_MODE in globalDirectives ) return <EOL> val referenceDtsFile = module . files . first ( ) . originalFile . withReplacedExtensionOrNull ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ? : error ( "<STR_LIT>" ) <EOL> val generatedDtsFile = info . outputFile . withReplacedExtensionOrNull ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ? : info . outputFile . withReplacedExtensionOrNull ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ? : error ( "<STR_LIT>" ) <EOL> val generatedDts = generatedDtsFile . readText ( ) <EOL> if ( JsEnvironmentConfigurationDirectives . UPDATE_REFERENCE_DTS_FILES in globalDirectives ) <EOL> referenceDtsFile . writeText ( generatedDts ) <EOL> else <EOL> KotlinTestUtils . assertEqualsToFile ( referenceDtsFile , generatedDts ) <EOL> }


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> private external fun getSize ( ) : Int


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override fun get ( index : Int ) : Any ?


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override fun add ( index : Int , element : Any ? ) : Unit


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override fun removeAt ( index : Int ) : Any ?


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override fun set ( index : Int , element : Any ? ) : Any ?


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override fun contains ( element : Any ? ) : Boolean


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override fun getElement ( element : Any ? ) : Any ?


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override fun iterator ( ) : Iterator < Any ? >


override fun equals ( other : Any ? ) : Boolean

{ <EOL> if ( this === other ) return true <EOL> if ( other !is Map < * , * > ) return false <EOL> if ( this . size != other . size ) return false <EOL> return other . entries . all { this . containsEntry ( it . key , it . value ) } <EOL> }


{ <EOL> var result = <NUM_LIT:0> <EOL> keyIterator ( ) . forEach { key -> <EOL> result += key . hashCode ( ) xor this . getOrThrowConcurrentModification ( key ) . hashCode ( ) <EOL> } <EOL> return result <EOL> }


= entries . joinToString ( "<STR_LIT:U+002CU+0020>" , "<STR_LIT>" , "<STR_LIT:}>" ) { toString ( it . key ) + "<STR_LIT>" + toString ( it . value ) }


private fun toString ( o : Any ? ) : String

= if ( o === this ) "<STR_LIT>" else o . toString ( )


= ( size == <NUM_LIT:0> )


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> override external fun containsKey ( key : Any ? ) : Boolean


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> override external fun containsValue ( value : Any ? ) : Boolean


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> external override operator fun get ( key : Any ? ) : Any ?


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> private external fun getOrThrowConcurrentModification ( key : Any ? ) : Any ?


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> private external fun containsEntry ( key : Any ? , value : Any ? ) : Boolean


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> private external fun keyIterator ( ) : Iterator < Any ? >


override fun iterator ( ) : Iterator < Any ? >

= this@NSDictionaryAsKMap . keyIterator ( )


override fun contains ( element : Any ? ) : Boolean

= this@NSDictionaryAsKMap . containsKey ( element )


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> private external fun valueIterator ( ) : Iterator < Any ? >


= this@NSDictionaryAsKMap . valueIterator ( )


= this@NSDictionaryAsKMap . containsValue ( element )


override fun iterator ( ) : Iterator < Map . Entry < Any ? , Any ? > >

= this@NSDictionaryAsKMap . EntryIterator ( )


override fun contains ( element : Map . Entry < Any ? , Any ? > ) : Boolean

{ <EOL> return this@NSDictionaryAsKMap . containsEntry ( element . key , element . value ) <EOL> }


= <EOL> other is Map . Entry < * , * > && <EOL> other . key == key && <EOL> other . value == value


= key . hashCode ( ) xor value . hashCode ( )


= "<STR_LIT>"


= keyIterator . hasNext ( )


override fun next ( ) : Map . Entry < Any ? , Any ? >

{ <EOL> val nextKey = keyIterator . next ( ) <EOL> val nextValue = this@NSDictionaryAsKMap . getOrThrowConcurrentModification ( nextKey ) <EOL> return Entry ( nextKey , nextValue ) <EOL> }


@ GCUnsafeCall ( "<STR_LIT>" ) <EOL> override external fun computeNext ( )


@ ExportForCppRuntime <EOL> private fun Kotlin_NSEnumeratorAsKIterator_done ( )

= this . done ( )


@ ExportForCppRuntime <EOL> private fun Kotlin_NSEnumeratorAsKIterator_setNext ( value : Any ? )

= this . setNext ( value )


@ ExportForCppRuntime private fun Kotlin_Collection_getSize ( collection : Collection < * > ) : Int

= collection . size


@ ExportForCppRuntime private fun Kotlin_List_get ( list : List < * > , index : Int ) : Any ?

= list . get ( index )


@ ExportForCppRuntime private fun Kotlin_MutableList_addObjectAtIndex ( list : MutableList < Any ? > , index : Int , obj : Any ? )

{ <EOL> list . add ( index , obj ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_MutableList_removeObjectAtIndex ( list : MutableList < Any ? > , index : Int )

{ <EOL> list . removeAt ( index ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_MutableCollection_addObject ( list : MutableCollection < Any ? > , obj : Any ? )

{ <EOL> list . add ( obj ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_MutableList_removeLastObject ( list : MutableList < Any ? > )

{ <EOL> list . removeAt ( list . lastIndex ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_MutableList_setObject ( list : MutableList < Any ? > , index : Int , obj : Any ? )

{ <EOL> list . set ( index , obj ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_MutableCollection_removeObject ( collection : MutableCollection < Any ? > , element : Any ? <EOL> )

{ <EOL> collection . remove ( element ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_Iterator_hasNext ( iterator : Iterator < Any ? > ) : Boolean

= iterator . hasNext ( )


@ ExportForCppRuntime private fun Kotlin_Iterator_next ( iterator : Iterator < Any ? > ) : Any ?

= iterator . next ( )


@ ExportForCppRuntime private fun Kotlin_Set_contains ( set : Set < Any ? > , element : Any ? ) : Boolean

= set . contains ( element )


@ ExportForCppRuntime private fun Kotlin_Set_getElement ( set : Set < Any ? > , element : Any ? ) : Any ?

= <EOL> if ( set is KonanSet < Any ? > ) { <EOL> set . getElement ( element ) <EOL> } else if ( set . contains ( element ) ) { <EOL> set . first { it == element } <EOL> } else { <EOL> null <EOL> }


@ ExportForCppRuntime private fun Kotlin_Set_iterator ( set : Set < Any ? > ) : Iterator < Any ? >

= set . iterator ( )


@ ExportForCppRuntime private fun Kotlin_MutableSet_createWithCapacity ( capacity : Int ) : MutableSet < Any ? >

= <EOL> HashSet < Any ? > ( capacity )


@ ExportForCppRuntime private fun Kotlin_Map_getSize ( map : Map < Any ? , Any ? > ) : Int

= map . size


@ ExportForCppRuntime private fun Kotlin_Map_containsKey ( map : Map < Any ? , Any ? > , key : Any ? ) : Boolean

= map . containsKey ( key )


@ ExportForCppRuntime private fun Kotlin_Map_get ( map : Map < Any ? , Any ? > , key : Any ? ) : Any ?

= map . get ( key )


@ ExportForCppRuntime private fun Kotlin_Map_keyIterator ( map : Map < Any ? , Any ? > ) : Iterator < Any ? >

= map . keys . iterator ( )


@ ExportForCppRuntime private fun Kotlin_MutableMap_createWithCapacity ( capacity : Int ) : MutableMap < Any ? , Any ? >

= <EOL> HashMap < Any ? , Any ? > ( capacity )


@ ExportForCppRuntime private fun Kotlin_MutableMap_set ( map : MutableMap < Any ? , Any ? > , key : Any ? , value : Any ? )

{ <EOL> map . set ( key , value ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_MutableMap_remove ( map : MutableMap < Any ? , Any ? > , key : Any ? )

{ <EOL> map . remove ( key ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_ObjCExport_ThrowCollectionTooLarge ( )

{ <EOL> throw Error ( "<STR_LIT>" ) <EOL> }


@ ExportForCppRuntime private fun Kotlin_ObjCExport_ThrowCollectionConcurrentModification ( )


@ ExportForCppRuntime private fun Kotlin_NSArrayAsKList_create ( )

= NSArrayAsKList ( )


@ ExportForCppRuntime private fun Kotlin_NSMutableArrayAsKMutableList_create ( )

= NSMutableArrayAsKMutableList ( )


@ ExportForCppRuntime private fun Kotlin_NSEnumeratorAsKIterator_create ( )

= NSEnumeratorAsKIterator ( )


@ ExportForCppRuntime private fun Kotlin_NSSetAsKSet_create ( )

= NSSetAsKSet ( )


@ ExportForCppRuntime private fun Kotlin_NSDictionaryAsKMap_create ( )

= NSDictionaryAsKMap ( )


@ ExportForCppRuntime private fun Kotlin_ObjCExport_NSErrorAsExceptionImpl ( message : String ? , error : Any )

= ObjCErrorException ( message , error )


= "<STR_LIT>"


@ PublishedApi <EOL> @ GCUnsafeCall ( "<STR_LIT>" ) <EOL> @ ExportForCppRuntime <EOL> internal external fun trapOnUndeclaredException ( exception : Throwable )


@ ExportForCppRuntime <EOL> private fun Kotlin_Throwable_getMessage ( throwable : Throwable ) : String ?

= throwable . message


@ ExportForCppRuntime <EOL> private fun Kotlin_ObjCExport_getWrappedError ( throwable : Throwable ) : Any ?

= <EOL> ( throwable as? ObjCErrorException ) ? . error


fun generateParentInterfaces ( repository : Repository , todir : String , packg : String )

{ <EOL> val allParentIfaces = repository . tags . values . filterIgnored ( ) . map { tag -> <EOL> val parentAttributeIfaces = tag . attributeGroups . map { it . name . humanize ( ) . capitalize ( ) + "<STR_LIT>" } <EOL> val parentElementIfaces = tag . tagGroupNames . map { it . humanize ( ) . capitalize ( ) } <EOL> val sum = parentAttributeIfaces + parentElementIfaces <EOL> sum . toSet ( ) <EOL> } . filter { it . isNotEmpty ( ) } . toSet ( ) <EOL> val allIntroduced = HashSet < Set < String > > ( allParentIfaces . size ) <EOL> do { <EOL> val introduced = HashSet < Set < String > > ( ) <EOL> allParentIfaces . toList ( ) . allPairs ( ) . forEach { pair -> <EOL> val intersection = pair . first . intersect ( pair . second ) <EOL> if ( intersection . size > <NUM_LIT:1> && intersection !in allIntroduced && intersection !in allParentIfaces ) { <EOL> introduced . add ( intersection ) <EOL> } <EOL> } <EOL> if ( introduced . isEmpty ( ) ) { <EOL> break <EOL> } <EOL> allIntroduced . addAll ( introduced ) <EOL> } while ( true ) <EOL> FileOutputStream ( "<STR_LIT>" ) . writer ( Charsets . UTF_8 ) . use { <EOL> it . with { <EOL> packg ( packg ) <EOL> emptyLine ( ) <EOL> emptyLine ( ) <EOL> doNotEditWarning ( ) <EOL> emptyLine ( ) <EOL> emptyLine ( ) <EOL> ( allIntroduced . map { it . sorted ( ) } + allParentIfaces . filter { it . size > <NUM_LIT:1> } . map { it . sorted ( ) } ) . distinct ( ) . sortedBy { it . sorted ( ) . joinToString ( "<STR_LIT>" ) . let { renames [ it ] ? : it } } . forEach { iface -> <EOL> val ifaceName = humanizeJoin ( iface ) <EOL> val subs = <EOL> allIntroduced . map { it . sorted ( ) } . filter { other -> other != iface && other . all { it in iface } } + <EOL> allParentIfaces . map { it . sorted ( ) } . filter { other -> other != iface && other . all { it in iface } } <EOL> val computedParents = <EOL> ( iface - subs . flatMap { it } + subs . map ( :: humanizeJoin ) - ifaceName ) <EOL> . distinct ( ) <EOL> . map { renames [ it ] ? : it } <EOL> . sorted ( ) <EOL> clazz ( Clazz ( name = renames [ ifaceName ] ? : ifaceName , parents = computedParents , isInterface = true ) ) { <EOL> } <EOL> emptyLine ( ) <EOL> } <EOL> } <EOL> } <EOL> }


fun < T > List < T > . allPairs ( skipSamePairs : Boolean = true ) : Sequence < Pair < T , T > >

= PairsSequence ( this , skipSamePairs )

/**
 * Returns a sequence that consists of all possible pair of original list elements, does nothing with potential duplicates
 * @param skipSamePairs indicates whether it should produce pairs from the same element at both first and second positions
 */


override fun iterator ( ) : Iterator < Pair < T , T > >

= PairsIterator ( source , skipSamePairs )


{ <EOL> if ( source . isEmpty ( ) ) { <EOL> done ( ) <EOL> return <EOL> } <EOL> index ++ <EOL> val i1 = index / source . size <EOL> val i2 = index % source . size <EOL> if ( i1 >= source . lastIndex ) { <EOL> done ( ) <EOL> return <EOL> } <EOL> if ( skipSamePairs && i1 == i2 ) { <EOL> return computeNext ( ) <EOL> } <EOL> setNext ( Pair ( source [ i1 ] , source [ i2 ] ) ) <EOL> }


{ <EOL> assertDylib ( true , "<STR_LIT>" ) <EOL> }


{ <EOL> assertDylib ( false , "<STR_LIT>" ) <EOL> }


private fun assertDylib ( expected : Boolean , resource : String )

{ <EOL> val tmp = temporaryFolder . newFile ( ) <EOL> tmp . writeResource ( resource ) <EOL> return assertEquals ( expected , MachO . isDylib ( tmp , buildProject ( ) . logger ) ) <EOL> }


private fun File . writeResource ( resource : String )

{ <EOL> outputStream ( ) . use { out -> <EOL> MachOTest :: class . java . getResourceAsStream ( resource ) ! ! . use { input : InputStream -> <EOL> input . copyTo ( out ) <EOL> } <EOL> } <EOL> }


= <NUM_LIT:1>


{ <EOL> val d = OneofField . OneofUint32 ( <NUM_LIT> ) <EOL> val s = d . toString ( ) <EOL> if ( s != "<STR_LIT>" ) return s <EOL> return "<STR_LIT:OK>" <EOL> }


{ <EOL> return <NUM_LIT:1> <EOL> }


override fun removeAt ( index : Int ) : Int

{ <EOL> return <NUM_LIT:1> <EOL> }


override fun remove ( element : Int ) : Boolean

{ <EOL> return true <EOL> }


{ <EOL> b . get ( <NUM_LIT:1> ) <EOL> b . size <EOL> b . add ( <NUM_LIT:1> ) <EOL> b . remove ( ) <EOL> b . remove ( <NUM_LIT:1> ) <EOL> b . removeAt ( <NUM_LIT:1> ) <EOL> c . get ( <NUM_LIT:1> ) <EOL> c . size <EOL> c . add ( <NUM_LIT:1> ) <EOL> c . remove ( ) <EOL> c . remove ( <NUM_LIT:1> ) <EOL> c . removeAt ( <NUM_LIT:1> ) <EOL> d . remove ( <NUM_LIT:1> ) <EOL> }


private fun transformToNewType ( type : SimpleType ) : SimpleType

{ <EOL> when ( val constructor = type . constructor ) { <EOL> is CapturedTypeConstructorImpl -> { <EOL> val lowerType = constructor . projection . takeIf { it . projectionKind == Variance . IN_VARIANCE } ? . type ? . unwrap ( ) <EOL> if ( constructor . newTypeConstructor == null ) { <EOL> constructor . newTypeConstructor = <EOL> NewCapturedTypeConstructor ( constructor . projection , constructor . supertypes . map { it . unwrap ( ) } ) <EOL> } <EOL> return NewCapturedType ( CaptureStatus . FOR_SUBTYPING , constructor . newTypeConstructor ! ! , lowerType , type . attributes , type . isMarkedNullable ) <EOL> } <EOL> is IntegerValueTypeConstructor -> { <EOL> val newConstructor = <EOL> IntersectionTypeConstructor ( constructor . supertypes . map { TypeUtils . makeNullableAsSpecified ( it , type . isMarkedNullable ) } ) <EOL> return KotlinTypeFactory . simpleTypeWithNonTrivialMemberScope ( type . attributes , newConstructor , listOf ( ) , false , type . memberScope ) <EOL> } <EOL> is IntersectionTypeConstructor -> if ( type . isMarkedNullable ) { <EOL> val newConstructor = constructor . transformComponents ( transform = { it . makeNullable ( ) } ) ? : constructor <EOL> return newConstructor . createType ( ) <EOL> } <EOL> } <EOL> return type <EOL> }


override fun prepareType ( type : KotlinTypeMarker ) : UnwrappedType

{ <EOL> require ( type is KotlinType ) <EOL> val unwrappedType = type . unwrap ( ) <EOL> return when ( unwrappedType ) { <EOL> is SimpleType -> transformToNewType ( unwrappedType ) <EOL> is FlexibleType -> { <EOL> val newLower = transformToNewType ( unwrappedType . lowerBound ) <EOL> val newUpper = transformToNewType ( unwrappedType . upperBound ) <EOL> if ( newLower !== unwrappedType . lowerBound || newUpper !== unwrappedType . upperBound ) { <EOL> KotlinTypeFactory . flexibleType ( newLower , newUpper ) <EOL> } else { <EOL> unwrappedType <EOL> } <EOL> } <EOL> } . inheritEnhancement ( unwrappedType , :: prepareType ) <EOL> }


override fun create ( element : PsiNamedElement ) : DocComment ?

{ <EOL> val ktElement = element . navigationElement as? KtElement ? : return null <EOL> val kdoc = ktElement . findKDoc ( ) ? : return null <EOL> return KotlinDocComment ( kdoc . contentTag , ResolveDocContext ( ktElement ) ) <EOL> }


@ Test <EOL> fun zeroedInputTensorWithDefaultValues ( )

{ <EOL> val input = create1DTensor ( batchSize = <NUM_LIT:1> , size = <NUM_LIT:3> , channels = <NUM_LIT:1> , initValue = <NUM_LIT:0.0f> ) <EOL> val expected = create1DTensor ( batchSize = <NUM_LIT:1> , size = <NUM_LIT:3> , channels = <NUM_LIT> , initValue = <NUM_LIT:0.0f> ) <EOL> assertTensorsEquals ( Conv1D ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , name = "<STR_LIT>" , biasInitializer = Zeros ( ) ) , input , expected ) <EOL> }


@ Test <EOL> fun constantInputTensorWithValidPadding ( )

{ <EOL> val input = create1DTensor ( batchSize = <NUM_LIT:1> , size = <NUM_LIT:3> , channels = <NUM_LIT:1> , initValue = <NUM_LIT> ) <EOL> val expected = create1DTensor ( batchSize = <NUM_LIT:1> , size = <NUM_LIT:2> , channels = <NUM_LIT:16> , initValue = <NUM_LIT> ) <EOL> assertTensorsEquals ( Conv1D ( strides = <NUM_LIT:1> , name = "<STR_LIT>" , filters = <NUM_LIT:16> , kernelInitializer = Constant ( <NUM_LIT> ) , biasInitializer = Zeros ( ) , kernelLength = <NUM_LIT:2> , padding = ConvPadding . VALID ) , input , expected ) <EOL> }


@ Test <EOL> fun randomInputTensorWithOnesWeight ( )

{ <EOL> val input = arrayOf ( arrayOf ( floatArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , floatArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , floatArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> val expected = arrayOf ( arrayOf ( floatArrayOf ( input . sum ( ) ) ) ) <EOL> assertTensorsEquals ( Conv1D ( strides = <NUM_LIT:1> , name = "<STR_LIT>" , filters = <NUM_LIT:1> , kernelInitializer = Constant ( <NUM_LIT> ) , biasInitializer = Zeros ( ) , kernelLength = <NUM_LIT:3> , padding = ConvPadding . VALID ) , input , expected ) <EOL> }


internal fun create1DTensor ( batchSize : Int , size : Int , channels : Int , initValue : Float )

= Array ( batchSize ) { Array ( size ) { FloatArray ( channels ) { initValue } } }


internal fun create1DTensor ( batchSize : Int , channels : Int , sequence : FloatArray , )

= Array ( batchSize ) { Array ( sequence . size ) { idx -> FloatArray ( channels ) { sequence [ idx ] } } }


{ <EOL> val list1 = ArrayList < Int > ( ) <EOL> val range1 = <NUM_LIT:3> .. <NUM_LIT:9> step <NUM_LIT:2> <EOL> for ( i in range1 ) { <EOL> list1 . add ( i ) <EOL> if ( list1 . size > <NUM_LIT:23> ) break <EOL> } <EOL> if ( list1 != listOf < Int > ( <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:9> ) ) { <EOL> return "<STR_LIT>" <EOL> } <EOL> val list2 = ArrayList < Int > ( ) <EOL> val range2 = <NUM_LIT:3> . toByte ( ) .. <NUM_LIT:9> . toByte ( ) step <NUM_LIT:2> <EOL> for ( i in range2 ) { <EOL> list2 . add ( i ) <EOL> if ( list2 . size > <NUM_LIT:23> ) break <EOL> } <EOL> if ( list2 != listOf < Int > ( <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:9> ) ) { <EOL> return "<STR_LIT>" <EOL> } <EOL> val list3 = ArrayList < Int > ( ) <EOL> val range3 = <NUM_LIT:3> . toShort ( ) .. <NUM_LIT:9> . toShort ( ) step <NUM_LIT:2> <EOL> for ( i in range3 ) { <EOL> list3 . add ( i ) <EOL> if ( list3 . size > <NUM_LIT:23> ) break <EOL> } <EOL> if ( list3 != listOf < Int > ( <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:9> ) ) { <EOL> return "<STR_LIT>" <EOL> } <EOL> val list4 = ArrayList < Long > ( ) <EOL> val range4 = <NUM_LIT:3L> .. <NUM_LIT> step <NUM_LIT> <EOL> for ( i in range4 ) { <EOL> list4 . add ( i ) <EOL> if ( list4 . size > <NUM_LIT:23> ) break <EOL> } <EOL> if ( list4 != listOf < Long > ( <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:9> ) ) { <EOL> return "<STR_LIT>" <EOL> } <EOL> val list5 = ArrayList < Char > ( ) <EOL> val range5 = '<CHAR_LIT:c>' .. '<CHAR_LIT>' step <NUM_LIT:2> <EOL> for ( i in range5 ) { <EOL> list5 . add ( i ) <EOL> if ( list5 . size > <NUM_LIT:23> ) break <EOL> } <EOL> if ( list5 != listOf < Char > ( '<CHAR_LIT:c>' , '<CHAR_LIT:e>' , '<CHAR_LIT>' ) ) { <EOL> return "<STR_LIT>" <EOL> } <EOL> return "<STR_LIT:OK>" <EOL> }


private fun renderAnnotation ( ann : FirAnnotation ) : String

{ <EOL> return FirRenderer ( typeRenderer = ConeTypeRenderer ( ) , idRenderer = ConeIdShortRenderer ( ) , referencedSymbolRenderer = FirIdRendererBasedSymbolRenderer ( ) , resolvedNamedReferenceRenderer = FirResolvedNamedReferenceRenderer ( ) , resolvedQualifierRenderer = FirResolvedQualifierRenderer ( ) , getClassCallRenderer = FirGetClassCallRendererForReadability ( ) , ) . renderElementAsString ( ann , trim = true ) <EOL> }


public fun AnyCol . toArrowField ( mismatchSubscriber : ( ConvertingMismatch ) -> Unit = ignoreMismatchMessage ) : Field

{ <EOL> val column = this <EOL> val columnType = column . type ( ) <EOL> val nullable = columnType . isMarkedNullable <EOL> return when { <EOL> columnType . isSubtypeOf ( typeOf < String ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Utf8 ( ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < Boolean ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Bool ( ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < Byte ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Int ( <NUM_LIT:8> , true ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < Short ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Int ( <NUM_LIT:16> , true ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < Int ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Int ( <NUM_LIT> , true ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < Long ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Int ( <NUM_LIT> , true ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < Float ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . FloatingPoint ( FloatingPointPrecision . SINGLE ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < Double ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . FloatingPoint ( FloatingPointPrecision . DOUBLE ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < LocalDate ? > ( ) ) || columnType . isSubtypeOf ( typeOf < kotlinx . datetime . LocalDate ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Date ( DateUnit . DAY ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < LocalDateTime ? > ( ) ) || columnType . isSubtypeOf ( typeOf < kotlinx . datetime . LocalDateTime ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Date ( DateUnit . MILLISECOND ) , null ) , emptyList ( ) ) <EOL> columnType . isSubtypeOf ( typeOf < LocalTime ? > ( ) ) -> Field ( column . name ( ) , FieldType ( nullable , ArrowType . Time ( TimeUnit . NANOSECOND , <NUM_LIT> ) , null ) , emptyList ( ) ) <EOL> else -> { <EOL> mismatchSubscriber ( ConvertingMismatch . SavedAsString ( column . name ( ) , column . typeClass . java ) ) <EOL> Field ( column . name ( ) , FieldType ( true , ArrowType . Utf8 ( ) , null ) , emptyList ( ) ) <EOL> } <EOL> } <EOL> }

/**
 * Create Arrow [Field] (note: this is part of [Schema], does not contain data itself) that has the same
 * name, type and nullable as [this]
 */


public fun List < AnyCol > . toArrowSchema ( mismatchSubscriber : ( ConvertingMismatch ) -> Unit = ignoreMismatchMessage ) : Schema

{ <EOL> val fields = this . map { it . toArrowField ( mismatchSubscriber ) } <EOL> return Schema ( fields ) <EOL> }

/**
 * Create Arrow [Schema] matching [this] actual data.
 * Columns with not supported types will be interpreted as String
 */


{ <EOL> while ( false ) ; <EOL> var x = <NUM_LIT:0> <EOL> while ( x ++ < <NUM_LIT:5> ) ; <EOL> if ( x != <NUM_LIT:6> ) return "<STR_LIT>" <EOL> return "<STR_LIT:OK>" <EOL> }


fun lenetOnMnistExportImportToJSONWithAdamOptimizerState ( )

{ <EOL> val ( train , test ) = mnist ( ) <EOL> val ( newTrain , validation ) = train . split ( <NUM_LIT> ) <EOL> val optimizer = Adam ( ) <EOL> lenet5 ( ) . use { <EOL> it . compile ( optimizer = optimizer , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> it . logSummary ( ) <EOL> print ( it . kGraph ( ) ) <EOL> it . fit ( trainingDataset = newTrain , validationDataset = validation , epochs = EPOCHS , trainBatchSize = TRAINING_BATCH_SIZE , validationBatchSize = TEST_BATCH_SIZE ) <EOL> it . save ( modelDirectory = File ( PATH_TO_MODEL ) , saveOptimizerState = true , savingFormat = SavingFormat . JsonConfigCustomVariables ( ) , writingMode = WritingMode . OVERRIDE ) <EOL> val accuracy = it . evaluate ( dataset = test , batchSize = TEST_BATCH_SIZE ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> val model = Sequential . loadModelConfiguration ( File ( "<STR_LIT>" ) ) <EOL> model . use { <EOL> it . layers . filterIsInstance < Conv2D > ( ) . forEach ( Layer :: freeze ) <EOL> it . compile ( optimizer = optimizer , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> it . logSummary ( ) <EOL> print ( it . kGraph ( ) ) <EOL> it . loadWeights ( File ( PATH_TO_MODEL ) , loadOptimizerState = true ) <EOL> val accuracyBefore = it . evaluate ( dataset = test , batchSize = <NUM_LIT:100> ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> it . fit ( dataset = train , validationRate = <NUM_LIT> , epochs = <NUM_LIT:1> , trainBatchSize = <NUM_LIT> , validationBatchSize = <NUM_LIT:100> ) <EOL> val accuracyAfterTraining = it . evaluate ( dataset = test , batchSize = <NUM_LIT:100> ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> val model2 = Sequential . loadModelConfiguration ( File ( "<STR_LIT>" ) ) <EOL> model2 . use { <EOL> it . compile ( optimizer = optimizer , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> it . logSummary ( ) <EOL> it . loadWeights ( File ( PATH_TO_MODEL ) , loadOptimizerState = false ) <EOL> val accuracyBefore = it . evaluate ( dataset = test , batchSize = <NUM_LIT:100> ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> it . fit ( dataset = train , validationRate = <NUM_LIT> , epochs = <NUM_LIT:1> , trainBatchSize = <NUM_LIT> , validationBatchSize = <NUM_LIT:100> ) <EOL> val accuracyAfterTraining = it . evaluate ( dataset = test , batchSize = <NUM_LIT:100> ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }

/**
 * This examples demonstrates model, model weights, and optimizer weights export and import back:
 * - Model is exported in Keras-style JSON format; weights are exported in custom (txt) format.
 * - Model is trained on Mnist dataset.
 * - It saves all the data to the project root directory.
 * - The first [Sequential] model is created via JSON configuration, weights, and optimizer state loading.
 * - After loading model is trained again with the same optimizer with frozen Conv2D layers. Only weights in Dense layers can be updated.
 * - The second [Sequential] model is created via JSON configuration and weights loading.
 * - After loading model is trained again with the same optimizer with frozen Conv2D layers. Only weights in Dense layers can be updated.
 * - Results of two training (with restored optimizer state and without) could be compared via accuracy comparison.
 */


= lenetOnMnistExportImportToJSONWithAdamOptimizerState ( )


= PRESET_NAME


override fun createTargetInternal ( name : String ) : KotlinWithJavaTarget < KotlinJvmOptions , KotlinJvmCompilerOptions >

{ <EOL> project . reportDiagnostic ( KotlinToolingDiagnostics . DeprecatedJvmWithJavaPresetDiagnostic ( ) ) <EOL> project . plugins . apply ( JavaPlugin :: class . java ) <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" , "<STR_LIT:DEPRECATION>" , "<STR_LIT:TYPEALIAS_EXPANSION_DEPRECATION>" ) <EOL> val target = ( project . objects . newInstance ( KotlinWithJavaTarget :: class . java , project , KotlinPlatformType . jvm , name , { <EOL> object : DeprecatedHasCompilerOptions < KotlinJvmCompilerOptions > { <EOL> override val options : KotlinJvmCompilerOptions = project . objects <EOL> . newInstance ( KotlinJvmCompilerOptionsDefault :: class . java ) <EOL> . configureExperimentalTryNext ( project ) <EOL> } <EOL> } , { compilerOptions : KotlinJvmCompilerOptions -> <EOL> object : KotlinJvmOptions { <EOL> override val options : KotlinJvmCompilerOptions <EOL> get ( ) = compilerOptions <EOL> } <EOL> } ) as KotlinWithJavaTarget < KotlinJvmOptions , KotlinJvmCompilerOptions > ) <EOL> . apply { <EOL> disambiguationClassifier = name <EOL> preset = this@KotlinJvmWithJavaTargetPreset <EOL> } <EOL> AbstractKotlinPlugin . configureTarget ( target ) { compilation -> <EOL> Kotlin2JvmSourceSetProcessor ( KotlinTasksProvider ( ) , KotlinCompilationInfo ( compilation ) ) <EOL> } <EOL> target . compilations . configureEach { <EOL> @ Suppress ( "<STR_LIT:DEPRECATION>" ) <EOL> it . compilerOptions . options . moduleName . convention ( it . moduleNameForCompilation ( ) ) <EOL> } <EOL> target . compilations . getByName ( "<STR_LIT:test>" ) . run { <EOL> val main = target . compilations . getByName ( KotlinCompilation . MAIN_COMPILATION_NAME ) <EOL> compileDependencyFiles = project . files ( main . output . allOutputs , project . configurations . maybeCreateResolvable ( compileDependencyConfigurationName ) ) <EOL> runtimeDependencyFiles = project . files ( output . allOutputs , main . output . allOutputs , project . configurations . maybeCreateResolvable ( runtimeDependencyConfigurationName ) ) <EOL> } <EOL> return target <EOL> }


{ <EOL> coEvery1 { b . save ( any ( ) ) } <EOL> }


fun < T > coEvery1 ( stubBlock : suspend MockKMatcherScope . ( ) -> T )


inline fun < reified T : Any > any ( ) : T

= TODO ( )


= TODO ( )


fun getNameForDestructuredParameterOrNull ( valueParameterDescriptor : ValueParameterDescriptor ) : String ?

{ <EOL> val variables = ValueParameterDescriptorImpl . getDestructuringVariablesOrNull ( valueParameterDescriptor ) ? : return null <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> return DESTRUCTURED_LAMBDA_ARGUMENT_VARIABLE_PREFIX + variables . joinToString ( separator = "<STR_LIT:$>" ) { descriptor -> <EOL> val name = descriptor . name <EOL> mangleNameIfNeeded ( when { <EOL> name . isSpecial -> "<STR_LIT>" <EOL> else -> descriptor . name . asString ( ) <EOL> } ) <EOL> } <EOL> }


= <NUM_LIT:3>


suspend fun suspendWithValue ( v : String ) : String

= suspendCoroutineUninterceptedOrReturn { x -> <EOL> postponedActions . add { <EOL> x . resume ( v ) <EOL> } <EOL> COROUTINE_SUSPENDED <EOL> }


suspend fun suspendWithException ( e : Exception ) : String

= suspendCoroutineUninterceptedOrReturn { x -> <EOL> postponedActions . add { <EOL> x . resumeWithException ( e ) <EOL> } <EOL> COROUTINE_SUSPENDED <EOL> }


fun run ( c : suspend Controller . ( ) -> String )

{ <EOL> c . startCoroutine ( this , handleResultContinuation { <EOL> globalResult = it <EOL> } ) <EOL> while ( postponedActions . isNotEmpty ( ) ) { <EOL> postponedActions [ <NUM_LIT:0> ] ( ) <EOL> postponedActions . removeAt ( <NUM_LIT:0> ) <EOL> } <EOL> }


fun builder ( expectException : Boolean = false , c : suspend Controller . ( ) -> String )

{ <EOL> val controller = Controller ( ) <EOL> globalResult = "<STR_LIT:#>" <EOL> wasCalled = false <EOL> if ( ! expectException ) { <EOL> controller . run ( c ) <EOL> } <EOL> else { <EOL> try { <EOL> controller . run ( c ) <EOL> globalResult = "<STR_LIT>" <EOL> } catch ( e : Exception ) { <EOL> globalResult = e . message ! ! <EOL> } <EOL> } <EOL> if ( ! wasCalled ) { <EOL> throw RuntimeException ( "<STR_LIT>" ) <EOL> } <EOL> if ( globalResult != "<STR_LIT:OK>" ) { <EOL> throw RuntimeException ( "<STR_LIT>" ) <EOL> } <EOL> }


{ <EOL> throw t <EOL> }


{ <EOL> builder { <EOL> try { <EOL> try { <EOL> suspendWithValue ( "<STR_LIT>" ) <EOL> suspendWithValue ( "<STR_LIT:OK>" ) <EOL> } <EOL> catch ( e : RuntimeException ) { <EOL> suspendWithValue ( "<STR_LIT:failU+00201>" ) <EOL> } <EOL> } finally { <EOL> wasCalled = true <EOL> } <EOL> } <EOL> builder { <EOL> try { <EOL> try { <EOL> suspendWithException ( RuntimeException ( "<STR_LIT>" ) ) <EOL> } <EOL> catch ( e : RuntimeException ) { <EOL> if ( e . message != "<STR_LIT>" ) throw RuntimeException ( "<STR_LIT:failU+00202>" ) <EOL> wasCalled = true <EOL> suspendWithValue ( "<STR_LIT:OK>" ) <EOL> } <EOL> } catch ( e : Exception ) { <EOL> suspendWithValue ( "<STR_LIT:failU+00203>" ) <EOL> } <EOL> } <EOL> builder { <EOL> try { <EOL> try { <EOL> suspendWithException ( Exception ( "<STR_LIT>" ) ) <EOL> } <EOL> catch ( e : RuntimeException ) { <EOL> suspendWithValue ( "<STR_LIT:failU+00204>" ) <EOL> } finally { <EOL> wasCalled = true <EOL> } <EOL> } catch ( e : Exception ) { <EOL> if ( e . message != "<STR_LIT>" ) throw RuntimeException ( "<STR_LIT:failU+00205>" ) <EOL> suspendWithValue ( "<STR_LIT:OK>" ) <EOL> } <EOL> } <EOL> return globalResult <EOL> }


{ <EOL> val file = File ( workingDir , "<STR_LIT>" ) <EOL> file . writeText ( "<STR_LIT:test>" ) <EOL> val snapshot = fileSnapshotProvider [ file ] <EOL> val deserializedSnapshot = saveAndReadBack ( snapshot ) <EOL> assertEquals ( snapshot , deserializedSnapshot ) <EOL> }


@ Test <EOL> fun testEqualityNoChanges ( )

{ <EOL> val file = File ( workingDir , "<STR_LIT>" ) . apply { writeText ( "<STR_LIT>" ) } <EOL> val oldSnapshot = fileSnapshotProvider [ file ] <EOL> val newSnapshot = fileSnapshotProvider [ file ] <EOL> assertEquals ( oldSnapshot , newSnapshot ) <EOL> }


@ Test <EOL> fun testEqualityDifferentFile ( )

{ <EOL> val file1 = File ( workingDir , "<STR_LIT>" ) . apply { writeText ( "<STR_LIT>" ) } <EOL> val file2 = File ( workingDir , "<STR_LIT>" ) . apply { <EOL> writeText ( file1 . readText ( ) ) <EOL> setLastModified ( file1 . lastModified ( ) ) <EOL> } <EOL> val oldSnapshot = fileSnapshotProvider [ file1 ] <EOL> val newSnapshot = fileSnapshotProvider [ file2 ] <EOL> assertNotEquals ( oldSnapshot , newSnapshot ) <EOL> }


@ Test <EOL> fun testEqualityDifferentTimestamp ( )

{ <EOL> val text = "<STR_LIT>" <EOL> val file = File ( workingDir , "<STR_LIT>" ) . apply { writeText ( text ) } <EOL> val oldSnapshot = fileSnapshotProvider [ file ] <EOL> Thread . sleep ( <NUM_LIT> ) <EOL> file . writeText ( text ) <EOL> val newSnapshot = fileSnapshotProvider [ file ] <EOL> assertEquals ( oldSnapshot , newSnapshot ) <EOL> }


@ Test <EOL> fun testEqualityDifferentSize ( )

{ <EOL> val file = File ( workingDir , "<STR_LIT>" ) . apply { writeText ( "<STR_LIT>" ) } <EOL> val oldSnapshot = fileSnapshotProvider [ file ] <EOL> file . writeText ( "<STR_LIT>" ) <EOL> val newSnapshot = fileSnapshotProvider [ file ] <EOL> assertNotEquals ( oldSnapshot , newSnapshot ) <EOL> }


@ Test <EOL> fun testEqualityDifferentHash ( )

{ <EOL> val file = File ( workingDir , "<STR_LIT>" ) . apply { writeText ( "<STR_LIT>" ) } <EOL> val oldSnapshot = fileSnapshotProvider [ file ] <EOL> file . writeText ( "<STR_LIT:main>" ) <EOL> val newSnapshot = fileSnapshotProvider [ file ] <EOL> assertNotEquals ( oldSnapshot , newSnapshot ) <EOL> }


private fun saveAndReadBack ( snapshot : FileSnapshot ) : FileSnapshot

{ <EOL> val byteOut = ByteArrayOutputStream ( ) <EOL> DataOutputStream ( byteOut ) . use { FileSnapshotExternalizer . save ( it , snapshot ) } <EOL> val byteIn = ByteArrayInputStream ( byteOut . toByteArray ( ) ) <EOL> return DataInputStream ( byteIn ) . use { FileSnapshotExternalizer . read ( it ) } <EOL> }


{ <EOL> fun A . localX ( ) { <EOL> x = s + "<STR_LIT:K>" <EOL> } <EOL> val a : A = A ( "<STR_LIT:FAIL>" ) <EOL> a . apply ( A :: localX ) <EOL> if ( a . x != "<STR_LIT:OK>" ) return a . x <EOL> a . apply { localX ( ) } <EOL> return a . x <EOL> }


{ <EOL> return f ( "<STR_LIT:O>" ) <EOL> }


actual fun Modifier . addUserInput ( state : ScalableState ) : Modifier

= <EOL> pointerInput ( Unit ) { <EOL> detectDragGestures { change , dragAmount : Offset -> <EOL> state . addDragAmount ( dragAmount ) <EOL> change . consume ( ) <EOL> } <EOL> } . pointerInput ( Unit ) { <EOL> awaitPointerEventScope { <EOL> while ( true ) { <EOL> val event = awaitPointerEvent ( ) <EOL> if ( event . type == PointerEventType . Scroll ) { <EOL> val delta = event . changes . getOrNull ( <NUM_LIT:0> ) ? . scrollDelta ? : Offset . Zero <EOL> state . addScale ( delta . y / <NUM_LIT:100> ) <EOL> } <EOL> } <EOL> } <EOL> }


override fun check ( expression : FirAnnotation , context : CheckerContext , reporter : DiagnosticReporter )

{ <EOL> if ( context . containingDeclarations . lastOrNull ( ) ? . source ? . kind != KtRealSourceElementKind ) return <EOL> val callableSymbol = expression . annotationTypeRef . toClassLikeSymbol ( context . session ) as? FirClassSymbol < * > ? : return <EOL> if ( callableSymbol . origin !is FirDeclarationOrigin . Java ) return <EOL> val lookupTag = expression . annotationTypeRef . coneTypeSafe < ConeClassLikeType > ( ) ? . lookupTag ? : return <EOL> javaToKotlinNameMap [ lookupTag . classId ] ? . let { betterName -> <EOL> reporter . reportOn ( expression . source , FirJvmErrors . DEPRECATED_JAVA_ANNOTATION , betterName . asSingleFqName ( ) , context ) <EOL> } <EOL> if ( expression is FirAnnotationCall ) { <EOL> val argumentList = expression . argumentList <EOL> if ( argumentList is FirResolvedArgumentList ) { <EOL> val arguments = argumentList . originalArgumentList ? . arguments ? : return <EOL> for ( key in arguments ) { <EOL> if ( key !is FirWrappedArgumentExpression && argumentList . mapping [ key ] ? . name . let { it != null && it != Annotations . ParameterNames . value } ) { <EOL> reporter . reportOn ( key . source , FirJvmErrors . POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION , context ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> }


= "<STR_LIT:OK>" as? T


{ <EOL> val callable : ( ) -> String ? = :: funNoArgs <EOL> assertEquals ( callable ( ) , "<STR_LIT:OK>" ) <EOL> }


inline fun < reified T > funWithArgs ( x : T , y : T )

= x to y


{ <EOL> val callable : ( String , String ) -> Pair < String , String > = :: funWithArgs <EOL> assertEquals ( callable ( "<STR_LIT:O>" , "<STR_LIT:K>" ) , "<STR_LIT:O>" to "<STR_LIT:K>" ) <EOL> }


inline fun < reified T > funWithVarargs ( vararg i : T )

= i . toList ( )


{ <EOL> val callable : ( Array < Int > ) -> List < Int > = :: funWithVarargs <EOL> assertEquals ( callable ( arrayOf ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) , listOf ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> }


inline fun < reified T > T . funWithExtensionNoArgs ( )

= this


{ <EOL> val callable1 = String :: funWithExtensionNoArgs <EOL> assertEquals ( callable1 ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val callable2 = "<STR_LIT>" :: funWithExtensionNoArgs <EOL> assertEquals ( callable2 ( ) , "<STR_LIT>" ) <EOL> val callable3 = callable1 :: funWithExtensionNoArgs <EOL> assertEquals ( callable3 ( ) ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val callable4 = with ( "<STR_LIT>" ) { :: funWithExtensionNoArgs } <EOL> assertEquals ( callable4 ( ) , "<STR_LIT>" ) <EOL> }


inline fun < reified T > T . funWithExtensionAndArgs ( x : Int , y : Int )

= this to ( x + y )


fun testFunctionWithExtensionAndArgs ( )

{ <EOL> val callable1 = String :: funWithExtensionAndArgs <EOL> assertEquals ( callable1 ( "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT:2> ) , "<STR_LIT>" to <NUM_LIT:3> ) <EOL> val callable2 = "<STR_LIT>" :: funWithExtensionAndArgs <EOL> assertEquals ( callable2 ( <NUM_LIT:3> , <NUM_LIT:4> ) , "<STR_LIT>" to <NUM_LIT:7> ) <EOL> val callable3 = callable1 :: funWithExtensionAndArgs <EOL> val ( cb , s ) = callable3 ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> assertEquals ( s , <NUM_LIT:11> ) <EOL> assertEquals ( cb ( "<STR_LIT>" , <NUM_LIT:7> , <NUM_LIT:8> ) , "<STR_LIT>" to <NUM_LIT> ) <EOL> val callable4 = with ( "<STR_LIT>" ) { :: funWithExtensionAndArgs } <EOL> assertEquals ( callable4 ( <NUM_LIT:9> , <NUM_LIT:10> ) , "<STR_LIT>" to <NUM_LIT> ) <EOL> }


inline fun < reified T > T . funWithExtensionAndVarargs ( vararg i : Int )

= this to i . sum ( )


fun testFunctionWithExtensionAndVararg ( )

{ <EOL> val callable1 = String :: funWithExtensionAndVarargs <EOL> assertEquals ( callable1 ( "<STR_LIT>" , arrayOf ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) . toIntArray ( ) ) , "<STR_LIT>" to <NUM_LIT:6> ) <EOL> val callable2 = "<STR_LIT>" :: funWithExtensionAndVarargs <EOL> assertEquals ( callable2 ( arrayOf ( <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ) . toIntArray ( ) ) , "<STR_LIT>" to <NUM_LIT> ) <EOL> val callable3 = callable1 :: funWithExtensionAndVarargs <EOL> val ( cb , s ) = callable3 ( arrayOf ( <NUM_LIT:7> , <NUM_LIT:8> ) . toIntArray ( ) ) <EOL> assertEquals ( s , <NUM_LIT> ) <EOL> assertEquals ( cb ( "<STR_LIT>" , arrayOf ( <NUM_LIT:9> , <NUM_LIT:10> ) . toIntArray ( ) ) , "<STR_LIT>" to <NUM_LIT> ) <EOL> val callable4 = with ( "<STR_LIT>" ) { :: funWithExtensionAndVarargs } <EOL> assertEquals ( callable4 ( arrayOf ( <NUM_LIT:11> , <NUM_LIT:12> ) . toIntArray ( ) ) , "<STR_LIT>" to <NUM_LIT:23> ) <EOL> }


inline fun < reified T > classFunNoArgs ( )

= s as? T


inline fun < reified T > classFunWithArgs ( x : T )

= x to s


inline fun < reified T > classFunWithVarargs ( vararg i : T )

= i . toList ( ) to s


{ <EOL> val callable : ( ) -> String ? = with ( TestClass ( "<STR_LIT>" ) ) { :: classFunNoArgs } <EOL> assertEquals ( callable ( ) , "<STR_LIT>" ) <EOL> }


{ <EOL> val callable : ( Int ) -> Pair < Int , String > = with ( TestClass ( "<STR_LIT>" ) ) { :: classFunWithArgs } <EOL> assertEquals ( callable ( <NUM_LIT:1> ) , <NUM_LIT:1> to "<STR_LIT>" ) <EOL> }


{ <EOL> val callable : ( Array < Int > ) -> Pair < List < Int > , String > = with ( TestClass ( "<STR_LIT>" ) ) { :: classFunWithVarargs } <EOL> assertEquals ( callable ( arrayOf ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , listOf ( <NUM_LIT:1> , <NUM_LIT:2> ) to "<STR_LIT>" ) <EOL> }


{ <EOL> testFunctionNoArgs ( ) <EOL> testFunctionWithArgs ( ) <EOL> testFunctionWithVarargs ( ) <EOL> testFunctionWithExtensionNoArgs ( ) <EOL> testFunctionWithExtensionAndArgs ( ) <EOL> testFunctionWithExtensionAndVararg ( ) <EOL> testClassFunctionNoArgs ( ) <EOL> testClassFunctionWithArgs ( ) <EOL> testClassFunctionWithVarargs ( ) <EOL> return "<STR_LIT:OK>" <EOL> }


{ <EOL> var sum = <NUM_LIT:0> <EOL> for ( i in ( <NUM_LIT:4> downTo <NUM_LIT:1> ) . reversed ( ) . reversed ( ) ) { <EOL> sum = sum * <NUM_LIT:10> + i <EOL> } <EOL> assertEquals ( <NUM_LIT> , sum ) <EOL> var sumL = <NUM_LIT:0L> <EOL> for ( i in ( <NUM_LIT> downTo <NUM_LIT:1L> ) . reversed ( ) . reversed ( ) ) { <EOL> sumL = sumL * <NUM_LIT:10> + i <EOL> } <EOL> assertEquals ( <NUM_LIT> , sumL ) <EOL> var sumC = <NUM_LIT:0> <EOL> for ( i in ( '<CHAR_LIT:4>' downTo '<CHAR_LIT:1>' ) . reversed ( ) . reversed ( ) ) { <EOL> sumC = sumC * <NUM_LIT:10> + i . toInt ( ) - '<CHAR_LIT:0>' . toInt ( ) <EOL> } <EOL> assertEquals ( <NUM_LIT> , sumC ) <EOL> return "<STR_LIT:OK>" <EOL> }


infix fun resource ( factory : Factory < R , T > ) : Delegate < R , T >


fun < Self : Some , Target : Some > Self . delegateOf ( clazz : Class < Target > ) : Delegate < Self , Target ? >

= null ! !


fun < M : SomeImpl < T > , T : Some > getFactory ( ) : Factory < M , T ? >

= null ! !


{ <EOL> val keys = generateKeys ( hashCodeType , size * <NUM_LIT:2> ) <EOL> persistentMap = persistentMapBuilderPut ( implementation , keys . take ( size ) , <NUM_LIT:0.0> ) <EOL> sameMap = persistentMapBuilderPut ( implementation , keys . take ( size ) , <NUM_LIT:0.0> ) <EOL> slightlyDifferentMap = sameMap . build ( ) . builder ( ) <EOL> slightlyDifferentMap . put ( keys [ size ] , "<STR_LIT>" ) <EOL> slightlyDifferentMap . remove ( keys [ <NUM_LIT:0> ] ) <EOL> veryDifferentMap = persistentMapBuilderPut ( implementation , keys . drop ( size ) , <NUM_LIT:0.0> ) <EOL> }


= persistentMap == sameMap


= persistentMap == slightlyDifferentMap


= persistentMap == veryDifferentMap


public actual fun < T > setOf ( element : T ) : Set < T >

= java . util . Collections . singleton ( element )

/**
 * Returns a new read-only set containing only the specified object [element].
 *
 * The returned set is serializable.
 *
 * @sample samples.collections.Collections.Sets.singletonReadOnlySet
 */


@ PublishedApi <EOL> @ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> internal actual inline fun < E > buildSetInternal ( builderAction : MutableSet < E > . ( ) -> Unit ) : Set < E >

{ <EOL> return build ( createSetBuilder < E > ( ) . apply ( builderAction ) ) <EOL> }


@ PublishedApi <EOL> @ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> internal actual inline fun < E > buildSetInternal ( capacity : Int , builderAction : MutableSet < E > . ( ) -> Unit ) : Set < E >

{ <EOL> return build ( createSetBuilder < E > ( capacity ) . apply ( builderAction ) ) <EOL> }


@ PublishedApi <EOL> @ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> internal fun < E > createSetBuilder ( ) : MutableSet < E >

{ <EOL> return SetBuilder ( ) <EOL> }


@ PublishedApi <EOL> @ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> internal fun < E > createSetBuilder ( capacity : Int ) : MutableSet < E >

{ <EOL> return SetBuilder ( capacity ) <EOL> }


@ PublishedApi <EOL> @ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> internal fun < E > build ( builder : MutableSet < E > ) : Set < E >

{ <EOL> return ( builder as SetBuilder < E > ) . build ( ) <EOL> }


public fun < T > sortedSetOf ( vararg elements : T ) : java . util . TreeSet < T >

= elements . toCollection ( java . util . TreeSet < T > ( ) )

/**
 * Returns a new [java.util.SortedSet] with the given elements.
 */


public fun < T > sortedSetOf ( comparator : Comparator < in T > , vararg elements : T ) : java . util . TreeSet < T >

= elements . toCollection ( java . util . TreeSet < T > ( comparator ) )

/**
 * Returns a new [java.util.SortedSet] with the given [comparator] and elements.
 */


private fun runInteractive ( vararg inputsToExpectedOutputs : Pair < String ? , String > , expectedExitCode : Int = <NUM_LIT:0> , workDirectory : File ? = null , compilationClasspath : List < File > = emptyList ( ) )

{ <EOL> val javaExecutable = File ( File ( CompilerSystemProperties . JAVA_HOME . safeValue , "<STR_LIT>" ) , "<STR_LIT:java>" ) <EOL> val processBuilder = ProcessBuilder ( javaExecutable . absolutePath , "<STR_LIT>" , File ( PathUtil . kotlinPathsForDistDirectory . homePath , "<STR_LIT>" ) . absolutePath , ) <EOL> if ( workDirectory != null ) { <EOL> processBuilder . directory ( workDirectory ) <EOL> } <EOL> if ( compilationClasspath . isNotEmpty ( ) ) { <EOL> with ( processBuilder . command ( ) ) { <EOL> add ( "<STR_LIT>" ) <EOL> add ( compilationClasspath . joinToString ( File . pathSeparator ) { it . absolutePath } ) <EOL> } <EOL> } <EOL> val process = processBuilder . start ( ) <EOL> data class ExceptionContainer ( var value : Throwable ? = null ) <EOL> fun InputStream . captureStream ( ) : Triple < Thread , ExceptionContainer , ArrayList < String > > { <EOL> val out = ArrayList < String > ( ) <EOL> val exceptionContainer = ExceptionContainer ( ) <EOL> val thread = thread { <EOL> val promptRegex = Regex ( "<STR_LIT>" ) <EOL> try { <EOL> reader ( ) . forEachLine { rawLine -> <EOL> promptRegex . split ( rawLine ) . forEach { line -> <EOL> if ( line . isNotEmpty ( ) ) { <EOL> out . add ( line . trimEnd ( ) ) <EOL> } <EOL> } <EOL> } <EOL> } catch ( e : Throwable ) { <EOL> exceptionContainer . value = e <EOL> } <EOL> } <EOL> return Triple ( thread , exceptionContainer , out ) <EOL> } <EOL> val ( stdoutThread , stdoutException , processOut ) = process . inputStream . captureStream ( ) <EOL> val ( stderrThread , stderrException , processErr ) = process . errorStream . captureStream ( ) <EOL> val inputIter = inputsToExpectedOutputs . iterator ( ) <EOL> var stdinException : Throwable ? = null <EOL> val stdinThread = <EOL> thread { <EOL> try { <EOL> writeInputsToOutStream ( process . outputStream , inputIter ) <EOL> } catch ( e : Throwable ) { <EOL> stdinException = e <EOL> } <EOL> } <EOL> process . waitFor ( <NUM_LIT> , TimeUnit . MILLISECONDS ) <EOL> try { <EOL> if ( process . isAlive ) { <EOL> process . destroyForcibly ( ) <EOL> TestCase . fail ( "<STR_LIT>" ) <EOL> } <EOL> stdoutThread . join ( <NUM_LIT:100> ) <EOL> TestCase . assertFalse ( "<STR_LIT>" , stdoutThread . isAlive ) <EOL> TestCase . assertNull ( stdoutException . value ) <EOL> stderrThread . join ( <NUM_LIT:100> ) <EOL> TestCase . assertFalse ( "<STR_LIT>" , stderrThread . isAlive ) <EOL> TestCase . assertNull ( stderrException . value ) <EOL> TestCase . assertFalse ( "<STR_LIT>" , stdinThread . isAlive ) <EOL> TestCase . assertNull ( stdinException ) <EOL> assertOutputMatches ( inputsToExpectedOutputs , processOut ) <EOL> TestCase . assertEquals ( expectedExitCode , process . exitValue ( ) ) <EOL> TestCase . assertFalse ( inputIter . hasNext ( ) ) <EOL> } catch ( e : Throwable ) { <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> throw e <EOL> } <EOL> }


private fun writeInputsToOutStream ( dataOutStream : OutputStream , inputIter : Iterator < Pair < String ? , String > > )

{ <EOL> val writer = PrintWriter ( dataOutStream . writer ( ) , true ) <EOL> fun writeNextInput ( nextInput : String ) { <EOL> with ( writer ) { <EOL> println ( nextInput ) <EOL> } <EOL> } <EOL> while ( inputIter . hasNext ( ) ) { <EOL> val nextInput = inputIter . next ( ) . first ? : continue <EOL> writeNextInput ( nextInput ) <EOL> } <EOL> writeNextInput ( "<STR_LIT>" ) <EOL> writer . close ( ) <EOL> }


private fun assertOutputMatches ( inputsToExpectedOutputs : Array < out Pair < String ? , String > > , actualOut : List < String > )

{ <EOL> val inputsToExpectedOutputsIter = inputsToExpectedOutputs . iterator ( ) <EOL> val actualIter = actualOut . iterator ( ) <EOL> while ( true ) { <EOL> if ( inputsToExpectedOutputsIter . hasNext ( ) && ! actualIter . hasNext ( ) ) { <EOL> Assert . fail ( "<STR_LIT>" ) <EOL> } <EOL> if ( ! inputsToExpectedOutputsIter . hasNext ( ) || ! actualIter . hasNext ( ) ) break <EOL> var ( input , expectedPattern ) = inputsToExpectedOutputsIter . next ( ) <EOL> var actualLine = actualIter . next ( ) <EOL> while ( input != null ) { <EOL> if ( actualLine . startsWith ( input ) ) { <EOL> actualLine = actualLine . substring ( input . length ) <EOL> } else if ( expectedPattern . isEmpty ( ) && actualLine . isNotEmpty ( ) && inputsToExpectedOutputsIter . hasNext ( ) ) { <EOL> val nextInputToOutput = inputsToExpectedOutputsIter . next ( ) <EOL> expectedPattern = nextInputToOutput . second <EOL> input = nextInputToOutput . first <EOL> continue <EOL> } <EOL> break <EOL> } <EOL> if ( ! Regex ( expectedPattern ) . matches ( actualLine ) ) { <EOL> fail ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }


{ <EOL> runInteractive ( * replOutHeader , "<STR_LIT>" to "<STR_LIT:42>" , ) <EOL> }


{ <EOL> runInteractive ( * replOutHeader , "<STR_LIT>" to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , null to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT:42>" , ) <EOL> }


{ <EOL> runInteractive ( * replOutHeader , "<STR_LIT>" to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT>" , ) <EOL> }


{ <EOL> runInteractive ( * replOutHeader , "<STR_LIT>" to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT>" , "<STR_LIT>" to "<STR_LIT>" , ) <EOL> }