Commit Graph

7976 Commits

Author SHA1 Message Date
Jacob Bandes-Storch
c8b373b03d [Sema] Disallow multiple overrides of the same base declaration 2016-11-21 22:38:07 -08:00
Pavel Yaskevich
965d2d6d87 [QoI] Coerce tuple type elements to RValue before erasure
When trying to convert tuple type to existential look through
it's elements and convert found LValues to RValues (via load)
before applying erasure.

Resolves: <rdar://problem/27575060>.
2016-11-21 00:42:45 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
2e901cb4f9 AST: Clean up PrintOptions a bit 2016-11-19 22:53:53 -08:00
Jacob Bandes-Storch
2fd3aa157a [QoI] Improve diagnostics when all .init candidates are inaccessible 2016-11-19 01:19:27 -08:00
Doug Gregor
7c58b6ba2f Allow generic requirements that augment Self in Swift 3 compatibility mode.
PR #5857 started rejecting generic requirements that adding
constraints directly to 'Self', which means the requirements would be
unsatisfiable by some models. At the time that commit was merged, we
had thought the compiler crashed on all instances of this problem.

It turns out that, with assertions disabled, these protocols would be
accepted and could be used, so downgrade the error to a 'deprecated'
warning in Swift 3 compatibility mode.
2016-11-18 14:51:43 -08:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
Doug Gregor
dc70877465 Merge pull request #5834 from xedin/rdar27464577
[TypeChecker] Don't assume that cast expressions always have sub-expressions
2016-11-18 13:00:01 -08:00
Slava Pestov
a760186505 AST: Remove -enable-experimental-nested-generic-types flag 2016-11-18 00:39:15 -08:00
Doug Gregor
585e065c90 Handle requirement environments with concrete same-type constraints.
It is possible to have requirement environments in which substitution
of the conforming type for Self into the requirement's signature would
result in substituted same-type requirements that no longer involve
type parameters. This triggered an assertion in the construction of
the requiremet environement; instead, just drop the requirement
because it is no longer interesting. Witness matching will simply fail
later one.

With this fix, it now because possible to add generic requirements to
a protocol that were unsatisfiable for certain models. For example,
the following protocol:

    protocol P {
      associatedtype A
      associatedtype B

      func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B
    }

can only be satisfied by conforming types for which Self.A ==
Self.B. SE-0142 will introduce a proper way to add such requirements
onto associated types. This commit makes any such attempt to add
requirements onto "Self" (or its associated types) ill-formed, so we
will reject the protocol P above with a diagnostic such as:

    error: instance method requirement 'f' cannot add constraint
    'Self.A == Self.B' on 'Self'

Fixes rdar://problem/29075927.
2016-11-17 23:53:10 -08:00
Doug Gregor
85296ef1ea Merge pull request #5855 from DougGregor/archetype-builder-typo-correction
[Archetype builder] Cope with typo-corrected nested types slightly better
2016-11-17 22:52:18 -08:00
Doug Gregor
5ba8ea7a83 [Archetype builder] Cope with typo-corrected nested types slightly better.
Fix two issues that cropped up in rdar://problem/29261689:

* We didn't have an ordering between two typo-corrected nested types
  that were corrected to the same name, triggering an assertion, which
  we resolve by ordering based on the original (pre-correction) names.
* In some cases, typo corrections would not be diagnosed because the
  type checker wasn't able to map them to specific uses of that
  type. Introduce a lame fallback case to make sure we get some
  diagnostic---even though the location information is poor.

All of this needs an overhaul, but not today.

Fixes rdar://problem/29261689.
2016-11-17 21:29:10 -08:00
practicalswift
6fa577dfbd [gardening] Fix recently introduced typos. Fix inconsistent headers. 2016-11-17 13:09:02 +01:00
Pavel Yaskevich
351ae5bde9 [TypeChecker] Don't assume that cast expressions always have sub-expressions
When cast expressions (conditional or forced downcasts) are part
of the closure expression with invalid parameters or return type,
they are not going be to folded by PreCheckExpression, which means
that they are not going to have sub-expression (from) set.

