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

Improve reporting of values with cycles #217

Merged
merged 1 commit into from Jun 18, 2020
Merged

Improve reporting of values with cycles #217

merged 1 commit into from Jun 18, 2020

Conversation

dsnet
Copy link
Collaborator

@dsnet dsnet commented Jun 13, 2020

Previously, the reporter could handle formatting values with cycles
in that it did not crash with a stack overflow. However, the output
was not particularly understandable as it did not surface to the user
why a particular value was truncated, and if it was truncated due
to a cyclic reference, what was the referent.

This change annotates the reporter tree with pointer information
so that a later pass can inject reference information if it is needed
to produce more understandable output.

@dsnet
Copy link
Collaborator Author

dsnet commented Jun 13, 2020

This is the last major cmp change I have in mind. It's unfortunately a bit complex as cycle detection is hard. Printing cycles in a sensible way for humans is even harder.

@dsnet dsnet force-pushed the cycle-references branch 2 times, most recently from 8ecf200 to 6a70c4c Compare June 14, 2020 15:45
return &textWrap{Prefix: typeName, Value: wrapParens(s)}
}

// wrapParens wraps s with a set of parenthesis, but avoids it if it is super

Choose a reason for hiding this comment

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

super? Missing end phrase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ooops. Fixed.

@dsnet
Copy link
Collaborator Author

dsnet commented Jun 18, 2020

Thank you for reviewing all my changes. I think this concludes my series of planned cmp improvements.

Previously, the reporter could handle formatting values with cycles
in that it did not crash with a stack overflow. However, the output
was not particularly understandable as it did not surface to the user
why a particular value was truncated, and if it was truncated due
to a cyclic reference, what was the referent.

This change annotates the reporter tree with pointer information
so that a later pass can inject reference information if it is needed
to produce more understandable output.

Consider the following example:
  map[string]*cmp_test.CycleAlpha{
  	"Foo": &⟪ref#0⟫{
  		Name: "Foo",
  		Bravos: map[string]*cmp_test.CycleBravo{
  			"FooBravo": &{
- 				ID:     101,
+ 				ID:     0,
  				Name:   "FooBravo",
  				Mods:   100,
  				Alphas: {"Foo": &⟪ref#0⟫(...)},
  			},
  		},
  	},
  }

This graph contains a cycle. To ensure that a graph can be formatted,
the cycle is truncated as indicated with: &⟪ref#0⟫(...).
The referent was identified earlier with: &⟪ref#0⟫{...}.
@dsnet dsnet merged commit 77ae86f into master Jun 18, 2020
@dsnet dsnet deleted the cycle-references branch June 18, 2020 00:25
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

2 participants