Commit Graph

7976 Commits

Author SHA1 Message Date
Slava Pestov
b0c1799f45 Sema: Merge CSGen's canSatisfy() with TypeChecker::typesSatisfyConstraint() 2017-04-20 00:37:38 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Slava Pestov
55df58d2a3 Sema: More accurate cast diagnostics for subclass existentials
Normally there is very little the type checker can conclude about
casts between existentials, because new conformances can be added
retroactively. However if the existentials are class-constrained,
we can rule out certain casts as always failing by looking at
superclass bounds.
2017-04-20 00:37:37 -07:00
Joe Groff
517c45aa3d Followups from merging master 2017-04-19 20:58:52 -07:00
Joe Groff
cdb54ccadf Put keypaths behind a flag. 2017-04-19 20:39:11 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Graydon Hoare
6a94c9fb9e Merge pull request #8735 from graydon/rdar-30959593-operators-defeat-incrementality
Attribute @_implements & deriving enum equality not-named ==
2017-04-19 11:18:55 -07:00
swift-ci
504b6f2a55 Merge pull request #8852 from DougGregor/protocol-conformance-cleanups 2017-04-19 00:05:06 -07:00
Doug Gregor
8584e97408 [AST] Sink ProtocolConformance::getWitness() down into NormalProtocolConformance.
NormalProtocolConformance has the only correct implementation of this
functionality. Instead, providing a safer getWitnessDecl() that
doesn't promise substitutions that are incorrect (and not actually
used by any clients).
2017-04-18 23:35:24 -07:00
Graydon Hoare
e6027eeb4e Derive @_implements(Equatable, ==(_:_:)) _DerivedEnumEquals, not func==. 2017-04-18 23:21:44 -07:00
John McCall
91ffc9baaa Weaken the circularity re-delay assertion when errors have been emitted.
We don't finalize declarations when there's been an error, which means
we might never assign types to the stored properties/cases of a nominal
type from another file, which means that circularity checking for types
using those types be re-delayed.

Fixes SR-4594.
2017-04-19 01:08:41 -04:00
Joe Groff
a6cd471c2b IRGen/stdlib: Instantiate non-generic computed key path components. 2017-04-18 21:51:12 -07:00
Doug Gregor
d9af96ffe4 [AST] Remove more interface-type redundancy from ProtocolConformance. 2017-04-18 17:15:15 -07:00
Doug Gregor
ebdd56a1f0 [AST] Eliminate the "interface type" from protocol conformances.
We don't need this notion.
2017-04-18 17:15:15 -07:00
Graydon Hoare
db515885f8 Typecheck contents of @_implements attribute. 2017-04-18 11:12:54 -07:00
Graydon Hoare
6eddd7f0e4 Wire up @_implements to witness lookup. 2017-04-18 11:12:54 -07:00
Graydon Hoare
c71295a12a Add @_implements decl attribute. 2017-04-18 11:12:53 -07:00
Graydon Hoare
3a79d83233 Forward declare TypeRepr in TypeLoc.h, adjust other code to compensate. 2017-04-18 11:12:53 -07:00
practicalswift
b6ce00a012 Merge pull request #8832 from practicalswift/typos-20170418
[gardening] Fix 100 typos.
2017-04-18 19:13:31 +02:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
Doug Gregor
17846e2be1 [GSB] Cope with recursive requirements by delaying them.
Rather than detecting recursion and bailing early, delay requirements
that would form recursive types. Note that we aren't actually
processing them later.
2017-04-17 23:13:21 -07:00
Slava Pestov
244a5f7a53 Sema: Fix crash with recursive subscript validation via associated type inference
Looks like subscript validation wasn't checking or setting
ValueDecl::isBeingValidated(). This caused a stack overflow
with associated type inference. The way to trigger this
during normal use is to invoke the fixit for adding
missing protocol requirements -- they're written in terms
of the protocol's associated type, which the user might
not have defined yet.

Fixes <rdar://problem/26680599>.
2017-04-17 19:57:12 -07:00
Slava Pestov
700be61438 Sema: Fix crash with metatype construction -vs- dynamic Self
Fixes <rdar://problem/31297864>.
2017-04-17 19:57:12 -07:00
Slava Pestov
cc611de2aa Merge pull request #8788 from slavapestov/subclass-existentials-irgen
Tiny bit more progress on IRGen support for subclass existentials
2017-04-17 17:05:06 -07:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00
Slava Pestov
ff20d0661b Sema: Remove a usage of getExistentialTypeProtocols() 2017-04-17 17:22:29 -06:00
swift-ci
961a319b97 Merge pull request #8799 from rudkx/propagate-constraints 2017-04-15 20:44:04 -07:00
Mark Lacey
5e6b4a97ee [Constraint solver] Fix memory corruption issue.
We use simplifyConstraint() to activate other constraints, and then
examine those constraints to find related disjunctions. In examining
those active constraints, we were simplifying them in case they
failed (which would allow us to bail out earlier). In doing so, we could
potentially generate new disjunctions when we simplify an unresolved
value member constraint. If we do that, we end up collecting these new
disjunctions as part of the set of related disjunctions, but that's
problematic because as part of exiting the solver scope to roll back
changes we delete these disjunctions from the system.

Instead of actually simplifying the active constraints, just collect the
disjunctions and move the active constraints back to the inactive list.

