-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Split std/times
#18378
Split std/times
#18378
Conversation
Add module `std/times/core` Add module `std/times/durations`
Remove `{.raises: [Defect].}`
as the CI logs say:
PrivateAccess is only available for nim >= 1.5.1 so this can't be used during bootstrap unless csources_v1 gets updated to 1.6 Other than that, nothing against splitting std/times, but IMO we should build Durations on top of
|
Does that mean I shouldn't use |
# This is really bad, but overflow checks are broken badly for | ||
# ints on the JS backend. See #6752. | ||
{.push overflowChecks: off.} | ||
proc `*`(a, b: int64): int64 = | ||
system.`*`(a, b) | ||
proc `*`(a, b: int): int = | ||
system.`*`(a, b) | ||
proc `+`(a, b: int64): int64 = | ||
system.`+`(a, b) | ||
proc `+`(a, b: int): int = | ||
system.`+`(a, b) | ||
proc `-`(a, b: int64): int64 = | ||
system.`-`(a, b) | ||
proc `-`(a, b: int): int = | ||
system.`-`(a, b) | ||
proc inc(a: var int, b: int) = | ||
system.inc(a, b) | ||
proc inc(a: var int64, b: int) = | ||
system.inc(a, b) | ||
{.pop.} | ||
|
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 decided to remove this for now, to make things easier. This still needs to be addressed somehow though, perhaps by disabling overflow checks for the JS backend in system
?
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 would be addressed by timotheecour#762 (int128
which can be implemented on top of jsBigInt on js backend)
@@ -2067,7 +1673,7 @@ template formatValue*(result: var string; value: Time, specifier: string) = | |||
|
|||
proc parse*(input: string, f: TimeFormat, zone: Timezone = local(), | |||
loc: DateTimeLocale = DefaultLocale): DateTime | |||
{.raises: [TimeParseError, Defect].} = |
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.
see #16724 (comment)
this requires csources_v1 >= 1.4.0
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.
Does that mean I should undo this change (also see #18378 (comment))?
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.
unless you can figure out a way that works during bootstrap, I don't see another way.
you can test locally whether it works by building:
bin/nim_csources_a8a5241f9475099c823cfe1a5e0ca4022ac201ff c compiler/nim
bin/nim_csources_a8a5241f9475099c823cfe1a5e0ca4022ac201ff c koch
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.
So I also can't use importutils.privateAccess
/{.use.}
?
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.
you mean {.all.}, not {.use.} ? indeed. It can be used in code that's not used during compiler bootstrap or needs when defined(nimHasHintAll)
or any recent such condsyms symbol if you can get away with custom implementation for the needed symbols during bootstrap
# Duration | ||
# | ||
|
||
const DurationZero* = Duration() ## \ |
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.
is there any style guide still recommending ## \
? if so they should be updated, it doesn't seem necessary (simpler = better)
as can be seen with:
nim doc -r main
const a1* = 10 ## \
## ok1
## ok2
const a2* = 10
## ok1
## ok2
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.
My bad, I forgot to change that (times
used this before, for some reason).
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.
separate cleanup PR welcome; better to separate non-controversial PRs from more difficult ones so that the non-controversial one gets merged fast and doesn't complicate the other one
While you're here: #17072 |
yes, but it can be done independently of this PR (either before or after) |
No, you can't and I don't see why it's necessary. Use proper layering instead. |
The problem is that for example If there's another way to do this, please tell me (sorry if I'm missing something obvious). |
this is a common problem with re-exports in similar cases, we could patch docgen to show docs for re-exported symbols (with an indication that it's a re-export); it's not critical though as nagivation in docs will still work so you can click the re-export and see its docs (even if it points to a private module). The important things to preserve are:
The other point (regarding Duration as int128) is more tricky but important. |
That would be the proper way though. But yeah, considering that then the docs are more annoying to use, can't we leave times.nim alone instead please? |
IMHO re-exports are bad style and a last resort.
That mitigates the problems of re-exporting but avoiding re-exports is still the better solution.
There are no plans to update csources to 1.6 anytime soon btw, if we need to write new compiler in a |
not sure how that would help with bootstrap issues (including for building As for docs + re-export, it's a solvable problem that only requires a targeted (docgen) patch. Besides the solvable docs problem, I'm not sure what are objective downsides of re-export (eg it doesn't give ambiguous symbol error since it's the same symbol) |
Re-exports are bad because they add access paths to a symbol: You type |
... but D, python3, swift, rust, js, typescript, etc even C++ modules and C's Error messages and docs only require targeted fixes, eg keeping the mapping in some |
Not sure if they're bad or not, but re-exports are needed to get predictable behavior with generic code - the guideline we use is that if a public symbol uses a type declared in another module, that module should be reexported - it's the only way we've managed to alleviate unpredictable and surprising behavior (https://status-im.github.io/nim-style-guide/language.import.html) - also because in order to actually use the public symbols, you need those definitions anyway - ie |
IMO a pre-requisite for a durations module is nim-lang/RFCs#399, so that we're not stuck with a bad design forever. |
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
I don't think this is currently viable. |
Refs nim-lang/RFCs#55.
This PR splits off two modules from
std/times
, which are both reexported:std/times/core
contains core types and procs used by the other modulesstd/times/durations
contains the types and procs related to durationsI used the
{.all.}
pragma andimportutils.privateAccess
to be able to access internal definitions from thecore
anddurations
modules, that are needed bytimes
, as I didn't want to create separate private modules that export everything and are then partly reexported.The CI is currently failing, partly due to my use of
std/importutils
(cc @timotheecour), I'm investigating this. A part of the reason is that operators are redefined to not include overflow checks for the JS backend (since that's apparently broken), is that really necessary (shouldn't that either be handled insystem
or not at all)?