Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
0b0e2c3a
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,发现更多精彩内容 >>
提交
0b0e2c3a
编写于
12月 04, 2020
作者:
D
Dmitriy Novozhilov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD] Create real helpers files for coroutines checkers
上级
710c5ec8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
136 addition
and
0 deletion
+136
-0
compiler/testData/diagnostics/helpers/coroutines/CoroutineHelpers.kt
...stData/diagnostics/helpers/coroutines/CoroutineHelpers.kt
+49
-0
compiler/testData/diagnostics/helpers/coroutines/StateMachineChecker.kt
...ata/diagnostics/helpers/coroutines/StateMachineChecker.kt
+52
-0
compiler/testData/diagnostics/helpers/coroutines/TailCallOptimizationChecker.kt
...nostics/helpers/coroutines/TailCallOptimizationChecker.kt
+35
-0
未找到文件。
compiler/testData/diagnostics/helpers/coroutines/CoroutineHelpers.kt
0 → 100644
浏览文件 @
0b0e2c3a
package
helpers
import
kotlin.coroutines.*
import
kotlin.coroutines.intrinsics.*
import
kotlin.coroutines.jvm.internal.*
fun
<
T
>
handleResultContinuation
(
x
:
(
T
)
->
Unit
):
Continuation
<
T
>
=
object
:
Continuation
<
T
>
{
override
val
context
=
EmptyCoroutineContext
override
fun
resumeWith
(
result
:
Result
<
T
>)
{
x
(
result
.
getOrThrow
())
}
}
fun
handleExceptionContinuation
(
x
:
(
Throwable
)
->
Unit
):
Continuation
<
Any
?
>
=
object
:
Continuation
<
Any
?
>
{
override
val
context
=
EmptyCoroutineContext
override
fun
resumeWith
(
result
:
Result
<
Any
?
>)
{
result
.
exceptionOrNull
()
?.
let
(
x
)
}
}
open
class
EmptyContinuation
(
override
val
context
:
CoroutineContext
=
EmptyCoroutineContext
)
:
Continuation
<
Any
?
>
{
companion
object
:
EmptyContinuation
()
override
fun
resumeWith
(
result
:
Result
<
Any
?
>)
{
result
.
getOrThrow
()
}
}
class
ResultContinuation
:
Continuation
<
Any
?
>
{
override
val
context
=
EmptyCoroutineContext
override
fun
resumeWith
(
result
:
Result
<
Any
?
>)
{
this
.
result
=
result
.
getOrThrow
()
}
var
result
:
Any
?
=
null
}
abstract
class
ContinuationAdapter
<
in
T
>
:
Continuation
<
T
>
{
override
val
context
:
CoroutineContext
=
EmptyCoroutineContext
override
fun
resumeWith
(
result
:
Result
<
T
>)
{
if
(
result
.
isSuccess
)
{
resume
(
result
.
getOrThrow
())
}
else
{
resumeWithException
(
result
.
exceptionOrNull
()
!!
)
}
}
abstract
fun
resumeWithException
(
exception
:
Throwable
)
abstract
fun
resume
(
value
:
T
)
}
compiler/testData/diagnostics/helpers/coroutines/StateMachineChecker.kt
0 → 100644
浏览文件 @
0b0e2c3a
package
helpers
import
kotlin.coroutines.*
import
kotlin.coroutines.intrinsics.*
import
kotlin.coroutines.jvm.internal.*
class
StateMachineCheckerClass
{
private
var
counter
=
0
var
finished
=
false
var
proceed
:
()
->
Unit
=
{}
fun
reset
()
{
counter
=
0
finished
=
false
proceed
=
{}
}
suspend
fun
suspendHere
()
=
suspendCoroutine
<
Unit
>
{
c
->
counter
++
proceed
=
{
c
.
resume
(
Unit
)
}
}
fun
check
(
numberOfSuspensions
:
Int
,
checkFinished
:
Boolean
=
true
)
{
for
(
i
in
1
..
numberOfSuspensions
)
{
if
(
counter
!=
i
)
error
(
"Wrong state-machine generated: suspendHere should be called exactly once in one state. Expected "
+
i
+
", got "
+
counter
)
proceed
()
}
if
(
counter
!=
numberOfSuspensions
)
error
(
"Wrong state-machine generated: wrong number of overall suspensions. Expected "
+
numberOfSuspensions
+
", got "
+
counter
)
if
(
finished
)
error
(
"Wrong state-machine generated: it is finished early"
)
proceed
()
if
(
checkFinished
&&
!
finished
)
error
(
"Wrong state-machine generated: it is not finished yet"
)
}
}
val
StateMachineChecker
=
StateMachineCheckerClass
()
object
CheckStateMachineContinuation
:
ContinuationAdapter
<
Unit
>()
{
override
val
context
:
CoroutineContext
get
()
=
EmptyCoroutineContext
override
fun
resume
(
value
:
Unit
)
{
StateMachineChecker
.
proceed
=
{
StateMachineChecker
.
finished
=
true
}
}
override
fun
resumeWithException
(
exception
:
Throwable
)
{
throw
exception
}
}
compiler/testData/diagnostics/helpers/coroutines/TailCallOptimizationChecker.kt
0 → 100644
浏览文件 @
0b0e2c3a
package
helpers
import
kotlin.coroutines.*
import
kotlin.coroutines.intrinsics.*
import
kotlin.coroutines.jvm.internal.*
class
TailCallOptimizationCheckerClass
{
private
val
stackTrace
=
arrayListOf
<
StackTraceElement
?>()
suspend
fun
saveStackTrace
()
=
suspendCoroutineUninterceptedOrReturn
<
Unit
>
{
saveStackTrace
(
it
)
}
fun
saveStackTrace
(
c
:
Continuation
<
*
>)
{
if
(
c
!
is
CoroutineStackFrame
)
error
(
"Continuation "
+
c
+
" is not subtype of CoroutineStackFrame"
)
stackTrace
.
clear
()
var
csf
:
CoroutineStackFrame
?
=
c
while
(
csf
!=
null
)
{
stackTrace
.
add
(
csf
.
getStackTraceElement
())
csf
=
csf
.
callerFrame
}
}
fun
checkNoStateMachineIn
(
method
:
String
)
{
stackTrace
.
find
{
it
?.
methodName
?.
startsWith
(
method
)
==
true
}
?.
let
{
error
(
"tail-call optimization miss: method at "
+
it
+
" has state-machine "
+
stackTrace
.
joinToString
(
separator
=
"\n"
))
}
}
fun
checkStateMachineIn
(
method
:
String
)
{
stackTrace
.
find
{
it
?.
methodName
?.
startsWith
(
method
)
==
true
}
?:
error
(
"tail-call optimization hit: method "
+
method
+
" has no state-machine "
+
stackTrace
.
joinToString
(
separator
=
"\n"
))
}
}
val
TailCallOptimizationChecker
=
TailCallOptimizationCheckerClass
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录