Commit Graph

93 Commits

Author SHA1 Message Date
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Venkatesh Sriram
38cbdf87a8 Merge pull request #79400 from venkatesh5789/result-builder-initialization
[Compile Time Constant Extraction] Handle cases where variables with attached result builders are initialized without builder syntax
2025-02-24 11:25:59 -08:00
Allan Shortlidge
eb6506a1ad AST: Introduce SemanticAvailabilitySpec.
It wraps an type-checked `AvailabilitySpec`, which guarantees that the spec has
a valid `AvailabilityDomain` associated with it. This will unblock moving
AvailabilitySpec domain resolution from parsing to sema.
2025-02-23 10:53:06 -08:00
Allan Shortlidge
774248fcac ConstExtract: Refactor handling of AvailabilitySpec.
Soon, `AvailabilitySpec` will require that the `AvailabiltyDomain` it contains
be queried using a request that takes the `DeclContext` as input in order to
resolve the parsed domain name to an instance of `AvailabilityDomain`. The
constant extraction pipeline needed a bit of refactoring to thread a
`DeclContext` through to the place where it will be needed to execute the
query.

NFC.
2025-02-17 15:12:50 -08:00
Venkatesh Sriram
2eaaf5193a [Compile Time Constant Extraction] Handle cases where variables with attached result builders are initialized without builder syntax 2025-02-14 10:36:06 -08:00
Allan Shortlidge
670084a9ac AST: Retire PlatformVersionConstraintAvailabilitySpec. 2025-02-12 22:46:58 -08:00
Allan Shortlidge
6daea78ccf AST: Remove AvailabilitySpec.h include from Stmt.h.
Include it where it's actually used instead to improve compile times.
2025-02-11 20:03:01 -08:00
Venkatesh Sriram
a5cc53f356 Merge pull request #78511 from venkatesh5789/null-value-optional-extraction
[Compile Time Constant Extraction] Extract Nil Values for Optionals
2025-01-16 18:43:07 +05:30
Venkatesh Sriram
c6c8526b87 [Compile Time Constant Extraction] Extract Nil Values for Optionals 2025-01-16 12:04:03 +05:30
Venkatesh Sriram
aa498087ac Merge pull request #78462 from venkatesh5789/partial-keypath-extraction
[Compile Time Constant Extraction] Extract Partial Keypath Expressions
2025-01-09 11:11:07 +05:30
Allan Shortlidge
680bb5b05b ConstExtract: Adopt SemanticAvailableAttr more thoroughly. 2025-01-07 07:31:29 -08:00
Venkatesh Sriram
14a5207f48 [Compile Time Constant Extraction] Extract Partial Keypath Expressions 2025-01-07 16:46:05 +05:30
Allan Shortlidge
887bc1124f ConstExtract: Adopt Decl::getSemanticAvailableAttrs(). 2024-12-19 08:40:00 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Venkatesh Sriram
0d9e62e143 Merge pull request #76917 from venkatesh5789/external-conformance-info
[Compile Time Constant Extraction] Add information about where a particular conformance has been defined
2024-10-17 10:19:07 -07:00
Venkatesh Sriram
9ca55fdf89 [Compile Time Constant Extraction] Add information about where a particular conformance has been defined 2024-10-15 15:46:21 -07:00
James Paolantonio
5e1de491b6 [Const extract] Extract static function calls (#76251)
Co-authored-by: James Paolantonio <j_paolantonio@apple.com>
2024-10-10 09:59:20 -04:00
Venkatesh Sriram
f04486db3e [Compile Time Constant Extraction] Extract listed Availability Attributes for buildLimitedAvailability in Result Builders 2024-09-26 14:14:10 -07:00
Venkatesh Sriram
82f85d83c2 Merge pull request #75219 from venkatesh5789/result-builder-extraction
[Compile Time Constant Extraction] Extract Result Builder Expressions
2024-07-24 18:27:17 -07:00
Venkatesh Sriram
4c3439f942 [Compile Time Constant Extraction] Extract Result Builder Expressions 2024-07-24 10:08:24 -07:00
Artem Chikin
3e8e44d34e Merge pull request #74698 from artemcm/ConstExtractConformanceExtractionFix
[Compile Time Constant Extraction] Query nominal type *conformances* to get at the protocols, instead of `getAllProtocols()`.
2024-06-27 09:56:27 -07:00
Venkatesh Sriram
465634cada Merge pull request #74491 from venkatesh5789/interpolated-string-extraction
[Compile Time Constant Extraction] Extract Interpolated String Literals
2024-06-26 10:34:42 -07:00
Artem Chikin
1be5dbba38 [Compile Time Constant Extraction] Ensure macro-expanded declarations are visited in WMO
Resolves rdar://130036855
2024-06-25 14:23:41 -07:00
Artem Chikin
f5f0c0043d [Compile Time Constant Extraction] Query nominal type conformances to get at the protocols, instead of getAllProtocols.
As it stands, for extension macros which add protocol conformances, the list of protocols specified on the macro's 'conformances:' parameter gets added in its entirety to the list of a nominal type's protocols in 'ConformanceLookupTable::addMacroGeneratedProtocols'. Whereas the macro itself, may only add *some* of the specified conformances. This means that `getAllProtocols` may contain a super-set of protocols captured in `getAllConformances`, some of which may not actually be generated by the macro.

This change narrowly fixes ConstExtract to query actual generated conformances. Though, potentially we should make 'ConformanceLookupTable::addMacroGeneratedProtocols' behave in a way that reflects the protocols the macro actually adds the conformances to, instead of the ones it may add conformances to.

Resolves rdar://130316531
2024-06-25 12:29:29 -07:00
Venkatesh Sriram
9820865a80 [Compile Time Constant Extraction] Extract Interpolated String Literals 2024-06-25 11:11:20 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Venkatesh Sriram
a0d62d972e Merge pull request #73718 from venkatesh5789/keypath-extraction
[Compile Time Constant Extraction] Extract KeyPath Expressions
2024-05-23 10:01:36 -07:00
Venkatesh Sriram
6e797f5047 [Compile Time Constant Extraction] Extract KeyPath Expressions 2024-05-22 11:24:48 -07:00
James Paolantonio
b37640800c Remove duplicate hasAttachedPropertyWrapper check (#73456)
Co-authored-by: James Paolantonio <j_paolantonio@apple.com>
2024-05-08 11:35:55 -04:00
artemcm
486654eb58 [Const Extract] Extract property wrapper details even when no default init is present 2024-04-25 11:42:51 -07:00
Apollo Zhu
708fb13c5b Extract decl in macro added extensions 2024-03-18 22:58:17 -07:00
Slava Pestov
37dbd05354 ConstExtract: Update for noncopyable generics (sort of) 2024-03-01 11:05:54 -05: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
Apollo Zhu
9f9b3abeaa [Compile Time Constant Extraction] Extract from macro expansions
Fix logic for @_objcImplementation
2023-12-06 16:08:02 -08:00
Apollo Zhu
a8fd83703b Allow extractConstantsFromMembers on all nominal decls 2023-11-30 18:35:17 -08:00
Zhiyu Zhu/朱智语
6d3017cde3 [Compile Time Constant Extraction] Extract from extensions of types not declared in the same file/module (#70081)
Resolves rdar://118904022
2023-11-29 09:07:52 -08:00
Zhiyu Zhu/朱智语
9d1a92eb72 [Compile Time Constant Extraction] Add @extractConstantsFromMembers (#69944)
Add @extractConstantsFromMembers attribute under ExtractConstantsFromMembers experimental feature flag
2023-11-29 08:49:57 -08:00
Doug Gregor
236418dbf8 Make the "typechecked function body" request more central and resilient
The "typechecked function body" request was defined to type-check a
function body that is known to be present, and not skipped, and would
assert these conditions, requiring its users to check whether a body
was expected. Often, this means that callers would use `getBody()`
instead, which retrieves the underlying value in whatever form it
happens to be, and assume it has been mutated appropriately.

Make the "typechecked function body" request, triggered by
`getTypecheckedBody()`, more resilient and central. A `NULL` result is
now acceptable, signifying that there is no body. Clients will need to
tolerate NULL results.

* When there is no body but should be one, produce an appropriate
error.
* When there shouldn't be a body but is, produce an appropriate error
* Handle skipping of function bodies here, rather than elsewhere.

Over time, we should move clients off of `getBody` and `hasBody`
entirely, and toward `getTypecheckedBody` or some yet-to-be-introduced
forms like `getBodyAsWritten` for the pre-typechecked body.
2023-11-26 09:09:29 -08:00
Artem Chikin
faa9751c37 [Compile Time Constant Extraction] Emit underlying types for typealias types
Resolves rdar://113402135
2023-08-18 10:44:46 -07:00
Pavel Yaskevich
b21e8426a0 [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:16:40 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Artem Chikin
f39d62f65d Merge pull request #67692 from artemcm/ConstExtractPrintTypesOutOfContext
[Compile Time Constant Extraction] Map types with archetypes out of context, before mangling them for printing.
2023-08-03 11:08:58 -07:00
Artem Chikin
8fb4294507 [Compile Time Constant Extraction] Map types with archetypes out of context, before mangling them for printing.
Matching logic in the ASTPrinter. Otherwise we attempt to mangle types with archetypes in them, which cannot be done, and causes the compiler to crash.

Resolves rdar://113039215
2023-08-02 17:37:59 -07:00
Artem Chikin
0ea41efded [Compile Time Constant Extraction] Deprecated extraction of property mangled
names. It can often be more complex than the code can currently handle (e.g.
properties whose types include archetypes), and we
do not have a good motivating use-case to extract them.

Resolves rdar://113039215
2023-08-01 15:52:52 -07:00
Artem Chikin
72ed4e37ff [Compile Time Constant Extraction] Refactor collection of opaque type requirements
To reduce duplication of logic with other parts of the compiler, instead of destructuring the constraint type, write the requirements in the opaque type declaration's generic signature.
2023-06-30 11:02:24 -07:00
Slava Pestov
5ce14265e4 Fix some random compiler warnings 2023-06-29 16:29:10 -04:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Artem Chikin
9a11e048e5 Merge pull request #66639 from artemcm/ConstExtractConformanceInfo
[Compile Time Constant Extraction] Add extraction of all conformances and type aliases of applicable nominal types
2023-06-23 08:35:11 -07:00
Artem Chikin
3f0c0f0553 [Compile Time Constant Extraction] Add extraction of all conformances and type aliases of applicable nominal types
This change adds to the extracted type metadata the following fields:
- Conformances: this is a list of all protocols that the given nominal type conforms to
- associated type aliases: this is a list of all associated types across all conformances that the given nominal type substitutes with concrete types. For a given associated type, we gather:
  - Associated type name
  - Substituted type's fully-qualified name
  - Substituted type's mangled name
  - If the substituted type is opaque:
    - List of conformance requirements of this opaque type
    - List of same-type requirements of this opaque type
2023-06-22 07:13:24 -07:00
Steven Wu
8fb0d5f803 Virtualize swiftconstvalues output
Virtualize swiftconstvalues output so it can be cached inside CAS.
2023-06-12 13:22:10 -07:00