Skip to content

Emit attribute changes for parameters#54835

Merged
davidwengier merged 18 commits intodotnet:mainfrom
davidwengier:EnCEmitParametersOnMethodUpdate
Jul 27, 2021
Merged

Emit attribute changes for parameters#54835
davidwengier merged 18 commits intodotnet:mainfrom
davidwengier:EnCEmitParametersOnMethodUpdate

Conversation

@davidwengier
Copy link
Copy Markdown
Member

Fixes #54777

This was a pain! In a way I'm glad I didn't do this while doing custom attributes because I probably would have gone crosseyed.

@davidwengier davidwengier requested review from a team as code owners July 15, 2021 05:10
@ghost ghost added the Area-Compilers label Jul 15, 2021
@davidwengier
Copy link
Copy Markdown
Member Author

Oh, as painful as some of this is, most of it is necessary for parameter renames anyway, so we get bang for our buck!

Comment thread src/Compilers/Core/Portable/Emit/SemanticEdit.cs Outdated
Comment thread src/Compilers/Core/Portable/Emit/EditAndContinue/DeltaMetadataWriter.cs Outdated
Comment thread src/Compilers/Core/Portable/Emit/SemanticEditOption.cs Outdated
Comment thread src/Compilers/Core/Portable/Emit/SemanticEdit.cs Outdated
Comment thread src/Compilers/Core/Portable/Emit/EditAndContinue/DeltaMetadataWriter.cs Outdated
Comment thread src/Compilers/Core/Portable/Emit/EditAndContinue/DeltaMetadataWriter.cs Outdated
Comment thread src/Compilers/Core/Portable/Emit/EditAndContinue/DeltaMetadataWriter.cs Outdated
@davidwengier
Copy link
Copy Markdown
Member Author

/azp run

@davidwengier
Copy link
Copy Markdown
Member Author

The build errors don't match the file contents ¯\_(ツ)_/¯

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@tmat
Copy link
Copy Markdown
Member

tmat commented Jul 21, 2021

    protected override void PopulateEncLogTableRows(ImmutableArray<int> rowCounts)

Let's make PopulateEncTables virtual and PopulateEncLogTableRows and PopulateEncMapTableRows private non-virtual.

Then _customAttributeEncMapRows and _paramEncMapRows can be passed between these methods isntead of being fields defined on the writer.


Refers to: src/Compilers/Core/Portable/Emit/EditAndContinue/DeltaMetadataWriter.cs:782 in c13f258. [](commit_id = c13f258, deletion_comment = False)

Copy link
Copy Markdown
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

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

🕐

@davidwengier davidwengier force-pushed the EnCEmitParametersOnMethodUpdate branch from c13f258 to 2dd3ad6 Compare July 23, 2021 04:16
@davidwengier
Copy link
Copy Markdown
Member Author

Tomas and I discussed offline and we decided to just have the compiler emit Param rows whenever a method is updated, rather than try to be smart about it. That simplifies this PR a lot, but unfortunately, and I normally hate to do this after a review has started, it did mean I had to rebase and force push to drop the relevant commits.

Copy link
Copy Markdown
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

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

:shipit:

@davidwengier
Copy link
Copy Markdown
Member Author

@cston Care to have another look?
@RikkiGibson Can you review?

Would love to get this in before snap tomorrow.

@RikkiGibson RikkiGibson self-assigned this Jul 27, 2021
}
}

if (methodChange == SymbolChange.Added)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm assuming the behavior of type parameters is unchanged here, i.e. adding an attribute to a type parameter during an EnC session is not supported.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, editing generic types is not supported.


private void EmitParametersFromDelta(IMethodDefinition methodDef, MethodDefinitionHandle handle)
{
var ok = _previousGeneration.FirstParamRowMap.TryGetValue(handle, out var firstRowId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It feels like it might be reasonable to fail in retail builds here if the handle isn't present, e.g. by changing the code to var firstRowId = _previousGeneration.FirstParamRowMap[handle]. However, I don't know exactly what the failure mode is here if we proceed into the loop with a firstRowId which is just 0 instead of being something meaningful for the given handle.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This would still fail later, when trying to emit an EncLog row for Param row 0, and I think that would give a more descriptive exception that "element not found".

Realistically this can only fail if someone changes how EnC works in a way that would break a lot of things, like perhaps allowing direct creation of a delta without a baseline, so a debug assert feels appropriate to me.

@davidwengier davidwengier merged commit 3d8acbd into dotnet:main Jul 27, 2021
@ghost ghost added this to the Next milestone Jul 27, 2021
@davidwengier davidwengier deleted the EnCEmitParametersOnMethodUpdate branch July 27, 2021 19:46
@davidwengier
Copy link
Copy Markdown
Member Author

Thanks all!

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.

EnC - Attribute updates on parameters don't get emitted

5 participants