Commit Graph

2698 Commits

Author SHA1 Message Date
Becca Royal-Gordon
cf541c1da9 [NFC] Hoist getAttributeInsertionLoc() up to Decl
This functionality was previously reserved for ValueDecls. Move it all the way up to Decl; in the process, make it correctly handle EnumElementDecls and EnumCaseDecls.

This change also allows us to generalize `swift::fixDeclarationObjCName()` to work on extensions, though we do not use that capability in this commit.
2024-05-16 18:05:23 -07:00
Becca Royal-Gordon
07b9fe9ce6 Support @objc(CustomName) on extensions
This now specifies a category name that’s used in TBDGen, IRGen, and PrintAsClang. There are also now category name conflict diagnostics; these subsume some @implementation diagnostics.

(It turns out there was already a check for @objc(CustomName) to make sure it wasn’t a selector!)
2024-05-16 13:40:13 -07:00
Michael Gottesman
e3e78ad6bb [sending] Change the internals of sending to be based around 'sending' instead of 'transferring'.
We still only parse transferring... but this sets us up for adding the new
'sending' syntax by first validating that this internal change does not mess up
the current transferring impl since we want both to keep working for now.

rdar://128216574
2024-05-16 12:20:45 -07:00
Doug Gregor
b641c54ee2 Generalize AbstractStorageDecl::isSettable() to return a three-state value
This operation determines whether a particular storage declaration,
when accessed from a particular location, is mutable or not. It has a
particular semantic that `let` declarations, when accessed from an
initializer, are considered mutable even though they can only be
assigned. There is similar logic for init accessors.

Tease apart "truly mutable" from "initializable because we're in an
initializer", introducing AbstractStorageDecl::mutability() to
represent all three states. isSettable() remains available as a thin
shim over mutability() and all clients are unchanged thus far, making
this a no-op refactoring.
2024-05-14 14:35:11 -07:00
Slava Pestov
7e36060331 AST: Remove VarDecl::getOpenedElementEnvironment() 2024-05-10 17:21:17 -04:00
Becca Royal-Gordon
c3225b066e [NFC] Merge two category name accessors 2024-05-01 12:18:19 -07:00
Ellie Shin
3f047102c2 Merge pull request #72937 from apple/elsh/pkg-sil-verify
Add a package serialization bit to Module for SIL verifier in Package CMO mode.
2024-04-22 12:44:28 -07:00
Slava Pestov
e342a38b87 Sema: Convert TypeChecker::computeCaptures() into two requests
We now compute captures of functions and default arguments
lazily, instead of as a side effect of primary file checking.

Captures of closures are computed as part of the enclosing
context, not lazily, because the type checking of a single
closure body is not lazy.

This fixes a specific issue with the `-experimental-skip-*` flags,
where functions declared after a top-level `guard` statement are
considered to have local captures, but nothing was forcing these
captures to be computed.

Fixes rdar://problem/125981663.
2024-04-20 22:16:25 -04:00
Slava Pestov
55ff73f205 AST: Stronger assertions around CaptureInfo 2024-04-19 17:59:58 -04:00
Anthony Latsis
4af5140d8b Merge pull request #70579 from AnthonyLatsis/super-sema
Move unsupported `super` use diagnosis from Parse to Sema
2024-04-19 20:07:12 +03:00
Anthony Latsis
fa6924a34e ParamDecl: Defend against default argument kind overwrites 2024-04-19 16:57:05 +03:00
Anthony Latsis
1d3a5860e2 [NFC] ParamDecl: Extract write of type-checked default expr into its own method 2024-04-19 16:57:05 +03:00
Anthony Latsis
61bdbd2fe3 Move unsupported super use diagnosis form Parse to Sema 2024-04-19 16:57:04 +03:00
Slava Pestov
3e637b0afb Merge pull request #73129 from slavapestov/local-function-isolation-change
Local functions inherit isolation from context instead of captures
2024-04-19 08:32:46 -04:00
Slava Pestov
d222470a0b AST: Remove unused methods from CaptureInfo 2024-04-18 22:47:23 -04:00
Ellie Shin
0c0d8c0316 Merge branch 'main' into elsh/pkg-sil-verify 2024-04-18 13:34:29 -07:00
nate-chandler
b00b5aad4f Merge pull request #72646 from nate-chandler/bitwise-copyable/20240327/1
[BitwiseCopyable] Allow suppression via ~.
2024-04-18 07:05:10 -07:00
Ellie Shin
45e8454a9e Merge branch 'main' into elsh/pkg-sil-verify 2024-04-17 22:46:55 -07:00
Ellie Shin
fbb3382e21 During Package CMO, SIL cloning happens during which
SILOptions::EnableSerializePackage info is lost.

SILVerifier needs this info to determine whether resilience
can be bypassed for decls serialized in a resiliently
built module when Package CMO optimization enabled.

This PR adds SerializePackageEnabled bit to Module format
and uses that in SILVerifier.

Resolves rdar://126157356
2024-04-17 22:37:48 -07:00
Allan Shortlidge
bd59db6e15 AST: Refactor missing import diagnostic into standalone utility.
NFC.
2024-04-16 16:29:51 -07:00
Nate Chandler
ba467d2bd2 [Sema] Enable suppression of inferred conformances.
Add the machinery to support suppression of inference of conformance to
protocols that would otherwise be derived automatically.

This commit does not enable any conformances to be suppressed.
2024-04-15 16:46:22 -07:00
Meghana Gupta
4b440a1d80 Merge pull request #72916 from meg-gupta/lifetimedepreq
Requestify LifetimeDependenceInfo
2024-04-09 11:28:18 -07:00
Konrad `ktoso` Malawski
7cd9063ba5 [Distributed] Diagnose missing import also for funcs in extensions
Resolves rdar://125813581
2024-04-09 17:08:27 +09:00
Meghana Gupta
bfa6c57ac4 Requestify LifetimeDependenceInfo
Query and cache lifetime dependence info via evaluator requests
2024-04-08 15:15:36 -07:00
Allan Shortlidge
feba547411 AST: Adopt Decl::isUnreachableAtRuntime() in Hashable/Equatable derivation.
When deriving `Hashable` and `Equatable` for enums, use
`Decl::isUnreachableAtRuntime()` to determine whether or not to insert
`_diagnoseUnavailableCodeReached()` traps for specific enum elements. This
fixes a bug where inappropriate traps were inserted for enum elements that are
unavailable for app extensions. It also fixes a bug where traps were inserted
when building a zippered library for macOS and enum elements were unavailable
on macOS but not for macCatalyst clients.

Resolves rdar://125371621
2024-04-04 16:18:35 -07:00
Doug Gregor
b84f8ab080 Rename "suppressible protocols" to "invertible protocols".
We've decided to use the "invertible protocols" terminology throughout
the runtime and compiler, so move over to that terminology
consistently.
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
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
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
02c30d1c15 AST: Fix confusion when builtin conformance passed to registerProtocolConformance() 2024-03-07 12:24:33 -05: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
Rintaro Ishizaki
e5592c7984 [ASTGen] Generate interpolated string literal 2024-03-06 10:32:00 -08: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
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
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
61ecdead7b Sema: Replace sole usage of TypeDecl::hasMarking() with getDirectlyInheritedNominalTypeDecls() 2024-02-24 07:25:59 -05:00
Slava Pestov
443919a9bf AST: Introduce ProtocolDecl::getAllInheritedProtocols() 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