Commit Graph

733 Commits

Author SHA1 Message Date
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Bob Wilson
fbc6a28472 Use llvm::MD5::stringifyResult to get a hash string.
llvm r298322 broke the Swift master-next build because it changed MD5Result
to be a struct and not just an array. Rather than a superficial patch to
extract the array, this changes the code to use llvm's stringifyResult
function, which basically addresses one of the FIXMEs in that code.
2017-03-21 10:36:52 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Alex Hoppen
dd1c661c16 Merge pull request #8015 from ahoppen/isOperator-gardening
[Gardening] Change calls of getName().isOperator() to isOperator()
2017-03-10 21:10:33 +00:00
Alex Hoppen
1b7055db5a [Gardening] Change calls of getName().isOperator() to isOperator() 2017-03-10 09:06:20 +00:00
Slava Pestov
2777c9b478 AST: Remove TypeBase::gatherAllSubstitutions() 2017-03-08 13:54:31 -08:00
Slava Pestov
c040c71ea9 AST: Remove some unnecessary SubstitutionList copies
ASTContext::getSpecializedConformance() already copies the
substitutions, so remove some AllocateCopy() calls.

Also, add a new overload taking a SubstitutionMap instead.
This allows removing some gatherAllSubstitutions() calls,
which have an allocation inside them.

Finally, remove the now-unused ModuleDecl parameter from
ProtocolConformance::subst() and make it public.
2017-03-07 15:59:05 -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
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -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
practicalswift
849b27b406 [gardening] Fix recently introduced \t 2017-01-21 10:31:33 +01:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Hugh Bellamy
cd8427ed41 Fix MSVC static assertion failue 2017-01-19 08:50:46 +00:00
Hugh Bellamy
201ad5d594 Prefix COMPILER_IS_MSVC with SWIFT_ 2017-01-16 22:09:53 +00:00
Hugh Bellamy
cf777d04f5 Introduce and use COMPILER_IS_MSVC 2017-01-15 15:17:18 +00:00
Hugh Bellamy
7a5ef4bdd1 Support building swift/AST with MSVC on Windows 2017-01-09 09:05:06 +00:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
e4abdfc2bd AST: Model protocols nested inside other types
We might allow protocols inside non-generic class/struct/enum
declarations eventually; there's no conceptual difficulty, just
some IRGen and Serialization work that has to happen first.

Also, this fixes a crasher :-)
2017-01-04 00:10:29 -08:00
Slava Pestov
2b05dd9d85 AST: Remove error path that was causing crashes 2017-01-04 00:10:28 -08:00
Slava Pestov
b6d8bbb698 AST: Return abstract conformance for UnresolvedType
We "fake" a conformance of UnresolvedType to any protocol.
Instead of returning a concrete conformance, return an
abstract conformance. The concrete conformance had several
problems leading to further crashes:

- The DC was set to a module, not a type declaration context,
  since there is not type declaration context here.

- The conformance was marked complete even though it was missing
  inherited conformances.
2017-01-04 00:10:28 -08:00
Slava Pestov
7e1bc3c980 AST: Fix calls to protocol extension methods from class methods returning 'Self'
Here, the 'self' value has a dynamic Self type, which we must strip
off when performing the conformance lookup.

Fixes <https://bugs.swift.org/browse/SR-2696>.
2017-01-03 20:13:43 -08:00
Slava Pestov
caa7045ae5 AST: Remove unnecessary ModuleDecl parameter from GenericSignature::getSubstitutions() 2016-12-22 14:33:00 -05:00
Slava Pestov
ed19f2cbe9 AST: Fix gatherAllSubstitutions() for recent change to not adopt archetypes from context
This could lead to verifier failures on invalid nesting of
generic types in generic functions.
2016-12-19 18:49:57 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Slava Pestov
2c6b9f71b6 AST: Change TypeAliasDecls to store an interface type as their underlying type
- TypeAliasDecl::getAliasType() is gone. Now, getDeclaredInterfaceType()
  always returns the NameAliasType.

- NameAliasTypes now always desugar to the underlying type as an
  interface type.

- The NameAliasType of a generic type alias no longer desugars to an
  UnboundGenericType; call TypeAliasDecl::getUnboundGenericType() if you
  want that.

- The "lazy mapTypeOutOfContext()" hack for deserialized TypeAliasDecls
  is gone.

- The process of constructing a synthesized TypeAliasDecl is much simpler
  now; instead of calling computeType(), setInterfaceType() and then
  setting the recursive properties in the right order, just call
  setUnderlyingType(), passing it either an interface type or a
  contextual type.

  In particular, many places weren't setting the recursive properties,
  such as the ClangImporter and deserialization. This meant that queries
  such as hasArchetype() or hasTypeParameter() would return incorrect
  results on NameAliasTypes, which caused various subtle problems.

- Finally, add some more tests for generic typealiases, most of which
  fail because they're still pretty broken.
