Commit Graph

2036 Commits

Author SHA1 Message Date
Dmitri Hrybenko
41b5f2486c AST printer: pretty-print import declarations while printing deserialized modules
Swift SVN r11144
2013-12-11 21:48:57 +00:00
Adrian Prantl
1f927d9ffc Overhaul the handling of return locations for auto-generated code.
- change SILGenFunction to use Cleanup and Implicit return locations for
  auto-generated cleanups/returns where sensible.
- Fix a bug in where ConstructorDecl that would return the wrong
  source range.
- Move the expected locations of some errors to the end of the function
  where they should belong.

Fixes <rdar://problem/15609768> Line tables for classes that don't have
init but just initialize ivars are odd

Swift SVN r11086
2013-12-10 19:23:34 +00:00
Joe Groff
0a929d35bb Assert that PolymorphicFunctionTypes don't get used as interface types.
Swift SVN r10989
2013-12-08 00:34:28 +00:00
Joe Groff
7efe2eba90 Lazily borrow the context initializer type as the initializer interface type for non-generic ConstructorDecls.
And assert that we don't try to put a PolymorphicFunctionType in the interface type.

Swift SVN r10988
2013-12-08 00:34:27 +00:00
Joe Groff
864ed38b2f Add getGetterInterfaceType and getSetterInterfaceType methods to property decls.
Swift SVN r10987
2013-12-08 00:34:25 +00:00
Anna Zaks
378a425dba Allow @transparent on computed VarDecls.
Addresses radar://15489270. This is mainly a convenience enhancement.

Swift SVN r10943
2013-12-06 22:10:44 +00:00
Nadav Rotem
cdb7413052 Remove the FIXME and the conditional from Decl.cpp Decl::isTransparent()
Swift SVN r10938
2013-12-06 21:34:59 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Doug Gregor
37a68b7f69 Ensure that we don't end up with interface types that involve type variables.
Swift SVN r10757
2013-12-03 22:14:21 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Joe Groff
969e70ea82 AST: Settable static properties are settable through metatype bases.
Swift SVN r10396
2013-11-13 00:34:45 +00:00
Joe Groff
4c333d8071 AST: Accessors of static properties must be static functions.
Build the getter and setter of a static property as static func decls, and add a verifier check that the static-ness of a var and its accessors match up.

Swift SVN r10395
2013-11-13 00:28:52 +00:00
Joe Groff
4f2adbe7ed AST: Include 'static' bit in VarDecls.
And track the 'static' SourceLoc in the PatternBindingDecl. This lets isInstanceMember return the right thing for static vars.

Swift SVN r10369
2013-11-12 06:16:48 +00:00
Dmitri Hrybenko
de2064a83f @objc diagnostics: highlight source range of the variable type
Introduced VarDecl::getTypeSourceRangeForDiagnostics(), which is not precise
right now; it just highlights the type source range of the typed pattern.
Filed rdar://15441111 to improve it in future.


Swift SVN r10344
2013-11-11 22:07:56 +00:00
Doug Gregor
eb7ce396db Use VarDecl::get[GS]etterType() and SubscriptDecl::get[GS]etterType() in SILGen
Eliminate SILGen's own computation of getter/setter types in favor of
the AST methods to compute the same.


Swift SVN r9992
2013-11-06 06:53:13 +00:00
Doug Gregor
d79b1758c1 Add getter/setter type computations to VarDecl and SubscriptDecl.
Use the getter type computation for dynamic subscript references so
that we can handle optional subscripts in protocols properly.


Swift SVN r9975
2013-11-05 23:31:13 +00:00
Doug Gregor
84a4c08f1d Factor the computation of the 'self' type into an easier-to-use place.
Swift SVN r9973
2013-11-05 22:51:17 +00:00
Doug Gregor
0107e36e8b Allow models to omit witnesses for optional protocol requirements.
Swift SVN r9962
2013-11-05 16:28:34 +00:00
Doug Gregor
f7e285d9b3 Revert r9937; getInnermostDeclContext() doesn't do what we need
Swift SVN r9942
2013-11-04 23:44:27 +00:00
Doug Gregor
25b604fe82 getInnermostDeclContext() is already better than getPotentialGenericDeclContext().
Swift SVN r9939
2013-11-04 23:17:43 +00:00
Doug Gregor
ce104ed48b Introduce ValueDecl::getPotentialGenericDeclContext()
This little "find the context where the generic parameters could be"
idiom was copy-pasted in a few places, which is ugly. And if we get
generic subscripts (or some other generic value decl), we'll be sorry.


Swift SVN r9927
2013-11-04 18:21:16 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Doug Gregor
f342493144 Give every declaration an interface type.
For declarations that aren't generic and aren't in a generic context,
the interface type is the same as the normal type.


