Commit Graph

7976 Commits

Author SHA1 Message Date
Joe Groff
886c83f6e7 SILGen: Allow static stored properties in fully-concrete extensions of generic types.
There's no need for per-instantiation storage in this case, so we can relax the implementation limitation for them.
2017-02-24 15:25:39 -08:00
swift-ci
82073f9954 Merge pull request #7739 from DougGregor/sr-4056 2017-02-24 00:02:54 -08:00
Doug Gregor
99a139695a [Constraint solver] Dont assume orphans are along in the inactive list.
The inactive list may contain other disjunctions associated with bound
type variables. For now, make sure we recover the orphan directly to
fix the crash in SR-4056 / rdar://problem/30686926. Later, we can
treat these as orphans, too.
2017-02-23 23:38:23 -08:00
Slava Pestov
928a74c47e Parse: Support for generic subscripts 2017-02-23 21:14:02 -08:00
Mark Lacey
f32824296a Add an empty constraint propagation pass.
This is disabled by default but enabled under the frontend option
-propagate-constraints.

The idea here is to have a pass that enforces local consistency in our
constraint system, in order to reduce the domains of constraint
variables, speeding up the solving of the constraint system.

The initial focus will be on reducing the size of the disjunctions for
function overloads with the hope that it substantially improves the
performance of type checking many expressions.
2017-02-23 15:04:07 -08:00
Mark Lacey
77ee77fa02 Merge pull request #7720 from rudkx/type-check-scale-test
Add a scale-test counter for expression type checking.
2017-02-23 13:24:57 -08:00
Mark Lacey
b026a07fd8 Add a scale-test counter for expression type checking.
Also add the first example of using the counter to test for
known-exponential typechecking behavior for nil-coalescing.
2017-02-23 12:08:30 -08:00
Slava Pestov
b866edd79a Merge pull request #7708 from CodaFi/fully-reloaded
[SR-3896] Add missing r-value coercion for type(of:)'s argument
2017-02-22 22:02:22 -08:00
Robert Widmann
10f680bd4e Add missing r-value coercion in type(of:)
When this was migrated over to the awesome new special representation
of type(of:) the argument coercion didn’t come with it.  The missing
load expression caused any l-value run through type(of:) to crash in the
verifier.
2017-02-22 23:49:21 -05:00
Slava Pestov
7b06b3da03 Merge pull request #7704 from KingOfBrian/bugfix/SR-4024
[Diagnostics] Do not report an override warning multiple times
2017-02-22 19:56:33 -08:00
Brian King
43a168aa56 Do not generate warning when recording the override for a func_decl contained in a variable 2017-02-22 21:00:34 -05:00
Slava Pestov
6a9abafbc7 Sema: Subscripts in generic contexts should have a GenericFunctionType
Fixes <rdar://problem/22086900>.
2017-02-21 23:52:13 -08:00
Slava Pestov
79e7820a03 Sema: Refactor class method override matching for generic subscripts
Subscripts in generic context will soon have a
GenericFunctionType, so get ready to handle that.
2017-02-21 23:52:13 -08:00
Slava Pestov
1a8ba93e59 Sema: Refactor getTypeOfMemberReference() for generic subscripts
Subscripts in generic context will soon have a
GenericFunctionType, so get ready to handle that.
2017-02-21 23:52:12 -08:00
Slava Pestov
4f83f6ef21 Sema: Fix CSRanking in preparation for generic subscripts
Subscripts in generic context will soon have a
GenericFunctionType, so get ready to handle that.
2017-02-21 23:52:12 -08:00
Slava Pestov
f8e60e8a57 Sema: Type checking of generic subscripts 2017-02-21 23:52:11 -08:00
Slava Pestov
edcb82d2a0 AST: Refactor name lookup for generic subscripts
Get ready to handle lookup of generic parameters into a DeclContext
that is a SubscriptDecl. No functional change yet, this this code
path is not reachable.
2017-02-21 23:52:11 -08:00
Slava Pestov
8e5605cb85 Sema: Another small cleanup 2017-02-21 23:35:49 -08:00
practicalswift
8c1ae56c7c [gardening] Add missing copyright header. 2017-02-21 14:20:34 +01:00
Doug Gregor
40b6764e80 [Constraint solver] Handle disjunctions as separate connected components.
The constraint graph models type variables (as the nodes) and
constraints (as the multi-edges connecting nodes). The connected
components within this (multi-)graph are independent subproblems that
are solved separately; the results from each subproblem are then
combined. The approach helps curtail exponential behavior, because
(e.g.) the disjunctions/type variables in one component won't ever be
explored while solving for another component

This approach assumes that all of the constraints that cannot be
immediately solved are associated with one or more type
variables. This is almost entirely true---constraints that don't
involve type variables are immediately simplified.

Except for disjunctions. A disjunction involving no type variables
would not appear *at all* in the constraint graph. Worse, it's
independence from other constraints could not be established, so the
constraint solver would go exponential for every one of these
constraints. This has always been an issue, but it got worse with the
separation of type checking of "as" into the "coercion" case and the
"bridging" case, which introduced more of these disjunctions. This led
to counterintuitive behavior where adding "as Foo" would cause the
type checking to take *more* time than leaving it off, if both sides
of the "as" were known to be concrete. rdar://problem/30545483
captures a case (now in the new test case) where we saw such
exponential blow-ups.

Teach the constraint graph to keep track of "orphaned" constraints
that don't reference any type variables, and treat each "orphaned"
constraint as a separate connected component. That way, they're solved
independently.

Fixes rdar://problem/30545483 and will likely curtain other
exponential behavior we're seeing in the solver.
2017-02-20 17:18:18 -08:00
Slava Pestov
a79fd9eff1 Merge pull request #7639 from slavapestov/sourcekit-indexing-protocol-typealias
SourceKit: Fix indexing crash with protocol typealiases
2017-02-20 12:07:37 -08:00
Doug Gregor
042e6510c3 [AST] Drop ProtocolDecl's "inherited protocols" list.
The list of directly inherited protocols of a ProtocolDecl is already
encoded in the requirement signature, as conformance constraints where
the subject is Self. Gather the list from there rather than separately
computing/storing the list of "inherited protocols".
2017-02-20 09:41:00 -08:00
Slava Pestov
0bc802e7ad SourceKit: Fix indexing crash with protocol typealiases
The root cause is that NormalProtocolConformance::forEachValueWitness()
needs to skip protocol members that are not requirements.

Otherwise we end up passing such a non-requirement member down to
NormalProtocolConformance::getWitness() and hit an assert when we
cannot find it.

It looks like this code path was only ever hit from SourceKit.
The fix moves TypeChecker::isRequirement() to a method on ValueDecl,
and calls it in the right places.

Fixes <https://bugs.swift.org/browse/SR-3815>.
2017-02-20 03:35:19 -08:00
Slava Pestov
880803aaba AST: Initial plumbing for generic subscripts 2017-02-19 21:34:26 -08:00
Slava Pestov
fe16cf869d Sema: Move some code around for better organization 2017-02-19 20:33:11 -08:00
Mark Lacey
4908e8410b Merge pull request #7619 from rudkx/fix-rdar30271695
Attempt to bind the result of unwrapping optionals if we're asked to …
2017-02-19 19:35:30 -07:00
Mark Lacey
d4a5fe58be Attempt to bind the result of unwrapping optionals if we're asked to bind subtypes.
When trying to solve for the test case we attempt to simplify a value
member constraint and it fails because we've bound the LHS type
variable to an optional as a result of other constraints involving
other type variables in the equivalence class of this type
variable.

We don't have enough information to directly deduce the non-optional
type directly from other constraints involving this type variable.

This change results in one interesting type checking anomoly. In Swift
3 mode, we now successfully typecheck an expression that we previously
did not. Although the type checking technically makes sense given the
type checking rules we have in place, it can be a bit surprising to
users. Fortunately we emit a warning that calls out the surprising
behavior of considering an expression unused.

