Skip to content

[region-isolation] Do not look through begin_borrow or move_value if they are marked as a var_decl. #72959

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 18 commits into from
Apr 18, 2024

Conversation

gottesmm
Copy link
Contributor

Just chopping off parts of a larger piece of work while I work at the same time on another piece of work.


The reason why we do this is that we want to treat this as a separate value from
their operand since they are the result of defining a new value.

This has a few nice side-effects, one of which is that if a let results in just
a begin_borrow [var_decl], we emit names for it.

I also did a little work around helping variable name utils to lookup names from
applies that are fed into a {move_value,begin_borrow} [var_decl] which then has
the debug_value we are searching for.

@gottesmm gottesmm requested a review from ktoso as a code owner April 10, 2024 20:11
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm gottesmm enabled auto-merge April 10, 2024 20:11
@gottesmm gottesmm disabled auto-merge April 10, 2024 21:04
@gottesmm
Copy link
Contributor Author

This is actually going to cause a merge conflict with a different PR I have going. I am going to do some more work here and rebase on top of that. That means I am going to put my SILIsolationInfo refactoring work here as well.

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

isolatedValue(isolatedValue), actorInstance(actorInstance) {
assert((!actorInstance ||
(actorIsolation.getKind() == ActorIsolation::ActorInstance &&
actorInstance->getType().isActor())) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
actorInstance->getType().isActor())) &&
actorInstance->getType().isAnyActor())) &&

otherwise would crash on a distributed actor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually calls:

bool TypeBase::isActorType() {                                                                                            
  if (auto actor = getAnyActor())                                                                                         
    return actor->isActor();                                                                                              
  return false;                                                                                                           
} 

which does any actor.

Copy link
Contributor

@ktoso ktoso Apr 12, 2024

Choose a reason for hiding this comment

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

Right, which is still wrong isn't it? It does actor->isActor() there but should do actor->isAnyActor().
The isActor checks for inheriting from Actor but we need either Actor or DistributedActor or this will fail when isolated to a distributed actor right?

@ktoso
Copy link
Contributor

ktoso commented Apr 11, 2024

Not much I can say about the analysis bits but looked good :)

gottesmm added 15 commits April 11, 2024 15:41
… isolation info.

I am finding that I am calling that a bunch so this just makes it a little more
convenient.
…ment.

Having two artificial typedefs for the same wrapped value is just confusing.
Better to just have one and make the code simpler to understand.
…they are marked as a var_decl.

The reason why we do this is that we want to treat this as a separate value from
their operand since they are the result of defining a new value.

This has a few nice side-effects, one of which is that if a let results in just
a begin_borrow [var_decl], we emit names for it.

I also did a little work around helping variable name utils to lookup names from
applies that are fed into a {move_value,begin_borrow} [var_decl] which then has
the debug_value we are searching for.
…ment_addr and global_addr onto SILIsolationInfo and call that instead.
…efInst/ClassMethodInst into SILIsolationInfo::get instead of handrolling in RegionAnalysis.
…ationInfo::get instead of computing actor isolation by hand.

Just more recoring on top of SILIsolationInfo::get.
This ensures that when we process, we consider load/load_borrow's result to be
equivalent to its operand. This ensures that a load/load_borrow cannot act as a
use of its operand preventing spurious diagnostics.
…ce that a value is isolated to if we are dealing with an actor instance.

This will let us distinguish in between values derived from two actor instances
of the same type and to emit better errors.
…o VariableNameInferrer.

I have been using these in TransferNonSendable and they are useful in terms of
reducing the amount of code that one has to type to use this API. I am going to
need to use it in SILIsolationInfo, so it makes sense to move it into
SILOptimizer/Utils.

NFCI.
…iagnostics, if we have a SIL actor instance, print -isolated instead of actor-isolated.

rdar://122501400
…ated to a #isolated as being globally isolated to that.

Instead, we need to consider the isolation at the apply site.

rdar://126285681
rdar://125078448
The thinko was that rather than use the actual isolated parameter of a partial apply as the isolated parameter, I instead just used the last operand... :doh:. This fixes:

rdar://126297097
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm gottesmm enabled auto-merge April 11, 2024 23:02
@gottesmm
Copy link
Contributor Author

Lets try this again

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

1 similar comment
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

ktoso
ktoso previously requested changes Apr 12, 2024
Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Sorry but I still think this assertion will wrongly crash for distributed actor isolated code -- commented inline

@gottesmm gottesmm dismissed ktoso’s stale review April 17, 2024 20:09

I went through and converted all usages in TransferNonSendable to use isAnyActor instead of isActor as requested.

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

I also included some tests around distributed actors as well to validate that we do not crash.

@gottesmm gottesmm merged commit bfa910d into swiftlang:main Apr 18, 2024
@gottesmm gottesmm deleted the tns-upstream-2 branch April 18, 2024 05:39
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