Skip to content

Rollup of 12 pull requests #140562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 50 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cf26d82
chore: remove redundant words in comment
pudongair Mar 26, 2025
d81559a
Refactor `diy_float`
TDecking Mar 31, 2025
5a20701
Change signature of File::try_lock and File::try_lock_shared
cberner Apr 4, 2025
7302f8e
Implement error::Error for TryLockError
cberner Apr 6, 2025
e5fb426
docs: Add example to `Iterator::take` with `by_ref`
ongardie Apr 14, 2025
0369ccb
Fix some grammar errors and hyperlinks in doc for `trait Allocator`
Lee-Janggun Apr 14, 2025
31cb737
simd_select_bitmask: the 'padding' bits in the mask are just ignored
RalfJung Apr 19, 2025
3a372e3
std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concu…
xizheyin Apr 20, 2025
2b8e9b5
Enable [behind-upstream] triagebot option
xizheyin Apr 25, 2025
451d73f
use repo name in push pr title
Apr 28, 2025
3d23917
Add an example of the example of an edition migration lint
ehuss Apr 28, 2025
b0e675b
Add documentation on how to migration the edition of the standard lib…
ehuss Apr 28, 2025
0aae3ca
Update mdbook to 0.4.48
ehuss Apr 28, 2025
5050037
Add documentation on how to stabilize the compiler edition
ehuss Apr 28, 2025
5ce6fa7
Merge pull request #2361 from ehuss/update-mdbook
JohnTitor Apr 29, 2025
c466cd0
Update compiler-src.md
smanilov Apr 29, 2025
a2b3f11
Filter out LoongArch features not supported by the current LLVM version
heiher Apr 29, 2025
74b55b4
Add comment to remind filtering unsupported features when adding new …
heiher Apr 29, 2025
e2fb99c
Introduce a normalization chapter
BoxyUwU Apr 29, 2025
fcec80a
Merge pull request #2266 from BoxyUwU/normalization
lcnr Apr 29, 2025
7f1ae9b
Fix footnotes
BoxyUwU Apr 29, 2025
0f9146b
Merge pull request #2365 from BoxyUwU/norm_footnotes
BoxyUwU Apr 29, 2025
c7eeeb1
Merge PR #2360: Add docs about stabilizing an edition
traviscross Apr 29, 2025
029a2c4
Merge pull request #2363 from smanilov/patch-1
Apr 29, 2025
48bbf5a
for a more friendly output
Apr 29, 2025
7135a9f
Merge pull request #2366 from rust-lang/tshepang-patch-1
jieyouxu Apr 30, 2025
b1c8693
Merge pull request #2359 from rust-lang/tshepang-repo-name
jieyouxu Apr 30, 2025
b02178b
Merge pull request #2352 from xizheyin/enable-behind-upstream
jieyouxu Apr 30, 2025
482ad5c
Remove redundant min-llvm-version annotations for LoongArch tests
heiher May 1, 2025
3e0cbbb
adds 'with' to help clarify how to build a new compiler
martinomburajr May 1, 2025
27eb274
Preparing for merge from rustc
invalid-email-address May 1, 2025
560de7e
Merge from rustc
invalid-email-address May 1, 2025
9a3a212
adds commas
martinomburajr May 1, 2025
9ce6c52
Merge pull request #2368 from martinomburajr/master
May 1, 2025
bf06eaf
Merge pull request #2367 from rust-lang/rustc-pull
May 1, 2025
714ea10
rustdoc: Fix doctest heuristic for main fn wrapping
fmease Apr 29, 2025
5d30814
allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`
folkertdev May 1, 2025
bc68d3a
Improve error output in case `nodejs` or `npm` is not installed for r…
GuillaumeGomez May 1, 2025
b75a19c
Rollup merge of #138703 - pudongair:master, r=workingjubilee
GuillaumeGomez May 1, 2025
b4e16d1
Rollup merge of #139186 - TDecking:float, r=workingjubilee
GuillaumeGomez May 1, 2025
4b13179
Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubilee
GuillaumeGomez May 1, 2025
c18481d
Rollup merge of #139780 - ongardie:iterator-take-by_ref-example, r=wo…
GuillaumeGomez May 1, 2025
63c46b8
Rollup merge of #139802 - Lee-Janggun:fix-allocate-hyperlink, r=worki…
GuillaumeGomez May 1, 2025
66fd8b1
Rollup merge of #140034 - RalfJung:simd_select_bitmask-padding, r=wor…
GuillaumeGomez May 1, 2025
8c9393c
Rollup merge of #140062 - xizheyin:issue-139958, r=workingjubilee
GuillaumeGomez May 1, 2025
1840f10
Rollup merge of #140420 - fmease:rustdoc-fix-doctest-heur, r=Guillaum…
GuillaumeGomez May 1, 2025
9d2a3d8
Rollup merge of #140460 - heiher:issue-140455, r=Urgau
GuillaumeGomez May 1, 2025
cf943e1
Rollup merge of #140538 - tshepang:rust-push, r=jieyouxu
GuillaumeGomez May 1, 2025
95abfbb
Rollup merge of #140552 - folkertdev:naked-function-rustc_std_interna…
GuillaumeGomez May 1, 2025
633788e
Rollup merge of #140556 - GuillaumeGomez:improve-rustdoc-gui-tool-err…
GuillaumeGomez May 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/doc/rustc-dev-guide/src/normalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ This is likely to change as const generics functionality is improved, for exampl

There are two forms of normalization, structural (sometimes called *shallow*) and deep. Structural normalization should be thought of as only normalizing the "outermost" part of a type. On the other hand deep normalization will normalize *all* aliases in a type.

In practice structural normalization can result in more than just the outer layer of the type being normalized[^1], but this behaviour should not be relied upon. Unnormalizable non-rigid aliases making use of bound variables (`for<'a>`) cannot be normalized by either kind of normalization.
In practice structural normalization can result in more than just the outer layer of the type being normalized, but this behaviour should not be relied upon. Unnormalizable non-rigid aliases making use of bound variables (`for<'a>`) cannot be normalized by either kind of normalization.

