Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd traits w/ auto-deriving for soundly serializing/inspecting/transforming rustc types. #36588
Comments
eddyb
added
C-cleanup
A-compiler
labels
Sep 19, 2016
nikomatsakis
added
the
I-nominated
label
Sep 22, 2016
This comment has been minimized.
This comment has been minimized.
|
Nominating for discussion next week. In this week's compiler team meeting, @arielb1 raised concerns about leaving (ab)uses of unsound specialization in the compiler, which I am sympathetic to. It'd be good to figure out how we can prioritize moving away from that. |
arielb1
added
the
T-compiler
label
Oct 24, 2016
nikomatsakis
removed
the
I-nominated
label
Nov 10, 2016
steveklabnik
removed
the
A-compiler
label
Mar 24, 2017
This comment has been minimized.
This comment has been minimized.
|
I believe we can reduce our deriving needs to a single "
Even without VG we can build implementations of all sorts of operations we need (such as EDITs:
|
bors
added a commit
that referenced
this issue
Nov 28, 2018
bors
added a commit
that referenced
this issue
Nov 28, 2018
bors
added a commit
that referenced
this issue
Nov 28, 2018
bors
added a commit
that referenced
this issue
Nov 29, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
eddyb commentedSep 19, 2016
Currently, we're limited to the general-purpose
Eq,Ord,Hash,EncodableandDecodabletraits, even though the compiler often has more unconventional desires, involving contexts and custom behaviors.There are several special-purpose traits already in the compiler, such as AST/HIR
Folder/Visitorand the two-in-oneTypeFoldable(which also does visiting).Also, #36551 adds a specialization mechanism in the bundled
rustc_serializeto work around the fact thatEncodableandDecodablehave their methods be generic over the encoder/decoder instead of the trait, but this abuses the yet-unclosed lifetime soundness hole in specialization (#31844):That
implrequires that the'tcxof the decodedTymatch the'tcxof the decoder, but this cannot be enforced through specialization as the lifetime relationships do not exist before monomorphization.A better solution would involve custom traits that can dispatch over the decoder w/o specialization, i.e.:
To make all of this ergonomic, auto-deriving is necessary, and I believe macros 1.1 (perhaps helped by a permanent switch to rustbuild) can make it happen.
Last but not least, it may be possible to generalize encoding/decoding and visiting/folding/relating into a single (or a pair of) abstraction(s), but I'd have to leave that to someone who understands tree folding, transducers, and perhaps Haskell lenses, although there's no guarantee they map nicely to Rust.
cc @rust-lang/compiler