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

Throw a compiler error when a macro parameter is unquoted more than once in a quasi #234

Open
masak opened this issue Jun 9, 2017 · 2 comments

Comments

@masak
Copy link
Owner

masak commented Jun 9, 2017

We're talking about this situation, as seen in #214:

quasi {
    {{{it}}} = {{{it}}} * 2;
}

The same comment in that issue also coins the Single Evaluation Rule: if a quasi unquotes the same AST fragment more than once, it's more likely than not to be a thinko.

(Why? Because in the end, it seems to be a blind spot for macro authors — at least for me — that it above might involve a side effect, and by duplicating it we're also duplicating the side effect.)

We can trivially detect this; at least we can trivially detect when the same variable is unquoted more than once in a quasi — which is probably good enough. If we can then make the error message nice and friendly, this ought to be a win. Maybe the error message should mention the is lazy @succinct trait, which allows a developer to keep not caring about duplicated side effects.

@masak
Copy link
Owner Author

masak commented Jul 14, 2017

There also needs to be a way to suppress the error message — simply because language designers are not omniscient, and might overlook a genuine need by a macro author.

At worst, I could imagine suppressing the error message through a macro trait. Maybe there's some nicer way.

@masak
Copy link
Owner Author

masak commented Mar 14, 2018

There is a nicer way. We can mark parameters and local variables with is thunky or @Thunky if we want to suppress the error.

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

No branches or pull requests

1 participant