Skip to content

Commit dce0ee8

Browse files
committed
Move to the use site tracking for the purpose of recording used assemblies
1 parent 3f488c6 commit dce0ee8

294 files changed

Lines changed: 5967 additions & 4844 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Compilers/CSharp/Portable/Binder/Binder.QueryTranslationState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public RangeVariableMap RangeVariableMap()
5757
return result;
5858
}
5959

60-
internal RangeVariableSymbol AddRangeVariable(Binder binder, SyntaxToken identifier, DiagnosticBag diagnostics)
60+
internal RangeVariableSymbol AddRangeVariable(Binder binder, SyntaxToken identifier, BindingDiagnosticBag diagnostics)
6161
{
6262
string name = identifier.ValueText;
6363
var result = new RangeVariableSymbol(name, binder.ContainingMemberOrLambda, identifier.GetLocation());

src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.CSharp
1010
{
1111
internal partial class Binder
1212
{
13-
private delegate BoundBlock LambdaBodyFactory(LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, DiagnosticBag diagnostics);
13+
private delegate BoundBlock LambdaBodyFactory(LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, BindingDiagnosticBag diagnostics);
1414

1515
private class QueryUnboundLambdaState : UnboundLambdaState
1616
{
@@ -38,7 +38,7 @@ public QueryUnboundLambdaState(Binder binder, RangeVariableMap rangeVariableMap,
3838
public override Location ParameterLocation(int index) { return _parameters[index].Locations[0]; }
3939
public override TypeWithAnnotations ParameterTypeWithAnnotations(int index) { throw new ArgumentException(); } // implicitly typed
4040

41-
public override void GenerateAnonymousFunctionConversionError(DiagnosticBag diagnostics, TypeSymbol targetType)
41+
public override void GenerateAnonymousFunctionConversionError(BindingDiagnosticBag diagnostics, TypeSymbol targetType)
4242
{
4343
// TODO: improved diagnostics for query expressions
4444
base.GenerateAnonymousFunctionConversionError(diagnostics, targetType);
@@ -49,7 +49,7 @@ public override Binder ParameterBinder(LambdaSymbol lambdaSymbol, Binder binder)
4949
return new WithQueryLambdaParametersBinder(lambdaSymbol, _rangeVariableMap, binder);
5050
}
5151

52-
protected override BoundBlock BindLambdaBody(LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, DiagnosticBag diagnostics)
52+
protected override BoundBlock BindLambdaBody(LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, BindingDiagnosticBag diagnostics)
5353
{
5454
return _bodyFactory(lambdaSymbol, lambdaBodyBinder, diagnostics);
5555
}

src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs

Lines changed: 61 additions & 43 deletions
Large diffs are not rendered by default.

src/Compilers/CSharp/Portable/Binder/Binder.WithQueryLambdaParametersBinder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public WithQueryLambdaParametersBinder(LambdaSymbol lambdaSymbol, RangeVariableM
3030
}
3131
}
3232

33-
protected override BoundExpression BindRangeVariable(SimpleNameSyntax node, RangeVariableSymbol qv, DiagnosticBag diagnostics)
33+
protected override BoundExpression BindRangeVariable(SimpleNameSyntax node, RangeVariableSymbol qv, BindingDiagnosticBag diagnostics)
3434
{
3535
Debug.Assert(!qv.IsTransparent);
3636

@@ -65,7 +65,7 @@ protected override BoundExpression BindRangeVariable(SimpleNameSyntax node, Rang
6565
return base.BindRangeVariable(node, qv, diagnostics);
6666
}
6767

68-
private BoundExpression SelectField(SimpleNameSyntax node, BoundExpression receiver, string name, DiagnosticBag diagnostics)
68+
private BoundExpression SelectField(SimpleNameSyntax node, BoundExpression receiver, string name, BindingDiagnosticBag diagnostics)
6969
{
7070
var receiverType = receiver.Type as NamedTypeSymbol;
7171
if ((object)receiverType == null || !receiverType.IsAnonymousType)
@@ -88,17 +88,17 @@ private BoundExpression SelectField(SimpleNameSyntax node, BoundExpression recei
8888

8989
LookupResult lookupResult = LookupResult.GetInstance();
9090
LookupOptions options = LookupOptions.MustBeInstance;
91-
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
92-
LookupMembersWithFallback(lookupResult, receiver.Type, name, 0, ref useSiteDiagnostics, basesBeingResolved: null, options: options);
93-
diagnostics.Add(node, useSiteDiagnostics);
91+
CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = default;
92+
LookupMembersWithFallback(lookupResult, receiver.Type, name, 0, ref useSiteInfo, basesBeingResolved: null, options: options);
93+
diagnostics.Add(node, useSiteInfo);
9494

9595
var result = BindMemberOfType(node, node, name, 0, indexed: false, receiver, default(SeparatedSyntaxList<TypeSyntax>), default(ImmutableArray<TypeWithAnnotations>), lookupResult, BoundMethodGroupFlags.None, diagnostics);
9696
lookupResult.Free();
9797
return result;
9898
}
9999

100100
internal override void LookupSymbolsInSingleBinder(
101-
LookupResult result, string name, int arity, ConsList<TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
101+
LookupResult result, string name, int arity, ConsList<TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
102102
{
103103
Debug.Assert(result.IsClear);
104104

@@ -109,7 +109,7 @@ internal override void LookupSymbolsInSingleBinder(
109109

110110
foreach (var rangeVariable in _parameterMap[name])
111111
{
112-
result.MergeEqual(originalBinder.CheckViability(rangeVariable, arity, options, null, diagnose, ref useSiteDiagnostics));
112+
result.MergeEqual(originalBinder.CheckViability(rangeVariable, arity, options, null, diagnose, ref useSiteInfo));
113113
}
114114
}
115115

src/Compilers/CSharp/Portable/Binder/Binder.cs

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -457,52 +457,52 @@ internal OverloadResolution OverloadResolution
457457
}
458458
}
459459

460-
internal static void Error(DiagnosticBag diagnostics, DiagnosticInfo info, SyntaxNode syntax)
460+
internal static void Error(BindingDiagnosticBag diagnostics, DiagnosticInfo info, SyntaxNode syntax)
461461
{
462462
diagnostics.Add(new CSDiagnostic(info, syntax.Location));
463463
}
464464

465-
internal static void Error(DiagnosticBag diagnostics, DiagnosticInfo info, Location location)
465+
internal static void Error(BindingDiagnosticBag diagnostics, DiagnosticInfo info, Location location)
466466
{
467467
diagnostics.Add(new CSDiagnostic(info, location));
468468
}
469469

470-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, CSharpSyntaxNode syntax)
470+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, CSharpSyntaxNode syntax)
471471
{
472472
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code), syntax.Location));
473473
}
474474

475-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, CSharpSyntaxNode syntax, params object[] args)
475+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, CSharpSyntaxNode syntax, params object[] args)
476476
{
477477
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code, args), syntax.Location));
478478
}
479479

