Skip to content

Improve stack-related compiler error messages#331

Merged
olix0r merged 8 commits intover/profile-router-no-builderfrom
ver/stack-invesion
Sep 3, 2019
Merged

Improve stack-related compiler error messages#331
olix0r merged 8 commits intover/profile-router-no-builderfrom
ver/stack-invesion

Conversation

@olix0r
Copy link
Member

@olix0r olix0r commented Aug 31, 2019

Service stacks were built from "top" to bottom, so that the concrete
service type is satisied after all middlewares are composed toegether.
This leads to exceedingly complex compiler error messages.

This change adds a svc::Stack builder that aids composing layers
around a concrete inner service so that the compiler can more clearly
identity the layer that violates the type contract.

Note: this does not appear to improve compile times.

No functional changes are intended.

@olix0r olix0r self-assigned this Aug 31, 2019
Service stacks were built from "top" to bottom, so that the concrete
service type is satisied after all middlewares are composed toegether.
This leads to exceedingly complex compiler error messages.

This change adds a `svc::Stack` builder that aids composing layers
around a concrete inner service so that the compiler can more clearly
identity the layer that violates the type contract.

Note: this does *not* appear to improve compile times.

No functional changes are intended.
@olix0r olix0r force-pushed the ver/stack-invesion branch from b59db2f to 546c72e Compare September 1, 2019 00:03
Copy link
Contributor

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

I'm very +1 on this for the improved error messages alone. It's a shame that the build times aren't improved, but that's not too surprising IMO — the build time improvement from doing this with our pre-tower-layer stack types was probably an artifact of that specific implementation.

Have we considered upstreaming this after proving it out in the proxy?

The builder type should only be used when composing layers. Now that we
have `Builder::into_inner`, we need not store a builder in the profile
router.
@olix0r olix0r marked this pull request as ready for review September 3, 2019 02:33
@olix0r
Copy link
Member Author

olix0r commented Sep 3, 2019

@hawkw i'd encourage tower to mirror these changes. from the linkerd perspective, i'm not particularly bothered by maintaining our own builder types, especially if we continue ensure they are only used narrowly (i.e. code doesn't depend on concrete builder types).

@hawkw
Copy link
Contributor

hawkw commented Sep 3, 2019

@hawkw i'd encourage tower to mirror these changes.

👍 @LucioFranco may be interested in this!

@LucioFranco
Copy link

@olix0r by chance, do you have an example of error messages and how they differ?

Copy link
Contributor

@kleimkuhler kleimkuhler left a comment

Choose a reason for hiding this comment

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

Overall change looks good. An example could be helpful, but otherwise I just left a few questions and small changes.

@olix0r
Copy link
Member Author

olix0r commented Sep 3, 2019

@LucioFranco sorry, it's pretty annoying (time consuming) to generate these errors, so I'll have to leave that as an exercise to others. The problem is actually pretty easy to understand, though: If I construct a stack as layerA.layer(layerB).layer(layerC).layer(layerD).service(svc), the type of this stack isn't bound until the service() call, and so the user has to trawl through a bunch of compiler errors to figure out which layer violated the contract. If we invert this to be svc.push(layerD).push(layerC).push(...), then we always know the concrete type of the stack at each step, and I can make additional type assertions in the middle. So if there's an error, it should happen at the proper layer...

Copy link
Contributor

@kleimkuhler kleimkuhler left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@LucioFranco
Copy link

@olix0r I'm onboard with that! I remember the discussion we had a while back. I do think with tower 0.1 we should keep it how it is now. Does linkerd have any plans around updating to futures 0.3? I guess there should be some talk around that...in relation to tower.

@olix0r olix0r merged commit a27926b into ver/profile-router-no-builder Sep 3, 2019
@olix0r olix0r deleted the ver/stack-invesion branch September 4, 2019 00:31
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.

4 participants