Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
12a04c7d
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
12a04c7d
编写于
4月 30, 2015
作者:
K
Kevin Halverson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2315 from KevinH-MS/LocalsInAsyncLambdas
Fix Locals in async lambdas...
上级
8a08d3f8
cdf941c8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
146 addition
and
44 deletion
+146
-44
src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/CompilationContext.cs
...or/CSharp/Source/ExpressionCompiler/CompilationContext.cs
+1
-1
src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/SymUnmanagedReaderExtensions.cs
...Source/ExpressionCompiler/SymUnmanagedReaderExtensions.cs
+45
-43
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs
...onEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs
+48
-0
src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/LocalsTests.vb
...luator/VisualBasic/Test/ExpressionCompiler/LocalsTests.vb
+52
-0
未找到文件。
src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/CompilationContext.cs
浏览文件 @
12a04c7d
...
@@ -619,7 +619,7 @@ private static BoundStatement BindAssignment(Binder binder, ExpressionSyntax syn
...
@@ -619,7 +619,7 @@ private static BoundStatement BindAssignment(Binder binder, ExpressionSyntax syn
BinderFlags
.
UncheckedRegion
|
BinderFlags
.
UncheckedRegion
|
BinderFlags
.
AllowManagedAddressOf
|
BinderFlags
.
AllowManagedAddressOf
|
BinderFlags
.
AllowAwaitInUnsafeContext
);
BinderFlags
.
AllowAwaitInUnsafeContext
);
var
hasImports
=
!
importRecordGroups
.
IsDefault
;
var
hasImports
=
!
importRecordGroups
.
IsDefault
OrEmpty
;
var
numImportStringGroups
=
hasImports
?
importRecordGroups
.
Length
:
0
;
var
numImportStringGroups
=
hasImports
?
importRecordGroups
.
Length
:
0
;
var
currentStringGroup
=
numImportStringGroups
-
1
;
var
currentStringGroup
=
numImportStringGroups
-
1
;
...
...
src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/SymUnmanagedReaderExtensions.cs
浏览文件 @
12a04c7d
...
@@ -21,56 +21,59 @@ internal static class SymUnmanagedReaderExtensions
...
@@ -21,56 +21,59 @@ internal static class SymUnmanagedReaderExtensions
var
importStringGroups
=
reader
.
GetCSharpGroupedImportStrings
(
methodToken
,
methodVersion
,
out
externAliasStrings
);
var
importStringGroups
=
reader
.
GetCSharpGroupedImportStrings
(
methodToken
,
methodVersion
,
out
externAliasStrings
);
Debug
.
Assert
(
importStringGroups
.
IsDefault
==
externAliasStrings
.
IsDefault
);
Debug
.
Assert
(
importStringGroups
.
IsDefault
==
externAliasStrings
.
IsDefault
);
if
(
importStringGroups
.
IsDefault
)
ArrayBuilder
<
ImmutableArray
<
ImportRecord
>>
importRecordGroupBuilder
=
null
;
ArrayBuilder
<
ExternAliasRecord
>
externAliasRecordBuilder
=
null
;
if
(!
importStringGroups
.
IsDefault
)
{
{
return
default
(
MethodDebugInfo
);
importRecordGroupBuilder
=
ArrayBuilder
<
ImmutableArray
<
ImportRecord
>>.
GetInstance
(
importStringGroups
.
Length
);
}
foreach
(
var
importStringGroup
in
importStringGroups
)
var
importRecordGroupBuilder
=
ArrayBuilder
<
ImmutableArray
<
ImportRecord
>>.
GetInstance
(
importStringGroups
.
Length
);
foreach
(
var
importStringGroup
in
importStringGroups
)
{
var
groupBuilder
=
ArrayBuilder
<
ImportRecord
>.
GetInstance
(
importStringGroup
.
Length
);
foreach
(
var
importString
in
importStringGroup
)
{
{
ImportRecord
record
;
var
groupBuilder
=
ArrayBuilder
<
ImportRecord
>.
GetInstance
(
importStringGroup
.
Length
)
;
if
(
NativeImportRecord
.
TryCreateFromCSharpImportString
(
importString
,
out
record
)
)
foreach
(
var
importString
in
importStringGroup
)
{
{
groupBuilder
.
Add
(
record
);
ImportRecord
record
;
}
if
(
NativeImportRecord
.
TryCreateFromCSharpImportString
(
importString
,
out
record
))
else
{
{
groupBuilder
.
Add
(
record
);
Debug
.
WriteLine
(
$"Failed to parse import string
{
importString
}
"
);
}
else
{
Debug
.
WriteLine
(
$"Failed to parse import string
{
importString
}
"
);
}
}
}
importRecordGroupBuilder
.
Add
(
groupBuilder
.
ToImmutableAndFree
());
}
}
importRecordGroupBuilder
.
Add
(
groupBuilder
.
ToImmutableAndFree
());
}
var
externAliasRecordBuilder
=
ArrayBuilder
<
ExternAliasRecord
>.
GetInstance
(
externAliasStrings
.
Length
);
if
(!
externAliasStrings
.
IsDefault
)
foreach
(
string
externAliasString
in
externAliasStrings
)
{
string
alias
;
string
externAlias
;
string
target
;
ImportTargetKind
kind
;
if
(!
CustomDebugInfoReader
.
TryParseCSharpImportString
(
externAliasString
,
out
alias
,
out
externAlias
,
out
target
,
out
kind
))
{
{
Debug
.
WriteLine
(
$"Unable to parse extern alias '
{
externAliasString
}
'"
);
externAliasRecordBuilder
=
ArrayBuilder
<
ExternAliasRecord
>.
GetInstance
(
externAliasStrings
.
Length
);
continue
;
foreach
(
string
externAliasString
in
externAliasStrings
)
}
{
string
alias
;
string
externAlias
;
string
target
;
ImportTargetKind
kind
;
if
(!
CustomDebugInfoReader
.
TryParseCSharpImportString
(
externAliasString
,
out
alias
,
out
externAlias
,
out
target
,
out
kind
))
{
Debug
.
WriteLine
(
$"Unable to parse extern alias '
{
externAliasString
}
'"
);
continue
;
}
Debug
.
Assert
(
kind
==
ImportTargetKind
.
Assembly
,
"Programmer error: How did a non-assembly get in the extern alias list?"
);
Debug
.
Assert
(
kind
==
ImportTargetKind
.
Assembly
,
"Programmer error: How did a non-assembly get in the extern alias list?"
);
Debug
.
Assert
(
alias
!=
null
);
// Name of the extern alias.
Debug
.
Assert
(
alias
!=
null
);
// Name of the extern alias.
Debug
.
Assert
(
externAlias
==
null
);
// Not used.
Debug
.
Assert
(
externAlias
==
null
);
// Not used.
Debug
.
Assert
(
target
!=
null
);
// Name of the target assembly.
Debug
.
Assert
(
target
!=
null
);
// Name of the target assembly.
AssemblyIdentity
targetIdentity
;
AssemblyIdentity
targetIdentity
;
if
(!
AssemblyIdentity
.
TryParseDisplayName
(
target
,
out
targetIdentity
))
if
(!
AssemblyIdentity
.
TryParseDisplayName
(
target
,
out
targetIdentity
))
{
{
Debug
.
WriteLine
(
$"Unable to parse target of extern alias '
{
externAliasString
}
'"
);
Debug
.
WriteLine
(
$"Unable to parse target of extern alias '
{
externAliasString
}
'"
);
continue
;
continue
;
}
}
externAliasRecordBuilder
.
Add
(
new
NativeExternAliasRecord
<
AssemblySymbol
>(
alias
,
targetIdentity
));
externAliasRecordBuilder
.
Add
(
new
NativeExternAliasRecord
<
AssemblySymbol
>(
alias
,
targetIdentity
));
}
}
}
}
var
hoistedLocalScopeRecords
=
ImmutableArray
<
HoistedLocalScopeRecord
>.
Empty
;
var
hoistedLocalScopeRecords
=
ImmutableArray
<
HoistedLocalScopeRecord
>.
Empty
;
...
@@ -97,11 +100,10 @@ internal static class SymUnmanagedReaderExtensions
...
@@ -97,11 +100,10 @@ internal static class SymUnmanagedReaderExtensions
out
dynamicLocalConstantMap
);
out
dynamicLocalConstantMap
);
}
}
return
new
MethodDebugInfo
(
return
new
MethodDebugInfo
(
hoistedLocalScopeRecords
,
hoistedLocalScopeRecords
,
importRecordGroupBuilder
.
ToImmutableAndFree
()
,
importRecordGroupBuilder
?.
ToImmutableAndFree
()
??
ImmutableArray
<
ImmutableArray
<
ImportRecord
>>.
Empty
,
externAliasRecordBuilder
.
ToImmutableAndFree
()
,
externAliasRecordBuilder
?.
ToImmutableAndFree
()
??
ImmutableArray
<
ExternAliasRecord
>.
Empty
,
dynamicLocalMap
,
dynamicLocalMap
,
dynamicLocalConstantMap
,
dynamicLocalConstantMap
,
defaultNamespaceName
:
""
);
// Unused in C#.
defaultNamespaceName
:
""
);
// Unused in C#.
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs
浏览文件 @
12a04c7d
...
@@ -1588,6 +1588,54 @@ .maxstack 1
...
@@ -1588,6 +1588,54 @@ .maxstack 1
locals
.
Free
();
locals
.
Free
();
}
}
[
WorkItem
(
2240
)]
[
Fact
]
public
void
AsyncLambda
()
{
var
source
=
@"using System;
using System.Threading.Tasks;
class C
{
static void M()
{
Func<int, Task> f = async (x) =>
{
var y = 42;
};
}
}"
;
var
compilation
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
compilation
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.<>c.<<M>b__0_0>d.MoveNext"
);
var
locals
=
ArrayBuilder
<
LocalAndMethod
>.
GetInstance
();
string
typeName
;
var
testData
=
new
CompilationTestData
();
context
.
CompileGetLocals
(
locals
,
argumentsOnly
:
false
,
typeName
:
out
typeName
,
testData
:
testData
);
Assert
.
Equal
(
locals
.
Count
,
2
);
VerifyLocal
(
testData
,
"<>x"
,
locals
[
0
],
"<>m0"
,
"x"
,
expectedILOpt
:
@"{
// Code size 7 (0x7)
.maxstack 1
.locals init (int V_0,
System.Exception V_1)
IL_0000: ldarg.0
IL_0001: ldfld ""int C.<>c.<<M>b__0_0>d.x""
IL_0006: ret
}"
);
VerifyLocal
(
testData
,
"<>x"
,
locals
[
1
],
"<>m1"
,
"y"
,
expectedILOpt
:
@"{
// Code size 7 (0x7)
.maxstack 1
.locals init (int V_0,
System.Exception V_1)
IL_0000: ldarg.0
IL_0001: ldfld ""int C.<>c.<<M>b__0_0>d.<y>5__1""
IL_0006: ret
}"
);
locals
.
Free
();
}
[
WorkItem
(
996571
)]
[
WorkItem
(
996571
)]
[
Fact
]
[
Fact
]
public
void
MissingReference
()
public
void
MissingReference
()
...
...
src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/LocalsTests.vb
浏览文件 @
12a04c7d
...
@@ -1647,6 +1647,58 @@ End Class"
...
@@ -1647,6 +1647,58 @@ End Class"
locals
.
Free
()
locals
.
Free
()
End
Sub
End
Sub
<
WorkItem
(
2240
)
>
<
Fact
>
Public
Sub
AsyncLambda
()
Const
source
=
"Imports System
Imports System.Threading.Tasks
Class C
Shared Sub M()
Dim f As Func(Of Integer, Task) = Async Function (x)
Dim y = 42
End Function
End Sub
End Class"
Dim
comp
=
CreateCompilationWithReferences
(
MakeSources
(
source
),
{
MscorlibRef_v4_0_30316_17626
,
MsvbRef_v4_0_30319_17929
,
SystemCoreRef_v4_0_30319_17929
},
TestOptions
.
DebugDll
)
Dim
runtime
=
CreateRuntimeInstance
(
comp
)
Dim
context
=
CreateMethodContext
(
runtime
,
methodName
:
=
"C._Closure$__.VB$StateMachine___Lambda$__1-0.MoveNext"
)
Dim
testData
As
New
CompilationTestData
()
Dim
locals
=
ArrayBuilder
(
Of
LocalAndMethod
).
GetInstance
()
Dim
typeName
As
String
=
Nothing
context
.
CompileGetLocals
(
locals
,
argumentsOnly
:
=
False
,
typeName
:
=
typeName
,
testData
:
=
testData
)
Assert
.
Equal
(
2
,
locals
.
Count
)
VerifyLocal
(
testData
,
typeName
,
locals
(
0
),
"<>m0"
,
"x"
,
expectedILOpt
:
=
"{
// Code size 7 (0x7)
.maxstack 1
.locals init (Integer V_0,
System.Threading.Tasks.Task V_1,
System.Exception V_2)
IL_0000: ldarg.0
IL_0001: ldfld
""
C._Closure$__.VB$StateMachine___Lambda$__1-0.$VB$Local_x As Integer
""
IL_0006: ret
}"
)
VerifyLocal
(
testData
,
typeName
,
locals
(
1
),
"<>m1"
,
"y"
,
expectedILOpt
:
=
"{
// Code size 7 (0x7)
.maxstack 1
.locals init (Integer V_0,
System.Threading.Tasks.Task V_1,
System.Exception V_2)
IL_0000: ldarg.0
IL_0001: ldfld
""
C._Closure$__.VB$StateMachine___Lambda$__1-0.$VB$ResumableLocal_y$0 As Integer
""
IL_0006: ret
}"
)
locals
.
Free
()
End
Sub
<
WorkItem
(
996571
)
>
<
WorkItem
(
996571
)
>
<
Fact
>
<
Fact
>
Public
Sub
MissingReference
()
Public
Sub
MissingReference
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录