Skip to content
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

[BUG] Modules support #269

Closed
JohelEGP opened this issue Mar 10, 2023 · 7 comments
Closed

[BUG] Modules support #269

JohelEGP opened this issue Mar 10, 2023 · 7 comments
Labels

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented Mar 10, 2023

Describe the bug
A clear and concise description of what the bug is.

  1. export module a; doesn't work in -pure-cpp2 mode.
  2. #include "cpp2util.h" should be inserted in the GMF.
    Additional work might also be necessary.
    1. CPP2_USE_MODULES shouldn't be defined while preprocessing it, as imports can't come from an #include.
    2. With regards to the #ifdef CPP2_USE_MODULES,
      its #ifdef __cpp_modules branch of should happen after the GMF, and
      its #else branch in the GMF.
  3. No declaration can be exported. It's not part of the grammar, and as such can't happen in the generated code.
    I suppose one can also run into an issue due to the lack of support for inline, similar to Fix duplicate symbol of cpp2::args() function #268.

To Reproduce
Steps to reproduce the behavior:

  1. Sample code - distilled down to minimal essentials please
    1. https://godbolt.org/z/7bP99nr4q
    2. https://godbolt.org/z/1f4Tr4bxM
    3. https://godbolt.org/z/rY6WG38nx
  2. Command lines including which C++ compiler you are using
    1. Happens at the cppfront level.
    2. TBD
    3. Happens at the cppfront level.
  3. Expected result - what you expected to happen
    1. Cpp2 supports exporting modules.
    2. The functionality provided by the generated #include "cpp2util.h" also works in module units.
    3. Declarations can be exported.
  4. Actual result/error
    1. example.cpp2(1,1): error: pure-cpp2 switch disables Cpp1 syntax
      
    2. error: declaration of 'operator new' in module main follows declaration in the global module
      
    3. example.cpp2(2,13): error: missing semicolon at end of declaration (at 'namespace')
      example.cpp2(2,1): error: unexpected text at end of Cpp2 code section (at 'ns')
      example.cpp2(2,0): error: parse failed for section starting here
      

Additional context
Add any other context about the problem here.

@JohelEGP JohelEGP added the bug Something isn't working label Mar 10, 2023
@gregmarr
Copy link
Contributor

I haven't seen anything about CPP2 having export support yet.

@JohelEGP
Copy link
Contributor Author

That's right. This is partly what this is about. I accidentally submitted it while editing.

@gregmarr
Copy link
Contributor

I just meant that I don't see this as a bug but as not yet implemented.

@JohelEGP
Copy link
Contributor Author

I have updated the bug report.

I could try implementing this. Where in the grammar should the export for declarations go?

//G unnamed-declaration:
//G     ':' template-parameter-declaration-list? function-type '=' statement
//G     ':' template-parameter-declaration-list? type-id? '=' statement
//G     ':' template-parameter-declaration-list? type-id
//G     ':' template-parameter-declaration-list? 'type' meta-constraints? '=' statement
//G     ':' 'namespace' '=' statement
//G
//G declaration:
//G     access-specifier? identifier unnamed-declaration
//G
//G access-specifier:
//G     public
//G     protected
//G     private

@hsutter
Copy link
Owner

hsutter commented Mar 11, 2023

[[meta]]

Timing note for @JohelEGP and @filipsajdak: As you can see I've started the preliminary work to implement UDTs, and I plan to do further major extension and cleanup in the remaining March weekends, plus probably a week of vacation to work on cppfront. So it might make sense to defer new/updated PRs until after March ends as things will quiet down again about three weeks from now, otherwise you'll probably find yourself with conflicts/rebasing.


@JohelEGP Thanks! There's basic modules support in mixed Cpp1/Cpp2 files, and one reason I've put further modules support lower down the design/implementation backlog list is because GCC and Clang don't support them yet (though I know support is in progress). Modules is the only major feature of C++20 (or C++23) that is available on only one of the three major implementations (see Clang status)... even <format> (the other big feature that's been lagging) is further along and on the cusp of wide support being imminent in GCC 13 and being largely supported in Clang if you enable "experimental" ABI-unstable features. Given that modules don't really exist yet for portable code, I've pushed them down the backlog, though I hasten to add that Cpp2 is still a modules-first design... I can't wait for compilers to implement C++20!

I think export would go in the grammar on declaration... possibly as part of access-specifier because if export can't be put on individual class members, then it could share the same grammar production as public/private/protected since it's mutually exclusive with them. I did the same thing with implicit which shares a single this-specifier production with the virtual/override/final specifiers. (In today's Cpp1 grammar, explicit, virtual, override, and final are split up in five productions... function-specifier and base-specifier for the first one, explicit-specifier for the second, and virt-specifier and class-virt-specifier for the last two.)

@JohelEGP
Copy link
Contributor Author

That makes sense. Thank you. I'm looking forward to your continued work.

@filipsajdak
Copy link
Contributor

@hsutter I will continue and will do the rebate.

I will be mainly focusing on bugs and fixes making my project compilable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants