Commit Graph

1923 Commits

Author SHA1 Message Date
Doug Gregor
c7fd48aa67 Rework storage for conformance isolation
Switch over to split caching for the conformance isolation request,
which optimizes for the common case where the conformance is
nonisolated. Also put the explicit global actor TypeExpr* in an
ASTContext side table, so we don't take a pointer's worth of storage
in every conformance.

For that side table, introduce a new "ASTContext::GlobalCache" that's
there only for side tables, so we don't have to go add get/set
operations to ASTContext and recompile the world every time we want to
add a side table like this.

Thanks, Slava!
2025-03-13 17:38:54 -07:00
Alastair Houghton
55afa47bea [Concurrency] More work on the custom executor implementation.
Added an `-executor-factory` argument to the compiler to let you safely
specify the executors you wish to use (by naming a type that returns
them).

Also added some tests of the new functionality.

rdar://141348916
2025-03-13 13:34:41 +00:00
Allan Shortlidge
542986032f AST: Unique CustomAvailabilityDomain instances.
Store `CustomAvailabilityDomain` instances in a folding set on `ASTContext`.
This instances of custom domains to be created without needing to cache them in
disparate locations.
2025-03-12 18:30:45 -07:00
Tony Allevato
68876a6d4a Merge pull request #76636 from allevato/rich-identifiers
Support raw identifiers (backtick-delimited identifiers containing non-identifier characters).
2025-03-12 14:56:14 -04:00
eeckstein
47b449372e Merge pull request #79917 from eeckstein/rename-opened-archetype-type
AST: rename OpenArchetypeType -> ExistentialArchetypeType
2025-03-12 06:01:10 +01:00
Tony Allevato
8752920875 Allow module aliases to be expressed in the explicit Swift module map JSON file.
For build systems that already generate these files, it makes sense to include the aliases so that the map file serves as a comprehensive index of how the module inputs are referenced.
2025-03-11 17:18:43 -04:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Slava Pestov
4eaa5ce3c5 AST: Move a few things from ASTContext::Implementation::Arena up to Implementation
Normal conformances, self conformances, and availability contexts cannot
contain types with type variables, so there is no reason to duplicate
the uniquing maps between the permanent arena and solver arena.
2025-03-10 10:39:50 -04:00
Allan Shortlidge
c6a5e6f745 AST: Reimplement AvailabilityContext storage using TrailingObjects.
This makes more efficient use of the permanent memory allocated for
`AvailabilityContext` representations and also fixes a leak that was introduced
in https://github.com/swiftlang/swift/pull/79718 where the small vector for
unavailable domain storage was not being cleaned up on `ASTContext`
deallocation.

