-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[sil] Change all single value instructions with forwarding ownership … #20497
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] Change all single value instructions with forwarding ownership … #20497
Conversation
@swift-ci smoke test |
Should be NFC. I don't think we were relying on ownership changing dynamically anywhere. |
sigh made a mistake while slicing and dicing with git. |
004da09
to
9f615e1
Compare
@swift-ci smoke test |
4 similar comments
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test |
992c921
to
b24eef6
Compare
…to have static ownership. Previously we would always calculate these instructions ownership dynamically when asked and rely on the ownership verifier to catch if we made any mistakes. Instead with this commit we move to a more static model where the ownership that these instructions can take are frozen on construction. This is a more static model that simplifies the ownership model. I also eliminated a few asserts that are enforced in other places that caused problems when parsing since we may not have a Function while Parsing (it was generally asserts if a type was trivial).
b24eef6
to
fed6145
Compare
@swift-ci smoke test |
4 similar comments
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test |
/// AssumeUnqualifiedOwnershipWhenParsing. | ||
/// | ||
/// TODO: Once we start printing [ossa] on SILFunctions to indicate ownership | ||
/// and get rid of this global option, this can go away. |
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.
Ok, it's good that this is somehow temporary. I don't like the idea of adding flags to the SILBuilder.
@@ -5234,27 +5276,45 @@ class SelectEnumInstBase | |||
/// not to need this. | |||
NullablePtr<EnumElementDecl> getSingleTrueElement() const; | |||
}; | |||
|
|||
|
|||
/// A select enum inst that produces a static OwnershipKind set upon the |
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.
I don't know what makes the Ownership kind "static" since it appears to be dynamically selected based on the operands.
@@ -4023,19 +4042,35 @@ class ConversionInst : public SingleValueInstruction { | |||
DEFINE_ABSTRACT_SINGLE_VALUE_INST_BOILERPLATE(ConversionInst) | |||
}; | |||
|
|||
/// A conversion inst that produces a static OwnershipKind set upon the |
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.
The OwnershipKind doesn't seem to be "static", since there's no way to know from the instruction type. It does seem to be constant though.
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. You are correct that is a better terminology.
if (values.empty()) | ||
return Optional<ValueOwnershipKind>(ValueOwnershipKind::Trivial); | ||
|
||
// Find the first index where we have a trivial value. |
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.
Should say "non-trivial value"
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.
return Optional<ValueOwnershipKind>(ValueOwnershipKind::Trivial); | ||
|
||
// Find the first index where we have a trivial value. | ||
auto iter = find_if(values, [](SILValue v) -> bool { |
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.
iter
should be called firstNonTrivialPos
or something like that because it's alive across multiple iterative loops.
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.
|
||
for (SILValue v : values.slice(index + 1)) { | ||
auto opKind = v.getOwnershipKind(); | ||
if (opKind.merge(ValueOwnershipKind::Trivial)) |
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.
It's confusing that this "merges" the operand's ownership with trivial. It seems like you want to make a special rule here that trivial operands can be "merged" with nontrivial as if they are "any" ownership, but don't want to express that within SILValue::merge
itself. So you should explain that in comments and just check v.getOwnershipKind() == Trivial
.
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.
This will go away when I eliminate trivial in favor of Any.
@@ -259,7 +254,7 @@ ValueOwnershipKindClassifier::visitForwardingInst(SILInstruction *I, | |||
#define FORWARDING_OWNERSHIP_INST(INST) \ | |||
ValueOwnershipKind ValueOwnershipKindClassifier::visit##INST##Inst( \ | |||
INST##Inst *I) { \ | |||
return visitForwardingInst(I); \ | |||
return I->getOwnershipKind(); \ |
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.
This is confusing because getOwnershipKind
is implemented with ValueOwnershipKindClassifier
, so it looks like circular recursion. If you're relying on method overriding, then that should be commented.
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.
I am not. getOwnershipKind is on SILValue. This is calling on a SILInstruction.
SILFunction *F; | ||
|
||
/// If the current block that we are inserting into must assume that | ||
/// the current context we are in has ownership. | ||
bool hasOwnership; |
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.
I hope this extra SILBuilder
flag is temporary. Adding extra state in the Builder will lead to more bugs in this area.
A SILBuilder
can provide its context to a new SILBuilder
instance. Presumably this flag would need to be transferred to any new SILBuilders
. Shouldn't it be in SILBuilderContext
?
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.
It is tied to the SILFunction being passed in, so I don't think it will be an issue. That being said, I think that once I get [ossa] flag in SIL then we will be able to get rid of this.
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.
So sorry for all that noise! I got stuck in a bad habit of hitting the wrong save button. Overall this looks like a fine direction.
…to have static ownership.
Previously we would always calculate these instructions ownership dynamically
when asked and rely on the ownership verifier to catch if we made any
mistakes. Instead with this commit we move to a more static model where the
ownership that these instructions can take are frozen on construction. This is a
more static model that simplifies the ownership model.