Skip to content

Commit

Permalink
Misc.
Browse files Browse the repository at this point in the history
  • Loading branch information
cston committed Jan 17, 2021
1 parent c65c6e1 commit 686fcb8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ public TypeWithAnnotations GetInferredReturnType(ConversionsBase conversions, Nu
diagnostics,
delegateInvokeMethodOpt: delegateType?.DelegateInvokeMethod,
initialState: nullableState,
analyzedNullabilityMapOpt: null,
snapshotBuilderOpt: null,
returnTypes);
diagnostics.Free();
var inferredReturnType = InferReturnType(returnTypes, node: this, Binder, delegateType, Symbol.IsAsync, conversions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ private Variables(NextId nextId, int id, Variables? container, Symbol? symbol)
Debug.Assert(container is null || container.Id < id);
Debug.Assert(id < nextId.Value);
_nextId = nextId;
// PROTOTYPE: Handle > 64K nested methods (distinct ids). See NullableStateTooManyNestedFunctions().
Id = id;
Container = container;
Symbol = symbol;
Expand Down Expand Up @@ -249,10 +248,10 @@ internal void GetMembers(ArrayBuilder<(VariableIdentifier, int)> builder, int co
{
(int id, int index) = DeconstructSlot(containingSlot);
var variables = GetVariablesForId(id)!;

for (index++; index < variables.Count; index++)
var variableBySlot = variables._variableBySlot;
for (index++; index < variableBySlot.Count; index++)
{
var variable = variables._variableBySlot[index];
var variable = variableBySlot[index];
if (variable.ContainingSlot == containingSlot)
{
builder.Add((variable, ConstructSlot(id, index)));
Expand Down
8 changes: 3 additions & 5 deletions src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,6 @@ internal static void Analyze(
DiagnosticBag diagnostics,
MethodSymbol? delegateInvokeMethodOpt,
VariableState initialState,
ImmutableDictionary<BoundExpression, (NullabilityInfo, TypeSymbol?)>.Builder? analyzedNullabilityMapOpt,
SnapshotManager.Builder? snapshotBuilderOpt,
ArrayBuilder<(BoundReturnStatement, TypeWithAnnotations)>? returnTypesOpt)
{
var symbol = lambda.Symbol;
Expand All @@ -1310,12 +1308,12 @@ internal static void Analyze(
conversions,
variables,
returnTypesOpt,
analyzedNullabilityMapOpt,
snapshotBuilderOpt);
analyzedNullabilityMapOpt: null,
snapshotBuilderOpt: null);
try
{
var localState = LocalState.Create(initialState.VariableNullableStates).CreateNestedFunction(variables);
Analyze(walker, symbol, diagnostics, localState, snapshotBuilderOpt);
Analyze(walker, symbol, diagnostics, localState, snapshotBuilderOpt: null);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,35 @@ public void NullableStateLocalFunctions()
}

[ConditionalFact(typeof(NoIOperationValidation))]
public void NullableStateTooManyLocals()
public void NullableStateTooManyLocals_01()
{
const int nLocals = 65536;

var builder = new StringBuilder();
builder.AppendLine("#pragma warning disable 168");
builder.AppendLine("#nullable enable");
builder.AppendLine("class Program");
builder.AppendLine("{");
builder.AppendLine(" static void F(object arg)");
builder.AppendLine(" {");
for (int i = 1; i < nLocals; i++)
{
builder.AppendLine($" object i{i};");
}
builder.AppendLine(" object i0 = arg;");
builder.AppendLine(" if (i0 == null) i0.ToString();");
builder.AppendLine(" }");
builder.AppendLine("}");

var source = builder.ToString();
var comp = CreateCompilation(source);
// No warning for i0.ToString() because the local is not tracked
// by the NullableWalker.Variables instance (too many locals).
comp.VerifyDiagnostics();
}

[ConditionalFact(typeof(NoIOperationValidation))]
public void NullableStateTooManyLocals_02()
{
const int nLocals = 65536;

Expand All @@ -482,7 +510,9 @@ public void NullableStateTooManyLocals()

var source = builder.ToString();
var comp = CreateCompilation(source);
// PROTOTYPE: Perf: NullableWalker.Variables.GetMembers() is O(n^2).
// PROTOTYPE: Each assignment results in a call to NullableWalker.InheritDefaultState().
// InheritDefaultState() is O(n) where n is the number of locals, and since there is one
// assignment per local, the overall perf is O(n^2).
#if false
comp.VerifyDiagnostics(
// (6,21): warning CS8600: Converting null literal or possible null value to non-nullable type.
Expand All @@ -494,7 +524,7 @@ public void NullableStateTooManyLocals()
[ConditionalFact(typeof(NoIOperationValidation))]
public void NullableStateTooManyNestedFunctions()
{
const int nFunctions = 65536;
const int nFunctions = 32768;

var builder = new StringBuilder();
builder.AppendLine("#nullable enable");
Expand All @@ -515,7 +545,7 @@ public void NullableStateTooManyNestedFunctions()

var source = builder.ToString();
var comp = CreateCompilation(source);
// PROTOTYPE: Investigate performance.
// PROTOTYPE: Handle 32K nested methods (distinct ids) gracefully in NullableWalker.Variables.
#if false
comp.VerifyDiagnostics();
#endif
Expand Down

0 comments on commit 686fcb8

Please sign in to comment.