Allow conditional inclusion of elements in array/dictionary literals?

The core team briefly discussed this, but that discussion we had got cut short and isn't likely to be picked up for a couple of weeks (due to holidays, travel etc). We originally wanted to discuss and get back quickly to the community with some guidance, but since that isn't happening, I think it would be great to see what you all think about these issues.

Here's a short (non-normative!) summary to give a sense of the issue:

Everyone is very +1 on this change, but I (and others) are concerned about the specific patch for this feature, because it adds significant AST complexity to support this (obviously good!) user feature. Swift's design for #if handling is just broken here IMO. While this proposal is one tiny step of progress, we should really support #if in many many many more places, and this proposal/patch doesn't push us in the right direction.

I consider our current design of handling #if blocks to be a failed experiment: the current design is the result of having the parser try to parse the "#if 0" parts of code. This policy is the result of some (now obsolete) goals that I don't want to get into, but don't matter because they are obsolete. The only other reason for parsing the #if 0 code is to make warning messages better in some extremely narrow cases, but that can be done in other ways. I think that @jrose has some goals where the current behavior is useful for textual interface for swift module stability. I don't understand and therefore won't attempt to explain that use, but I suspect that there could be other ways of solving the same problems.

In any case, I think we should go back to the drawing board on the design of #if handling. I think it would be fine to make this a lexer based skipping mechanism, which would allow arbitrary unstructured code. Some other members suggest that we could/should force some amount of structure, which would require parser integration of some sort. As I mentioned before, we didn't have time to really get into it, so the core team doesn't have a recommendation here yet.

I'd love to see the community explore these issues, and design a superset of our current #if directive handling model that will address the user needs (e.g. be able to #if out attributes, arguments, other not-really-structured things) without requiring tremendous AST complexity.

-Chris

13 Likes