@xwu I think you are right that these are not really the same kind of thing, and it's a question of if it is convenient to use the same mechanism. It is possible this should be two separate proposals, one like default @MainActor and one like using @available (strawman). It's also possible this is not so surprising in practice, or that we could alleviate the concerns about the exceptions being surprising:
One option could be to emit warnings in the cases where we don't do the naive thing, within a group, which can be silenced with an explicit annotation, or with a file level diagnose attribute:
default @MainActor
default @diagnose(IsolationAssumption, as: ignored)
or (these diagnostics are not up to snuff but they convey the gist. could also be a remark?)
default @MainActor // note: file-level default '@MainActor' isolation specified here
// note: silence warnings about 'IsolationAssumption' with a default here
// ... (example from 466)
struct S: Codable {
var a: Int
// warning: 'CodingKeys' was inferred to be 'nonisolated' in spite of file-level default due to 'nonisolated' requirements of 'CodingKey' [#IsolationAssumption]
enum CodingKeys: CodingKey { // note: silence this warning by writing 'nonisolated' here
case a
}
}
And we could emit these diagnostics any time we have a file-level default, but choose to use another default (or maybe just when it seems needed? I don't find type alias surprising), along with a tailored reason based on the logic that overruled the file-level default.
Aside: I think we would want to be very careful about offering default @diagnose(Group, as: ignored), as a fix-it for warnings... Lot of risk of being blindly accepting and swallowing issues.
I don't think it looks as nice, and to me pound directives imply "hacky" and evoke c preprocessor (and have motivations in c that swift doesn't have) but that's an aesthetic judgement and I think it certainly could be a right answer. Note that we do consider newlines, and it's not actually ambiguous in practice afaik.
I agree! However, I disagree that SE-0522 is really addressing the same question, I read that alternative considered as addressing a different question; why is SE-522 not region based pragmas, to which the answer is favoring attaching to declarations, and needing to think about the end of a region. I think the arguments made are compelling in the context of SE-522 (I would oppose a "to the end of the file if unspecified" behavior for ignoring diagnostics via pragma, it seems footgun prone). You could make the argument that SE-522 should have pursued that design to avoid the need for this proposal, I guess.
The design of SE-0522 is such that the normal way of interacting with the feature is already naturally declaration scoped. This pitch of SE-0478 is about extending attributes which today can only be attached to declarations so they can be specified for a whole file, sort of like a pragma. I don't particularly mind syntax like #pragma default @MainActor or #compiler-directive default @diagnose(...) although I would strongly advocate for it being restricted to the top of the file (which makes it hardly a typical pragma...) for the same reasons I advocate that in this proposal already. In that case, it's just an alternative syntax that aims to be more conspicuous, which is fine by me although I suspect rather verbose for many.
That being said, an argument against #pragma; c family compilers need this to interoperate between different compilers and versions, with support for different pragmas (afaik unrecognized #pragma is largely ignored). A compiler can add whatever they need (optimization hints, diagnostic suppression) within a pragma, and still make an effort at portable c. Swift does not have this constraint; there are not parallel implementations of the language, so we are able to add new, privileged syntax without worrying about alternative implementations that don't wish to adopt it or adopt it with the same syntax. I don't think that's really an argument against using pound in the syntax, but I do lean against #pragma ... for that reason.