Skip to content

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented May 20, 2020

Mitigates a few issues by disabling some fixes/refactorings in presence of top-level statements:

Relates to #43563 (test plan for top-level statements)

@jcouv jcouv self-assigned this May 20, 2020
@jcouv jcouv marked this pull request as ready for review May 20, 2020 05:08
@jcouv jcouv requested a review from a team as a code owner May 20, 2020 05:08
@jcouv
Copy link
Member Author

jcouv commented May 20, 2020

Tagging @CyrusNajmabadi @sharwell @AlekseyTs
Fixing those scenarios is not trivial given timeline, so I'm adding temporary mitigations.

@CyrusNajmabadi
Copy link
Member

I'm fine with blocking tihs. But what tracks reenabling them? I would totally expect these to work by ship time :)

}
</Document>
</Project>
</Workspace>",
Copy link
Member

Choose a reason for hiding this comment

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

surprised you used the <workspace> form here. Was that necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know it's possible to using XML approach starting with <Project> directly. Will simplify.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, on second thought, when I removed <Workspace> in test TopLevelStatement_Nested below, it started outputting XML instead of just source. I'm not sure how this works. Is it okay to leave <Workspace> here?

</Document>
</Project>
</Workspace>",
new TestParameters(parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp8)));
Copy link
Member

Choose a reason for hiding this comment

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

i'm confused by the Project xml specifying the lang version and the test specifying something different.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, sorry about that.
I can remove the .WithLanguageVersion (tests would still work).
But since it's the main change I'd make to address feedback and the PR has already gone through CI, I'm tempted to leave as-is until the scenarios get properly fixed. Let me know if that's okay.

public async Task TopLevelStatement_ArgumentInInvocation()
{
// Note: the cast should be simplified
// https://github.com/dotnet/roslyn/issues/44260
Copy link
Member

Choose a reason for hiding this comment

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

this issue doesn't seem related.

Copy link
Member Author

Choose a reason for hiding this comment

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

The cast gets correctly simplified for similar situation inside in a method, so the problem may be specific to top-level statement somehow.

if (method.IsNonImplicitAndFromSource())
{
var methodNode = root.FindNode(method.Locations[0].SourceSpan);
if (methodNode.RawKind == syntaxFacts.SyntaxKinds.GlobalStatement)
Copy link
Member

Choose a reason for hiding this comment

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

this is pretty ugly. tbh i'm not even sure why this works. Why does looking for the span of a method end up with the node for a GlocalStatement?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason for this specific code is that later in the fixer we use this logic (root.FindNode(method.Locations[0]..., see AddParameterService.cs line 104) to find the parameter list to update. But that fails because we find a top-level statement.

The .Locations[0] seemed correct (it's the identifier/name of the local function).
But the FindNode logic has tie-breaker rule and flag getInnermostNodeForTie.

I suspect the ultimate fix might be using getInnermostNodeForTie=true, but didn't have time to explore fully.


var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
if (localFunction && syntaxFacts.ContainsGlobalStatement(root))
Copy link
Member

Choose a reason for hiding this comment

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

this is weird. so if i'm extracting to a local function from within a method in a class in a file that hsa global statements, i'm just blocked?

Copy link
Member Author

Choose a reason for hiding this comment

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

At the moment yes. I agree it's weird experience :-/

MethodExtractor.CodeGenerator.GenerateAsync (line 96-100, where we handle local function scenario) and CSharpCodeGenerationService.AddStatement (line 467) is where the problem seems to be, But the logic there is complex enough that I couldn't extract/replicate a simple condition for when it won't work.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

since this is just disabling for stability, i'm fine. but we have ot ensure that we actually fix this before shipping.

@jcouv
Copy link
Member Author

jcouv commented May 20, 2020

But what tracks reenabling them?

The linked issues will remain open.

@jcouv
Copy link
Member Author

jcouv commented May 20, 2020

It looks like @sharwell has a solution ready for InlineTemp, so I'm reverting that portion of the PR.

@jcouv jcouv merged commit a118521 into dotnet:features/SimplePrograms May 20, 2020
@jcouv jcouv deleted the simple-inline branch May 20, 2020 20:15
@AlekseyTs AlekseyTs added this to the 16.7.P2 milestone May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants