Boxy
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# `Const`'s `ty` field, what is it good for ## Random 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 with `ConstKind`). When using a `Const` argument we have to ensure that the provided arg is of the same type/kind as the actual param: ```rust fn foo<const N: u8>() {} fn bar() { foo::<10_u16>(); } //~^ should error because providing a `u16` value to a `u8` const param // is not legal ``` 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 two `ty`'s compared via `PartialEq` 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: ```rust fn foo<T, const N: T>() -> T { N } fn main() { let mut a = foo::<_, { 1 }>(); // ^^^^^ expected type would be `_` a = 1_u8; } ``` 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: ```rust fn foo<const N: T, T = bool>() {} fn main() { foo::<{ 1_u8 }, _>(); } ``` This would require inferring the type infer var to `u8` by typechecking the anon const. --- Currently `super_relate_consts` has an assertion that both `Const`'s have the same `ty`. This is at first was implemented via just `==` but this is inadequate. With `adt_const_params` we can have const/type aliases in the `ty` 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 call `normalize_erasing_regions` in `super_relate_consts` before `==`. Under `mgce` or `T, const N: T` we wil start getting infer vars in the `ty` 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 a `Const` have a type equal to some `Ty` would potentially solve two issues that mgce would have: - Would actually check that provided args are of the correct type - Is checked after substs are built allowing forward declared const parameter types And as outlined in [pcg-44](https://github.com/rust-lang/project-const-generics/issues/44): - Would allow for less error prone trait/impl checks (a win for even min const generics) Implemented in [#107965](https://github.com/rust-lang/rust/pull/107965) --- Note: dont actually know if this is possible or not :upside_down_face: It seems tricky to do 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 supporting `fn foo<const N: T, T>` and `foo::<{ 1_u8 }, _>();` will likely need this. - This should allow for the desired type inference quality where type checking the anon const can infer the return type and type checking the function can infer the anon const's return type. - Sidesteps the problem of not having the expected type available during astconv of substs as we only actually create the anon const once the return type has been inferred - Don't have to deal with infer vars in the `type_of` returned value as we only create the anon const after the return type has been inferred Not yet implemented --- Change the assertion in `super_relate_consts` from `a_ty == b_ty` to instead actually relate the two tys inside of a probe and ICE if it returns an error. - It's important to do it inside of a probe as this assertion should not help code to compile. - The assertion likely will not catch every mistake as it will succeed for `?0 eq ?1` even if we never actually relate the two infer vars outside of the probe Implemented in [#107940](https://github.com/rust-lang/rust/pull/107940)

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

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.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully