Commit Graph

1958 Commits

Author SHA1 Message Date
Joe Groff
e1c838962e Revert "Remove [objc_block] attribute from Swift type system."
Implementing SIL bridging is going to take more IRGen work than I anticipated.

Swift SVN r5113
2013-05-09 16:32:18 +00:00
Jordan Rose
ccae995f61 Use a list of module loaders instead of a single Clang importer.
This paves the way for having a Swift module importer. The eventual goal
here is to eliminate all explicit uses of the Clang module loader, but
I'm not going to push too hard on that for now.

Swift SVN r5092
2013-05-08 18:09:33 +00:00
Joe Groff
38f13e56f5 Remove [objc_block] attribute from Swift type system.
We will handle Swift-function-to-ObjC-block bridging in SILGen as part of general Cocoa-to-Swift type bridging. Temporarily disable building swiftAppKit and tests that exercise block bridging until the new implementation lands.

Swift SVN r5090
2013-05-08 16:52:12 +00:00
Joe Groff
c75e1bb048 Sema: Correctly set parent type of local types looked up in context.
When an IdentifierType is resolved to a local type in the same decl context, we weren't setting the parent type correctly, causing blowups in type checking when a local type didn't have its generic parameters from context available. Set the parent type to the DeclaredTypeInContext of the type to which we resolved an unqualified lookup. Fixes <rdar://problem/12895793>.

Swift SVN r5084
2013-05-08 00:34:36 +00:00
Doug Gregor
0f6b7a9d22 Rework our handling of "external" definitions created by the Clang importer.
Keep track of external definitions as they are created by broadcasting
them through a mutation listener interface. At name binding time, we
just cache them. When a type checker is alive, it immediately performs
any additional operations necessary on those types (e.g., declaring
implicit constructors).

This also eliminates some O(N^2) behavior in the type checker as well,
because we don't have to walk through all of the module imports to
find the external definitions. We just keep a single list in the
ASTContext along with our place in the list.

Fixes <rdar://problem/13769497>.


Swift SVN r5032
2013-05-03 00:24:34 +00:00
Joe Groff
aa6c506f58 Add '[thin]' attribute to function types.
Some SIL operations only make sense on no-context functions, such as creating a context for a function with "curry" or specializing. We're going to need this concept in Swift for interop with C functions too, so I'm adding it to the Swift type system. This patch only adds the attribute bit to function types without exposing the attribute to Swift syntax or providing any means in Swift to produce values of thin function type or to type-check them.

Swift SVN r4416
2013-03-18 19:59:39 +00:00
Doug Gregor
a9a90fd56a Track the Clang macros that were used to generate Swift constants.
Swift SVN r3960
2013-02-06 00:57:03 +00:00
Joe Groff
30e715f633 AST: Hack in an '[objc_block]' FunctionType attr.
For the demo we'll import block types as [objc_block] (A) -> B types in Swift and rely on the type attribute to handle bridging Swift closures to ObjC blocks.

Swift SVN r3895
2013-01-29 22:38:21 +00:00
Joe Groff
0422897a47 Expose %swift.opaque as a builtin type.
Archetypes and projected existentials have the type %swift.opaque* and not i8*, so I need a corresponding SIL type to be able to model the ProjectExistential operation. We might also end up needing the builtin type for other low-level things down the line.

Swift SVN r3793
2013-01-18 02:24:23 +00:00
Doug Gregor
83f2874ba1 Implement support for calling imported C functions from Swift.
There is no protection whatsoever if the Clang-to-Swift type
conversion produces something that Swift doesn't lower in an
ABI-compatible way. That will be dealt with later.


Swift SVN r3249
2012-11-27 00:34:48 +00:00
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00
Doug Gregor
2183b57fa4 Introduce a special memory arena in ASTContext for the type checker.
This introduces the notion of arenas into ASTContext, with two arenas
currently defined: one for 'permanent' storage, and another for the
current constraint checker. The latter is used when allocating any
types that involve type variables, which are only used temporarily
during type checking anyway.

This gives us a 1% speedup on swift.swift (because we're hitting
smaller hash tables when doing lookups) and < 1% memory reduction
(since that's not the main source of memory usage). It's more
important architecturally, so our memory usage doesn't grow with the
number of type-checks performed.

Note also that this arena scheme could be generalized, which we may
very well want to do in the future. For example, we could easily have
an arena for temporary nodes introduced by parsing (e.g.,
UnresolvedDeclRefExpr) or by name binding (OverloadedDeclRefExpr), and
clear that arena when we successfully move onto the next phase. Or, in
a REPL/debugger context, have a 'temporary' arena for
statements/expressions that can be removed.



Swift SVN r3175
2012-11-14 06:57:16 +00:00
John McCall
24d819e133 Split BoundGenericType into BoundGeneric{Class,OneOf,Struct}Type.
We'll want a superclass pointer on ClassType and BoundGenericClassType,
and this also makes it easier to detect both kinds of class type.

Swift SVN r3061
2012-10-25 21:44:44 +00:00
Eli Friedman
77c0114186 Make sure TupleType::get never returns an invalid TupleType.
Finishes off <rdar://problem/12337042>.

Also, fix constraint application so that test/Constraints/closures.swift
doesn't explode with the above fix.



Swift SVN r2888
2012-09-21 01:54:26 +00:00
Doug Gregor
42b1ab6fbd Introduce a LangOptions class to capture various type-checker-tweaking flags. For now, introduce bits to enable the constraint solver and to enable debugging of the constraint solver, and use those to eliminate the "useConstraintSolver" bit that was threaded through too much of the type checker.
Swift SVN r2836
2012-09-12 20:19:33 +00:00
Doug Gregor
9d315ae72a Keep track of whether a given type involves a type variable.
Swift SVN r2705
2012-08-22 00:24:22 +00:00
Doug Gregor
531583e2d1 Implement support for nested generics in the AST and type
checker. There are a few related sets of changes here:

  - Generic parameter lists have a link  to their "outer" generic
  parameter lists, so its easy to establish the full generic context
  of an entity.
  - Bound and unbound generic types now carry a parent type, so that
  we distinguish between, e.g., X<Int>.Inner<Int> and
  X<Double>.Inner<Int>. Deduction, substitution, canonicalization,
  etc. cope with the parent type.
  - Opening of polymorphic types now handles multiple levels of
  generic parameters when needed (e.g., when we're substituting into
  the base).

Note that the generics module implied by this representation restricts
what one can do with requirements clauses in nested generics. For
example, one cannot add requirements to outer generic parameters or
their associated types, e.g., this is ill-formed:

  struct X<T : Range> {
    func f<U requires T.Element : Range>() {}
  }

The restriction has some precedent (e.g., in C#), but could be
loosened by rearchitecting how we handle archetypes in nested
generics. The current approach is more straightforward.


Swift SVN r2568
2012-08-06 19:02:06 +00:00
Doug Gregor
532737205b Improve checking of protocol-conformance requirements for generic
types in a few ways:
  - Actually check the extra requirements placed on associated types,
  e.g., "T.Element : Ordered"
  - Actually encode/store the protocol conformance information for a
  BoundGenericType in the same way that we do for SpecializeExpr,
  GenericMemberRefExpr, and GenericSubscriptExpr. Yay, consistency.
  - Move the storage for the protocol conformance information into a
  DenseMap in the ASTContext indexed by canonical BoundGenericType, so
  it doesn't require inline storage in BoundGenericType.


Swift SVN r2517
2012-08-03 00:41:32 +00:00
Doug Gregor
3eed1fbafd Generalize the substitution of a "base type" into a reference to a
member of a oneof/struct/class/extension to support types nested
within generic classes, e.g., Vector<Int>.ElementRange. 

Most importantly, nominal types are no longer inherently canonical. A
nominal type refers to both a particular nominal type declaration as
well as its parent, which may be non-canonical and will vary. For
example, the variance in the parent makes Vector<Int>.ElementRange and
Vector<Float>.ElementRange different types. 

Introduce deduction and substitution for nominal types. Deduction is
particular interesting because we actually do allow deduction of T
when comparing X<T>.Inner and X<Int>.Inner, because (unlike C++) there
is no specialization to thwart us.



Swift SVN r2507
2012-08-02 21:22:44 +00:00
Doug Gregor
e27d65f199 Introduce a "parent' context into oneof, struct, and class types. The
parent context encodes the generic arguments for outer generic types,
so that X<Int>.Nested and X<Float>.Nested are distinct types.


Swift SVN r2502
2012-08-01 23:20:36 +00:00
Eli Friedman
0f4d49385c Remove SourceLoc from ArraySliceType.
Swift SVN r2425
2012-07-24 06:29:36 +00:00
Eli Friedman
d6a4ba90dd Move TypeLocs to a design where a TypeLoc is a struct containing a type plus
location info for that type.  Propagate TypeLocs a bit more through the AST.



Swift SVN r2383
2012-07-20 21:00:30 +00:00
Eli Friedman
7330aca582 Start propagating TypeLocs into TypeChecker::validateType.
Swift SVN r2373
2012-07-19 03:40:30 +00:00
Eli Friedman
f1f67db652 Big cleanup for how we handle computing types for functions and semantic
analysis for patterns.

Major changes:
1. We no longer try to compute the types of functions in the parser.
2. The type of a function always matches the type of the argument patterns.
3. Every FuncDecl now has a corresponding FuncExpr; that FuncExpr might not
   have a body, though.
4. We now use a new class "ExprHandle" so that both a pattern and a type
   can hold a reference to the same expression.

Hopefully this will be a more reasonable foundation for further changes to
how we compute the types of FuncDecls in generics and for the implementation
of type location information.



Swift SVN r2370
2012-07-19 02:09:04 +00:00
Eli Friedman
6a4098b102 Mess with the way we do canonicalization for ProtocolCompositionTypes in a way
that doesn't violate canonical type invariants.  It's still a little messy,
but it's consistent.  Fixes <rdar://problem/11886926>.



Swift SVN r2368
2012-07-18 01:31:40 +00:00
Doug Gregor
be55c18fcf Check that the arguments in a bound generic type conform to the
protocol requirements of that type, and capture that
protocol-conformance information in the canonical bound generic type.


Swift SVN r2322
2012-07-09 19:52:59 +00:00
Eli Friedman
a54c5493da Per discussion with Doug, add UnboundGenericType and BoundGenericType to represent generic types.
Swift SVN r2304
2012-07-04 01:17:16 +00:00
Eli Friedman
99fac3aaa8 Change MetaTypeType so that the instance type is actually a Type, not a TypeDecl*.
Swift SVN r2301
2012-07-03 23:12:19 +00:00
Eli Friedman
2268f7155d Introduce UnresolvedNominalType to represent a generic type without an argument list, and add an argument list to NominalType to represent a generic type including an argument list.
Swift SVN r2299
2012-07-03 22:15:02 +00:00
Doug Gregor
bac5470881 Collate the OneOfType*/ClassType*/StructType*/ProtocolType* members of
the various NominalDecl subclasses into a single NominalType* member
in NominalDecl. Use it to make TypeDecl::getDeclaredType() more
efficient/simpler, and simplify the ProtocolDecl/ProtocolType
interaction along the way.

No functionality change.


Swift SVN r2298
2012-07-03 21:46:52 +00:00
Doug Gregor
04ffc8c432 Introduce a new abstract type, SubstitutableType, to cover types that
can be substituted, and do some simply renaming to distance ourselves
from archetypes in these code paths.


Swift SVN r2295
2012-07-03 17:37:27 +00:00
Eli Friedman
01e7041600 Misc fixes on top of John's PolymorphicFunctionType patch.
Swift SVN r2256
2012-06-27 02:23:38 +00:00
John McCall
668f674bfa Split off a PolymorphicFunctionType from FunctionType. I am
*positive* that the behavior here is blatantly wrong in a lot
of places, but I'm going to leave it to Doug to clean up after me. :)

Swift SVN r2255
2012-06-27 00:22:15 +00:00
Doug Gregor
c079874625 Implement parsing, AST, type canonicalization, and type validation for
protocol conformance types, e.g., 'protocol<P, Q>'. A few things
people *might* want to scream about, or at least scrutinize:

  - The parsing of the '<' and '>' is odd, because '<' and '>' aren't
    tokens, but are part of the operator grammar. Neither are '>>',
    '>>>', '<>', etc., which also come up and need to be parsed
    here. Rather than turning anything starting with '<' or '>' into a
    different kind of token, I instead parse the initial '<' or '>'
    from an operator token and leave the rest of the token as the
    remaining operator.
  - The canonical form of a protocol-composition type is minimized by
    removing any protocols in the list that were inherited by other
    protocols in the list, then sorting it. If a singleton list is
    left, then the canonical type is simply that protocol type.
  - It's a little unfortunate that we now have two existential types
    in the system (ProtocolType and ProtocolCompositionType), because
    many places will have to check both. Once ProtocolCompositionTypes
    are working, we should consider whether it makes sense to remove
    ProtocolType.

Still to come: name lookup, coercions.



Swift SVN r2066
2012-05-30 00:39:08 +00:00
Doug Gregor
9096497f0f Rename "dependent type" to "unresolved type" universally. We've been
using the term "unresolved" in expressions for a while, and it fits
for types better than "dependent type."

The term "dependent type" will likely come back at some point to mean
"involves an archetype".



Swift SVN r1962
2012-05-23 19:03:14 +00:00
Doug Gregor
8e1cd3990b Implement substitution of types, which substitutes concrete types for
archetypes. Use this substitution when checking the
variable/function/subscript witnesses during protocol conformance.

This allows us to check the conforms-to relationship for the Range
protocol as we want to express it.


Swift SVN r1945
2012-05-23 00:39:06 +00:00
Doug Gregor
b1f1e1430d Introduce NominalType as a base class of
OneOfType/StructType/ClassType/ProtocolType, an eliminate the
ridiculous chained ifs that used to check for most (or all) of these.


Swift SVN r1923
2012-05-22 00:13:59 +00:00
John McCall
38bac7c706 Add Builtin.ObjCPointer with accompanying IR-gen support and
wrap it in an 'id' type in the standard library.

Also fix a bug noticed by inspection where initWithTake for
function types wasn't entering a cleanup for the taken value.
This probably doesn't matter for existing possibilities, but
it's potentially important under exceptions.

Swift SVN r1902
2012-05-18 23:40:17 +00:00
John McCall
71c45f5212 Lion's libc++ headers do not support shared_ptr under -fno-rtti.
This is <rdar://problem/10217868>.  Apparently I'm using Lion's
libc++ headers somehow, which I should probably fix;  but since
the use of shared_ptr is just a hack until DenseMap supports
move-only types, I don't feel bad about changing it to a different
hack that avoids shared_map altogether.

Swift SVN r1897
2012-05-18 10:01:54 +00:00
Eli Friedman
099a97847d Parsing and AST support for varargs tuples.
Swift SVN r1875
2012-05-16 22:02:01 +00:00
Eli Friedman
a5a39860cd Basic parsing plus a bit more of the AST for ClassDecls.
Swift SVN r1860
2012-05-15 22:07:31 +00:00
Eli Friedman
790687e025 Don't try to unique TupleTypes with default values.
Swift SVN r1844
2012-05-15 00:15:43 +00:00
Eli Friedman
77fa49ec2b Introduce StructDecl and StructType; use them for structs instead of OneOfDecl/OneOfType. To keep this patch small, I'm leaving in LookThroughOneOf etc. for the moment, but that's next on the agenda.
Swift SVN r1780
2012-05-09 00:27:44 +00:00
Doug Gregor
5f2344afe0 Introduce ProtocolDecl, which describes (*gasp*) a protocol. Move the
guts of ProtocolType over to ProtocolDecl.


Swift SVN r1778
2012-05-08 23:28:55 +00:00
Eli Friedman
4ca443d0f5 Add OneOfDecl; use it as a DeclContext for OneOfElementDecls instead of OneOfType, and get rid of the implicit TypeAliasDecl. Add TypeDecl as a base class for OneOfDecl and TypeAliasDecl (and StructDecl, once we have it). Adjust a whole bunch of stuff to this new scheme.
Swift SVN r1774
2012-05-08 21:09:42 +00:00
John McCall
6133630544 When type-checking a slice type, "desugar" it to a type that is
generic over the type of the base.  By "generic" I mean that it's
looked up by prepending the word "Slice" to the name of the base
type.

Swift SVN r1464
2012-04-18 08:09:10 +00:00
Chris Lattner
65b400e30d introduce a new "Builtin.RawPointer" type, which corresponds to LLVM's "i8*" type,
and is just an unmanaged pointer.  Also, introduce a basic swift.string type.

This is progress towards rdar://10923403 and strings.  Review welcome.



Swift SVN r1349
2012-04-10 00:52:52 +00:00
Doug Gregor
f370accf59 Introduce the notion of structured dependent types, such as a tuple
type with one or more elements of dependent type. Previously, an
expression such as (x, 5) would have the (unstructured) dependent
type, limiting our ability to type-check the subexpression 'x'
early. Now, if 'x' has type 'int' (for example), this expression will
now have the type (int, <<unstructured dependent type>>).

Extend coercion of a tuple to tuple type to handle coercion to
(structured) dependent tuple types, coercing element-by-element. This
code is very lightly tested and may still need to be restructured.




Swift SVN r1294
2012-03-29 16:26:04 +00:00
Doug Gregor
4cc616f2be Rename the DependentType class to UnstructuredDependentType, because
this type is only going to cover dependent types for which there is
absolutely no structure. Still no functionality change.


Swift SVN r1292
2012-03-29 14:14:48 +00:00
John McCall
1f118dbda6 Basic support for Builtin.ObjectPointer as a completely
opaque type.  Also some rudimentary support for retain/release.

Swift SVN r1214
2012-03-16 09:26:32 +00:00