Skip to content

NCGenerics: New Inverse Mangling 3DS XL #71878

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 5 commits into from
Mar 6, 2024

Conversation

kavon
Copy link
Member

@kavon kavon commented Feb 26, 2024

Initial implementation of mangling for inverse requirements for NoncopyableGenerics. There are some known issues:

(1) Protocols with ~Copyable have bogus default witness tables. Entries for a default implementation of a method requirement gives this:

sil_default_witness_table NoncopyableProto {
  no_default
}

In general, protocols aren't well tested or fully covered by this PR. As discussion below reveals, we may need an updated mangling scheme to handle associated types.

(2) a number of tests now regress when NoncopyableGenerics is enabled in the compiler:

Failed Tests (4):
  Swift(macosx-x86_64) :: IRGen/existential_shape_metadata.swift
  Swift(macosx-x86_64) :: SILGen/existential_member_accesses_self_assoctype.swift
  Swift(macosx-x86_64) :: SILGen/tuple_attribute_reabstraction.swift
  Swift(macosx-x86_64) :: SILGen/variadic-generic-reabstract-tuple-result.swift

These have been marked XFAIL: noncopyable_generics since they're most likely issues that have been uncovered now that we're mangling inverses.

(3) type aliases were left basically as a TODO. I think since they can appear in an extension, and have their own generic signature, we need to be careful about how we mangle them. I have no tests for them yet either.

@kavon
Copy link
Member Author

kavon commented Feb 26, 2024

@swift-ci smoke test

@kavon
Copy link
Member Author

kavon commented Feb 26, 2024

preset=ncgenerics,smoketest=macosx
@swift-ci Please test with preset macOS Platform

@kavon kavon force-pushed the ncgenerics-mangling-2 branch 2 times, most recently from 17cb5cd to 0af627b Compare February 27, 2024 06:08
@kavon
Copy link
Member Author

kavon commented Feb 27, 2024

@swift-ci test

@kavon kavon force-pushed the ncgenerics-mangling-2 branch from 0af627b to a91fea5 Compare February 28, 2024 00:51
@kavon
Copy link
Member Author

kavon commented Feb 28, 2024

@swift-ci test

@kavon kavon force-pushed the ncgenerics-mangling-2 branch 3 times, most recently from 31146b7 to 9521098 Compare March 2, 2024 05:02
@kavon
Copy link
Member Author

kavon commented Mar 2, 2024

@swift-ci smoke test

1 similar comment
@kavon
Copy link
Member Author

kavon commented Mar 2, 2024

@swift-ci smoke test

@kavon kavon force-pushed the ncgenerics-mangling-2 branch from d94cb78 to a981a53 Compare March 2, 2024 17:59
@@ -925,13 +1012,19 @@ now codified into the ABI; the index 0 is therefore reserved.

generic-param-pack-marker ::= 'Rv' GENERIC_PARAM-INDEX // generic parameter pack marker

INVERTIBLE-KIND ::= 'c' // Copyable
INVERTIBLE-KIND ::= 'e' // Escapable
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should bake the invertible protocols we know about into the mangling scheme. Rather, I think we should mangle an "inverted conformance requirement" and add standard substitutions for Copyable and Escapable to keep it smaller.

Copy link
Member Author

@kavon kavon Mar 4, 2024

Choose a reason for hiding this comment

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

I considered that approach and would support it. I just went with this current approach as it was simple to sketch out.

GENERIC-PARAM-COUNT ::= 'z' // zero parameters
GENERIC-PARAM-COUNT ::= INDEX // N+1 parameters

requirement ::= protocol 'R' GENERIC-PARAM-INDEX // protocol requirement
requirement ::= protocol assoc-type-name 'Rp' GENERIC-PARAM-INDEX // protocol requirement on associated type
requirement ::= protocol assoc-type-list 'RP' GENERIC-PARAM-INDEX // protocol requirement on associated type at depth
requirement ::= protocol substitution 'RQ' // protocol requirement with substitution
#if SWIFT_RUNTIME_VERSION >= 6.0
requirement ::= 'Ri' INVERTIBLE-KIND GENERIC-PARAM-INDEX // inverse requirement
Copy link
Member

Choose a reason for hiding this comment

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

We'll also need a version that works with associated types, I presume?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I believe we'll need them.

Copy link
Contributor

Choose a reason for hiding this comment

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

@slavapestov seems to think we won’t need them

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently the only place in the language where you can state T: ~Copyable with T a dependent member type is inside of a protocol, eg

protocol P {
  associatedtype A: ~Copyable
}

I was thinking that for symbol mangling, we don't ever need this because the requirement signature is not mangled as part of any symbol. However, now that I think about it I do believe we mangle the requirement signature in the protocol's context descriptor. So perhaps we need a mangling here after all.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we do mangle the requirement signature as part of the protocol's context descriptor.

@kavon kavon force-pushed the ncgenerics-mangling-2 branch from a981a53 to a07d9eb Compare March 4, 2024 21:07
@kavon
Copy link
Member Author

kavon commented Mar 4, 2024

@swift-ci smoke test

@kavon kavon force-pushed the ncgenerics-mangling-2 branch from a07d9eb to 0d19444 Compare March 5, 2024 07:05
@kavon kavon marked this pull request as ready for review March 5, 2024 07:07
@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci smoke test

@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci test

@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

preset=ncgenerics,smoketest=macosx
@swift-ci Please test with preset macOS Platform

@kavon kavon force-pushed the ncgenerics-mangling-2 branch from 0d19444 to 3f03eef Compare March 5, 2024 08:07
@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci test

@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

preset=ncgenerics,smoketest=macosx
@swift-ci Please test with preset macOS Platform

@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

Failed Tests (2):
  Swift(macosx-x86_64) :: SILGen/mangling_inverse_generics.swift
  Swift(macosx-x86_64) :: stdlib/Observation/Observable.swift

@kavon kavon force-pushed the ncgenerics-mangling-2 branch from 3f03eef to 184ec68 Compare March 5, 2024 17:55
@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci smoke test

@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci test platform linux

@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci Please test Linux platform

@kavon kavon force-pushed the ncgenerics-mangling-2 branch from 184ec68 to 6ee6527 Compare March 5, 2024 20:56
@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci smoke test

@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

preset=ncgenerics,smoketest=macosx
@swift-ci Please test with preset macOS Platform

kavon added 2 commits March 5, 2024 14:19
After implementing mangling for inverses, issues have been revealed.
@kavon kavon force-pushed the ncgenerics-mangling-2 branch from 6ee6527 to 2a1cf37 Compare March 5, 2024 22:20
@kavon
Copy link
Member Author

kavon commented Mar 5, 2024

@swift-ci smoke test

@kavon kavon enabled auto-merge March 5, 2024 22:20
@kavon
Copy link
Member Author

kavon commented Mar 6, 2024

@swift-ci smoke test linux

@kavon kavon merged commit e2d33ec into swiftlang:main Mar 6, 2024
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.

4 participants