Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Straightforward bugfixes and trivial additions #6105

Merged
merged 2 commits into from Jul 18, 2018
Merged

Straightforward bugfixes and trivial additions #6105

merged 2 commits into from Jul 18, 2018

Conversation

acmyu
Copy link
Contributor

@acmyu acmyu commented Jul 17, 2018

Added some constants to FixupConstants.cs
Removed dead code from ImportSectionsTableNode.cs
Bugfix in VertexArray

Copy link
Member

@trylek trylek left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

_first = null;
_second = null;
}

Copy link
Member

Choose a reason for hiding this comment

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

I actually later fixed one more bug in the VertexArray in commit

trylek@f5cf18c

Please feel free to decide whether you'd prefer to cherrypick that from my commit and add to your change or deal with later.

Thanks a lot for doing this!

Tomas

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for incorporating the additional VertexArray fix, your change looks great to me!

@acmyu
Copy link
Contributor Author

acmyu commented Jul 17, 2018

@dotnet-bot Test this please

@@ -1731,20 +1752,31 @@ private Vertex ExpandBlock(int index, int depth, bool place, out bool isLeaf)
}
else
{
VertexTree tree = new VertexTree();
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to allocate and place the VertexTree here, only to have to unplace it/update it later? Can we just do the allocation/place call in the spot where tree.Update is called now and delete the Update and Pop APIs?

There's a lot of value in having immutable data structures. Plus the fact that we need multiple callsites to Pop at each exit from the method, all guarded with an assert proves how dangerous the new API is.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, these were the two "cleanups" I originally made during my "loose rewrite" of the code from CPP. And the changes Amy is reviewing right now amount to reverting both of them and putting them back in sync with the original C++ code at

https://github.com/dotnet/coreclr/blob/1c8c96ec2bb52368124928648d7557ac85ff9c40/src/zap/nativeformatwriter.cpp#L220

because both turned out to be incorrect.

  1. The order of calling "Place" defines the ordering of the nodes within the saved vertex blob and the somewhat tricky design algorithm is apparently carefully designed so that, in each tree node, the "left" subtree is at a lower address than the "right" subtree - this is required by the internal encoding format of the runtime function table.

  2. I originally removed the Pop logic because I incorrectly convinced myself that it's only used for C++ dynamic memory management (deletion of heap blocks that turned out to be unused), however in fact it turns out this is also needed for correctness of the algorithm as the recursive algorithm intentionally removes some previously added nodes.

Frankly speaking I still don't understand all details of this algorithm, I just did three iterative passes to make it behave the same as the C++ algorithm, at some point I even ended up stepping through both of them in parallel. I agree with your general observation that the algorithm could be probably made easier to reason; I'm however worried that the same holds for many other routines in CoreCLR and I sincerely doubt there's enough budget in the cross-plat AOT IL compiler project to clean them all up.

Thanks

Tomas

@acmyu acmyu merged commit cdd2842 into dotnet:r2r Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants