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

Properly implement import public. #329

Merged
merged 4 commits into from
Aug 28, 2019
Merged

Properly implement import public. #329

merged 4 commits into from
Aug 28, 2019

Conversation

judah
Copy link
Collaborator

@judah judah commented Aug 27, 2019

Fixes #19.

After this change, if bar.proto contains the line

import public foo.proto

Then it turns into

module Proto.Bar(..., module Proto.Foo) where

import Proto.Foo  -- unqualified, to allow the reexport of its definitions

The previous hacky approach was: Proto.Bar doesn't reexport Proto.Foo;
instead, if another file baz.proto imports bar.proto, then the codegen
of Proto.Baz imports Proto.Foo as well as Proto.Bar. This approach
let us avoid module-level exports, but had two limitations:

  1. It violated the principle of "strict dependencies", since Proto.Baz
    is importing what is essentially a transitive dependency.
  2. Non-codegen modules that import a proto module can't benefit from
    import public statements.

Fixes #19.

After this change, if `bar.proto` contains the line

    import public foo.proto

Then it turns into

```
module Proto.Bar(..., module Proto.Foo) where

import Proto.Foo  -- unqualified, to allow the reexport of its definitions
```

The previous hacky approach was: `Proto.Bar` doesn't reexport `Proto.Foo`;
instead, if another file `baz.proto` imports `bar.proto`, *then* the codegen
of `Proto.Baz` imports `Proto.Foo` as well as `Proto.Bar`.  This approach
let us avoid module-level exports, but had two limitations:

1) It violated the principle of "strict dependencies", since `Proto.Baz`
   is importing what is essentially a transitive dependency.
2) Non-codegen modules that import a proto module can't benefit from
   `import public` statements.
Copy link
Collaborator

@blackgnezdo blackgnezdo left a comment

Choose a reason for hiding this comment

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

I'll look at the code in a bit, for now some thoughts on the social aspects.

Could you add an entry to the ChangeLog describing this change? Maybe also mention on reddit and some Haskell mailing lists?

I imagine we can try this internally pretty easily. Do we have any users in Formation who could also try the change before the release?

@judah
Copy link
Collaborator Author

judah commented Aug 27, 2019

I can post an announcement to the Haskell list/reddit when we release the new version. We have a few changes queued up that will require a major bump; we can batch them together. I'll also see if we can get Formation to try out the new version before we release it.

@judah
Copy link
Collaborator Author

judah commented Aug 27, 2019

Updated the changelog.

@@ -3,6 +3,8 @@
## Pending
- Fix a potential naming conflict when message types and enum values
are the same except for case.
- Reexport transitive definitions from files with `import public` statements
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we draw attention to potentially breaking changes in some manner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made a separate "breaking changes" section, like we did for 0.5.0.0.

@@ -295,6 +295,9 @@ exportWith q = Syntax.EThingWith ()
q
. map (Syntax.ConName ())

exportModule :: ModuleName -> ExportSpec
Copy link
Collaborator

Choose a reason for hiding this comment

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

We haven't been particularly good about documenting this module, is this because it's not supposed to be user facing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it's not intended for use outside of this project. Also, hopefully soon it will be replaced by ghc-source-gen.

@@ -46,9 +44,12 @@ testFoo = testCase "testFoo" $ do

testUseDep :: Test
testUseDep = testCase "testUseDep" $ do
-- Due to "import public" statements, imports_dep.proto reexports the
Copy link
Collaborator

Choose a reason for hiding this comment

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

One of the existing tests seems to be detecting a difference suggesting the code is achieving the goal. Does it also make sense to add a new test just for this feature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is the right place for these tests since they're intended to test the effects of import public.

I changed this a little so it keeps the previous test cases and just adds new ones (showing the new behavior) rather than replacing them.

@judah judah merged commit 3e9cd10 into master Aug 28, 2019
@judah judah deleted the public-imports branch August 28, 2019 22:52
avdv pushed a commit to avdv/proto-lens that referenced this pull request Aug 9, 2023
Fixes google#19.

After this change, if `bar.proto` contains the line

    import public foo.proto

Then it turns into

```
module Proto.Bar(..., module Proto.Foo) where

import Proto.Foo  -- unqualified, to allow the reexport of its definitions
```

The previous hacky approach was: `Proto.Bar` doesn't reexport `Proto.Foo`;
instead, if another file `baz.proto` imports `bar.proto`, *then* the codegen
of `Proto.Baz` imports `Proto.Foo` as well as `Proto.Bar`.  This approach
let us avoid module-level exports, but had two limitations:

1) It violated the principle of "strict dependencies", since `Proto.Baz`
   is importing what is essentially a transitive dependency.
2) Non-codegen modules that import a proto module can't benefit from
   `import public` statements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finish support for "import public"
3 participants