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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate string literal rendering, fix 4909 #8193

Merged
merged 5 commits into from
Apr 17, 2023

Conversation

roberth
Copy link
Member

@roberth roberth commented Apr 9, 2023

Motivation

Repay some tech debt and fix #4909

Context

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • documentation in the internal API docs
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Priorities

Add 馃憤 to pull requests you find important.

@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Apr 9, 2023
src/libexpr/value/print.cc Outdated Show resolved Hide resolved
src/libexpr/value/print.cc Outdated Show resolved Hide resolved
*
* @param s The logical string
*/
std::ostream & printLiteral(std::ostream & o, std::string_view s);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this overloaded printLiteral function (as opposed to printBool, printString etc.) is a good idea. For instance, at some point somebody is going to do printLiteral(null), expecting a null value to be printed, but instead it will call the char * overload...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. It's printLiteralString now, so that it's explicit which kind of literal will be rendered; same for printLiteralBool.
I've kept the "literal" part because I've renamed the file to cover relevant parts of the whole language, not just the values.

*
* @param res Where to print to
* @param s Which logical string to print
*/
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this function should be moved to print.cc?

Copy link
Member

Choose a reason for hiding this comment

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

Which print.cc? This is for the aterm printing of dervations, and part of the store layer.

Copy link
Member

Choose a reason for hiding this comment

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

I certainly wouldn't mind say having derivation/{aterm,json}.{cc.hh} to separate data types from serialization, and put both serializations on equal footing, but that seems like a separate PR to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not feasible, because that's a different library. We should keep these separate. As mentioned in the comment, this is a different function.
I can remove this mention of the language completely if we want to be very (overly?) thorough about libstore not depending on libexpr. Personally I think there's value in cross-referencing components in both directions, although this may not be the brightest example.

@@ -0,0 +1,26 @@
#include "value/print.hh"
Copy link
Member

Choose a reason for hiding this comment

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

It seems a bit arbitrary to introduce a "value" subdirectory, when nothing else value-related is there...

Copy link
Member

Choose a reason for hiding this comment

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

We already have a value subdirectory. I previously made value/context.{hh,cc} on analogy with primops/context.cc. String contexts are part of string values.

Copy link
Member Author

Choose a reason for hiding this comment

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

While value/ was not a terrible choice, generalizing the file to allow printing all of the language is more useful. I've renamed it to just print.{cc,hh} in the libexpr top level.

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Co-authored-by: John Ericson <git@JohnEricson.me>
@github-actions github-actions bot added the repl The Read Eval Print Loop, "nix repl" command and debugger label Apr 15, 2023
@roberth
Copy link
Member Author

roberth commented Apr 16, 2023

I've moved the file to the libexpr top level, so that it's more useful. printIdentifier and printAttributeName are now also in the file, highlight some more tech debt. I won't resolve that in this PR though, because that would not be as reviewable:

  • First commit has the only behavioral change
  • The other ones are pure refactoring; no change in behavior

@roberth roberth merged commit 9af9c26 into NixOS:master Apr 17, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl The Read Eval Print Loop, "nix repl" command and debugger with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nix repl renders strings improperly escaped
3 participants