2016-12-15 22:46:15 -08:00
Joe Groff
ccfabd1118 Make LookupConformanceFn callbacks return Optional<ProtocolConformanceRef>.
NFC yet, but this is a step toward centralizing error handling policy for failed conformance lookups instead of leaving it ad-hoc.
2016-12-14 18:04:35 -08:00
Michael Gottesman
1af1cbfb76 [gardening] Add a bunch of end namespace comments found by clang-tidy. 2016-12-06 19:22:52 -08:00
Slava Pestov
9caaad442b AST: Don't call hasType()/getType()/setType() on TypeDecls 2016-12-01 13:00:19 -08: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
Slava Pestov
c5b461924a AST: Don't canonicalize types when caching substitutions
This causes us to lose sugar in some cases; needed for the next patch.
2016-11-26 01:30:32 -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
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
Doug Gregor
85ba4fe40f [AST] Narrow TypeSubstitutionMap to SubstitutableType keys.
Type substitution works on a fairly narrow set of types: generic type
parameters (to, e.g., use a generic) and archetypes (to map out of a
generic context). Historically, it was also used with
DependentMemberTypes, but recent refactoring to eliminate witness
markers eliminate that code path.

Therefore, narrow TypeSubstitutionMap's keys to SubstitutableType,
which covers archetypes and generic type parameters. NFC
2016-11-15 11:34:09 -08:00
Doug Gregor
6bfd219e14 [AST] Separate GenericEnvironment's representation from its interface. 2016-11-14 21:44:58 -08:00
Jordan Rose
a7b027df92 Merge pull request #4579 from aleksgapp/sr-2209-access-scope
[SR-2209] Add real AccessScope type.
2016-11-11 11:16:12 -08:00
Doug Gregor
4cadee421b Handle nested generic extensions in TypeBase::gatherAllSubstitutions().
The code in TypeBase::gatherAllSubstitutions() walks a declaration
context and type to form a complete set of substitutions for a
(nested) type. When provided with a context for a nested
extension---e.g., "extension OuterGeneric.InnerGeneric", it would skip
over OuterGeneric due to the lexical nesting of DeclContexts not
matching the semantic nesting.

Teach this function to determine the type parameters without walking DeclContexts.
2016-11-06 01:48:26 -08:00
Aleksey Gaponov
f51b2d12c4 [SR-2209] Make a real AccessScope class and use it in access checking.
1. Add new AccessScope type that just wraps a plain DeclContext.
2. Propagate it into all uses of "ValueDecl::getFormalAccessScope".
3. Turn all operations that combine access scopes into methods on AccessScope.
4. Add the "private" flag to distinguish "private" from "fileprivate"
scope for top-level DeclContext.
2016-11-04 12:42:38 +01:00
Doug Gregor
ab959c9f21 Introduce TypeBase::isTypeVariableOrMember(). NFC
Similar to “isTypeParameter,” this new entry point determines whether the type is a type variable or a nested type of a type thereof. The latter case isn’t actually formed yet, so this is NFC staging the trivial bits of this change.
2016-10-11 11:38:52 -07: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
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Slava Pestov
c28529315b AST: Tweak conformance lookup for class-constrained archetypes
The comment explains the situation; now that we drop protocol
conformance requirements that are made redundant by a superclass
requirement, we necessarily have to prefer returning a concrete
conformance here rather than an abstract one, because an
abstract one will not be fulfilled by a substitution that
makes the archetype concrete, since there's no explicit
conformance requirement to fulfill.
2016-09-06 11:51:12 -07:00
Slava Pestov
fbe9573598 AST: Add some utility methods to GenericSignature
These will be more useful once substitutions in protocol conformances
are moved to use interface types.

At first, these are only going to be used by the SIL optimizer.
2016-09-06 11:51:12 -07:00
Doug Gregor
4e214687ca [WIP Name binding] Introduce a basic 'scope map' to model scopes in the AST.
The scope map models all of the name lookup scopes within a source
file. It can be queried by source location to find the innermost scope
that contains that source location. Then, one can follow the parent
pointers in the scope to enumerate the enclosing scopes.

The scope map itself is lazily constructed, only creating scope map
nodes when required implicitly (e.g, when searching for a particular
innermost scope) or forced for debugging purposes.

using a lazily-constructed tree that can be searched by source
location. A search within a particular source location will
2016-09-02 17:13:05 -07:00
Slava Pestov
ca0b548584 SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
2016-08-28 13:51:37 -07:00
Slava Pestov
410062ba66 AST: Refactor Type::gatherAllSubstitutions() to use GenericSignature::getSubstitutions(), NFC
This removes a pile of getAll{Nested,}Archetypes() usages and
greatly simplifies the logic here.
2016-08-22 10:45:50 -07:00
Slava Pestov
b671b9f5d5 AST: gatherAllSubstitutions() no longer passes IgnoreMissing
It seems we passed this flag in from the very start, when this
code was added in 2013. It no longer appears to make a difference
though, since I think other bugs that were causing us to miss
archetypes here are now fixed.
2016-08-22 10:45:50 -07:00