Commit Graph

521 Commits

Author SHA1 Message Date
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
David Farler
3034b0139c Merge pull request #3833 from bitjammer/dsohandle-multi-file-26565092
[SILGen] Directly silgen access of #dsohandle
2016-07-29 15:55:31 -07:00
David Farler
3c11665d56 [SILGen] Directly silgen access of #dsohandle
Synthesizing a VarDecl for #dsohandle causes some unwanted accessors to
be expected, but we really don't need them: this is a global variable
for the start of the image. There are only two uses of getDSOHandle:
getting the type and emitting the SIL for it. Rather than perform
acrobatics to turn off switches, just emit access directly where it's
needed.

rdar://problem/26565092
2016-07-29 12:09:43 -07:00
John McCall
cfd9b83d39 Protect the operator/precedencegroup lookup code against modules that
import themselves.

It's not clear to me whether this situation is really intended, but
this does fix build modules with this strange situation.
2016-07-29 10:50:30 -07:00
Andrew Trick
a18d490d6a Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3773)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 14:21:15 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Andrew Trick
0ed9ee8dee Revert "Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)"
This reverts commit ece0951924.

This results in lldb failues on linux that I can't readily debug.
Backing out until they can be resolved.
2016-07-26 02:50:57 -07:00
Andrew Trick
ece0951924 Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 02:18:21 -07:00
Jordan Rose
508e825ff2 Split 'fileprivate' and 'private', but give them the same behavior.
'fileprivate' is considered a broader level of access than 'private',
but for now both of them are still available to the entire file. This
is intended as a migration aid.

One interesting fallout of the "access scope" model described in
758cf64 is that something declared 'private' at file scope is actually
treated as 'fileprivate' for diagnostic purposes. This is something
we can fix later, once the full model is in place. (It's not really
/wrong/ in that they have identical behavior, but diagnostics still
shouldn't refer to a type explicitly declared 'private' as
'fileprivate'.)

As a note, ValueDecl::getEffectiveAccess will always return 'FilePrivate'
rather than 'Private'; for purposes of optimization and code generation,
we should never try to distinguish these two cases.

This should have essentially no effect on code that's /not/ using
'fileprivate' other than altered diagnostics.

Progress on SE-0025 ('fileprivate' and 'private')
2016-07-25 13:13:35 -07:00
Doug Gregor
211c580158 [Cleanup] Eliminate DerivedFileUnit.
The only client of DerivedFileUnit was synthesized global '=='
operators for Equatable conformances, which has since been removed.
2016-07-21 12:54:27 -07:00
Slava Pestov
bbefeb2fc5 Sema: Better support for nested generic functions
There was a weird corner case with nested generic functions that
would fail in the SIL verifier with some nonsense about archetypes
out of context.

Fix this the "right" way, by re-working Sema function declaration
validation to assign generic signatures in a more principled way.

Previously, nested functions did not get an interface type unless
they themselves had generic parameters.

This was inconsistent with methods nested inside generic types,
which did get an interface type even if they themselves did not
have a generic parameter list.

There's some spill-over in SILGen from this change. Mostly it
makes things more consistent and fixes some corner cases.
2016-06-13 01:22:43 -07:00
Slava Pestov
98a0e73b02 AST: Merge BoundGenericType::getSubstitutions() with TypeBase::gatherAllSubstitutions(), NFC 2016-06-13 00:57:09 -07:00
Slava Pestov
09c57d32c7 AST: Fix some nested generics issues exposed by generic initializer inheritance
BoundGenericType::getSubsitutions() would only look at the bound
generic arguments of the innermost type, ignoring parent types.
However, it would then proceed to walk the AllArchetypes list
of all outer generic parameter lists when forming the final
result.

The gatherAllSubstitutions() would also walk through parent types.
As a result, outer generic parameters would appear multiple
times.

Simplify gatherAllSubstitutions() to just skip to the innermost
BoundGenericType, and delegate to getSubsitutions() for the rest.

Most calls to gatherAllSubstitutions() are from SILGen it seems,
and fix only fixes one compiler_crasher.

However an upcoming patch adds a new call to gatherAllSubstitutions()
which caused some crashers to regress, so I'm going to fix it
properly here.
2016-05-21 12:51:50 -07:00