Skip to content

TypeLowering: add Type.hasCustomDeinit #81784

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

atrick
Copy link
Contributor

@atrick atrick commented May 27, 2025

  • [NFC] TypeLowering: add CustomDeinit.
    Teach SIL type lowering to recursively track custom vs. default deinit status.

    Determine whether each type recursively only has default deinitialization. This
    includes any recursive deinitializers that may be invoked by releasing a
    reference held by this type.

    If a type only has default deinitialization, then the deinitializer cannot
    have any semantically-visible side effects. It cannot write to any memory

  • SwiftCompilerSources bridge Type.hasCustomDeinit.

@atrick atrick requested review from eeckstein and jckarter as code owners May 27, 2025 16:37
@atrick atrick force-pushed the typelower-customdeinit branch from d89f074 to 22ac782 Compare May 27, 2025 16:46
@atrick atrick force-pushed the typelower-customdeinit branch from 4f4b0b2 to c7b7811 Compare June 5, 2025 07:35
@atrick
Copy link
Contributor Author

atrick commented Jun 5, 2025

@slavapestov Take a look at classifyTypeParameters.
012116e#diff-f225973f74fb5d01a20a43ffa69ab2ee1652880a40733d654d4c20bba3612879R2779

We need this for certain certain types (Array, Dictionary) that may only have a custom deinit when their generic parameters may have a custome deinit (hasConditionalDefaultDeinit() == true). So type lowering an Array<Element> requires checking the CustomDeinit flag on the Element type parameter.

I'm using an opaque abstraction pattern, guessing that it can't affect recursive type properties. But maybe this code should know how to extract the originalElementType from AbstractionPattern origType that corresponds to each generic parameter in the BoundGenericType, before calling getTypeLowering(origElementType, paramType,...)?

Here's the code:

    RecursiveProperties classifyTypeParameters(CanType type, TypeConverter &tc,
                                               TypeExpansionContext expansion) {
      RecursiveProperties props;
      if (auto bgt = dyn_cast<BoundGenericType>(type)) {
        for (auto paramType : bgt->getGenericArgs()) {
          // Use an opaque abstraction pattern for the element type because
          // abstraction does not apply to the generic parameter itself.
          AbstractionPattern origElementType = AbstractionPattern::getOpaque();
          auto &lowering = tc.getTypeLowering(origElementType, paramType,
                                              expansion);
          props.addSubobject(lowering.getRecursiveProperties());
        }
      }
      return props;
    }

@atrick atrick force-pushed the typelower-customdeinit branch from c7b7811 to 7d45a5a Compare June 5, 2025 23:31
@atrick atrick changed the title Improve LifetimeDependenceDefUseWalker: consult Type.hasCustomDeinit TypeLowering: add Type.hasCustomDeinit Jun 6, 2025
@atrick atrick force-pushed the typelower-customdeinit branch from 7d45a5a to 2b38ea0 Compare June 6, 2025 22:20
@atrick
Copy link
Contributor Author

atrick commented Jun 6, 2025

@swift-ci test

atrick added 2 commits June 6, 2025 17:46
Teach SIL type lowering to recursively track custom vs. default deinit status.

Determine whether each type recursively only has default deinitialization. This
includes any recursive deinitializers that may be invoked by releasing a
reference held by this type.

If a type only has default deinitialization, then the deinitializer cannot
have any semantically-visible side effects. It cannot write to any memory
@atrick atrick force-pushed the typelower-customdeinit branch from 2b38ea0 to 35c49c8 Compare June 7, 2025 00:46
@atrick
Copy link
Contributor Author

atrick commented Jun 7, 2025

@swift-ci test

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