Skip to content

Commit

Permalink
Further updates after today's meeting.
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Oct 12, 2018
1 parent a21916e commit dcbd24e
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 66 deletions.
62 changes: 11 additions & 51 deletions src/Compilers/Core/Portable/Compilation/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ namespace Microsoft.CodeAnalysis
{
public static class ModelExtensions
{
/// <summary>
/// Gets a semantic model based on this semantic model that can return information about calculated
/// nullability. This model is used to query for information about expressions that can have
/// inferred nullability, such as references, inferred type parameters, declared nullability
/// of <c>var</c> variables or discard expression, or lambda parameters.
/// </summary>
public static SemanticModel GetNullabilityAwareSemanticModel(this SemanticModel semanticModel, CancellationToken cancellationToken = default)

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Oct 12, 2018

Member

i like this. (or, it should be an instance mehtod on SemanticModel). but either approach seems good to me.

{
throw new NotImplementedException();
}

/// <summary>
/// Gets symbol information about a syntax node.
/// </summary>
Expand All @@ -24,12 +35,6 @@ public static class ModelExtensions
return semanticModel.GetSymbolInfo(node, cancellationToken);
}

// If there is no single symbol, return will be the same as GetSymbolInfoWithNullability
public static SymbolInfo GetSymbolInfoWithNullability(this SemanticModel semanticModel, SyntaxNode, CancellationToken ct = default)
{
throw new NotImplementedException();
}

/// <summary>
/// Binds the node in the context of the specified location and get semantic information
/// such as type, symbols and diagnostics. This method is used to get semantic information
Expand Down Expand Up @@ -66,11 +71,6 @@ public static SymbolInfo GetSpeculativeSymbolInfo(this SemanticModel semanticMod
return semanticModel.GetTypeInfo(node, cancellationToken);
}

public static TypeInfo GetTypeInfoWithNullability(this SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

/// <summary>
/// If "nameSyntax" resolves to an alias name, return the IAliasSymbol corresponding
/// to A. Otherwise return null.
Expand Down Expand Up @@ -146,46 +146,6 @@ public static TypeInfo GetSpeculativeTypeInfo(this SemanticModel semanticModel,
return semanticModel.GetDeclaredSymbolForNode(declaration, cancellationToken);
}

public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IDiscardSymbol discard, CancellationToken ct = default)
{
throw new NotImplementedException();
}

public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IEventSymbol eventSymbol, CancellationToken ct = default)
{
throw new NotImplementedException();
}

public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IFieldSymbol field, CancellationToken ct = default)
{
throw new NotImplementedException();
}

public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, ILocalSymbol local, CancellationToken ct = default)
{
throw new NotImplementedException();
}

public static TypeInfo GetReturnTypeWithNullability(this SemanticModel semanticModel, IMethodSymbol method, CancellationToken ct = default)
{
throw new NotImplementedException();
}

public static ImmutableArray<TypeInfo> GetTypeParametersWithNullability(this SemanticModel semanticModel, IMethodSymbol method, CancellationToken ct = default)
{
throw new NotImplementedException();
}

public static TypeInfo GetReceiverTypeWithNullability(this SemanticModel semanticModel, IMethodSymbol method, CancellationToken ct = default)
{
throw new NotImplementedException();
}

public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IParameterSymbol local, CancellationToken ct = default)
{
throw new NotImplementedException();
}

/// <summary>
/// Gets a list of method or indexed property symbols for a syntax node.
/// </summary>
Expand Down
19 changes: 7 additions & 12 deletions src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ Microsoft.CodeAnalysis.FlowAnalysis.IStaticLocalInitializationSemaphoreOperation
Microsoft.CodeAnalysis.FlowAnalysis.IStaticLocalInitializationSemaphoreOperation.Local.get -> Microsoft.CodeAnalysis.ILocalSymbol
Microsoft.CodeAnalysis.IArrayTypeSymbol.ElementNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IDiscardSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IEventSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IFieldSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.ILocalSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IEventSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IFieldSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.ILocalSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IMethodSymbol.ReceiverNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IMethodSymbol.ReturnNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IMethodSymbol.TypeArgumentsNullability.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Nullability>
Microsoft.CodeAnalysis.IMethodSymbol.TypeArgumentsNullabilities.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Nullability>
Microsoft.CodeAnalysis.INamedTypeSymbol.TypeArgumentsNullability.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Nullability>
Microsoft.CodeAnalysis.IOperation.SemanticModel.get -> Microsoft.CodeAnalysis.SemanticModel
Microsoft.CodeAnalysis.IParameterSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IParameterSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.IPropertySymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability
Microsoft.CodeAnalysis.ISymbol.ToDisplayParts(Microsoft.CodeAnalysis.Nullability nullability, Microsoft.CodeAnalysis.SymbolDisplayFormat format = null) -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.SymbolDisplayPart>
Microsoft.CodeAnalysis.ISymbol.ToDisplayString(Microsoft.CodeAnalysis.Nullability nullability, Microsoft.CodeAnalysis.SymbolDisplayFormat format = null) -> string
Expand Down Expand Up @@ -156,13 +157,7 @@ static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.Cod
static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.CodeAnalysis.Operations.IParameterInitializerOperation initializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph
static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.CodeAnalysis.Operations.IPropertyInitializerOperation initializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph
static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SemanticModel semanticModel, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph
static Microsoft.CodeAnalysis.ModelExtensions.GetReturnTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IMethodSymbol method, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo
static Microsoft.CodeAnalysis.ModelExtensions.GetSymbolInfoWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.SyntaxNode , System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.SymbolInfo
static Microsoft.CodeAnalysis.ModelExtensions.GetTypeInfoWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.SyntaxNode node, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo
static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IEventSymbol eventSymbol, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo
static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IFieldSymbol field, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo
static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.ILocalSymbol local, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo
static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IParameterSymbol local, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo
static Microsoft.CodeAnalysis.ModelExtensions.GetNullabilityAwareSemanticModel(this Microsoft.CodeAnalysis.SemanticModel semanticModel, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.SemanticModel
virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitCaughtException(Microsoft.CodeAnalysis.FlowAnalysis.ICaughtExceptionOperation operation) -> void
virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitFlowCapture(Microsoft.CodeAnalysis.FlowAnalysis.IFlowCaptureOperation operation) -> void
virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitFlowCaptureReference(Microsoft.CodeAnalysis.FlowAnalysis.IFlowCaptureReferenceOperation operation) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public enum SymbolDisplayPartKind
/// <summary>The name of a type parameter.</summary>
TypeParameterName = 26,
/// <summary>The name of a query range variable..</summary>
RangeVariableName = 27,
/// <summary>The nullability of the symbol.</summary>
Nullability = 28
RangeVariableName = 27
}

