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

proto3 standard compatibility improvements #143

Merged
merged 14 commits into from
Jun 28, 2021

Conversation

tim2CF
Copy link
Collaborator

@tim2CF tim2CF commented Mar 22, 2021

  • Added DotProtoMessageOption constructor to support options inside messages, provided example, included to tests, example
  • Added globalIdentifier parser to support leading dots on field types, provided example, included to tests, example
  • Fixed SwaggerObject conditional compilation bug here
  • Fixed shell.nix (cabal might not like wget installed on host machine) here
  • Added CircleCI support
  • Added proposal related to protoc plugins here
  • Need help with this

Copy link
Contributor

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

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

Looks great! Just one suggestion

@@ -126,6 +126,8 @@ instance CanonicalRank DotProtoMessagePart
DotProtoMessageReserved _fs -> Left (Right ())
-- We use '()' here because 'Canonicalize [DotProtoMessagePart]'
-- collapses all of the 'DotProtoMessageReserved's into just one.
DotProtoMessageOption _ -> Left (Right ())
Copy link
Contributor

Choose a reason for hiding this comment

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

So I'm new to this section of the code, too, but I think I know what we need to do here. Basically, this module is formatting a .proto file with everything in a specified order. The way that it works is that it maps each node in the syntax tree to some type that has an Ord instance and then uses that Ord instance to sort them.

This part of the code would probably be clearer and easier to fix if you first make a small refactor to replace the weird nested Either type with a new separate datatype, like this:

data PartRank
    = PartRankDefinition (Int, DotProtoIdentifier)
    | PartRankReserved
    | PartRankField (Maybe FieldNumber)

instance CanonicalRank DotProtoMessagePart where
    canonicalRank = \case
      DotProtoMessageField f -> PartRankField (canonicalRank f)
      DotProtoMessageOneOf _ fs -> PartRankField (canonicalRank f)
      DotProtoMessageDefinition d -> PartRankDefinition (canonicalRank d)
      DotProtoMessageReserved _ -> PartRankReserved 

… and then once you refactor it like that then it's easier to add in a new constructor for message options, like this:

data PartRank
    = PartRankDefinition (Int, DotProtoIdentifier)
    | PartRankReserved
    | PartRankField (Maybe FieldNumber)
    | PartRankOption DotProtoOption

instance CanonicalRank DotProtoMessagePart where
    canonicalRank = \case
      DotProtoMessageField f -> PartRankField (canonicalRank f)
      DotProtoMessageOneOf _ fs -> PartRankField (canonicalRank f)
      DotProtoMessageDefinition d -> PartRankDefinition (canonicalRank d)
      DotProtoMessageReserved _ -> PartRankReserved 
      DotProtoMessageOption o -> PartRankOption o

I haven't type-checked that suggestion, so there might be a few mistakes or other things that would need to be fixed, but I think that's the general idea of how to go about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Gabriel439 thanks for advise, it worked perfectly! Fixed in 699277b

I also changed order of PartRank constructors to provide more logical ordering of protobuf AST.

Copy link
Contributor

@evanrelf evanrelf left a comment

Choose a reason for hiding this comment

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

I don't understand the "Added CircleCI support" part of this pull request, since we don't use CircleCI. What's your intention adding .circleci/config.yml?

@21it
Copy link
Contributor

21it commented Mar 22, 2021

I don't understand the "Added CircleCI support" part of this pull request, since we don't use CircleCI. What's your intention adding .circleci/config.yml?

We are using CircleCI, in our fork, you can see it there https://github.com/coingaming/proto3-suite/commits/master
In general, CirecleCI is quite popular and working CircleCI config might be useful for people who fork this library, and want CI to be working from the box.

But if you don't want it - I can remove it for sure.

@evanrelf
Copy link
Contributor

@tkachuk-labs I think it would be best if you removed it from the pull request to avoid confusion. I don't think it's common for open source projects to have multiple CI configs unless they're actually using those CI services.

@21it
Copy link
Contributor

21it commented Mar 22, 2021

@evanrelf sure, no problem!

@tim2CF
Copy link
Collaborator Author

tim2CF commented Mar 23, 2021

@evanrelf done in 699277b

Copy link
Contributor

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

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

Looks great! Just one last thing

