Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
92b4ad67
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,发现更多精彩内容 >>
提交
92b4ad67
编写于
3月 09, 2016
作者:
T
Tomas Matousek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dedup import scopes based on value equality instead of reference equality
上级
0ea15464
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
169 addition
and
23 deletion
+169
-23
nuget
nuget
+0
-0
src/Compilers/CSharp/Portable/Binder/Binder.cs
src/Compilers/CSharp/Portable/Binder/Binder.cs
+2
-1
src/Compilers/CSharp/Portable/Binder/ImportChain.cs
src/Compilers/CSharp/Portable/Binder/ImportChain.cs
+6
-0
src/Compilers/CSharp/Portable/Binder/Imports.cs
src/Compilers/CSharp/Portable/Binder/Imports.cs
+10
-0
src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs
src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs
+38
-19
src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
+87
-0
src/Compilers/Core/Portable/PEWriter/IImportScope.cs
src/Compilers/Core/Portable/PEWriter/IImportScope.cs
+1
-0
src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs
...lers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs
+23
-1
src/Test/PdbUtilities/Metadata/MetadataVisualizer.cs
src/Test/PdbUtilities/Metadata/MetadataVisualizer.cs
+2
-2
未找到文件。
nuget
0 → 100644
浏览文件 @
92b4ad67
src/Compilers/CSharp/Portable/Binder/Binder.cs
浏览文件 @
92b4ad67
...
...
@@ -263,7 +263,8 @@ public virtual ConsList<LocalSymbol> ImplicitlyTypedLocalsBeingBound
}
/// <summary>
/// The Imports for all containing namespace declarations (innermost-to-outermost, including global).
/// The imports for all containing namespace declarations (innermost-to-outermost, including global),
/// or null if there are none.
/// </summary>
internal
virtual
ImportChain
ImportChain
{
...
...
src/Compilers/CSharp/Portable/Binder/ImportChain.cs
浏览文件 @
92b4ad67
...
...
@@ -7,6 +7,7 @@
namespace
Microsoft.CodeAnalysis.CSharp
{
[
DebuggerDisplay
(
"{GetDebuggerDisplay(),nq}"
)]
internal
sealed
class
ImportChain
:
Cci
.
IImportScope
{
public
readonly
Imports
Imports
;
...
...
@@ -22,6 +23,11 @@ public ImportChain(Imports imports, ImportChain parentOpt)
ParentOpt
=
parentOpt
;
}
private
string
GetDebuggerDisplay
()
{
return
$"
{
Imports
.
GetDebuggerDisplay
()}
^
{
ParentOpt
?.
GetHashCode
()
??
0
}
"
;
}
ImmutableArray
<
Cci
.
UsedNamespaceOrType
>
Cci
.
IImportScope
.
GetUsedNamespaces
()
{
// The imports should have been translated during code gen.
...
...
src/Compilers/CSharp/Portable/Binder/Imports.cs
浏览文件 @
92b4ad67
...
...
@@ -16,6 +16,7 @@ namespace Microsoft.CodeAnalysis.CSharp
/// <summary>
/// Represents symbols imported to the binding scope via using namespace, using alias, and extern alias.
/// </summary>
[
DebuggerDisplay
(
"{GetDebuggerDisplay(),nq}"
)]
internal
sealed
class
Imports
{
internal
static
readonly
Imports
Empty
=
new
Imports
(
...
...
@@ -53,6 +54,15 @@ internal sealed class Imports
this
.
ExternAliases
=
externs
;
}
internal
string
GetDebuggerDisplay
()
{
return
string
.
Join
(
"; "
,
UsingAliases
.
OrderBy
(
x
=>
x
.
Value
.
UsingDirective
.
Location
.
SourceSpan
.
Start
).
Select
(
ua
=>
$"
{
ua
.
Key
}
=
{
ua
.
Value
.
Alias
.
Target
}
"
).
Concat
(
Usings
.
Select
(
u
=>
u
.
NamespaceOrType
.
ToString
())).
Concat
(
ExternAliases
.
Select
(
ea
=>
$"extern alias
{
ea
.
Alias
.
Name
}
"
)));
}
public
static
Imports
FromSyntax
(
CSharpSyntaxNode
declarationSyntax
,
InContainerBinder
binder
,
...
...
src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs
浏览文件 @
92b4ad67
...
...
@@ -11,6 +11,7 @@
using
Microsoft.CodeAnalysis.CSharp.Test.Utilities
;
using
Roslyn.Test.Utilities
;
using
Microsoft.CodeAnalysis.Emit
;
using
System.Diagnostics
;
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests.Emit
{
...
...
@@ -37,7 +38,7 @@ private ImmutableArray<byte> EmitDeterministic(string source, Platform platform,
{
var
options
=
(
optimize
?
TestOptions
.
ReleaseExe
:
TestOptions
.
DebugExe
).
WithPlatform
(
platform
).
WithDeterministic
(
true
);
var
compilation
=
CreateCompilation
(
source
,
assemblyName
:
"DeterminismTest"
,
references
:
new
[]
{
MscorlibRef
},
options
:
options
);
var
compilation
=
CreateCompilation
(
source
,
assemblyName
:
"DeterminismTest"
,
references
:
new
[]
{
MscorlibRef
,
SystemCoreRef
,
CSharpRef
},
options
:
options
);
// The resolution of the PE header time date stamp is seconds, and we want to make sure that has an opportunity to change
// between calls to Emit.
...
...
@@ -101,6 +102,34 @@ public void Simple()
Assert
.
NotEqual
(
mvid3
,
mvid7
);
}
const
string
CompareAllBytesEmitted_Source
=
@"
using System;
using System.Linq;
using System.Collections.Generic;
namespace N
{
using I4 = System.Int32;
class Program
{
public static IEnumerable<int> F()
{
I4 x = 1;
yield return 1;
yield return x;
}
public static void Main(string[] args)
{
dynamic x = 1;
const int a = 1;
F().ToArray();
Console.WriteLine(x + a);
}
}
}"
;
[
Fact
]
public
void
CompareAllBytesEmitted_Release
()
{
...
...
@@ -111,17 +140,12 @@ public void CompareAllBytesEmitted_Release()
DebugInformationFormat
.
Embedded
})
{
var
source
=
@"class Program
{
public static void Main(string[] args) {}
}"
;
var
result1
=
EmitDeterministic
(
source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
true
);
var
result2
=
EmitDeterministic
(
source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
true
);
var
result1
=
EmitDeterministic
(
CompareAllBytesEmitted_Source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
true
);
var
result2
=
EmitDeterministic
(
CompareAllBytesEmitted_Source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
true
);
AssertEx
.
Equal
(
result1
,
result2
);
var
result3
=
EmitDeterministic
(
s
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
true
);
var
result4
=
EmitDeterministic
(
s
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
true
);
var
result3
=
EmitDeterministic
(
CompareAllBytesEmitted_S
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
true
);
var
result4
=
EmitDeterministic
(
CompareAllBytesEmitted_S
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
true
);
AssertEx
.
Equal
(
result3
,
result4
);
}
}
...
...
@@ -136,17 +160,12 @@ public void CompareAllBytesEmitted_Debug()
DebugInformationFormat
.
Embedded
})
{
var
source
=
@"class Program
{
public static void Main(string[] args) {}
}"
;
var
result1
=
EmitDeterministic
(
source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
false
);
var
result2
=
EmitDeterministic
(
source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
false
);
var
result1
=
EmitDeterministic
(
CompareAllBytesEmitted_Source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
false
);
var
result2
=
EmitDeterministic
(
CompareAllBytesEmitted_Source
,
Platform
.
AnyCpu32BitPreferred
,
pdbFormat
,
optimize
:
false
);
AssertEx
.
Equal
(
result1
,
result2
);
var
result3
=
EmitDeterministic
(
s
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
false
);
var
result4
=
EmitDeterministic
(
s
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
false
);
var
result3
=
EmitDeterministic
(
CompareAllBytesEmitted_S
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
false
);
var
result4
=
EmitDeterministic
(
CompareAllBytesEmitted_S
ource
,
Platform
.
X64
,
pdbFormat
,
optimize
:
false
);
AssertEx
.
Equal
(
result3
,
result4
);
}
}
...
...
src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
浏览文件 @
92b4ad67
...
...
@@ -8,6 +8,7 @@
using
System.Reflection.PortableExecutable
;
using
System.Text
;
using
Microsoft.CodeAnalysis.CSharp.Test.Utilities
;
using
Microsoft.CodeAnalysis.Emit
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.MetadataUtilities
;
using
Roslyn.Test.Utilities
;
...
...
@@ -2386,5 +2387,91 @@ void M()
</methods>
</symbols>"
);
}
[
Fact
]
public
void
ImportScopeEquality
()
{
var
sources
=
new
[]
{
@"
extern alias A;
using System;
using C = System;
namespace N.M
{
using System.Collections;
class C1 { void F() {} }
}
namespace N.M
{
using System.Collections;
class C2 { void F() {} }
}
"
,
@"
extern alias A;
using System;
using C = System;
namespace N.M
{
using System.Collections;
class C3 { void F() {} }
}
namespace N.M
{
using System.Collections.Generic;
class C4 { void F() {} }
}
"
,
@"
extern alias A;
using System;
using D = System;
namespace N.M
{
using System.Collections;
class C5 { void F() {} }
}
"
,
@"
extern alias A;
using System;
class C6 { void F() {} }
"
};
var
c
=
CreateCompilationWithMscorlib
(
sources
,
new
[]
{
SystemCoreRef
.
WithAliases
(
ImmutableArray
.
Create
(
"A"
))
});
var
pdbStream
=
new
MemoryStream
();
c
.
EmitToArray
(
EmitOptions
.
Default
.
WithDebugInformationFormat
(
DebugInformationFormat
.
PortablePdb
),
pdbStream
:
pdbStream
);
var
pdbImage
=
pdbStream
.
ToImmutable
();
using
(
var
metadata
=
new
PinnedMetadata
(
pdbImage
))
{
var
mdReader
=
metadata
.
Reader
;
var
writer
=
new
StringWriter
();
var
mdVisualizer
=
new
MetadataVisualizer
(
mdReader
,
writer
);
mdVisualizer
.
WriteImportScope
();
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
@"
ImportScope (index: 0x35, size: 36):
=============================================================================================
Parent Imports
=============================================================================================
1: nil 'A' (#1) = 0x23000002 (AssemblyRef)
2: 0x35000001 (ImportScope) Extern Alias 'A' (#1), 'System' (#7)
3: 0x35000001 (ImportScope) Extern Alias 'A' (#1), 'System' (#7), 'C' (#1d) = 'System' (#7)
4: 0x35000003 (ImportScope) nil
5: 0x35000004 (ImportScope) 'System.Collections' (#27)
6: 0x35000004 (ImportScope) 'System.Collections.Generic' (#4b)
7: 0x35000001 (ImportScope) Extern Alias 'A' (#1), 'System' (#7), 'D' (#69) = 'System' (#7)
8: 0x35000007 (ImportScope) nil
9: 0x35000008 (ImportScope) 'System.Collections' (#27)
"
,
writer
.
ToString
());
}
}
}
}
src/Compilers/Core/Portable/PEWriter/IImportScope.cs
浏览文件 @
92b4ad67
...
...
@@ -11,6 +11,7 @@ internal interface IImportScope
{
/// <summary>
/// Zero or more used namespaces. These correspond to using directives in C# or Imports syntax in VB.
/// Multiple invocations return the same array instance.
/// </summary>
ImmutableArray
<
UsedNamespaceOrType
>
GetUsedNamespaces
();
...
...
src/Compilers/Core/Portable/PEWriter/MetadataWriter.PortablePdb.cs
浏览文件 @
92b4ad67
...
...
@@ -7,6 +7,7 @@
using
System.Linq
;
using
System.Reflection.Metadata
;
using
Microsoft.CodeAnalysis
;
using
Roslyn.Utilities
;
namespace
Microsoft.Cci
{
...
...
@@ -78,7 +79,28 @@ private struct CustomDebugInformationRow
private
readonly
List
<
CustomDebugInformationRow
>
_customDebugInformationTable
=
new
List
<
CustomDebugInformationRow
>();
private
readonly
Dictionary
<
DebugSourceDocument
,
int
>
_documentIndex
=
new
Dictionary
<
DebugSourceDocument
,
int
>();
private
readonly
Dictionary
<
IImportScope
,
int
>
_scopeIndex
=
new
Dictionary
<
IImportScope
,
int
>();
private
readonly
Dictionary
<
IImportScope
,
int
>
_scopeIndex
=
new
Dictionary
<
IImportScope
,
int
>(
ImportScopeEqualityComparer
.
Instance
);
/// <summary>
/// Import scopes are associated with binders (in C#) and thus multiple instances might be created for a single set of imports.
/// We consider scopes with the same parent and the same imports the same.
/// Internal for testing.
/// </summary>
internal
sealed
class
ImportScopeEqualityComparer
:
IEqualityComparer
<
IImportScope
>
{
public
static
readonly
ImportScopeEqualityComparer
Instance
=
new
ImportScopeEqualityComparer
();
public
bool
Equals
(
IImportScope
x
,
IImportScope
y
)
{
return
(
object
)
x
==
y
||
x
!=
null
&&
y
!=
null
&&
Equals
(
x
.
Parent
,
y
.
Parent
)
&&
x
.
GetUsedNamespaces
().
SequenceEqual
(
y
.
GetUsedNamespaces
());
}
public
int
GetHashCode
(
IImportScope
obj
)
{
return
Hash
.
Combine
(
Hash
.
CombineValues
(
obj
.
GetUsedNamespaces
()),
obj
.
Parent
!=
null
?
GetHashCode
(
obj
.
Parent
)
:
0
);
}
}
private
void
SerializeMethodDebugInfo
(
IMethodBody
bodyOpt
,
int
methodRid
,
int
localSignatureRowId
)
{
...
...
src/Test/PdbUtilities/Metadata/MetadataVisualizer.cs
浏览文件 @
92b4ad67
...
...
@@ -142,7 +142,7 @@ public void Visualize(int generation = -1)
WriteLocalScope
();
WriteLocalVariable
();
WriteLocalConstant
();
Write
LocalImport
();
Write
ImportScope
();
WriteCustomDebugInformation
();
// heaps:
...
...
@@ -1716,7 +1716,7 @@ private static bool IsPrimitiveType(SignatureTypeCode typeCode)
}
}
p
rivate
void
WriteLocalImport
()
p
ublic
void
WriteImportScope
()
{
AddHeader
(
"Parent"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录