Commit Graph

1901 Commits

Author SHA1 Message Date
Slava Pestov
fec6c06240 AST: TupleType::get() asserts if pack expansion type is followed by an unlabeled element 2022-10-16 21:37:24 -04:00
Slava Pestov
d9cf85d72a AST: Relax an invariant in PackExpansionType::get()
The expression type checker replaces type variables with UnresolvedType
and PlaceholderType sometimes, so allow them to appear here.
2022-10-16 21:37:24 -04:00
Hamish Knight
6aa44a1754 [AST] Remove @_typeSequence attribute
This is no longer needed now that we have the
ellipsis spelling.
2022-10-14 15:40:13 +01:00
Hamish Knight
b645e63ce5 [AST] NFC: Refactor GenericTypeParamDecl construction
Add distinct overloads for the parser,
deserialization and code synthesis.
2022-10-14 15:40:12 +01:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Pavel Yaskevich
d1ff79eef7 [ASTContext] Add {Async}IteratorProtocol::next to list of known decls 2022-09-14 11:35:27 -07:00
Slava Pestov
1edb9a4ca9 AST: Add some assertions to PackType::get() 2022-09-10 00:26:43 -04:00
Slava Pestov
c1b8690401 AST: Introduce special Builtin.TheTupleType singleton 2022-09-10 00:26:42 -04:00
Artem Chikin
070540f99a Merge pull request #60942 from artemcm/AttemptScannerFailDianostics
[Dependency Scanner] Diagnose failure to find a module
2022-09-08 09:01:03 -07:00
Artem Chikin
6da780e272 [Dependency Scanner] Diagnose failure to find a module
And produce a dependency path from the missing dependency to the main module being scanned.
2022-09-07 15:56:44 -07:00
Allan Shortlidge
bbf189c8ab AST: Make the versioned variants of #if canImport() more reliable and consistent.
Previously, when evaluating a `#if canImport(Module, _version: 42)` directive the compiler could diagnose and ignore the directive under the following conditions:

- The associated binary module is corrupt/bogus.
- The .tbd for an underlying Clang module is missing a current-version field.

This behavior is surprising when there is a valid `.swiftinterface` available and it only becomes apparent when building against an SDK with an old enough version of the module that the version in the `.swiftinterface` is too low, making this failure easy to miss. Some modules have different versioning systems for their Swift and Clang modules and it can also be intentional for a distributed binary `.swiftmodule` to contain bogus data (to force the compiler to recompile the `.swiftinterface`) so we need to handle both of these cases gracefully and predictably.

Now the compiler will enumerate all module loaders, ask each of them to attempt to parse the module version and then consistently use the parsed version from a single source. The `.swiftinterface` is preferred if present, then the binary module if present, and then finally the `.tbd`. The `.tbd` is still always used exclusively for the `_underlyingVersion` variant of `canImport()`.

Resolves rdar://88723492
2022-09-07 14:18:05 -07:00
Marina Azevedo
68687a693f [Diagnostics] Update existential type error message for clarity
Rework solution

to be squashed
2022-09-05 13:17:21 -03:00
Slava Pestov
007fe96aaf AST: Don't build useless inherited conformances 2022-08-29 21:57:01 -04:00
Slava Pestov
6549e0e168 AST: Introduce representation for pack conformances 2022-08-23 21:07:30 -04:00
Slava Pestov
22dc9882b0 AST: Stub out ASTContext::getOpenedElementSignature() 2022-08-23 11:12:01 -04:00
Slava Pestov
7a16b0275b AST: Allow one-element tuple types to be constructed
These will never appear in the source language, but can arise
after substitution when the original type is a tuple type with
a pack expansion type.

Two examples:
- original type: (Int, T...), substitution T := {}
- original type: (T...), substitution T := {Int}

We need to model these correctly to maintain invariants.

Callers that previously used to rely on TupleType::get()
returning a ParenType now explicitly check for the one-element
case instead.
2022-08-23 11:12:00 -04:00
Slava Pestov
ae37591c06 AST: Add a count type field to PackExpansionType
Even if we can't spell them in source, we want to model expansions where
the pattern does not depend on any pack type parameters, eg

    func f<C...: Collection>(_ c: C...) {
      let x = (c.count...)
    }

