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 cabal template #1022

Merged
merged 9 commits into from
Jan 16, 2025
Merged

Gen cabal template #1022

merged 9 commits into from
Jan 16, 2025

Conversation

endgame
Copy link
Collaborator

@endgame endgame commented Jan 15, 2025

I was talking with a colleague about the generator today. I think one of the big reasons the generator is hard to untangle is that many of its types are pulling double or triple duty: first, they represent the JSON files are they are read in from botocore (and merged with our annexes); second, they represent the service as the generator understands them (as a service with endpoints and operations that send/receive shapes in formats); third, they represent (via their ToJSON instances) the input to the various .ede templates used to generate the output files.

I hope to eventually deal with #888 by starting at the output and refactoring backwards, until the types currently in amazonka-gen aren't participating in output any more. This PR is the first step in that plan. It introduces the Gen.Output namespace and a Gen.Output.Template.Template type, representing a template that tracks the type of the record it needs to consume. Gen.Output.Template.CabalFile then represents the fields needed by cabal.ede, and its only job is to get them into the HashMap Text Aeson.Value that EDE requires.

This then revealed some easy opportunities for simplification, so I did them too.

The hope is that once the current types are no longer overloaded, we can simplify them by removing type variables, instances, etc., and eventually replace them (e.g., by replacing the cofree comonadic shape functor with a type that only refers to shapes by name; when everything looks at it from that perspective, #888 becomes impossible).

The current goal is to have three phases — "input", "model", and "output":

  • "Input" should read the source IDL as accurately as possible. Currently this is botocore and we have https://github/bellroy/hs-botocore to eventually swap in here;
  • "Model" will be our playground to describe AWS services. I expect this to be aware of request and response shapes, but also Haskell-specific things like what types to use in a representation, which deriving clauses we need to generate, and which module names to import (and whether to import them {-# SOURCE #-} or not); and
  • "Output" will be where we set up the output directory tree, feed data to EDE templates, etc. Because each template will eventually have its own record to track its inputs, we may want to include a thin layer of type-safety here. Future work might have an argument record contain a [ModuleName] naming the exposed-modules instead of a [Text], but the main point is to keep this as simple as possible.

This PR does not change the output of the generator at all; I re-ran it over the repo and got a clean diff.

It used to denote the compatible amazonka-core version but since it
always matches the library version and we upload everything in
lockstep, let's remove it for simplicity.
We export every module we generate now, so there's no point
maintaining this distinction.
@endgame endgame force-pushed the gen-cabal-template branch from 6833765 to 1b04c4d Compare January 15, 2025 09:37
gen/src/Gen/IO.hs Outdated Show resolved Hide resolved
gen/src/Gen/Output/Template/CabalFile.hs Show resolved Hide resolved
@endgame endgame merged commit e9b076e into brendanhay:main Jan 16, 2025
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants