Commit Graph

7976 Commits

Author SHA1 Message Date
Xi Ge
509a99b71d FixCode: for missing type witnesses with default definitions, avoid inserting stubs. (#8068) 2017-03-14 11:03:14 -07:00
Slava Pestov
1248f8054e Sema: Fix another compiler_crasher regression from associated type where clause work
If a protocol's signature is not valid yet, don't attempt a
conformance check.
2017-03-14 00:10:44 -07:00
Slava Pestov
f0e3459068 AST: Fix compiler_crasher regression from associated type where clause work
New GenericTypeParamDecls should always be created with an
InvalidDepth, to prevent canonicalization before the generic
parameter list has been type checked.
2017-03-14 00:10:43 -07:00
Slava Pestov
b0019ee89d Sema: Fix a warning 2017-03-14 00:10:42 -07:00
Slava Pestov
1bbb9410b2 Merge pull request #8065 from slavapestov/generic-typealias-missing-check
Sema: Actually check generic typealias requirements
2017-03-13 21:55:48 -07:00
Robert Widmann
1367b0cb36 Invalidate default argument exprs if typechecking fails
If typechecking fails, the expression will have unsolved type variables
written into it.  This Crashes The Compiler.

In that case, there’s no reason to keep a tree of dangling references
around.  Detach the initializer expression from the AST, but continue
to typecheck it to see if we can get some useful diagnostics out of it.
2017-03-13 23:27:02 -04:00
Slava Pestov
4a46023d17 Sema: Actually check generic typealias requirements
TypeChecker::applyUnboundGenericArguments() did not call
checkGenericArguments() when applying arguments to a generic
typealias. This would cause bad diagnostics or AST verifier
failures if the arguments did not match the requirements of
the typealias.

Add the missing check and converge the two different code paths
inside this function; the code for generic typealiases was
actually more general, and subsumes the nominal type case
entirely.

Fixes <rdar://problem/29061136>.
2017-03-13 20:04:10 -07:00
Jordan Rose
f12afd2ffa Merge pull request #8010 from KingOfBrian/bugfix/SR-1762-Remove-Final-In-Protocol-Extensions
Remove final in protocol extensions
2017-03-13 16:23:24 -07:00
Slava Pestov
068f3a18da Sema: Fix crash if we try to look up constructors while validating a constructor
addImplicitConstructors() will crash if validateDecl() does not produce
a valid signature for one of the class's constructors because the
constructor is already being validated.

This was triggered during associated type inference in the test case
in the radar.

Fixes <rdar://problem/30751491>.
2017-03-13 01:50:41 -07:00
Slava Pestov
3ab7c7283d Sema: Allow protocol typealiases to witness associated type requirements
When resolving a type witness by lookup, also consider protocol members.

Fixes <rdar://problem/30442622>.
2017-03-13 01:19:45 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Brian King
0770037f6b Only generate a warning for Swift 3 and 4 mode. 2017-03-11 20:34:55 -05:00
Xi Ge
b4cf37bf7d Sema: several improvements on missing switch cases diagnostics. (#8026)
1. Make sure the actions taken by fixits are reflected in diagnostics messages.
2. Issue missing cases diagnostics at the start of the switch statement instead of its end.
3. Use <#code#> instead of <#Code#> in the stub.
2017-03-10 19:32:37 -08:00
swift-ci
6ee6378e5d Merge pull request #8029 from rudkx/more-cs-typemap 2017-03-10 18:42:47 -08:00
Mark Lacey
b592260cdd [Constraint solver] More updates for using the constraint solver type map. 2017-03-10 18:16:09 -08:00
Jordan Rose
c4599d9e1c Merge pull request #8009 from jrose-apple/fix-varying-version-failability
Allow "redeclaring" an initializer or method with non-overlapping availability.
2017-03-10 17:42:27 -08:00
swift-ci
36f465e947 Merge pull request #8027 from rudkx/cache-some-types 2017-03-10 17:15:03 -08:00
swift-ci
2ba4f03d8a Merge pull request #8023 from huonw/tweak 2017-03-10 17:06:39 -08:00
Mark Lacey
3f8e1fec4a [Constraint solver] Cache a the types of a few AST nodes we create.
Another small step toward moving to using the side map for all types in
the constraint solver.
2017-03-10 16:51:03 -08:00
Huon Wilson
a9299802bb Factor out first = true; ... if (first) first = false; else ....
There's an `interleave` function for this: let's use it.
2017-03-10 15:44:12 -08:00
Huon Wilson
731953b879 [Sema] replace std::pair<bool, bool> with something clearer.
TypeChecker::{checkGenericArguments, conformsToProtocol} used booleans
inappropriately.
2017-03-10 14:55:46 -08:00
Joe Groff
a16daf1312 Merge pull request #8020 from jckarter/open-existential-helper
Sema: Add a stdlib-internal _openExistential helper.
2017-03-10 14:06:02 -08:00
Joe Groff
eb40d4303b Sema: Add a stdlib-internal _openExistential helper.
Leverage the "special type-checking semantics" hack to pass an opened existential down to an arbitrary subexpression. Please don't use this.
2017-03-10 13:41:00 -08:00
Alex Hoppen
dd1c661c16 Merge pull request #8015 from ahoppen/isOperator-gardening
[Gardening] Change calls of getName().isOperator() to isOperator()
2017-03-10 21:10:33 +00:00
Xi Ge
555e52206a Sema: fill-protocol-stub fixits should include those missing witnesses that are handled by delayed diagnostics. (#8011) 2017-03-10 11:54:25 -08:00
Jordan Rose
f53831d455 Allow adding/removing 'throws' to methods across Swift versions.
Like the previous commit, but for methods too.
2017-03-10 11:39:35 -08:00
Jordan Rose
d5a18da8de Allow "redeclaring" an initializer with non-overlapping availability.
This allows a library to "fix" an initializer that should have been
failable or non-failable by gating the change on the user's version of
Swift. Failability (and whether or not the initializer throws) is
something that doesn't change the "overload signature", so normally
the compiler would call this an invalid redeclaration. But since only
one version can be active at a time based on the client context, there
won't be a problem in practice.

https://bugs.swift.org/browse/SR-4171 / rdar://problem/30470854

I realized in the process of doing this that methods may also have
mismatched 'throws', and we should allow that as well. Next commit.
2017-03-10 11:31:11 -08:00
Brian King
1ab9e451e5 Remove the final attribute instead of invalidating it to ensure that child decls pass the ASTVerifier 2017-03-10 14:14:51 -05:00
Alex Hoppen
1b7055db5a [Gardening] Change calls of getName().isOperator() to isOperator() 2017-03-10 09:06:20 +00:00
Doug Gregor
790cf48955 [Type checker] Always build conformance access paths in debug mode.
As a sanity check, build conformance access paths for conformance
checks of (non-existential) archetypes to protocols.
2017-03-09 21:57:54 -08:00
Huon Wilson
5d89786031 [Sema] Feed protocol where clauses into the places that need to reason about them. 2017-03-09 16:23:31 -08:00
Jordan Rose
3e45121b59 Fix accidental use of a pointer as a boolean.
This argument treated the pointer value as an "allow invalid" flag,
meaning the search could turn up a 'dynamic' attribute that was
already marked invalid. In practice this will probably affect absolutely
no one, but the old code was still wrong.
2017-03-09 14:09:19 -08:00
Xi Ge
69ba7f3d35 Sema: clean some unnecessary delayed diagnostics emits.. (#8001) 2017-03-09 12:58:14 -08:00
Brian King
29c1fc472b Generate an error message on protocol extensions with the final attribute. 2017-03-09 14:18:39 -05:00
Slava Pestov
d73bb452ec Sema: Fix 'super' method calls inside local generic functions
It is generally useful to allow 'super' method calls inside a
closure, so you can have overrides that do things like:

  override func foo() {
    doSomething { super.foo() }
  }

However this didn't work if the closure was a local generic
function because we didn't map the 'super' type into the
right generic context.
2017-03-08 20:10:58 -08:00
Slava Pestov
e62c238bc9 AST: Remove unused overload of GenericSignature::getSubstitutions() 2017-03-08 13:54:31 -08:00
Slava Pestov
46600b5f1a Sema: Remove gatherAllSubstitutions() usage 2017-03-08 13:54:30 -08:00
Slava Pestov
df81e51f36 AST: Add TypeBase::getRootGenericParam() utility method 2017-03-08 13:54:29 -08:00
Xi Ge
b5256f53b2 Sema: introduce a language option flag, DiagnosticsEditorMode. (#7982)
SourceKit always sets it positively. This may lead to more aggressive fixits however
less informative messages. We currently use the flag only for filling protocol stubs.
2017-03-08 12:46:02 -08:00
Slava Pestov
0dc16d8c1a Merge pull request #7969 from slavapestov/subst-cleanup
More SubstitutionList => SubstitutionMap cleanups
2017-03-07 18:28:11 -08:00
Xi Ge
b4322967eb Sema: Fix a container-overflow issue found by asan. rdar://30901119 2017-03-07 16:43:49 -08:00
Slava Pestov
c040c71ea9 AST: Remove some unnecessary SubstitutionList copies
ASTContext::getSpecializedConformance() already copies the
substitutions, so remove some AllocateCopy() calls.

Also, add a new overload taking a SubstitutionMap instead.
This allows removing some gatherAllSubstitutions() calls,
which have an allocation inside them.

Finally, remove the now-unused ModuleDecl parameter from
ProtocolConformance::subst() and make it public.
2017-03-07 15:59:05 -08:00
Xi Ge
de6c375c52 Sema: replace a suspicious constructor call. rdar://30901119 2017-03-07 13:36:14 -08:00
swift-ci
fa4a196fe0 Merge pull request #7956 from DougGregor/conformance-access-path 2017-03-07 10:21:37 -08:00
Doug Gregor
202bc7eeea [AST] Introduce GenericSignature::getConformanceAccessPath().
Introduce an API that determines the "conformance access path" that
one would follow to find the conformance of a given type parameter
(e.g., T.Iterator.Element) to a given protocol (e.g., Equatable). A
conformance access path starts at one of the explicit requirements
of that generic signature and then proceeds through zero or more
protocol-supplied requirements. For example, given this function:

  func f<C: Collection>(_: C) { }

The conformance access path for "C.Iterator: IteratorProtocol" is

  (C, Collection) -> (Self, Sequence) -> (Self.Iterator, IteratorProtocol)

because one starts with the explicit requirement "C: Collection", goes
to the inherited protocol requirement (the "Self" in Collection
conforms to Sequence) and then a requirement on the associated type
(Self.Iterator in Sequence conforms to IteratorProtocol).

This is all scaffolding now; it's intended to be used by IRGen (to
find the witness tables it needs) and SubstitutionMap (to dig out
conformances during substitution).
2017-03-07 09:25:43 -08:00
Doug Gregor
cd93126b4f [GSB] Teach requirement inference to use SubstitutionMaps.
The ad hoc substitution functions here were really odd; use
SubstitutionMap directly, and pass it through to
GenericSignatureBuilder::addRequirement().
2017-03-07 09:09:49 -08:00
Xi Ge
5d2cd20051 Sema/FixCode: Introducing a wrapper for ConformanceChecker to fix missing stubs for multiple protocols in a single fixit invocation. (#7937) 2017-03-06 16:37:43 -08:00
Slava Pestov
80e3cbab08 Sema: Fix 'super' calls from methods returning 'Self'
We have a quirk where TypeBase::getSuperclass() on DynamicSelfType
returns the underlying class type, and not the superclass of the
underlying class type. As a result, we would emit a SuperRefExpr
whose type was the type of 'self' and not the type of 'super'.

Fixes <rdar://problem/30853768>.
2017-03-04 16:37:39 -08:00
Hugh Bellamy
5a6867adc4 Merge pull request #7889 from hughbe/unreachable-030317
Update unreachable control path annotations
2017-03-04 09:59:30 +07:00
Joe Groff
fe5b1f16b0 Merge pull request #7901 from jckarter/no-bridging-constraints-without-bridging
Sema: Assert that bridging constraints aren't formed when ObjC interop is disabled.
2017-03-03 14:55:54 -08:00