Comments (14)
It was much easier to change Continue
than I thought. Should have this PR together and ready for review in the next day or two.
from dialectic.
Regarding the ToUnary
trait, this is how it seems like it must be defined. There must be a wrapper type Number
to convert from the land of constants to the land of types; you can't directly implement a trait on a constant:
pub trait ToUnary {
type AsUnary: Unary;
}
struct Number<const N: usize>(PhantomData<[(); N]>);
impl ToUnary for Number<0> {
type AsUnary = Z;
}
from dialectic.
Also, seems like the timeline for min_const_generics
stabilization is farther out than we thought? Need more info about that.
from dialectic.
As we've confirmed that min_const_generics will hit stable on 2021-03-25, it seems likely that we'll be preparing for a release 0.4 on or slightly after 2021-03-25, using the new feature to improve the user-facing API. Since we're now on board this conversion, there's an important question that needs to be answered: should Continue<N>
have N
be a const generic, or be a unary type? If we make it a unary type, then we can leave codegen in the macro compiler unchanged; if we instead have a Continue_<N>
or UnaryContinue<N>
which takes an N: Unary
rather than const N: usize
, and then have a type synonym pub type Continue<N> = Continue_<<Number<N> as ToUnary>::AsUnary>;
then the user-facing API can nicely use Continue<1>
, Continue<0>
, etc. while having the unary continue exist under the hood.
from dialectic.
Choosing to leave it as unary means that error messages will mention fully-expanded unary numbers, which I think is less intelligible than mentioning constants. Given that we are merely emitting a token stream, I don't think it should be a problem to emit a numeric token in the correct position, should it?
from dialectic.
This is true, but if we emit unary type level integers we could avoid modifying the codegen significantly and also possibly speed up compilation a tiny bit by not putting the onus on Rust to convert the constants into type-level unaries.
from dialectic.
On second thought, I don't think the performance gain from that would be significant. We could find out, but for now I'll emit integers and swap Continue
completely over to using const usize.
from dialectic.
Actually, it gets worse. Continue
has type-level addition/similar operations performed directly on it. We could convert const generics to unary and then perform the ops and then go back with another trait conversion, but this is all starting to feel a lot like basically just bandaging over the fact that const generics are not ready for arbitrary usage like this yet. We can totally use them for user facing stuff but once we convert to unary, we really don't want to go back if we can avoid it, I think.
from dialectic.
Could we not relatively easily generate impls for a FromUnary
trait alongside those for the ToUnary
trait, just as we need to generate both List
and Tuple
to get both directions for tuple-to-list conversions?
Another note: we shouldn't forget to seal the ToUnary
(and if implemented, FromUnary
) traits.
from dialectic.
So, we can, but there's a couple glitches in that; at the type level, we cannot go from some type containing a const N: usize
without binding it to a type variable, and then "solving" for it. The main issue with this is that it is not possible to uniquely specify a const generic parameter without having it in the type being implemented for (trait or non-trait impl.) Const generics cannot be produced from type families. This is annoying.
One possible workaround is not to have Continue<const N: usize>
but Continue<Number<N>>
, and since Number<N>
is of the type kind rather than the const generic usize
kind, we can treat it w/ a type family (and we could also potentially have an Indexed
trait that produces a Number<const N: usize>
from a type implementing it.) I would just like to note that every time we end up doing something that modifies a Continue
, we'll end up going from const to Unary
to const again. That feels very hacky but I guess it's just the machinery needed to work around the current drawbacks of const generics.
from dialectic.
Perhaps we can defer this to last, since these modifications are independent of all others? I think I have some ideas of how to have and eat our cake simultaneously here, but it will require some experimentation. In general I think it is better to have a more complex internal implementation if it improves error messages. I don't think we need to worry about compile times for the conversions, because since they are non-recursive, each conversion is approximately constant time in the size of the number.
from dialectic.
Defer which to last, the Continue
changes? Point taken on the compile times.
from dialectic.
That's right—defer the Continue
change to last, since it will likely be the most tricky, and nothing else depends on it.
from dialectic.
Well, I have the rest implemented for the most part, minus the syntactic changes for macros. Other things currently do depend on what Continue
uses, such as the macro compiler which currently emits unary integers.
from dialectic.
Related Issues (20)
- [transmit-case] Ergonomics for `Choice<N>` bounds
- Self-documenting `offer!()` and `choose!()` HOT 3
- Make serialization non-dependent on serde HOT 5
- Try lifting `Session<Action = _>` bounds into `impl` for better errors HOT 2
- Backend wrapper restricted by an explicit allow-list
- `offer!` macro does not catch too-small arity
- Improve type error presentation
- Fix broken Clippy after update
- Ensure channel_id is actually unique HOT 1
- Add `confirmation_depth` to Merchant.toml example as well as explanation in README.md
- Provide a way to dialectic to have an extra encryption tunnel using a session key
- Write key-server function to accept a request to store a secret
- Add CHANGELOG since 0.3
- Support batching backends
- Transition to poll_fn style backend traits HOT 2
- Multiplexing backend adapter
- Explicit "unsafe" in session type language HOT 2
- Parameterize serde backend by serialization strategy HOT 1
- Allow sending types "as" other types HOT 1
- [transmit-case] Issues with `TransmitCase` by ref
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dialectic.