Uh oh!
There was an error while loading. Please reload this page.
Allow constant expressions in [Type * n]. - #5112
Conversation
sanxiyn
commented
Feb 26, 2013
It seems to me that the problem is |
pcwalton
commented
Feb 26, 2013
So you will need to be careful about situations like this: Here the right order to evaluate the constants—and determine their types—is
|
nikomatsakis
commented
Feb 26, 2013
Why not intertwine constant eval and type checking? If a constant appears in a type, we start to evaluate it. If that encounters a cyclic situation, report an error. We already do this for type expansion. |
nikomatsakis
commented
Feb 26, 2013
I meant not "type evaluation" but rather "type collection", I guess |
nikomatsakis
commented
Feb 26, 2013
There are still the unresolved questions of precisely what sort of constant expressions to allow. For now we could do a best effort thing where the type checker complains if it is asked to evaluate a constant that includes field projection / dereferencing or anything beyond basic arithmetic. |
pcwalton
commented
Feb 26, 2013
@nikomatsakis Sure, that's basically implicitly doing the topological sort. I don't know if we need to overly restrict what constant expressions to allow. As long as it's not cyclic I don't see any issues… |
graydon
commented
Feb 27, 2013
We had a discussion about this but I'm not finding it. Anyone have a link? Untangling this needs to happen eventually before 1.0. |
sanxiyn
commented
Feb 27, 2013
Re: previous discussion. #2317 has long comments on constant expression design, from 10 months ago. |
graydon
commented
Feb 27, 2013
I was looking for the discussion in https://github.com/mozilla/rust/wiki/Meeting-weekly-2013-01-15 concerning |
luqmana
commented
Mar 6, 2013
So this actually works now. It also fixes the So now you can do stuff like: constFOO:int = 2;let v:[int*FOO*3] = [0, ..FOO + 2 + 2];r? @pcwalton |
nikomatsakis
commented
Mar 6, 2013
I think that this PR is a good starting point but does not address some of the more subtle issues, but maybe things work out simpler than I expect. Can you add the following two tests and tell me what happens? These tests are not expected to compile successfully but we want to be sure they report the right sort of error. Test 1: Test 2: |
nikomatsakis
commented
Mar 6, 2013
See my comment on #3469: #3469 (comment) |
nikomatsakis
commented
Mar 6, 2013
By the way, I don't want to let the perfect be the enemy of the good---I am not opposed to taking this pull request, it seems like a strict improvement on the current situation! I just don't consider the matter of gracefully handling constants in types fully resolved yet. |
nikomatsakis
commented
Mar 6, 2013
luqmana
commented
Mar 6, 2013
@nikomatsakis ah no, your comments definitely make sense. The way constant expressions work now seems a bit delicate in terms of the order in which type checking and const checking happen. The two tests above would currently fail: constX:uint = Y[0];constY:[uint*X] = [3,2,1];
---
error: expected constant expr for vector length:Unsupported constant expr
constY:[uint *X] = [3,2,1];
^~~~~~~~~~structFoo{f:uint,g:[uint*X]}constX:uint = Z.f;constZ:Foo = Foo{f:3,g:[3,2,1]};
---
error: expected constant expr for vector length:Unsupported constant expr
structFoo{f: uint,g:[uint *X]}
^~~~~~~~~~I think this should be a separate issue as this pull mostly just addresses using const expressions that evaluate to uint/int to declare fixed length vectors. |
erickt
commented
Mar 7, 2013
I have to say the type Evil. This feels like a good justification for an alternative syntax. Perhaps |
luqmana
commented
Mar 7, 2013
Definitely, but i'm not sure about reception to that kind of syntax change or at least in the scope of this pull request (i think that'd require an RFC). |
graydon
commented
Mar 7, 2013
Expression language doesn't fit in pattern language or type language. I'd prefer the type form only takes an ident. |
luqmana
commented
Mar 7, 2013
@graydon so |
brendanzab
commented
Mar 15, 2013
Still no review? This would be super nice to have in glfw-rs, ticking off one of my old issues (#3469). |
graydon
commented
Mar 15, 2013
Sorry, keep hesitating because of the fragility of the approach; the long term fix is to intertwine constant eval and type checking. Not sure what subset is most useful in the short term. |
… length vector syntax.
luqmana
commented
Mar 19, 2013
I think, at least in the short term, this address the useful ability to use a const expr for declaring fixed length vectors. It also fixes the issue where the vector repeat syntax ICE's on expressions more complex than a single term. |
graydon
commented
Mar 19, 2013
Discussed at meeting today, agreed this is good enough for the short term, and we'll implement a longer-term fix intertwining constant evaluation and type checking later. |
So this is a partial fix for #3469. Partial because it only works for simple constant expressions like `32/2` and `2+2` and not for any actual constants. For example: ``` const FOO: uint = 2+2; let v: [int * FOO]; ``` results in: ``` error: expected constant expr for vector length: Non-constant path in constant expr ``` This seems to be because at the point of error (`typeck::astconv`) the def_map doesn't contain the constant and thus it can't lookup the actual expression (`2+2` in this case). So, feedback on what I have so far and suggestions for how to address the constant issue?
Don't trigger [debug_assert_with_mut_call] on debug_assert!(_.await) Fixesrust-lang#5105 cc rust-lang#5112 changelog: Don't trigger [`debug_assert_with_mut_call`] on `debug_assert!(_.await)` and move it to nursery.
[Priroda] Add `stepi` and `locals` commands, and handle repeated breakpoint hits on the same source line
5112: Update Chalk to released version r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <flodiebold@gmail.com>
So this is a partial fix for #3469. Partial because it only works for simple constant expressions like32/2and2+2and not for any actual constants.For example:
results in:
This seems to be because at the point of error (
typeck::astconv) the def_map doesn't contain the constant and thus it can't lookup the actual expression (2+2in this case).So, feedback on what I have so far and suggestions for how to address the constant issue?