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

Gen hackery #761

Merged
merged 6 commits into from
Jun 6, 2022
Merged

Gen hackery #761

merged 6 commits into from
Jun 6, 2022

Conversation

endgame
Copy link
Collaborator

@endgame endgame commented Mar 11, 2022

I had hoped to teach gen how to handle recursive shape definitions in general, but ran out of time and mainline project work re-starts from next week. This at least lets us regenerate everything, as previously rds-data failed to generate due to a three-deep recursive cycle.

This PR teaches gen to handle recursive shape definitions.

@endgame endgame requested a review from brendanhay March 11, 2022 06:09
@endgame
Copy link
Collaborator Author

endgame commented Mar 11, 2022

@brendanhay I tried generating a Ptr every time we see a type that we've seen before, basically by generalising the condition on the below line to n `elem` seen:

| conseq seen = pure $! n :< Ptr (s ^. info) (pointerTo n s)

When I tried to generate bindings for dynamodb (it's a service I know reasonably well), it failed to generate lens prefixes on labels, like what happened when you tried to generate kendra bindings (reported at #730). This makes me think that there's some rewriting pass or something that doesn't add the prefixes correctly if it sees a Ptr instead of a proper recursive shape; do you have any insights?

Otherwise, I hope we can at least turn the handle on some of the new services, and get a big regenerate in sometime in the next few weeks.

@RobertFischer
Copy link

RobertFischer commented Mar 11, 2022 via email

@endgame
Copy link
Collaborator Author

endgame commented Mar 12, 2022

If you mean the PR as a whole, no: we need to be able to regen services.

If you mean the Ptr stuff, then I still think that's unwise: I think there's probably something else afoot that we ignore at our peril. AIUI, the eventual plan for lens is to avoid the lens dependency (so callers can use either generic-lens or generic-optics, but still provide VL lenses for data types under unambiguous names.

@endgame endgame mentioned this pull request Mar 23, 2022
@brendanhay
Copy link
Owner

brendanhay commented Mar 24, 2022

Need to run this and poke around to rebuild my memory index as nothing concrete comes to mind.

I suspect your intuition is correct, ie. elaborate from the flat JSON parse result (shape) -> recursive cofree, then probably only rename the top-level without descending into the recursive shape to rename all references, or something similarly stupid.

@endgame
Copy link
Collaborator Author

endgame commented Mar 25, 2022

That would be excellent. I wasn't able to grok that part of the generator, so if you get a chance to test my theory, I'd be very grateful.

@endgame
Copy link
Collaborator Author

endgame commented Apr 22, 2022

@brendanhay Starting next week, I should have a couple of work weeks where I can give amazonka some more attention. If you can get a chance to look at the generator before then, I'd really appreciate it. If not, then I intend to merge this to unblock things (we can't gen right now for some services we previously could; I suspect the change to hash functions in hashable ^>=1.4) and see what i can get done.

This allows rds-data to successfully gen once again.
@endgame
Copy link
Collaborator Author

endgame commented Apr 27, 2022

@brendanhay Some friends and I found what we believe to be a subtle bug in the way the seen list was being tracked inside elaborate: when recursing into refs, the refs would add themselves to the seen list. If the root object adds itself to seen, then it looks like we can unconditionally generate Ptr when we hit a shape that we've seen before. Because seen is cleared each time we explore a value in the input HashMap, we guarantee that we never memoise a Ptr and that the top level structures are always StructF, so generation still proceeds.

It would be great if you could review b3985cd in particular, but I'm happy to merge and get back to fixing services if you're busy.

@endgame
Copy link
Collaborator Author

endgame commented Apr 27, 2022

When I tried to generate bindings for dynamodb (it's a service I know reasonably well), it failed to generate lens prefixes on labels, like what happened when you tried to generate kendra bindings (reported at #730)...

This appears to be fixed, too.

gen/src/Gen/Types/Config.hs Outdated Show resolved Hide resolved
@endgame
Copy link
Collaborator Author

endgame commented Apr 29, 2022

For some libraries with recursive definitions (e.g., wafv2; #736), this version of gen successfully generates code, but the generated library will not build thanks to a module import cycle. Should we generate .hs-boot files for any shapes where we had to create a Ptr?

@endgame
Copy link
Collaborator Author

endgame commented May 6, 2022

Notes for myself, for when I next get a chance to hack on this:

I think also it might not be too bad:

  • when writing out a type file, if the shape you need to import is a Ptr, do an import {-# SOURCE #-}
  • when building the tree of files to write out, generate .hs-boot for files which are referenced at least once by Ptr

Copy link
Collaborator Author

@endgame endgame left a comment

Choose a reason for hiding this comment

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

@brendanhay The branch in its current form can re-generate all configured services in the current botocore pin, and they all compiled successfully on my machine. Do you think we should merge this?

Future work: when we advance the botocore pin and configure new services, we may have problems with import cycles - wafv2 is the only one I'm aware of. If it's the only one, I think a manual fixup is probably the way to go: suppress generation of its Statement shape, and replace it with a proper sum type a la #724 .

I hit other problems on an updated botocore pin, but I think we do them one at a time:

  1. merge this
  2. ship config fixups that have current issues/PRs
  3. regen all services
  4. update botocore, regen all services, fixing up as necessary
  5. start configuring new services.

Thoughts? If you're busy, I'll probably merge in the back half of next week.

gen/src/Gen/Types/Service.hs Show resolved Hide resolved
@endgame endgame merged commit 3219840 into brendanhay:main Jun 6, 2022
@endgame endgame deleted the gen-hackery branch June 6, 2022 01:35
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.

None yet

3 participants