Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
7dc3be3b
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 搜索 >>
提交
7dc3be3b
编写于
3月 18, 2021
作者:
D
Dmitriy Novozhilov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIR2IR] Replace star projections with upper bounds for SAM conversion types
上级
50f2666e
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
70 addition
and
20 deletion
+70
-20
compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt
...otlin/fir/backend/generators/CallAndReferenceGenerator.kt
+20
-1
compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java
...test/runners/codegen/FirBlackBoxCodegenTestGenerated.java
+6
-0
compiler/testData/codegen/box/invokedynamic/sam/specializedGenerics/genericWithStarProjection.kt
...amic/sam/specializedGenerics/genericWithStarProjection.kt
+0
-1
compiler/testData/codegen/box/sam/samConversionToJavaWildcard.kt
...r/testData/codegen/box/sam/samConversionToJavaWildcard.kt
+26
-0
compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt
...a/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt
+0
-7
compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.txt
...Data/ir/irText/expressions/sam/samByProjectedType.fir.txt
+0
-11
compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt
.../testData/ir/irText/expressions/sam/samByProjectedType.kt
+1
-0
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java
...in/test/runners/codegen/BlackBoxCodegenTestGenerated.java
+6
-0
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java
.../test/runners/codegen/IrBlackBoxCodegenTestGenerated.java
+6
-0
compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
...brains/kotlin/codegen/LightAnalysisModeTestGenerated.java
+5
-0
未找到文件。
compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt
浏览文件 @
7dc3be3b
...
...
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import
org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents
import
org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType
import
org.jetbrains.kotlin.fir.resolve.inference.isKMutableProperty
import
org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
import
org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import
org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
import
org.jetbrains.kotlin.fir.resolve.toSymbol
...
...
@@ -622,7 +623,8 @@ class CallAndReferenceGenerator(
return
this
}
val
samFirType
=
parameter
.
returnTypeRef
.
coneTypeSafe
<
ConeKotlinType
>()
?.
let
{
val
substituted
=
substitutor
.
substituteOrSelf
(
it
)
var
substituted
=
substitutor
.
substituteOrSelf
(
it
)
substituted
=
starProjectionApproximator
.
substituteOrSelf
(
substituted
)
if
(
substituted
is
ConeRawType
)
substituted
.
lowerBound
else
substituted
}
var
samType
=
samFirType
?.
toIrType
(
ConversionTypeContext
.
WITH_INVARIANT
)
?:
createErrorType
()
...
...
@@ -634,6 +636,23 @@ class CallAndReferenceGenerator(
return
IrTypeOperatorCallImpl
(
this
.
startOffset
,
this
.
endOffset
,
samType
,
IrTypeOperator
.
SAM_CONVERSION
,
samType
,
this
)
}
private
val
starProjectionApproximator
=
object
:
AbstractConeSubstitutor
()
{
override
fun
substituteType
(
type
:
ConeKotlinType
):
ConeKotlinType
?
{
if
(
type
!
is
ConeClassLikeType
||
type
.
typeArguments
.
none
{
it
==
ConeStarProjection
})
return
null
val
fir
=
type
.
lookupTag
.
toSymbol
(
session
)
?.
fir
as
?
FirTypeParameterRefsOwner
?:
return
null
val
typeParameters
=
fir
.
typeParameters
.
map
{
it
.
symbol
.
fir
}
if
(
typeParameters
.
size
!=
type
.
typeArguments
.
size
)
return
null
val
newTypeArguments
=
typeParameters
.
zip
(
type
.
typeArguments
).
map
{
(
parameter
,
argument
)
->
if
(
argument
==
ConeStarProjection
){
parameter
.
bounds
.
first
().
coneType
}
else
{
argument
}
}
return
type
.
withArguments
(
newTypeArguments
.
toTypedArray
())
}
}
private
fun
needSamConversion
(
argument
:
FirExpression
,
parameter
:
FirValueParameter
):
Boolean
{
// If the type of the argument is already an explicitly subtype of the type of the parameter, we don't need SAM conversion.
if
(
argument
.
typeRef
!
is
FirResolvedTypeRef
||
...
...
compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java
浏览文件 @
7dc3be3b
...
...
@@ -37440,6 +37440,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/sam/samConstructorGenericSignature.kt");
}
@Test
@TestMetadata("samConversionToJavaWildcard.kt")
public void testSamConversionToJavaWildcard() throws Exception {
runTest("compiler/testData/codegen/box/sam/samConversionToJavaWildcard.kt");
}
@Test
@TestMetadata("smartCastSamConversion.kt")
public void testSmartCastSamConversion() throws Exception {
compiler/testData/codegen/box/invokedynamic/sam/specializedGenerics/genericWithStarProjection.kt
浏览文件 @
7dc3be3b
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun
interface
Cmp
<
T
>
{
...
...
compiler/testData/codegen/box/sam/samConversionToJavaWildcard.kt
0 → 100644
浏览文件 @
7dc3be3b
// TARGET_BACKEND: JVM
// FULL_JDK
// FILE: ConventionMapping.java
import
java.util.concurrent.Callable;
public
class
ConventionMapping
{
MappedProperty
map
(
String
propertyName
,
Callable
<
?
>
value
)
{
return
new
MappedProperty
();
}
public
static
class
MappedProperty
{
}
}
// FILE: FileCollection.java
public
class
FileCollection
{}
// FILE: test.kt
fun
test
(
mapping
:
ConventionMapping
,
fn
:
()
->
FileCollection
)
{
mapping
.
map
(
"classpath"
,
fn
)
}
fun
box
():
String
=
"OK"
compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt
已删除
100644 → 0
浏览文件 @
50f2666e
fun test1() {
bar(j = local fun <anonymous>(x: Any): @FlexibleNullability Any? {
return x
}
/*-> @FlexibleNullability J<*>? */)
}
compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.txt
已删除
100644 → 0
浏览文件 @
50f2666e
FILE fqName:<root> fileName:/samByProjectedType.kt
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public open fun bar (j: @[FlexibleNullability] <root>.J<*>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
j: TYPE_OP type=@[FlexibleNullability] <root>.J<*>? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] <root>.J<*>?
FUN_EXPR type=kotlin.Function1<kotlin.Any, @[FlexibleNullability] kotlin.Any?> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.Any) returnType:@[FlexibleNullability] kotlin.Any?
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (x: kotlin.Any): @[FlexibleNullability] kotlin.Any? declared in <root>.test1'
GET_VAR 'x: kotlin.Any declared in <root>.test1.<anonymous>' type=kotlin.Any origin=null
compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt
浏览文件 @
7dc3be3b
// FIR_IDENTICAL
// FILE: samByProjectedType.kt
fun
test1
()
{
H
.
bar
{
x
:
Any
->
x
}
...
...
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java
浏览文件 @
7dc3be3b
...
...
@@ -37440,6 +37440,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/sam/samConstructorGenericSignature.kt");
}
@Test
@TestMetadata("samConversionToJavaWildcard.kt")
public void testSamConversionToJavaWildcard() throws Exception {
runTest("compiler/testData/codegen/box/sam/samConversionToJavaWildcard.kt");
}
@Test
@TestMetadata("smartCastSamConversion.kt")
public void testSmartCastSamConversion() throws Exception {
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java
浏览文件 @
7dc3be3b
...
...
@@ -37440,6 +37440,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/sam/samConstructorGenericSignature.kt");
}
@Test
@TestMetadata("samConversionToJavaWildcard.kt")
public void testSamConversionToJavaWildcard() throws Exception {
runTest("compiler/testData/codegen/box/sam/samConversionToJavaWildcard.kt");
}
@Test
@TestMetadata("smartCastSamConversion.kt")
public void testSmartCastSamConversion() throws Exception {
compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
浏览文件 @
7dc3be3b
...
...
@@ -29842,6 +29842,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/sam/samConstructorGenericSignature.kt");
}
@TestMetadata("samConversionToJavaWildcard.kt")
public void testSamConversionToJavaWildcard() throws Exception {
runTest("compiler/testData/codegen/box/sam/samConversionToJavaWildcard.kt");
}
@TestMetadata("smartCastSamConversion.kt")
public void testSmartCastSamConversion() throws Exception {
runTest("compiler/testData/codegen/box/sam/smartCastSamConversion.kt");
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录