DotProtoMessageOption x -> PartRankOption x
DotProtoMessageDefinition d -> PartRankDefinition (canonicalRank d)
DotProtoMessageReserved _fs -> PartRankReserved
-- We don't use '_fs' here because 'Canonicalize [DotProtoMessagePart]'
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment needs to be relocated above the DotProtoMessageOneOf case after your change

Copy link
Collaborator Author

@tim2CF tim2CF Mar 24, 2021

Choose a reason for hiding this comment

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

But it was like this before. Comment is related to DotProtoMessageReserved _fs AST node. So it depends on style of codebase - should I put comment after related to comment line, or before.

DotProtoMessageReserved _fs -> Left (Right ())
-- We use '()' here because 'Canonicalize [DotProtoMessagePart]'
-- collapses all of the 'DotProtoMessageReserved's into just one.

@tim2CF
Copy link
Collaborator Author

tim2CF commented Mar 24, 2021

I did added swagger2isAbove_2_4_0 optional flag here. It's needed for being able to get suitable version of proto3-suite.proto3-suite-linux executable, which can properly generate hs files from proto files according version of swagger2 used in application project. By default, before it always was generating hs files for swagger2 version > 2.4.0, and this caused compilation errors in generated code. Another possible solution is to move CPP conditional compilation to generated code itself, but it seems harder to do.

     * Couldn't match expected type `HsJSONPB.SwaggerType                                 
                                       'swagger2-2.3.1.1:Data.Swagger.Internal.           
 SwaggerKindSchema                                                                        
 '                                                                                        
                   with actual type `Hs.Maybe                                             
                                       (HsJSONPB.SwaggerType                              
                                          'swagger2-2.3.1.1:Data.Swagger.Internal.        
 SwaggerKindSch                                                                           
 ema)'                                                                                    
     * In the `_paramSchemaType' field of a record                                        
       In the `_schemaParamSchema' field of a record                                      
       In the `_namedSchemaSchema' field of a record                                      
     |                                                                                    
 134 |                                                                  Hs.Just HsJSONPB. 
 Swagger                                                                                  
 Object},                                                                                 
     |                                                                                    
 ^^^^^^^^^^^^^^^^^^^^^^^^                                                                 
 ^^^^^^                                                                                   

@Gabriella439
Copy link
Contributor

@tim2CF: I added you as a collaborator so that you can merge this whenever you think this is ready

@tim2CF
Copy link
Collaborator Author

tim2CF commented Apr 1, 2021

Thanks, Gabriel!

@Gabriella439
Copy link
Contributor

You're welcome! 🙂

@evanrelf
Copy link
Contributor

@tim2CF I made some non-trivial changes to the Nix code in another PR (#159) which conflict with the changes you made here. Would you mind if I pushed to your branch to fix up the Nix stuff?

After that, unless anything else is left to be done, I think this'll be ready to merge!

@tim2CF
Copy link
Collaborator Author

tim2CF commented Jun 22, 2021

@tim2CF I made some non-trivial changes to the Nix code in another PR (#159) which conflict with the changes you made here. Would you mind if I pushed to your branch to fix up the Nix stuff?

After that, unless anything else is left to be done, I think this'll be ready to merge!

Sure @evanrelf ! I've got busy with the other stuff, so if you will help me to fix conflicts and finally merge, this will be super cool!

@evanrelf
Copy link
Contributor

Hmm... @tim2CF, can you see if this option is enabled in the pull request sidebar?

I can't seem to push to coingaming/proto3-suite's master branch:

ERROR: Permission to coingaming/proto3-suite.git denied to evanrelf.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Or maybe I've misunderstood that GitHub option?

@tim2CF
Copy link
Collaborator Author

tim2CF commented Jun 25, 2021

@evanrelf seems like organization github accounts don't have this feature, but I did invited you as a contributor directly from our fork repo. Please try it

@evanrelf
Copy link
Contributor

evanrelf commented Jun 25, 2021

I invited you as a contributor directly from our fork repo

Thanks, that worked. This branch is now updated with the latest changes from master.

@tim2CF Since Gabriel gave you the commit bit, feel free to merge whenever you're ready!

EDIT: And feel free to remove me from coingaming/proto3-suite afterwards if you want.

@tim2CF
Copy link
Collaborator Author

tim2CF commented Jun 28, 2021

Cool, thanks for the help @evanrelf !

@tim2CF tim2CF merged commit 9a89cc0 into awakesecurity:master Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants