Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
b343d05e
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b343d05e
编写于
9月 23, 2020
作者:
D
Dmitriy Novozhilov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIR] Implement JvmTypeMapper based on cone types
上级
a28d0e0b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
134 addition
and
0 deletion
+134
-0
compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/StandardClassIds.kt
.../src/org/jetbrains/kotlin/fir/symbols/StandardClassIds.kt
+9
-0
compiler/fir/fir2ir/jvm-backend/build.gradle.kts
compiler/fir/fir2ir/jvm-backend/build.gradle.kts
+1
-0
compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt
.../org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt
+118
-0
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt
.../jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt
+6
-0
未找到文件。
compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/StandardClassIds.kt
浏览文件 @
b343d05e
...
...
@@ -5,6 +5,7 @@
package
org.jetbrains.kotlin.fir.symbols
import
org.jetbrains.kotlin.builtins.StandardNames
import
org.jetbrains.kotlin.name.ClassId
import
org.jetbrains.kotlin.name.FqName
import
org.jetbrains.kotlin.name.Name
...
...
@@ -74,6 +75,14 @@ object StandardClassIds {
val
unsignedTypes
=
listOf
(
UByte
,
UShort
,
UInt
,
ULong
)
val
unsignedArrayTypeByElementType
=
unsignedTypes
.
associate
{
id
->
id
to
id
.
shortClassName
.
primitiveArrayId
()
}
val
elementTypeByUnsignedArrayType
=
unsignedArrayTypeByElementType
.
inverseMap
()
val
Continuation
=
ClassId
(
StandardNames
.
COROUTINES_PACKAGE_FQ_NAME_RELEASE
,
StandardNames
.
CONTINUATION_INTERFACE_FQ_NAME_RELEASE
.
shortName
())
@Suppress
(
"FunctionName"
)
fun
FunctionN
(
n
:
Int
):
ClassId
{
return
"Function$n"
.
baseId
()
}
}
private
fun
<
K
,
V
>
Map
<
K
,
V
>.
inverseMap
()
=
entries
.
associate
{
(
k
,
v
)
->
v
to
k
}
compiler/fir/fir2ir/jvm-backend/build.gradle.kts
浏览文件 @
b343d05e
...
...
@@ -5,6 +5,7 @@ plugins {
dependencies
{
compileOnly
(
project
(
":core:descriptors"
))
compileOnly
(
project
(
":core:compiler.backend.common.jvm"
))
compileOnly
(
project
(
":compiler:fir:cones"
))
compileOnly
(
project
(
":compiler:fir:resolve"
))
compileOnly
(
project
(
":compiler:fir:jvm"
))
...
...
compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt
0 → 100644
浏览文件 @
b343d05e
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package
org.jetbrains.kotlin.fir.backend.jvm
import
org.jetbrains.kotlin.descriptors.ClassKind
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.FirSessionComponent
import
org.jetbrains.kotlin.fir.resolve.defaultType
import
org.jetbrains.kotlin.fir.resolve.firSymbolProvider
import
org.jetbrains.kotlin.fir.resolve.inference.isKClassType
import
org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
import
org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import
org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import
org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import
org.jetbrains.kotlin.fir.symbols.StandardClassIds
import
org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import
org.jetbrains.kotlin.fir.typeContext
import
org.jetbrains.kotlin.fir.types.*
import
org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import
org.jetbrains.kotlin.load.kotlin.JvmDescriptorTypeWriter
import
org.jetbrains.kotlin.load.kotlin.TypeMappingMode
import
org.jetbrains.kotlin.types.AbstractTypeMapper
import
org.jetbrains.kotlin.types.TypeMappingContext
import
org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
import
org.jetbrains.kotlin.types.TypeSystemCommonBackendContextForTypeMapping
import
org.jetbrains.kotlin.types.model.KotlinTypeMarker
import
org.jetbrains.kotlin.types.model.SimpleTypeMarker
import
org.jetbrains.kotlin.types.model.TypeConstructorMarker
import
org.jetbrains.kotlin.types.model.TypeParameterMarker
import
org.jetbrains.org.objectweb.asm.Type
class
FirJvmTypeMapper
(
val
session
:
FirSession
)
:
TypeMappingContext
<
JvmDescriptorTypeWriter
<
Type
>>,
FirSessionComponent
{
override
val
typeContext
=
ConeTypeSystemCommonBackendContextForTypeMapping
(
session
.
typeContext
)
fun
mapType
(
type
:
ConeKotlinType
,
mode
:
TypeMappingMode
=
TypeMappingMode
.
DEFAULT
):
Type
{
return
AbstractTypeMapper
.
mapType
(
this
,
type
,
mode
)
}
override
fun
getClassInternalName
(
typeConstructor
:
TypeConstructorMarker
):
String
{
require
(
typeConstructor
is
ConeClassLikeLookupTag
)
return
typeConstructor
.
classId
.
asString
().
replace
(
"."
,
"$"
).
replace
(
"/"
,
"."
)
}
override
fun
JvmDescriptorTypeWriter
<
Type
>.
writeGenericType
(
type
:
SimpleTypeMarker
,
asmType
:
Type
,
mode
:
TypeMappingMode
)
{
error
(
"Should not be called"
)
}
}
val
FirSession
.
jvmTypeMapper
:
FirJvmTypeMapper
by
FirSession
.
sessionComponentAccessor
()
class
ConeTypeSystemCommonBackendContextForTypeMapping
(
val
context
:
ConeTypeContext
)
:
TypeSystemCommonBackendContext
by
context
,
TypeSystemCommonBackendContextForTypeMapping
{
private
val
symbolProvider
=
context
.
session
.
firSymbolProvider
override
fun
TypeConstructorMarker
.
isTypeParameter
():
Boolean
{
return
this
is
ConeTypeParameterLookupTag
}
override
fun
TypeConstructorMarker
.
defaultType
():
ConeSimpleKotlinType
{
require
(
this
is
ConeClassifierLookupTag
)
return
when
(
this
)
{
is
ConeTypeParameterLookupTag
->
ConeTypeParameterTypeImpl
(
this
,
isNullable
=
false
)
is
ConeClassLikeLookupTag
->
{
val
symbol
=
symbolProvider
.
getClassLikeSymbolByFqName
(
classId
)
as
?
FirRegularClassSymbol
?:
error
(
"Class for $this not found"
)
symbol
.
fir
.
defaultType
()
}
else
->
error
(
"Unsupported type constructor: $this"
)
}
}
override
fun
SimpleTypeMarker
.
isSuspendFunction
():
Boolean
{
require
(
this
is
ConeSimpleKotlinType
)
return
isSuspendFunctionType
(
context
.
session
)
}
override
fun
SimpleTypeMarker
.
isKClass
():
Boolean
{
require
(
this
is
ConeSimpleKotlinType
)
return
isKClassType
()
}
override
fun
KotlinTypeMarker
.
isRawType
():
Boolean
{
return
this
is
ConeRawType
}
override
fun
TypeConstructorMarker
.
typeWithArguments
(
arguments
:
List
<
KotlinTypeMarker
>):
ConeSimpleKotlinType
{
arguments
.
forEach
{
require
(
it
is
ConeKotlinType
)
}
@Suppress
(
"UNCHECKED_CAST"
)
return
defaultType
().
withArguments
((
arguments
as
List
<
ConeKotlinType
>).
toTypedArray
())
}
override
fun
TypeParameterMarker
.
representativeUpperBound
():
ConeKotlinType
{
require
(
this
is
ConeTypeParameterLookupTag
)
val
bounds
=
this
.
typeParameterSymbol
.
fir
.
bounds
.
map
{
it
.
coneType
}
return
bounds
.
firstOrNull
{
val
classId
=
it
.
classId
?:
return
@firstOrNull
false
val
classSymbol
=
symbolProvider
.
getClassLikeSymbolByFqName
(
classId
)
as
?
FirRegularClassSymbol
?:
return
@firstOrNull
false
val
kind
=
classSymbol
.
fir
.
classKind
kind
!=
ClassKind
.
INTERFACE
&&
kind
!=
ClassKind
.
ANNOTATION_CLASS
}
?:
bounds
.
first
()
}
override
fun
continuationTypeConstructor
():
ConeClassLikeLookupTag
{
return
symbolProvider
.
getClassLikeSymbolByFqName
(
StandardClassIds
.
Continuation
)
?.
toLookupTag
()
?:
error
(
"Continuation class not found"
)
}
override
fun
functionNTypeConstructor
(
n
:
Int
):
TypeConstructorMarker
{
return
symbolProvider
.
getClassLikeSymbolByFqName
(
StandardClassIds
.
FunctionN
(
n
))
?.
toLookupTag
()
?:
error
(
"Function$n class not found"
)
}
}
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt
浏览文件 @
b343d05e
...
...
@@ -17,6 +17,8 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import
org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
import
org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import
org.jetbrains.kotlin.fir.typeContext
import
org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import
org.jetbrains.kotlin.fir.symbols.StandardClassIds
import
org.jetbrains.kotlin.fir.types.*
import
org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import
org.jetbrains.kotlin.name.ClassId
...
...
@@ -121,6 +123,10 @@ fun ConeKotlinType.findContributedInvokeSymbol(
return
if
(
overriddenInvoke
!=
null
)
declaredInvoke
else
null
}
fun
ConeKotlinType
.
isKClassType
():
Boolean
{
return
classId
==
StandardClassIds
.
KClass
}
fun
ConeKotlinType
.
receiverType
(
expectedTypeRef
:
FirTypeRef
?,
session
:
FirSession
):
ConeKotlinType
?
{
if
(
isBuiltinFunctionalType
(
session
)
&&
isExtensionFunctionType
(
session
))
{
return
(
this
.
fullyExpandedType
(
session
).
typeArguments
.
first
()
as
ConeKotlinTypeProjection
).
type
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录