As an example: conceptually, structurally normalizing the type `Vec<<u8 as Identity>::Assoc>` would be a no-op, whereas deeply normalizing would give `Vec<u8>`. In practice even structural normalization would give `Vec<u8>`, though, again, this should not be relied upon.

Expand Down Expand Up @@ -162,8 +162,6 @@ In this example:
- Normalizing `<?x as Iterator>::Item` results in some new inference variable `?y`, as `<?x as Iterator>::Item` is an ambiguous alias
- The final result is that normalizing `Foo<?x>` results in `?y`

[^1]: In the new solver this is done implicitly

## How to normalize

When interfacing with the type system it will often be the case that it's necessary to request a type be normalized. There are a number of different entry points to the underlying normalization logic and each entry point should only be used in specific parts of the compiler.
Expand Down Expand Up @@ -198,11 +196,7 @@ There are two ways to deeply normalize with an `InferCtxt`, `normalize` and `dee

When the new solver is stabilized the `infcx.at.normalize` function will be removed and everything will have been migrated to the new deep or structural normalization methods. For this reason the `normalize` function is a no-op under the new solver, making it suitable only when the old solver needs normalization but the new solver does not.

Using `deeply_normalize` will result in errors being emitted when encountering ambiguous aliases[^1] as it is not possible to support normalizing *all* ambiguous aliases to inference variables[^2]. `deeply_normalize` should generally only be used in cases where we do not expect to encounter ambiguous aliases, for example when working with types from item signatures.

[^1]: There is a subtle difference in how ambiguous aliases in binders are handled between old and new solver. In the old solver we fail to error on some ambiguous aliases inside of higher ranked types whereas the new solver correctly errors.

[^2]: Ambiguous aliases inside of binders cannot be normalized to inference variables, this will be covered more later.
Using `deeply_normalize` will result in errors being emitted when encountering ambiguous aliases[^2] as it is not possible to support normalizing *all* ambiguous aliases to inference variables[^3]. `deeply_normalize` should generally only be used in cases where we do not expect to encounter ambiguous aliases, for example when working with types from item signatures.

##### `infcx.query_normalize`

Expand Down Expand Up @@ -281,7 +275,7 @@ Ultimately this means that it is not always possible to ensure all aliases insid

Diverging aliases, like ambiguous aliases, are normalized to inference variables. As normalizing diverging aliases results in trait solver cycles, it always results in an error in the old solver. In the new solver it only results in an error if we wind up requiring all goals to hold in the current context. E.g. normalizing diverging aliases during HIR typeck will result in an error in both solvers.

Alias well formedness doesn't require that the alias doesn't diverge[^1], this means that checking an alias is well formed isn't sufficient to cause an error to be emitted for diverging aliases; actually attempting to normalize the alias is required.
Alias well formedness doesn't require that the alias doesn't diverge[^4], this means that checking an alias is well formed isn't sufficient to cause an error to be emitted for diverging aliases; actually attempting to normalize the alias is required.

Erroring on diverging aliases being a side effect of normalization means that it is very *arbitrary* whether we actually emit an error, it also differs between the old and new solver as we now normalize in less places.

Expand All @@ -300,10 +294,16 @@ struct Bar<T: ?Sized = <u8 as Trait>::Diverges<u8>>(Box<T>);

In this example a diverging alias is used but we happen to not emit an error as we never explicitly normalize the defaults of generic parameters. If the `?Sized` opt out is removed then an error is emitted because we wind up happening to normalize a `<u8 as Trait>::Diverges<u8>: Sized` goal which as a side effect results in erroring about the diverging alias.

Const aliases differ from type aliases a bit here; well formedness of const aliases requires that they can be successfully evaluated (via [`ConstEvaluatable`][const_evaluatable] goals). This means that simply checking well formedness of const arguments is sufficient to error if they would fail to evaluate. It is somewhat unclear whether it would make sense to adopt this for type aliases too or if const aliases should stop requiring this for well formedness[^2].
Const aliases differ from type aliases a bit here; well formedness of const aliases requires that they can be successfully evaluated (via [`ConstEvaluatable`][const_evaluatable] goals). This means that simply checking well formedness of const arguments is sufficient to error if they would fail to evaluate. It is somewhat unclear whether it would make sense to adopt this for type aliases too or if const aliases should stop requiring this for well formedness[^5].

[^1]: In the new solver this is done implicitly

[^2]: There is a subtle difference in how ambiguous aliases in binders are handled between old and new solver. In the old solver we fail to error on some ambiguous aliases inside of higher ranked types whereas the new solver correctly errors.

[^3]: Ambiguous aliases inside of binders cannot be normalized to inference variables, this will be covered more later.

[^1]: As checking aliases are non-diverging cannot be done until they are fully concrete, this would either imply that we cant check aliases are well formed before codegen/const-evaluation or that aliases would go from being well-formed to not well-formed after monomorphization.
[^4]: As checking aliases are non-diverging cannot be done until they are fully concrete, this would either imply that we cant check aliases are well formed before codegen/const-evaluation or that aliases would go from being well-formed to not well-formed after monomorphization.

[^2]: Const aliases certainly wouldn't be *less* sound than type aliases if we stopped doing this
[^5]: Const aliases certainly wouldn't be *less* sound than type aliases if we stopped doing this

[const_evaluatable]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/type.ClauseKind.html#variant.ConstEvaluatable