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
2 changes: 1 addition & 1 deletion src/Compilers/Core/Portable/Compilation/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3000,7 +3000,7 @@ internal void MarkImportDirectiveAsUsed(SyntaxNode node)
MarkImportDirectiveAsUsed(node.SyntaxTree, node.Span.Start);
}

internal void MarkImportDirectiveAsUsed(SyntaxTree syntaxTree, int position)
internal void MarkImportDirectiveAsUsed(SyntaxTree? syntaxTree, int position)
{
// Optimization: Don't initialize TreeToUsedImportDirectivesMap in submissions.
if (!IsSubmission && syntaxTree != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Diagnostics;
using Roslyn.Utilities;
Expand Down Expand Up @@ -86,7 +88,7 @@ internal override void CopyTo(ArrayElement<GreenNode>[] array, int offset)
Array.Copy(this.children, 0, array, offset, this.children.Length);
}

internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
{
var separated = this.SlotCount > 1 && HasNodeTokenPattern();
if (parent != null && parent.ShouldCreateWeakList())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;

namespace Microsoft.CodeAnalysis.Syntax
Expand All @@ -8,15 +10,15 @@ internal partial class SyntaxList
{
internal class SeparatedWithManyChildren : SyntaxList
{
private readonly ArrayElement<SyntaxNode>[] _children;
private readonly ArrayElement<SyntaxNode?>[] _children;

internal SeparatedWithManyChildren(InternalSyntax.SyntaxList green, SyntaxNode parent, int position)
internal SeparatedWithManyChildren(InternalSyntax.SyntaxList green, SyntaxNode? parent, int position)
: base(green, parent, position)
{
_children = new ArrayElement<SyntaxNode>[(green.SlotCount + 1) >> 1];
_children = new ArrayElement<SyntaxNode?>[(green.SlotCount + 1) >> 1];
}

internal override SyntaxNode GetNodeSlot(int i)
internal override SyntaxNode? GetNodeSlot(int i)
{
if ((i & 1) != 0)
{
Expand All @@ -27,7 +29,7 @@ internal override SyntaxNode GetNodeSlot(int i)
return this.GetRedElement(ref _children[i >> 1].Value, i);
}

internal override SyntaxNode GetCachedSlot(int i)
internal override SyntaxNode? GetCachedSlot(int i)
{
if ((i & 1) != 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;

namespace Microsoft.CodeAnalysis.Syntax
Expand All @@ -8,17 +10,17 @@ internal partial class SyntaxList
{
internal class SeparatedWithManyWeakChildren : SyntaxList
{
private readonly ArrayElement<WeakReference<SyntaxNode>>[] _children;
private readonly ArrayElement<WeakReference<SyntaxNode>?>[] _children;

internal SeparatedWithManyWeakChildren(InternalSyntax.SyntaxList green, SyntaxNode parent, int position)
: base(green, parent, position)
{
_children = new ArrayElement<WeakReference<SyntaxNode>>[(((green.SlotCount + 1) >> 1) - 1)];
_children = new ArrayElement<WeakReference<SyntaxNode>?>[(((green.SlotCount + 1) >> 1) - 1)];
}

internal override SyntaxNode GetNodeSlot(int i)
internal override SyntaxNode? GetNodeSlot(int i)
{
SyntaxNode result = null;
SyntaxNode? result = null;

if ((i & 1) == 0)
{
Expand All @@ -29,9 +31,9 @@ internal override SyntaxNode GetNodeSlot(int i)
return result;
}

internal override SyntaxNode GetCachedSlot(int i)
internal override SyntaxNode? GetCachedSlot(int i)
{
SyntaxNode result = null;
SyntaxNode? result = null;

if ((i & 1) == 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;

namespace Microsoft.CodeAnalysis.Syntax
Expand All @@ -8,20 +10,20 @@ internal partial class SyntaxList
{
internal class WithManyChildren : SyntaxList
{
private readonly ArrayElement<SyntaxNode>[] _children;
private readonly ArrayElement<SyntaxNode?>[] _children;

internal WithManyChildren(InternalSyntax.SyntaxList green, SyntaxNode parent, int position)
internal WithManyChildren(InternalSyntax.SyntaxList green, SyntaxNode? parent, int position)
: base(green, parent, position)
{
_children = new ArrayElement<SyntaxNode>[green.SlotCount];
_children = new ArrayElement<SyntaxNode?>[green.SlotCount];
}

internal override SyntaxNode GetNodeSlot(int index)
internal override SyntaxNode? GetNodeSlot(int index)
{
return this.GetRedElement(ref _children[index].Value, index);
}

internal override SyntaxNode GetCachedSlot(int index)
internal override SyntaxNode? GetCachedSlot(int index)
{
return _children[index];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Threading;

Expand All @@ -9,7 +11,7 @@ internal partial class SyntaxList
{
internal class WithManyWeakChildren : SyntaxList
{
private readonly ArrayElement<WeakReference<SyntaxNode>>[] _children;
private readonly ArrayElement<WeakReference<SyntaxNode>?>[] _children;

// We calculate and store the positions of all children here. This way, getting the position
// of all children is O(N) [N being the list size], otherwise it is O(N^2) because getting
Expand All @@ -20,7 +22,7 @@ internal WithManyWeakChildren(InternalSyntax.SyntaxList.WithManyChildrenBase gre
: base(green, parent, position)
{
int count = green.SlotCount;
_children = new ArrayElement<WeakReference<SyntaxNode>>[count];
_children = new ArrayElement<WeakReference<SyntaxNode>?>[count];

var childOffsets = new int[count];

Expand All @@ -45,9 +47,9 @@ internal override SyntaxNode GetNodeSlot(int index)
return GetWeakRedElement(ref _children[index].Value, index);
}

internal override SyntaxNode GetCachedSlot(int index)
internal override SyntaxNode? GetCachedSlot(int index)
{
SyntaxNode value = null;
SyntaxNode? value = null;
_children[index].Value?.TryGetTarget(out value);
return value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;

namespace Microsoft.CodeAnalysis.Syntax
Expand All @@ -8,16 +10,16 @@ internal partial class SyntaxList
{
internal class WithThreeChildren : SyntaxList
{
private SyntaxNode _child0;
private SyntaxNode _child1;
private SyntaxNode _child2;
private SyntaxNode? _child0;
private SyntaxNode? _child1;
private SyntaxNode? _child2;

internal WithThreeChildren(InternalSyntax.SyntaxList green, SyntaxNode parent, int position)
: base(green, parent, position)
{
}

internal override SyntaxNode GetNodeSlot(int index)
internal override SyntaxNode? GetNodeSlot(int index)
{
switch (index)
{
Expand All @@ -32,7 +34,7 @@ internal override SyntaxNode GetNodeSlot(int index)
}
}

internal override SyntaxNode GetCachedSlot(int index)
internal override SyntaxNode? GetCachedSlot(int index)
{
switch (index)
{
Expand Down
10 changes: 6 additions & 4 deletions src/Compilers/Core/Portable/Syntax/SyntaxList.WithTwoChildren.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Collections.Generic;
using Roslyn.Utilities;
Expand All @@ -10,15 +12,15 @@ internal partial class SyntaxList
{
internal class WithTwoChildren : SyntaxList
{
private SyntaxNode _child0;
private SyntaxNode _child1;
private SyntaxNode? _child0;
private SyntaxNode? _child1;

internal WithTwoChildren(InternalSyntax.SyntaxList green, SyntaxNode parent, int position)
: base(green, parent, position)
{
}

internal override SyntaxNode GetNodeSlot(int index)
internal override SyntaxNode? GetNodeSlot(int index)
{
switch (index)
{
Expand All @@ -31,7 +33,7 @@ internal override SyntaxNode GetNodeSlot(int index)
}
}

internal override SyntaxNode GetCachedSlot(int index)
internal override SyntaxNode? GetCachedSlot(int index)
{
switch (index)
{
Expand Down
9 changes: 6 additions & 3 deletions src/Compilers/Core/Portable/Syntax/SyntaxList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Collections.Generic;
using Roslyn.Utilities;
Expand All @@ -8,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Syntax
{
internal abstract partial class SyntaxList : SyntaxNode
{
internal SyntaxList(InternalSyntax.SyntaxList green, SyntaxNode parent, int position)
internal SyntaxList(InternalSyntax.SyntaxList green, SyntaxNode? parent, int position)
: base(green, parent, position)
{
}
Expand All @@ -21,9 +23,10 @@ public override string Language
}
}

protected override SyntaxTree SyntaxTreeCore => this.Parent.SyntaxTree;
// https://github.com/dotnet/roslyn/issues/40733
protected override SyntaxTree SyntaxTreeCore => this.Parent!.SyntaxTree;

protected internal override SyntaxNode ReplaceCore<TNode>(IEnumerable<TNode> nodes = null, Func<TNode, TNode, SyntaxNode> computeReplacementNode = null, IEnumerable<SyntaxToken> tokens = null, Func<SyntaxToken, SyntaxToken, SyntaxToken> computeReplacementToken = null, IEnumerable<SyntaxTrivia> trivia = null, Func<SyntaxTrivia, SyntaxTrivia, SyntaxTrivia> computeReplacementTrivia = null)
protected internal override SyntaxNode ReplaceCore<TNode>(IEnumerable<TNode>? nodes = null, Func<TNode, TNode, SyntaxNode>? computeReplacementNode = null, IEnumerable<SyntaxToken>? tokens = null, Func<SyntaxToken, SyntaxToken, SyntaxToken>? computeReplacementToken = null, IEnumerable<SyntaxTrivia>? trivia = null, Func<SyntaxTrivia, SyntaxTrivia, SyntaxTrivia>? computeReplacementTrivia = null)
{
throw ExceptionUtilities.Unreachable;
}
Expand Down
26 changes: 14 additions & 12 deletions src/Compilers/Core/Portable/Syntax/SyntaxListBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Diagnostics;

namespace Microsoft.CodeAnalysis.Syntax
{
internal class SyntaxListBuilder
{
private ArrayElement<GreenNode>[] _nodes;
private ArrayElement<GreenNode?>[] _nodes;
public int Count { get; private set; }

public SyntaxListBuilder(int size)
{
_nodes = new ArrayElement<GreenNode>[size];
_nodes = new ArrayElement<GreenNode?>[size];
}

public void Clear()
Expand All @@ -32,7 +34,7 @@ internal void AddInternal(GreenNode item)
throw new ArgumentNullException();
}

if (_nodes == null || Count >= _nodes.Length)
if (Count >= _nodes.Length)
{
this.Grow(Count == 0 ? 8 : _nodes.Length * 2);
}
Expand All @@ -47,7 +49,7 @@ public void AddRange(SyntaxNode[] items)

public void AddRange(SyntaxNode[] items, int offset, int length)
{
if (_nodes == null || Count + length > _nodes.Length)
if (Count + length > _nodes.Length)
{
this.Grow(Count + length);
}
Expand Down Expand Up @@ -81,15 +83,15 @@ public void AddRange(SyntaxList<SyntaxNode> list)

public void AddRange(SyntaxList<SyntaxNode> list, int offset, int count)
{
if (_nodes == null || this.Count + count > _nodes.Length)
if (this.Count + count > _nodes.Length)
{
this.Grow(Count + count);
}

var dst = this.Count;
for (int i = offset, limit = offset + count; i < limit; i++)
{
_nodes[dst].Value = list.ItemInternal(i).Green;
_nodes[dst].Value = list.ItemInternal(i)!.Green;
Copy link
Contributor

@sharwell sharwell Jan 3, 2020

Choose a reason for hiding this comment

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

💡 Consider splitting the expression list.ItemInternal(i) to a local, then asserting that it is not null. #WontFix

dst++;
}

Expand All @@ -115,7 +117,7 @@ public void AddRange(SyntaxNodeOrTokenList list)

public void AddRange(SyntaxNodeOrTokenList list, int offset, int count)
{
if (_nodes == null || this.Count + count > _nodes.Length)
if (this.Count + count > _nodes.Length)
{
this.Grow(Count + count);
}
Expand Down Expand Up @@ -144,7 +146,7 @@ public void AddRange(SyntaxTokenList list, int offset, int length)

private void Grow(int size)
{
var tmp = new ArrayElement<GreenNode>[size];
var tmp = new ArrayElement<GreenNode?>[size];
Array.Copy(_nodes, tmp, _nodes.Length);
_nodes = tmp;
}
Expand All @@ -153,7 +155,7 @@ public bool Any(int kind)
{
for (int i = 0; i < Count; i++)
{
if (_nodes[i].Value.RawKind == kind)
if (_nodes[i].Value!.RawKind == kind)
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Is it possible for this to reach external code and still be null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I'm aware of. It's an implementation detail of this type.


In reply to: 362963462 [](ancestors = 362963462)

{
return true;
}
Expand All @@ -162,7 +164,7 @@ public bool Any(int kind)
return false;
}

internal GreenNode ToListNode()
internal GreenNode? ToListNode()
{
switch (this.Count)
{
Expand All @@ -175,7 +177,7 @@ internal GreenNode ToListNode()
case 3:
return InternalSyntax.SyntaxList.List(_nodes[0].Value, _nodes[1].Value, _nodes[2].Value);
default:
var tmp = new ArrayElement<GreenNode>[this.Count];
var tmp = new ArrayElement<GreenNode?>[this.Count];
for (int i = 0; i < this.Count; i++)
{
tmp[i].Value = _nodes[i].Value;
Expand All @@ -198,7 +200,7 @@ public static implicit operator SyntaxList<SyntaxNode>(SyntaxListBuilder builder
internal void RemoveLast()
{
this.Count -= 1;
this._nodes[Count] = default(ArrayElement<GreenNode>);
this._nodes[Count] = default;
}
}
}
Loading