What are the compiler technologies that support the App Intents framework?

Hello,

While looking at WWDC 2022 - Dive into App Intents, my attention was caught by two sentences pronounced by the speaker Michael Gorbach during the presentation:

For example, declaring a struct that conforms to the AppShortcutsProvider protocol is enough for iOS to vend app shortcuts to the end user:

import AppIntents

struct MyShortcuts: AppShortcutsProvider {
    static var appShortcuts: [AppShortcut] {
        AppShortcut(...)
    }
}

My app does not run any line of the above code. And yet the mere presence of this type in my target has consequences. Surely some technique(s) I'm totally unaware of is at play here.

The transcript mentions "literals", "build time" and "build process", although a close inspection of the build logs did not make anything pop up to my eyes (maybe I did not look close enough).

Has anyone some insight about the techniques that are at play here? The requirement for "literals" make me think of a pre-release of SE-0359. The "during your build process" snippet may just refer to some Xcode proprietary technology, perhaps akin to package plugins. Yet I can't quite figure out what "information received from the Swift compiler as it runs on your code" refers to.

4 Likes

When I saw this, I just assumed that this was a build tool package plugin at play, which would somehow scan my source code and generate the entitlements needed. But I haven't looked into any of that, so this is pure speculation.

This is indeed build time extraction. There is an "Extract app intents metadata" step in the build log. The way this works is that the Swift compiler outputs some information that it generates while compiling your code, which describes what types are available in your code, as well as type-level and some value-level information from your App Intents method implementations. This information is parsed by another tool which generates a metadata.appintents directory in your built product which contains files that describe your intents, and other information we need to know without running your app, such as information needed to render your intents in Shortcuts.

7 Likes

The interaction with SE-0359 is basically that Swift uses an underscored version of that feature to force the operand to be a literal so that the static extraction of these values by that secondary tool cannot fail.

2 Likes

Thank you Michael :-) And thanks for the name of the "Extract app intents metadata" step :+1:

Out of curiosity, what files is the tooling in the "Extract app intents metadata" step looking at for this information?