Fixes rdar://problem/30271695.
2017-02-19 14:53:01 -07:00
Slava Pestov
ea0f271786 Sema: Remove unnecessary function signature typecheck pass
This was necessary when we would 'adopt' archetypes from outer
contexts, but that is long gone, and the only thing it accomplished
was emitting duplicate diagnostics.
2017-02-18 23:12:21 -08:00
Joe Groff
6752266798 Merge pull request #7534 from jckarter/covariant-self-init-delegation
Sema: Type-check initializer delegation as a covariant expression.
2017-02-17 17:32:03 -08:00
David Farler
3645736ac0 Merge pull request #7393 from bitjammer/syntax-tree
Start the Syntax structured editing library
2017-02-17 15:26:00 -08:00
Doug Gregor
da39d9b17b [GenericSig Builder] Rework RequirementSource to describe requirement path.
Reimplement the RequirementSource class, which captures how
a particular requirement is satisfied by a generic signature. The
primary goal of this rework is to keep the complete path one follows
in a generic signature to get from some explicit requirement in the
generic signature to some derived requirement or type, e.g.,

1) Start at an explicit requirement "C: Collection"
2) Go to the inherited protocol Sequence,
3) Get the "Iterator" associated type
4) Get its conformance to "IteratorProtocol"
5) Get the "Element" associated type

We don't currently capture all of the information we want in the path,
but the basic structure is there, and should also allow us to capture
more source-location information, find the "optimal" path, etc. There are
are a number of potential uses:

* IRGen could eventually use this to dig out the witness tables and
  type metadata it needs, instead of using its own fulfillment
  strategy
* SubstitutionMap could use this to lookup conformances, rather than
  it's egregious hacks
* The canonical generic signature builder could use this to lookup
  conformances as needed, e.g., for the recursive-conformances case.

... and probably more simplifications, once we get this right.
2017-02-17 13:50:51 -08:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
David Farler
431b7ff2af [Syntax] Add Equal '=' token location to TypeAliasDecl
Needed for full-fidelity structured editing.
2017-02-17 12:57:04 -08:00
Joe Groff
6717e96ee4 Merge pull request #7564 from jckarter/assoc-type-mixed-explicit-and-inferred
Sema: Don't infer associated types from witness candidates that contradict explicit type witnesses.
2017-02-17 12:07:33 -08:00
Joe Groff
749bef78ca Sema: Don't infer associated types from witness candidates that contradict explicit type witnesses.
If a conforming type provided explicit witnesses for some of its associated types and inferred others, we would still harvest inference solutions from methods that contradict the explicit witnesses, leading to bogus ambiguity errors in some situations. Fix this by skipping inference candidates that contradict explicit type witnesses. Fixes SR-3979.
2017-02-17 09:53:02 -08:00
Joe Groff
eae044c07d Sema: Type-check initializer delegation as a covariant expression.
If a convenience initializer in a subclass delegated to an inherited initializer from its base, we would end up type-checking the reference to the base class constructor as returning the base type, leading to type mismatches in the result AST and downstream crashes. We can wrap up the synthesized OtherConstructorRefExpr in a CovariantFunctionConversionExpr, which will trick the type checker into propagating the covariant result that gets rebound to `self` on return, avoiding this problem. (For now, I'm avoiding making the constructor decl formally have a Self return type, since that exposes a bunch of downstream breakage in code paths that only expect FuncDecls to be covariant, and also affects the mangling of constructors, causing a bunch of test case thrash we really don't want to inflict on the 3.1 branch.)
2017-02-16 13:19:11 -08:00
Doug Gregor
966f616049 [AST] Make NominalTypeDecl::lookupDirect() return by value.
This function was returning an ArrayRef pointing into a data structure
that is easily mutated via code walking over that ArrayRef, which
could cause spooky side effects, particularly during
deserialization. Perform a defensive copy to eliminate such side
effects.
2017-02-16 10:59:23 -08:00
swift-ci
36a60d253c Merge pull request #7519 from rudkx/dump-source-range 2017-02-16 00:35:47 -08:00
Mark Lacey
58b14ffc2d Update -debug-constraints to dump the source range immediately.
We end up dumping information during constraint generation, and it's
nice to know which range we're dealing with at that point.
2017-02-15 23:21:52 -08:00
Michael Gottesman
8437819b5a [CMake] Revert recent changes.
These changes caused a number of issues:

