Commit Graph

15871 Commits

Author SHA1 Message Date
fischertony
6f08216936 Sema: Support where clauses on contextually generic decls 2020-03-05 04:37:12 +03:00
Robert Widmann
0a28307c41 [CS] Use The Full Opened Type When Forming Subscripts
The "opened type" of a subscript reference has all references to Self
immediately substituted out, which destroys the link between Self and
the opened existential type we form for the "fully opened type". This
means, in general, we cannot use this type when rewriting subscript
applies, or we'll miss closing opened existentials.

Use the "fully opened type" everywhere except the AnyObject subscript
path. Then, add an assertion that AnyObject subscripts never involve
opened archetypes that we would have to close.

Resolves SR-11748, rdar://57092093
2020-03-04 17:23:15 -08:00
Alexis Laferrière
2bbebcb180 [Sema] Remove invalid @_spi attributes 2020-03-04 16:43:05 -08:00
Alexis Laferrière
26c6a18345 [Sema] Improve type-checking of the use and exposability of SPIs 2020-03-04 16:43:05 -08:00
Alexis Laferrière
c61cc6fe4e [AST] Add SPI information to public access scopes 2020-03-04 16:42:18 -08:00
Alexis Laferrière
7bd585001a [AST] Intro and use isSPI and getSPIGroups 2020-03-04 16:42:18 -08:00
Holly Borla
516b3e43cd Merge pull request #30195 from hborla/function-builder-crash
[ConstraintSystem] Bail out of applyFunctionBuilderBodyTransform if there is a failure in constraint generation.
2020-03-04 06:52:18 -08:00
omochimetaru
dfd8af154b use for-in 2020-03-04 22:26:07 +09:00
omochimetaru
ed4d8370b6 change paramIdx to local variable 2020-03-04 22:26:07 +09:00
omochimetaru
88e26b44a3 change nextArgIdx to local variable 2020-03-04 22:26:07 +09:00
omochimetaru
34e895c739 remove unnecessary skipClaimedArgs call 2020-03-04 22:26:07 +09:00
omochimetaru
c946548a19 use local variable for temporary loop 2020-03-04 22:26:07 +09:00
omochimetaru
521a8a5d8f remove unused nextArgIdx operation 2020-03-04 22:26:07 +09:00
omochimetaru
14c6155278 use claim for trailing closure 2020-03-04 22:26:03 +09:00
Slava Pestov
a60ffb9e26 Merge pull request #30196 from slavapestov/abi-check-cleanup
AST: Centralize ABI-related deployment target checks
2020-03-04 02:07:52 -05:00
Brent Royal-Gordon
a3e3598b9a Make cross-importing faster
We previously computed cross-imports by comparing N transitive imports against N transitive imports. This is wasteful, because at least one of the two modules in a pair has to actually declare a cross-import overlay for us to discover one, and the vast majority of modules don’t declare any.

This commit makes us instead compare N transitive imports against M transitive imports which are known to declare at least one cross-import overlay. Since N is potentailly in the thousands while M is perhaps in the double digits, this should be good for a substantial time savings.

However, this optimization has made a test of another cross-import performance optimization fail—not because we have regressed on that, but because it skips work the test case expects us to perform. I have XFAILed that test for now.

Fixes <rdar://problem/59538458>.
2020-03-03 21:56:19 -08:00
Holly Borla
24d8aa148f Merge pull request #30185 from hborla/dependent-type-requirement-failure
[ConstraintSystem] Replace dependent member types with holes when the…
2020-03-03 19:55:07 -08:00
Slava Pestov
3904fe83fb AST: Centralize ABI-related deployment target checks
There were a couple of methods in LangOptions and some related ones in
Availability and ASTContext that were added more recently.

Refactor the three older checks to the newer scheme.
2020-03-03 22:49:19 -05:00
Holly Borla
e3239ba5fc [ConstraintSystem] Bail out of applyFunctionBuilderBodyTransform if
there is a failure in constraint generation.
2020-03-03 19:32:06 -08:00
Doug Gregor
12f8b51921 Merge pull request #30189 from DougGregor/function-builders-switch-exhaustive
[Constraint solver] Check switch exhaustiveness in function builders
2020-03-03 18:48:39 -08:00
Hamish Knight
011f4f1584 Requestify SourceFile parsing
Add ParseSourceFileRequest that parses a SourceFile
for its top-level decls.
2020-03-03 15:53:18 -08:00
Holly Borla
fce8738ea8 [ConstraintSystem] Replace dependent member types with holes when the base type
doesn't conform to the associatedtype's protocol (only in diagnostic mode).

