From 25a5025c58f6fd72e50d9672f93aa6feea340e89 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 17 Jun 2013 19:06:24 +0400 Subject: [PATCH] Built-ins can now be initialized on demand --- .../cli/jvm/compiler/JetCoreEnvironment.java | 2 - .../jet/lang/types/lang/KotlinBuiltIns.java | 8 ++-- idea/src/META-INF/plugin.xml | 3 -- .../jet/plugin/BuiltInsInitializer.java | 40 ------------------- .../references/BuiltInsReferenceResolver.java | 7 +--- j2k/src/org/jetbrains/jet/j2k/Converter.java | 2 - 6 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/BuiltInsInitializer.java diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java index 0ccb9b9b1de..ab57dfb4a0f 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java @@ -124,8 +124,6 @@ public class JetCoreEnvironment { } JetScriptDefinitionProvider.getInstance(project).addScriptDefinitions(configuration.getList(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY)); - - KotlinBuiltIns.initialize(); } public CompilerConfiguration getConfiguration() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index 906a3dae8c1..3301f5df3e8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -72,9 +72,7 @@ public class KotlinBuiltIns { private static volatile boolean initializing; private static Throwable initializationFailed; - // This method must be called at least once per application run, on any project - // before any type checking is run - public static synchronized void initialize() { + private static synchronized void initialize() { if (instance == null) { if (initializationFailed != null) { throw new RuntimeException( @@ -98,7 +96,7 @@ public class KotlinBuiltIns { } } - @NotNull // This asserts that initialize() is called before any resolution happens + @NotNull public static KotlinBuiltIns getInstance() { if (initializing) { synchronized (KotlinBuiltIns.class) { @@ -107,7 +105,7 @@ public class KotlinBuiltIns { } } if (instance == null) { - throw new IllegalStateException("Initialize standard library first"); + initialize(); } return instance; } diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index eb217c87984..618bf01be3d 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -13,9 +13,6 @@ com.intellij.copyright - - org.jetbrains.jet.plugin.BuiltInsInitializer - org.jetbrains.jet.plugin.compiler.JetCompilerManager diff --git a/idea/src/org/jetbrains/jet/plugin/BuiltInsInitializer.java b/idea/src/org/jetbrains/jet/plugin/BuiltInsInitializer.java deleted file mode 100644 index 736d0d3341c..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/BuiltInsInitializer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin; - -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; - -/** - * This project component initializes KotlinBuiltIns so that throwing a ProcessCanceledException while - * loading PSI from declaration files is prevented. - */ -public class BuiltInsInitializer { - public BuiltInsInitializer(@NotNull final Project project) { - ProgressManager.getInstance().executeNonCancelableSection(new Runnable() { - @Override - public void run() { - // MULTI_THREADED is important not only because of threading as such: since built-ins rely on a project, - // if they are not fully initialized when a project is closed, - // they will be referencing invalid PSI upon a next request - KotlinBuiltIns.initialize(); - } - }); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/references/BuiltInsReferenceResolver.java b/idea/src/org/jetbrains/jet/plugin/references/BuiltInsReferenceResolver.java index 2cad0a1b1ab..47bfc32a96c 100644 --- a/idea/src/org/jetbrains/jet/plugin/references/BuiltInsReferenceResolver.java +++ b/idea/src/org/jetbrains/jet/plugin/references/BuiltInsReferenceResolver.java @@ -46,7 +46,6 @@ import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; -import org.jetbrains.jet.plugin.BuiltInsInitializer; import org.jetbrains.jet.renderer.DescriptorRenderer; import java.net.URL; @@ -59,11 +58,7 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent { private BindingContext bindingContext = null; private Set builtInsSources = Sets.newHashSet(); - public BuiltInsReferenceResolver( - Project project, - // This parameter is needed to initialize built-ins before this component - BuiltInsInitializer ignored - ) { + public BuiltInsReferenceResolver(Project project) { super(project); } diff --git a/j2k/src/org/jetbrains/jet/j2k/Converter.java b/j2k/src/org/jetbrains/jet/j2k/Converter.java index 5e5b7ea357e..e47ceb6552a 100644 --- a/j2k/src/org/jetbrains/jet/j2k/Converter.java +++ b/j2k/src/org/jetbrains/jet/j2k/Converter.java @@ -29,7 +29,6 @@ import org.jetbrains.jet.j2k.util.AstUtil; import org.jetbrains.jet.j2k.visitors.*; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.expressions.OperatorConventions; -import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import java.util.*; @@ -63,7 +62,6 @@ public class Converter { public Converter(@NotNull Project project) { this.project = project; - KotlinBuiltIns.initialize(); } @NotNull