Incremental development for compound variable names

I've been working on a prototype implementation for compound variable names on-and-off for the past few weeks, and I'm starting to think about what the best way to land this change would be. It's going to be a pretty significant change, since pretty much every part of the compiler has to be reworked to support VarDecl::getName() returning a DeclName instead of an Identifier.

I wanted to solicit feedback from maintainers about what parts of this feature (if any) would be appropriate to land on master before the proposal has actually gone through review.

For instance, much of the parsing logic could be merged in, which would allow the compiler to emit a more-helpful "variable declarations may not have compound names" diagnostic rather than the nonsense "consecutive declarations on a line must be separated by ';'" error that is emitted today. This seems potentially useful regardless of whether compound variable names eventually get added or not.

To take it further, though, much larger portions of the feature could be landed if compound variable names are something we definitely want to have in some form in the future. E.g., we could change VarDecl::getName() to return a DeclName without actually enabling compound variable names in order to front load the work of migrating all the portions of the compiler affected by that API difference.

In the extreme, of course, the entire feature could be merged behind an experimental flag. I'd appreciate guidance from anyone (especially those with with authority on this decision) about what seems appropriate so that I can better organize my development effort!

6 Likes

For this particular part, if it is possible to factor it out, I would merge that as a separate patch focused on improving the diagnostic.

More generally, if there is some refactoring that would be independently useful of the new proposal itself, it would good to factor it out and merge it sooner rather than later.

2 Likes

I think this is a good development direction. You can generalize VarDecl::getName() to return a DeclName, which will require a bunch of refactoring throughout the compiler but will likely not change its behavior (except, e.g., in diagnostics). Then, your implementation of compound variable names should be much smaller and more focused on the actual semantics of compound variable names; hopefully, small enough that there's no need to do the experimental feature flag at all.

Doug

[EDIT: Added a bit about an experimental flag]

2 Likes

Great, thank you for the validation on that front, Doug. I'll hopefully be able to put up a PR for some of the preliminary work in the next couple weeks!

3 Likes

Ended up having less free time than I wanted so it took a bit longer than anticipated, but I've put up a PR for some of the preliminary refactoring here.

1 Like
Terms of Service

Privacy Policy

Cookie Policy