Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Workspaces/Core/Portable/Remote/RemoteArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ public async Task<ISymbol> TryRehydrateAsync(
// The server and client should both be talking about the same compilation. As such
// locations in symbols are save to resolve as we rehydrate the SymbolKey.
var symbol = SymbolKey.ResolveString(
SymbolKeyData, compilation, cancellationToken: cancellationToken).GetAnySymbol();
SymbolKeyData, compilation, out var failureReason, cancellationToken).GetAnySymbol();

if (symbol == null)
{
try
{
throw new InvalidOperationException(
$"We should always be able to resolve a symbol back on the host side:\r\n{SymbolKeyData}");
$"We should always be able to resolve a symbol back on the host side:\r\n{SymbolKeyData}\r\n{failureReason}");
}
catch (Exception ex) when (FatalError.ReportWithoutCrash(ex))
{
Expand Down
12 changes: 10 additions & 2 deletions src/Workspaces/Core/Portable/SymbolKey/SymbolKey.AliasSymbolKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ public static void Create(IAliasSymbol symbol, SymbolKeyWriter visitor)
visitor.WriteString(FirstOrDefault(symbol.DeclaringSyntaxReferences)?.SyntaxTree.FilePath ?? "");
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var name = reader.ReadString();
var targetResolution = reader.ReadSymbolKey();
var targetResolution = reader.ReadSymbolKey(out var targetFailureReason);
var filePath = reader.ReadString();

if (targetFailureReason != null)
{
failureReason = $"({nameof(AliasSymbolKey)} {nameof(targetResolution)} failed -> {targetFailureReason})";
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general pattern when a subportion fails is: (this type failed resolving this piece of data -> due to this underlying cause). The parens are there for nesting to make all the nested reasons something that can be grokked.

return default;
}

var syntaxTree = reader.GetSyntaxTree(filePath);
if (syntaxTree != null)
{
Expand All @@ -34,11 +40,13 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var result = Resolve(semanticModel, syntaxTree.GetRoot(reader.CancellationToken), name, target, reader.CancellationToken);
if (result.HasValue)
{
failureReason = null;
return result.Value;
}
}
}

failureReason = $"({nameof(AliasSymbolKey)} '{name}' not found)";
return default;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ public static void Create(ISymbol symbol, SymbolKeyWriter visitor)
visitor.WriteLocation(FirstOrDefault(symbol.Locations));
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var isAnonymousDelegateType = reader.ReadBoolean();
var location = reader.ReadLocation();
var location = reader.ReadLocation(out var locationFailureReason);

if (locationFailureReason != null)
{
failureReason = $"({nameof(AnonymousFunctionOrDelegateSymbolKey)} {nameof(location)} failed -> {locationFailureReason})";
return default;
}

var syntaxTree = location.SourceTree;
if (syntaxTree == null)
{
failureReason = $"({nameof(AnonymousFunctionOrDelegateSymbolKey)} {nameof(SyntaxTree)} failed)";
return default;
}

Expand All @@ -58,6 +65,7 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
symbol = anonymousDelegate;
}

failureReason = null;
return new SymbolKeyResolution(symbol);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ public static void Create(INamedTypeSymbol symbol, SymbolKeyWriter visitor)
visitor.WriteLocationArray(propertyLocations);
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
using var propertyTypes = reader.ReadSymbolKeyArray<ITypeSymbol>();
using var propertyTypes = reader.ReadSymbolKeyArray<ITypeSymbol>(out var propertyTypesFailureReason);
using var propertyNames = reader.ReadStringArray();
using var propertyIsReadOnly = reader.ReadBooleanArray();
using var propertyLocations = reader.ReadLocationArray();
using var propertyLocations = reader.ReadLocationArray(out var propertyLocationsFailureReason);

if (propertyTypesFailureReason != null)
{
failureReason = $"({nameof(AnonymousTypeSymbolKey)} {nameof(propertyTypes)} failed -> {propertyTypesFailureReason})";
return default;
}

if (propertyLocationsFailureReason != null)
{
failureReason = $"({nameof(AnonymousTypeSymbolKey)} {nameof(propertyLocations)} failed -> {propertyLocationsFailureReason})";
return default;
}

if (!propertyTypes.IsDefault)
{
Expand All @@ -42,13 +54,15 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var anonymousType = reader.Compilation.CreateAnonymousTypeSymbol(
propertyTypes.ToImmutable(), propertyNames.ToImmutable(),
propertyIsReadOnly.ToImmutable(), propertyLocations.ToImmutable());
failureReason = null;
return new SymbolKeyResolution(anonymousType);
}
catch (ArgumentException)
{
}
}

