Skip to content

[TypeConverter] Track address lowering. #62343

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

Conversation

nate-chandler
Copy link
Contributor

When opaque values are enabled, TypeConverter associates to an address-only type an OpaqueValueTypeLowering. That lowering stores a single lowered SIL type, and its value category is "object". So long as the module has not yet been address-lowered, that type has the appropriate value category. After the module has been address-lowered, however, that type has the wrong value category: the type is address-only, and in an address-lowered module, its lowered type's value category must be "address".

Code that obtains a lowered type expects the value category to reflect the state of the module. So somewhere, it's necessary to fixup that single lowered type's value category.

One option would be to update all code that uses lowered types. That would require many changes across the codebase and all new code that used lowered types would need to account for this.

Another option would be to update some popular conveniences that call through to TypeConverter, for example those on SILFunction, and ensure that all code used those conveniences. Even if this were done completely, it would be easy enough for new code to be added which didn't use the conveniences.

A third option would be to update TypeLowering::getLoweredType to take in the context necessary to determine whether the stored SILType should be fixed up. That would require each callsite to be changed and potentially to carry around more context than it already had in order to be able to pass it along.

A fourth option would be to make TypeConverter aware of the address-loweredness, and to update its state at the end of AddressLowering.

Updating TypeConverter's state would entail updating all cached OpaqueValueTypeLowering instances. Additionally, when TypeConverter produces new OpaqueValueTypeLowerings, they would need to have the "address" value category from creation.

Of all the options, the last is least invasive and least error-prone, so it is taken here.

The new flag allows TypeLowering to be forced to behave as though
-enable-sil-opaque-values was passed.  That's needed in order to
reasonably write tests on SIL which _notionally_ started out in opaque
values mode and have since been address lowered.
When opaque values are enabled, TypeConverter associates to an
address-only type an OpaqueValueTypeLowering.  That lowering stores a
single lowered SIL type, and its value category is "object".  So long as
the module has not yet been address-lowered, that type has the
appropriate value category.  After the module has been address-lowered,
however, that type has the wrong value category: the type is
address-only, and in an address-lowered module, its lowered type's value
category must be "address".

Code that obtains a lowered type expects the value category to reflect
the state of the module.  So somewhere, it's necessary to fixup that
single lowered type's value category.

One option would be to update all code that uses lowered types.  That
would require many changes across the codebase and all new code that
used lowered types would need to account for this.

Another option would be to update some popular conveniences that call
through to TypeConverter, for example those on SILFunction, and ensure
that all code used those conveniences.  Even if this were done
completely, it would be easy enough for new code to be added which
didn't use the conveniences.

A third option would be to update TypeLowering::getLoweredType to take
in the context necessary to determine whether the stored SILType should
be fixed up.  That would require each callsite to be changed and
potentially to carry around more context than it already had in order to
be able to pass it along.

A fourth option would be to make TypeConverter aware of the
address-loweredness, and to update its state at the end of
AddressLowering.

Updating TypeConverter's state would entail updating all cached
OpaqueValueTypeLowering instances at the end of the AddressLowering
pass.  Additionally, when TypeConverter produces new
OpaqueValueTypeLowerings, they would need to have the "address" value
category from creation.

Of all the options, the last is least invasive and least error-prone, so
it is taken here.
@nate-chandler nate-chandler force-pushed the opaque-values/1/20221130 branch from 6fe4e04 to e9e93c1 Compare December 1, 2022 22:18
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test macOS platform

@nate-chandler nate-chandler marked this pull request as ready for review December 2, 2022 16:18
@nate-chandler nate-chandler merged commit cfbd52d into swiftlang:main Dec 5, 2022
@nate-chandler nate-chandler deleted the opaque-values/1/20221130 branch December 5, 2022 17:22
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

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.

2 participants