Skip to content

Commit 9dc30e4

Browse files
committed
work on darwin_objc PR feedback
1 parent f9be4b3 commit 9dc30e4

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ pub(crate) struct ObjcClassParser;
164164
impl<S: Stage> SingleAttributeParser<S> for ObjcClassParser {
165165
const PATH: &[rustc_span::Symbol] = &[sym::rustc_objc_class];
166166
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
167-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
167+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
168168
const ALLOWED_TARGETS: AllowedTargets =
169-
AllowedTargets::AllowListWarnRest(&[Allow(Target::ForeignStatic)]);
169+
AllowedTargets::AllowList(&[Allow(Target::ForeignStatic)]);
170170
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "ClassName");
171171

172172
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
@@ -193,9 +193,9 @@ pub(crate) struct ObjcSelectorParser;
193193
impl<S: Stage> SingleAttributeParser<S> for ObjcSelectorParser {
194194
const PATH: &[rustc_span::Symbol] = &[sym::rustc_objc_selector];
195195
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
196-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
196+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
197197
const ALLOWED_TARGETS: AllowedTargets =
198-
AllowedTargets::AllowListWarnRest(&[Allow(Target::ForeignStatic)]);
198+
AllowedTargets::AllowList(&[Allow(Target::ForeignStatic)]);
199199
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "methodName");
200200

201201
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ pub(crate) fn compile_codegen_unit(
111111

112112
// Define Objective-C module info for 32-bit x86 macOS. Note, this generates a global
113113
// that gets added to the `llvm.compiler.used` variable, created later.
114+
//
115+
// This is only necessary when we need the linker to do its Objective-C-specific magic.
116+
// We could theoretically do it unconditionally, but at a slight cost to linker
117+
// performance in the common case where it's unnecessary.
114118
let uses_objc =
115119
!cx.objc_classrefs.borrow().is_empty() || !cx.objc_selrefs.borrow().is_empty();
116120
if uses_objc && cx.tcx.sess.target.arch == "x86" && cx.tcx.sess.target.os == "macos" {
@@ -141,6 +145,10 @@ pub(crate) fn compile_codegen_unit(
141145
}
142146

143147
// Add Objective-C module flags.
148+
//
149+
// This is only necessary when we need the linker to do its Objective-C-specific magic.
150+
// We could theoretically do it unconditionally, but at a slight cost to linker
151+
// performance in the common case where it's unnecessary.
144152
if uses_objc {
145153
cx.add_objc_module_flags();
146154
}

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@ impl<'ll> CodegenCx<'ll, '_> {
588588
class_t
589589
}
590590

591+
// We do our best here to match what Clang does when compiling Objective-C natively. We
592+
// deduplicate references within a CGU, but we need a reference definition in each referencing
593+
// CGU. All attempts at using external references to a single reference definition result in
594+
// linker errors.
591595
fn get_objc_classref(&self, classname: Symbol) -> &'ll Value {
592596
let mut classrefs = self.objc_classrefs.borrow_mut();
593597
if let Some(classref) = classrefs.get(&classname).copied() {
@@ -631,6 +635,10 @@ impl<'ll> CodegenCx<'ll, '_> {
631635
g
632636
}
633637

638+
// We do our best here to match what Clang does when compiling Objective-C natively. We
639+
// deduplicate references within a CGU, but we need a reference definition in each referencing
640+
// CGU. All attempts at using external references to a single reference definition result in
641+
// linker errors.
634642
fn get_objc_selref(&self, methname: Symbol) -> &'ll Value {
635643
let mut selrefs = self.objc_selrefs.borrow_mut();
636644
if let Some(selref) = selrefs.get(&methname).copied() {
@@ -684,6 +692,13 @@ impl<'ll> CodegenCx<'ll, '_> {
684692
assert_eq!(self.tcx.sess.target.arch, "x86");
685693
assert_eq!(self.tcx.sess.target.os, "macos");
686694

695+
// struct _objc_module {
696+
// long version; // Hardcoded to 7 in Clang.
697+
// long size; // sizeof(struct _objc_module)
698+
// char *name; // Hardcoded to classname "" in Clang.
699+
// struct _objc_symtab* symtab; // Null without class or category definitions.
700+
// }
701+
687702
let llty = self.type_named_struct("struct._objc_module");
688703
let i32_llty = self.type_i32();
689704
let ptr_llty = self.type_ptr();

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
709709
},
710710
);
711711

712-
if self.tcx.sess.target.abi == "sim" {
712+
if self.tcx.sess.target.env == "sim" {
713713
llvm::add_module_flag_u32(
714714
self.llmod,
715715
llvm::ModuleFlagMergeBehavior::Error,

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,11 +1049,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
10491049
EncodeCrossCrate::No,
10501050
),
10511051
rustc_attr!(
1052-
rustc_objc_class, Normal, template!(NameValueStr: "ClassName"), FutureWarnPreceding,
1052+
rustc_objc_class, Normal, template!(NameValueStr: "ClassName"), ErrorPreceding,
10531053
EncodeCrossCrate::Yes,
10541054
),
10551055
rustc_attr!(
1056-
rustc_objc_selector, Normal, template!(NameValueStr: "methodName"), FutureWarnPreceding,
1056+
rustc_objc_selector, Normal, template!(NameValueStr: "methodName"), ErrorPreceding,
10571057
EncodeCrossCrate::Yes,
10581058
),
10591059

library/core/src/os/darwin/objc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Defines types and macros for Objective-C interoperability.
22
33
#![unstable(feature = "darwin_objc", issue = "145496")]
4+
#![allow(nonstandard_style)]
45

56
use crate::fmt;
67

library/core/src/os/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! OS-specific functionality.
22
33
#![unstable(feature = "darwin_objc", issue = "145496")]
4-
#![allow(nonstandard_style)]
54

65
// darwin
76
#[cfg(not(all(

0 commit comments

Comments
 (0)