Commit Graph

45066 Commits

Author SHA1 Message Date
Rintaro Ishizaki
a506bae136 [ASTGen] Generate 'IsExpansionPattern' generic requirements
E.g. `where repeat each T: Comparable`
2025-03-07 10:28:47 -08:00
susmonteiro
51357a952c [cxx-interop] Prevent usage in Swift of C++ move constructor with default args 2025-03-07 16:02:38 +00:00
Rintaro Ishizaki
c669004e4c [ASTGen] Clone expanded AvailabilitySpec to set macro location 2025-03-07 07:18:39 -08:00
Rintaro Ishizaki
0a56198879 [ASTGen] Remove BridgedAvailabilityDomain 2025-03-07 07:18:23 -08:00
Erik Eckstein
26c7310a9a Swift AST: Fix debug description of Type
Don't get the swift source version string, but the debug dump string
2025-03-07 15:59:35 +01:00
Erik Eckstein
46035305aa Optimizer: improve simplification of alloc_stack
* Reimplement most of the logic in Swift as an Instruction simplification and remove the old code from SILCombine
* support more cases of existential archetype replacements:

For example:
```
  %0 = alloc_stack $any P
  %1 = init_existential_addr %0, $T
  use %1
```
is transformed to
```
  %0 = alloc_stack $T
  use %0
```

Also, if the alloc_stack is already an opened existential and the concrete type is known,
replace it as well:
```
  %0 = metatype $@thick T.Type
  %1 = init_existential_metatype %0, $@thick any P.Type
  %2 = open_existential_metatype %1 : $@thick any P.Type to $@thick (@opened("X", P) Self).Type
  ...
  %3 = alloc_stack $@opened("X", any P) Self
  use %3
```
is transformed to
```
  ...
  %3 = alloc_stack $T
  use %3
```
2025-03-07 15:59:34 +01:00
Erik Eckstein
5572c832e1 SILOptimizer: replace existential archetypes with concrete types in witness_method instructions 2025-03-07 15:59:34 +01:00
Erik Eckstein
71de3d90e0 Optimizer: replace existential archetypes with concrete types in apply instructions
If an apply uses an existential archetype (`@opened("...")`) and the concrete type is known, replace the existential archetype with the concrete type
  1. in the apply's substitution map
  2. in the arguments, e.g. by inserting address casts
For example:
```
  %5 = apply %1<@opend("...")>(%2) : <τ_0_0> (τ_0_0) -> ()
```
->
```
  %4 = unchecked_addr_cast %2 to $*ConcreteType
  %5 = apply %1<ConcreteType>(%4) : <τ_0_0> (τ_0_0) -> ()
```
2025-03-07 15:59:34 +01:00
Erik Eckstein
77dab77702 Swift SIL: make isLegalFormalType available in AST.Type 2025-03-07 15:59:34 +01:00
Erik Eckstein
431401c0dd Swift AST: add an initializer to SubstitutionMap
And let it conform to `NoReflectionChildren` to make it's debug dump in lldb nicer
2025-03-07 15:59:34 +01:00
Erik Eckstein
67925ea27e Swift AST: add GenericSignature
and add `var Type.invocationGenericSignatureOfFunctionType`
2025-03-07 15:59:34 +01:00
Erik Eckstein
810064b7dc Cleanup and additions to AST and SIL Type/CanonicalType
* factor out common methods of AST Type/CanonicalType into a `TypeProperties` protocol.
* add more APIs to AST Type/CanoncialType.
* move `MetatypeRepresentation` from SIL.Type to AST.Type and implement it with a swift enum.
* let `Builder.createMetatype` get a CanonicalType as instance type, because the instance type must not be a lowered type.
2025-03-07 15:59:33 +01:00
Erik Eckstein
35097b5a71 Optimizer: simplify unconditional_checked_cast to existential metatypes.
Replace `unconditional_checked_cast` to an existential metatype with an `init_existential_metatype`, it the source is a conforming type.
Note that init_existential_metatype is better than unconditional_checked_cast because it does not need to do any runtime casting.
2025-03-07 15:59:33 +01:00
Erik Eckstein
df81283b97 SILCombine: make it possible to add a Swift simplification to an existing SILCombine visit function.
So far a `SILCombineSimplifiable` could only replace a SILCombine visit implementation.
With the `SWIFT_SILCOMBINE_PASS_WITH_LEGACY` (to be used in Passes.def) it's possible to keep an existing C++ implementation and on top of that add a Swift Simplification pass.
2025-03-07 15:59:33 +01:00
Erik Eckstein
de841fdcd5 Fix a comment about SILCombine "passes" in Passes.def 2025-03-07 15:59:33 +01:00
Erik Eckstein
db03a55c79 Swift SIL: add some Builder APIs
* `createCheckedCastAddrBranch`
* `createUnconditionalCheckedCastAddr`
* `createDebugValue`
* `createWitnessMethod`
* `createInitEnumDataAddr`
2025-03-07 15:59:33 +01:00
Erik Eckstein
f7466eac78 SIL: fix bridging of SILDebugVariable
The optional C++ type was bridged to a non-optional Swift type.
The correct way is to bridged the non-optional C++ type to the non-optional Swift type.
2025-03-07 15:59:33 +01:00
Erik Eckstein
31057332ff Swift SIL: add some Instruction APIs
* getting the formal source and target types of casts
* `isFromVarDecl` and `usesMoveableValueDebugInfo` for AllocStackInst
* WitnessMethod APIs
* `TryApply.isNonAsync`
2025-03-07 15:59:33 +01:00
Erik Eckstein
eadfbf6842 Swift AST: add some APIs to Type and CanonicalType 2025-03-07 15:59:33 +01:00
Erik Eckstein
48db89031a SIL: be more tolerant when a user is deleted during use-list iteration.
Check if an operand's instruction has been deleted in `UseList.next()`.
This allows to delete an instruction, which has two uses of a value, during use-list iteration.
2025-03-07 15:59:32 +01:00
Erik Eckstein
aff36b056b SIL: fix cloning of keypath instruction
Don't include type-dependent operands in the argument list of the new keypath instruction.
Also enable the assert, which catches this problem, in release builds.

