Skip to content
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

experimental switch for generic compileTime, remove typeof behavior #24230

Closed
wants to merge 1 commit into from

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Oct 3, 2024

fixes #24228, refs #22022

The typeof behavior from #22022 causes issues like #24228, but it's required for the proc declval in the package stew to keep working as expected with the rest of #22022. To accomodate this, the generic compileTime proc behavior in #22022 is now opt-in with the switch --experimental:genericProcCompileTime, so that packages can continue to work until we have a proper design for compileTime.

Another option instead of using an experimental switch would be to add a pragma like constantFold that needs to be added to individual generic procs to enable compileTime folding for them, maybe for all procs eventually (it would break code currently if required for all procs). But this is a language addition.

Will add to changelog if accepted. Mutually exclusive with #24229.

@metagn metagn changed the title experimental switch for generic compileTime, remove typeof behavior experimental switch for generic compileTime, remove typeof behavior [backport:2.0] Oct 5, 2024
@metagn metagn changed the title experimental switch for generic compileTime, remove typeof behavior [backport:2.0] experimental switch for generic compileTime, remove typeof behavior Oct 5, 2024
Araq pushed a commit that referenced this pull request Oct 6, 2024
fixes #24228, refs #22022

As described in
#24228 (comment),
instantiating generic routines inside `typeof` causes all code inside to
be treated as being in a typeof context, and thus preventing compile
time proc folding, causing issues when code is generated for the
instantiated routine. Now, instantiated generic procs are treated as
never being inside a `typeof` context.

This is probably an arbitrary special case and more issues with the
`typeof` behavior from #22022 are likely. Ideally this behavior would be
removed but it's necessary to accomodate the current [proc `declval` in
the package `stew`](status-im/nim-stew#190), at
least without changes to `compileTime` that would either break other
code (making it not eagerly fold by default) or still require a change
in stew (adding an option to disable the eager folding).

Alternatively we could also make the eager folding opt-in only for
generic compileTime procs so that #22022 breaks nothing whatsoever, but
a universal solution would be better. Edit: Done in #24230 via
experimental switch
@metagn
Copy link
Collaborator Author

metagn commented Oct 8, 2024

#24229 was merged, this PR is out of date, but this might come up again later

@metagn metagn closed this Oct 8, 2024
@arnetheduck
Copy link
Contributor

fwiw, I think this PR was better - the design of compileTime as "force compile time eager folding" is quite strange and not really supported by practical use nor documentation of the feature

@metagn
Copy link
Collaborator Author

metagn commented Oct 8, 2024

We can probably still address that, it's just a matter of finding a good replacement for it. This PR might have made that more complicated if anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants