Commit Graph

5160 Commits

Author SHA1 Message Date
Mark Lacey
e2c82aca92 Merge pull request #7247 from rudkx/cs-typemap
More progress on constraint system type map.
2017-02-05 20:06:48 -07:00
Michael Gottesman
fee2db81de [cmake] Add a new option called SWIFT_FORCE_OPTIMIZED_TYPECHECKER that forces Sema to be built optimized.
This should help speed up people trying to compile the standard library and do
SILGen work. *NOTE* This will not necessarily result in a type checker that is
as fast as a release build since most likely the type checker will use some
link_once odr functions that are debug. But it should still be significantly
faster otherwise.

This makes getting to SILGen take 16 seconds on my machine instead of forever
when compiling with everything else in the compiler in debug mode.
2017-02-05 16:48:54 -08:00
Mark Lacey
ef442daa8a More progress on constraint system type map.
Another pile of changes to use a side map for types in the constraint
solver and only write them directly into expressions once we have a
known good solution that we want to apply.

Still incomplete, we continue to write the types into expressions along
the way at the moment.
2017-02-05 17:37:03 -07:00
practicalswift
aa59098ad7 Merge pull request #7239 from practicalswift/gardening-20170203
[gardening] Fix typos. Fix word processor artefacts. Fix duplicate includes. Fix clang-tidy warnings.
2017-02-04 13:27:22 +01:00
practicalswift
e2f8af7762 [gardening] Fix clang-tidy warnings 2017-02-04 09:23:10 +01:00
Slava Pestov
cf4043b668 AST: Get rid of old form of Type::subst()
First, add some new utility methods to create SubstitutionMaps:

- GenericSignature::getSubstitutionMap() -- provides a new
  way to directly build a SubstitutionMap. It takes a
  TypeSubstitutionFn and LookupConformanceFn. This is
  equivalent to first calling getSubstitutions() with the two
  functions to create an ArrayRef<Substitution>, followed by
  the old form of getSubstitutionMap() on the result.

- TypeBase::getContextSubstitutionMap() -- replacement for
  getContextSubstitutions(), returning a SubstitutionMap.

- TypeBase::getMemberSubstitutionMap() -- replacement for
  getMemberSubstitutions(), returning a SubstitutionMap.

With these in place, almost all existing uses of subst() taking
a ModuleDecl can now use the new form taking a SubstitutionMap
instead. The few remaining cases are explicitly written to use a
TypeSubstitutionFn and LookupConformanceFn.
2017-02-03 19:55:40 -08:00
Slava Pestov
fc3244b2f2 Sema: Remove some redundant conformance lookup callbacks
Now we have LookUpConformanceInModule and
LookUpConformanceInSubstitutionMap.
2017-02-03 19:55:40 -08:00
Slava Pestov
00700c1729 AST: Always call getMemberForBaseType() with non-null origBase 2017-02-03 19:55:39 -08:00
Slava Pestov
a4fd57647c AST: Remove unused resolver parameter from getTypeOfMember() 2017-02-03 19:55:39 -08:00
Doug Gregor
ea90fa6345 [Archetype builder] Suppress redundant constraints more effectively.
Fix a couple of places where we were not managing to consider
redundant constraints as 'redundant', so the canonicalized generic
signatures were not in fact minimal. Address this in several places:

* When a type is made concrete, any superclass requirements on it are
  redundant
* When a type is made concrete, any same-type relationships among its
  nested types are redundant
* Only emit potential-archetype-to-concrete constraints in the
  resulting signature for the component anchors; not for every type.

The first two bullets were existing problems that are now fixed; the
last is something I appear to have introduced with last week's
refactoring of canonicalized same-type constraints.

The recent work to make the canonicalization deterministic exacerbated
the issue considerably, leading to huge blow-up in the size of
canonical generic signatures that cost ~100k in standard library
size. This change recovers that 100k.
2017-02-03 10:15:44 -08:00
Doug Gregor
ee00acf3d0 [AST] Remove GenericSignature::getRepresentative(). NFC
This entrypoint is unused and is a Bad Idea (TM). Remove it.
2017-02-02 21:25:29 -08:00
Doug Gregor
ded7e83aab [Archetype builder] Make canonicalization of dependent types deterministic.
The canonicalization of dependent member types had some
nondeterminism. The root of the problem was that we couldn't
round-trip dependent member types through the archetype
builder---resolving them to a potential archetype lost the specific
associated type that was recorded in the dependent member type, which
affected canonicalization. Maintain that information, make sure that
we always get the right archetype anchor, and tighten up the
canonicalization logic within a generic signature.

Fixes rdar://problem/30274260 and should unblock some other work
that depends on sanity from the archetype builder and generic
signature canonicalization.
2017-02-02 21:25:29 -08:00
Doug Gregor
2dcf6f0e27 [Archetype builder] Look up nested types on the requested parent.
When requesting a nested type of a potential archetype, the archetype
builder was immediately jumping to the representative of the (parent)
archetype. However, this means that we completely lost the structure
of the incoming types... one you ask for "U.AssocType" and end up with
"T.AssocType". Worse, the "representative" can vary based on the
ordering of constraints (particularly, same-type constraints), which
means that the resulting type would be somewhat unstable.