Fixes a compiler crash.
2025-03-07 15:09:11 +01:00
Rintaro Ishizaki
ff6cb11bb0 [ASTGen] Introduce 'AvailableAttr::createUnavailableInEmbedded()' 2025-03-07 04:14:50 -08:00
Rintaro Ishizaki
d60f1986a8 [ASTGen] Adopt AvailabilityDomainOrIdentifier scheme
Aligning with libParse
2025-03-07 04:14:50 -08:00
Allan Shortlidge
35fed04aa1 Merge pull request #79807 from tshortli/availability-context-available-custom-domains
AST: Teach AvailabilityContext to represent version-less availability
2025-03-07 03:25:40 -08:00
Allan Shortlidge
0462cfda11 AST: Teach AvailabilityContext to represent version-less availability.
This enables potential unavailability diagnostics to be emitted for decls that
are only available in version-less domains.
2025-03-06 22:29:50 -08:00
Michael Gottesman
58ea40ba6d [sil] Add missing flag to SILDeclRef's hash and change SILDeclRef to use llvm::hash_combine instead of rolling its own hash combiner.
This is really old code from before llvm::hash_combine existed. We really
shouldn't be rolling out own hash combine when we have something that we are
consistently using from LLVM. I validated the history of this code and talked
with JoeG/DougG/others to see if there was any reason beyond not having
hash_combine for us not to use hash_combine.

The reason why I am changing this now is that I want to convert SILDeclRef to
have another additional bit and use an OptionSet. When I noticed this... my eyes
burned, so I thought I would just quickly fix it before I landed the other
change so it could be a NFC change.
2025-03-06 13:28:34 -08:00
Allan Shortlidge
6ab32cff94 Sema: Parameterize potential unavailability diagnostics to allow no version.
This allows `X is only available in` diagnostics to be emitted for potential
unavailability in domains that do not support versioning.
2025-03-06 13:04:18 -08:00
Allan Shortlidge
0bf464b272 AST: Return optional AvailabilityRange from SemanticAvailableAttr queries.
Introduction, deprecation, and obsoleteion ranges should only be returned by
the accessors on `SemanticAvailableAttr` when the attribute actually has an
affect on the corresponding kind of availability.
2025-03-06 13:02:19 -08:00
Rintaro Ishizaki
017c0d98ec [ASTGen] Generate AutoDiff attributes
`@differentiable`, `@derivative` and `@transpose`
2025-03-06 10:36:13 -08:00
Mike Ash
30b622dc70 Merge pull request #79773 from mikeash/metadatareader-better-descriptor-sizing
[Reflection] Fix undersized reads in MetadataReader::readContextDescriptor.
2025-03-05 19:10:39 -05:00
Artem Chikin
148fb369fe [Dependency Scanning] Unique collected cross-import overlay files with a set
Resolves rdar://146141228
2025-03-05 15:13:07 -08:00
Doug Gregor
0997a7e016 Merge pull request #79688 from DougGregor/diagnostic-ref-footnotes
[Diagnostics] Reference markdown files for educational notes and diagnostic group documentation
2025-03-05 12:41:16 -08:00
Allan Shortlidge
77d18a87ea Merge pull request #79784 from tshortli/optimize-version-range-layout
AST: Optimize the layout of `AvailabilityRange`
2025-03-05 12:10:29 -08:00
Steven Wu
c5278f5801 Merge pull request #79779 from cachemeifyoucan/eng/PR-146155049
[Caching] Mark `-emit-module-source-info-path` as CacheInvariant
2025-03-05 08:15:38 -08:00
Anthony Latsis
6a3903bb53 Revert "Revert "Introduce adoption mode for Swift features""
This reverts commit 393c59c078.
2025-03-05 15:21:01 +00:00
Allan Shortlidge
cad1ee75d5 AST: Optimize the layout of AvailabilityRange.
`AvailabilityRange` is now being used as a currency type in more of the
compiler, and some of those uses are in permanent `ASTContext` allocations. The
class wraps the `VersionRange` utility, which is itself a wrapper around
`llvm::VersionTuple` with some additional storage for representing sentinel
values. Even though the two sentinel values can be be represented with just a
single bit of additional storage on top of the 16 bytes required to represent
`VersionTuple`, because of alignment requirements the sentinel values end up
bloating the layout of `VersionRange` by many bytes.