Resolves rdar://145929932.
2025-03-03 18:29:34 -08:00
Allan Shortlidge
866db542a3 Gardening: Use const consistently for ASTContext parameters. 2025-03-02 14:45:50 -08:00
Allan Shortlidge
bc982097b9 AST/Sema: Adopt AvailabilityDomain arguments in even more diagnostics.
Update potential unavailability diagnostics to take `AvailabilityDomain`
instead of a platform string.
2025-02-28 14:13:24 -08:00
Rintaro Ishizaki
cb049d8ed1 [ASTGen] Generate anonymous closure parameters
E.g. '$0'
2025-02-07 19:39:57 -08:00
Anton Korobeynikov
1e7a1d91fc Emit reabstraction thunks for implicit conversions between T.TangentType and Optional<T>.TangentType (#78076) 2025-02-05 20:57:52 -08:00
Rintaro Ishizaki
df2ada37df [ASTGen] Generate AvailableAttr
* Move `AvailabilitySpec` handling logic to AST, so they can be shared
  between libParse and ASTGen
* Requestify '-define-availability' arguments parsing and parse them
  with 'SwiftParser' according to the 'ParserASTGen' feature flag
* Implement 'AvailableAttr' generation in ASTGen
2025-02-04 23:40:01 -08:00
Doug Gregor
4395537fa0 Introduce the @safe attribute as described in the opt-in safety checking proposal 2025-01-23 07:47:17 -08:00
Allan Shortlidge
0b5d787a73 AST: Rename AvailabilityContext::PlatformInfo.
It's about to get updated to contain more than just platform-specific
availability context information.

NFC.
2025-01-21 11:44:28 -08:00
Ian Anderson
87d6979dae Merge pull request #78303 from ian-twilightcoder/clang-importer-search-paths
[ClangImporter] clang's -iframework comes before builtin usr/local/include, but Swift's -Fsystem comes after
2025-01-06 13:05:25 -08:00
Ian Anderson
cdb42c3535 [ClangImporter] clang's -iframework comes before builtin usr/local/include, but Swift's -Fsystem comes after
When Swift passes search paths to clang, it does so directly into the HeaderSearch. That means that those paths get ordered inconsistently compared to the equivalent clang flag, and causes inconsistencies when building clang modules with clang and with Swift. Instead of touching the HeaderSearch directly, pass Swift search paths as driver flags, just do them after the -Xcc ones.

Swift doesn't have a way to pass a search path to clang as -isystem, only as -I which usually isn't the right flag. Add an -Isystem Swift flag so that those paths can be passed to clang as -isystem.

rdar://93951328
2024-12-23 22:15:52 -08:00
Doug Gregor
5b90b8851a Generalize protocol conformance options spelled via attribute and incorporate @unsafe
Protocol conformances have a handful attributes that can apply to them
directly, including @unchecked (for Sendable), @preconcurrency, and
@retroactive. Generalize this into an option set that we carry around,
so it's a bit easier to add them, as well as reworking the
serialization logic to deal with an arbitrary number of such options.

Use this generality to add support for @unsafe conformances, which are
needed when unsafe witnesses are used to conform to safe requirements.
Implement general support for @unsafe conformances, including
producing a single diagnostic per missing @unsafe that provides a
Fix-It and collects together all of the unsafe witnesses as notes.
2024-12-20 23:16:23 -08:00
Anthony Latsis
855c5758d2 [NFC] AST: Clean up unused field and parameter in LocalArchetypeType subclasses 2024-12-20 02:57:29 +00:00
Joe Groff
8436db3b9d Merge pull request #78021 from jckarter/addressable-params-2
Add an `@_addressableSelf` attribute to mark the self param of methods as addressable.
2024-12-09 08:42:49 -08:00
Joe Groff
ac7a61679d Add an @_addressableSelf attribute to mark the self param of methods as addressable. 2024-12-06 16:54:01 -08:00
Slava Pestov
302b163edc AST: Optimize TypeAliasType representation 2024-12-06 17:39:55 -05:00
Pavel Yaskevich
8a0a083a45 Merge pull request #77797 from xedin/locatable-types
[AST/Sema]  Introduce a new type that has associated location in source
2024-12-02 16:33:43 -08:00
Pavel Yaskevich
0fe4cea7d7 [AST] Introduce a new type that has associated location in source
This type is intended to be used to wrap compiler synthesized nodes
(i.e. variables) to make it easier for diagnostic to diagnose precise
failure locations.

Consider the situation like:

```
protocol P {}

extension Array: P where Element: P {}

func test<T: P>() -> T {
  $_a = ...
  $_b = ...
  return [$_a, $_b]
}
```

This is a common pattern with result builders.

In this case if one of the elements don't conform to `P` the best
user experience would be to attach diagnostic to the element otherwise
the developers would have to figure out where in result expression
the error occured before attempting to fix it.
2024-11-21 11:01:13 -08:00
Hamish Knight
4946c799af [AST] Remove ModuleDecl::addFile
Rather than exposing an `addFile` member on
ModuleDecl, have the `create` members take a
lambda that populates the files for the module.
Once module construction has finished, the files
are immutable.
2024-11-17 14:17:20 +00:00
Meghana Gupta
c0a55e11d4 Merge pull request #77314 from meg-gupta/ossaflag
Remove -enable-ossa-modules for Synchronization and Distributed
2024-11-04 02:40:54 -08:00
Meghana Gupta
1985b6cceb [NFC] Add SerializationOptions to ASTContext 2024-10-31 13:40:56 -07:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Joe Groff
8242110bbe Merge pull request #76831 from jckarter/builtin-vector
Builtin.FixedArray
2024-10-23 05:20:21 -10:00
Joe Groff
a184782a38 Introduce a Builtin.FixedArray type.
`Builtin.FixedArray<let N: Int, T: ~Copyable & ~Escapable>` has the layout of `N` elements of type `T` laid out
sequentially in memory (with the tail padding of every element occupied by the array). This provides a primitive
on which the standard library `Vector` type can be built.
2024-10-22 16:21:45 -07:00
Allan Shortlidge
b346385544 AST: Refactor AvailabilityContext into a value type.
Make the pointer to uniqued storage an implementation detail of an
`AvailabilityContext` value. This way clients of `AvailabilityContext` don't
need to think about pointers and can have access to mutating operations on a
context when appropriate.
2024-10-21 15:16:08 -07:00
Allan Shortlidge
0730209302 AST: Move AvailabilityContext into its own header and cpp file. 2024-10-21 15:16:08 -07:00
Allan Shortlidge
439c5951ec AST: Introduce AvailabilityContext.
This class is designed to be a compact representation of the active
availability constraints in a specific scope. For now, it only models platform
introduction availability but it will soon be updated to cover additional
availability constraints, like platform unavailability.

In anticipation of needing to reference `AvailabilityContext`s from
`TypeRefinementContext`s and increasing memory requirements for these contexts,
a cache of uniqued instances of `AvailabilityContext` are stored in a
`llvm::FoldingSet` on `ASTContext`.
2024-10-17 11:26:28 -07:00
Egor Zhdan
3a200deee9 [cxx-interop] Add UnsafeCxxContiguousIterator & UnsafeCxxMutableContiguousIterator protocols
This adds a pair of Swift protocols that represents C++ iterator types conforming to `std::contiguous_iterator_tag` requirements. These are random access iterators that guarantee that the values are stored in consequent memory addresses.

This will be used to optimize usage of C++ containers such as `std::vector` from Swift, for instance, by providing an overload of `withContiguousStorageIfAvailable` for contiguous containers.

rdar://137877849
2024-10-15 14:30:09 +01:00
Alexis Laferrière
ff803c6df1 Sema: Move the availability macros cache to the ASTContext
The availability macros definitions are parsed from the command line and
stored in a cache. The cache was in the Parser, which would have it be
computed for each file using availability macros. Let's move it to the
ASTContext instead where it can generally be computed once per invocation
and used across the module.

rdar://134797088
2024-10-01 09:07:56 -07:00
Steven Wu
82c9fdf68b [Blocklist] Make sure blocklist config is read through VFS
Make sure block-list file is read through VFS so CASFS can be used to
read the configuration to ensure sound caching, and also the path of the
blocklist can be canonicalized via path remapping.
2024-09-26 17:02:10 -07:00
Slava Pestov
c77fae3a2d Basic: Add -fine-grained-timers flag
By default, -stats-output-dir does not collect per-request timers and
counters, because of overhead.
2024-09-23 18:04:25 -04:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Doug Gregor
b597f6bed4 Consolidate get(Opaque|Opened)TypeArchetypeProperties into archetypeProperties() 2024-09-09 13:02:49 -07:00
Augusto Noronha
5f851b664d Merge pull request #76065 from augusto2112/clash-abi-name-demangler
Account for multiple modules when looking up the DeclContext of a type
2024-09-06 14:22:24 -07:00
Alejandro Alonso
71fee06c9a Requestify GTPD::getValueType 2024-09-04 15:13:46 -07:00
Slava Pestov
b9b6bb7b69 AST: Introduce new kind of sugared GenericTypeParamType
This one just stores an identifier instead of a declaration.
2024-09-04 15:13:46 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso
7c85261a77 Add runtime support 2024-09-04 15:13:27 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Slava Pestov
abb8e8feb1 AST: Remove old form of getOpenedExistentialSignature() 2024-09-04 10:42:19 -04:00
Slava Pestov
dbda573e88 AST: Remove OpenedArchetypeType::getSelfInterfaceTypeFromContext() 2024-09-04 10:42:19 -04:00
Slava Pestov
c47f352df7 AST: Use new form of getOpenedExistentialSignature() in GenericEnvironment::forOpenedExistential() 2024-09-04 10:42:18 -04:00
Slava Pestov
3f317a10fc Merge pull request #76216 from slavapestov/existential-signature-rework-part-2
Convert more callers to use new form of ASTContext::getOpenedExistentialSignature()
2024-09-03 23:22:00 -04:00