480-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxToken token)
480+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, SyntaxToken token)
481481
{
482482
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code), token.GetLocation()));
483483
}
484484

485-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxToken token, params object[] args)
485+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, SyntaxToken token, params object[] args)
486486
{
487487
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code, args), token.GetLocation()));
488488
}
489489

490-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax)
490+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax)
491491
{
492492
Error(diagnostics, code, syntax.GetLocation());
493493
}
494494

495-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax, params object[] args)
495+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax, params object[] args)
496496
{
497497
Error(diagnostics, code, syntax.GetLocation(), args);
498498
}
499499

500-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, Location location)
500+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, Location location)
501501
{
502502
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code), location));
503503
}
504504

505-
internal static void Error(DiagnosticBag diagnostics, ErrorCode code, Location location, params object[] args)
505+
internal static void Error(BindingDiagnosticBag diagnostics, ErrorCode code, Location location, params object[] args)
506506
{
507507
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code, args), location));
508508
}
@@ -526,7 +526,15 @@ internal void ReportDiagnosticsIfObsolete(DiagnosticBag diagnostics, Symbol symb
526526
}
527527
}
528528

529-
internal void ReportDiagnosticsIfObsolete(DiagnosticBag diagnostics, Conversion conversion, SyntaxNodeOrToken node, bool hasBaseReceiver)
529+
internal void ReportDiagnosticsIfObsolete(BindingDiagnosticBag diagnostics, Symbol symbol, SyntaxNodeOrToken node, bool hasBaseReceiver)
530+
{
531+
if (diagnostics.DiagnosticBag is object)
532+
{
533+
ReportDiagnosticsIfObsolete(diagnostics.DiagnosticBag, symbol, node, hasBaseReceiver);
534+
}
535+
}
536+
537+
internal void ReportDiagnosticsIfObsolete(BindingDiagnosticBag diagnostics, Conversion conversion, SyntaxNodeOrToken node, bool hasBaseReceiver)
530538
{
531539
if (conversion.IsValid && (object)conversion.Method != null)
532540
{
@@ -600,6 +608,21 @@ internal static void ReportDiagnosticsIfObsolete(
600608
}
601609
}
602610

611+
internal static void ReportDiagnosticsIfObsolete(
612+
BindingDiagnosticBag diagnostics,
613+
Symbol symbol,
614+
SyntaxNodeOrToken node,
615+
bool hasBaseReceiver,
616+
Symbol containingMember,
617+
NamedTypeSymbol containingType,
618+
BinderFlags location)
619+
{
620+
if (diagnostics.DiagnosticBag is object)
621+
{
622+
ReportDiagnosticsIfObsolete(diagnostics.DiagnosticBag, symbol, node, hasBaseReceiver, containingMember, containingType, location);
623+
}
624+
}
625+
603626
internal static ObsoleteDiagnosticKind ReportDiagnosticsIfObsoleteInternal(DiagnosticBag diagnostics, Symbol symbol, SyntaxNodeOrToken node, Symbol containingMember, BinderFlags location)
604627
{
605628
Debug.Assert(diagnostics != null);
@@ -626,29 +649,37 @@ internal static ObsoleteDiagnosticKind ReportDiagnosticsIfObsoleteInternal(Diagn
626649
return kind;
627650
}
628651

652+
internal static void ReportDiagnosticsIfObsoleteInternal(BindingDiagnosticBag diagnostics, Symbol symbol, SyntaxNodeOrToken node, Symbol containingMember, BinderFlags location)
653+
{
654+
if (diagnostics.DiagnosticBag is object)
655+
{
656+
ReportDiagnosticsIfObsoleteInternal(diagnostics.DiagnosticBag, symbol, node, containingMember, location);
657+
}
658+
}
659+
629660
internal static bool IsSymbolAccessibleConditional(
630661
Symbol symbol,
631662
AssemblySymbol within,
632-
ref HashSet<DiagnosticInfo> useSiteDiagnostics)
663+
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
633664
{
634-
return AccessCheck.IsSymbolAccessible(symbol, within, ref useSiteDiagnostics);
665+
return AccessCheck.IsSymbolAccessible(symbol, within, ref useSiteInfo);
635666
}
636667

637668
internal bool IsSymbolAccessibleConditional(
638669
Symbol symbol,
639670
NamedTypeSymbol within,
640-
ref HashSet<DiagnosticInfo> useSiteDiagnostics,
671+
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo,
641672
TypeSymbol throughTypeOpt = null)
642673
{
643-
return this.Flags.Includes(BinderFlags.IgnoreAccessibility) || AccessCheck.IsSymbolAccessible(symbol, within, ref useSiteDiagnostics, throughTypeOpt);
674+
return this.Flags.Includes(BinderFlags.IgnoreAccessibility) || AccessCheck.IsSymbolAccessible(symbol, within, ref useSiteInfo, throughTypeOpt);
644675
}
645676

646677
internal bool IsSymbolAccessibleConditional(
647678
Symbol symbol,
648679
NamedTypeSymbol within,
649680
TypeSymbol throughTypeOpt,
650681
out bool failedThroughTypeCheck,
651-
ref HashSet<DiagnosticInfo> useSiteDiagnostics,
682+
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo,
652683
ConsList<TypeSymbol> basesBeingResolved = null)
653684
{
654685
if (this.Flags.Includes(BinderFlags.IgnoreAccessibility))
@@ -657,7 +688,7 @@ internal bool IsSymbolAccessibleConditional(
657688
return true;
658689
}
659690

660-
return AccessCheck.IsSymbolAccessible(symbol, within, throughTypeOpt, out failedThroughTypeCheck, ref useSiteDiagnostics, basesBeingResolved);
691+
return AccessCheck.IsSymbolAccessible(symbol, within, throughTypeOpt, out failedThroughTypeCheck, ref useSiteInfo, basesBeingResolved);
661692
}
662693

663694
/// <summary>
@@ -666,8 +697,7 @@ internal bool IsSymbolAccessibleConditional(
666697
internal static void ReportUseSiteDiagnosticForSynthesizedAttribute(
667698
CSharpCompilation compilation,
668699
WellKnownMember attributeMember,
669-
bool recordUsage,
670-
DiagnosticBag diagnostics,
700+
BindingDiagnosticBag diagnostics,
671701
Location location = null,
672702
CSharpSyntaxNode syntax = null)
673703
{
@@ -677,7 +707,7 @@ internal static void ReportUseSiteDiagnosticForSynthesizedAttribute(
677707
// (comes from an unified assembly). When the symbol is not found no error is reported. See test VersionUnification_UseSiteDiagnostics_OptionalAttributes.
678708
bool isOptional = WellKnownMembers.IsSynthesizedAttributeOptional(attributeMember);
679709

680-
GetWellKnownTypeMember(compilation, attributeMember, recordUsage, diagnostics, location, syntax, isOptional);
710+
GetWellKnownTypeMember(compilation, attributeMember, diagnostics, location, syntax, isOptional);
681711
}
682712

683713
#if DEBUG

src/Compilers/CSharp/Portable/Binder/BinderFlags.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,26 @@ internal enum BinderFlags : uint
8787
/// </summary>
8888
IgnoreCorLibraryDuplicatedTypes = 1 << 26,
8989

90-
/// <summary>
91-
/// Set for a binder used to bind a using directive target
92-
/// </summary>
93-
InUsing = 1 << 27,
94-
9590
/// <summary>
9691
/// When binding imports in scripts/submissions, using aliases (other than from the current submission)
9792
/// are considered but other imports are not.
9893
/// </summary>
99-
InScriptUsing = 1 << 28,
94+
InScriptUsing = 1 << 27,
10095

10196
/// <summary>
10297
/// In a file that has been included in the compilation via #load.
10398
/// </summary>
104-
InLoadedSyntaxTree = 1 << 29,
99+
InLoadedSyntaxTree = 1 << 28,
105100

106101
/// <summary>
107102
/// This is a <see cref="ContextualAttributeBinder"/>, or has <see cref="ContextualAttributeBinder"/> as its parent.
108103
/// </summary>
109-
InContextualAttributeBinder = 1 << 30,
104+
InContextualAttributeBinder = 1 << 29,
110105

111106
/// <summary>
112107
/// Are we binding for the purpose of an Expression Evaluator
113108
/// </summary>
114-
InEEMethodBinder = 1U << 31,
109+
InEEMethodBinder = 1U << 30,
115110

116111
// Groups
117112

src/Compilers/CSharp/Portable/Binder/Binder_AnonymousTypes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.CSharp
1515
/// </summary>
1616
internal partial class Binder
1717
{
18-
private BoundExpression BindAnonymousObjectCreation(AnonymousObjectCreationExpressionSyntax node, DiagnosticBag diagnostics)
18+
private BoundExpression BindAnonymousObjectCreation(AnonymousObjectCreationExpressionSyntax node, BindingDiagnosticBag diagnostics)
1919
{
2020
// prepare
2121
var initializers = node.Initializers;
@@ -201,7 +201,7 @@ private bool IsAnonymousTypesAllowed()
201201
/// Returns the type to be used as a field type; generates errors in case the type is not
202202
/// supported for anonymous type fields.
203203
/// </summary>
204-
private TypeSymbol GetAnonymousTypeFieldType(BoundExpression expression, CSharpSyntaxNode errorSyntax, DiagnosticBag diagnostics, ref bool hasError)
204+
private TypeSymbol GetAnonymousTypeFieldType(BoundExpression expression, CSharpSyntaxNode errorSyntax, BindingDiagnosticBag diagnostics, ref bool hasError)
205205
{
206206
object errorArg = null;
207207
TypeSymbol expressionType = expression.Type;

0 commit comments

Comments
 (0)