Stream: wg-traits

Topic: unification of const values


nikomatsakis (Oct 07 2019 at 14:42, on Zulip):

Hey @oli, @varkor :

I am looking at the code that handles unification of const values, and I have a question. Currently it does this:

        (a_val @ ConstValue::Scalar(Scalar::Raw { .. }), b_val @ _)
            if a.ty == b.ty && a_val == b_val =>
        {
            Ok(tcx.mk_const(ty::Const {
                val: a_val,
                ty: a.ty,
            }))
        }

This kind of surprises me. I would expect two scalars to be relatable, but this seems to "equate" a scalar with any other constant value. Oh, I see, it's relating a_val == b_val

nikomatsakis (Oct 07 2019 at 14:43, on Zulip):

I guess it would be equivalent to do something like this?

(ConstValue::Scalar(a_val @ ..), (constValue::Scalar(b_val @ ..) if a.ty == b.ty && a_val == b_val => { .. }
nikomatsakis (Oct 07 2019 at 14:45, on Zulip):

I guess this FIXME answers my next question:

        // FIXME(const_generics): we should either handle `Scalar::Ptr` or add a comment
        // saying that we're not handling it intentionally.

which was basically "what about Ptr?"

varkor (Oct 07 2019 at 23:20, on Zulip):

@nikomatsakis: yes, that's right — what you've written is clearer

varkor (Oct 07 2019 at 23:20, on Zulip):

see https://github.com/rust-lang/rust/pull/64986/files#diff-af1c8bc6ae3623b749b5aebeaa1e0bffR575-R578 also, which refactors that method a little bit

varkor (Oct 07 2019 at 23:21, on Zulip):

it seems more readable there

Last update: Nov 18 2019 at 00:40UTC