-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargotest/support: remove internal mutability in favor of switching types #4314
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Wow, this looks cool @nodakai ! I think we need to consult @alexcrichton about general approach here. I personally like this idea, because I've been bitten myself by not calling Looks like almost all methods are implemented on So perhaps we can make two non-generic types, |
Good point, but actually my benchmark with So we can focus on which design is easier to use/maintain without worrying about compile time. > bef<-c(297.70, 290.04, 290.38, 299.61, 301.13)
> aft<-c(294.68, 297.19, 296.62, 290.33, 296.24)
> var.test(bef, aft)
F test to compare two variances
data: bef and aft
F = 3.5338, num df = 4, denom df = 4, p-value = 0.249
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.3679351 33.9409042
sample estimates:
ratio of variances
3.533843
> t.test(bef, aft, var.equal=T)
Two Sample t-test
data: bef and aft
t = 0.2873, df = 8, p-value = 0.7812
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-5.340106 6.860106
sample estimates:
mean of x mean of y
295.772 295.012 https://gist.github.com/nodakai/3600c808725f44f2cd24939168358726 |
I've personally never really been a huge fan of typestate and how the ergonomics work out in Rust, could we perhaps just maintain internal state and "do the right thing"? I don't think "you can only call |
Yeah, phantom types do seem like an overkill here. However, splitting this into two completely different types, |
Wow that is a dated comment. But sure yeah, having two types seems fine. |
☔ The latest upstream changes (presumably #4439) made this pull request unmergeable. Please resolve the merge conflicts. |
6a32139
to
b94d333
Compare
…ypes Remove is_build: Cell<bool> from ProjectBuilder and introduce a new type Project. is_build==false <-> ProjectBuilder is_build==true <-> Project Also add #[must_use] to ProjectBuilder to confirm its instances are surely consumed by its build() method to produce Project. The same goes for RepoBuilder. ProjectBuilder::cargo_process() was removed as its design heavily depended on the internal mutability. Signed-off-by: NODA, Kai <nodakai@gmail.com>
b94d333
to
d43ee1d
Compare
Removed phantom types according to the above discussion, and rebased against master |
@matklad mind taking over in reviewing this? |
@alexcrichton unfortunately I don't have enough time now :( |
@nodakai unfortunately I'm also a little short on time right now, so it may be awhile before I can get to this. It's a pretty huge diff so if you can do anything to shrink it that'd definitely be appreciated. |
@alexcrichton No need to rush, take your time. As you know, the cargo test suite consists of an internal library |
|
||
#[must_use] |
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.
👍 💯
📌 Commit d43ee1d has been approved by |
⌛ Testing commit d43ee1d with merge e237a19259561f36d75507bb4b2a8a47bbc5f3b2... |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit d43ee1d has been approved by |
cargotest/support: remove internal mutability in favor of switching types `Cell<bool>` was removed from `ProjectBuilder`. Instead `PhantomData<T>` was added to it (and `RepoBuilder`) to manage state transition in the type level (`T` is either `Configuring` or `Done`.) `ProjectBuilder::cargo_process()` was removed as its design heavily depended on the internal mutability. Also added `#[must_use]` to `ProjectBuilder` and `RepoBuilder` to check for call sites of their `build()` method.
☀️ Test successful - status-appveyor, status-travis |
Cell<bool>
was removed fromProjectBuilder
. InsteadPhantomData<T>
was added to it (andRepoBuilder
) to manage state transition in the type level (T
is eitherConfiguring
orDone
.)ProjectBuilder::cargo_process()
was removed as its design heavily depended on the internal mutability.Also added
#[must_use]
toProjectBuilder
andRepoBuilder
to check for call sites of theirbuild()
method.