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
0.5.x: use higher resolution file stat fields #3049
0.5.x: use higher resolution file stat fields #3049
Conversation
cf57399
to
99b2fbf
Compare
Why Linux / Test runtime (3.2.1, release-fast, immix) failed? InflaterTest.inflaterCanInflateByteArraysWhenGivenBufferIsSmallerThanTotalOutput failed due to DataFormatException. |
may be relevant |
prepare for reworking scala-native#1635: nanosecond resolution in javalib FileTime and posixlib sys/stat This commit introduces breaking changes in public api. This commit changes stat struct fields so that it can use high resolution file stat, which is available since linux kernel 2.5.48 and later. For more detail,see linux man page https://linux.die.net/man/2/stat
99b2fbf
to
55c0b58
Compare
error disappears after running test again...🤔 |
anyway, all checks have passed. |
@i10416 Thank you for this PR and for taking some time to extract some I have read through this PR on a first pass. Could merge of this be put off I do not want to make things so difficult that nothing ever gets done. This week is a holiday week where I live, so it will take me a few days |
@@ -10,6 +10,7 @@ typedef unsigned int scalanative_uid_t; | |||
typedef unsigned int scalanative_gid_t; | |||
typedef long long scalanative_off_t; | |||
typedef long int scalanative_time_t; | |||
typedef struct timespec scalanative_timespec; |
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 believe this line is improper. POSIX 2018 (and many before, I believe) specify timespec
as being defined
in time.h
, not types.h
( probably time
was well established before types.h
was specified.)
Some else in this PR there is probably an import
which
needs to change or happen.
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.
Thank you for feedback! I will address this later.
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.
Hmm, could you tell me why scalanative_timespec
introduced here?(link below) If we use timespec from time.h, I don't think scalanative_timespec is needed. Do you mean I should create another time.h file and put scalanative_timespec
in it?
By the way, reading the comment in sys/stat.c, I guess src/main/resources/scala-native/types.h intentionally violates spec for portability.
// We don't use the "standard" types such as `dev_t` for instance
// because these have different sizes on eg. Linux and OSX. We use the
// smallest type that can hold all the possible values for the different
// systems.
struct scalanative_stat {
scalanative_dev_t st_dev; /** Device ID of device containing file. */
scalanative_dev_t st_rdev; /** Device ID (if file is character or block
special). */
scalanative_ino_t st_ino; /** File serial number. */
These types above were introduced by Martin Duhem at 2017. Is this statement "these have different sizes on eg. Linux and OSX" not the case for recent versions?
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.
NOTE: I'm not in a hurry😉 Have a nice holiday!
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.
i10416 You ask good questions. Let me finish my
highest level concern, so the PR can progress, and return to the trickery at play here.
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.
Quick answer to 1st question. I'll get back to second later (tomorrow?)
Lines 92-102 check that Scala Natives scala timespec can be passed thru
to C with no "copy-in/copy-out" code.
// struct timespec
_Static_assert(sizeof(struct scalanative_timespec) == sizeof(struct timespec),
"Unexpected size: struct timespec");
_Static_assert(offsetof(struct scalanative_timespec, tv_sec) ==
offsetof(struct timespec, tv_sec),
"offset mismatch: timespec.tv_sec");
// and so on.
From software engineering view, it is unfortunate that the C declaration of scalanative_timespec
is hand edited and hand synchronized with the corresponding Scala struct. The test would
be stronger if the former where generated from the latter. For now, the costly safeguards
are education & review. In someplaces there are "If you change .scala, also change .c" comments.
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.
Thank you!
So,
- there exist
scalanative_timespec
and otherscalanative_*
structs so that we can verify Scala struct is the same format as c struct.
From software engineering view, it is unfortunate that the C declaration of scalanative_timespec
is hand edited and hand synchronized with the corresponding Scala struct. The test would
be stronger if the former where generated from the latter. For now, the costly safeguards
are education & review. In someplaces there are "If you change .scala, also change .c" comments.
- I guess you mean it is better to put
typedef struct timespec scalanative_timespec;
intime.h
for future maintenance, though the original PR Fix #1610: add nanosecond resolution in javalib FileTime & posixlib sys/stat; requires previous PRs #1635 puts it intypes.h
.
Am I right?
Heisenbugs (indeterminate, flaky) bugs are the worst. I have not seen this failure before but will keep my eyes out for it. |
ref #3050 |
scalanative_time_t _st_atime; /** Time of last access. */ | ||
scalanative_time_t _st_mtime; /** Time of last data modification. */ | ||
scalanative_time_t _st_ctime; /** Time of last status change. */ | ||
scalanative_timespec st_atim; /** Time of last access. */ |
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 do not want to make things so difficult that nothing ever gets done.
I suspect that it is possible to introduce this PR in a way which causes
less breakage to existing users.
Hmm, how can we introduce public api changes in a less breaking way?
Is there way better than deprecation warning?
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.
SN 0.5.0 is advertised/envisioned as requiring a re-build from sources and possibly requiring source changes.
That gives us some degrees of freedom to do things
a 'right' way.
So;
- This PR should be marked in base topic as "0.5.0"
- There should be an entry in `docs/changelog/0.5.0.md"
briefly describing the required source change and
pointing to an entry in javalib.rst - There should be a section in `docs/lib/javalib.rst'
giving a fuller description and examples of the
required source change (i.e. change foo._8 to
foo.a_time to use seconds, foo.a_tim to use timespec).
Once the dust settles on this PR, I can either help you
set up the Sphinx environment on your system to build .rst (use "Makefile html" not 'scripts/makedoc") and .md files or do a followup PR for you to review.
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.
stat.c
scalanative_stat_init()
is exactly the kind of
glue code I have been trying to expunge from Scala Native.
After a bunch of network code, I had hoped to get to this one before it changed.
I think this section of code is correct/OK and will try
to queue up a follow on PR to optimize (probably to
optimize for Linux passthru with appropriate _Static guards.)
stat
is supposed to be fast (but must always be correct).
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.
There should be an entry in `docs/changelog/0.5.0.md" briefly describing the required source change and pointing to an entry in javalib.rst
There should be a section in `docs/lib/javalib.rst' giving a fuller description and examples of the required source change
Though I changed java File internal, it doesn't leak posixlib implementation for users.
In terms of source change, I think you mean docs/lib/posixlib
, don't you?
Of course, we should mention that java File metadata will support nanosecond resolution in the future(probably in 0.5.x?).
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.
- improve readability and reduce making a mistake to access wrong fields - prevent stat.scala misc changes(e.g. changing field order) from spreading around codebase
@i10416 Thank you for your understanding & patience over the holidays. I am beginning to work my way through this PR. It may take me awhile. I think Let me see if I can answer some of your direct questions first. |
javalib/src/main/scala/java/nio/file/attribute/PosixFileAttributeViewImpl.scala
Show resolved
Hide resolved
Review status, 2022-01-02 21:00 UTC Things are looking pretty good at this point. Especially if we posit a (soon) follow-on documentation PR ISO C has no My next sprint I hope to address two areas:
Sorry, am losing daylight & must run and give my back-brain some time to |
a5811b8
to
7ec4eac
Compare
As I looked through javalib File tests, I believe they cover good amount of current In terms of nanosecond file metadata APIs, this PR focuses on stat fields in (I will add some tests for st_atimespec and kinds in this PR.) |
|
LGTM - Looks good to me This PR looks ready for general review & merge in a day or so. To make it easier for reviewers to make sure the proper boxes are ticked: re: documentation I believe this is the first in a series of PRs. To not complicate this PR, I would re: testing i10415 may possibly adding some tests to either this PR or a separate javalib PR. @i10415 Thank you for your patience with my not being able to review this over the holidays. Nice to see nanosecond time fields progressing. |
d10d88e
to
80b1dae
Compare
80b1dae
to
174e9df
Compare
@i10416 You mentioned possibly doing some work to extend higher resolution stat fields to Now that this PR has merged, could I encourage you to work on If I can help, even by staying out of the way, please let me know. PR #1635 used Instant.scala in Of course, since that PR was created, Windows support has been added to SN. So the |
Yes, off course. |
rel #1610
prepare for reworking #1635: nanosecond resolution in javalib FileTime and posixlib sys/stat
This commit introduces breaking changes in public api
This commit changes stat struct fields so that it can use high resolution file stat, which is available since linux kernel 2.5.48 and later.
For more detail,see linux man page https://linux.die.net/man/2/stat