Skip to content

Rework the representation and handling of type attributes #71208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

rjmccall
Copy link
Contributor

Introduce a proper TypeAttribute class hierarchy.

The old TypeAttributes representation wasn't too bad for a small number of simple attributes. Unfortunately, the number of attributes has grown over the years by quite a bit, which made TypeAttributes fairly bulky even at just a single SourceLoc per attribute; that's okay as a temporary thing, but TypeAttributes was being stored as a whole in AttributedTypeRepr. The bigger problem is that we do need to carry more information than just the presence and location of the attribute for some of these attributes, which is all super ad hoc and awkward. And given that we want to do some things for each attribute we see, like diagnosing unapplied attributes, the linear data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in with the new representation better. The most significant change here is the change to how we handle implicit noescape, where now we're passing the escaping attribute's presence down in the context instead of resetting the context anytime we see any attributes at all. This should be cleaner overall.

The source range changes around some of the @escaping checking is really a sort of bugfix --- the existing code was really jumping from the @ sign all the way past the autoclosure keyword in a way that I'm not sure always works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these parameter specifiers; it seems better now, at least.

Philosophically, there are some things that feel a little incomplete here, but this is a good stopping place.

@rjmccall
Copy link
Contributor Author

@swift-ci Please test

The old TypeAttributes reprsentation wasn't too bad for a small number of
simple attributes.  Unfortunately, the number of attributes has grown over
the years by quite a bit, which makes TypeAttributes fairly bulky even at
just a single SourceLoc per attribute.  The bigger problem is that we want
to carry more information than that on some of these attributes, which is
all super ad hoc and awkward.  And given that we want to do some things
for each attribute we see, like diagnosing unapplied attributes, the linear
data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in
with the new representation better.  The most significant change here is the
change to how we handle implicit noescape, where now we're passing the
escaping attribute's presence down in the context instead of resetting the
context anytime we see any attributes at all.  This should be cleaner overall.

The source range changes around some of the @escaping checking is really a
sort of bugfix --- the existing code was really jumping from the @ sign
all the way past the autoclosure keyword in a way that I'm not sure always
works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these
parameter specifiers; it seems better now, at least.
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@rjmccall rjmccall enabled auto-merge January 29, 2024 07:07
@rjmccall rjmccall merged commit 4bf5a34 into swiftlang:main Jan 29, 2024
@rjmccall rjmccall deleted the type-attributes branch January 29, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant