[Wasm] Major compiler and stdlib update
This commit is contained in:
@@ -232,7 +232,7 @@ val currentOsType = run {
|
||||
OsType(osName, osArch)
|
||||
}
|
||||
|
||||
val jsShellDirectory = "https://archive.mozilla.org/pub/firefox/nightly/2019/08/2019-08-11-09-56-40-mozilla-central"
|
||||
val jsShellDirectory = "https://archive.mozilla.org/pub/firefox/nightly/2020/06/2020-06-29-15-46-04-mozilla-central"
|
||||
val jsShellSuffix = when (currentOsType) {
|
||||
OsType(OsName.LINUX, OsArch.X86_32) -> "linux-i686"
|
||||
OsType(OsName.LINUX, OsArch.X86_64) -> "linux-x86_64"
|
||||
@@ -248,6 +248,7 @@ val downloadedTools = File(buildDir, "tools")
|
||||
val downloadJsShell by task<Download> {
|
||||
src(jsShellLocation)
|
||||
dest(File(downloadedTools, "jsshell-$jsShellSuffix.zip"))
|
||||
overwrite(false)
|
||||
}
|
||||
|
||||
val unzipJsShell by task<Copy> {
|
||||
@@ -257,13 +258,45 @@ val unzipJsShell by task<Copy> {
|
||||
into(unpackedDir)
|
||||
}
|
||||
|
||||
val v8osString = when (currentOsType) {
|
||||
OsType(OsName.LINUX, OsArch.X86_32) -> "linux32"
|
||||
OsType(OsName.LINUX, OsArch.X86_64) -> "linux64"
|
||||
OsType(OsName.MAC, OsArch.X86_64) -> "mac64"
|
||||
OsType(OsName.WINDOWS, OsArch.X86_32) -> "win32"
|
||||
OsType(OsName.WINDOWS, OsArch.X86_64) -> "win64"
|
||||
else -> error("unsupported os type $currentOsType")
|
||||
}
|
||||
|
||||
val v8edition = "rel" // rel or dbg
|
||||
val v8version = "8.8.104"
|
||||
val v8fileName = "v8-${v8osString}-${v8edition}-${v8version}"
|
||||
val v8url = "https://storage.googleapis.com/chromium-v8/official/canary/$v8fileName.zip"
|
||||
|
||||
val downloadV8 by task<Download> {
|
||||
src(v8url)
|
||||
dest(File(downloadedTools, "$v8fileName.zip"))
|
||||
overwrite(false)
|
||||
}
|
||||
|
||||
val unzipV8 by task<Copy> {
|
||||
dependsOn(downloadV8)
|
||||
from(zipTree(downloadV8.get().dest))
|
||||
val unpackedDir = File(downloadedTools, v8fileName)
|
||||
into(unpackedDir)
|
||||
}
|
||||
|
||||
projectTest("wasmTest", true) {
|
||||
dependsOn(unzipJsShell)
|
||||
dependsOn(unzipV8)
|
||||
include("org/jetbrains/kotlin/js/test/wasm/semantics/*")
|
||||
val jsShellExecutablePath = File(unzipJsShell.get().destinationDir, "js").absolutePath
|
||||
systemProperty("javascript.engine.path.SpiderMonkey", jsShellExecutablePath)
|
||||
val v8ExecutablePath = File(unzipV8.get().destinationDir, "d8").absolutePath
|
||||
println(v8ExecutablePath)
|
||||
|
||||
dependsOn(":kotlin-stdlib-js-ir:compileKotlinJs")
|
||||
systemProperty("javascript.engine.path.SpiderMonkey", jsShellExecutablePath)
|
||||
systemProperty("javascript.engine.path.V8", v8ExecutablePath)
|
||||
|
||||
dependsOn(":kotlin-stdlib-wasm:compileKotlinJs")
|
||||
systemProperty("kotlin.wasm.stdlib.path", "libraries/stdlib/wasm/build/classes/kotlin/js/main")
|
||||
|
||||
setUpBoxTests()
|
||||
|
||||
@@ -956,3 +956,14 @@ abstract class BasicBoxTest(
|
||||
else ScriptEngineV8Lazy(KotlinTestUtils.tmpDirForReusableFolder("j2v8_library_path").path)
|
||||
}
|
||||
}
|
||||
|
||||
fun KotlinTestWithEnvironment.createPsiFile(fileName: String): KtFile {
|
||||
val psiManager = PsiManager.getInstance(project)
|
||||
val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
||||
|
||||
val file = fileSystem.findFileByPath(fileName) ?: error("File not found: $fileName")
|
||||
|
||||
return psiManager.findFile(file) as KtFile
|
||||
}
|
||||
|
||||
fun KotlinTestWithEnvironment.createPsiFiles(fileNames: List<String>): List<KtFile> = fileNames.map(this::createPsiFile)
|
||||
@@ -9,18 +9,20 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.psi.PsiManager
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.phaser.toPhaseMap
|
||||
import org.jetbrains.kotlin.backend.wasm.compileWasm
|
||||
import org.jetbrains.kotlin.backend.wasm.wasmPhases
|
||||
import org.jetbrains.kotlin.checkers.parseLanguageVersionSettings
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.loadKlib
|
||||
import org.jetbrains.kotlin.js.config.JsConfig
|
||||
import org.jetbrains.kotlin.js.facade.TranslationUnit
|
||||
import org.jetbrains.kotlin.js.test.engines.ExternalTool
|
||||
import org.jetbrains.kotlin.js.test.engines.SpiderMonkeyEngine
|
||||
import org.jetbrains.kotlin.library.resolver.impl.KotlinLibraryResolverResultImpl
|
||||
import org.jetbrains.kotlin.library.resolver.impl.KotlinResolvedLibraryImpl
|
||||
@@ -28,10 +30,11 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.Directives
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import org.jetbrains.kotlin.test.TestFiles
|
||||
import org.jetbrains.kotlin.test.*
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
import java.lang.Boolean.getBoolean
|
||||
@@ -48,8 +51,13 @@ abstract class BasicWasmBoxTest(
|
||||
|
||||
private val spiderMonkey by lazy { SpiderMonkeyEngine() }
|
||||
|
||||
fun doTestWithCoroutinesPackageReplacement(filePath: String, coroutinesPackage: String) {
|
||||
TODO("TestWithCoroutinesPackageReplacement are not supported")
|
||||
}
|
||||
|
||||
fun doTest(filePath: String) {
|
||||
val file = File(filePath)
|
||||
|
||||
val outputDir = getOutputDir(file)
|
||||
val fileContent = KotlinTestUtils.doLoadFile(file)
|
||||
|
||||
@@ -58,21 +66,31 @@ abstract class BasicWasmBoxTest(
|
||||
val testPackage = testFactory.testPackage
|
||||
val outputFileBase = outputDir.absolutePath + "/" + getTestName(true)
|
||||
val outputWatFile = outputFileBase + ".wat"
|
||||
val outputWasmFile = outputFileBase + ".wasm"
|
||||
val outputJsFile = outputFileBase + ".js"
|
||||
|
||||
val languageVersionSettings = inputFiles.mapNotNull { it.languageVersionSettings }.firstOrNull()
|
||||
|
||||
val kotlinFiles = inputFiles.filter { it.fileName.endsWith(".kt") }
|
||||
val psiFiles = createPsiFiles(kotlinFiles.map { File(it.fileName).canonicalPath }.sorted())
|
||||
val config = createConfig()
|
||||
val config = createConfig(languageVersionSettings)
|
||||
translateFiles(
|
||||
file,
|
||||
psiFiles.map(TranslationUnit::SourceFile),
|
||||
File(outputWatFile),
|
||||
File(outputWasmFile),
|
||||
File(outputJsFile),
|
||||
config,
|
||||
testPackage,
|
||||
TEST_FUNCTION
|
||||
)
|
||||
|
||||
spiderMonkey.runFile(outputJsFile)
|
||||
ExternalTool(System.getProperty("javascript.engine.path.V8"))
|
||||
.run(
|
||||
"--experimental-wasm-typed-funcref",
|
||||
"--experimental-wasm-gc",
|
||||
outputJsFile
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,26 +104,32 @@ abstract class BasicWasmBoxTest(
|
||||
}
|
||||
|
||||
private fun translateFiles(
|
||||
testFile: File,
|
||||
units: List<TranslationUnit>,
|
||||
outputWatFile: File,
|
||||
outputWasmFile: File,
|
||||
outputJsFile: File,
|
||||
config: JsConfig,
|
||||
testPackage: String?,
|
||||
testFunction: String
|
||||
) {
|
||||
val filesToCompile = units.map { (it as TranslationUnit.SourceFile).file }
|
||||
val debugMode = getBoolean("kotlin.js.debugMode")
|
||||
val debugMode =getBoolean("kotlin.js.debugMode")
|
||||
|
||||
val phaseConfig = if (debugMode) {
|
||||
val allPhasesSet = wasmPhases.toPhaseMap().values.toSet()
|
||||
val dumpOutputDir = File(outputWatFile.parent, outputWatFile.nameWithoutExtension + "-irdump")
|
||||
println("\n ------ Dumping phases to file://$dumpOutputDir")
|
||||
println("\n ------ KT file://${testFile.absolutePath}")
|
||||
println("\n ------ WAT file://$outputWatFile")
|
||||
println("\n ------ WASM file://$outputWasmFile")
|
||||
println(" ------ JS file://$outputJsFile")
|
||||
PhaseConfig(
|
||||
wasmPhases,
|
||||
dumpToDirectory = dumpOutputDir.path,
|
||||
toDumpStateAfter = allPhasesSet,
|
||||
toValidateStateAfter = allPhasesSet,
|
||||
dumpOnlyFqName = null
|
||||
// toDumpStateAfter = allPhasesSet,
|
||||
// toValidateStateAfter = allPhasesSet,
|
||||
// dumpOnlyFqName = null
|
||||
)
|
||||
} else {
|
||||
PhaseConfig(wasmPhases)
|
||||
@@ -124,12 +148,12 @@ abstract class BasicWasmBoxTest(
|
||||
)
|
||||
|
||||
outputWatFile.write(compilerResult.wat)
|
||||
outputWasmFile.writeBytes(compilerResult.wasm)
|
||||
|
||||
val runtime = File("libraries/stdlib/wasm/runtime/runtime.js").readText()
|
||||
|
||||
val testRunner = """
|
||||
const wat = read(String.raw`${outputWatFile.absoluteFile}`);
|
||||
const wasmBinary = wasmTextToBinary(wat);
|
||||
const wasmBinary = read(String.raw`${outputWasmFile.absoluteFile}`, 'binary');
|
||||
const wasmModule = new WebAssembly.Module(wasmBinary);
|
||||
const wasmInstance = new WebAssembly.Instance(wasmModule, { runtime });
|
||||
|
||||
@@ -141,20 +165,11 @@ abstract class BasicWasmBoxTest(
|
||||
outputJsFile.write(runtime + "\n" + compilerResult.js + "\n" + testRunner)
|
||||
}
|
||||
|
||||
private fun createPsiFile(fileName: String): KtFile {
|
||||
val psiManager = PsiManager.getInstance(project)
|
||||
val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
||||
|
||||
val file = fileSystem.findFileByPath(fileName) ?: error("File not found: $fileName")
|
||||
|
||||
return psiManager.findFile(file) as KtFile
|
||||
}
|
||||
|
||||
private fun createPsiFiles(fileNames: List<String>): List<KtFile> = fileNames.map(this::createPsiFile)
|
||||
|
||||
private fun createConfig(): JsConfig {
|
||||
private fun createConfig(languageVersionSettings: LanguageVersionSettings?): JsConfig {
|
||||
val configuration = environment.configuration.copy()
|
||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, TEST_MODULE)
|
||||
configuration.languageVersionSettings = languageVersionSettings ?: LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE)
|
||||
return JsConfig(project, configuration, null, null)
|
||||
}
|
||||
|
||||
@@ -169,11 +184,13 @@ abstract class BasicWasmBoxTest(
|
||||
}
|
||||
}
|
||||
|
||||
val languageVersionSettings = parseLanguageVersionSettings(directives)
|
||||
|
||||
val temporaryFile = File(tmpDir, "WASM_TEST/$fileName")
|
||||
KotlinTestUtils.mkdirs(temporaryFile.parentFile)
|
||||
temporaryFile.writeText(text, Charsets.UTF_8)
|
||||
|
||||
return TestFile(temporaryFile.absolutePath)
|
||||
return TestFile(temporaryFile.absolutePath, languageVersionSettings)
|
||||
}
|
||||
|
||||
var testPackage: String? = null
|
||||
@@ -184,7 +201,7 @@ abstract class BasicWasmBoxTest(
|
||||
}
|
||||
}
|
||||
|
||||
private class TestFile(val fileName: String)
|
||||
private class TestFile(val fileName: String, val languageVersionSettings: LanguageVersionSettings?)
|
||||
|
||||
override fun createEnvironment() =
|
||||
KotlinCoreEnvironment.createForTests(testRootDisposable, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES)
|
||||
|
||||
@@ -39,6 +39,6 @@ class SpiderMonkeyEngine(
|
||||
private val jsShell = ExternalTool(jsShellPath)
|
||||
|
||||
fun runFile(file: String) {
|
||||
jsShell.run(file)
|
||||
jsShell.run("--wasm-gc", file)
|
||||
}
|
||||
}
|
||||
Generated
+5
@@ -10655,6 +10655,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/functions/recursiveIncrementCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParameterAsUpperBound.kt")
|
||||
public void testTypeParameterAsUpperBound() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/typeParameterAsUpperBound.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParametersInLocalFunction.kt")
|
||||
public void testTypeParametersInLocalFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/typeParametersInLocalFunction.kt");
|
||||
|
||||
Generated
+5
@@ -10655,6 +10655,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/functions/recursiveIncrementCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParameterAsUpperBound.kt")
|
||||
public void testTypeParameterAsUpperBound() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/typeParameterAsUpperBound.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParametersInLocalFunction.kt")
|
||||
public void testTypeParametersInLocalFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/typeParametersInLocalFunction.kt");
|
||||
|
||||
+5
@@ -10655,6 +10655,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/functions/recursiveIncrementCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParameterAsUpperBound.kt")
|
||||
public void testTypeParameterAsUpperBound() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/typeParameterAsUpperBound.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeParametersInLocalFunction.kt")
|
||||
public void testTypeParametersInLocalFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/typeParametersInLocalFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user