internal static class InternalSymbolDisplayPartKind
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/Core/Portable/Symbols/IDiscardSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public interface IDiscardSymbol : ISymbol
/// The type of the discarded value.
/// </summary>
ITypeSymbol Type { get; }

/// <summary>
/// The nullability of the discard symbol.
/// </summary>
Nullability Nullability { get; }

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Oct 12, 2018

Member

as per our convo, i still don't like this. But i think we agree that ew can drive a design here based on experiements/perf-analysis of actual compile time impact, and actual IDE latency/memory impact.

}
}
5 changes: 5 additions & 0 deletions src/Compilers/Core/Portable/Symbols/IEventSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public interface IEventSymbol : ISymbol
/// </summary>
ITypeSymbol Type { get; }

/// <summary>
/// The nullability of the event
/// </summary>
Nullability Nullability { get; }

/// <summary>
/// Returns true if the event is a WinRT type event.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/Core/Portable/Symbols/IFieldSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public interface IFieldSymbol : ISymbol
/// </summary>
ITypeSymbol Type { get; }

/// <summary>
/// The declared nullability of this field
/// </summary>
Nullability Nullability { get; }

/// <summary>
/// Returns false if the field wasn't declared as "const", or constant value was omitted or erroneous.
/// True otherwise.
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/Core/Portable/Symbols/ILocalSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public interface ILocalSymbol : ISymbol
/// </summary>
ITypeSymbol Type { get; }

/// <summary>
/// The declared nullability of this local
/// </summary>
Nullability Nullability { get; }

/// <summary>
/// Returns true if this local variable was declared as "const" (i.e. is a constant declaration).
/// Also returns true for an enum member.
Expand Down
17 changes: 17 additions & 0 deletions src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@ public interface IMethodSymbol : ISymbol
/// </summary>
ITypeSymbol ReturnType { get; }

/// <summary>
/// The nullability of the return of the method.
/// </summary>
Nullability ReturnNullability { get; }

/// <summary>
/// Returns the type arguments that have been substituted for the type parameters.
/// If nothing has been substituted for a given type parameter,
/// then the type parameter itself is consider the type argument.
/// </summary>
ImmutableArray<ITypeSymbol> TypeArguments { get; }

/// <summary>
/// Returns the nullablities of the type arguments that have been subsituted for the
/// type parameters.
/// </summary>
ImmutableArray<Nullability> TypeArgumentsNullabilities { get; }

/// <summary>
/// Get the type parameters on this method. If the method has not generic,
/// returns an empty list.
Expand Down Expand Up @@ -135,6 +146,12 @@ public interface IMethodSymbol : ISymbol
/// </summary>
ITypeSymbol ReceiverType { get; }

/// <summary>
/// If this method can be applied to an object, returns the nullability of the object it is
/// applied to.
/// </summary>
Nullability ReceiverNullability { get; }

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Oct 12, 2018

Member

i do like the naming consistency.


/// <summary>
/// If this method is a reduced extension method, returns the definition of extension
/// method from which this was reduced. Otherwise, returns null.
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/Core/Portable/Symbols/IParameterSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public interface IParameterSymbol : ISymbol
/// </summary>
ITypeSymbol Type { get; }

/// <summary>
/// Gets the nullability of the parameter.
/// </summary>
Nullability Nullability { get; }

/// <summary>
/// Custom modifiers associated with the parameter type, or an empty array if there are none.
/// </summary>
Expand Down

0 comments on commit dcbd24e

Please sign in to comment.