[Accepted] SE-0315: Placeholder types

Hi everyone. The review period for SE-0315: Placeholder types ran from June 21 through July 6, 2021. The core team has accepted this proposal. Support for the added functionality was unanimous; there was some discussion about whether the proposal might be better titled "type placeholders" or "inferred types", but that would not affect the behavior of the feature within the language. Thanks to everyone who participated in the review!

21 Likes

The name of the feature affects the implementation PR (I'm mostly thinking about diagnostics). Is there a path forward for resolving this discussion so the implementation can be updated (in subsequent PRs)?

7 Likes

The name I'm planning to use in "The Swift Programming Language" is type placeholder. Usually I'd solicit feedback on naming during tech review of the new material, discussing it now lets use the same name in diagnostics and documentation, which is even better.

Calling it a placeholder type or inferred type implies that _ is a type. It's not a type, it's something you write as part of a type, asking the type inference engine to please fill in this part of the type at compile time.

There was some discussion on the review thread about how the Generics chapter in the guide also uses the word "placeholder" when discussing the arguments to a generic type. I don't think that's likely to cause confusion. In context, the concept is initially introduced by describing the T as a placeholder, but the next section gives it an actual name, type parameter.

25 Likes

Thanks @Alex_Martini, definitely agree that we should align diagnostics with the language in TSPL so that context is super helpful. With regards to the proposal text, "type placeholder" and "placeholder type" are probably similar enough to not hurt searchability, but I still think we should try to align the terminology there as well.

I'll put up a PR to update both of these soon!

6 Likes

And the term can scale, like we could call the underscore here:

// Fixed-size array prototype syntax; not real
let x: [_ ; Int] = [1, 2, 3, 4, 5, 6]

an extent placeholder.

I don’t understand what this means.

2 Likes

It's a hypothetical syntax for fixed sized arrays where the dimensions come before the semicolon.

He's saying that we could use a placeholder for the size when it can be inferred.

// This
let x: [6; Int] = [1, 2, 3, 4, 5, 6]
// is the same as
let x: [_; Int] = [1, 2, 3, 4, 5, 6]
1 Like

I wasn't talking about the actual concept here, but the name. We could use "XXX placeholder" for concepts similar to type placeholders.

For the concept itself, the nice part is that if we change the number of terms in the literal, we wouldn't have to go back to update the extent size.

1 Like
Terms of Service

Privacy Policy

Cookie Policy