mGCA: Validate const literal against expected type#152001
mGCA: Validate const literal against expected type#152001reddevilmidzy wants to merge 5 commits intorust-lang:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
very cool :) thanks for working on this |
This comment has been minimized.
This comment has been minimized.
…=oli-obk Dont strip const blocks in array lengths r? oli-obk mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong. We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals. Once we properly support literals in `hir::ConstArgKind` (see rust-lang#152139 rust-lang#152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :) Fixes rust-lang/rustfmt#6788 The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from `const {}` to `{}`. I'm not entirely sure why this was happening. cc @rust-lang/rustfmt How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
…=oli-obk Dont strip const blocks in array lengths r? oli-obk mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong. We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals. Once we properly support literals in `hir::ConstArgKind` (see rust-lang#152139 rust-lang#152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :) Fixes rust-lang/rustfmt#6788 The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from `const {}` to `{}`. I'm not entirely sure why this was happening. cc @rust-lang/rustfmt How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
…=oli-obk Dont strip const blocks in array lengths r? oli-obk mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong. We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals. Once we properly support literals in `hir::ConstArgKind` (see rust-lang#152139 rust-lang#152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :) Fixes rust-lang/rustfmt#6788 The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from `const {}` to `{}`. I'm not entirely sure why this was happening. cc @rust-lang/rustfmt How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
…=oli-obk Dont strip const blocks in array lengths r? oli-obk mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong. We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals. Once we properly support literals in `hir::ConstArgKind` (see rust-lang#152139 rust-lang#152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :) Fixes rust-lang/rustfmt#6788 The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from `const {}` to `{}`. I'm not entirely sure why this was happening. cc @rust-lang/rustfmt How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
Rollup merge of #152234 - BoxyUwU:dont_strip_const_blocks, r=oli-obk Dont strip const blocks in array lengths r? oli-obk mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong. We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals. Once we properly support literals in `hir::ConstArgKind` (see #152139 #152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :) Fixes rust-lang/rustfmt#6788 The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from `const {}` to `{}`. I'm not entirely sure why this was happening. cc @rust-lang/rustfmt How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
e08830e to
cd5b323
Compare
This comment has been minimized.
This comment has been minimized.
|
Haha, ICE occurs in other tests... |
ac69206 to
ca77eab
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
In ten crash tests, the ICE disappeared; however, in tests/crashes/117460.rs, tests/crashes/114212-2.rs and tests/crashes/114212.rs, adding the main function caused the ICE to occur again.
| @@ -0,0 +1,23 @@ | |||
| //! Regression test for <https://github.com/rust-lang/rust/issues/116554> | |||
There was a problem hiding this comment.
This issue was closed; is there a need to add further testing?
There was a problem hiding this comment.
unsure, I will look over all the GCE tests (outside of this PR) at some point soon and see which ones are worth keeping
| @@ -1,14 +0,0 @@ | |||
| //@ known-bug: #101036 | |||
| #![feature(generic_const_exprs)] | |||
|
|
|||
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Boxy <rust@boxyuwu.dev>
75e7e18 to
2b5c8b7
Compare
This comment has been minimized.
This comment has been minimized.
| let str_bytes = s.as_str().as_bytes(); | ||
| ty::ValTree::from_raw_bytes(tcx, str_bytes) | ||
| } | ||
| (ast::LitKind::Str(s, _), ty::Str) if tcx.features().deref_patterns() => { |
There was a problem hiding this comment.
you've deleted the logic here for string literals being of type str under deref_patterns. I don't know why there's no test that cares about this though 🤔
There was a problem hiding this comment.
The existing (ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() and (ast::LitKind::Str(s, _), ty::Str) if tcx.features().deref_patterns() had identical processing logic, so I've enabled both patterns to be handled as (ast::LitKind::Str(s, _), _) !
There was a problem hiding this comment.
Hmm yeah you're right about the actual ValTree structure 🤔 I think there is a behaviour difference now though. Previously if there was an expected type of str the valtree's type would be str whereas now its always &str.
If that doesn't actually affect anything in practice then I guess we should just... always have the &str type and then maybe one day when it breaks something we can get a test
| (ty::ValTree::from_scalar_int(tcx, scalar_int), Ty::new_uint(tcx, ui)) | ||
| } | ||
| (ast::LitKind::Int(_, ast::LitIntType::Unsigned(_)), _) if neg => return None, | ||
| (ast::LitKind::Int(n, ast::LitIntType::Signed(i)), _) => { |
There was a problem hiding this comment.
you can merge the branches for unsuffixed with type hint, and suffixed with OR patterns:
| (ast::LitKind::Int(n, ast::LitIntType::Signed(i)), _) => { | |
| (ast::LitKind::Int(n, ast::LitIntoType::Unsuffixed), ty::Int(i)) | |
| | (ast::LitKind::Int(n, ast::LitIntType::Signed(i)), _) => { |
can do the same for handling of unsuffixed vs unsigned too
There was a problem hiding this comment.
I tried the code you suggested, but it failed to compile because each type was different. 😢
I'll see if I can handle this with a more fancy pattern.
There was a problem hiding this comment.
ah if that pattern doesn't "just work" then it seems fine to keep it as is :)
|
cool! sorry for a lot of comments but this is looking really good :) |
2b5c8b7 to
bdb21eb
Compare
|
In my current code, an ICE will occur in the Looking at the stacktrace and log, it appears that after returning How would you recommend handling this situation? |
No worries at all — I really appreciate the detailed feedback. Thanks for taking the time to review (_ _) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
9 similar comments
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
does it still ICE after removing some of the checks you had for types being equal? If so I'd just remove that test |
close: #151625
close: #150983
todo
lit_to_constmethod test coverage