Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
ad966b80
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,发现更多精彩内容 >>
提交
ad966b80
编写于
9月 25, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify common calls to Parallel.For with a RoslynParallel.For helper
上级
89567d8b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
90 addition
and
103 deletion
+90
-103
src/Compilers/CSharp/Portable/CommandLine/CSharpCompiler.cs
src/Compilers/CSharp/Portable/CommandLine/CSharpCompiler.cs
+8
-12
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
...ompilers/CSharp/Portable/Compilation/CSharpCompilation.cs
+8
-25
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol_Completion.cs
...rtable/Symbols/Source/SourceNamespaceSymbol_Completion.cs
+6
-30
src/Compilers/Core/Portable/InternalUtilities/RoslynParallel.cs
...mpilers/Core/Portable/InternalUtilities/RoslynParallel.cs
+46
-0
src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCompiler.vb
...s/VisualBasic/Portable/CommandLine/VisualBasicCompiler.vb
+9
-9
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
...isualBasic/Portable/Compilation/VisualBasicCompilation.vb
+7
-13
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceModuleSymbol.vb
...VisualBasic/Portable/Symbols/Source/SourceModuleSymbol.vb
+6
-14
未找到文件。
src/Compilers/CSharp/Portable/CommandLine/CSharpCompiler.cs
浏览文件 @
ad966b80
...
...
@@ -11,13 +11,12 @@
using
System.IO
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Task
s
;
using
Microsoft.CodeAnalysi
s
;
using
Microsoft.CodeAnalysis.Collections
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis
;
namespace
Microsoft.CodeAnalysis.CSharp
{
...
...
@@ -60,9 +59,10 @@ protected CSharpCompiler(CSharpCommandLineParser parser, string responseFile, st
if
(
Arguments
.
CompilationOptions
.
ConcurrentBuild
)
{
Parallel
.
For
(
0
,
sourceFiles
.
Length
,
UICultureUtilities
.
WithCurrentUICulture
<
int
>(
i
=>
{
try
RoslynParallel
.
For
(
0
,
sourceFiles
.
Length
,
UICultureUtilities
.
WithCurrentUICulture
<
int
>(
i
=>
{
//NOTE: order of trees is important!!
trees
[
i
]
=
ParseFile
(
...
...
@@ -72,12 +72,8 @@ protected CSharpCompiler(CSharpCommandLineParser parser, string responseFile, st
sourceFiles
[
i
],
diagnosticBag
,
out
normalizedFilePaths
[
i
]);
}
catch
(
Exception
e
)
when
(
FatalError
.
Report
(
e
))
{
throw
ExceptionUtilities
.
Unreachable
;
}
}));
}),
CancellationToken
.
None
);
}
else
{
...
...
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
浏览文件 @
ad966b80
...
...
@@ -51,8 +51,6 @@ public sealed partial class CSharpCompilation : Compilation
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
internal
static
readonly
ParallelOptions
DefaultParallelOptions
=
new
ParallelOptions
();
private
readonly
CSharpCompilationOptions
_options
;
private
readonly
Lazy
<
Imports
>
_globalImports
;
private
readonly
Lazy
<
Imports
>
_previousSubmissionImports
;
...
...
@@ -2472,31 +2470,16 @@ internal override void GetDiagnostics(CompilationStage stage, bool includeEarlie
var
syntaxTrees
=
this
.
SyntaxTrees
;
if
(
this
.
Options
.
ConcurrentBuild
)
{
var
parallelOptions
=
cancellationToken
.
CanBeCanceled
?
new
ParallelOptions
()
{
CancellationToken
=
cancellationToken
}
:
DefaultParallelOptions
;
Parallel
.
For
(
0
,
syntaxTrees
.
Length
,
parallelOptions
,
RoslynParallel
.
For
(
0
,
syntaxTrees
.
Length
,
UICultureUtilities
.
WithCurrentUICulture
<
int
>(
i
=>
{
try
{
var
syntaxTree
=
syntaxTrees
[
i
];
AppendLoadDirectiveDiagnostics
(
builder
,
_syntaxAndDeclarations
,
syntaxTree
);
builder
.
AddRange
(
syntaxTree
.
GetDiagnostics
(
cancellationToken
));
}
catch
(
Exception
e
)
when
(
FatalError
.
ReportUnlessCanceled
(
e
))
{
throw
ExceptionUtilities
.
Unreachable
;
}
catch
(
OperationCanceledException
e
)
when
(
cancellationToken
.
IsCancellationRequested
&&
e
.
CancellationToken
!=
cancellationToken
)
{
// Parallel.For checks for a specific cancellation token, so make sure we throw with the
// correct one.
cancellationToken
.
ThrowIfCancellationRequested
();
throw
ExceptionUtilities
.
Unreachable
;
}
}));
var
syntaxTree
=
syntaxTrees
[
i
];
AppendLoadDirectiveDiagnostics
(
builder
,
_syntaxAndDeclarations
,
syntaxTree
);
builder
.
AddRange
(
syntaxTree
.
GetDiagnostics
(
cancellationToken
));
}),
cancellationToken
);
}
else
{
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol_Completion.cs
浏览文件 @
ad966b80
...
...
@@ -2,14 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
using
System
;
using
System.Diagnostics
;
using
System.Threading
;
using
System.Threading.Task
s
;
using
Roslyn.Utilitie
s
;
namespace
Microsoft.CodeAnalysis.CSharp.Symbols
{
...
...
@@ -49,29 +43,11 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok
if
(
this
.
DeclaringCompilation
.
Options
.
ConcurrentBuild
)
{
var
po
=
cancellationToken
.
CanBeCanceled
?
new
ParallelOptions
()
{
CancellationToken
=
cancellationToken
}
:
CSharpCompilation
.
DefaultParallelOptions
;
Parallel
.
For
(
0
,
members
.
Length
,
po
,
UICultureUtilities
.
WithCurrentUICulture
<
int
>(
i
=>
{
try
{
var
member
=
members
[
i
];
ForceCompleteMemberByLocation
(
locationOpt
,
member
,
cancellationToken
);
}
catch
(
Exception
e
)
when
(
FatalError
.
ReportUnlessCanceled
(
e
))
{
throw
ExceptionUtilities
.
Unreachable
;
}
catch
(
OperationCanceledException
e
)
when
(
cancellationToken
.
IsCancellationRequested
&&
e
.
CancellationToken
!=
cancellationToken
)
{
// Parallel.For checks for a specific cancellation token, so make sure we throw with the
// correct one.
cancellationToken
.
ThrowIfCancellationRequested
();
throw
ExceptionUtilities
.
Unreachable
;
}
}));
RoslynParallel
.
For
(
0
,
members
.
Length
,
UICultureUtilities
.
WithCurrentUICulture
<
int
>(
i
=>
ForceCompleteMemberByLocation
(
locationOpt
,
members
[
i
],
cancellationToken
)),
cancellationToken
);
foreach
(
var
member
in
members
)
{
...
...
src/Compilers/Core/Portable/InternalUtilities/RoslynParallel.cs
0 → 100644
浏览文件 @
ad966b80
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis
;
namespace
Roslyn.Utilities
{
internal
static
class
RoslynParallel
{
internal
static
readonly
ParallelOptions
DefaultParallelOptions
=
new
ParallelOptions
();
/// <inheritdoc cref="Parallel.For(int, int, ParallelOptions, Action{int})"/>
public
static
ParallelLoopResult
For
(
int
fromInclusive
,
int
toExclusive
,
Action
<
int
>
body
,
CancellationToken
cancellationToken
)
{
var
parallelOptions
=
cancellationToken
.
CanBeCanceled
?
new
ParallelOptions
{
CancellationToken
=
cancellationToken
}
:
DefaultParallelOptions
;
return
Parallel
.
For
(
fromInclusive
,
toExclusive
,
parallelOptions
,
errorHandlingBody
);
// Local function
void
errorHandlingBody
(
int
i
)
{
try
{
body
(
i
);
}
catch
(
Exception
e
)
when
(
FatalError
.
ReportUnlessCanceled
(
e
,
cancellationToken
))
{
throw
ExceptionUtilities
.
Unreachable
;
}
catch
(
OperationCanceledException
e
)
when
(
cancellationToken
.
IsCancellationRequested
&&
e
.
CancellationToken
!=
cancellationToken
)
{
// Parallel.For checks for a specific cancellation token, so make sure we throw with the
// correct one.
cancellationToken
.
ThrowIfCancellationRequested
();
throw
ExceptionUtilities
.
Unreachable
;
}
}
}
}
}
src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCompiler.vb
浏览文件 @
ad966b80
...
...
@@ -4,6 +4,7 @@
Imports
System.Collections.Immutable
Imports
System.IO
Imports
System.Threading
Imports
Microsoft.CodeAnalysis.Collections
Imports
Microsoft.CodeAnalysis.Diagnostics
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
...
@@ -99,22 +100,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
trees
(
sourceFiles
.
Length
-
1
)
As
SyntaxTree
If
Arguments
.
CompilationOptions
.
ConcurrentBuild
Then
Parallel
.
For
(
0
,
sourceFiles
.
Length
,
UICultureUtilities
.
WithCurrentUICulture
(
Of
Integer
)(
RoslynParallel
.
For
(
0
,
sourceFiles
.
Length
,
UICultureUtilities
.
WithCurrentUICulture
(
Of
Integer
)(
Sub
(
i
As
Integer
)
Try
' NOTE: order of trees is important!!
trees
(
i
)
=
ParseFile
(
' NOTE: order of trees is important!!
trees
(
i
)
=
ParseFile
(
consoleOutput
,
parseOptions
,
scriptParseOptions
,
hadErrors
,
sourceFiles
(
i
),
errorLogger
)
Catch
ex
As
Exception
When
FatalError
.
Report
(
ex
)
Throw
ExceptionUtilities
.
Unreachable
End
Try
End
Sub
))
End
Sub
),
CancellationToken
.
None
)
Else
For
i
=
0
To
sourceFiles
.
Length
-
1
' NOTE: order of trees is important!!
...
...
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
浏览文件 @
ad966b80
...
...
@@ -2087,20 +2087,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' Embedded trees shouldn't have any errors, let's avoid making decision if they should be added too early.
' Otherwise IDE performance might be affect.
If
Options
.
ConcurrentBuild
Then
Dim
options
=
New
ParallelOptions
()
With
{.
CancellationToken
=
cancellationToken
}
Parallel
.
For
(
0
,
SyntaxTrees
.
Length
,
options
,
UICultureUtilities
.
WithCurrentUICulture
(
Sub
(
i
As
Integer
)
Try
RoslynParallel
.
For
(
0
,
SyntaxTrees
.
Length
,
UICultureUtilities
.
WithCurrentUICulture
(
Sub
(
i
As
Integer
)
builder
.
AddRange
(
SyntaxTrees
(
i
).
GetDiagnostics
(
cancellationToken
))
Catch
e
As
Exception
When
FatalError
.
ReportUnlessCanceled
(
e
)
Throw
ExceptionUtilities
.
Unreachable
Catch
e
As
OperationCanceledException
When
cancellationToken
.
IsCancellationRequested
AndAlso
e
.
CancellationToken
<>
cancellationToken
' Parallel.For checks for a specific cancellation token, so make sure we throw with the
' correct one.
cancellationToken
.
ThrowIfCancellationRequested
()
Throw
ExceptionUtilities
.
Unreachable
End
Try
End
Sub
))
End
Sub
),
cancellationToken
)
Else
For
Each
tree
In
SyntaxTrees
cancellationToken
.
ThrowIfCancellationRequested
()
...
...
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceModuleSymbol.vb
浏览文件 @
ad966b80
...
...
@@ -616,22 +616,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim
trees
=
ArrayBuilder
(
Of
SyntaxTree
).
GetInstance
()
trees
.
AddRange
(
SyntaxTrees
)
Dim
options
=
New
ParallelOptions
()
With
{.
CancellationToken
=
cancellationToken
}
Parallel
.
For
(
0
,
trees
.
Count
,
options
,
RoslynParallel
.
For
(
0
,
trees
.
Count
,
UICultureUtilities
.
WithCurrentUICulture
(
Sub
(
i
As
Integer
)
Try
cancellationToken
.
ThrowIfCancellationRequested
()
TryGetSourceFile
(
trees
(
i
)).
GenerateAllDeclarationErrors
()
Catch
e
As
Exception
When
FatalError
.
ReportUnlessCanceled
(
e
)
Throw
ExceptionUtilities
.
Unreachable
Catch
e
As
OperationCanceledException
When
cancellationToken
.
IsCancellationRequested
AndAlso
e
.
CancellationToken
<>
cancellationToken
' Parallel.For checks for a specific cancellation token, so make sure we throw with the
' correct one.
cancellationToken
.
ThrowIfCancellationRequested
()
Throw
ExceptionUtilities
.
Unreachable
End
Try
End
Sub
))
TryGetSourceFile
(
trees
(
i
)).
GenerateAllDeclarationErrors
()
End
Sub
),
cancellationToken
)
trees
.
Free
()
Else
For
Each
tree
In
SyntaxTrees
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录