This allows the solver to find solutions for more cases involving requirement
failures for dependent member types without special cases across the solver
that check for dependent member types with no type variables.
2020-03-03 15:45:24 -08:00
Doug Gregor
7ee33a920d [Constraint solver] Check switch exhaustiveness in function builders 2020-03-03 13:44:36 -08:00
Doug Gregor
8191aa4924 Merge pull request #30174 from DougGregor/function-builder-switch
[Constraint system] Implement switch support for function builders.
2020-03-03 12:34:08 -08:00
Pavel Yaskevich
f37c9a7f6f Merge pull request #30165 from xedin/rdar-59703585
[Diagnostics] Don't fix partial mismatch for sub-types associated with…
2020-03-03 09:54:04 -08:00
Doug Gregor
ea8d143f64 [Constraint system] Introduce a one-way constraint for a switch subject.
The normal type checking of switch statements checks the switch subject
first, without context, then evaluates the cases. Introduce a one-way
constraint into the type checking of switch statements within function
builders to provide this same behavior. The difference can be observed
in code such as:

    enum E {
      case a
      case b(Int, String?)
    }

    enum E2 {
      case b(Int, String?)
    }

    func getSomeEnumOverloaded(_: Double) -> E { return .a }
    func getSomeEnumOverloaded(_: Int) -> E2 { return .b(0, nil) }

    func f() {
      switch getSomeEnumOverloaded(17) {
      case .a:  // error: no member named "a" in E2
        print("a")
      default:
        print("default")
      }
    }

When the subject expression `getSomeEnumOverloaded(17)` is resolved
without consider cases, it will select the second
`getSomeEnumOverloaded(_:)`, because the literal 17 prefers to be
an `Int`. The type checking of the first case would then fail because E2
does not contain a member named "a".

Prior to this change, the same expression within a function
builder would succeed in type checking, because the lack of case named
"a" within "E2" would make the second getSomeEnumOverloaded() unusable.

Making this code work by considering the cases along with the subject
expression is not unreasonable, and may be the right long term
direction for the language. However, it's a feature that should be
discussed separately, and the semantics should agree between function
builders and normal statements.