To make `AvailabilityRange` and `VersionRange` more efficient to store, we can
instead reserve two unlikely `llvm::VersionTuple` bit patterns as the sentinel
values instead. The values chosen are the same ones LLVM uses to represent
version tuple tombstones and empty keys in a `DenseMap`.
2025-03-05 07:15:15 -08:00
Mike Ash
91e7daa693 [Reflection] Fix undersized reads in MetadataReader::readContextDescriptor.
Determining a descriptor's size requires reading its contents, but reading its contents from out of process requires knowing its size.

Build up the size incrementally by walking over the TrailingObjects. Take advantage of the fact that each trailing object's presence/count depends only on data that comes before it. This allows us to read prefixes that we gradually expand until we've covered the whole thing.

Add calls to TrailingObjects to allow iterating over the prefix sizes, and modify readContextDescriptor to use them. This replaces the old code which attempted to determine the descriptor size in an ad-hoc fashion that didn't always get it right.

rdar://146006006
2025-03-05 09:29:06 -05:00
Allan Shortlidge
6eab842e7a Merge pull request #79777 from tshortli/potential-unavailability-diagnostics
AST/Sema: Decouple potential unavailability diagnostics from platform version
2025-03-05 00:35:23 -08:00
Allan Shortlidge
b5954e114b Merge pull request #79782 from tshortli/semantic-availability-spec-request
AST: Request-ify retrieval of `SemanticAvailabilitySpec`
2025-03-04 23:12:31 -08:00
Allan Shortlidge
a9707786eb IRGen: Update diagnostics to take AvailabilityRange instead of VersionTuple. 2025-03-04 19:41:04 -08:00
Allan Shortlidge
437382507e IDE: Update diagnostics to take AvailabilityRange instead of VersionTuple. 2025-03-04 19:41:04 -08:00
Allan Shortlidge
fe0688c40e Sema: Update diagnostics to take AvailabilityRange instead of VersionTuple. 2025-03-04 19:41:04 -08:00
Allan Shortlidge
1409cb1a30 AST: Teach DiagnosticEngine to accept AvailabilityRange arguments. 2025-03-04 19:41:04 -08:00
Allan Shortlidge
b64df7384e AST: Simplify AvailabilityRange construction.
Introduce a constructor that takes an `llvm::VersionTuple` directly, instead of
needing to spell out `VersionRange::allGTE(<tuple>)` which is unnecessarily
verbose.
2025-03-04 19:41:04 -08:00
Allan Shortlidge
cb778b7ce4 AST/Sema: Expand potential unavailability diagnostics to arbitrary domains.
When emitting potential unavailability diagnostics, don't assume that they can
only apply to the target platform `AvailabilityDomain`.
2025-03-04 19:41:04 -08:00
Rintaro Ishizaki
393c59c078 Revert "Introduce adoption mode for Swift features" 2025-03-04 19:13:05 -08:00
Allan Shortlidge
3ea979f712 AST: Request-ify retrieval of SemanticAvailabilitySpec.
Introduced `SemanticAvailabilitySpecRequest` to retrieve the semantic spec for
an `AvailabilitySpec`. Add an `isInvalid` bit to `AvailabilitySpec` to track
whether the request failed. Unfortunately, there aren't any easily accessible
spare bits in the layout of `AvailabilitySpec` so it had to be a new field.
2025-03-04 17:46:18 -08:00
Steven Wu
ae69713639 [Caching] Mark -emit-module-source-info-path as CacheInvariant
For the options that specifies the output, it should be cache invariant.
Fix the one remaining option that is not correctly labelled and add an
unittest to make sure all the options with output path naming convertion
are correctly marked as CacheInvariant.

rdar://146155049
2025-03-04 16:20:26 -08:00
Anthony Latsis
43b00af490 Merge pull request #79649 from AnthonyLatsis/danaus-plexippus
Introduce adoption mode for Swift features
2025-03-04 23:16:28 +00:00
Artem Chikin
6da529f098 Merge pull request #79753 from artemcm/NewConstFeatureDefinition
[Compile Time Values] Add a new experimental feature and the parsing of the `@const` attribute
2025-03-04 12:26:04 -08:00