Resolves: <rdar://problem/27464577>.
2016-11-16 23:58:03 -08:00
David Farler
ff98e5fd81 Merge pull request #5811 from bitjammer/syntax
Preserve source trivia in the lexer
2016-11-16 11:47:32 -08:00
Doug Gregor
b8b13f2a0d Merge pull request #5788 from xedin/r27249691
[TypeChecker] Disallow solutions with free type variables when finalizing witness match
2016-11-15 22:29:24 -08:00
Mark Lacey
a4a6c0d5e0 Clean-up solver state management for a constraint system.
Make SolverState manage whether the ConstraintSystem it belongs to has a
current SolverState.

Also a couple minor formatting fixes for ternary expressions involving
solverState.
2016-11-15 17:06:20 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
swift-ci
272440340d Merge pull request #5801 from DougGregor/substitution-cleanup 2016-11-15 13:50:58 -08:00
Pavel Yaskevich
ad0b1c7383 [TypeChecker] Disallow solutions with free type variables when finalizing witness match
Disallows solutions containing free type variables on the final step of
witness matching, because that would yield incorrect results when witness
type has free type variables as well.

Resolves: <rdar://problem/27249691>.
2016-11-15 13:43:31 -08:00
Doug Gregor
85ba4fe40f [AST] Narrow TypeSubstitutionMap to SubstitutableType keys.
Type substitution works on a fairly narrow set of types: generic type
parameters (to, e.g., use a generic) and archetypes (to map out of a
generic context). Historically, it was also used with
DependentMemberTypes, but recent refactoring to eliminate witness
markers eliminate that code path.

Therefore, narrow TypeSubstitutionMap's keys to SubstitutableType,
which covers archetypes and generic type parameters. NFC
2016-11-15 11:34:09 -08:00
Mark Lacey
fbbd8346d0 Small control-flow simplifications, NFC.
Simplify some control-flow to reduce indentation and eliminate an
unneeded flag variable.

