-
Notifications
You must be signed in to change notification settings - Fork 5k
Allow the CustomAttribute metadata table to be updated by ApplyChanges, with correct ordering #53066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
For an example of the issue: Given an initial compile with the following (partial) metadata:
When method
That
If a type were to be updated before (or at the same time, since types are sorted first) the method then the CustomAttribute table emitted as a delta might look like this instead:
Now when those rows are added to the table, it ends up out of order:
|
Tagging subscribers to this area: @tommcdon Issue DetailsThere is a bug in Roslyn, dotnet/roslyn#52816, which results in Edit and Continue/Hot Reload duplicating attributes when emitting updates to a method/type/etc. Roslyn is currently adding rows to the CustomAttributes table with every delta, regardless of what was emitted in the original compilation. To fix this I'm changing how we output the EncLog and EncMap tables, and from initial testing the runtime seems to be applying the updates correctly, updating existing CustomAttributes rows as necessary, and adding otherwise. Unfortunately the runtime expects the CustomAttributes table to be sorted by Parent, but does not currently maintain that sort order when applying updates. From an investigation by @lambdageek:
Before we can fix the Roslyn issue we probably need the runtime to be updated, otherwise it is unknown what things will break. It's worth noting that this bug exists right now, and the CustomAttributes table will already be getting out of order with updates, but fixing the Roslyn bug would make it worse. Right now each update to the CustomAttributes table at least includes all of the attributes for the thing being updated in order and in a contiguous block. If a binary search stumbled across a block of rows it would at least behave consistently. Presumably this hasn't caused any real problems in the past because of the reflection caches, however those are now being cleared. Also in the past updates to attributes would be rude edits, but we're also changing that by adding a new runtime capability. /cc @tmat @lambdageek @mikem8361 @tommcdon
|
@davidwengier, this might be a dumb question, but is there anyway that Roslyn can order the CustomAttributes by Parent? |
@mikem8361 I don't think we should do that as that would require emitting the entire CustomAttribute table on every change. The goal of EnC is to emit minimal delta, not reemit whole metadata tables. |
Roslyn is doing that, and within each delta the CustomAttributes table is ordered by parent. The issue is that after applying the updates (with info from EncLog) the resulting table ends up out of order. As Tomas says the only way for Roslyn to deal with this would be for it to emit the entire CustomAttrbutes table and have the runtime simply forget any previous data it had. This would be potentially very large, and very expensive though. |
I asked for some help from @jkotas on this and he says:
|
What Jan is saying is what I'd expect to happen as well. |
So there isn't actual an issue here? |
I don't know. Do we have a test that validates this works? Also, Mono does not have this mechanism so that needs to be addressed in Mono. |
Neither the runtime or the diagnosticstest have any ENC tests. Aleksey add some infrastructure and few simple hot reload tests. Nothing that would exercise this. |
Right, so the issue is that we need a test, otherwise we don't know if this works or not. |
Yep, that's tracked by #52993 |
Before we can add tests for this PR dotnet/roslyn#53507 needs to get merged. |
for C#-level tests the following needs to happen:
|
That is excellent news if this is not a problem.
This shouldn't be necessary to validate current behaviour. An example that would manifest the issue now: Initial code: [System.Obsolete]
class C
{
[System.Obsolete]
static void M() { }
} Updated code (add a class and method with attributes): [System.Obsolete]
class C
{
[System.Obsolete]
static void M() { }
}
[System.Obsolete]
class D
{
[System.Obsolete]
static void M() { }
} This results in two custom attributes tables being emitted that look like this:
and
If those two tables are concatenated without being re-sorted then that should be possible to validate in a test, right? |
@mikem8361 @davidwengier I added a draft PR with a new test like David suggested - should know how it goes pretty soon: |
Thanks! |
Can we close this issue now? Adding and changing custom attributes works, we have tests and a separate issue on "delete". |
Sounds good to me. Thanks for verifying @lambdageek |
There is a bug in Roslyn, dotnet/roslyn#52816, which results in Edit and Continue/Hot Reload duplicating attributes when emitting updates to a method/type/etc. Roslyn is currently adding rows to the CustomAttributes table with every delta, regardless of what was emitted in the original compilation.
To fix this I'm changing how we output the EncLog and EncMap tables, and from initial testing the runtime seems to be applying the updates correctly, updating existing CustomAttributes rows as necessary, and adding otherwise. Unfortunately the runtime expects the CustomAttributes table to be sorted by Parent, but does not currently maintain that sort order when applying updates.
From an investigation by @lambdageek:
Before we can fix the Roslyn issue we probably need the runtime to be updated, otherwise it is unknown what things will break.
It's worth noting that this bug exists right now, and the CustomAttributes table will already be getting out of order with updates, but fixing the Roslyn bug would make it worse. Right now each update to the CustomAttributes table at least includes all of the attributes for the thing being updated in order and in a contiguous block. If a binary search stumbled across a block of rows it would at least behave consistently. Presumably this hasn't caused any real problems in the past because of the reflection caches, however those are now being cleared. Also in the past updates to attributes would be rude edits, but we're also changing that by adding a new runtime capability.
/cc @tmat @lambdageek @mikem8361 @tommcdon
The text was updated successfully, but these errors were encountered: