-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add location-set as a generic type to Transport #14
Conversation
f42fb67
to
44c3478
Compare
44c3478
to
2bd32d5
Compare
a1ce6bb
to
24ad199
Compare
chorus_lib/src/core.rs
Outdated
@@ -338,13 +333,16 @@ where | |||
where | |||
L: Subset<LS, IndexSet>, | |||
{ | |||
struct EppOp<'a, L: HList, L1: ChoreographyLocation, B: Transport> { | |||
struct EppOp<'a, L: HList, L1: ChoreographyLocation, LS: HList, B: Transport<LS>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: What's the difference between L
and LS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm; It seems to me that L
here comes from the Choreography: Look at Line 345. The L first is inferred from the Choreography, then at line 455 we use the same L as a concrete value for the L at line 352.
But LS is the location set for the transport (and the projector). So we need it as a different generic and can't use L. L is a subset of LS (line 350).
There is an issue where LS
is first introduced on line 303, but has to be introduced again on line 359; and it seems it's a Rust thing where you can't use a generic of an outer function inside an inner function!
chorus_lib/src/transport/http.rs
Outdated
@@ -3,6 +3,8 @@ | |||
use std::thread; | |||
use std::{collections::HashMap, sync::Arc}; | |||
|
|||
use core::marker::PhantomData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be imported from std::marker
Allow the Transport to have a different kind of information for the target ChoreographyLocation
cb93c5b
to
9c99e5c
Compare
726e5d0
to
00e6f1c
Compare
31eaf1a
to
8a63b03
Compare
8a63b03
to
2b379cd
Compare
7cae423
to
f0b8461
Compare
chorus_lib/src/transport.rs
Outdated
{ | ||
/// Adds information about a new `ChoreographyLocation`. | ||
pub fn with<NewLocation: ChoreographyLocation>( | ||
self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you take mut self
, can you reuse the hashmap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already changed!
6948989
to
82e3c07
Compare
``` | ||
|
||
You can construct a `LocalTransport` instance by passing a slice of locations to the `from` method. | ||
To use the `local` transport, first import the `LocalTransport` struct from the `chorus_lib` crate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence seems redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we have this sentence in the current version of the book: "To use the local
transport, import the LocalTransport
struct from the chorus_lib
crate."
In this commit, it's just in a different paragraph. But if you do think that it shouldn't have been there in the first place, sure! I'll delete it (But let me know if you want it to be gone completely or you want me to put it before the snippet)
pub fn with<NewLocation: ChoreographyLocation>( | ||
self, | ||
_location: NewLocation, | ||
) -> LocalTransportChannel<HCons<NewLocation, L>> { | ||
let mut queue_map: QueueMap = HashMap::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's not a big deal, but you can probably take mut self
and reuse the hashmap without creating a new one all over every time we call with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queue_map is always an Arc
, and if you want it to be muted, I think you have to change the type to something else. And even if you can do that, the code will become harder to understand. (Here, it's clear what queue_map contains if someone reads the code, but if you want it to be changed so that only new information is added to it, someone might need to read it a couple of times before they understand all the content, not just how it's updated every time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a library and that complexity won't be exposed to the user. IMO that readability issue is not a valid explanation for creating a nested hash map.
/// | ||
/// This transport uses a blocking queue to allow for communication between threads. Each location must be executed in its thread. | ||
/// | ||
/// Unlike network-based transports, all locations must share the same `LocalTransport` instance. The struct implements `Clone` so that it can be shared across threads. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is no longer true?
/// Unlike network-based transports, all locations must share the same `LocalTransport` instance. The struct implements `Clone` so that it can be shared across threads. | |
/// Unlike network-based transports, all locations must share the same `LocalTransportChannel` instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree with your point, BUT: LocalTransportChannel
is not a field in network-based transports, so it doesn't even make sense to compare the two. Can we just go with "all locations must share the same LocalTransportChannel
instance" and remove the Unlike network-based transports
part?
chorus_lib/src/transport.rs
Outdated
/// The information about the target choreography | ||
pub target_info: (TargetLocation, TargetInfoType), | ||
/// The struct is parametrized by the location set (`L`). | ||
pub location_set: PhantomData<L>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't want to pub
this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do I make all the fields private? It works currently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we need to have other fields public so when people use it for their custom transport they can access the fields
chorus_lib/src/transport.rs
Outdated
{ | ||
/// Adds information about a new `ChoreographyLocation`. | ||
pub fn with<NewLocation: ChoreographyLocation>( | ||
self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chorus_lib/src/transport/http.rs
Outdated
/// The header name for the source location. | ||
const HEADER_SRC: &str = "X-CHORUS-SOURCE"; | ||
|
||
/// A wrapper for HashMap<String, (String, u16)> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used?
c2f1eca
to
a1d2df1
Compare
a1d2df1
to
83a5212
Compare
Merging this PR and I will make more adjustments at #12 |
This adds location-set as a generic type to transport, and removes the need for users to specify the location-set for Projector. Now, the location-set of Projector is inferred from the location-set of transport.