-
Notifications
You must be signed in to change notification settings - Fork 453
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
doc: lean.h
#3846
doc: lean.h
#3846
Conversation
Mathlib CI status (docs):
|
src/include/lean/lean.h
Outdated
A notable example of types which *do* satisfy `lean_is_ctor` are structure types which are represented | ||
as inductive types with a single constructor (whose parameters are the structure's fields). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is phrased as if it's an exception, but it really isn't, given the way the elaborator treats structures. What about:
A notable example of types which *do* satisfy `lean_is_ctor` are structure types which are represented | |
as inductive types with a single constructor (whose parameters are the structure's fields). | |
Behind the scenes, structure types are inductive types with a single constructor (whose parameters are the structure's fields), so values of structure types typically satisfy `lean_is_ctor`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the phrasing better, but now there's a weird transition from the previous sentence. So perhaps we can just remove this sentence entirely?
By the way, the easiest way you can verify layout behavior is to make a test program structure S where
a : String
b : Bool
c : UInt64
d : Array Nat
e : UInt8
def foo (x : S) : UInt64 := x.c and then compile it and look in Spoiler:
so we conclude that they are stored in the order Based on some additional testing, I conclude that the fields are bucketed by alignment and placed in decreasing order by alignment but otherwise in textual order. This ordering has the nice property that padding is never needed between fields. I'm not sure what happens on 32-bit architectures though, since in that case pointers are not the most-aligned things (UInt64 has alignment 8 but void* has alignment 4). |
From a documentation / explanation point of view, I'm not sure about the idea of spreading the layout algorithm over these individual functions. I think the best approach would be to have the layout algorithm in one place (e.g. |
I added docs for the layout algorithm in #3915. This should take some of the pressure off to try to explain the details in individual accessors. |
Co-authored-by: David Thrane Christiansen <[email protected]>
I've removed my (incorrect) description of the layout algorithm now, instead linking to @digama0's section in the Lean Manual. I've kept the examples for |
ping |
@marcusrossel Thanks for the PR and sorry for the long wait. We took a look at the PR in the triage team meeting and decided that we would like to keep documentation on this level concentrated in ffi.md so it doesn't go out of sync. Also, |
This PR adds documentation comments for a few functions in
lean.h
. This was previously discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Structure.20in.20FFI/near/431985775I think it would be good if someone knowledgable (@digama0?) could check that the content of the comments is actually correct.