Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0a0d8f2e
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,发现更多精彩内容 >>
提交
0a0d8f2e
编写于
6月 07, 2017
作者:
V
Vladimir Sadov
提交者:
GitHub
6月 07, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20058 from VSadov/spanDetect2
Fix detection of Span types
上级
80a2dabd
bc78c3ed
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
134 addition
and
30 deletion
+134
-30
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs
.../CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs
+4
-22
src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
...Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
+25
-0
src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs
...rs/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs
+105
-8
未找到文件。
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs
浏览文件 @
0a0d8f2e
...
@@ -2061,7 +2061,10 @@ internal override bool IsByRefLikeType
...
@@ -2061,7 +2061,10 @@ internal override bool IsByRefLikeType
if
(
this
.
TypeKind
==
TypeKind
.
Struct
)
if
(
this
.
TypeKind
==
TypeKind
.
Struct
)
{
{
if
(
IsWellknownSpans
())
//PROTOTYPE(span): Span and ReadOnlySpan should have ByRefLike attribute, eventually.
// For now assume that any "System.Span" and "System.ReadOnlySpan" structs
// are ByRefLike
if
(
this
.
IsSpanType
())
{
{
isByRefLike
=
ThreeState
.
True
;
isByRefLike
=
ThreeState
.
True
;
}
}
...
@@ -2108,27 +2111,6 @@ internal override bool IsReadOnly
...
@@ -2108,27 +2111,6 @@ internal override bool IsReadOnly
}
}
}
}
//PROTOTYPE(span): Span and ReadonlySpan should have spanLike marker.
// For now assume that any "System.Span" and "System.ReadOnlySpan" structs
// are span-like
private
bool
IsWellknownSpans
()
{
var
originalDef
=
this
.
OriginalDefinition
;
if
(
originalDef
.
Name
!=
"Span"
&&
originalDef
.
Name
!=
"ReadonlySpan"
)
{
return
false
;
}
var
ns
=
originalDef
.
ContainingSymbol
as
NamespaceSymbol
;
if
(
ns
?.
Name
!=
"System"
)
{
return
false
;
}
return
ns
.
IsGlobalNamespace
;
}
internal
override
bool
HasDeclarativeSecurity
internal
override
bool
HasDeclarativeSecurity
{
{
get
{
return
(
_flags
&
TypeAttributes
.
HasSecurity
)
!=
0
;
}
get
{
return
(
_flags
&
TypeAttributes
.
HasSecurity
)
!=
0
;
}
...
...
src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
浏览文件 @
0a0d8f2e
...
@@ -1278,6 +1278,31 @@ private static bool HasNamespaceName(NamespaceSymbol @namespace, string namespac
...
@@ -1278,6 +1278,31 @@ private static bool HasNamespaceName(NamespaceSymbol @namespace, string namespac
return
(
name
.
Length
==
length
)
&&
(
string
.
Compare
(
name
,
0
,
namespaceName
,
offset
,
length
,
comparison
)
==
0
);
return
(
name
.
Length
==
length
)
&&
(
string
.
Compare
(
name
,
0
,
namespaceName
,
offset
,
length
,
comparison
)
==
0
);
}
}
internal
static
bool
IsSpanType
(
this
TypeSymbol
type
)
{
if
((
type
as
NamedTypeSymbol
)?.
Arity
!=
1
)
{
// must be a generic type of arity '1'
return
false
;
}
if
(
type
.
Name
!=
"Span"
&&
type
.
Name
!=
"ReadOnlySpan"
)
{
// must be called "Span" or "ReadOnlySpan"
return
false
;
}
var
ns
=
type
.
ContainingSymbol
as
NamespaceSymbol
;
if
(
ns
?.
Name
!=
"System"
)
{
// must be in "System" namespace
return
false
;
}
// the "System" must be in the global namespace
return
ns
.
ContainingNamespace
.
IsGlobalNamespace
;
}
internal
static
bool
IsNonGenericTaskType
(
this
TypeSymbol
type
,
CSharpCompilation
compilation
)
internal
static
bool
IsNonGenericTaskType
(
this
TypeSymbol
type
,
CSharpCompilation
compilation
)
{
{
var
namedType
=
type
as
NamedTypeSymbol
;
var
namedType
=
type
as
NamedTypeSymbol
;
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs
浏览文件 @
0a0d8f2e
...
@@ -28,7 +28,7 @@ namespace System
...
@@ -28,7 +28,7 @@ namespace System
public override int GetHashCode() => 1;
public override int GetHashCode() => 1;
}
}
public ref struct Read
o
nlySpan<T>
public ref struct Read
O
nlySpan<T>
{
{
public ref readonly T this[int i] => throw null;
public ref readonly T this[int i] => throw null;
public override int GetHashCode() => 2;
public override int GetHashCode() => 2;
...
@@ -40,6 +40,7 @@ namespace System
...
@@ -40,6 +40,7 @@ namespace System
}
}
}
}
"
;
"
;
//PROTOTYPE(span): this will be updated when rules for defining span are implemented
//PROTOTYPE(span): this will be updated when rules for defining span are implemented
// most likely we would just pick the actual binary/corlib where
// most likely we would just pick the actual binary/corlib where
// span lives.
// span lives.
...
@@ -83,7 +84,7 @@ class Program
...
@@ -83,7 +84,7 @@ class Program
static void Main()
static void Main()
{
{
object x = new Span<int>();
object x = new Span<int>();
object y = new Read
o
nlySpan<byte>();
object y = new Read
O
nlySpan<byte>();
object z = new SpanLike<int>();
object z = new SpanLike<int>();
}
}
}
}
...
@@ -95,9 +96,9 @@ static void Main()
...
@@ -95,9 +96,9 @@ static void Main()
// (8,20): error CS0029: Cannot implicitly convert type 'System.Span<int>' to 'object'
// (8,20): error CS0029: Cannot implicitly convert type 'System.Span<int>' to 'object'
// object x = new Span<int>();
// object x = new Span<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Span<int>()"
).
WithArguments
(
"System.Span<int>"
,
"object"
).
WithLocation
(
8
,
20
),
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Span<int>()"
).
WithArguments
(
"System.Span<int>"
,
"object"
).
WithLocation
(
8
,
20
),
// (9,20): error CS0029: Cannot implicitly convert type 'System.Read
o
nlySpan<byte>' to 'object'
// (9,20): error CS0029: Cannot implicitly convert type 'System.Read
O
nlySpan<byte>' to 'object'
// object y = new Read
o
nlySpan<byte>();
// object y = new Read
O
nlySpan<byte>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Read
onlySpan<byte>()"
).
WithArguments
(
"System.Reado
nlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
),
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Read
OnlySpan<byte>()"
).
WithArguments
(
"System.ReadO
nlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
),
// (10,20): error CS0029: Cannot implicitly convert type 'System.SpanLike<int>' to 'object'
// (10,20): error CS0029: Cannot implicitly convert type 'System.SpanLike<int>' to 'object'
// object z = new SpanLike<int>();
// object z = new SpanLike<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new SpanLike<int>()"
).
WithArguments
(
"System.SpanLike<int>"
,
"object"
)
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new SpanLike<int>()"
).
WithArguments
(
"System.SpanLike<int>"
,
"object"
)
...
@@ -109,9 +110,9 @@ static void Main()
...
@@ -109,9 +110,9 @@ static void Main()
// (8,20): error CS0029: Cannot implicitly convert type 'System.Span<int>' to 'object'
// (8,20): error CS0029: Cannot implicitly convert type 'System.Span<int>' to 'object'
// object x = new Span<int>();
// object x = new Span<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Span<int>()"
).
WithArguments
(
"System.Span<int>"
,
"object"
).
WithLocation
(
8
,
20
),
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Span<int>()"
).
WithArguments
(
"System.Span<int>"
,
"object"
).
WithLocation
(
8
,
20
),
// (9,20): error CS0029: Cannot implicitly convert type 'System.Read
o
nlySpan<byte>' to 'object'
// (9,20): error CS0029: Cannot implicitly convert type 'System.Read
O
nlySpan<byte>' to 'object'
// object y = new Read
o
nlySpan<byte>();
// object y = new Read
O
nlySpan<byte>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Read
onlySpan<byte>()"
).
WithArguments
(
"System.Reado
nlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
),
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Read
OnlySpan<byte>()"
).
WithArguments
(
"System.ReadO
nlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
),
// (10,20): error CS0029: Cannot implicitly convert type 'System.SpanLike<int>' to 'object'
// (10,20): error CS0029: Cannot implicitly convert type 'System.SpanLike<int>' to 'object'
// object z = new SpanLike<int>();
// object z = new SpanLike<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new SpanLike<int>()"
).
WithArguments
(
"System.SpanLike<int>"
,
"object"
)
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new SpanLike<int>()"
).
WithArguments
(
"System.SpanLike<int>"
,
"object"
)
...
@@ -743,5 +744,101 @@ static void Main()
...
@@ -743,5 +744,101 @@ static void Main()
Diagnostic
(
ErrorCode
.
ERR_MethDelegateMismatch
,
"ToString"
).
WithArguments
(
"ToString"
,
"System.Func<string>"
).
WithLocation
(
16
,
46
)
Diagnostic
(
ErrorCode
.
ERR_MethDelegateMismatch
,
"ToString"
).
WithArguments
(
"ToString"
,
"System.Func<string>"
).
WithLocation
(
16
,
46
)
);
);
}
}
//PROTOTYPE(span): Span and ReadOnlySpan should have ByRefLike attribute, eventually.
// For now assume that any "System.Span" and "System.ReadOnlySpan" structs
// are ByRefLike
[
Fact
]
public
void
SpanDetect
()
{
//span structs are not marked as "ref"
string
spanSourceNoRefs
=
@"
namespace System
{
public struct Span<T>
{
public ref T this[int i] => throw null;
public override int GetHashCode() => 1;
}
public struct ReadOnlySpan<T>
{
public ref readonly T this[int i] => throw null;
public override int GetHashCode() => 2;
}
public struct RegularStruct<T>
{
}
// arity 0 - not a span
public struct Span
{
}
// arity 2 - not a span
public struct Span<T, U>
{
public ref T this[int i] => throw null;
public override int GetHashCode() => 1;
}
}
// nested
public struct S1
{
public struct Span<T>
{
public ref T this[int i] => throw null;
public override int GetHashCode() => 1;
}
}
public struct Span<T>
{
public ref T this[int i] => throw null;
public override int GetHashCode() => 1;
}
"
;
var
reference
=
CreateCompilation
(
spanSourceNoRefs
,
references
:
new
List
<
MetadataReference
>()
{
MscorlibRef_v4_0_30316_17626
,
SystemCoreRef
,
CSharpRef
},
options
:
TestOptions
.
ReleaseDll
);
reference
.
VerifyDiagnostics
();
var
text
=
@"
using System;
class Program
{
static void Main()
{
object x = new System.Span<int>();
object y = new ReadOnlySpan<byte>();
object z1 = new Span();
object z2 = new Span<int, int>();
object z3 = new S1.Span<int>();
object z4 = new Span<int>();
}
}
"
;
var
comp
=
CreateCompilation
(
text
,
references
:
new
List
<
MetadataReference
>()
{
MscorlibRef_v4_0_30316_17626
,
SystemCoreRef
,
CSharpRef
,
reference
.
EmitToImageReference
()
},
options
:
TestOptions
.
ReleaseExe
);
comp
.
VerifyDiagnostics
(
// (8,20): error CS0029: Cannot implicitly convert type 'System.Span<int>' to 'object'
// object x = new System.Span<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new System.Span<int>()"
).
WithArguments
(
"System.Span<int>"
,
"object"
).
WithLocation
(
8
,
20
),
// (9,20): error CS0029: Cannot implicitly convert type 'System.ReadOnlySpan<byte>' to 'object'
// object y = new ReadOnlySpan<byte>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new ReadOnlySpan<byte>()"
).
WithArguments
(
"System.ReadOnlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
)
);
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录