Here, the type of 'x' is notionally 'Int * C.count'.
2022-08-23 11:12:00 -04:00
Egor Zhdan
e3a321721d [cxx-interop] Synthesize conformances to CxxSequence
This makes ClangImporter automatically conform C++ sequence types to `Cxx.CxxSequence` protocol.

We consider a C++ type to be a sequence type if it defines `begin()` & `end()` methods that return iterators of the same type which conforms to `UnsafeCxxInputIterator`.
2022-08-17 16:06:37 +01:00
Slava Pestov
a091425ea1 AST: GenericEnvironment::forOpenedExistential() uniques the environment 2022-08-15 17:55:30 -04:00
Slava Pestov
b36f37cc72 Serialization: Preserve identity of opened generic environments
We used to create a new environment for each opened archetype, which is
incorrect when deserializing a nested type of another opened archetype.
2022-08-15 13:59:12 -04:00
Slava Pestov
7a970367fd AST: Rename GenericEnvironment::Kind::Normal to ::Primary, ::getIncomplete() to ::forPrimary() 2022-08-15 13:59:12 -04:00
Slava Pestov
7d8f3e6b63 AST: Change return type of Requirement::subst() to Requirement
Instead of returning None, let callers check hasError() if they need to.

Fixes rdar://problem/98565072.
2022-08-12 14:03:57 -04:00
Slava Pestov
87871d7347 AST: Rename getOpenedArchetypeSignature() to getOpenedExistentialSignature() 2022-08-10 23:44:36 -04:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
Slava Pestov
d222ac5f6e Sema: New syntax for @opened archetypes in textual SIL
The old syntax was

    @opened("UUID") constraintType

Where constraintType was the right hand side of a conformance requirement.

This would always create an archetype where the interface type was `Self`,
so it couldn't cope with member types of opened existential types.

Member types of opened existential types is now a thing with SE-0309, so
this lack of support prevented writing SIL test cases using this feature.

The new syntax is

    @opened("UUID", constraintType) interfaceType

The interfaceType is a type parameter rooted in an implicit `Self`
generic parameter, which is understood to be the underlying type of the
existential.

Fixes rdar://problem/93771238.
2022-08-07 19:03:46 -04:00
Slava Pestov
63307760e4 AST: The underlying conformance of a specialized conformance is always a root conformance 2022-08-03 00:28:43 -04:00
Slava Pestov
10f0d27c4a AST: Collapse multiple levels of inherited conformance 2022-08-03 00:28:43 -04:00
Hamish Knight
9da53193da [AST] Remove ParameterTypeFlags from ParenType and TupleType
The last clients that relied on stashing parameter
type flags on these types are now gone.
2022-08-02 13:56:32 +01:00
Hamish Knight
6e51841d14 [AST] Enforce that composeTuple drops parameter flags
Callers may either assert that the parameter flags
are empty, or ask for them to be dropped.
2022-08-02 13:56:31 +01:00
Slava Pestov
affc39a452 AST: Use QueryOverrideSubs/LookUpConformanceInOverrideSubs in getOverrideGenericSignature() 2022-07-29 13:33:14 -04:00
Slava Pestov
5ad096f7ee AST: Remove special handling of protocols in getOverrideGenericSignature() 2022-07-29 12:01:26 -04:00
Slava Pestov
1d87bc207c AST: Simplify getOverrideGenericSignature() 2022-07-29 12:01:05 -04:00
Slava Pestov
4e658b8217 AST: Refactor getOverrideGenericSignature() to use a more correct uniquing key 2022-07-29 12:01:05 -04:00
Egor Zhdan
d85d2e9e75 [cxx-interop] Synthesize conformances to UnsafeCxxInputIterator
This teaches ClangImporter to synthesize conformances of C++ iterator types to `UnsafeCxxInputIterator` protocol from the `Cxx` module.

We consider a C++ type to be an iterator if it defines a subtype (usually a typedef or a using decl) called `iterator_category` that inherits from `std::input_iterator_tag`.

