Commit Graph

9116 Commits

Author SHA1 Message Date
Mark Lacey
37cb6a80b3 Make Type::join return Any by default.
For the moment, update the sole caller to not infer Any in cases where
neither argument was Any. This is in part because not all the cases are
handled here and the result of inferring Any will be to miss appropriate
bindings in certain cases. It is also in part because by inferring Any
we may end up deferring diagnostics until later in a function, which may
result in very hard to understand diagnostics for users.

This will be revisted once all the cases are properly handled here.
2017-09-24 16:20:00 -07:00
Tony Allevato
13ad81a173 Synthed hashValue now calls _mixForSynthesizedHashValue
For enums, we now only call _mixInt on the computed hash value if
it has associated values; for enums without associated values, we
use the ordinal alone, as before.
2017-09-24 10:57:31 -07:00
Doug Gregor
cf78384dd5 Merge pull request #12075 from apple/revert-12062-make-fewer-gsbs
Revert "Create fewer generic signature builders"
2017-09-23 07:28:56 -07:00
Graydon Hoare
85dda86130 Merge pull request #12071 from graydon/trace-stats-deltas
Trace stats deltas
2017-09-22 22:25:58 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
David Ungar
d4cf2d4a24 Merge pull request #11656 from davidungar/addingTimers
Refactoring performSema in order to add timers
2017-09-22 20:31:06 -07:00
Doug Gregor
eccdedaf97 Merge pull request #12062 from DougGregor/make-fewer-gsbs
Create fewer generic signature builders
2017-09-22 18:38:27 -07:00
Pavel Yaskevich
80e4a2226b [ConstraintGraph] Don't try to contract edge of parameter bindings with inout attribute
Currently edge related to the parameter bindings is contracted
without properly checking if newly created equivalence class has
the same inout & l-value requirements. This patch improves the
situation by disallowing contraction of the edges related to parameter
binding constraint where left-hand side has `inout` attribute set.

Such guarantees that parameter can get `inout` type assigned when
argument gets `l-value` type.

Resolves: rdar://problem/33429010
2017-09-22 17:23:12 -07:00
Doug Gregor
76a532b3af [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-22 17:11:05 -07:00
Graydon Hoare
5df55e4d06 [stats] Add a stats-tracer for type-checking. 2017-09-22 19:17:32 -04:00
Doug Gregor
115d81a327 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-22 11:32:26 -07:00
Doug Gregor
fa7801f503 Stop dumping the full state of the GSB in testing.
The full state of the GSB isn’t all that useful for testing, creates a ton of noise and gets in the way of some cleanups we’d like to make in the interface.
Stop dumping it as part of `-debug-generic-signatures`.
2017-09-22 11:32:26 -07:00
Doug Gregor
da56cb33b8 Make unconstrained extensions use the generic signature of extended type.
An unconstrained extension will always have the same generic signature as the
nominal type it extends. Rather can constructing a new generic signature
builder to tell us that, just re-use the generic signature. Improves
type-checking performance of the standard library by 15%.
2017-09-22 11:32:25 -07:00
Doug Gregor
98a255994d Don’t create a new generic signature builder for non-generic members.
When type-checking a function or subscript that itself does not have generic
parameters (but is within a generic context), we were creating a generic
signature builder which will always produce the same generic signature as
the enclosing context. Stop creating that generic signature builder.

Instead, teach the CompleteGenericTypeResolver to use the generic signature
+ the canonical generic signature builder for that signature to resolve
types, which also eliminates some extraneous re-type-checking.

Improves type-checking performance of the standard library by 36%.
2017-09-22 11:32:25 -07:00
Tony Allevato
f2c434a038 Merge branch 'master' into synthesize-equatable-hashable 2017-09-21 22:54:36 -07:00
David Ungar
097dd71ffe Simple fixes per Jordan's comments:
- Use isWholeModuleCompilation in CompilerInstance::createSILModule
- Remove some unneeded timers
- Improve the comment in CompilerInstance::parseAndCheckTypes
- Remove needless const ref to an llvm::function_ref parameter in forEachSourceFileIn
- Remove "OfFile" from "finishTypeCheckingOfFile"
2017-09-21 20:18:34 -07:00
David Zarzycki
7aa7df1048 Merge pull request #12042 from davezarzycki/nfc_matchFunctionTypes_fixes2 2017-09-21 22:38:54 -04:00
Mark Lacey
c0c848d2b3 Add Builtin.type_join* family of functions.
These will be used for unit-testing the Type::join functionality in the
type checker. The result of the join is replaced during constraint
generation with the actual type.

There is currently no checking for whether the arguments can be used to
statically compute the value, so bad things will likely happen if
e.g. they are type variables. Once more of the basic functionality of
Type::join is working I'll make this a bit more bullet-proof in that
regard.

They include:
  // Compute the join of T and U and return the metatype of that type.
  Builtin.type_join<T, U, V>(_: T.Type, _: U.Type) -> V.Type

  // Compute the join of &T and U and return the metatype of that type.
  Builtin.type_join_inout<T, U, V>(_: inout T, _: U.Type) -> V.Type

  // Compute the join of T.Type and U.Type and return that type.
  Builtin.type_join_meta<T, U, V>(_: T.Type, _: U.Type) -> V.Type

I've added a couple simple tests to start off, based on what currently
works (aka doesn't cause an assert, crash, etc.).
2017-09-21 14:43:26 -07:00
David Zarzycki
e02d4c5afa [Sema] NFC: Ensure that closures are not subtypes of auto-closures
Right now, the sole caller ensures this, but that is just a hack.
2017-09-21 14:16:26 -04:00
David Zarzycki
03a48b076f [Sema] NFC: Simplify matchFunctionTypes()
In this scope, if func1->throws() is false, then func2->throws() must be true.
2017-09-21 14:16:26 -04:00
Robert Widmann
e9e0c2e8e4 Merge pull request #12036 from CodaFi/rank-existentialist-nonsense
[NFC] Remove Existential Ranking Hack
2017-09-21 10:59:12 -04:00
Robert Widmann
9bd12bc20c [NFC] Remove Existential Ranking Hack
This hack was originally intended to distinguish between functions
of single arguments that were overloaded on AnyObject and AnyObject?.
Nowadays, CSRanking is capable of handling that itself, and the check
this function was using to detect AnyObject no longer works.
2017-09-21 01:15:58 -04:00
swift-ci
abe34f804b Merge pull request #11902 from itaiferber/factor-out-isdefaultinitializable 2017-09-20 11:32:39 -07:00
Itai Ferber
cda3bf19aa Factor isDefaultInitializable logic for reuse
Factors isDefaultInitializable logic from
TypeChecker::addImplicitConstructors (and others) so it can be reused
for Codable synthesis.
2017-09-20 09:45:25 -07:00
Slava Pestov
55916fa128 Sema: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Doug Gregor
45b31c7cd1 [Conformance checking] Don’t report invalid conformances.
Fixes crashes on some invalid code that comes up with piles of recursive
constraints.

(cherry picked from commit 81355938761fcc2deec9c0330581263ac4a4dd5d)
2017-09-19 15:11:54 -07:00
Doug Gregor
dc43b42c00 [Type witness inference] Use “local” dependent member types when possible.
When inferring associated type witnesses, we depend (too much) on the
identity of the associated types that show up in potential witnesses.
Rewrite dependent member types that refer to associate types of other
related protocols into dependent member types that refer into the protocol
for the conformance being checked (if it has a same-named associated type).
This isolates us somewhat from the effects of the canonicalization algorithm.

(cherry picked from commit f50183d5a4bc50a20b4afd7e6a882d63a15504ee)
2017-09-19 15:11:54 -07:00
Kacper Harasim
3902688b04 [Diagnostics] Resolves: SR-5324 Improved diagnostic when instance member of outer type is referenced from nested type (#11609)
* [Diagnostics] Improved error diagnostics when inner type references instance member of outer type

Resolves: SR-5324.
2017-09-19 14:08:16 -07:00
Slava Pestov
731a2f26aa Sema: Fix unused variable warning 2017-09-19 00:04:26 -07:00
Erik Eckstein
0bdd91a039 Produce more efficient code for the init(rawValue: String) constructor of string enums.
Instead of inlining a series of string comparisons, we call a library function which does the string lookup on a table of static strings.
This reduces the code size of those initializers dramatically.
Performance wise it's slower than before, because the string comparisons are not inlined anymore.
2017-09-18 17:50:24 -07:00
David Ungar
0787be754b Renamed finishTypeChecking to finishTypeCheckingOfSourceFile
To free up that name
2017-09-18 14:01:12 -07:00
David Ungar
26e90a624c Removed performTypeChecking timer
To maintain coverage added timers:
performWholeModuleTypeChecking, and
verifyAllLoadedModules
2017-09-18 14:01:12 -07:00
Doug Gregor
6d9e921983 Restrict the ability to specify "protocol P : class, AnyObject" to Swift >= 5. 2017-09-18 13:28:31 -07:00
Doug Gregor
d0aa22c2c7 Allow "protocol P : class, AnyObject..." for Swift 4 compatibility.
Because of the way we modeled the 'class' constraint in Swift <= 4, we
allowed both 'class' and 'AnyObject' to be specified on a protocol,
even in Swift 4 when they became equivalent. Recent refactoring
started rejecting such code; allow it now.

Fixes rdar://problem/34496151.
2017-09-18 13:28:31 -07:00
swift-ci
29e69e2d1b Merge pull request #11966 from xedin/prefer-literal-bindings-over-typevars 2017-09-18 12:04:36 -07:00
Slava Pestov
10bd85cb34 Sema: Fix Equatable, Hashable, RawRepresentable derivation for @_versioned enums
The synthesized declarations should inherit the @_versioned attribute
from the type, just like they inherit access control.

Fixes <rdar://problem/34342955>.
2017-09-17 21:35:55 -07:00
Slava Pestov
39872d9a96 Sema: Remove "at least internal" check for derived conformance declarations
It looks like at some point derived conformances were in their own
FileUnit, but this is no longer the case.
2017-09-17 21:35:55 -07:00
Joe Groff
875435de53 Merge pull request #11957 from jckarter/key-path-subscript-review
Code updates from review on #11953
2017-09-17 20:12:59 -07:00
Robert Widmann
c485199e42 Merge pull request #11945 from CodaFi/basic-instinct
Coerce the base of existential keypath applies
2017-09-17 21:13:04 -04:00
Robert Widmann
e310ab3e3c Coerce the base of existential keypath applies
We can wind up in a situation where the base of a keypath
application is concrete but is being applied to a keypath
with an existential source type.  Coerce the base to the
intended type if necessary when building the final subscript
expression.

Resolves SR-5878.
2017-09-17 16:52:49 -04:00
Matthew Baranowski
b68ece64e0 [SR-5856] Fix diagnostic for static stored properties in protocol extensions (#11930)
* [SR-5856] Fix diagnostic message for static stored properties not supported in protocol extensions

* fix test failure in decl/var/properties.swift
this looks like a better place to test the new behavior, so removing changes to static_var.swift
2017-09-17 14:07:52 -04:00
Pavel Yaskevich
c8fad863c4 [ConstraintSolver] NFC: Refactor PontentialBindings to reference type variable they belong to 2017-09-16 23:35:44 -07:00
Pavel Yaskevich
3792ada50b [ConstraintSolver] Attempt literal bindings earlier
If the best bindings we could get on the current step are bindings
to literal type without any other type variable involved, let's try
to attempt them right away, that should help to prune search space.
2017-09-16 23:28:00 -07:00
Slava Pestov
f3e9aa35a7 Sema: Inherited initializers inherit the @_versioned attribute
Fixes <rdar://problem/34398148>.
2017-09-16 00:23:14 -07:00
Pavel Yaskevich
7d80daf0ff [ConstraintSolver] When ranking bindings prefer type vars with literal bindings
Change the potential binding ranking logic to prefer type variables
which don't have other type variables related to them, but have literal
bindings, over the ones that do have other type variables.
2017-09-15 22:19:39 -07:00
Slava Pestov
400693b811 AST: Store the default argument resilience expansion in the AbstractFunctionDecl
Previously we stored this inside each default argument
initializer context. This was overkill, because it is
the same for all default arguments in a single function,
and also insufficient, because initializer contexts are
not serialized and thus not available in SILGen when
the function is in a different module.

Instead store it directly inside the function and
serialize it.

NFC for now, since SILGen isn't using this yet.
2017-09-15 16:20:45 -07:00
Joe Groff
6ccc96cf67 Code updates from review on #11953
- Remove dead `if !genericEnv` checks
- Do conformance checks for subscript indexes `InExpression`
- Use `GenericEnvironment::mapTypeOutOfContext` static method instead of null checking everywhere
2017-09-15 15:43:59 -07:00
Pavel Yaskevich
6c43424ff6 Merge pull request #11951 from xedin/add-binding-refactor
[ConstraintSolver] NFC: Move `addPotentialBinding` into PotentialBindings
2017-09-15 15:01:47 -07:00
Pavel Yaskevich
8c2fa12ac9 [ConstraintSolver] NFC: Move addPotentialBinding into PotentialBindings 2017-09-15 13:31:15 -07:00
Joe Groff
2ba8f57514 Remove staging flag for unimplemented key path components.
All the originally-planned component kinds are now implemented.
2017-09-15 11:55:35 -07:00