Commit Graph

3502 Commits

Author SHA1 Message Date
Chris Lattner
9462fca05c Several NFC changes:
- In AST/Decl.cpp, simplify by always setting isMutating to true for 
   ctors/dtors, since mutability only means something to struct/enum 
   methods anyway.
 - in DeclContext.cpp, continue to lvalue qualify the 'self' of protocol 
   methods, this is currently dead.
 - in CSApply, fix logic for some value-type member processing stuff
   to properly handle methods that have a self which is not lvalue 
   qualified. Not exercised yet.


Swift SVN r11650
2013-12-26 01:42:51 +00:00
Chris Lattner
a49dfe2b3a Start setting 'self' as a rvalue instead of an rvalue. First up are
property and subscript getters which have no explicit FuncDecl for 
the getter.  I'm not exactly sure where these come from, but they 
look like something the clang importer is producing in some cases.


Swift SVN r11642
2013-12-25 23:37:29 +00:00
Chris Lattner
d7621b5a7b Remove the concept of a "nonsettable lvalue": Now everything that is
nonsettable is represented as an rvalue.  Yay for one less concept in
the AST.


Swift SVN r11640
2013-12-25 22:20:01 +00:00
Chris Lattner
f99492202f Make some fairly major internal changes to our value system: now, get-only
properties are represented as rvalues, not non-mutable lvalues.  As part of
this, isReferencedAsLValue() only returns true for mutable VarDecls.

This required some pretty serious rearrangement and refactoring of code,
because now (among other things) get-only properties can be emitted as rvalues,
so the rvalue machinery needs to be able to produce getter calls.

This is an important step towards getting proper value semantics going (for
'let's etc) and also allows us to materialize addresses less often.  As a
simple example, before we would silgen this:

struct S {
  var i : Int
}
var P : S { get: ... }
func f() {
  print(P.i)
}

into:

 %2 = function_ref @_TF1tg1PVS_1S : $@thin () -> S // user: %3
  %3 = apply %2() : $@thin () -> S                // user: %5
  %4 = alloc_stack $S                             // users: %9, %6, %5
  store %3 to %4#1 : $*S                          // id: %5
  %6 = struct_element_addr %4#1 : $*S, #i         // user: %7
  %7 = load %6 : $*Int64                          // user: %8

now we generate:

  %2 = function_ref @_TF1tg1PVS_1S : $@thin () -> S // user: %3
  %3 = apply %2() : $@thin () -> S                // user: %4
  %4 = struct_extract %3 : $S, #i                 // user: %5



Swift SVN r11632
2013-12-25 17:43:10 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Jordan Rose
f1ff340367 Move the "conformances" array from TypeDecl to NominalTypeDecl.
No functionality change, but a nice limiting of scope.

Swift SVN r11489
2013-12-19 23:25:07 +00:00
Jordan Rose
7a30de2efe Disallow inheritance clauses for concrete typealiases.
typealias MyInt: ForwardIndex = Int

There is no real reason to allow this; it's just a static_assert that Int
conforms to ForwardIndex, which would be better spelled some other way.

This only applies to concrete typealiases, i.e. those that simply alias an
underlying type. Associated types can still have both inheritance clauses
and a (default) underlying type.

Swift SVN r11481
2013-12-19 21:13:54 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Chris Lattner
42d0fdadcf - Introduce the ability for attributes to be inverted with !.
- Switch @mutable to be a tri-state attribute that is invertable with @!mutable.
- Move the semantic form of 'mutable' to being a bit on FuncDecl instead of
  something in DeclAttrs.  The former is a binary bit, the later is a tristate
  which differentiates between "not present", "present and set" "present and inverted".
- Diagnose some invalid uses of @mutable, e.g. on class methods.
- Make setters default to mutable, and allow them to be switched with @!mutable.



Swift SVN r11439
2013-12-18 21:38:53 +00:00
Doug Gregor
ec4913b0ea Implement default definitions for associated types.
Addresses <rdar://problem/14292873>.


Swift SVN r11422
2013-12-18 06:24:53 +00:00
Chris Lattner
51862b91fd rename the inout decl attribute (not the type attribute) to @mutating.
Swift SVN r11416
2013-12-18 04:44:56 +00:00
Chris Lattner
01be26cd4b Add a new command line option that turns on by-value self arguments for structs
when a method is not declared @inout.


Swift SVN r11386
2013-12-17 17:25:42 +00:00
Doug Gregor
292192efac Record the value-witness-of relationship in the ASTContext as we assign witnesses.
Previously, this was being handled when we set conformances. We want
something lazier.


Swift SVN r11339
2013-12-16 02:49:37 +00:00
Doug Gregor
2d75ca2adf Add a LazyResolver to ProtocolConformance::getWitness().
Swift SVN r11331
2013-12-15 19:40:49 +00:00
Doug Gregor
b4a739854d Stop using ProtocolConformance::getWitnesses().
It's going away, soon.


Swift SVN r11277
2013-12-13 23:44:42 +00:00
Doug Gregor
0c4baac6f6 Make the 'self' declaration of a value type constructor be '@inout'.
This removes an oddity in the AST whereby the 'self' declaration
within a value type constructor was not represented as @inout, despite
having @inout semantics in the language.


Swift SVN r11194
2013-12-12 18:31:54 +00:00
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