rdar://96235368
2022-07-20 11:44:25 +01:00
Michael Gottesman
198b974622 Merge pull request #59859 from gottesmm/pr-276c4e4220a25490659a285e8b94a36bd28ffede
[no-implicit-copy] Rename SILMoveOnlyType -> SILMoveOnlyWrappedType.
2022-07-01 23:17:43 -07:00
Michael Gottesman
8f3fe63fed [no-implicit-copy] Rename SILMoveOnlyType -> SILMoveOnlyWrappedType.
Since I am beginning to prepare for adding real move only types to the language,
I am renaming everything that has to do with copyable types "move only wrapped"
values instead of move only. The hope is this reduces/prevents any confusion in
between the two.
2022-07-01 17:26:13 -07:00
swift-ci
9aa2de4137 Merge pull request #41083 from kavon/inconvenienced-actors
[SE-327] Remove need for `convenience` for delegating initializers of an actor.
2022-06-30 14:56:32 -07:00
Kavon Farvardin
cf637c271b break request-evaluator cycle when synthesizing actor init
When synthesizing the default initializer for an actor, we'd sometimes hit
a cycle when that initializer needs to chain to NSObject.init. The cycle
only happens because we ask if the initializer we're trying to synthesize
is a convenience init in a scenario which only applies to non-final classes.

Since all actors are effectively "final" classes, it's valid to workaround the
cycle by only asking that initializer question for non-final classes, thus
breaking the cycle.
2022-06-27 16:01:47 -07:00
Holly Borla
0053526c5d Merge pull request #41909 from hborla/existential-any-anyobject
[Sema] Use `ExistentialType` for `Any` and `AnyObject`.
2022-06-24 20:51:50 -07:00
Hamish Knight
2145ded730 [AST] NFC: Remove unused field
This doesn't appear to have ever been used.
2022-06-23 17:06:22 +01:00
Robert Widmann
ce4afc7e4d Recurse Into Existential Types With Generic Structure
Before the introduction of parameterized existential types, there
was no generic structure under these types. Now that there is, we'll
need to recurse into them to pick up any latent generic types
and lower them appropriately.

rdar://94320481
2022-06-18 12:36:50 -06:00
Holly Borla
429488f6c9 [Sema] Use ExistentialType for Any and AnyObject. 2022-06-17 18:29:15 -07:00
Becca Royal-Gordon
a4a6d0943a Merge pull request #59479 from beccadax/you-completion-me
Allow @objc protocols to declare async alternatives
2022-06-17 09:58:44 -07:00
Becca Royal-Gordon
9b5f89963b [NFC] Serialize ObjC selectors for protocols
The ObjCMethodLookupTable for protocols was not being serialized and rebuilt on load, so NominalTypeDecl::lookupDirect() on selectors was not working correctly for deserialized types. Correct this oversight.
2022-06-16 14:07:49 -07:00
Med Ismail Bennani
ee87094e9e [ASTContext] Fix unordered member initialization warning (NFC)
This patch should fix a warning triggered because `PreModuleImportCallback`
is initialized before other `ASTContext` members.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-06-16 12:47:19 -07:00
Med Ismail Bennani
1328dca30f [AST] Add mechanism to notify module loading to other clients
This patch adds an optional callback function member to the AST Context.
The callback gets invoked when a new module (or overlay module) gets
loaded.

This can be used for instance by other clients, such as lldb, to perform
actions when a module gets loaded, like showing progress to the end-user.

rdar://94165195

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-06-15 15:09:55 -07:00
Med Ismail Bennani
21c390f46f Revert "[AST] Add mechanism to notify module loading to other clients"
This reverts commit 38146fc601.
2022-06-15 14:47:25 -07:00
Med Ismail Bennani
38146fc601 [AST] Add mechanism to notify module loading to other clients
This patch adds an optional callback function member to the AST Context.
The callback gets invoked when a new module (or overlay module) gets
loaded.

This can be used for instance by other clients, such as lldb, to perform
actions when a module gets loaded, like showing progress to the end-user.

rdar://94165195

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-06-15 13:19:25 -07:00