Skip to content

Speculative semantic model - create child member models for attributes and parameter default values.#64634

Merged
AlekseyTs merged 5 commits intodotnet:mainfrom
AlekseyTs:Issue60801_02
Oct 14, 2022
Merged

Speculative semantic model - create child member models for attributes and parameter default values.#64634
AlekseyTs merged 5 commits intodotnet:mainfrom
AlekseyTs:Issue60801_02

Conversation

@AlekseyTs
Copy link
Contributor

Fixes #60801.
Fixes #24135.

This could occur when member semantic models were used to support/represent speculative semantic models.
This change gets us one step closer to addressing dotnet#60801.
…for attributes and parameter default values.

Fixes dotnet#60801.
Fixes dotnet#24135.
@CyrusNajmabadi
Copy link
Contributor

@jasonmalinowski anything in particular you wanted me to hone in on? Overall this looks fine to me :)

@jasonmalinowski
Copy link
Member

@CyrusNajmabadi No; this needed some IDE reviewer and you seemed like a good choice.

@CyrusNajmabadi
Copy link
Contributor

Gotcha. LGTM.

@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler For the second review.

@jcouv jcouv self-assigned this Oct 13, 2022
@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler For the second review.

using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp
{
Copy link
Member

@jcouv jcouv Oct 13, 2022

Choose a reason for hiding this comment

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

Consider adding xml doc.
nit: extra blank line below #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider adding xml doc.

I think the name is descriptive enough and captures everything that the doc comment would say.

namespace Microsoft.CodeAnalysis.CSharp
{
/// <summary>
/// Instances of this <see cref="SemanticModel"/> can be exposed to external consumers.
Copy link
Member

@jcouv jcouv Oct 13, 2022

Choose a reason for hiding this comment

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

Do we have a comment somewhere explaining why some instances should not be exposed to external customers? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a comment somewhere explaining why some instances should not be exposed to external customers?

This would violate the design.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't follow how having a comment (I'm not talking about xml doc) would violate the design.

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 didn't follow how having a comment (I'm not talking about xml doc) would violate the design.

Sorry for the confusion. I was not referring to having a comment, but to exposing other instances to external consumers. Doing that would violate the design.

(binder: containing.GetEnclosingBinder(attribute.SpanStart), model: containing));
}

private MemberSemanticModel GetOrAddModelForParameter(SyntaxNode node, MemberSemanticModel containing, ParameterSyntax paramDecl)
Copy link
Member

@jcouv jcouv Oct 13, 2022

Choose a reason for hiding this comment

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

This seem very close or duplicated from SyntaxTreeSemanticModel.GetOrAddModelForParameter. Could we factorize? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we factorize?

I considered that, but didn't think the refactoring worth the trouble.

_parentSemanticModel = parentSemanticModel;
_position = position;
_parentSnapshotManagerOpt = snapshotManagerOpt;
_memberModel = null!;
Copy link
Member

@jcouv jcouv Oct 13, 2022

Choose a reason for hiding this comment

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

How is this safe? Never mind, this ctor is private, and other constructors that depend on it make sure to initialize _memberModel. #Closed

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 4) with some minor comments/questions

@AlekseyTs AlekseyTs merged commit c12de00 into dotnet:main Oct 14, 2022
@ghost ghost added this to the Next milestone Oct 14, 2022
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.

Speculation within attributes on local functions is broken Speculative semantic model produces different behavior for local functions

6 participants