failureReason = null;
return new SymbolKeyResolution(reader.Compilation.ObjectType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ public static void Create(IArrayTypeSymbol symbol, SymbolKeyWriter visitor)
visitor.WriteInteger(symbol.Rank);
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var elementTypeResolution = reader.ReadSymbolKey();
var elementTypeResolution = reader.ReadSymbolKey(out var elementTypeFailureReason);
var rank = reader.ReadInteger();

if (elementTypeFailureReason != null)
{
failureReason = $"({nameof(ArrayTypeSymbolKey)} {nameof(elementTypeResolution)} failed -> {elementTypeFailureReason})";
return default;
}

using var result = PooledArrayBuilder<IArrayTypeSymbol>.GetInstance(elementTypeResolution.SymbolCount);
foreach (var typeSymbol in elementTypeResolution.OfType<ITypeSymbol>())
{
result.AddIfNotNull(reader.Compilation.CreateArrayTypeSymbol(typeSymbol, rank));
}

return CreateResolution(result);
return CreateResolution(result, $"({nameof(ArrayTypeSymbolKey)})", out failureReason);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void Create(IAssemblySymbol symbol, SymbolKeyWriter visitor)
visitor.WriteString(symbol.Identity.Name);
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var assemblyName = reader.ReadString();
var compilation = reader.Compilation;
Expand All @@ -38,7 +38,7 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
}
}

return CreateResolution(result);
return CreateResolution(result, $"({nameof(AssemblySymbolKey)} '{assemblyName}' not found)", out failureReason);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,21 @@ private static bool TryGetSemanticModel(
return false;
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string? failureReason)
{
var cancellationToken = reader.CancellationToken;

var name = reader.ReadString();
var kind = (SymbolKind)reader.ReadInteger();
var locations = reader.ReadLocationArray();
var locations = reader.ReadLocationArray(out var locationsFailureReason);
var ordinal = reader.ReadInteger();

if (locationsFailureReason != null)
{
failureReason = $"({nameof(BodyLevelSymbolKey)} {nameof(locations)} failed -> {locationsFailureReason})";
return default;
}

// First check if we can recover the symbol just through the original location.
foreach (var loc in locations)
{
Expand All @@ -136,6 +142,7 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
if (symbol?.Kind == kind &&
SymbolKey.Equals(reader.Compilation, name, symbol.Name))
{
failureReason = null;
return resolution;
}
}
Expand All @@ -148,10 +155,14 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
foreach (var symbol in EnumerateSymbols(semanticModel, kind, name, cancellationToken))
{
if (symbol.ordinal == ordinal)
{
failureReason = null;
return new SymbolKeyResolution(symbol.symbol);
}
}
}

failureReason = $"({nameof(BodyLevelSymbolKey)} '{name}' not found)";
return default;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public static void Create(SymbolKeyWriter _)
// per compilation.
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
=> new SymbolKeyResolution(reader.Compilation.DynamicType);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
failureReason = null;
return new SymbolKeyResolution(reader.Compilation.DynamicType);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,30 @@ private static ImmutableArray<string> GetContainingNamespaceNamesInReverse(IName
return builder.ToImmutable();
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var name = reader.ReadString();
var containingSymbolResolution = ResolveContainer(reader);

var containingSymbolResolution = ResolveContainer(reader, out var containingSymbolFailureReason);
var arity = reader.ReadInteger();

using var typeArguments = reader.ReadSymbolKeyArray<ITypeSymbol>();
using var typeArguments = reader.ReadSymbolKeyArray<ITypeSymbol>(out var typeArgumentsFailureReason);

if (containingSymbolFailureReason != null)
{
failureReason = $"({nameof(ErrorTypeSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})";
return default;
}

if (typeArgumentsFailureReason != null)
{
failureReason = $"({nameof(ErrorTypeSymbolKey)} {nameof(typeArguments)} failed -> {typeArgumentsFailureReason})";
return default;
}

if (typeArguments.IsDefault)
{
failureReason = $"({nameof(ErrorTypeSymbolKey)} {nameof(typeArguments)} failed)";
return default;
}

Expand All @@ -85,15 +100,15 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
reader, container: null, name, arity, typeArgumentsArray));
}

return CreateResolution(result);
return CreateResolution(result, $"({nameof(ErrorTypeSymbolKey)} failed)", out failureReason);
}

