Introduced lazy type and some related optimizations.
This commit is contained in:
+1
-1
@@ -205,7 +205,7 @@ public class TypeDeserializer {
|
||||
return debugName;
|
||||
}
|
||||
|
||||
private class DeserializedType extends AbstractJetType {
|
||||
private class DeserializedType extends AbstractJetType implements LazyType {
|
||||
private final ProtoBuf.Type typeProto;
|
||||
private final NotNullLazyValue<TypeConstructor> constructor;
|
||||
private final List<TypeProjection> arguments;
|
||||
|
||||
@@ -23,14 +23,14 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.util.ReenteringLazyValueComputationException;
|
||||
import org.jetbrains.jet.util.Box;
|
||||
import org.jetbrains.jet.util.ReenteringLazyValueComputationException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DEFERRED_TYPE;
|
||||
|
||||
public class DeferredType implements JetType {
|
||||
public class DeferredType implements LazyType {
|
||||
|
||||
public static DeferredType create(BindingTrace trace, NotNullLazyValue<JetType> lazyValue) {
|
||||
DeferredType deferredType = new DeferredType(lazyValue);
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import org.jetbrains.jet.lang.types.JetTypeImpl
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor
|
||||
import org.jetbrains.jet.lang.types.TypeProjection
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.types.LazyType
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.types.LazyJavaType
|
||||
import org.jetbrains.jet.utils.valuesToMap
|
||||
import org.jetbrains.jet.utils.keysToMap
|
||||
import org.jetbrains.jet.utils.keysToMapExceptNulls
|
||||
@@ -151,7 +151,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
|
||||
val arguments = listOf(TypeProjectionImpl(`type`))
|
||||
|
||||
val javaClassObjectType = object : LazyType(c.storageManager) {
|
||||
val javaClassObjectType = object : LazyJavaType(c.storageManager) {
|
||||
override fun computeTypeConstructor() = jlClass.getTypeConstructor()
|
||||
override fun computeArguments() = arguments
|
||||
override fun computeMemberScope() = jlClass.getMemberScope(arguments)
|
||||
|
||||
+2
-1
@@ -24,8 +24,9 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.types.AbstractJetType
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.util.inn
|
||||
import org.jetbrains.jet.lang.types.LazyType
|
||||
|
||||
abstract class LazyType(storageManager: StorageManager) : AbstractJetType() {
|
||||
abstract class LazyJavaType(storageManager: StorageManager) : AbstractJetType(), LazyType {
|
||||
|
||||
private val _typeConstructor = storageManager.createLazyValue {computeTypeConstructor()}
|
||||
override fun getConstructor(): TypeConstructor = _typeConstructor()
|
||||
+1
-1
@@ -88,7 +88,7 @@ class LazyJavaTypeResolver(
|
||||
private inner class LazyJavaClassifierType(
|
||||
private val javaType: JavaClassifierType,
|
||||
private val attr: JavaTypeAttributes
|
||||
) : LazyType(c.storageManager) {
|
||||
) : LazyJavaType(c.storageManager) {
|
||||
|
||||
private val classifier = c.storageManager.createNullableLazyValue { javaType.getClassifier() }
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.lang.types;
|
||||
|
||||
public interface LazyType extends JetType {
|
||||
}
|
||||
@@ -116,10 +116,6 @@ public class TypeUtils {
|
||||
|
||||
@NotNull
|
||||
public static JetType makeNullableAsSpecified(@NotNull JetType type, boolean nullable) {
|
||||
if (type.isNullable() == nullable) {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Wrapping serves two purposes here
|
||||
// 1. It's requires less memory than copying with a changed nullability flag: a copy has many fields, while a wrapper has only one
|
||||
// 2. It preserves laziness of types
|
||||
@@ -129,6 +125,11 @@ public class TypeUtils {
|
||||
return makeNullableAsSpecified(((AbstractTypeWithKnownNullability) type).delegate, nullable);
|
||||
}
|
||||
|
||||
// checking to preserve laziness
|
||||
if (!(type instanceof LazyType) && type.isNullable() == nullable) {
|
||||
return type;
|
||||
}
|
||||
|
||||
return nullable ? new NullableType(type) : new NotNullType(type);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,9 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
if (type == CANT_INFER_LAMBDA_PARAM_TYPE || type == CANT_INFER_TYPE_PARAMETER || type == DONT_CARE) {
|
||||
return "???";
|
||||
}
|
||||
if (type instanceof LazyType && debugMode) {
|
||||
return type.toString();
|
||||
}
|
||||
if (type.isError()) {
|
||||
return renderDefaultType(type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user