-
-
Notifications
You must be signed in to change notification settings - Fork 667
Add support for Objective-C classes #9179
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
Conversation
|
Thanks for your pull request and interest in making D better, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9179" |
5f0e7c2 to
b1be7a6
Compare
| $(UL | ||
| $(LI `static` and `final` methods are virtual. Although `final` methods are | ||
| virtual it's not possible to override a `final` method in a subclass) | ||
| $(LI `static` methods are overridable in subclasses) |
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.
That sounds quite fishy. An extern declaration is used for compatibility, but we always stayed away from importing other language's semantic into D, as it's a hornets nest. It's fine to have final method as virtual if ObjC has no way to represent it, but allowing override static is downright confusing.
I assume this comes from the necessity to have it in the vtable, even if its static ?
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.
Class/static methods in Objective-C are instance methods on the metaclass. In Objective-C classes are object themselves.
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 assume this comes from the necessity to have it in the vtable, even if its static ?
There is no vtable for Objective-C classes. All method calls are lowered to a function in the Objective-C runtime.
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.
Without this, it is basically impossible to actually use existing Objective C classes. We sometimes need to be practical even when it sounds weird...
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.
@jacob-carlborg : Is there a way to expose this without changing the language ?
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.
Expose what? That static methods are overridable?
87b2ad8 to
4b99aba
Compare
|
Using the HEAD of this PR (`DMD64 D Compiler v2.084.0-rc.1-161-g4b99aba26) and slightly modifying the example code: void main()
{
auto foo = Foo.alloc.init;
scope (exit) foo.release();
assert(foo.bar(3) == 3);
pragma(msg, &__traits(getOverloads, Foo, "alloc"));
}
extern (Objective-C):
class NSObject
{
static NSObject alloc() @selector("alloc");
NSObject init() @selector("init");
void release() @selector("release");
}
class Foo : NSObject
{
override static Foo alloc() @selector("alloc");
override Foo init() @selector("init");
int bar(int a) @selector("bar:")
{
return a;
}
} |
The official documentation is in Ddoc .dd files. Trying to mix and match .md and .dd files will cause a lot of bugs and effort for others trying to build the dlang website. |
These files aren't part of the official user documentation, but for developers and in markdown as that's what GitHub understands when you browse those files on the web (which only DMD devs or very interested people would do). |
|
Thanks. |
|
@Geod24 that error in #9179 (comment) is not something new in this PR. It exists in current DMD. Well, it segfaults rather than asserts. |
aa470d3 to
cd471c2
Compare
|
I've fixed the #9179 (comment) comment now. I moved all the Objective-C specific semantic functions for function declaration to the first semantic phase, where the original were located. I'll leave the issue that @Geod24 mentioned because it was already present before this PR. It doesn't look like it's possible to take the address of a method in Objective-C. It's possible to replace methods at runtime in Objective-C, but the Objective-C runtime provides functions to get access to the actual implementation. Because of this I think we should make it illegal to take the address of a function with Objective-C linkage in D. |
|
@thewilsonator This is good to go, unless I should change the implementation of anonymous variable declarations, see: #9179 (comment). |
|
OSX64 auto-tester failed with Not particularly helpful message. |
I’ll have a look. |
It's a test that should fail to compile to succeeds. Hence the unhelpful message. |
Representing an Objective-C class as a D interface has been deprecated. Classes have now been properly implemented and the `class` keyword should be used instead. In the future, `extern(Objective-C)` interfaces will be used to represent Objective-C protocols.
90e5b77 to
c48b235
Compare
|
Looks like the tests are passing now. |
|
@thewilsonator everything is green. |
|
Auto-merge toggled on |
Why don't you use "auto-merge"? |
Seems he toggled it in the auto-tester UI and not here on GitHub. |
|
Bingo. I need to upgrade my system because GH has dropped support for it and broke almost everything in the process. |
So you're saying that your Chrome/Firefox doesn't allow you to add this anymore: FWIW it is still just a one-liner with their API and curl: |
|
I have an old iPad stuck at iOS 9. I can't add inline comments or set labels on that because the browser is too old. |

This PR contains a bit more code then I would like but it's difficult to reduce it anymore.
The PR consists of four commits and can be individually reviewed but doesn't make sense to split up in multiple PRs.
Spec update: dlang/dlang.org#2540.