-
Notifications
You must be signed in to change notification settings - Fork 23
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
Better effect tracking for inner routines #435
Comments
Araq
changed the title
Better effect tracking for inner rountines
Better effect tracking for inner routines
Nov 9, 2021
How much more complex?, like in a scale of 0 ~ 10. |
Hard to say, 6 with the current compiler? |
Another example of the same sort of problem: {.experimental: "strictEffects".}
type
Foo = object
bar: seq[Foo]
proc `==`(a, b: Foo): bool {.noSideEffect.} =
# ^ explicit annotation required
a.bar == b.bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refs: status-im/nim-chronos#226
The problem: Currently code like this does not compile:
The compiler produces:
When
inner
is analysed for its effects the effects ofouter
arenot yet known. The specification/manual currently does not really say
what should happen:
outer
is not forward declared as it doesn't haveto be, but the intention of the spec clearly was to cover this case via
the rule (3):
So, in order to make the example compile,
outer
's effects need to be annotatedexplicitly:
While that might not be that bad, the problem here is that code like in the
initial example used to work for years and only the recent bugfixes in the
.experimental: "strictEffects"
mode make it not compile. It's a breakingchange which could be handled more smoothly if we make the compiler smarter.
Proposal: Infer the effects of inner routines in combination with outer routines
The effect inference algorithm could work on
outer
andinner
in lock-step:When
inner
callsouter
it is assumed thatouter
has no effects and if thatassumption does not turn out to be true, calls of
outer
need to be "patched".Or, to phrase it differently: The interference algorithm infers the effects of
outer
by also following inner routines directly, treating them much like templates.
Benefits
.experimental: "strictEffects"
(and this modeis about to become the default as it fixes a number of loopholes in Nim's effect
system.)
Downsides
The text was updated successfully, but these errors were encountered: