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

[WIP] Make it build with Rust 1.0.0-alpha #135

Merged
merged 1 commit into from Jan 27, 2015

Conversation

rgs1
Copy link
Contributor

@rgs1 rgs1 commented Jan 20, 2015

WIP: don't pull yet

Signed-off-by: Raul Gutierrez S rgs@itevenworks.net

@rgs1 rgs1 force-pushed the more-fixes-for-alpha branch 2 times, most recently from b1e3963 to 70075e2 Compare January 21, 2015 06:13
@rgs1
Copy link
Contributor Author

rgs1 commented Jan 21, 2015

Not ready yet, but more progress

@SimonTeixidor
Copy link
Member

I saw that the dependencies broke today again. I updated them so we can keep working on this. Are you still working on this @rgs1? If not I might try to finish it during the weekend.

@dkhenry
Copy link

dkhenry commented Jan 22, 2015

Ok so @rgs1 I have fixed most the errors from the latest nightly, but I have no idea what the following construct's are doing so I don't even know how to begin to fix them.

json_body_parser.rs:34:16: 34:30 error: type parameters may not appear here [E0085]
json_body_parser.rs:34         self::<JsonBodyParser>().and_then(|&: parsed| {

If you can point me in the direction of what that language construct even is I can have a pull request for you that should fix all the build errors.

@SimonTeixidor
Copy link
Member

You must have edited that line.

What it originally says is self.get::<JsonBodyParser>().and_then(|parsed|.

What that is supposed to do is the following:

  • Retrieve the JsonBodyParser from the typemap.
  • If it was found, execute the function on the following line.
    • If it wasn't found, return without doing anything.

I assume the confusion comes from the fact that you have edited the line.

I'm super glad to see new contributors by the way!

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 24, 2015

Ah very nice @dkhenry! I'll resume this today!

@BenMorganIO
Copy link

👍

@rgs1 rgs1 force-pushed the more-fixes-for-alpha branch 2 times, most recently from 5c1b4ba to 1e8b7ff Compare January 25, 2015 04:31
@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

Ok! It builds! It's not ready for merge because there are some inefficient things (i.e.: assigning a Regex::new to a static inside a mod is not working for me, need to dig in) plus in general things are not super tidy. I also haven't touched the tests.

I'll make a 2nd pass now to get things in order, unless someone gets there first.

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

(I updated the branch, but it's still WIP)

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

Ah, so regex! is available via a separate lib (plugin), regex_macros. So the static issue is fixed, next warnings + tests!

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

No more warnings! Only tests are left to be fixed!

@SimonTeixidor
Copy link
Member

Beautiful! I will have a look at the code later (as will the others, I'm sure. @Ryman always manage to find some nitpicks :) ). When you feel that you're done, would you mind naming your commit according to the following conventions? I forgot to tell you on your last commit but we're looking at automatically generating a changelog in the future.

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

Tests build!! They don't pass though :-) But I think I mostly know why. Going out for a run and will fix them when I get back. Almost there! Stay tuned

@SimonTeixidor
Copy link
Member

You have changed the mutability on the Request parameter to some handler functions in the examples where it isn't necessary. Interestingly enough, the compiler doesn't warn us that the mutability isn't needed. Anyways, as we don't need it to be mutable in these examples we might just as well change that back.

And what's up with storing the handler in a variable like that? Are you sure issue #15444 is related? Because this was working a month and a half ago and that issue is older, no?

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

Oops, sorry about the unneeded mut. Sure I'll fix all the unneeded stuff on a final pass (making tests pass now).

Wrt to coercing handlers, I couldn't find another way to make it work with nightly. Here's a toy example: http://is.gd/H60Xjl.

I asked around #rust, and they say it'll get fix at some point.

@SimonTeixidor
Copy link
Member

No worries. Sounds good!

Yeah, I also figured that it must be a bit of a bug in the compiler. I questioned whether issue #15444 that you mentioned in a comment is the one to blame, as that issue dates from before this stopped working. Anyways, we have the router! macro available so people won't have to use that workaround if the don't want to :)

We'll have to remember to revert the examples once this gets fixed in the compiler just.

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

Yup I'll try to find the actual real/current issue in so we can mention that in the FIXMEs

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 25, 2015

All tests passing! Now, we can do some real review @simonpersson ;-)

Up next:

  • drop the unneeded &mut
  • format the commit according to the contributing guidelines

Please feel free to point out nits (and not nits) so we can get this in good shape. Thanks!

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 26, 2015

Updated the commit message according to the used convention + drop the unneeded &mut changes. Should be ready-ish for merge hopefully.

@SimonTeixidor
Copy link
Member

Yay! Travis passed too, great news.

The not_found_handler in the file nickel.rs is commented out (line 142). Is there a reason for that or did you just miss it?

Some calls to unwrap() are introduced. These are not good, as they can cause the server to panic. For example, line 108 in response.rs was changed from using and_then to unwrap. Can't we use and_then for some reason here? If we can't use and_then for some reason, I suppose we can use normal pattern matching. Could you look at all the calls to unwrap() that you introduced and see if they can be eliminated (preferably with an error message on the failing case where it makes sense, like in the creation of regexes from handler path strings)? I think it's preferable that the server is misbehaving on incorrect data rather than crashing.

Line 140 in response.rs was moved, now the comments there doesn't make much sense. Line 139 and 140 should be switched.

Other than these things, I think this looks great! I'd like to hear the opinion of @Ryman or @cburgdorf before merging though,

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 26, 2015

Great, thanks for the review! I'll take a look in a bit, all of those are probably left over or omissions.

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 26, 2015

Wrt to the rust-http issue, in nickel-org/rust-http@53d30c0 I wonder if:

-impl fmt::Show for Status {
+impl fmt::Display for Status {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    write!(f, \"{} {}\", self.code(), self.reason())
}

has something to do.

server.utilize(logger);
// issue #15444
let logger_handler: fn(&Request, &mut Response) -> MiddlewareResult = logger;
server.utilize(logger_handler);
Copy link
Member

Choose a reason for hiding this comment

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

server.utilize(logger as fn(&Request, &mut Response) -> MiddlewareResult); is the common form of this last I saw, but it's still horrible :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I guess we leave it as is and revisit later on when the variants of rust-lang/rust#20178 are done?

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 it's worth trying (this could go in nickel/lib.rs with a doccomment explaining its purpose):
type HandlerPtr = fn(&Request, &mut Response) -> MiddlewareResult
and changing fallout code to:
foo(bar as HandlerPtr)

OR I think changing the naming convention, logger_handler => logger_fnptr.

I guess it's a nit really, but I'm guessing people may understand a cast to a function pointer if they come from c++/c rather than reading 'I'm turning my handler into a handler..?' and perhaps being confused.

cc @simonpersson

@Ryman
Copy link
Member

Ryman commented Jan 26, 2015

Added a few inline comments, looks good other than that, and we can iterate easier once master's buildable :) I've let an old branch porting to hyper bitrot, might try to rebase onto this sometime soon.

Thanks for the efforts @rgs1!

@SimonTeixidor
Copy link
Member

@Ryman - Hyper sounds cool (and needed)!

@rgs1 - I pushed a fix to the http repo, reverting your changes in that file. Now it works again :)

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 26, 2015

@simonpersson: thanks! Though Show is deprecated and was split into Debug and Display. I think we want both for status (i.e.: impl Display and derive Debug). We can follow-up in that repo.

@Ryman: thanks for the review! I'll get to that a bit later, would be great to have master be buildable again!

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 27, 2015

Updated to conform with @Ryman's review - let me know how it looks now.

@Ryman
Copy link
Member

Ryman commented Jan 27, 2015

@rgs1 Thanks, I think I checked all the changes, still a few outstanding nits.

In future, could you make changes in new separate commits that can be squashed later, as it helps to minimize incremental review time. 👍

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 27, 2015

Added two commits to address the last two comments. Shall we wait for @simonpersson to weight in on how to handle the casts?

Note that the last two commits don't adhere to the usual commit formatting, since we'll probably squash them.

Thanks for the review @Ryman.

@Ryman
Copy link
Member

Ryman commented Jan 27, 2015

LGTM once there's a consensus on the casting/ergonomics issue :)

@SimonTeixidor
Copy link
Member

Have we tried declaring a type for easier casting? If it works it is prettier I suppose. On the other hand, it's not meant to be a permanent solution anyways and there's still the router!-macro for those who value ergonomics.

So, it doesn't really matter to me :)

@rgs1
Copy link
Contributor Author

rgs1 commented Jan 27, 2015

I assume we'll be tracking nightly from now on, so things will be in a state of flux anyway. As soon as this is fixed in the compiler, we can change it.

@SimonTeixidor
Copy link
Member

Exactly. I say we merge this as it is.

@rgs1 - Can you squash the commits to make it ready for merging?
@Ryman - You press the button if you can't think of anything more!

A bunch of things need to happen so that all plays nicely
with latest rust nightly:

- Middleware impls need to be coerced (variant of issue #20178)
- Regex is now an external lib
- A bunch of compiler directive got renamed/changed (i.e.:
  deriving -> derive, feature(phase) is gone, phase(plugin)
  is just #[plugin], etc.
- Use BTreeMap instead of plain TreeMap
- Use #![allow(unstable)] to silence warnings
- std::sync::atomic::Relaxed is now std::sync::atomic::Ordering::Relaxed
- Int types got renamed and regroupd (i.e.: uint -> usize, u -> us, etc)
- Show trait got split into Display and Debug
- The plugin lib changed its API
- Closures need |&:| to hint they are FnShare
- Slice methods are deprecated in favor of &[..]
- Occupied and Vacant moved: std::collections::{hash_map, Entry::}

Signed-off-by: Raul Gutierrez S <rgs@itevenworks.net>
@rgs1
Copy link
Contributor Author

rgs1 commented Jan 27, 2015

Squashed @simonpersson @Ryman !

@thiagopnts
Copy link
Contributor

Awesome work @rgs1 :)

Ryman added a commit that referenced this pull request Jan 27, 2015
Bring nickel up to Rust 1.0.0-alpha
@Ryman Ryman merged commit d1fb72c into nickel-org:master Jan 27, 2015
@Ryman
Copy link
Member

Ryman commented Jan 27, 2015

Merged, thanks for the work @rgs1! 👍

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.

None yet

6 participants