Stop doing that. When asking for a nested type, always return a type
nested within the given potential archetype, setting up the
appropriate same-type constraints with the representative's
corresponding nested type.
2017-02-02 21:25:29 -08:00
Doug Gregor
25017f0a8e [Archetype builder] Remove weird concrete-same-type assignment.
It's unclear why we ever thought we needed this, but we clearly don't
now; remove it.
2017-02-02 21:25:29 -08:00
Argyrios Kyrtzidis
a14cf1d7d4 Merge pull request #7208 from akyrtzi/usr-macro-no-pprecord
[USRGeneration] For clang macro USRs, use the more general API that doesn't require a PreprocessingRecord.
2017-02-02 13:21:57 -08:00
Argyrios Kyrtzidis
b62bd0c086 [USRGeneration] For clang macro USRs, use the more general API that doesn't require a PreprocessingRecord. 2017-02-02 10:24:57 -08:00
Xi Ge
6b699d8855 SourceEntityWalker: keep track of type reference in extension declarations' openings. (#7192)
This is necessary when we want to differentiate between type reference
on extension declaration's start, e.g "extension A {}", and other
references of "A". NFC on existing functionality.
2017-02-01 17:09:01 -08:00
Doug Gregor
f7f703ad04 [Archetype builder] Canonicalize and minimize same-type constraints.
Introduce an algorithm to canonicalize and minimize same-type
constraints. The algorithm itself computes the equivalence classes
that would exist if all explicitly-provided same-type constraints are
ignored, and then forms a minimal, canonical set of explicit same-type
constraints to reform the actual equivalence class known to the type
checker. This should eliminate a number of problems we've seen with
inconsistently-chosen same-type constraints affecting
canonicalization.
2017-02-01 10:51:02 -08:00
Jordan Rose
cde35430c6 Fix ParameterList::clone to handle deserialized defaults arguments. (#7156)
It was checking the wrong predicate, and therefore failing to mark
inherited default arguments as actually being inherited.

While here, explicitly clear out default arguments from non-inherited
cloned parameter lists. I don't think this case can come up today, but
it's better to be correct when we do hit it.

rdar://problem/30167924
2017-01-31 16:30:01 -08:00
Slava Pestov
b3cabb0745 Use llvm casts in various places instead of looking at {Expr,Decl,TypeBase}::getKind()
Also add some FIXMEs for some code in debug info emission that
looks incorrect.
2017-01-30 00:08:53 -08:00
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00
Slava Pestov
7da7651345 Sema: Fix assertion failure in typo correction with static base
For some reason we weren't desugaring the base type, so the
metatype check would fail.
2017-01-28 18:35:25 -08:00
Slava Pestov
45a19ddf2d Sema: Fix assertion failures with UnresolvedType in diagnostics
We sometimes construct DependentMemberTypes with an UnresolvedType
base. These are not "real" interface types and can end up in
places where we don't expect interface types, triggering an
assertion. Make sure such types don't respond true to hasTypeParameter().
2017-01-28 18:35:23 -08:00
Argyrios Kyrtzidis
51bdd6f09b Merge pull request #7117 from akyrtzi/index-module-global-var
[index] Fix indexing of global variables from serialized module files.
2017-01-27 18:35:22 -08:00
Argyrios Kyrtzidis
86f638558b [index] Fix indexing of global variables from serialized module files. 2017-01-27 16:23:38 -08:00
Slava Pestov
1b92e72ab1 AST: Fix Type::join() to do the right thing with class metatypes
Fixes <rdar://problem/30233451>.
2017-01-27 13:18:15 -08:00
Jordan Rose
1cf1961fc7 Merge pull request #7007 from jrose-apple/accessor-argument-labels
[Importer] Preserve argument labels even for accessors.
2017-01-27 11:18:44 -08:00
Hugh Bellamy
d17b6daef6 Fix recently introduced control path warnings with Clang
> warning: control may reach end of non-void function [-Wreturn-type]
2017-01-27 11:52:26 +00:00
Slava Pestov
f9789ce5a8 AST: Fix compareDependentTypes() for protocol typealiases
We must order protocol typealiases *after* other types, so that
if a protocol typealias is equal to an associated type, the
representative is chosen to be the associated type and not the
typealias.

Fixes <https://bugs.swift.org/browse/SR-3687> and
<rdar://problem/30118513>.
2017-01-26 21:33:25 -08:00
Slava Pestov
0efa3fb849 AST: Better assertions to catch ErrorTypes in bad places 2017-01-26 21:20:05 -08:00
swift-ci
bfff1c884f Merge pull request #6922 from atrick/silconv 2017-01-26 16:35:08 -08:00
Nathan Hawes
f2c99d22e2 Merge pull request #7056 from nathawes/rdar30118572
[indexer] Fix crash in initVarRefIndexSymbols by handling references from 'import var ...'
2017-01-26 16:14:37 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Nathan Hawes
8ccccc6f74 [indexer] Fix crash in initVarRefIndexSymbols by handling func/var references in ImportDecls
IndexSwiftASTWalker::initVarRefIndexSymbols wasn't handling getCurrentExpr() returning a nullptr
as it does when processing a reference to someVar in the below import:
import var SomeModule.someVar

This patch fixes rdar://problem/30118572 and adds tests for import var/func references.
2017-01-26 09:15:42 -08:00
Doug Gregor
9b99d26d0e Merge pull request #7029 from huonw/protocol-self-signature
[AST] Introduce the notion of a protocol requirement signature.
2017-01-25 20:55:52 -08:00
Huon Wilson
a964b6ad78 [AST] Introduce the notion of a protocol requirement signature.
This is a generic signature that stores exactly the requirements that a
protocol decl introduces, not letting them be implied by the Self :
Protocol requirement, nor storing any requirements introduced by the
protocols requirements.

Specifically, suppose we have

    protocol Foo {}
    protocol Bar {}

    protocol Baz {
        associatedtype X : Foo
    }
    protocol Qux: Baz {
        associatedtype X : Bar
    }

The normal generic signature and (canonical) protocol requirement
signature of `Baz` will be, respectively

    <Self where Self : Baz>
    <Self where Self : Baz, Self.X : Foo>

And for `Qux`, they will be:

    <Self where Self : Qux>
    <Self where Self : Qux, Self : Baz, Self.X : Bar>

Note that the `Self.X : Foo` requirement is not listed.

For the moment, this is unused except for `-debug-generic-signatures`.
2017-01-25 16:06:50 -08:00
Jordan Rose
98ead6bf04 [Verifier] Always check function DeclName / ParamDecl matches. 2017-01-25 13:44:24 -08:00
Doug Gregor
6bcfce5f00 [AST] Teach SubstitutionMap::lookupConformance to search parent conformances.
Conformances for an associated type might be attached to any
same-named associated type of the parent, so search those as
well. Overally, this is a fairly expensive search, and there is likely
a better architectural solution that will require some refactoring of
SubstitutionMap.
2017-01-24 19:36:44 -08:00
Doug Gregor
51fbd297bc [AST] Prefer concrete to abstract conformances in SubstitutionMap's lookup. 2017-01-24 19:36:44 -08:00
Doug Gregor
d3c7a71f85 [AST] Factor the search for conformances more cleanly. NFC 2017-01-24 19:36:44 -08:00
Doug Gregor
227919a97e [AST] Add SubstitutionMap::dump() debugging utility 2017-01-24 19:36:44 -08:00
Doug Gregor
200d7d77f1 [Archetype builder] Infer same-type constraints for same-named associated types.
When two associated types with the same name are on the same dependent
type T, introduce a same-type constraint between the the corresponding
potential archetypes. This eliminates ordering dependencies in the
archetype builder.

Fixes the reduced test case from rdar://problem/23149063, but doesn't
fully address the idea that we should be tracking associated type
redeclarations in a meaningful way.
2017-01-24 19:36:44 -08:00
Doug Gregor
56a016c748 [Archetype builder] Sink archetype anchor helpers down into static functions.
NFC
2017-01-24 19:36:44 -08:00
Doug Gregor
e4d6118adb [Archetype builder] Remove an anachronism. NFC.
We no longer adopt outer archetypes as concrete types, so this check
always returned true.
2017-01-24 19:36:44 -08:00
Doug Gregor
1f9406915b [Archetype builder] Make the "archetype anchor" use a total order.
Make the "archetype anchor" algorithm use the same total order used to
compare dependent types in a generic signature, so that it is a
dependable total order. Tighten up the compareDependentTypes() logic
(and checking of it) a bit now that it's being used more frequently.

The weird code around GenericSignature::isCanonicalTypeInContext() is
due to a longstanding issue where

  ArchetypeBuilder::resolveArchetype(t)->getDependentType()

is not the identity function when the incoming type is a
DependentMemberType with known associated types. We want to establish
this behavior at some point going forward, in which case we can go
back to the prior implementation of
GenericSignature::isCanonicalTypeInContext().
2017-01-24 19:36:44 -08:00
Erik Eckstein
a56a97c89f Mangling: prepare for using new mangling for USR and debug-info type generation.
Select between old and new mangling as we already do in other places in the compiler.
NFC as long as the new mangling is not enabled yet.
2017-01-23 17:49:00 -08:00
Rintaro Ishizaki
571804b02e [ASTDumper] print 'trailing_semi' for Expr, Stmt, and Decl if they have valid 'TrailingSemiLoc' 2017-01-23 13:45:41 +09:00
practicalswift
7e48c04277 [gardening] Fix inconsistent headers. 2017-01-21 10:59:10 +01:00
practicalswift
157fa60371 [gardening] Fix invalid Swift URLs. 2017-01-21 10:33:27 +01:00
practicalswift
849b27b406 [gardening] Fix recently introduced \t 2017-01-21 10:31:33 +01:00