or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
const wf bounds implementation
This is a way to fix https://github.com/rust-lang/rust/issues/68436#issuecomment-663190861, the goal is to pretty much implement proposal 2.
One problem is dealing with desugarings. Example:
I do not think that the const in the where clause should imply the const in function body here. Proving equality here is impossible in the general case and any non general solution puts a stability requirement on how exactly
for
-loops are implemented.I therefore think we should only allow basic arithmetic, arbitrary function calls, and generic constants.
This restriction is probably fairly close to simply walking the MIR and erroring when encountering a terminator other than
Goto
,Return
,Call
orAssert
.Examples of what's allowed under this proposal:
4 + N
,N * 2
,N.saturating_sub(1) + 10
,std::mem::size_of::<T>()
,T::ASSOC + 10
andfoo::<T>() + bar::<T, N>() - 3
.We would forbid things like
if N > 0 { 100 / N } else { 10 }
and the expression used in the above example for now (and recommend wrapping them inside of aconst fn
instead). If expressions like this end up being fine after we implemented this, it should always be possible to allow them later.We do not yet add a special syntax for const wf bounds for now. If required, we could use something like
where (1 + N)
in the future.Implementation
We already have a
PredicateKind::ConstEvaluatable
for every anonymous constant during typeck at the moment. Instead of having to prove this predicate for every anon const, consts inwhere
bounds and function signatures get added to thecaller_bounds
of the relevantParamEnv
instead.If we now want to check
PredicateKind::ConstEvaluatable
for a const inside of the function, we first check if it depends on any generic parameter (probably using something similar to #74595). If so, we search for an equal const in theParamEnv
.To implement this comparision we will convert MIR (
mir_const
ormir_validated
, so optimizations don't affect this) to an abstract term tree and then relate that term tree with the term trees of allPredicateKind::ConstEvaluatable
in theparam_env
.The conversion from MIR to an abstract term tree would be a query akin to
query anon_to_abstract(DefId) -> Option<AbstractConst>
.