Refactor Objective-C frontend integration#6679
Conversation
|
Also the C++ headers need updating with all necessary removals/additions, but otherwise a welcome step in the right direction. |
src/ddmd/objc.d
Outdated
There was a problem hiding this comment.
I'm not a big fan of trailing _. We don't use it anyplace else.
There was a problem hiding this comment.
What do you suggest instead, a leading _? The trailing underscore is there to avoid conflict with the objc function [1].
[1] https://github.com/dlang/dmd/pull/6679/files#diff-6c74f81a6d424346a88e4920f9f16869R245
There was a problem hiding this comment.
I switch the trailing underscore to a leading.
src/ddmd/mars.d
Outdated
There was a problem hiding this comment.
_init isn't a great name, but perhaps we should be consistent here.
There was a problem hiding this comment.
Ok, so to fix this name and remove the renamed import, should I move the initialize function to a static method inside the Objc interface and name it _init?
There was a problem hiding this comment.
The initialize function has been moved into the Objc interface as a static method and renamed to _init. At the call site it's now: Objc._init();.
src/ddmd/mars.d
Outdated
There was a problem hiding this comment.
We don't use this style anyplace else in dmd.
There was a problem hiding this comment.
I'll remove the renamed import.
It's a bit difficult to know which D features can be used. Are there some guidelines for DMD somewhere?
|
I like this much better than the last one. Some gripes about names used. |
Last one being #4813 ? :-) |
Yes, I forgot about that. A general question, what does need to be exposed as |
Thanks, I'll fix the names. |
ibuclaw
left a comment
There was a problem hiding this comment.
A general question, what does need to be exposed as extern(C++), the whole AST?
Added notes inline.
src/ddmd/objc.d
Outdated
There was a problem hiding this comment.
I guess remove everything except struct ObjcSelector from objc.h.
There was a problem hiding this comment.
However in my C++ port, I'll probably include class Objc { }; with all these virtual functions. So I'm on the sideline here, as I don't want to deviate the C++ interface too much from upstream, but at the same time, this will be a non-issue once switching to D front-end.
The question was a bit off-topic, but I was referring to DMD in general and not specific to this PR. |
In the strictest sense, anything that is used by the codegen routines. Just what is used depends on the compiler. It sometimes requires a shout out to prevent things being internalise as extern(D). |
Ok, thanks. I assume GDC and LDC uses their own glue layer and not the same as DMD, so they would need more declarations as |
e1f67db to
e6ac8aa
Compare
Indeed, there may be information about the compilation that gdc/ldc uses that dmd does not. But it also works the other way, as there is a lot of parts that are dmd specific too - almost littered, infact. |
|
@ibuclaw I updated the header files. Could you please verify those changes? |
src/ddmd/objc.d
Outdated
There was a problem hiding this comment.
I see you put it in the headers, in which case this should be extern(C++) interface.
There was a problem hiding this comment.
Yes, of course, I forgot that.
There was a problem hiding this comment.
Fixed. I also made the constructors extern(D).
There was a problem hiding this comment.
@ibuclaw The change to extern(C++) seems to cause every platform to fail in the auto tester. But it works fine locally (on macOS).
There was a problem hiding this comment.
I'll try the patch locally (linux 64bit)
There was a problem hiding this comment.
However looking at the travisci builds, it looks like it's only gdc that fails. And pretty much all autotester builds. So maybe we're triggering some lament C++ class bug in the frontend that has since fixed (I can't reproduce with gdc master). I think the autotester uses 2.067.
There was a problem hiding this comment.
What happens if you exchange interface Objc with class Objc ?
There was a problem hiding this comment.
Just pushed that change.
There was a problem hiding this comment.
Seems to work better. At least the druntime build now passes.
There was a problem hiding this comment.
Looks like that fixed it. Or at least it has built phobos w/o hitting a segv.
| ObjcSelector* selector; | ||
|
|
||
| extern (D) this(FuncDeclaration fdecl) | ||
| static void _init() |
There was a problem hiding this comment.
Oh! I apologise as I forgot, this static method should definitely be extern(C++) at the very least, because gdc's entrypoint is in C++.
| static void _init() | ||
| { | ||
| this.fdecl = fdecl; | ||
| if (global.params.isOSX && global.params.is64bit) |
There was a problem hiding this comment.
This condition is OK for now, but I'd like to move it to somewhere else in future. Maybe some Compiler interface, as Target doesn't quite fit.
Yes. Until the interface is split up or refactored into a more compartmentalized structure, LDC basically needs access to the full AST (not all fields and methods are used at any given time, of course, but I believe there are a few cases where we use stuff in our glue code that DMD doesn't.) |
825296a to
0003536
Compare
src/ddmd/objc.d
Outdated
There was a problem hiding this comment.
Private should be extern(D) too.
0003536 to
327a5f7
Compare
src/ddmd/aggregate.h
Outdated
There was a problem hiding this comment.
Another name nit. Note the subsequent isscope and isabstract as all lower case. isObjc looks like a function name, perhaps isobjc is better and more consistent with other usage.
There was a problem hiding this comment.
Ok, I can fix that. I tried to go with the standard D naming conventions.
862671b to
844266f
Compare
|
I don't see a button where I can approve this, but I do approve it. |
|
@WalterBright if you go to the " Files changed" tab, you should see a "Review changes button". When you click it, you should get three options: Request changes, Approve and Comment. |
|
I would like to squash the commits before this is merged. |
a33e12e to
69a50ac
Compare
|
Rebased. |
|
The error is now the same as before: |
This file is now shared for all platforms after the Objective-C integration refactoring: dlang/dmd#6679.
|
@ibuclaw Found the issue why DAutoTest was failing. I created another PR for that: dlang/dlang.org#1636. |
69a50ac to
7fef02e
Compare
|
@ibuclaw @WalterBright All tests are green now except for DAutoTest which needs this PR dlang/dlang.org#1636 and vibe.d which looks unrelated (other PRs have the same issue). |
|
@ibuclaw @WalterBright is there anything stopping this from being merged? |
src/ddmd/dclass.d
Outdated
There was a problem hiding this comment.
Nit-pick, can we remove the scope parameter here? It's only used for checking sc.linkage, which can be instead moved here.
There was a problem hiding this comment.
I'll fix this.
|
|
||
| struct Objc_ClassDeclaration | ||
| class Objc | ||
| { |
There was a problem hiding this comment.
I'll fix this.
Need |
|
Built on gdc with my two requested changes applied. Looks good, so I'm just awaiting your fix ups. |
7fef02e to
1f5f2e9
Compare
|
@ibuclaw everything fixed and rebased. |
1f5f2e9 to
62cb676
Compare
src/ddmd/objc.h
Outdated
There was a problem hiding this comment.
Aren't we forgetting something? 😉
There was a problem hiding this comment.
I truly hate header files 😃. Fixed.
The major reason for this refactoring is to move the decision if the Objective-C integration is enabled or not from a compile time (when building the compiler) decision using the makefile to a runtime (when running the compiler) decision. This allows to remove the extra objc_stubs.d file and is required for a cross-compilers like LDC, GDC and when DMD is cross-compiling for x86 64bit <-> 32bit.
62cb676 to
9fe35b1
Compare
|
@ibuclaw All tests are green now. |
|
Ping @WalterBright - I assume you are an admin who can merge this? dlang/dlang.org#1636 should fix the failing DAutoTest check, but requires this be in first. |
|
@WalterBright ping, Iain already toggled this for auto merging, but this other PR is necessary as well for dlang.org: dlang/dlang.org#1636. |
|
Auto-merge toggled on |
|
Thanks. |
This file is now shared for all platforms after the Objective-C integration refactoring: dlang/dmd#6679.
|
Doc build fixed by dlang/dlang.org#1636. |
The major reason for this refactoring is to move the decision if the Objective-C integration is enabled or not from a compile time (when building the compiler) decision using the makefile to a runtime (when running the compiler) decision. This allows to remove the extra
objc_stubs.dfile and is required for a cross-compilers like LDC, GDC and when DMD is cross-compiling for x86 64bit <-> 32bit.I will followup with a pull request for refactoring the glue layer parts in the same way when this pull request is accepted.