1. No debug info is emitted when a release-debug info compiler is built.
2. OS X deployment target specification is broken.
3. Swift options were broken without any attempt any recreating that
functionality. The specific option in question is --force-optimized-typechecker.

Such refactorings should be done in a fashion that does not break existing
users and use cases.

This reverts commit e6ce2ff388.
This reverts commit e8645f3750.
This reverts commit 89b038ea7e.
This reverts commit 497cac64d9.
This reverts commit 953ad094da.
This reverts commit e096d1c033.

rdar://30549345
2017-02-15 22:26:06 -08:00
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00
Slava Pestov
32316559f8 AST: Stored property accessors on non-Objective-C derived classes can be transparent
In 74d979f0ac, the policy was changed
so that only value type accessors are ever marked transparent, and
not class accessors.

This was intended to fix a bug where inlining an accessor of an
Objective-C-derived class across module boundaries caused a linker
failure because the accessor referenced a field offset variable,
which has hidden visibility.

However, this also caused a performance regression for Swift native
classes. Bring back the old behavior for Swift native classes in
non-resilient modules.

Fixes <rdar://problem/29884727>.
2017-02-14 22:35:27 -08:00
Mark Lacey
713e5a2135 Merge pull request #7481 from rudkx/fix-rdar30376186
Cache expression types in failure diagnosis.
2017-02-14 21:31:54 -08:00
Mark Lacey
f1f9e88360 Cache expression types in failure diagnosis.
After we call into typeCheckExpression() we need to cache the
resulting types in the constraint system type map because we later
call into code that reads the types out of the type map.

Fixes rdar://problem/30376186 as well as a couple crashers.
2017-02-14 19:22:41 -08:00
Slava Pestov
13d6b183c0 Merge pull request #7370 from llvm-beanz/simplify-add_swift_library
[CMake] Simplify add_swift_library
2017-02-14 19:16:59 -08:00
Slava Pestov
fd40597d90 Sema: Extend prohibition of @_inlineable designated initializers to classes
This check only applied to struct and enum initializers previously,
but that was an oversight.
2017-02-14 15:48:26 -08:00
Slava Pestov
50b5d01dd7 Sema: Tighten up rules for @_inlineable
- Don't allow @_inlineable on stored properties; this generates
  invalid SIL since clients can't know about stored properties of
  resilient types. Accessors for stored properties of non-resilient
  types are already @_inlineable anyway.

- Don't allow @_inlineable on declarations that are not public or
  @_versioned, since it's simply redundant.
2017-02-14 15:48:26 -08:00
Chris Bieneman
e096d1c033 [CMake] Simplify add_swift_library
This patch splits add_swift_library into two functions one which handles
the simple case of adding a library that is part of the compiler being
built and the second handling the more complicated case of "target"
libraries, which may need to build for one or more targets.

The new add_swift_library is built using llvm_add_library, which re-uses
LLVM's CMake modules. In adapting to use LLVM's modules some of
add_swift_library's named parameters have been removed and
LINK_LIBRARIES has changed to LINK_LIBS, and LLVM_LINK_COMPONENTS
changed to LINK_COMPONENTS.

This patch also cleans up libswiftBasic's handling of UUID library and
headers, and how it interfaces with gyb sources.

add_swift_library also no longer has the FILE_DEPENDS parameter, which
doesn't matter because llvm_add_library's DEPENDS parameter has the same
behavior.
2017-02-14 14:28:10 -08:00
swift-ci
25d58af2ad Merge pull request #7452 from DougGregor/sr-3917-unavaiable-reqs 2017-02-13 23:34:57 -08:00
Doug Gregor
769a40c2b5 [Type checker] Don't try to infer @objc from unavailable requirements.
@objc inference was looking at unavailable requirements---for which we
don't ever record witnesses---at a point when it is no longer possible
to record such a witness. This is a targeted fix; we need to tackle
the issue of unavailable and optional requirements more thoroughly.

Fixes SR-3917 / rdar://problem/30474860.
2017-02-13 23:12:14 -08:00