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

WIP: Detect recursive type unrolling #2134

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft

WIP: Detect recursive type unrolling #2134

wants to merge 29 commits into from

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Jun 26, 2024

No description provided.

@t0yv0 t0yv0 requested a review from iwahbe June 26, 2024 15:22
Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 70.02012% with 149 lines in your changes missing coverage. Please review.

Project coverage is 62.52%. Comparing base (674cf5b) to head (f161553).
Report is 12 commits behind head on master.

Files Patch % Lines
pkg/tfgen/unrec/comparer.go 47.97% 69 Missing and 21 partials ⚠️
pkg/tfgen/unrec/package_spec_util.go 79.67% 16 Missing and 9 partials ⚠️
pkg/tfgen/unrec/simplify.go 72.54% 9 Missing and 5 partials ⚠️
pkg/tfgen/unrec/type_visitor.go 78.72% 5 Missing and 5 partials ⚠️
pkg/tfgen/unrec/recursion_detector.go 91.04% 3 Missing and 3 partials ⚠️
pkg/tfgen/unrec/equality_classes.go 88.88% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2134      +/-   ##
==========================================
+ Coverage   60.64%   62.52%   +1.88%     
==========================================
  Files         350      355       +5     
  Lines       45793    38677    -7116     
==========================================
- Hits        27770    24183    -3587     
+ Misses      16491    12909    -3582     
- Partials     1532     1585      +53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

//
// Suppose ancestor(T1, T2) if T2 describes a sub-property of T1.
//
// Suppose T1 <= T2 if T1 has the subset of properties of T2 with types that are themselves Tx <= Ty.
Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to work really well for the AWS WAFv2 example at least.

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

I'm really exited about this. I'd love to see what the diff looks like for a couple of our smaller providers (does it detect recursion, and if so do we agree).

pkg/tfgen/internal/unrec/comparer.go Outdated Show resolved Hide resolved
pkg/tfgen/internal/unrec/comparer.go Outdated Show resolved Hide resolved
pkg/tfgen/internal/unrec/equality_classes.go Outdated Show resolved Hide resolved
pkg/tfgen/internal/unrec/example_schema_test.go Outdated Show resolved Hide resolved
return "", false
}
cleanRef := strings.TrimPrefix(rawRef, "#/types/")
return tokens.Type(cleanRef), true
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to validate here?

Suggested change
return tokens.Type(cleanRef), true
typ, err := tokens.ParseTypeToken(cleanRef)
contract.AssertNoErrorf(err, "invalid schema")
return typ, true

return best
}

func findGenericTypeReferences(x any) (typeRefs, error) {
Copy link
Member

Choose a reason for hiding this comment

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

It feels like this could be implemented via type_visitor.go and it would be much easer to reason about.

pkg/tfgen/internal/unrec/recursion_detector.go Outdated Show resolved Hide resolved
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.

3 participants