_modify in variable

I'm parsing the .swiftinterface file for interop from/to another language/compiler. What does _modify do different than set ?

In the same vain, "yield" which also doesn't seem to be part of the the spec and is used inside these modify clauses.

Have a look at this excellent video by @Ben_Cohen:

It is part of what is called "Generalized accessors" I believe. If you don't have 30 mins to spare, scrub to 21:19.

1 Like

Any idea where this or the yield keyword is documented?

1 Like

But this document is outdated and might not define the exact behavior in the current compiler. Also don't use these keywords for release builds as these are not yet officially public, hence the underscore on modify and read.

I don't want to, but the swiftinterface file uses them so my choices are limited (so effectively changing this would be abi breakage?)

Sure, then you have to teach your parser to respect both _read and read and other keywords so you can avoid breakage in the future.

I can't answer the question related to ABI here. cc @John_McCall


I find it curious that these kind of changes are apparently not all going thru the formal Proposal process (with an SE-XXXX id and everything), and that, when done, don't end up with official documentation somewhere in a proper spec? (not the _modify per se, if thats still internal, but even yield itself ic cannot find covered by any SE or in any official docs... which seems weird to me.

These things currently are simply stdlib implementation detail which will have it's own proposal in the future and potentially become available for everyone to use. The stdlib can implement things however it wants.

1 Like

Ah, so even yield is not an official feature yet?

Is there a decent place to find all currently implemented "unofficial/internal" features that could affect .swiftinterfaces?


I don't know really, I'm just a regular swift community member, not a compiler developer. I hope someone with more compiler insights will step in and answer that question. ;)

fingers crossed :crossed_fingers:t3:.

and thanks for your replies anyways/even more so.

1 Like

Module interface lead here. swiftinterface files are not meant for interop with other languages, since they still have to be type-checked to do most useful things with them. We haven't tried to make them parseable by SwiftSyntax, either, but that might be a reasonable middle ground.

A module interface necessarily needs to describe all parts of a module's public API (what's accessible to clients from source) and ABI (what's going to be used at run time). That does include some of the implementation details used to implement the standard library, all the way up to things that will probably never get official proposals like @_semantics or the "functions" in Builtin. _modify, on the other hand, is something the core team has committed to by now (mainly because it had some enormous performance benefits in the standard library), and so it's part of the Swift 5 ABI. As Adrian said, I do expect it to get a proper proposal in the future.

In general, anything that starts with an underscore is either "experimental" or "implementation detail with sharp edges" or both. I kind of wish this was something we could actually tell people, or that we used a rarer character, but oh well.

1 Like

What is, then?

:-/ SourceKit, really (or SwiftSyntax / libSyntax if you just need lexical information). Swift is a complicated enough language that you're expected to use the compiler to understand it.

1 Like

Hi. I am going to try to interop with swift directly though .swiftinterface, as a sourcekit dependency for us isn't an option at this moment with our tools, but thank you for the information above, it will be quite useful to solve it.

1 Like