Skip to content

Conversation

@ToddGrun
Copy link
Contributor

Additionally, reduce false positives in telemetry reporting inefficiencies in project system interactions wrt Preprocessor directives.

…hanges

Additionally, reduce false positives in telemetry reporting inefficiencies in project system interactions wrt Preprocessor directives.
@ToddGrun ToddGrun requested review from a team as code owners April 10, 2025 02:51
@ghost ghost added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 10, 2025
<CommandLineArgsForDesignTimeEvaluation Condition="'$(ChecksumAlgorithm)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -checksumalgorithm:$(ChecksumAlgorithm)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(DefineConstants)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -define:$(DefineConstants)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(Features)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -features:$(Features)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(DocumentationFile)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -doc:$(DocumentationFile)</CommandLineArgsForDesignTimeEvaluation>
Copy link
Member

Choose a reason for hiding this comment

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

This might need some quoting. Now, ironically, if all the IDE cares about is if it's set or not set, then it's kinda fine if it doesn't get quoting and only the first part of the file name is treated as part of the switch. But we should probably either quote, or leave a comment here that we don't actually care.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quotes FTW!

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Overall looks fine, some suggestions but that's just some improvements.

TryReportCompilationThrownAway(currentSolution, Id);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

If you could also make a paranoia change here: we should perhaps move all this sending of telemetry after the _projectPropertyModificationsInBatch.Add() line, so if this were to throw an exception, we're not corrupting state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good

{
if (oldValue is ParseOptions oldParseOptions)
{
var projectState = currentSolution.SolutionState.GetRequiredProjectState(Id);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than fetching the project to get language services, you should be able to shortcut and just do _projectSystemProjectFactory.SolutionServices.GetRequiredLanguageService(Language). That use of CurrentSolution should be fine, but this is probably shorter and doesn't require me to think about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's nicer.

Comment on lines 292 to 295
if (newValue is ParseOptions newParseOption)
{
if (oldValue is ParseOptions oldParseOptions)
{
Copy link
Member

Choose a reason for hiding this comment

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

Can we just do this logic in the ParseOptions setter and pass in logThrowAwayTelemetry appropriately? That way we're not doing this checks in other property tests, and we also skip all the stuff above which is probably not cheap either.

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'm a bit hesitant to move it to the caller as the code is currently running inside the _gate lock. I'd like to understand the concern a bit better. The code is only executed when logThrowAwayTelemetry is true, so it's just two of the callers, and the added code is only executed before the solution finishes loading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving it out would also mean adding exception handling to ensure the field was still updated

Copy link
Member

Choose a reason for hiding this comment

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

It's just a bit strange that this is applying to a specific case, but it's in the general helper.

Moving it out would also mean adding exception handling to ensure the field was still updated

What do you mean?

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 issues I see if the logThrowAwayTelemetry block were called outside and prior to ChangeProjectProperty:

  1. Exception handling would need to be added around the call to that block to ensure ChangeProjectProperty would continue to be called
  2. The block would probably need to be executed under the gate's protection (at least it is now, and I haven't tried to suss out if it need be)

I've added some comments that make things a bit clearer, I'm definitely willing to change things if you think there is a better way.

…onsInBatch

2) Simplify obtaining ISyntaxTreeFactoryService
3) Change version reference
4) Quote potential string containing value in targets files
<CommandLineArgsForDesignTimeEvaluation Condition="'$(ChecksumAlgorithm)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -checksumalgorithm:$(ChecksumAlgorithm)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(DefineConstants)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -define:$(DefineConstants)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(Features)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -features:$(Features)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(DocumentationFile)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -doc:"$(DocumentationFile)"</CommandLineArgsForDesignTimeEvaluation>
Copy link
Member

Choose a reason for hiding this comment

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

what do each of these correspond to?

Copy link
Member

Choose a reason for hiding this comment

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

perhaps doc why we want these.

if (!isFullyLoaded)
{
TryReportCompilationThrownAway(_projectSystemProjectFactory.Workspace.CurrentSolution, Id);
var reportCompilationThrownAway = true;
Copy link
Member

Choose a reason for hiding this comment

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

extract local function plz.

}

if (reportCompilationThrownAway)
TryReportCompilationThrownAway(_projectSystemProjectFactory.Workspace.CurrentSolution, Id);
Copy link
Member

Choose a reason for hiding this comment

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

mentioned offline. but there just isn't that many reasons why a prse option could change. we should actually detect what actually changed and report that as part of telem. For example, i'd love to know thigns like "90% of throwaways were caused by LangVersion changing", or something like that.

{
// Preprocessor directive only ParseOptions changes have special handling in DocumentState.UpdateParseOptionsAndSourceCodeKind.
// We don't want to report telemetry for those changes or for the initial evaluation result.
if (newValue is not ParseOptions newParseOption)
Copy link
Member

Choose a reason for hiding this comment

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

consider doc'ing the two flows that get here. one that is a ParsOptions one that is not. this was not clear to me :D

ToddGrun and others added 3 commits April 10, 2025 16:32
…stemProject.cs

Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com>
…stemProject.cs

Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com>
@ToddGrun
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler -- ptal

<CommandLineArgsForDesignTimeEvaluation Condition="'$(ChecksumAlgorithm)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -checksumalgorithm:$(ChecksumAlgorithm)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(DefineConstants)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -define:$(DefineConstants)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(Features)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -features:$(Features)</CommandLineArgsForDesignTimeEvaluation>
<CommandLineArgsForDesignTimeEvaluation Condition="'$(DocumentationFile)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -doc:"$(DocumentationFile)"</CommandLineArgsForDesignTimeEvaluation>
Copy link
Member

@jjonescz jjonescz Apr 14, 2025

Choose a reason for hiding this comment

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

I'm not sure how to review this change from the compiler's perspective. Ideally, I would like to see tests with different values passed here (e.g., to verify escaping works). But it seems this is really an IDE only property, not used by the compiler at all, right? In that case LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I don't really know how this fits into the compiler side of things, AFAIK this is just used as part of what the IDE feeds into the project build. @jasonmalinowski -- do you think this needs compiler side reviews too?

Copy link
Member

Choose a reason for hiding this comment

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

But it seems this is really an IDE only property, not used by the compiler at all, right? In that case LGTM

Correct; this only impacts the IDE side of things. I guess @jaredpar would be the arbiter here of whether he wants to see more reviews from his team or not.

Copy link
Member

Choose a reason for hiding this comment

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

Want to keep things simple and say that it's in the compiler code, we need two compiler sign offs. Even if the sign offs are as simple as us validating that "this is not compiler code"

Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

Verified compiler changes do not impact compiler.

@arunchndr arunchndr merged commit e7069f2 into dotnet:main Apr 18, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants