Commit Graph

3196 Commits

Author SHA1 Message Date
Allan Shortlidge
d421f55009 AST: Request-ify ValueDecl::findImport().
To prevent performance regressions from calling `findImport()` more frequently,
request-ify the computation.

NFC.

Prerequisite of rdar://16154294
2024-04-01 17:44:08 -07:00
Ben Barham
1fdda023b3 Rename StringRef::endswith references to StringRef::ends_with
Missed this when doing the `startswith` renaming. `endswith` has also
been deprecated upstream (and presumably soon to be removed).
2024-04-01 10:59:16 -07:00
Doug Gregor
79b78acdf6 Use SuppressibleProtocolSet as InvertibleProtocolSet
Collapse the representations of "suppressible" and "invertible"
protocol sets. Only minor adjustments were required.
2024-03-29 11:31:48 -07:00
Doug Gregor
994e342c98 [Demangle-to-AST] Match invertible-generics extensions with no signature
Introduce a predicate that determines when a given extension corresponds
to what one would get by existing the nominal type without spelling out
any constraints. This differs from the notion of a "constrained
extension" when the nominal type suppresses conformances on any of its
generic parameters, e.g.,

    struct X<T: ~Copyable> { ... }

    // doesn't spell out any constraints, but is constrained because it
    // implicitly adds T: ~Copyable.
    extension X { ... }

    // does spell out constraints, but is not constrained because the
    // generic signature matches that of X.
    extension X where T: ~Copyable { }

Use this predicate when demangling a name to metadata, because name
mangling for extensions suppresses the generic signature for cases
where one "doesn't spell out any constraints."
2024-03-27 17:07:41 -07:00
Doug Gregor
bbfdf7b36a Merge pull request #72470 from DougGregor/dynamic-suppressible-protocols
Metadata and runtime support for suppressible protocol requirements
2024-03-27 11:49:00 -07:00
Konrad `ktoso` Malawski
6132386371 [Distributed] Complete handling of protocol calls and witnesses using adjusted mangling scheme (#72416) 2024-03-23 23:54:23 +09:00
Doug Gregor
b167eece42 Metadata and runtime support for suppressible protocol requirements
Introduce metadata and runtime support for describing conformances to
"suppressible" protocols such as `Copyable`. The metadata changes occur
in several different places:

* Context descriptors gain a flag bit to indicate when the type itself has
  suppressed one or more suppressible protocols (e.g., it is `~Copyable`).
  When the bit is set, the context will have a trailing
  `SuppressibleProtocolSet`, a 16-bit bitfield that records one bit for
  each suppressed protocol. Types with no suppressed conformances will
  leave the bit unset (so the metadata is unchanged), and older runtimes
  don't look at the bit, so they will ignore the extra data.
* Generic context descriptors gain a flag bit to indicate when the type
  has conditional conformances to suppressible protocols. When set,
  there will be trailing metadata containing another
  `SuppressibleProtocolSet` (a subset of the one in the main context
  descriptor) indicating which suppressible protocols have conditional
  conformances, followed by the actual lists of generic requirements
  for each of the conditional conformances. Again, if there are no
  conditional conformances to suppressible protocols, the bit won't be
  set. Old runtimes ignore the bit and any trailing metadata.
* Generic requirements get a new "kind", which provides an ignored
  protocol set (another `SuppressibleProtocolSet`) stating which
  suppressible protocols should *not* be checked for the subject type
  of the generic requirement. For example, this encodes a requirement
  like `T: ~Copyable`. These generic requirements can occur anywhere
  that there is a generic requirement list, e.g., conditional
  conformances and extended existentials. Older runtimes handle unknown
  generic requirement kinds by stating that the requirement isn't
  satisfied.

Extend the runtime to perform checking of the suppressible
conformances on generic arguments as part of checking generic
requirements. This checking follows the defaults of the language, which
is that every generic argument must conform to each of the suppressible
protocols unless there is an explicit generic requirement that states
which suppressible protocols to ignore. Thus, a generic parameter list
`<T, Y where T: ~Escapable>` will check that `T` is `Copyable` but
not that it is `Escapable`, and check that `U` is both `Copyable` and
`Escapable`. To implement this, we collect the ignored protocol sets
from these suppressed requirements while processing the generic
requirements, then check all of the generic arguments against any
conformances not suppressed.

Answering the actual question "does `X` conform to `Copyable`?" (for
any suppressible protocol) looks at the context descriptor metadata to
answer the question, e.g.,

1. If there is no "suppressed protocol set", then the type conforms.
This covers types that haven't suppressed any conformances, including
all types that predate noncopyable generics.
2. If the suppressed protocol set doesn't contain `Copyable`, then the
type conforms.
3. If the type is generic and has a conditional conformance to
`Copyable`, evaluate the generic requirements for that conditional
conformance to answer whether it conforms.

The procedure above handles the bits of a `SuppressibleProtocolSet`
opaquely, with no mapping down to specific protocols. Therefore, the
same implementation will work even with future suppressible protocols,
including back deployment.

The end result of this is that we can dynamically evaluate conditional
conformances to protocols that depend on conformances to suppressible
protocols.

Implements rdar://123466649.
2024-03-21 14:57:47 -07:00
Slava Pestov
1a7bdb46eb AST: Shave a yak in ProtocolDecl 2024-03-21 15:17:44 -04:00
Slava Pestov
839063cab0 AST: Remove ProtocolDecl::getSuperclass()/setSuperclass() 2024-03-21 15:15:59 -04:00
Michael Gottesman
18aa7d8c3c [ast] Add a helper method ActorIsolation::getActorOrNullPtr().
ActorIsolation::getActor() asserts if an actor cannot be found. This new helper
method just returns nullptr instead.
2024-03-18 12:13:30 -07:00
Slava Pestov
a628b9c061 AST: Remove InverseMarking.h 2024-03-16 08:34:42 -04:00
Kavon Farvardin
149c052ec5 use new noncopyable types infrastructure
The infrastructure underpinning the new feature NoncopyableGenerics is
mature enough to be used.
2024-03-14 23:10:44 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Erik Eckstein
3c76464c1c rename withConcurrent -> withSendable
That was missed when "concurrent" was renamed to "sendable"
2024-03-13 09:58:31 +01:00
Rintaro Ishizaki
58e70e8535 Merge pull request #72103 from rintaro/astgen-stringliteral
[ASTGen] Generate interpolated string literal
2024-03-13 10:08:15 +09:00
Allan Shortlidge
c0303e0e7d Sema: Requestify Obj-C requirements map computation.
Avoids repeatedly rebuilding requirement maps during witness resolution.
2024-03-11 15:37:00 -07:00
Slava Pestov
f36b509eff AST: Remove ProtocolDecl::hasInverseMarking() 2024-03-07 12:22:33 -05:00
Slava Pestov
12626628bd AST: Remove AssociatedTypeDecl::hasInverseMarking() 2024-03-07 12:22:33 -05:00
Slava Pestov
dcea491dbe Sema: Remove inference of conditional Copyable conformance from generic parameters 2024-03-06 22:47:54 -05:00
Rintaro Ishizaki
e5592c7984 [ASTGen] Generate interpolated string literal 2024-03-06 10:32:00 -08:00
eeckstein
d1ec089c72 Merge pull request #72088 from language-core/main
chore: fix some comments
2024-03-06 10:08:50 +01:00
Anthony Latsis
fd93eea16b Merge pull request #70608 from AnthonyLatsis/unqualified-ident
[NFC] AST: Merge `SimpleIdentTypeRepr` & `GenericIdentTypeRepr` into `IdentTypeRepr`
2024-03-06 09:41:16 +03:00
Kavon Farvardin
e2d33ecd5f Merge pull request #71878 from kavon/ncgenerics-mangling-2
NCGenerics: New Inverse Mangling 3DS XL
2024-03-05 18:15:40 -08:00
Kavon Farvardin
215bd3cab4 Mangling: handle inverse requirements 2024-03-05 14:19:00 -08:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Alex Hoppen
aa955655ab Merge pull request #72048 from Jamezzzb/#56350
#56350 - Give Identifier a hasUnderscoredNaming() helper
2024-03-04 20:13:01 -08:00
James Brown
2c281208de 56350 - Give Identifier a hasUnderscoredNaming() helper and in the places currently using str().startsWith, change it to use the new helper. 2024-03-04 19:34:11 -05:00
Ellie Shin
8ffd8efe2d Merge branch 'main' into es-check-exp 2024-03-02 14:55:17 -08:00
Anthony Latsis
a315b22ff7 Remove non-essential uses of SimpleIdentTypeRepr & GenericIdentTypeRepr 2024-03-02 14:59:21 +03:00
Anthony Latsis
68746a0579 [NFC] AST: Rename IdentTypeReprUnqualifiedIdentTypeRepr 2024-03-02 08:28:47 +03:00
Ellie Shin
30669fca65 Currently when checking if resilience check can be bypassed within a package,
we only check if the loaded module is built from a package interface. This is
not enough as a binary module could just contain exportable decls if built with
experimental-skip-non-exportable-decls, essentially resulting in content equivalent
to interface content. This might be made a default behavior so this PR requires
a module to opt in to allow non-resilient access by a participating client in the
same package.

Since it affects module format, SWIFTMODULE_VERSION_MINOR is updated.

rdar://123651270
2024-03-01 15:13:58 -08:00
Slava Pestov
d88faf3626 AST: Move a couple of declarations to a more logical location 2024-03-01 15:46:59 -05:00
Slava Pestov
4a1b0c80cd RequirementMachine: Install placeholder requirement signature if completion fails
I did this if there was a request cycle but forgot the other obvious case.
2024-02-29 18:13:28 -05:00
Slava Pestov
f2bd764381 AST: Fix crash with circular raw value
Fixes rdar://problem/123543175.
2024-02-26 19:56:19 -05:00
Slava Pestov
6ac91cde5d Merge pull request #71821 from slavapestov/inheritance-clause-fixes
Refactor protocol inheritance clauses and existential layout for non-copyable generics
2024-02-24 11:58:03 -05:00
Slava Pestov
48d814b7aa AST: Remove ProtocolDecl::requiresInvertible() 2024-02-24 07:25:59 -05:00
Slava Pestov
9f0564c0e2 AST: Replace a ProtocolDecl::requiresInvertible() call with ProtocolDecl::inheritsFrom() 2024-02-24 07:25:59 -05:00
Slava Pestov
61ecdead7b Sema: Replace sole usage of TypeDecl::hasMarking() with getDirectlyInheritedNominalTypeDecls() 2024-02-24 07:25:59 -05:00
Slava Pestov
a801ac37de AST: Re-implement ProtocolDecl::inheritsFrom() to use getAllInheritedProtocols() 2024-02-24 07:25:59 -05:00
Slava Pestov
443919a9bf AST: Introduce ProtocolDecl::getAllInheritedProtocols() 2024-02-24 07:25:59 -05:00
Slava Pestov
1267f87251 AST: Fancier getPlaceholderRequirementSignature() 2024-02-24 07:25:59 -05:00
Ellie Shin
68e3488e7b Merge pull request #71779 from apple/es-pb
Allow resilience bypassing package optimization for all decls within a package boundary.
2024-02-23 12:51:01 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Ellie Shin
eedd0ddf78 When package optimization is enabled, treat public decls as non-resilient
as well besides package decls if in the same package boundary.

Resolves rdar://123344579
2024-02-21 00:20:47 -08:00
Slava Pestov
e7d7f6f69f RequirementMachine: Add Copyable/Escapable requirements to 'placeholder' generic signatures
If we fail to build a generic signature (or requirement signature of a
protocol) because of a request cycle or because Knuth-Bendix completion
failed, we would create a placeholder signature with no requirements.

However in a move-only world, a completely unconstrained generic
parameter might generate spurious diagnostics when used in a copyable
way. For this reason, let's outfit these placeholder signatures with
a default set of conformance requirements to Copyable and Escapable.
2024-02-20 18:26:05 -05:00
Pavel Yaskevich
11ef6e58d8 Merge pull request #71659 from xedin/noncopyable-circularity-fixes
[AST/Sema] NonCopyableGenerics: Address some of the request circularity issues
2024-02-20 12:38:16 -08:00
Pavel Yaskevich
b6af269933 [AST] Remove TypeDecl::hasInverse and move canBe{Copyable, Escapable} to NominalTypeDecl` 2024-02-19 13:04:44 -08:00
Pavel Yaskevich
c81db8e149 [AST] NonCopyableGenerics: Expand hasInverseMarking to support associated type declarations
This is required for `ASTPrinter` to wrap the protocol that has
associated type with inverses in a feature block.
2024-02-19 10:37:16 -08:00
Pavel Yaskevich
68b49b6fd0 [AST] NonCopyableGenerics: Don't resolve requirements in NominalTypeDecl::hasInverseMarking
TypeRepr for the subject should be already bound to a generic type
declaration, so there is no need to resolve the requirement to
check that.
2024-02-16 17:55:53 -08:00
Pavel Yaskevich
15b79c5bde [AST/Sema] NFC: Remove obsolete getMarking(...) and InvertibleAnnotationRequest 2024-02-16 17:55:52 -08:00