Skip to content

Conversation

@cston
Copy link
Contributor

@cston cston commented Apr 5, 2020

Reduce the size of the stack frames in ConstraintsHelper.CheckConstraints() overloads for nested constraint types.

For the cycle of calls from SourceTypeParameterSymbolBase.GetBounds(), reduces the overhead by:

  • x64: 18% from master
  • x86: 5% from master

Fixes #42361

@cston cston force-pushed the 42361 branch 4 times, most recently from 75e8be2 to db08f2b Compare April 7, 2020 18:03
@cston cston changed the base branch from master to release/dev16.6 April 7, 2020 18:03
@cston cston marked this pull request as ready for review April 7, 2020 20:26
@cston cston requested a review from a team as a code owner April 7, 2020 20:26
type.VisitType(s_checkConstraintsSingleTypeFunc, new CheckConstraintsArgs(compilation, conversions, includeNullability, location, diagnostics));
}

private readonly struct CheckConstraintsArgs
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 7, 2020

Choose a reason for hiding this comment

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

CheckConstraintsArgs [](start = 32, length = 20)

Moving this structure is going to create unnecessary merge conflicts with feature branches, please move it back #Closed

if (type.Kind == SymbolKind.NamedType)
{
((NamedTypeSymbol)type).CheckConstraints(args.CurrentCompilation, args.Conversions, args.IncludeNullability, args.Location, args.Diagnostics);
((NamedTypeSymbol)type).CheckConstraints(args);
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 7, 2020

Choose a reason for hiding this comment

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

args [](start = 57, length = 4)

Would it make sense to pass it by ref here as well? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The argument is passed by reference - the CheckConstraints() parameter is in.


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

Copy link
Member

Choose a reason for hiding this comment

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

nit: consider using an explicit 'in' where possible for clarity.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 2)

@cston cston added this to the 16.6.P3 milestone Apr 8, 2020
@RikkiGibson RikkiGibson self-requested a review April 8, 2020 19:33
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var result = !typeSyntax.HasErrors && CheckTypeConstraints(type, conversions, includeNullability, currentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt: diagnosticsBuilder, ref useSiteDiagnosticsBuilder);
var result = !typeSyntax.HasErrors && CheckTypeConstraints(type, conversions, currentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt: includeNullability ? diagnosticsBuilder : null, ref useSiteDiagnosticsBuilder);
Copy link
Member

Choose a reason for hiding this comment

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

nit: line is 244 characters, consider wrapping new lines for the arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave these long lines as-is since the issues were not introduced in this change.


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

var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var result = CheckTypeConstraints(type, conversions, includeNullability, currentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt: diagnosticsBuilder, ref useSiteDiagnosticsBuilder);
var result = CheckTypeConstraints(type, args.Conversions, args.CurrentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt: args.IncludeNullability ? diagnosticsBuilder : null, ref useSiteDiagnosticsBuilder);
Copy link
Member

Choose a reason for hiding this comment

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

nit: long line

var typeParameter = typeParameters[i];

if (!CheckConstraints(containingSymbol, conversions, includeNullability, substitution, typeParameter, typeArgument, currentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt, ref useSiteDiagnosticsBuilder,
if (!CheckConstraints(containingSymbol, conversions, substitution, typeParameter, typeArgument, currentCompilation, diagnosticsBuilder, nullabilityDiagnosticsBuilderOpt, ref useSiteDiagnosticsBuilder,
Copy link
Member

Choose a reason for hiding this comment

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

nit: long line

{
int n = (ExecutionConditionUtil.Architecture, ExecutionConditionUtil.Configuration) switch
{
(ExecutionArchitecture.x86, ExecutionConfiguration.Debug) => 420,
Copy link
Member

Choose a reason for hiding this comment

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

Is this change fixing a regression in our ability to handle complex constraint graphs? Or improving our ability past where it has historically been?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change improves the ability to handle complex constraint graphs, although 15.9 uses less stack space still.


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

@cston cston merged commit 4e5a229 into dotnet:release/dev16.6 Apr 8, 2020
@cston cston deleted the 42361 branch April 8, 2020 21:29
@cston cston mentioned this pull request Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler StackOverflow

3 participants