Skip to content

Refactor Objective-C frontend integration#6679

Merged
WalterBright merged 1 commit intodlang:masterfrom
jacob-carlborg:objc_refactor
Apr 25, 2017
Merged

Refactor Objective-C frontend integration#6679
WalterBright merged 1 commit intodlang:masterfrom
jacob-carlborg:objc_refactor

Conversation

@jacob-carlborg
Copy link
Contributor

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.

I will followup with a pull request for refactoring the glue layer parts in the same way when this pull request is accepted.

@ibuclaw
Copy link
Member

ibuclaw commented Apr 6, 2017

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of trailing _. We don't use it anyplace else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switch the trailing underscore to a leading.

src/ddmd/mars.d Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_init isn't a great name, but perhaps we should be consistent here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use this style anyplace else in dmd.

Copy link
Contributor Author

@jacob-carlborg jacob-carlborg Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@WalterBright
Copy link
Member

I like this much better than the last one. Some gripes about names used.

@ibuclaw
Copy link
Member

ibuclaw commented Apr 6, 2017

I like this much better than the last one. Some gripes about names used.

Last one being #4813 ? :-)

@jacob-carlborg
Copy link
Contributor Author

Also the C++ headers need updating with all necessary removals/additions, but otherwise a welcome step in the right direction.

Yes, I forgot about that.

A general question, what does need to be exposed as extern(C++), the whole AST?

@jacob-carlborg
Copy link
Contributor Author

I like this much better than the last one. Some gripes about names used.

Thanks, I'll fix the names.

Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general question, what does need to be exposed as extern(C++), the whole AST?

Added notes inline.

src/ddmd/objc.d Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess remove everything except struct ObjcSelector from objc.h.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jacob-carlborg
Copy link
Contributor Author

A general question, what does need to be exposed as extern(C++), the whole AST?

Added notes inline.

The question was a bit off-topic, but I was referring to DMD in general and not specific to this PR.

@ibuclaw
Copy link
Member

ibuclaw commented Apr 7, 2017

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).

@jacob-carlborg
Copy link
Contributor Author

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 extern(C++) than DMD?

@ibuclaw
Copy link
Member

ibuclaw commented Apr 7, 2017

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 extern(C++) than DMD?

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. ☺️

@jacob-carlborg
Copy link
Contributor Author

@ibuclaw I updated the header files. Could you please verify those changes?

src/ddmd/objc.d Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you put it in the headers, in which case this should be extern(C++) interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course, I forgot that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I also made the constructors extern(D).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibuclaw The change to extern(C++) seems to cause every platform to fail in the auto tester. But it works fine locally (on macOS).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try the patch locally (linux 64bit)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you exchange interface Objc with class Objc ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work better. At least the druntime build now passes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dnadlinger
Copy link
Contributor

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 extern(C++) than DMD?

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.)

@jacob-carlborg jacob-carlborg force-pushed the objc_refactor branch 2 times, most recently from 825296a to 0003536 Compare April 8, 2017 10:05
Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

src/ddmd/objc.d Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private should be extern(D) too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can fix that. I tried to go with the standard D naming conventions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@WalterBright
Copy link
Member

I don't see a button where I can approve this, but I do approve it.

@PetarKirov
Copy link
Member

@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.

@jacob-carlborg
Copy link
Contributor Author

I would like to squash the commits before this is merged.

ibuclaw
ibuclaw previously approved these changes Apr 9, 2017
@ibuclaw ibuclaw dismissed their stale review April 9, 2017 09:21

Dismissed.

Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squash/merge changes.

@jacob-carlborg
Copy link
Contributor Author

Rebased.

@jacob-carlborg
Copy link
Contributor Author

The error is now the same as before:

../dmd/src/ddmd/func.d(39): Error: module objc is in file 'ddmd/objc.d' which cannot be read

jacob-carlborg added a commit to jacob-carlborg/dlang.org that referenced this pull request Apr 17, 2017
This file is now shared for all platforms after the Objective-C
integration refactoring: dlang/dmd#6679.
@jacob-carlborg
Copy link
Contributor Author

@ibuclaw Found the issue why DAutoTest was failing. I created another PR for that: dlang/dlang.org#1636.

@jacob-carlborg
Copy link
Contributor Author

@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).

@jacob-carlborg
Copy link
Contributor Author

@ibuclaw @WalterBright is there anything stopping this from being merged?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit-pick, can we remove the scope parameter here? It's only used for checking sc.linkage, which can be instead moved here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


struct Objc_ClassDeclaration
class Objc
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert public: here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@ibuclaw
Copy link
Member

ibuclaw commented Apr 21, 2017

@ibuclaw @WalterBright is there anything stopping this from being merged?

Need public: in the objc header which allows me to call Objc::_init from GDC, and to backport this patch for the benefit of the C++ frontend. :-)

@ibuclaw
Copy link
Member

ibuclaw commented Apr 22, 2017

Built on gdc with my two requested changes applied. Looks good, so I'm just awaiting your fix ups.

@jacob-carlborg
Copy link
Contributor Author

@ibuclaw everything fixed and rebased.

src/ddmd/objc.h Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we forgetting something? 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@jacob-carlborg
Copy link
Contributor Author

@ibuclaw All tests are green now.

@ibuclaw
Copy link
Member

ibuclaw commented Apr 22, 2017

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.

@jacob-carlborg
Copy link
Contributor Author

@WalterBright ping, Iain already toggled this for auto merging, but this other PR is necessary as well for dlang.org: dlang/dlang.org#1636.

@WalterBright
Copy link
Member

Auto-merge toggled on

@WalterBright WalterBright merged commit c142eaa into dlang:master Apr 25, 2017
@jacob-carlborg
Copy link
Contributor Author

Thanks.

@jacob-carlborg jacob-carlborg deleted the objc_refactor branch April 25, 2017 11:18
schuetzm pushed a commit to dlang/dlang.org that referenced this pull request Apr 25, 2017
This file is now shared for all platforms after the Objective-C
integration refactoring: dlang/dmd#6679.
@MartinNowak
Copy link
Member

Doc build fixed by dlang/dlang.org#1636.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Comments