Also update a comment to match the code that went in with
b5500b8600.
2016-11-15 09:20:40 -08:00
swift-ci
0029ba22f3 Merge pull request #5785 from rudkx/minor-cleanup 2016-11-14 22:57:19 -08:00
Mark Lacey
85f7ddd363 Merge pull request #5783 from rudkx/minor-simplification
Remove extra calls to getRepresentative().
2016-11-14 22:17:14 -08:00
Mark Lacey
8b2bfcb442 Refactor a couple functions out of solveSimplified().
These are both logical bits of code that deserve first-class function status.
2016-11-14 22:14:10 -08:00
Mark Lacey
3ff07ab031 Remove extra calls to getRepresentative().
The calls to simplifyType() already return the representative if it exists.
2016-11-14 21:56:12 -08:00
Doug Gregor
6bfd219e14 [AST] Separate GenericEnvironment's representation from its interface. 2016-11-14 21:44:58 -08:00
swift-ci
62b6d6b0e6 Merge pull request #5782 from DougGregor/conforms-to-protocol-api 2016-11-14 16:25:57 -08:00
Doug Gregor
337c71d246 Merge pull request #5763 from apple/ignore-invalid-ext
[Sema] Don’t crash when typechecking invalid ExtensionDecls
2016-11-14 16:07:52 -08:00
Doug Gregor
e045429471 [Type Checker] Improve interface to TypeChecker::conformsToProtocol().
This function had a weird, pre-ProtocolConformanceRef interface that
returned true when the type conformed to the protocol, then had a
separate indirect return value for the concrete conformance (if there
is one). Refactor this API, and the similar
TypeChecker::containsProtocol(), to produce an optional
ProtocolConformanceRef, which is far more idiomatic and easier to
use. Push ProtocolConformanceRef into a few more places. Should be NFC
2016-11-14 16:00:58 -08:00
Slava Pestov
783012f6d3 Merge pull request #5751 from jtbandes/validation-ignore-unchecked
[Sema] Skip UNCHECKED_EXPRs in ErrorHandlingWalker
2016-11-14 12:50:45 -08:00
Slava Pestov
c6e3846cc8 Merge pull request #5773 from rintaro/sema-typecheckattr-specialized
[Sema] Check existence of GenericSignature before getting GenericParamList from it
2016-11-14 12:50:27 -08:00
Mark Lacey
7eba7aa532 Merge pull request #5720 from xedin/SR-2994
[Diagnostics] Coerce closure arguments to contextual type only if it valid
2016-11-14 11:00:54 -08:00
Rintaro Ishizaki
1b51bc1d6b [Sema] Check existence of GenericSignature before getting GenericParamList from it
Fixes 2 compiler crasher.
2016-11-14 22:01:53 +09:00
Jacob Bandes-Storch
dfea7ee441 [Sema] Skip UNCHECKED_EXPRs in ErrorHandlingWalker
On rare occasions, malformed programs can allow an UNCHECKED_EXPR (e.g. ArrowExpr) to escape type checking. The erroneous expression may have sub-expressions which aren't fully typechecked, so we can't safely visit them.
2016-11-13 14:33:40 -08:00
Jacob Bandes-Storch
bd4511f345 [Sema] Don’t crash when typechecking invalid ExtensionDecls 2016-11-13 11:32:35 -08:00
swift-ci
4e6af651c1 Merge pull request #5707 from rintaro/fixit-missing-arg 2016-11-11 18:06:30 -08:00
Huon Wilson
257142ea2f Merge pull request #5644 from huonw/genericsignature
Store a GenericSignature in GenericEnvironment
2016-11-11 16:16:40 -08:00
Huon Wilson
cc5529f9f4 Run git-clang-format. 2016-11-11 15:02:28 -08:00
Huon Wilson
8e6d4e737d [Sema] Remove redundant GenericSignature from checkExtensionGenericParams. 2016-11-11 15:02:27 -08:00
Huon Wilson
1f446847dd [Parse] Remove redundant GenericSignatures from SIL parsing. 2016-11-11 15:02:27 -08:00
Huon Wilson
fa56e7928d [AST] Remove redundant GenericSignatures.
The GenericSignature is now canonically available through the
GenericEnvironment.
2016-11-11 14:57:04 -08:00
Huon Wilson
1102cf6643 [AST] Store a GenericSignature in GenericEnvironment.
An environment is always associated with a location with a signature, so
having them separate is pointless duplication. This patch also updates
the serialization to round-trip the signature data.
2016-11-11 14:57:03 -08:00
Ben Langmuir
1356ca5165 Merge pull request #5724 from benlangmuir/cc-no-crash-deinit
[code-completion] Fix completion when deinit shows up inside a local context
2016-11-11 13:46:33 -08:00
Rintaro Ishizaki
903242c5fa [Diag] Don't use typed editor placeholder in diagnostics.
Most of command line users are not familiar with <#T##TypeName#> syntax.
2016-11-12 05:00:36 +09:00
Ben Langmuir
fe2c0db53b [code-completion] Fix completion when deinit shows up inside a local context
When braces are mismatched, we can have a deinit inside a function, so
ensure we don't crash in validateDecl.

rdar://problem/28867782
2016-11-11 11:41:08 -08:00
Rintaro Ishizaki
5adc3bf804 [QoI] Add fix-it for missing arguments 2016-11-12 04:29:52 +09:00
Jordan Rose
a7b027df92 Merge pull request #4579 from aleksgapp/sr-2209-access-scope
[SR-2209] Add real AccessScope type.
2016-11-11 11:16:12 -08:00
Pavel Yaskevich
28777a3c7e [Diagnostics] Coerce closure arguments to contextual type only if it is valid
Modify TypeChecker::coerceParameterListToType to always validate and consider only
valid contextual types (contains: no undefined, error, or type variables etc.) for
argument type coercion, such logic prevents erasure of important explicitly specified
type information attached to parameters of the closure expressions being diagnosed.

Resolves: SR-2994.
2016-11-11 10:31:30 -08:00
practicalswift
38351faefc [gardening] Fix recently introduced typos 2016-11-11 18:35:01 +01:00