-
Notifications
You must be signed in to change notification settings - Fork 13.7k
initial implementation of the darwin_objc unstable feature #145660
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred in compiler/rustc_hir/src/attrs |
This comment has been minimized.
This comment has been minimized.
I looked through the attribute changes and they look good to me. I can't judge the rest. @tmandry feel free to approve in both our names once you agree with the rest :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked through it, it seems to match what I tried to do with the objc2
macros those years back (which is not to say that it is correct, I had no idea what I was doing back then).
Also, it would be helpful with more comments, and a few codegen tests - I get why you haven't done that yet, it's bothersome while we're still somewhat discussing what the best approach is.
Note: I'm still a bit unsure that this is actually the correct approach going forward, I suspect there might be more value in the future from something like the define_in_every_cgu_used
you first proposed?
At the very least we'll also need some way to get protocol references, we might also need metaclass references, and possibly more if we're to support static NSString and support fully statically declared classes.
But I think it's fine to move forwards with this in the current state, then we can always figure that sort of stuff out well before stabilisation.
let mut classrefs = self.objc_classrefs.borrow_mut(); | ||
if let Some(classref) = classrefs.get(&classname).copied() { | ||
return classref; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so we're on the same page: It is basically this part that is the main feature here, right? I.e. that the symbol references are directly present in all translation units, and that they are deduplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. This self.objc_classrefs
is a per-CGU cache that allows us to deduplicate references within a codegen unit. But since this function ends up getting called in each CGU that references a class, we end up with definitions in all the referencing translations units and let the linker deduplicate across them. I'll add a comment to summarize that.
let extern_sym = format!("OBJC_CLASS_$_{}", classname.as_str()); | ||
let extern_llty = self.get_objc_class_t(); | ||
self.declare_global(&extern_sym, extern_llty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Does this add the unnamed_addr
attribute as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, should it? Clang doesn't generate unnamed_addr
here, and my understanding is unnamed_addr
is only useful for definitions with initializers, not external declarations like this.
}); | ||
set_global_alignment(self, g, self.tcx.data_layout.pointer_align().abi); | ||
llvm::set_initializer(g, llval); | ||
llvm::set_linkage(g, llvm::Linkage::PrivateLinkage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: In some places, you use PrivateLinkage
, in others InternalLinkage
. I assume this is intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just try to match what Clang does with these. My guess is they'd all work if they were all the same, but by mimicking Clang I figure it's more likely to continue to work with future linker versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrivateLinkage is basically InternalLinkage except that no symbol is generated in the object file.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
I added |
…RENCES_$_ and OBJC_SELECTOR_REFERENCES_
This comment has been minimized.
This comment has been minimized.
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #145728) made this pull request unmergeable. Please resolve the merge conflicts. |
Tracking issue: #145496
r? @tmandry