private static SymbolKeyResolution ResolveContainer(SymbolKeyReader reader)
private static SymbolKeyResolution ResolveContainer(SymbolKeyReader reader, out string failureReason)
{
var type = reader.ReadInteger();

if (type == 0)
return reader.ReadSymbolKey();
return reader.ReadSymbolKey(out failureReason);

if (type == 1)
{
Expand All @@ -104,11 +119,15 @@ private static SymbolKeyResolution ResolveContainer(SymbolKeyReader reader)
for (var i = namespaceNames.Count - 1; i >= 0; i--)
currentNamespace = reader.Compilation.CreateErrorNamespaceSymbol(currentNamespace, namespaceNames[i]);

failureReason = null;
return new SymbolKeyResolution(currentNamespace);
}

if (type == 2)
{
failureReason = null;
return default;
}

throw ExceptionUtilities.UnexpectedValue(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ public static void Create(IEventSymbol symbol, SymbolKeyWriter visitor)
visitor.WriteSymbolKey(symbol.ContainingType);
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var metadataName = reader.ReadString();
var containingTypeResolution = reader.ReadSymbolKey();
var containingTypeResolution = reader.ReadSymbolKey(out var containingTypeFailureReason);

if (containingTypeFailureReason != null)
{
failureReason = $"({nameof(EventSymbolKey)} {nameof(containingTypeResolution)} failed -> {containingTypeFailureReason})";
return default;
}

using var result = GetMembersOfNamedType<IEventSymbol>(containingTypeResolution, metadataName);
return CreateResolution(result);
return CreateResolution(result, $"({nameof(EventSymbolKey)} '{metadataName}' not found)", out failureReason);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ public static void Create(IFieldSymbol symbol, SymbolKeyWriter visitor)
visitor.WriteSymbolKey(symbol.ContainingType);
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var metadataName = reader.ReadString();
var containingTypeResolution = reader.ReadSymbolKey();
var containingTypeResolution = reader.ReadSymbolKey(out var containingTypeFailureReason);

if (containingTypeFailureReason != null)
{
failureReason = $"({nameof(FieldSymbolKey)} {nameof(containingTypeResolution)} failed -> {containingTypeFailureReason})";
return default;
}

using var result = GetMembersOfNamedType<IFieldSymbol>(containingTypeResolution, metadataName);
return CreateResolution(result);
return CreateResolution(result, $"({nameof(FieldSymbolKey)} '{metadataName}' not found)", out failureReason);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,40 @@ public static void Create(IFunctionPointerTypeSymbol symbol, SymbolKeyWriter vis
visitor.WriteParameterTypesArray(symbol.Signature.Parameters);
}

public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
{
var returnRefKind = reader.ReadRefKind();
var returnType = reader.ReadSymbolKey();
var returnType = reader.ReadSymbolKey(out var returnTypeFailureReason);
using var paramRefKinds = reader.ReadRefKindArray();
using var paramTypes = reader.ReadSymbolKeyArray<ITypeSymbol>();
using var parameterTypes = reader.ReadSymbolKeyArray<ITypeSymbol>(out var parameterTypesFailureReason);

if (paramTypes.IsDefault || !(returnType.GetAnySymbol() is ITypeSymbol returnTypeSymbol))
if (returnTypeFailureReason != null)
{
failureReason = $"({nameof(FunctionPointerTypeSymbolKey)} {nameof(returnType)} failed -> {returnTypeFailureReason})";
return default;
}

if (parameterTypesFailureReason != null)
{
failureReason = $"({nameof(FunctionPointerTypeSymbolKey)} {nameof(parameterTypes)} failed -> {parameterTypesFailureReason})";
return default;
}

if (parameterTypes.IsDefault)
{
failureReason = $"({nameof(FunctionPointerTypeSymbolKey)} no parameter types)";
return default;
}

if (!(returnType.GetAnySymbol() is ITypeSymbol returnTypeSymbol))
{
failureReason = $"({nameof(FunctionPointerTypeSymbolKey)} no return type)";
return default;
}

failureReason = null;
return new SymbolKeyResolution(reader.Compilation.CreateFunctionPointerTypeSymbol(
returnTypeSymbol, returnRefKind, paramTypes.ToImmutable(), paramRefKinds.ToImmutable()));
returnTypeSymbol, returnRefKind, parameterTypes.ToImmutable(), paramRefKinds.ToImmutable()));
}
}
}
Expand Down
Loading