Skip to content

[NCGenerics] Even more fixes for building the stdlib (Part 3) #70548

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
Jan 11, 2024

Conversation

kavon
Copy link
Member

@kavon kavon commented Dec 19, 2023

fixes rdar://120462547&120512544

Just another assorted set of changes as I fix things while getting the stdlib building with NoncopyableGenerics.

@kavon kavon marked this pull request as draft December 19, 2023 23:11
@kavon
Copy link
Member Author

kavon commented Dec 19, 2023

@swift-ci smoke test

@kavon kavon force-pushed the ncgenerics-stdlib-building-v3 branch from 2184ed2 to da14e36 Compare December 20, 2023 00:41
@kavon
Copy link
Member Author

kavon commented Dec 20, 2023

@swift-ci please smoke test Linux

1 similar comment
@kavon
Copy link
Member Author

kavon commented Dec 21, 2023

@swift-ci please smoke test Linux

@kavon
Copy link
Member Author

kavon commented Dec 23, 2023

preset=buildbot_linux_ncg
@swift-ci please test linux

};
};

unsigned RecursionTracker = 0;
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 not thread safe, for when sourcekit spawns multiple ASTContexts in a single process, etc. The real fix for catching runaway recursion is to record this in the IFS and make the whole thing iterative instead of recursive, but we're not there yet. Let's just remove this part for now

@kavon kavon force-pushed the ncgenerics-stdlib-building-v3 branch 2 times, most recently from 8c7fae0 to e853eb1 Compare January 5, 2024 05:29
@kavon
Copy link
Member Author

kavon commented Jan 5, 2024

@swift-ci please test

@kavon kavon marked this pull request as ready for review January 5, 2024 05:42
@kavon kavon requested review from hborla, a team, xedin and tshortli as code owners January 5, 2024 05:42
@@ -1472,6 +1472,10 @@ static void reconstituteInverses(GenericSignature genericSig,
for (auto tp : typeParams) {
assert(tp);

// Any generic parameter requiring a class could not have an inverse.
if (genericSig->requiresClass(tp))
Copy link
Contributor

Choose a reason for hiding this comment

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

does <T where T: AnyObject, T: Copyable> minimize as <T where T: AnyObject>? It should via a concrete conformance but I believe that needs to be implemented in the requirement machine itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe instead of doing sig->requiresProtocol(paramTy, Copyable) you can map paramTy into the signature's environment and do a global lookup with the archetype to Copyable? Then you won't need this special case.

@xedin xedin removed their request for review January 8, 2024 02:17
@kavon kavon force-pushed the ncgenerics-stdlib-building-v3 branch from e853eb1 to 3c51681 Compare January 9, 2024 09:51
@kavon kavon requested a review from AnthonyLatsis as a code owner January 9, 2024 09:51
@kavon
Copy link
Member Author

kavon commented Jan 9, 2024

@swift-ci smoke test

@kavon kavon force-pushed the ncgenerics-stdlib-building-v3 branch from 3c51681 to f445ee2 Compare January 9, 2024 22:12
@kavon kavon requested a review from ktoso as a code owner January 9, 2024 22:12
@kavon
Copy link
Member Author

kavon commented Jan 10, 2024

@swift-ci please test

@kavon kavon force-pushed the ncgenerics-stdlib-building-v3 branch from f445ee2 to 9bb45e8 Compare January 11, 2024 02:10
@kavon
Copy link
Member Author

kavon commented Jan 11, 2024

@swift-ci please smoke test

kavon added 3 commits January 10, 2024 19:37
When building the stdlib with noncopyable generics enabled,
requirements for Copyable and Escapable  end up being inferred on the
protocols Copyable and Escapable, themselves. So we need to opt-out
Copyable from requiring Escapable, and vice versa.
kavon added 15 commits January 10, 2024 19:37
Workaround for rdar://119950540 when dealing with invertible protocols.

This should be sound because "its an invariant that subst() on a
conformance returns the same thing as a global lookup with subst() of
the conforming type, assuming you don't have overlapping conformances."
The "no implicit copy" parameters such as a `consuming` or `borrowing`
parameter of an otherwise Copyable type was not being handled correctly
by `conformsToInvertible`. We don't have conformances for SIL types in
the AST, so they're supposed to be handled earlier.

fixes rdar://120462547
This is a temporary measure until I get a chance to fix the symbol
mangling. This round-tripper is exactly flagging the current
known issue in that all of the symbols get extra `Copyable` and
`Escapable` requirements mangled into them, and thus reconsituting the
type from the mangled name doesn't give you the same type back.
In cases where the generic parameter is class-constrained,
`GenericSignature::requiresProtocol` will not contain `Copyable` or
`Escapable` because GenericSignature minimization will recognize that
the class already requires them.

Thus, because classes always require those protocols, we can
simply ask if the generic parameter is required to be a class to
determine if it had any inverses.
Instead of injecting Copyable & Escapable protocols into every
ExistentialLayout, only add those protocols if the existing protocols
don't already imply them. This simplifies things like `any Error`
protocol, so it still only lists one protocol in its existential layout.
But existentials like `any NoCopyP` still end up with a Copyable in its
layout.
resolves rdar://120512544
In the Concurrency module, an unavailable Sendable extension triggers an
 error about unavailable Copyable conformance. This conformance came
 through in the SubstitutionMap of a BoundGenericType, so I think it's
 ok to just ignore these.
There are a bunch of static `collectExistentialConformances` copied
around Sema and SILGen that are almost the same, save for whether they
want to permit missing conformances and/or check conditional
conformances.

This commit requestifies and combines all but one of these functions
into a `ModuleDecl::collectExistentialConformances`. The motivation for
this clean-up is another place that will need this procedure.
The SILGen emission for `Builtin.createAsyncTask` performs an
existential erasure and assumed that `any Any.Type` has no protocols in
its ExistentialLayout, but it's now possible to have some there with
NoncopyableGenerics.
@kavon kavon force-pushed the ncgenerics-stdlib-building-v3 branch from dde546a to 5e050e6 Compare January 11, 2024 03:39
@kavon
Copy link
Member Author

kavon commented Jan 11, 2024

@swift-ci please test

@kavon kavon merged commit ac465ea into swiftlang:main Jan 11, 2024
@kavon kavon deleted the ncgenerics-stdlib-building-v3 branch January 11, 2024 16:14
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