Commit Graph

566 Commits

Author SHA1 Message Date
Slava Pestov
ee56292808 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-24 02:35:21 -05:00
Slava Pestov
35b7e9f245 Merge pull request #5872 from rintaro/sema-fold-arrowexpr
Handle 'P1 & P2 -> P3 & P4' expression.
2016-11-23 22:19:18 -05:00
Rintaro Ishizaki
a1760161c5 [Parse] Don't parse 'throws' or 'rethrows' as identifiers
It seems there is no reason to accept them.
Why we want to accept `class C<throws> { ... }`?
2016-11-24 10:55:24 +09:00
Rintaro Ishizaki
8d4ed3219e [Sema] Recusively preCheckExpression() for folded sequence expression
Since 'try' or '=' can be folded with type expression at the same time,
Shallow simplifyTypeExpr() results '->' being escaped from TypeChecker.

For instance:
  try () -> Int
Used to crash the compiler.

Also, never return nullptr for ArrowExpr. `1 -> Int` is invalid anyway.
Instead of leave ArrowExpr as is, construct ErrorTypeRepr for '1' part.
2016-11-24 10:46:36 +09: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
Jacob Bandes-Storch
48a1782246 [AST] Don’t treat missing arguments as a single () argument (#5856) 2016-11-18 13:22:58 -08:00
Rintaro Ishizaki
887fb3750a [Parse] Fix range containment problem in statement condition
For constructing the dummy expression for missing initializer,
use the end location of the pattern instead of the location of the
current token.

Previous behavior used to build AST like:

  { if let x [eof]
       |---|       Pattern range
             |---| Dummy introducer range
    |------------| IfStmt range
  |--------|       BraceStmt range

Now:

  { if let x [eof]
       |---|       Pattern range
           |       Dummy introducer range
    |------|       IfStmt range
  |--------|       BraceStmt range
2016-11-16 10:30:15 +09: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
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
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
Robert Widmann
75d28e12a7 Precedence group declarations are only valid at file scope. 2016-11-13 13:01:58 -05:00
Doug Gregor
3205b8a6c4 Fix ad hoc substitution lists to not include derived type substitutions. 2016-11-08 16:11:29 -08:00
Doug Gregor
00c98efcd7 Revert "[Type checker] Recurse into statements when cleaning type variables."
This reverts commit 45db3e3b89.
2016-11-06 22:31:08 -08:00
Doug Gregor
f19c4af050 Revert "[Type checker] Recurse into statements when cleaning type variables, harder."
This reverts commit 01913beba0.
2016-11-06 22:30:54 -08:00
Doug Gregor
01913beba0 [Type checker] Recurse into statements when cleaning type variables, harder.
Resolved crasher #28474, which is failing to crash reliably on CI. Just fix it.
2016-11-06 22:08:49 -08:00
Doug Gregor
45db3e3b89 [Type checker] Recurse into statements when cleaning type variables.
Resolves two crashes, one of which (28470) is affecting the buildbots
but not my local builds.
2016-11-06 21:53:53 -08:00
Doug Gregor
f168e7270c [Type checker] Use DependentMemberType instead of type variables for nested types.
In the constraint solver, we've traditionally modeled nested type via
a "type member" constraint of the form

  $T1 = $T0.NameOfTypeMember

and treated $T1 as a type variable. While the solver did generally try
to avoid attempting bindings for $T1 (it would wait until $T0 was
bound, which solves the constraint), on occasion we would get weird
behavior because the solver did try to bind the type
variable.

With this commit, model nested types via DependentMemberType, the same
way we handle (e.g.) the nested type of a generic type parameter. This
solution maintains more information (e.g., we know specifically which
associated type we're referring to), fits in better with the type
system (we know how to deal with dependent members throughout the type
checker, AST, and so on), and is easier to reason able.

This change is a performance optimization for the type checker for a
few reasons. First, it reduces the number of type variables we need to
deal with significantly (we create half as many type variables while
type checking the standard library), and the solver scales poorly with
the number of type variables because it visits all of the
as-yet-unbound type variables at each solving step. Second, it
eliminates a number of redundant by-name lookups in cases where we
already know which associated type we want.

Overall, this change provides a 25% speedup when type-checking the
standard library.
2016-11-05 23:20:28 -07:00
Mark Lacey
18c809d1d4 Fix crash in member lookup when base type contains type variables.
We were crashing during performTypoCorrection if the base type contained
type variables.

rdar://problem/28387684
2016-11-02 21:12:47 -07:00
Doug Gregor
852cda6c75 [Conformance checking] Factor requirement environment into its own type.
Rather than computing the requirement environment as a tuple of
(generic signature, generic environment, substitution map),
encapsulate the result in a new RequirementEnvironment
class. Moreover, create a RequirementEnvironment once and re-use it
when matching each of the witnesses, because the environment itself
doesn't change---only the substitutions do. This saves us some work
when there are multiple potential witnesses (which is common).
2016-10-31 14:11:58 -07:00
Doug Gregor
4cc41e5e64 [Constraint solver] Perform the "occurs" check properly.
We've been performing the "occurs" check when computing potential
bindings for type variables, but we weren't actually performing the
check for bindings that *must* occur. Perform the occurs check before
binding type variables, which fixes a few crashers and is far more principled.

Note that this obviates the need for tracking the type variables we've
substituted in simplifyType(), so simplify that as well.

Fixes rdar://problem/27879334 / SR-2351.
2016-10-25 13:32:06 -07:00
swift-ci
5877db3b6b Merge pull request #5099 from rintaro/rangle-location 2016-10-24 00:16:42 -07:00
Rintaro Ishizaki
31245aaa1a [Sema] Check hasResult() before getResult() from ReturnStmt (#5362)
Fixes compiler_crashers/28390-swift-expr-walk.swift
2016-10-20 08:18:36 +09:00
Rintaro Ishizaki
2cd25c8b5e Merge pull request #5194 from rintaro/parselist-earlybailout
[Parse] Improve error handling in parseList
2016-10-14 23:22:12 +09:00
Doug Gregor
c2b9759cd3 Simplify ConstraintSystem::getFixedTypeRecursive and use it consistently.
We had a few places that were performing ad hoc variants of
ConstraintSystem::getFixedTypeRecursive(); simplify it's interface so
we can use it everywhere consistently. Fixes rdar://problem/27261929.
2016-10-11 17:08:52 -07:00
Rintaro Ishizaki
1584602b8d Update an crasher test not to use -verify 2016-10-09 22:24:42 +09:00
Rintaro Ishizaki
f70d2d9e1c [Parse] Skip ahead if seeing any error while parsing list.
If we found any error in a list, in most cases, we cannot expect that the
following tokens could construct a valid element. Skip them, instead of trying
to parse them as the next element. This significally reduces bogus diagnostics.

Bailout if seeing tok::eof or token that can never start a element, after
parsing an element. This silences superfluous "expected ',' separator" error,
or misleading expected declaration error. What we should emit is
"expected ')' in expression list, or "expected '}' in struct".
2016-10-09 04:05:07 +09:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Slava Pestov
7069fbc9be Sema: Remove unnecessary error path in generic signature validation
The idea here is that if a generic signature has invalid requirements,
we would drop all the requirements and build a new set of archetypes
without requirements.

When this logic was added, it fixed 700 compiler_crashers:

<c258f991f6>

Nowadays it appears that all the underlying issues were solved, so
removing this error path actually fixed two crashers and improved
a couple of diagnostics.
2016-10-04 21:47:53 -04:00
Rintaro Ishizaki
056aed8fd3 [Parser] Fix right angle location in erroneous parameter list
If '>' could not be found, the parser should return the location of the
last token parsed, instead of the current token.
Previously, it may causes ASTVerifier error "child source range not contained
within its parent" in some cases.
2016-10-03 18:54:46 +09:00
Slava Pestov
581c99ba61 Resolve some crashers 2016-10-03 00:39:50 -04:00
Slava Pestov
639bc460e8 Parser: Fix a case where we emit multiple in-flight diagnostics 2016-10-02 21:17:43 -04:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
Slava Pestov
ced715cb46 Sema: Fix crash when attempting to diagnose a contextual conversion of an ambiguous expression
The fixits call back into the type checker via typeCheckCheckedCast(),
which sets up a new constraint system. As a result we would hit
assertions by introducing type variables from a previous "generation".

It seems that if we bail out of this code path altogether, we get a
better diagnostic -- in the provided test, it complains about an
ambiguous member to '.value', rather than not being able to convert
_? to V?.

Fixes <https://bugs.swift.org/browse/SR-2592>.
2016-09-19 17:53:05 -07:00
Slava Pestov
0c30979f47 Resolve some crashers 2016-09-06 11:52:25 -07:00
swift-ci
05e0cb65fe Merge pull request #4471 from rudkx/remove-assert 2016-08-23 23:35:05 -07:00
Mark Lacey
dc7d433a40 Remove an overzealous assert.
When we are able to type check an expression this assert is fine,
although of little value. In the context of failed type checks, though,
it can be actively harmful.

The issue is that we can attempt to solve smaller parts of the
constraint system and assign contextual types (e.g. for the arguments of
a function) despite not being able to drill into members.

Some of the diagnostics we emit in these cases are not terribly useful,
and I've opened rdar://problem/27982012 with one example.

Resolves:
  rdar://problem/25812474
  rdar://problem/26589865
  rdar://problem/27974638
2016-08-23 21:58:29 -07:00
SpringsUp
f9af1257ef Tighter type-checking of enums with synthesized RawRepresentable
conformance
Fixes SR-2134
2016-08-22 22:49:48 +02:00
Slava Pestov
47898c5962 These tests no longer require asserts to be enabled
Review feedback from @jrose-apple.
2016-08-05 16:26:01 -07:00
Slava Pestov
22aa032285 Sema: Clean up SE-0036 diagnostic a bit
Suggest a fix-it for unqualified references to all static members
from instance context, not just enum elements.

Also, fix a small problem with the fix-it for replacing protocol
names with 'Self' inside extension bodies -- we didn't handle nested
functions properly.
2016-08-05 14:27:16 -07:00
Slava Pestov
75bd88968b SILGen: Allow extensions to define designated initializers of generic types
Previously, if a generic type had a stored property with
a generic type and an initializer expression, we would
emit the expression directly in the body of each designated
initializer.

This is a problem if the designated initializer is defined
within an extension (even in the same source file), because
extensions have a different set of generic parameters and
archetypes.

Also, we've had bugs in the past where emitting an
expression multiple times didn't work properly. While these
might currently all be fixed, this is a tricky case to test
and it would be best to avoid it.

Fix both problems by emitting the initializer expression
inside its own function at the SIL level, and call the
initializer function from each designated initializer.

I'm using the existing 'variable initializer' mangling for this;
it doesn't seem to be used for anything else right now.

Currently, the default memberwise initializer does not use
this, because the machinery for emitting it is somewhat
duplicated and separate from the initializer expressions in
user-defined constructors. I'll clean this up in an upcoming
patch.

Fixes <https://bugs.swift.org/browse/SR-488>.
2016-08-03 01:03:08 -07:00
Chris Lattner
ee52ecccf4 Validation tests shouldn't check for diagnostics. 2016-07-31 16:58:07 -07:00
Joe Groff
c748ba6c12 Merge pull request #3870 from jckarter/no-bridged-default-literal-types
Sema: Don't try bridged classes as default literal types.
2016-07-29 22:16:53 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Joe Groff
11f03cd8b5 Sema: Don't try bridged classes as default literal types.
One last bit of SE-0072. We shouldn't fall back to bridged classes in the absence of type context for literals anymore. By itself, this kind of hoses the use of literals with NS types, but I think we can get most of the QoI back with overlay changes I plan to propose following this.
2016-07-29 15:18:31 -07:00
Slava Pestov
9a32575cbf Merge pull request #3738 from slavapestov/remove-protocol-typealias-flag
Remove -enable-protocol-typealiases staging flag
2016-07-26 11:41:49 -07:00
David Farler
4a57e647e6 Merge pull request #3762 from bitjammer/se-0081-diagnostic-and-crashes
[SE-0081] Warn on deprecated where clause inside angle brackets
2016-07-26 09:09:30 -07:00
Doug Gregor
5cce5c4d1d [Parser] Refactor parsing of calls and call-like expressions.
Rather than parsing the call arguments (or similar, e.g., subscript)
as a parenthesized expression or tuple, then later reworking that
ParenExpr/TupleExpr if a trailing closure comes along, then digging
through that ParenExpr/TupleExpr to pull out the arguments and
trailing closure... just parse the expression list and trailing
closure together, then directly form the appropriate AST node with
arguments/labels/label locations/trailing closure.

Fixes rdar://problem/19804707, which is an issue where trailing
closures weren't working with unresolved member expressions (e.g.,
".foo {... }"), and is a stepping-stone to SE-0111.
2016-07-26 08:40:11 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00