Swift SVN r9847
2013-10-31 17:38:42 +00:00
Doug Gregor
7b5fc3f3f8 Make the interface types of nominal types be a metatype.
All other interface types for type declarations were already
metatypes, as they should be; this oddity crept in. Kill it before it
causes more confusion.


Swift SVN r9826
2013-10-30 23:40:31 +00:00
Doug Gregor
77264dc10f Give associated type declarations interface types.
This required moving a gross hack from the old archetype-based
type-opening code over to the new, generic type parameter-based
type-opening code. We need the ability to build conformances for types
involving type variables to address this case properly.


Swift SVN r9821
2013-10-30 22:53:28 +00:00
Argyrios Kyrtzidis
e31c93add3 [AST] The ASTContext parameter in FuncDecl::getResultType() is not really needed.
Swift SVN r9798
2013-10-30 17:09:56 +00:00
Dmitri Hrybenko
8218c411ff Don't cache the result of ProtocolDecl::requiresClass() if the type checker did
not calculate the inherited protocols yet


Swift SVN r9774
2013-10-30 00:34:23 +00:00
Doug Gregor
a7664fda78 Clean up the checking of pattern binding declarations.
Eliminate the annoying, rarely-firing "while converting 'var' initial
value to declared type" note. We'll eventually have better ways to
deal with this. Otherwise, no functionality change.


Swift SVN r9677
2013-10-25 21:14:03 +00:00
Argyrios Kyrtzidis
549dfb882a [AST] Record and report the protocol requirement decls that a ValueDecl conforms to.
Swift SVN r9587
2013-10-22 15:47:37 +00:00
Doug Gregor
cd0299f85a Push get/setInterfaceType() up to ValueDecl.
No functionality change here.


Swift SVN r9552
2013-10-21 19:05:02 +00:00
Doug Gregor
e3ebb03c28 Start opening GenericFunctionTypes for references to non-member functions.
When the type checker sees a reference to a generic non-member
function, open its interface type, which is expressed as a
GenericFunctionType, rather than its PolymorphicFunctionType. This is
a tiny step toward weaning the type checker off archetypes within the
interface.




Swift SVN r9504
2013-10-18 23:04:16 +00:00
Joe Groff
5721bdda01 Don't pretend we can parse enum case refined types.
There's no way we'll be able to fully implement GADTs anytime soon.

Swift SVN r9477
2013-10-18 01:34:25 +00:00
Jordan Rose
55d4d05b23 Don't automatically create one SourceFile for every TranslationUnit.
Many places are still relying on having one, though.

Swift SVN r9077
2013-10-09 18:38:26 +00:00
Doug Gregor
a012f60633 Make protocol methods generic over <Self>.
Pull the implicit 'Self' associated type out of the protocol and into
an implicitly-declared generic parameter list for the protocol. This
makes all of the methods of a protocol polymorphic, e.g., given

  protocol P {
    typealias Assoc
    func getAssoc() -> Assoc
  }

the type of P.getAssoc is:

  <Self : P> (self : @inout P) -> () -> Self.Assoc

This directly expresses the notion that protocol methods are
polymorphic, even though 'Self' is always implicitly bound. It can be
used to simplify IRgen and some parts of the type checker, as well as
laying more of the groundwork for default definitions within
protocols as well as sundry other improvements to the generics
system.

