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

Chalkify: Add builtin Copy/Clone #60183

Merged
merged 3 commits into from
Apr 26, 2019

Conversation

tmandry
Copy link
Member

@tmandry tmandry commented Apr 22, 2019

This was left over from when closure copy and clone were gated behind
feature flags.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 22, 2019
@tmandry
Copy link
Member Author

tmandry commented Apr 22, 2019

cc @scalexm, feel free to self-assign if you'd like to review

@scalexm
Copy link
Member

scalexm commented Apr 23, 2019

r? @scalexm

Copy link
Member

@scalexm scalexm left a comment

Choose a reason for hiding this comment

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

LGTM, left two small comments.

use rustc::hir::def_id::DefId;
use crate::lowering::Lower;
use crate::generic_types;

fn builtin_impl_clause(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just add a small comment like:

/// Return a predicate of the form:
/// `Implemented(ty: Trait) :- Implemented(nested: Trait)... `
/// where `Trait == Trait(trait_def_id)`

or whatever

// int vars and float vars are always `Copy`.
// Other vars will trigger an ambiguity.
ty::Infer(..) => {
push_builtin_impl(tcx.types.i32, &[]);
Copy link
Member

Choose a reason for hiding this comment

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

These four solutions are only there to artificially trigger an ambiguity if we encounter an inference variable whatever its type, because we don't want to actually enumerate all solutions.

If we want int and float vars to always be Copy / Clone without having to resolve them, we should add a match arm:

ty::Infer(Infer::Float(..)) | ty::Infer(Infer::Int(..)) => push_builtin_impl(ty, &[]),

And probably do that for Sized as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding the match arm makes sense, but is this more of an optimization or a behavior change? (Leaving aside the fact that not all integer/float types were included.) Was there any reason that you included these four types in particular?

Copy link
Member

Choose a reason for hiding this comment

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

This would be a change of behavior, but probably would only affect error reporting in the end?

We’re talking about goals like ?T: Clone, eventually either ?T is resolved and the goal will be re-evaluated, or ?T remains unresolved and we’ll have a type inference error so I guess it does not matter...

Anyway I think that the code in rustc::traits::select does say that unresolved int / float inference variables always implement Copy / Clone (and probably does the same for Sized), so let’s do that.

I included these four types so that each kind of inference variable has at least two solutions to unify against, in order to trigger ambiguity. For example, if I only pushed i32 and f32 as solutions, then an ?IntVar inference variable would only unify against i32 and the solver would think that the only solution to my goal is i32: Clone and would arbitrarily think that ?IntVar == i32, while I wanted an ambiguous answer.

However if we only cared about triggering ambiguity for type variables (because we would now eagerly answer Implemented(?IntVar: Clone)), then pushing only two arbitrary solutions (e.g. f32 and i32) would suffice since type variables will unify with whatever they want.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, done.

@scalexm
Copy link
Member

scalexm commented Apr 25, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Apr 25, 2019

📌 Commit 56ab3e7 has been approved by scalexm

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 25, 2019
Centril added a commit to Centril/rust that referenced this pull request Apr 25, 2019
Centril added a commit to Centril/rust that referenced this pull request Apr 25, 2019
Centril added a commit to Centril/rust that referenced this pull request Apr 26, 2019
bors added a commit that referenced this pull request Apr 26, 2019
Rollup of 12 pull requests

Successful merges:

 - #59734 (Prevent failure in case no space left on device in rustdoc)
 - #59940 (Set cfg(test) when rustdoc is running with --test option)
 - #60134 (Fix index-page generation)
 - #60165 (Add Pin::{into_inner,into_inner_unchecked})
 - #60183 (Chalkify: Add builtin Copy/Clone)
 - #60225 (Introduce hir::ExprKind::Use and employ in for loop desugaring.)
 - #60247 (Implement Debug for Place using Place::iterate)
 - #60259 (Derive Default instead of new in applicable lint)
 - #60267 (Add feature-gate for f16c target feature)
 - #60284 (Do not allow const generics to depend on type parameters)
 - #60285 (Do not ICE when checking types against foreign fn)
 - #60289 (Make `-Z allow-features` work for stdlib features)

Failed merges:

r? @ghost
@bors bors merged commit 56ab3e7 into rust-lang:master Apr 26, 2019
@tmandry tmandry deleted the chalk-builtin-copy-clone branch May 6, 2019 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants