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.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Const
'sty
field, what is it good forRandom information
The
ty
field on const stores what kind the const parameter is (note: this is intended to be the type theory meaning of a generic kind, not to be confused withConstKind
). When using aConst
argument we have to ensure that the provided arg is of the same type/kind as the actual param:The
bar
item does not actually perform any checks that the correct kinds of const parameters are provided as arguments.Every const generic argument is desugared to an anonymous const item which is typeck'd separately from its parent item. When typeck'ing the const item the return type is set to the type of the const param it is an argument for.
An exception to this is arguments that are being inferred, either via the
generic_arg_infer
feature or when generics in paths have been elided. These do not have anon consts.We currently do not relate the
ty
field when relating consts, instead we just ICE if the twoty
's compared viaPartialEq
are not the same.If we were to support directly using const items (i.e. assoc consts) as const arguments for a
min_generic_const_exprs
(mgce
) (i.e.foo::<<T as Trait<_>>::ASSOC>()
) There would no longer be an anon const getting typeck'd and we would need to actually check that the types of const arguments are correct.If we were to support const generics that have types that depend on other generics it would be valuable to allow "forward declared" types of const params, i.e.
struct Foo<const N: T, T>
, as otherwise you could not have a non-defaulted const parameter of a type that has default i.e.struct Foo<const N: T, T = u32>
. This would mean we are no longer able to construct the expected ty of the const arg during ast lowering for the substs, it would only be available once they have all been built.Allowing this would make the current planned query feeding solution for typechecking anonymous constants inadequate as we would be able to end up with infer vars in the expected type and we are unable to have infer vars in query inputs/outputs:
If we're allowing
const N: T, T
, as previously mentioned, we would not even be able to construct the expected type to feed even if it did not contain infer vars, i.e.foo::<{ 1 }, u8>()
.Additionally it would be nice if the following were to compile:
This would require inferring the type infer var to
u8
by typechecking the anon const.Currently
super_relate_consts
has an assertion that bothConst
's have the samety
. This is at first was implemented via just==
but this is inadequate.With
adt_const_params
we can have const/type aliases in thety
which makes==
spurriously return false leading to ICEs. type alises are eagerly normalized at the moment so only const aliases which use lazy norm cause problems. To fix this we currently callnormalize_erasing_regions
insuper_relate_consts
before==
.Under
mgce
orT, const N: T
we wil start getting infer vars in thety
at which point this will also start spurriously ICEing because of things like?0 == ?1
not being true even though they might end up getting constrained by the end of the type relation.This assertion has caught many bugs so keeping it in some form will be valuable so just flat out removing it is not desirable.
Changes to make
A
ConstParamHasType
obligation that requires aConst
have a type equal to someTy
would potentially solve two issues that mgce would have:And as outlined in pcg-44:
Implemented in #107965
Note: dont actually know if this is possible or not
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Start type checking anon consts as part of the parent body and lower anon const const args to infer vars. When the anon const has been fully type checked use query feeding to create the defid for the anon const and relate a
ConstKind::Unevaluated
with the previously created infer var. This should be "necessary" even without supporting generic anon consts i.e.N + 1
. Just supportingfn foo<const N: T, T>
andfoo::<{ 1_u8 }, _>();
will likely need this.type_of
returned value as we only create the anon const after the return type has been inferredNot yet implemented
Change the assertion in
super_relate_consts
froma_ty == b_ty
to instead actually relate the two tys inside of a probe and ICE if it returns an error.?0 eq ?1
even if we never actually relate the two infer vars outside of the probeImplemented in #107940