Big thanks to John McCall for noting the missing one-way constraint!
2020-03-03 08:51:26 -08:00
Suyash Srijan
13487edd09 [Typechecker] Diagnose key paths with contextual type but no leading dot (#30164) 2020-03-03 12:17:32 +00:00
Pavel Yaskevich
f7b264583d [Diagnostic] Don't fix partial mismatch for sub-types associated with optional conversion
If mismatch detected by `repairFailures` is related to a complex
wrapped value of optional type formed from optional-to-optional
or value-to-optional conversion let's not try to fix it directly
but let `simplifyRestrictedConstraintImpl` record a top-level fix
for more context.

Resolves: rdar://problem/59703585
2020-03-03 00:24:34 -08:00
Robert Widmann
f142eedd52 Merge pull request #30171 from CodaFi/object-permanence
[Sema] Don't Emit @objc Fixits Into Extant Modules
2020-03-02 20:08:36 -08:00
Doug Gregor
4b43573693 [Constraint system] Implement switch support for function builders.
Implement support for switch statements within function builders. Cases can
perform arbitrary pattern matches, e.g.,

    tuplify(true) { c in
      "testSwitchCombined"
      switch e {
      case .a:
        "a"
      case .b(let i, _?), .b(let i, nil):
        i + 17
      }
    }

subject to the normal rules of switch statements. Cases within function
builders cannot, however, include “fallthrough” statements, because those
(like “break” and “continue”) are control flow.

The translation of performed for `switch` statements is similar to that of
`if` statements, using `buildEither(first:)` and `buildEither(second:)` on
the function builder type.

This is the bulk of switch support, tracked by rdar://problem/50426203.
2020-03-02 17:25:25 -08:00
Robert Widmann
a1397a8c60 [Sema] Don't Emit @objc Fixits Into Extant Modules
Overlays are specifically allowed to do magic things that regular Swift
modules are not. In this case, the UIImage and NSImage overlays have
extensions that allow them to conform to `_ExpressibleByImageLiteral`.
This, unfortunately, means that subclassing these classes with the
overlays present is impossible as one must override the required
initializers, but one cannot override these initializers since they are
declared in an extension.

While we cannot correct the overlays without breaking ABI, we can at
least make sure we don't attempt to stick @objc into them when users
have a go at subclassing these classes.

Resolves rdar://59610201
2020-03-02 16:27:06 -08:00
Hamish Knight
39d988da9c [CS] Remove ReturnAllDiscoveredSolutions flag
This is now no longer used.
2020-03-02 14:50:16 -08:00
Hamish Knight
6e616cdef0 [CS] Remove an unused function
This was previously used by CSDiag, which is now
gone.
2020-03-02 14:50:16 -08:00
Pavel Yaskevich
0cd44a83a7 [ConstraintSystem] Don't record general contextual mismatch if there are restrictions present
If there are any conversion restrictions present while trying to repair
failures related to contextual type, let's give `simplifyRestrictedConstraintImpl`
a chance to run and fix the problem.

Resolves: rdar://problem/59773317
2020-03-02 11:07:31 -08:00
Pavel Yaskevich
d5944ffa76 [ConstraintLocator] NFC: Introduce a way to determine whether locator points directly to a specific expression 2020-03-02 10:15:00 -08:00
Pavel Yaskevich
9db7144bbc [CSDiagnostics] Handle try? contextual mismatch directly
It detends on a situation whether try? would get a type inferred
so the mismatch is against a contextual type, or contextual type
would be used as a type of `try?` and fail comparsion with inner
expression type. In either case the mismatch is contextual.
2020-03-02 09:02:56 -08:00
Pavel Yaskevich
d1a11cd1f2 [ConstraintLocator] Add an accessor to check whether locator points directly at try? 2020-03-02 09:02:24 -08:00
Doug Gregor
13b200ddd5 [Constraint system] Generalize saved ASTNode -> solution target mapping.
We are currently only using the “solution targets” map for statement
conditions, but we will need it for more entities soon. Start generalizing
now.
2020-03-02 08:43:55 -08:00
Suyash Srijan
956e918476 [CSSimplify] Move property wrapper fix check after check for conversion restrictions (#30129) 2020-02-28 23:16:32 +00:00
Pavel Yaskevich
389e84fc55 Merge pull request #30115 from LucianoPAlmeida/nfc-abstract-is-stdlib
[NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl
2020-02-28 13:32:32 -08:00
Robert Widmann
d494cc8dcb Merge pull request #30109 from CodaFi/lies-more-lies-and-statistics
[Frontend] Clean Up Usage of UnifiedStatsReporter
2020-02-28 10:24:02 -08:00
Holly Borla
87bb7755c2 Merge pull request #30101 from hborla/dynamic-replacement-type-erasure
[Sema] Implement type erasure for dynamic replacement.
2020-02-28 09:37:33 -08:00
Luciano Almeida
f4b530fb95 [NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl 2020-02-28 07:40:08 -03:00
Pavel Yaskevich
c0b9394c42 Merge pull request #30113 from xedin/rdar-54580247
[CSBindings] Open collection before binding parameter only if origina…
2020-02-28 00:01:27 -08:00
Doug Gregor
3d9f753f87 Merge pull request #30111 from DougGregor/pattern-implicit-some-harder
[Constraint system] Handle implicit "some" patterns implicitly, better.
2020-02-27 20:57:29 -08:00
Slava Pestov
ea9806d490 Merge pull request #30097 from slavapestov/sr-75-super-method
Sema: Diagnose unbound method references on 'super.'
2020-02-27 23:06:33 -05:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Pavel Yaskevich
20fc51d4f4 [CSBindings] Open collection before binding parameter only if original argument type failed
Instead of always opening argument type represented by a collection
without type variables (to support subtyping when element is a labeled tuple),
let's try original type first and if that fails use a slower path with
indirection which attempts `array upcast`. Doing it this way helps to
propagate contextual information faster which fixes a performance regression.

Resolves: rdar://problem/54580247
2020-02-27 16:26:13 -08:00
Doug Gregor
30e8d1791e [Constraint system] Handle implicit "some" patterns implicitly, better.
We have two similar code paths here that should probably be unified. For
now, make sure the more-specific one for pattern matching kicks in first.

Fixes rdar://problem/59838566.
2020-02-27 16:25:02 -08:00
Suyash Srijan
a5241edae9 [MiscDiagnostics] Suppress KVO warning when the property has an explicit setter (#30098) 2020-02-27 22:41:50 +00:00