Commit Graph

731 Commits

Author SHA1 Message Date
Slava Pestov
4ba00a0c06 AST: Remove FuncDecl::getDynamicSelf() and getDynamicSelfInterface() 2016-12-01 20:17:58 -08:00
Doug Gregor
46e6a38e50 Mark three crashers as resolved 2016-12-01 15:25:43 -08:00
Slava Pestov
2ff9994313 Sema: Improve circularity checks
The previous patches regressed a test where we used to diagnose
(poorly) a circular associated type, like so:

  associatedtype e: e

With the error "inheritance from non-protocol, non-class type 'e'".

This error went away, because we end up not setting the interface
type of the associated type early enough. Instead, we return an
ErrorType from resolveTypeInContext() and diagnose nothing.

With this patch, emit a diagnostic at the point where the ErrorType
first appears.

Also, remove the isRecursive() bit from AssociatedTypeDecl, and
remove isBeingTypeChecked() which duplicates a bit with the same
name in Decl.
2016-12-01 13:00:19 -08:00
Doug Gregor
589b469484 [AST] Extend a hack to work around broken circular inheritance checking.
Extending this hack recovers a regression in a previously-fixed
compiler crasher (#26725), and fixes two more compiler crashers. So,
despite it's utter lack of principle, it's progress.
2016-11-30 15:44:14 -08:00
Slava Pestov
0f7a455d7d AST: Don't call setType() on AbstractFunctionDecls and EnumElementDecls 2016-11-29 03:05:33 -07:00
Slava Pestov
8272fc1530 AST: Assert if getType() called on AbstractFunctionDecl or EnumElementDecl
These can contain PolymorphicFunctionTypes, and should no longer be
accessed.
2016-11-29 03:05:32 -07:00
Slava Pestov
044034cae5 Sema: hasType() => hasInterfaceType() 2016-11-29 03:05:31 -07:00
Slava Pestov
1657060d1e AST: hasType() => hasInterfaceType() 2016-11-29 03:05:30 -07:00
Slava Pestov
4ebac86895 AST: Type::subst(): try harder to preserve sugar
If a sugared type desugars to a substitutable type, we would
return the replacement type without the sugar. I think in
practice this meant that ParenType would be lost sometimes.

Preserving this correctly is required for an upcoming CSDiag
change.

Note that there's a minor source-breaking change with enum
case constructors here. I've filed <rdar://problem/27261929>
to track sorting it out in Swift 3 mode.

Also an upcoming patch fixes another related issue and adds more
tests for case constructors.
2016-11-29 03:05:28 -07:00
Slava Pestov
6cbb494ad2 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-29 03:05:25 -07:00
Pavel Yaskevich
d111e9b4be [Diagnostics] When building a subscript don't assume that overload is always present
This handles situation when overload for the subscript hasn't been resolved
by constraint solver, such might happen, for example, if solver was allowed to
produce solutions with free or unresolved type variables (e.g. when running diagnostics).

Resolves: <rdar://problem/27329076>, <rdar://problem/28619118>, <rdar://problem/2778734>.
2016-11-28 19:18:44 -08:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Slava Pestov
37d38abeb1 AST: Fix crashes when ordering potential archetypes arising from typealias declarations in protocols
This fixes the oldest compiler crasher, number 46. All remaining unfixed
crashers are numbered 28155 and above.
2016-11-27 04:02:43 -08:00
Slava Pestov
ea28765ced Sema: Resolve invalid generic parameters to error types
When a generic parameter list fails to parse, we don't call
DeclContext::setGenericParams(), even though the generic
parameters are still available for name lookup.

This causes various crashes, which this patch fixes by
mapping the generic parameters to ErrorTypes.
2016-11-26 01:31:59 -05:00
Graydon Hoare
7c1dc18b64 Revert "Give all declarations an explicit interface type" 2016-11-24 09:55:27 -08:00
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