Commit graph

27 commits

Author SHA1 Message Date
Chayim Refael Friedman
cc11e1a796 Unify handling of path diagnostics in hir-ty
Because it was a mess.

Previously, pretty much you had to handle all path diagnostics manually: remember to check for them and handle them. Now, we wrap the resolver in `TyLoweringContext` and ensure proper error reporting.

This means that you don't have to worry about them: most of the things are handled automatically, and things that cannot will create a compile-time error (forcing you top `drop(ty_lowering_context);`) if forgotten, instead of silently dropping the diagnostics.

The real place for error reporting is in the hir-def resolver, because there are other things resolving, both in hir-ty and in hir-def, and they all need to ensure proper diagnostics. But this is a good start, and future compatible.

This commit also ensures proper path diagnostics for value/pattern paths, which is why it's marked "feat".
2024-12-24 18:58:52 +02:00
Chayim Refael Friedman
5f25ae3d1b Lay the foundation for diagnostics in ty lowering, and implement a first diagnostic
The diagnostic implemented is a simple one (E0109). It serves as a test for the new foundation.

This commit only implements diagnostics for type in bodies and body-carrying signatures; the next commit will include diagnostics in the rest of the things.

Also fix one weird bug that was detected when implementing this that caused `Fn::(A, B) -> C` (which is a valid, if bizarre, alternative syntax to `Fn(A, B) -> C` to lower incorrectly.

And also fix a maybe-bug where parentheses were sneaked into a code string needlessly; this was not detected until now because the parentheses were removed (by the make-AST family API), but with a change in this commit they are now inserted. So fix that too.
2024-12-04 14:22:56 +02:00
Chayim Refael Friedman
41658de227 Cleanup TypeRef lowering
By removing interior mutability from it.
2024-10-28 17:38:37 +02:00
Chayim Refael Friedman
061e5d7f71 Shrink Path to 16 bytes
Thanks to the observation (supported by counting) that the vast majority paths have neither generics no type anchors, and thanks to a new datastructure `ThinVecWithHeader` that is essentially `(T, Box<[U]>)` but with the size of a single pointer, we are able to reach this feat.

This (together with `ThinVecWithHeader`) makes the possibility to shrink `TypeRef`, because most types are paths.
2024-10-25 06:44:56 +03:00
Chayim Refael Friedman
89c0ffa6b0 Build source map for hir_def::TypeRefs
So that given a `TypeRef` we will be able to trace it back to source code.

This is necessary to be able to provide diagnostics for lowering to chalk tys, since the input to that is `TypeRef`.

This means that `TypeRef`s now have an identity, which means storing them in arena and not interning them, which is an unfortunate (but necessary) loss but also a pretty massive change. Luckily, because of the separation layer we have for IDE and HIR, this change never crosses the IDE boundary.
2024-10-25 06:15:04 +03:00
Chayim Refael Friedman
9d3368f2c2 Properly account for editions in names
This PR touches a lot of parts. But the main changes are changing
`hir_expand::Name` to be raw edition-dependently and only when necessary
(unrelated to how the user originally wrote the identifier),
and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware
(this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly
escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined
   by the edition of the edited crate. This is nice for IDE features,
   but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update
   tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-16 16:46:24 +03:00
Lukas Wirth
2346a80ab4 Remove Name::to_smol_str 2024-07-16 12:43:58 +02:00
Johann Hemmann
3839f9a9a2 needless_borrow 2024-01-19 17:31:01 +01:00
Lukas Wirth
92d447f976 🧹 2023-11-28 10:55:40 +01:00
Lukas Wirth
e243a03da1 Desugar builtin#format_args 2023-09-06 15:21:41 +02:00
hkalbasi
3a1054fc1c Replace x with it 2023-07-06 17:33:17 +03:30
Lukas Wirth
69cd3c30ac Format let-else 2023-07-03 20:34:09 +02:00
hkalbasi
a481e004b0 Lower const params with a bad id 2023-06-11 00:39:28 +03:30
Lukas Wirth
bca8029a6e Move Expander and LowerCtx into separate modules 2023-04-17 20:44:06 +02:00
Lukas Wirth
0bb9a17312 internal: Move layout logic from hir-def to hir-ty 2023-04-16 12:21:12 +02:00
hkalbasi
b7b9ae59a0 desugar ? operator 2023-03-17 13:08:35 +03:30
hkalbasi
cd67589f63 beginning of MIR 2023-02-27 23:45:54 +03:30
Lukas Wirth
4aee911ce4 Slim down GenericArgs by one usize once more 2023-02-14 17:41:16 +01:00
Lukas Wirth
853ae1927d Slim down GenericArgs by one usize 2023-02-14 17:40:24 +01:00
Lukas Wirth
4c2aef650a Slim down AssociatedTypeBinding by one usize 2023-02-14 17:40:24 +01:00
Lukas Wirth
a18ebf40cb Don't allocate the generic_args vec in hir_def::Path if it consists only of None args 2023-02-14 17:01:38 +01:00
Lukas Wirth
68723043db Split out hir-def attribute handling parts into hir-expand 2023-01-09 19:29:28 +01:00
Ryo Yoshida
63cba43b48
Collect generic arguments in associated type bindings 2022-10-27 19:18:59 +09:00
Amos Wenger
7e285e1ef5 Run cargo fmt 2022-07-20 15:06:15 +02:00
Amos Wenger
816f7fe12a Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
Lukas Wirth
2642f64570 internal: Simplify 2022-06-23 20:08:29 +02:00
Peh
1f011fa4a3 style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
Renamed from crates/hir_def/src/path.rs (Browse further)