This is an archive of the discontinued LLVM Phabricator instance.

[modules] While merging ObjCInterfaceDecl definitions, merge them as decl contexts too.
ClosedPublic

Authored by vsapsai on Sep 22 2021, 1:14 PM.

Details

Summary

While working on https://reviews.llvm.org/D110280 I've tried to merge
decl contexts as it seems to be correct and matching our handling of
decl contexts from different modules. It's not required for the fix in
https://reviews.llvm.org/D110280 but it revealed a missing diagnostic,
so separating this change into a separate commit.

Renamed some variables to distinguish diagnostic like "declaration of
'x' does not match" for different cases.

Diff Detail

Event Timeline

vsapsai created this revision.Sep 22 2021, 1:14 PM
vsapsai requested review of this revision.Sep 22 2021, 1:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2021, 1:14 PM
vsapsai updated this revision to Diff 380771.Oct 19 2021, 1:34 PM

Rebase as the pre-requisite change has landed.

Pre-merge checks are passing now after the rebase. I believe it is a straightforward change and we are merging decl contexts for other Decls already, so merging them for ObjCInterfaceDecl makes sense. If there are no objections, I plan to land the change on Friday, October 22. If any issues come up later, post-commit reviews are welcome as always.

Pre-merge checks are passing now after the rebase. I believe it is a straightforward change and we are merging decl contexts for other Decls already, so merging them for ObjCInterfaceDecl makes sense. If there are no objections, I plan to land the change on Friday, October 22. If any issues come up later, post-commit reviews are welcome as always.

Generally this sort of "if no one says anything I'll commit at this time" thing is to be avoided: The idea is that once something's been sent for review/the author has requested a second opinion, we want to avoid people committing that code without review only due to lack of feedback. Please reach out to reviewers to get a second set of eyes on this before committing.

rsmith added inline comments.Oct 19 2021, 5:16 PM
clang/lib/Serialization/ASTReaderDecl.cpp
1181–1184

A couple of other things you should consider doing in this case:

  • If there's an AST invariant that there is only one definition, think about how to maintain that invariant. For other kinds of declaration, we would update NewDD to make it act as a forward-declaration, but I'm not sure we can do much about it here given that an @interface is never a forward-declaration. Maybe for @interface there's nothing we can really do, and code dealing with these declarations just needs to handle there possibly being more than one definition?
  • Merge the definition visibility of the new definition into the canonical definition. This is necessary to ensure that in code for which the new definition is imported and the canonical definition is not, we still treat the canonical definition as being visible. (Eg, module A has the canonical definition, module B has another definition, module C imports A but doesn't re-export it, and C also imports B and re-exports it, and then you import C and try to use the class.)

For the latter, Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition) should be sufficient, assuming that all code treats the first definition as being the canonical one (for example, name lookups are performed into the first definition).

Pre-merge checks are passing now after the rebase. I believe it is a straightforward change and we are merging decl contexts for other Decls already, so merging them for ObjCInterfaceDecl makes sense. If there are no objections, I plan to land the change on Friday, October 22. If any issues come up later, post-commit reviews are welcome as always.

Generally this sort of "if no one says anything I'll commit at this time" thing is to be avoided: The idea is that once something's been sent for review/the author has requested a second opinion, we want to avoid people committing that code without review only due to lack of feedback. Please reach out to reviewers to get a second set of eyes on this before committing.

What would be a better way to deal with changes in areas where I'm more experienced in (Obj-C decl merging on AST deserialization) and still want to run pre-merge checks on other platforms? I got unofficial sign-offs internally but people defer to me because I've worked more in this area.

I believe this change is pretty trivial, while for D110452 I want another opinion. But one-line change in D110453 is trivial too and I don't think that waiting for reviews for half a year would improve its quality substantially.

vsapsai added inline comments.Oct 19 2021, 5:58 PM
clang/lib/Serialization/ASTReaderDecl.cpp
1181–1184

Change to merge visibility is D110453 and you are right, the code is simple, the main complexity is the test.

As for maintaining a single definition, we are already doing that (see my comment a few lines below in ASTDeclReader::VisitObjCInterfaceDecl). But not doing good job with ObjCInterfaceType::getDecl. The fix for that is D110452 but the summary is that ObjCInterfaceType stores the last encountered definition, it is never updated when we discard this definition, that not-so-definition-anymore is treated as a canonical definition.

Updating visibility doesn't work without D110452 because we might end up looking up a different "definition", not the one with correct[ed] visibility. And D110452 seems to be different enough, so I've split it out as a separate patch. I've made current change a separate patch for clear indication what code changes lead to changes in clang/test/Modules/odr_hash.mm, there is no technical reason it cannot be merged with other changes.

Also I should note that @interface tracking story isn't over yet, I still need to check and write tests for merging categories. They cannot have ivars, so don't expect IRGen issues but there is still enough room for other bugs.

1202–1206

Here we keep a single definition. Have a last chance to keep extra information from the second definition but afterwards just overwrite ID->Data.

rsmith accepted this revision.Oct 19 2021, 6:44 PM
rsmith added inline comments.
clang/lib/Serialization/ASTReaderDecl.cpp
1181–1184

OK, separating out those changes with separate tests makes sense to me. Thanks!

This revision is now accepted and ready to land.Oct 19 2021, 6:44 PM

Pre-merge checks are passing now after the rebase. I believe it is a straightforward change and we are merging decl contexts for other Decls already, so merging them for ObjCInterfaceDecl makes sense. If there are no objections, I plan to land the change on Friday, October 22. If any issues come up later, post-commit reviews are welcome as always.

Generally this sort of "if no one says anything I'll commit at this time" thing is to be avoided: The idea is that once something's been sent for review/the author has requested a second opinion, we want to avoid people committing that code without review only due to lack of feedback. Please reach out to reviewers to get a second set of eyes on this before committing.

What would be a better way to deal with changes in areas where I'm more experienced in (Obj-C decl merging on AST deserialization) and still want to run pre-merge checks on other platforms? I got unofficial sign-offs internally but people defer to me because I've worked more in this area.

Oh, sure - you can use Phabricator's draft support to just send the change for CI testing without sending a review to the mailing list: https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-command-line

I believe this change is pretty trivial, while for D110452 I want another opinion. But one-line change in D110453 is trivial too and I don't think that waiting for reviews for half a year would improve its quality substantially.

Reviews shouldn't/generally don't take half a year, especially for smaller, clearly correct changes. Pinging reviews if they're not getting traction can help get some attention, though sometimes more direct calls for assistance may be necessary/beneficial.

Thanks for the review! I'll commit this and other changes in the stack after testing with the current "main" and making sure the bots on other platforms are happy.

What would be a better way to deal with changes in areas where I'm more experienced in (Obj-C decl merging on AST deserialization) and still want to run pre-merge checks on other platforms? I got unofficial sign-offs internally but people defer to me because I've worked more in this area.

Oh, sure - you can use Phabricator's draft support to just send the change for CI testing without sending a review to the mailing list: https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-command-line

D'oh, haven't realized that. Thanks for the advice!

I believe this change is pretty trivial, while for D110452 I want another opinion. But one-line change in D110453 is trivial too and I don't think that waiting for reviews for half a year would improve its quality substantially.

Reviews shouldn't/generally don't take half a year, especially for smaller, clearly correct changes. Pinging reviews if they're not getting traction can help get some attention, though sometimes more direct calls for assistance may be necessary/beneficial.

Thanks, appreciate the advice. It is a sore subject for me, so I'll refrain from digging myself a deeper hole.