Skip to content

dmd: Move all public C++ functions into a dmd namespace#16155

Merged
ibuclaw merged 1 commit intodlang:masterfrom
ibuclaw:dmd_namespace
Feb 13, 2024
Merged

dmd: Move all public C++ functions into a dmd namespace#16155
ibuclaw merged 1 commit intodlang:masterfrom
ibuclaw:dmd_namespace

Conversation

@ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Feb 5, 2024

As discussed @kinke / @RazvanN7.

extern(C++) can/should be move to separate PR - I've just bundled it all in here, as it was simpler to fix them up so they didn't appear in the regexp I was using to match functions as I was going through them.


Update: now all extern(C++) top-level functions are in one (boilerplate) leaf module.

@ibuclaw ibuclaw requested review from RazvanN7 and kinke February 5, 2024 15:16
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ibuclaw!

Bugzilla references

Your 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 locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#16155"

@ibuclaw ibuclaw added Severity:Refactoring No semantic changes to code Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code labels Feb 5, 2024
@ibuclaw ibuclaw force-pushed the dmd_namespace branch 3 times, most recently from 887474d to 693828a Compare February 5, 2024 19:53
@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 6, 2024

Might have to park this for a while, the ability to import symbols in C++ "namespaces" wasn't added until 2.087.

https://issues.dlang.org/show_bug.cgi?id=19893

Workaround is to (1) remove all selective imports, and (2) add these in the same module as the definition.

static if (__VERSION__ < 2087)
{
    public Expression ctfeInterpret(Expression e)
    {
        return __traits(getMember, dmd.dinterpret.dmd, "ctfeInterpret")(e);
    }
}

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 9, 2024

Might have to park this for a while, the ability to import symbols in C++ "namespaces" wasn't added until 2.087.

https://issues.dlang.org/show_bug.cgi?id=19893

Workaround is to (1) remove all selective imports, and (2) add these in the same module as the definition.

static if (__VERSION__ < 2087)
{
    public Expression ctfeInterpret(Expression e)
    {
        return __traits(getMember, dmd.dinterpret.dmd, "ctfeInterpret")(e);
    }
}

Sitting on this, I think alternatively this could be turned on its head.

  1. Remove extern(C++) from all these functions.
// dmd.mtype
extern (D) Type mutableOf(Type t) { ... }
  1. Create a new leaf module for exposing D code to the C++ API.
module dmd.cxxfrontend;
static import dmd.mtype;
extern(C++, "dmd"):
Type mutableOf(Type t)
{
    return dmd.mtype.mutableOf(t);
}

@kinke any better ideas?

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 12, 2024

Now all C++ definitions have been put in a leaf module - not compiled into DMD, but for the C++ FE unittester only - there's nothing blocking this. We can continue having 2.079 as our baseline version, this module is only for GDC and LDC anyway.

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 12, 2024

@kinke I'm yet to give this a test against gdc, but please do have a glance at it regardless. I've put a few functions in version(IN_LLVM) because gdc doesn't call them from the C++ side.

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 12, 2024

One extern(C++) definition escaped my regex - #16182 - with that additional change, everything links. For my own sanity, have tested bootstrapping from gdc-9, gdc-11, and gdc-13.

@thewilsonator thewilsonator added Compiler:GDC Gnu D Compiler Compiler:LDC LLVM based D Compiler labels Feb 13, 2024
@RazvanN7
Copy link
Contributor

Looks good to me. Mind the conflict and we are good to go.

@kinke any objections?

@kinke
Copy link
Contributor

kinke commented Feb 13, 2024

No objections, should be good. I probably won't be able to check this before merging v2.108 into LDC, so might follow up then.

@ibuclaw ibuclaw force-pushed the dmd_namespace branch 2 times, most recently from 9e2cd96 to c393016 Compare February 13, 2024 18:59
@ibuclaw ibuclaw merged commit c137da8 into dlang:master Feb 13, 2024
@ibuclaw ibuclaw deleted the dmd_namespace branch February 13, 2024 20:05
ibuclaw added a commit to ibuclaw/dmd that referenced this pull request Apr 4, 2025
These are all exposed under a dmd namespace (dlang#16155)
thewilsonator pushed a commit that referenced this pull request Apr 5, 2025
These are all exposed under a dmd namespace (#16155)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compiler:GDC Gnu D Compiler Compiler:LDC LLVM based D Compiler Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code Merge:auto-merge Severity:Refactoring No semantic changes to code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants