-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL: Use a TypeExpansionContext in SIL lowering to expand opaque type archetypes as part of lowering #28044
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
SIL: Use a TypeExpansionContext in SIL lowering to expand opaque type archetypes as part of lowering #28044
Conversation
@swift-ci Please test |
@swift-ci Please test source compat |
Build failed |
Build failed |
47e15b4
to
159f988
Compare
test with swiftlang/llvm-project#144 |
test with swiftlang/llvm-project#144 |
1 similar comment
test with swiftlang/llvm-project#144 |
Build failed |
Build failed |
test with swiftlang/llvm-project#144 |
05db35f
to
291b5ed
Compare
test with swiftlang/llvm-project#144 |
Build failed |
Build failed |
@swift-ci Please test source compatibility |
1 similar comment
@swift-ci Please test source compatibility |
@swift-ci Please test os x |
Build failed |
test with swiftlang/llvm-project#144 |
@swift-ci Please test source compat |
FunctionRefInst(SILDebugLocation DebugLoc, SILFunction *F); | ||
/// \param context The type expansion context of the function reference. | ||
FunctionRefInst(SILDebugLocation DebugLoc, SILFunction *F, | ||
TypeExpansionContext context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For instructions and basic block arguments, could they get their TypeExpansionContext from the containing SILFunction
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SILInstructions don't have access to their parent basic block (or SILFunction) on creation. The TypeExpansionContext is needed at creation to compute the SILType of the instruction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I see that the SILBuilder
APIs haven't changed and use the builder's current context too. Thanks!
lib/AST/Type.cpp
Outdated
|
||
bool TypeBase::hasOpaqueArchetypePropertiesOrCases() { | ||
if (hasOpaqueArchetype()) | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A type could be parameterized by an opaque archetype, but not use that type parameter in any of its fields or cases. Was this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But I admit it is confusing. I will remove this hasOpaqueArchetype check in TypeBase and move it to the users of this API.
The place in TypeLowering that uses this predicate wants to know about either. It is used to map different type expansion context type lowerings to one map entry if we know that a type does not contain any opaque archetypes and is not resilient in any resilience domain.
lib/IRGen/GenClass.h
Outdated
VarDecl *field); | ||
|
||
OwnedAddress projectPhysicalClassMemberAddress( | ||
TypeExpansionContext context, IRGenFunction &IGF, llvm::Value *base, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a SILFunction always has a particular TypeExpansionContext, then similarly, maybe IRGenFunction could as well. For IRGenSILFunction
it could use the context from the function being lowered, and for other IGFs, maybe we could add it as a constructor argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…though by IRGen time, maybe we can also always use a maximal TypeExpansionContext, since we don't have to worry about cross-module SIL inlining anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right.
I have IRGenModule::getMaximalTypeExpansionContext() which I should have used here instead.
@swift-ci Please test |
Build failed |
Build failed |
test with swiftlang/llvm-project#144 |
@swift-ci Please test source compat |
Also add hasOpaqueArchetypePropertiesOrCases() this function will be needed by SIL type lowering to determine whether types containing opaque archetype stored properties or cases should be considered as potentially address types.
…by the type expansion context
07224f2
to
f3a5d69
Compare
test with swiftlang/llvm-project#144 |
Build failed |
Build failed |
test with swiftlang/llvm-project#144 |
Build failed |
test with swiftlang/llvm-project#144 |
Back in 33f4f57 of swiftlang#28044 fame, non-`CaptureKind::Constant:` uses of `Entry.val` in `SILGenFunction::emitCaptures` were replaced with a use of the newly added lambda `getAddressValue` applied at `Entry.val`. The replacement of `Entry.value` with `getAddressValue(Entry.value)` in the case of `CaptureKind::Box` had no effect. Back then, the reason was that the condition SGM.Types .getTypeLowering( valueType, TypeExpansionContext::noOpaqueTypeArchetypesSubstitution( expansion.getResilienceExpansion())) .isAddressOnly() && !entryValue->getType().isAddress() under which something other than the input was returned would never hold: CaptureKind::Box is used for LValues and those never satisfy `!entryValue->getType().isAddress()`. Since that PR, the getAddressValue lambda has grown. There are two additional aspects to consider: (1) forceCopy, (2) isPack. (1) is not relevant because `false` was being passed for the `CaptureKind::Box` case. (2) can not currently happen because pack lvalues haven't been implemented. But even if they were implemented, the argument passed to the lambda would still need to be an address. The same all holds for the `CaptureKind::ImmutableBox` case which only differs from the `CaptureKind::Box` by a couple of lines.
As part of SIL type lowering opaque archetypes should be expanded to
their underlying types depending on the context -- the function they are
in. This means there is only ever one SIL type for an opaque archetype
AST type inside a function body: either the original opaque archetype or
an underlying type substitution but not both.
This fixes ambiguities in type substitution that would be introduced by
specializing opaque archetypes.
rdar://52706501