Skip to content

[TypeChecker] Implement distributed computed properties #59481

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 15 commits into from
Jun 18, 2022

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 16, 2022

Add support for parsing distributed var <name> : <type> { ... } declarations and
type-checking them by injecting distributed thunks during Sema.

Resolves rdar://91283164

@xedin xedin added the distributed Feature → concurrency: distributed actor label Jun 16, 2022
@xedin xedin requested a review from ktoso June 16, 2022 02:01
@ktoso
Copy link
Contributor

ktoso commented Jun 16, 2022

Okey so I made the tests pass but... We're missing the info that "this was a distributed thunk" and I'm sorry but I forgot what we agreed upon -- are we doing the new attribute to mark those? It would honestly be the simplest solution and also useful to inspect those ASTs then, and we might need it for the avoiding double-synthesis anyway, right @xedin?

In any case this will now pass, and let's follow up fixing the FIXME's in 1178f62 by introducing an attr or what other idea you had there 👍

@ktoso
Copy link
Contributor

ktoso commented Jun 16, 2022

@swift-ci please test

if (auto *FD = dyn_cast<FuncDecl>(decl)) {
thunkDecl = FD->getDistributedThunk();
} else {
thunkDecl = cast<VarDecl>(decl)->getDistributedThunk();
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe

Suggested change
thunkDecl = cast<VarDecl>(decl)->getDistributedThunk();
} else if (let var cast<VarDecl>(decl)) {
thunkDecl = var->getDistributedThunk();
} else llvm_unreachable...

? Just in case I guess...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The validity is checked by requiresDistributedThunk so I don't really see a reason to double-check here, if anything cast is going to fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks!

declRefExpr->setFunctionRefKind(choice.getFunctionRefKind());
declRefExpr->setType(thunkType);

cs.cacheType(declRefExpr);
Copy link
Contributor

Choose a reason for hiding this comment

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

oh that's new to me, why do we do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you talking about cacheType specifically? That's used to let finishApply know what the type was for the newly created node, since all the expressions involved in solving should have their types cached.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that -- I see, thanks :)

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.

Thank you, looking awesome.

The only follow up is that I forgot what we agreed to do about the thunks (too little sleep -_-) -- I'd be ok with the attribute to detect them, but do we want to do something else?

@xedin
Copy link
Contributor Author

xedin commented Jun 16, 2022

are we doing the new attribute to mark those? It would honestly be the simplest solution and also useful to inspect those ASTs then, and we might need it for the avoiding double-synthesis anyway, right @xedin?

Yes, that's is correct.

@xedin xedin force-pushed the distributed-computed-properties branch from 1178f62 to b45f39a Compare June 16, 2022 23:36
@xedin xedin force-pushed the distributed-computed-properties branch from 31ca982 to 88db8a7 Compare June 17, 2022 19:13
@xedin xedin marked this pull request as ready for review June 17, 2022 19:13
@xedin
Copy link
Contributor Author

xedin commented Jun 17, 2022

@ktoso Tests have been fixed and new attributed simplified checking some what as well, so the changes are complete now.

@xedin
Copy link
Contributor Author

xedin commented Jun 17, 2022

@swift-ci please test

@xedin xedin force-pushed the distributed-computed-properties branch from 88db8a7 to 3fce990 Compare June 17, 2022 19:15
@xedin xedin force-pushed the distributed-computed-properties branch 2 times, most recently from 39bc076 to df10d4c Compare June 17, 2022 19:17
@xedin
Copy link
Contributor Author

xedin commented Jun 17, 2022

@swift-ci please test

xedin and others added 8 commits June 17, 2022 12:35
Replace distributed member references with distributed thunks
when access happens outside of distributed actor context. This
significantly simplifies distributed compute properties implementation.
…utedThunk`

Since the thunk is applied to expression during solution application,
the use of this flag has shifted towards stating the fact.
…eter/capture base

If distributed memeber is referenced on a base that represents
a result of some expression which is not a variable, parameter,
or a capture it should always be dispatched via a thunk.
…y check

All the heavy lifting of checking whether reference throws and
requires dispatch through a thunk is done during type-checking,
 so all `checkDistributedAccess` needs to do is determine whether
access is distributed or not.
The attribute comes handy during solution application to
determine whether the call is using a distributed thunk.
@xedin xedin force-pushed the distributed-computed-properties branch from df10d4c to fa2e64c Compare June 17, 2022 19:36
@xedin
Copy link
Contributor Author

xedin commented Jun 17, 2022

@swift-ci please test

@ktoso
Copy link
Contributor

ktoso commented Jun 17, 2022

Awesomeness, thank you Pavel :-)

// let's mark the call as implicitly throwing/async.
if (isa<SelfApplyExpr>(apply->getFn())) {
auto *FD = dyn_cast<FuncDecl>(callee.getDecl());
if (FD && FD->isDistributedThunk()) {
apply->setImplicitlyThrows(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very nice and simple now, came togeher nicely :)

@ktoso ktoso merged commit 8125a85 into swiftlang:main Jun 18, 2022
@ktoso
Copy link
Contributor

ktoso commented Jun 18, 2022

I'll pick it over to 5.7

@@ -7781,6 +7781,10 @@ bool AbstractFunctionDecl::isSendable() const {
return getAttrs().hasAttribute<SendableAttr>();
}

bool AbstractFunctionDecl::isNonisolated() const {
return getAttrs().hasAttribute<NonisolatedAttr>();
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a semantic definition of "nonisolated" (one should check getActorIsolation instead), so I'd prefer that we not have this function. Fortunately, it's unused, so we should remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see, cool will remove 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

ktoso added a commit to ktoso/swift that referenced this pull request Jun 24, 2022
…puted-properties"

This reverts commit 8125a85, reversing
changes made to 728971c.
ktoso added a commit to ktoso/swift that referenced this pull request Jun 24, 2022
…puted-properties"

This reverts commit 8125a85, reversing
changes made to 728971c.
DougGregor added a commit that referenced this pull request Jun 25, 2022
[Distributed] Revert "#59481 distributed-computed-properties"
DougGregor added a commit that referenced this pull request Jun 25, 2022
🍒[5.7][Distributed] Revert "#59481 distributed-computed-properties"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed Feature → concurrency: distributed actor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants