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

Introduce marker types #11768

Merged
merged 1 commit into from
Feb 1, 2014

Conversation

nikomatsakis
Copy link
Contributor

Introduce marker types for indicating variance and for opting out
of builtin bounds.

Fixes #10834.
Fixes #11385.
cc #5922.

r? @pnkfelix (since you reviewed the variance inference in the first place)

@nikomatsakis
Copy link
Contributor Author

cc @brson @alexcrichton

/// unsafe {
/// let x: *T = cast::transmute(s.x);
/// *x
/// }
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 is missing a }

@brson
Copy link
Contributor

brson commented Jan 24, 2014

There's a lot about this I don't understand. Maybe you can explain it to me offline.

@alexcrichton
Copy link
Member

This looks really awesome, nice work!

/// the type parameter `T` is irrelevant, and hence a `S<int>` can
/// safely be coerced to a `S<~[int]>` (or, for that matter, `S<U>` for
/// for any `U`). But this is incorrect because `get()` converts the
/// `*()` into a `fn(T)` and then passes a value of type `T` to it.
Copy link
Member

Choose a reason for hiding this comment

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

The type signature in the example suggests it converts it into a fn(T) -> T, should the return value above be ()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, corrected.

@nikomatsakis
Copy link
Contributor Author

Note: not all tests pass yet.


/// A mutable memory location that admits only `Pod` data.
#[no_freeze]
#[deriving(Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is failing with:

/home/flaper87/workspace/personal/rust/src/libstd/cell.rs:18:12: 18:17 error: mismatched types: expected `std::kinds::marker::InvariantType<T>` but found `&std::kinds::marker::InvariantType<T>` (expected struct st
d::kinds::marker::InvariantType but found &-ptr)
/home/flaper87/workspace/personal/rust/src/libstd/cell.rs:18 #[deriving(Clone)]
                                                                        ^~~~~
/home/flaper87/workspace/personal/rust/src/libstd/cell.rs:18:12: 18:17 error: mismatched types: expected `std::kinds::marker::NoFreeze` but found `&std::kinds::marker::NoFreeze` (expected struct std::kinds::marker
::NoFreeze but found &-ptr)
/home/flaper87/workspace/personal/rust/src/libstd/cell.rs:18 #[deriving(Clone)]
                                                                        ^~~~~

Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably caused because NoFreeze and InvariantType don't implement Clone.

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 common deriving(Clone) error, so I'm proposing a lint: #11818

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it happens, it is completely wrong for Cell to derive clone. I am not quite sure why this was failing, though, I think maybe something to do with the weird setup of tests and libstd? In any case, I have fixed the error locally and will push an updated version.

@pnkfelix
Copy link
Member

@nikomatsakis you said "not all tests pass yet"; will you post here when they do?

Anyway, I'll start a review and provide what feedback I can.

@@ -1237,17 +1237,18 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
//
// Be warned! You must call `init_function` before doing anything with the
Copy link
Member

Choose a reason for hiding this comment

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

you removed the above warning about init_function causing segfaults. Is your plan to later put in code to call init_function from within new_fn_ctxt, but you didn't want to remove this comment here about init_function until doing that?

Or does your code cause a hypothetical addition of init_function to no longer type-check, which is my more recent inference from reading your comment here? (Which would mean that this comment should indeed stay while the other comment should not stay, at least not in its current form.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe there is any danger. I didn't merge the two functions simply because that would have added yet more parameters to new_fn_ctxt, but maybe I should do so. It's not like one more parameter will hurt.

@nikomatsakis
Copy link
Contributor Author

Tests pass now, addressed previous comments.

@nikomatsakis
Copy link
Contributor Author

grr failed to commit my latest edits before pushing.

@nikomatsakis
Copy link
Contributor Author

@pnkfelix I never wound up writing the table you suggested; it makes sense though, maybe we can add it or open an issue or something. I guess there's a limit to the extent that we can explain variance in a doc comment...I was hoping we could at least identify common scenarios (e.g., mutability) and suggest to people which marker to use, in lieu of a deeper understanding (that's what I was going for, not sure if I succeeded).

@nikomatsakis
Copy link
Contributor Author

Along those lines, I basically think people ought to use invariance whenever in doubt.

@nikomatsakis
Copy link
Contributor Author

I have no idea what those failures are. I can't reproduce locally yet :(

@alexcrichton
Copy link
Member

I fix a thing or two with the bots recently, so these may have just been sporadic failures (I can't find the exact logs on this PR any more)

@nikomatsakis
Copy link
Contributor Author

Well, I'll give it one more try. If I see those failures again we'll have to dig deeper in.

bors added a commit that referenced this pull request Feb 1, 2014
…e, r=pnkfelix

Introduce marker types for indicating variance and for opting out
of builtin bounds.

Fixes #10834.
Fixes #11385.
cc #5922.

r? @pnkfelix (since you reviewed the variance inference in the first place)
@bors bors closed this Feb 1, 2014
@bors bors merged commit 81d8328 into rust-lang:master Feb 1, 2014
@flaper87
Copy link
Contributor

flaper87 commented Feb 1, 2014

w000t it landed!

@nikomatsakis nikomatsakis deleted the issue-11385-cell-and-variance branch March 30, 2016 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants