提交 17e041a8 编写于 作者: J Jared Parsons 提交者: Jared Parsons

Unify standard api surface

This unifies the API surface avalaible to code passed to CreateStandardCompilation
between CoreClr and Desktop execution to NetStandard2.0.

Ideally both would compile against NetStandard2.0 under the hood. But there are some
code execution limitations right now (no facades) that make that hard. For now just
ensuring the same API surface which will make it easier to port tests over.
上级 be77888b
......@@ -405,14 +405,15 @@ public static SyntaxTree ParseWithRoundTripCheck(string text, CSharpParseOptions
return CreateStandardCompilation(new SyntaxTree[] { syntaxTree }, references, options, assemblyName);
}
private static readonly ImmutableArray<MetadataReference> s_stdRefs = CoreClrShim.IsRunningOnCoreClr
? ImmutableArray.Create<MetadataReference>(NetStandard20.NetStandard, NetStandard20.MscorlibRef, NetStandard20.SystemRuntimeRef, NetStandard20.SystemDynamicRuntimeRef)
: ImmutableArray.Create(MscorlibRef);
// Careful! Make sure everything in s_desktopRefsToRemove is constructed with
// the same object identity, since MetadataReference uses reference equality.
// this may mean adding Interlocked calls in the construction of the reference.
private static readonly ImmutableArray<MetadataReference> s_desktopRefsToRemove = ImmutableArray.Create(SystemRef, SystemCoreRef);
private static readonly ImmutableArray<MetadataReference> s_desktopRefsToRemove = ImmutableArray.Create(SystemRef, SystemCoreRef, ValueTupleRef, SystemRuntimeFacadeRef);
private static readonly ImmutableArray<MetadataReference> s_stdRefs = CoreClrShim.IsRunningOnCoreClr
? ImmutableArray.Create<MetadataReference>(NetStandard20.NetStandard, NetStandard20.MscorlibRef, NetStandard20.SystemRuntimeRef, NetStandard20.SystemDynamicRuntimeRef)
: ImmutableArray.Create(MscorlibRef).AddRange(s_desktopRefsToRemove);
public static CSharpCompilation CreateStandardCompilation(
IEnumerable<SyntaxTree> trees,
......@@ -420,10 +421,17 @@ public static SyntaxTree ParseWithRoundTripCheck(string text, CSharpParseOptions
CSharpCompilationOptions options = null,
string assemblyName = "")
{
if (CoreClrShim.IsRunningOnCoreClr)
if (references != null)
{
references = references?.Except(s_desktopRefsToRemove);
foreach (var reference in references)
{
if (s_desktopRefsToRemove.Contains(reference))
{
throw new Exception($"Do not pass standard reference {reference.Display} to {nameof(CreateStandardCompilation)}");
}
}
}
return CreateCompilation(trees, (references != null) ? s_stdRefs.Concat(references) : s_stdRefs, options, assemblyName);
}
......
......@@ -109,7 +109,7 @@ private static ConstructorInitializerSyntax GetFirstConstructorInitializer(Synta
protected CompilationUtils.SemanticInfoSummary GetSemanticInfoForTest<TNode>(string testSrc, CSharpParseOptions parseOptions = null) where TNode : SyntaxNode
{
var compilation = CreateStandardCompilation(testSrc, new[] { SystemCoreRef }, parseOptions: parseOptions);
var compilation = CreateStandardCompilation(testSrc, parseOptions: parseOptions);
return GetSemanticInfoForTest<TNode>(compilation);
}
......@@ -124,7 +124,7 @@ private static ConstructorInitializerSyntax GetFirstConstructorInitializer(Synta
internal PreprocessingSymbolInfo GetPreprocessingSymbolInfoForTest(string testSrc, string subStrForPreprocessNameIndex)
{
var compilation = CreateStandardCompilation(testSrc, new[] { SystemCoreRef });
var compilation = CreateStandardCompilation(testSrc);
var tree = compilation.SyntaxTrees[0];
var model = compilation.GetSemanticModel(tree);
var position = testSrc.IndexOf(subStrForPreprocessNameIndex, StringComparison.Ordinal);
......@@ -135,7 +135,7 @@ internal PreprocessingSymbolInfo GetPreprocessingSymbolInfoForTest(string testSr
internal AliasSymbol GetAliasInfoForTest(string testSrc)
{
var compilation = CreateStandardCompilation(testSrc, new[] { SystemCoreRef });
var compilation = CreateStandardCompilation(testSrc);
return GetAliasInfoForTest(compilation);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册