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

Add location-set as a generic type to Transport #14

Merged
merged 26 commits into from
Sep 30, 2023

Conversation

ihaveint
Copy link
Collaborator

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.

@ihaveint ihaveint force-pushed the transport-location-set branch from f42fb67 to 44c3478 Compare September 18, 2023 11:18
@ihaveint ihaveint force-pushed the transport-location-set branch from 44c3478 to 2bd32d5 Compare September 18, 2023 11:50
@ihaveint ihaveint force-pushed the transport-location-set branch from a1ce6bb to 24ad199 Compare September 18, 2023 11:51
@@ -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>> {
Copy link
Member

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?

Copy link
Collaborator Author

@ihaveint ihaveint Sep 18, 2023

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!

@@ -3,6 +3,8 @@
use std::thread;
use std::{collections::HashMap, sync::Arc};

use core::marker::PhantomData;
Copy link
Member

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

@ihaveint ihaveint requested a review from shumbo September 20, 2023 00:14
@ihaveint ihaveint marked this pull request as ready for review September 20, 2023 02:31
@ihaveint ihaveint force-pushed the transport-location-set branch from cb93c5b to 9c99e5c Compare September 20, 2023 10:08
@ihaveint ihaveint force-pushed the transport-location-set branch from 726e5d0 to 00e6f1c Compare September 21, 2023 12:58
@ihaveint ihaveint force-pushed the transport-location-set branch 2 times, most recently from 31eaf1a to 8a63b03 Compare September 21, 2023 23:37
@ihaveint ihaveint force-pushed the transport-location-set branch from 8a63b03 to 2b379cd Compare September 21, 2023 23:42
@ihaveint ihaveint force-pushed the transport-location-set branch from 7cae423 to f0b8461 Compare September 21, 2023 23:50
chorus_lib/src/core.rs Outdated Show resolved Hide resolved
chorus_lib/src/core.rs Outdated Show resolved Hide resolved
chorus_lib/src/core.rs Outdated Show resolved Hide resolved
chorus_lib/src/transport.rs Outdated Show resolved Hide resolved
{
/// Adds information about a new `ChoreographyLocation`.
pub fn with<NewLocation: ChoreographyLocation>(
self,
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is already changed!

chorus_lib/src/transport/http.rs Outdated Show resolved Hide resolved
chorus_lib/src/transport/local.rs Outdated Show resolved Hide resolved
chorus_lib/src/transport/local.rs Outdated Show resolved Hide resolved
chorus_lib/src/transport/local.rs Outdated Show resolved Hide resolved
chorus_book/src/guide-transport.md Outdated Show resolved Hide resolved
@ihaveint ihaveint force-pushed the transport-location-set branch 2 times, most recently from 6948989 to 82e3c07 Compare September 28, 2023 02:23
```

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.
Copy link
Member

Choose a reason for hiding this comment

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

This sentence seems redundant.

Copy link
Collaborator Author

@ihaveint ihaveint Sep 29, 2023

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)

chorus_book/src/guide-transport.md Outdated Show resolved Hide resolved
chorus_lib/src/transport/http.rs Outdated Show resolved Hide resolved
pub fn with<NewLocation: ChoreographyLocation>(
self,
_location: NewLocation,
) -> LocalTransportChannel<HCons<NewLocation, L>> {
let mut queue_map: QueueMap = HashMap::new();
Copy link
Member

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

Copy link
Collaborator Author

@ihaveint ihaveint Sep 29, 2023

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)

Copy link
Member

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.
Copy link
Member

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?

Suggested change
/// 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.

Copy link
Collaborator Author

@ihaveint ihaveint Sep 29, 2023

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?

/// 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>,
Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

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

{
/// Adds information about a new `ChoreographyLocation`.
pub fn with<NewLocation: ChoreographyLocation>(
self,
Copy link
Member

Choose a reason for hiding this comment

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

/// The header name for the source location.
const HEADER_SRC: &str = "X-CHORUS-SOURCE";

/// A wrapper for HashMap<String, (String, u16)>
Copy link
Member

Choose a reason for hiding this comment

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

Is this used?

@ihaveint ihaveint force-pushed the transport-location-set branch 2 times, most recently from c2f1eca to a1d2df1 Compare September 29, 2023 10:34
@ihaveint ihaveint force-pushed the transport-location-set branch from a1d2df1 to 83a5212 Compare September 29, 2023 11:07
@shumbo shumbo merged commit 6509a2c into shumbo/available-locations Sep 30, 2023
3 checks passed
@shumbo
Copy link
Member

shumbo commented Sep 30, 2023

Merging this PR and I will make more adjustments at #12

@shumbo shumbo mentioned this pull request Oct 1, 2023
@shumbo shumbo deleted the transport-location-set branch October 1, 2023 12:34
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.

2 participants