Well-formedness dev guide page#2889
Conversation
|
|
||
| Wfck doesn't check or validate lifetimes, this is handled in [MIR](../borrow-check.md). | ||
|
|
||
| ## Generating Obligations |
There was a problem hiding this comment.
I think this makes more sense as being part of the wfness of terms section, item wfck doesn't really start by doing this
|
|
||
| Here we have a trivial bound that does not hold, because `String` is not `Copy`. | ||
|
|
||
| ## When We Don't Fully Do Wfck |
There was a problem hiding this comment.
i think as a general rule we should never just say "wfck" on its own in this, we should always explicitly say if we're talking about wfness of terms or checking wf of items.
| @@ -0,0 +1,166 @@ | |||
| # Well-Formedness of Terms and Items | |||
|
|
|||
| The area of the analysis pipeline that deals with questions like "does `T: Debug` hold true for some data structure that uses T?" or "is this const generic parameter `const B: bool` being handed a value of the right type?" | |||
There was a problem hiding this comment.
this feels slightly off to me, i would say the trait solver deals with those questions. though i guess that kind of makes sense since the trait solver is also responsible for proving wf obligations (i.e. checking terms are wf when we require them to be)
Co-authored-by: Boxy <rust@boxyuwu.dev>
|
|
||
| Well-formedness checking is not a coherent "stage" of type checking. It gets called from various contexts, and there are places where it gets skipped partially or entirely. | ||
|
|
||
| ### Trait Objects |
There was a problem hiding this comment.
Another example to illustrate this:
trait Trait
where
for<'a> [u8]: Sized {}
fn foo(_: &dyn Trait) {}this compiles even though [u8]: Sized doesn't hold. But if you try to actually construct an &dyn Trait we'll wind up checking all the where clauses hold and get an error.
probably a nicer example to lead with so you can separate out discussion of trait object wf jank from the const generics jank working around trait object wf jank lol
|
|
||
| Here we have a trivial bound that does not hold, because `String` is not `Copy`. | ||
|
|
||
| ## When We Don't Fully Do Well-Formedness Checking |
There was a problem hiding this comment.
Structurally it feels weird to lump this all under one header instead of wellformedness of terms and wellformedness of items having its own separate lists of "jank". Though I realise some things (e.g. const generics jank) would appear in both sections
There was a problem hiding this comment.
It's a bit difficult. I like having them all here so there's a stronger emphasis on them as collective jank, but I'll see if I can rework them into the two major sections.
|
|
||
| Wfck doesn't check or validate lifetimes, this is handled in [MIR](../borrow-check.md). | ||
|
|
||
| ## Type-Level Terms |
There was a problem hiding this comment.
would in theory like this header to be "Well-Formedness of Type-Level Terms" to mirror the following "Well-Formedness of Items" header 🤔 I realise you use this name as a subheader of Type-Level terms but that feels a bit weird to me.
I don't think the primary point of this page is to explain what a "type level term" is so I wouldn't structure it too heavily around that, rather than what it means for one to be well formed
There was a problem hiding this comment.
Yeah agreed, this is a weird glossary out of nowhere. Restructuring 🫡
| - "Items wfck" can call into "Term-wfck" as Items contain Terms. | ||
| - Sometimes normalize their inner Terms first. | ||
|
|
||
| Wfck is not "number of parameters" or "parameter type" checking (AKA "kind checking"), as we might see in languages like Haskell. Neither term-wfck nor item-wfck is concerned with if a type with 2 parameters has 1 or 3 types applied to it (assuming no defaults), or if a const generic parameter has a type applied to it. These kinds of problems will get handled during HIR-ty Lowering[^hir-ty-lower], not wfck. |
There was a problem hiding this comment.
I wonder if it'd make sense to have a more general header at the end like "what isn't covered by well formedness" so that this sort-of tangent doesn't get in the way, and also we can talk about other things which one might expect is covered by wfck but actually isnt
i guess problem statement: not a huge fan of having this big paragraph here at the very start of the page :3 it feels like it takes up a lot of space and is kinda scary (talks about haskell and "kind checking") while not being all that important for probably the average reader
There was a problem hiding this comment.
That's reasonable! I figured "problems I ran into while narrowing down what well-formedness is" just had to live somewhere, and that an earlier correction made more sense than a late one. But I'll move it down and replace this with a smaller "what this isn't" link.
| @@ -0,0 +1,163 @@ | |||
| # Well-Formedness of Items and Type-Level Terms | |||
|
|
|||
| The area of analysis that produces questions like "does `T: Debug` hold true for some data structure that uses T?" or "is this const generic parameter `const B: bool` being handed a value of the right type?" for the trait solver to answer. | |||
There was a problem hiding this comment.
something about this paragraph feels odd to me and im not sure I can place why. it might just be that it feels like it makes more sense in the "Well-Formedness of Type-Level Terms" section, but also that would feel a bit weird too.
I think leading with the second paragraph "Items and Type-Level Terms are 'well formed' when they ..." feels like it would work fine and also feels better to me for some reason?
I guess concretely leading with this feels weird because:
- item wfck does more than just produce obligations
- it implies that item wfck and wellformedness of terms are one singular analysis rather than two semi-separate things
- refers to an area of analysis that hasn't previously been referred to I guess :3
There was a problem hiding this comment.
I think I can see it? But also I'd like to put the high-level "input/output" of the processes described here somewhere close to the top. I think the following paragraph isn't concrete enough in comparison. I'll wiggle things around.
|
|
||
| HRBs also skip the wfck on their subjects. | ||
|
|
||
| TODO: bit of background of why this doesn't happen. |
There was a problem hiding this comment.
u need us to chat about this or just haven't gotten around to writing down what's in your notes?
There was a problem hiding this comment.
We gotta chat about this :') This is lightly mentioned but any details are missing from my notes.
| ## Well-Formedness of Items | ||
|
|
||
| Items[^items] are, generally speaking, "Things that get defined." Item-wfck[^item-wf-module] only happens at the signature level for types and functions, including the methods and implementations. This doesn't happen for Free Type Aliases other than Const Generic Argument type checking. | ||
|
|
There was a problem hiding this comment.
probably a concrete example here of a function and going "things here are item wfck'd" and "things here are handled by normal type checking" would be useful
|
|
||
| There are two different forms of well-formedness checking: | ||
|
|
||
| - Type-Level Term[^terms] wfck (term-wfck). |
There was a problem hiding this comment.
I think we discussed this a little 1:1 but to note it down here too, I feel unsure about the term "Term wfck". I feel like it has strong implications of it being a particular analysis/pass/something.
This is the case for item wfck but not as much for wellformedness of terms which is more of a general "thing you can get the trait solver to check" and is done all over the place 🤔
I think things would be a lot closer to how I "expect" them to be if instead of saying, for example, "Item-wfck is one of the entry points where most term-wfck will get performed" we instead wrote like, "Item-wfck is one of the places where well-formedness of terms will get checked"
definitely slightly nitpicky and not entirely structural, but also I guess it's kind of a semi-big-picture framing choice so feels somewhat important :3
There was a problem hiding this comment.
This is a helpful nudge ^^ I think I misinterpreted this originally as "always specify item-wfck vs term-wfck", rather than "'ck' has specific suffix implications and isn't just an abbreviation of check"
There was a problem hiding this comment.
didn't misinterpret :3 that was the point I was making but then seeing it written out made me unsure about term-wfck as a piece of terminology 😅 this is wholly nitpicky so feel free to ignore this and we can figure it out at a later point, just wanted to make sure i wrote it down and didnt forget
There was a problem hiding this comment.
Gotcha 😌 I've been rotating this in my mind today regardless so I'm kinda fine with either I think?
Initial work off of discussions with boxy + chasing hyperlinks. Part of #2663.
Few unsolved items here:
item-wfckorterm-wfck.I've also ended up doing some syntax here "from scratch", which I could use some input on. Specifically for showing off obligations I've done:
If this works fine, cool. Otherwise, open to being told to do it a different way :)
Finally, I'm putting this in an
analysissubfolder as I've been told we need to do some structural reordering of the mdbook directory, and this should eventually live in ananalysissubfolder so might as well have it there now.Footnotes
This was "Type-Level Term" in these files before I find-replaced it all to Term, which is maybe too vague to our target audience. ↩