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

xsdgen: type flattening routines are slow and incorrect #59

Open
droyo opened this issue Nov 16, 2017 · 0 comments
Open

xsdgen: type flattening routines are slow and incorrect #59

droyo opened this issue Nov 16, 2017 · 0 comments

Comments

@droyo
Copy link
Owner

droyo commented Nov 16, 2017

The xsdgen package flattens the XSD type hierarchy to produce nicer code.

a → b→ c → anyType

becomes

a → anyType
b → anyType
c → anyType

Practically speaking, instead of generating code like this:

type MyString string
type AllCapitalString MyString
type ShortAllCapitalString AllCapitalString

It generates code like this:

type MyString string
type AllCapitalString string
type ShortAllCapitalString string

This is done in the Config.flatten method. There are so many problems with this function, I don't know where to start.

  • It's slow -- it repeatedly recurses into the type hierarchy, even if all types have similar ancestry.
  • It's expensive -- it builds up a big slice of xsd.Type items that usually contains lots of duplicates
  • It's complicated -- not only does it flatten types, it opportunistically elides types that it deems useless, filters types not in the whitelist, unpacks struct types when it can, and who knows what else.
  • It's wrong -- see in Schema with top-level elements #14 where it does not correctly collect all types needed for a given subset of types.

The cfg.flatten and cfg.flatten1 functions need a redo, with the following goals:

  • Do one transformation at a time, rather than all at once.
  • Use memoization to skip flattening type hierarchies we've seen before.
  • If necessary, extend and use the internal/dependency package's Graph type to model dependencies between derived types and the types of their attributes, elements and ancestors, to avoid missing indirectly required types.
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

No branches or pull requests

1 participant