There are a number of moving parts that needed to be updated in tandem
for this. In no particular order:
  - Protocols always get an implicit generic parameter list, with a
  single generic parameter 'Self' that conforms to the protocol itself.
  - The 'Self' archetype type now knows which protocol it is
  associated with (since we can no longer point it at the Self
  associated type declaration).
  - Protocol methods now get interface types (i.e., canonicalizable
  dependent function types).
  - The "all archetypes" list for a polymorphic function type does not
  include the Self archetype nor its nested types, because they are
  handled implicitly. This avoids the need to rework IRGen's handling
  of archetypes for now.
  - When (de-)serializing a XREF for a function type that has an
  interface type, use the canonicalized interface type, which can be
  meaningfully compared during deserialization (unlike the
  PolymorphicFunctionType we'd otherwise be dealing with).
  - Added a SIL-specific type attribute @sil_self, which extracts the
  'Self' archetype of a protocol, because we can no longer refer to
  the associated type "P.Self". 




Swift SVN r9066
2013-10-09 17:27:58 +00:00
Doug Gregor
abeaef8996 Track the generic parameters and requirements of nominal type declarations.
Put generic nominal type declarations through the same dependent-type
validation as generic functions, then capture their generic parameters
and requirements in their generic signature. This allows us to
re-instate the requirements in their dependent forms, before the
archetypes ruin them completely.


Swift SVN r8958
2013-10-07 16:21:25 +00:00
Doug Gregor
91173c903d Handle 'self' and nested generics in the interface type of generic functions.
When building the (dependent) interface type of generic functions,
don't resolve any generic parameter types to archetypes, even those at
outer levels. Instead, keep everything dependent.

As a special case, the type of 'self' gets baked into the parameter
patterns with archetypes, so reconstruct the 'self' type ourselves.

The actual output of this is still frustratingly untestable, but we
get decent coverage because all of the type checking of generic
functions goes through here first.



Swift SVN r8936
2013-10-04 23:07:51 +00:00
Joe Groff
0d8d756c83 Sema: Teach conformance checking to derive requirements if needed.
For derivable protocols, such as RawRepresentable on raw-typed enums, when checking the conformance, create a conforming decl if an explicit decl wasn't found. Refactor the conformance derivation for toRaw/fromRaw to be driven by conformance checking in this way.

Swift SVN r8930
2013-10-04 20:50:43 +00:00
Doug Gregor
361447021c Canonicalize generic type parameters with depth/index.
Swift SVN r8893
2013-10-03 22:33:22 +00:00
Doug Gregor
12e228c0f1 Introduce a new representation of polymorphic function types.
Introduces a new kind of function type, GenericFunctionType, that
represents a polymorphic function type with all of its generic
parameters and requirements stored in a more readily canonicalizable
form. It is meant to eventually replace PolymorphicFunctionType, but
for now we build it up in parallel so we can switch over to it
pieacemeal.

Note: this representation is built and then thrown away. We'll start
recording it soon.


Swift SVN r8881
2013-10-03 17:59:35 +00:00
Dmitri Hrybenko
4a0c050d81 Store the standard library module name as ASTContext::StdlibModuleName
... instead of repeating it everywhere


Swift SVN r8792
2013-09-30 21:07:35 +00:00
Argyrios Kyrtzidis
3d7cf2072d [AST] If a ValueDecl is given an error type, also make it invalid.
Swift SVN r8760
2013-09-29 00:12:17 +00:00
Argyrios Kyrtzidis
6942646f80 [AST] Make 'self' vars implicit and provide a source location for them.
Verifier expects all decls to have locations, let's keep it happy.

Swift SVN r8757
2013-09-29 00:12:13 +00:00
Dmitri Hrybenko
09f44aec2b Move ValueDecl::getDefaultArg() -> AbstractFunctionDecl::getDefaultArg()
Swift SVN r8744
2013-09-27 22:27:12 +00:00
Anna Zaks
3e5c1f81d2 Support transparent attributes on struct and enum extensions.
Attribute [transparent] on extensions should apply to all members(functions, properties) of that extension.

Addresses radar://15035271.

Swift SVN r8735
2013-09-27 20:29:31 +00:00
Dmitri Hrybenko
ba2e4732d0 Remove unused member EnumDecl::isEnum
Swift SVN r8710
2013-09-27 00:22:39 +00:00
Jordan Rose
e05c03d5bc Standardize terminology for "computed", "stored", "variable", and "property".
These are the terms sent out in the proposal last week and described in
StoredAndComputedVariables.rst.

variable
  anything declared with 'var'
member variable
  a variable inside a nominal type (may be an instance variable or not)
property
  another term for "member variable"
computed variable
  a variable with a custom getter or setter
stored variable
  a variable with backing storage; any non-computed variable

These terms pre-exist in SIL and IRGen, so I only attempted to solidify
their definitions. Other than the use of "field" for "tuple element",
none of these should be exposed to users.

field
  a tuple element, or
  the underlying storage for a stored variable in a struct or class
physical
  describes an entity whose value can be accessed directly
logical
  describes an entity whose value must be accessed through some accessor

Swift SVN r8698
2013-09-26 18:50:44 +00:00
Doug Gregor
cc4c7d0fd8 [Clang importer] Stop creating property/subscript getter/setter thunks.
Instead of synthesizing Swift code for the property and subscript
getters and setters we import from Objective-C, just create the
declarations and mark them as being Objective-C (foreign) entry
points. This means that we'll use the Objective-C entry points (via
objc_msgSend).


Swift SVN r8692
2013-09-26 15:58:19 +00:00
Anna Zaks
c2adc1e35b Restructure parsing to ensure that bodiless constructors/destructors/subscripts are fully diagnosed.
Previously, we followed an early exit for bodiless constructors/destructors/subscripts.
This prevented some diagnostics and full AST class setup in SIL parsing mode and for bodiless subscripts in general.

Thanks for the suggestion Dmitry!

Swift SVN r8672
2013-09-25 23:28:52 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00