With this change we can build the stdlib.
2017-04-15 20:18:09 -07:00
practicalswift
b8ca098949 Merge pull request #8742 from practicalswift/gardening-20170413
[gardening] Use consistent headers. Remove redundant includes. Remove unused methods. Fix typos, etc.
2017-04-15 18:59:30 +02:00
swift-ci
d99141c312 Merge pull request #8786 from DougGregor/gsb-requirement-inference 2017-04-14 17:45:10 -07:00
Doug Gregor
faa0401598 [GSB] Allow requirement inference for synthesized requirements. 2017-04-14 17:19:02 -07:00
Doug Gregor
c3b507f462 [Type checker] Use GenericSignatureBuilder's substitution logic.
Rather than hardcoding all of the substitution logic for requirements
in the RequirementEnvironment constructor, harden and re-use the
GenericSignatureBuilder's substitution logic instead.
2017-04-14 17:19:02 -07:00
Doug Gregor
8a4451dda9 [GSB] Infer requirements from concrete types in requirements.
When a requirement mentions a concrete type, that type might utter
other types (e.g., Set<T>) that infer requirements (here, T:
Hashable). Perform requirement inference for such types.

Part of rdar://problem/31520386.
2017-04-14 17:19:01 -07:00
Maxwell Swadling
93d485e4f7 Changed handleDiagnostic to take a format string and format args instead of the formatted string
This allows diagnostic consumers to modify the way formatting of diagnostics is performed.
rdar://problem/31305854
2017-04-14 11:28:04 -07:00
swift-ci
62d077d2d3 Merge pull request #8776 from DougGregor/operator-availability-31592529 2017-04-14 09:57:22 -07:00
Doug Gregor
c739ab127c [Constraint Solver] Respect availability in operator-performance hacks.
We have various hacks in the constraint solver to improve the
compile-time performance characteristics of operators. Some of those
didn't respect availability annotations, causing us to incorrectly
choose an unavailable operator when available options exist.

Fixes rdar://problem/31592529.
2017-04-14 09:24:13 -07:00
practicalswift
40cf4d183d [gardening] Use consistent spacing after if, for and while 2017-04-14 17:35:36 +02:00
practicalswift
65bcc8ff84 [gardening] Use o && isa<T>(o) instead of dyn_cast_or_null<T>(o) when result is unused 2017-04-14 17:33:24 +02:00
practicalswift
6828ed9e1e [gardening] Use isa<T>(o) instead of dyn_cast<T>(o) when result is unused 2017-04-14 17:33:24 +02:00
practicalswift
d8d1693814 [gardening] Remove unused variables 2017-04-14 17:33:24 +02:00
Slava Pestov
e4905b942a Merge pull request #8770 from slavapestov/anyobject-removal-preparations
AnyObject removal preparations
2017-04-13 23:46:37 -07:00
Doug Gregor
5cf233ba20 [SE-0160] Swift 3: Downgrade error about non-ObjC @(IB|GK)Inspectable properties
@IBInspectable and @GKInspectable both work via the Objective-C
runtime. SE-0160 made them imply @objc, but doing so made it an error
to define an @IBInspectable or @GKInspectable property with a type
that could not be expressed in Objective-C. The attribute is useless,
but this broke Swift 3 code.

So, downgrade the error to a warning in Swift 3 compatibility mode,
with a Fix-It to remove the useless attribute. It remains an error in
Swift 4.

Fixes rdar://problem/31408971.
2017-04-13 23:08:03 -07:00
Slava Pestov
db58e02cb2 Sema: Hook up layout constraints to the solver
There were various problems with layout constraints either
being ignored or handled incorrectly. Now that I've exercised
this support with an upcoming patch, there are some fixes
here.

Also, introduce a new ExistentialLayout::getLayoutConstriant()
which returns a value for existentials which are class-constrained
but don't have a superclass or any class-constrained protocols;
an example would be AnyObject, or AnyObject & P for some
non-class protocol P.

NFC for now, since these layout-constrained existentials cannot
be constructed yet.
2017-04-13 21:17:05 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
d49f8fb6d9 AST: Introduce primitive AnyObject type
Add a 'hasExplicitAnyObject()' bit to ProtocolCompositionType
to represent canonical composition types containing '& AnyObject'.

Serialize this bit and take it into account when building
ExistentialLayouts.

Rename ProtocolCompositionType::getProtocols() to getMembers()
since it can contain classes now, and update a few usages that
need further attention with FIXMEs or asserts.

For now, nothing actually constructs these types, and they will
trigger arounds asserts. Upcoming patches will introduce support
for this.
2017-04-13 21:17:05 -07:00
Slava Pestov
7825926728 Sema: Remove unnecessary error path
Some crashers regress with this bogus error path after an
upcoming patch.
2017-04-13 13:45:55 -07:00
Slava Pestov
4cd5eb708a Fix a memory error introduced by recent changes
ExistentialLayout::getProtocols() can return an interior
pointer if the layout describes a single protocol type.

In this case we must not hold on to the result after
the layout goes out of scope.

Fix a few places where this was happening, which should
address a test failure we've been seeing.

Fixes <rdar://problem/31586433>.
2017-04-13 07:22:54 -07:00
John McCall
7952ddc86f Fix multifile infinite-type checks.
If checking succeeds, but we found an untyped property/case,
we just need to wait and re-check after everything has been typed.

Fixes rdar://30010094
2017-04-12 21:49:35 -04:00
swift-ci
98b4c69cf6 Merge pull request #8731 from rudkx/remove-redundant-constraint 2017-04-12 16:30:00 -07:00
Huon Wilson
b2d521730a Merge pull request #8703 from huonw/no-warning
[Sema] No release-mode warning in ProtocolRequirementTypeResolver.
2017-04-12 16:27:15 -07:00