1627 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
f9150a58b5 [AST/Serialization] Add a string for the generic requirements "as written" in the module file, to use it for
the printed interface.

Previously we printed the typechecked and uniqued requirements and the result was non-sensical.
Long-term the requirements will be preserved in a better form but for now print the requirements
and serialize them.

rdar://19963093

Swift SVN r27680
2015-04-24 06:11:09 +00:00
Doug Gregor
4e0e32197f Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27355
2015-04-16 06:36:45 +00:00
Argyrios Kyrtzidis
707394aea8 [AST] Refactor implementation for ValueDecl::getSatisfiedProtocolRequirements().
Move the map that keeps track of conforming decl -> requirement from ASTContext
to a nominal type's ConformanceLookupTable, and populate it lazily.

This allows getSatisfiedProtocolRequirements() to work with declarations from module files.
Test on the SourceKit side.

Part of rdar://20526240.

Swift SVN r27353
2015-04-16 06:23:56 +00:00
Argyrios Kyrtzidis
5f6d091efc [AST] Keep track of the type decl that the type witness came from, for protocol conformances.
Swift SVN r27352
2015-04-16 06:23:54 +00:00
Doug Gregor
921855ee0d Revert "Extend 'availability' attribute with an unconditional 'deprecated' option."
This reverts r27339; it broke an iOS test.

Swift SVN r27343
2015-04-16 03:36:40 +00:00
Doug Gregor
b4b5dbb5d8 Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27339
2015-04-15 23:59:20 +00:00
Joe Groff
e4e0f35aed IRGen: Implement an @_alignment attribute.
This is an internal-only affordance for the numerics team to be able to work on SIMD-compatible types. For now, it can only increase alignment of fixed-layout structs and enums; dynamic layout, classes, and other obvious extensions are left to another day when we can design a proper layout control design.

Swift SVN r27323
2015-04-15 17:23:30 +00:00
Doug Gregor
061795d2bf Revert "(De-)serialization for foreign error conventions."
This reverts commit face8b23dc1b7132039e8b20b96e9fabe4634649.

Swift SVN r27295
2015-04-14 23:37:18 +00:00
Doug Gregor
759346e5b8 (De-)serialization for foreign error conventions.
Currently untestable (due to SILGen's inability to handle throwing
@objc methods), but testing will become trivial once that's in place.

Swift SVN r27294
2015-04-14 22:57:44 +00:00
Doug Gregor
41ae48b22e Start parsing 'throws' on initializers.
Introduce basic validation for throwing @objc initializers, e.g., a
failable @objc initializer cannot also be throwing. However,
Objective-C selector computation is broken.

Swift SVN r27292
2015-04-14 22:52:29 +00:00
Chris Willmore
2d985c0a5d Revert "(De-)serialization for foreign error conventions."
This reverts commit r27290 due to several test failures in SourceKit.

Swift SVN r27291
2015-04-14 21:40:13 +00:00
Doug Gregor
f1d4293210 (De-)serialization for foreign error conventions.
Currently untestable (due to SILGen's inability to handle throwing
@objc methods), but testing will become trivial once that's in place.

Swift SVN r27290
2015-04-14 21:11:28 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Joe Pamer
9781bda6a0 Introduce support for serializing and deserializing throwing function types.
Swift SVN r27026
2015-04-05 19:33:03 +00:00
Joe Groff
56de5fb95e SIL: Drop unnecessary bits from SILFunctionType::ExtInfo.
"Autoclosure" is uninteresting to SIL. "noescape" isn't currently used by SIL and we shouldn't have it until it has a meaningful effect on SIL. "throws" should be adequately represented by a SIL function type having an error result.

Swift SVN r27023
2015-04-05 17:35:28 +00:00
Joe Groff
4821f594bb SIL: Separate SILFunctionType::Representation and ExtInfo from AST FunctionTypes.
The set of attributes that make sense at the AST level is increasingly divergent from those at the SIL level, so it doesn't really make sense for these to be the same. It'll also help prevent us from accidental unwanted propagation of attributes from the AST to SIL, which has caused bugs in the past. For staging purposes, start off with SILFunctionType's versions exactly the same as the FunctionType versions, which necessitates some ugly glue code but minimizes the potential disruption.

Swift SVN r27022
2015-04-05 17:04:55 +00:00
Doug Gregor
7c4823ec71 Convert PrintAsObjC over to conformance lookup table entrypoints.
Another step toward using the conformance lookup table for
everything. This uncovered a tricky little bug in the conformance
lookup table's filtering logic (when asking for only those
conformances explicitly specified within a particular context) that
would end up dropping non-explicit conformances from the table (rather
than just the result).

Ween a few tests off of -enable-source-import, because they'll break
otherwise.

Swift SVN r27021
2015-04-05 13:44:47 +00:00
Joe Pamer
37d65f4202 Start tracking SourceLoc data for function "throws" annotations and eliminate the (now unnecessary) "Throws" bit from AbstractFunctionDecls.
Swift SVN r26955
2015-04-03 21:45:30 +00:00
Chris Willmore
690daa539a Back out changes for in-place methods/operators from Xcode 7.
This reverts commits r26508, r26545, and r26576.

Swift SVN r26900
2015-04-02 21:14:28 +00:00
Doug Gregor
38cc1fe5c6 Remove LazyResolver arguments from API entry points to the conformance lookup table.
Swift SVN r26838
2015-04-02 00:06:01 +00:00
Chris Lattner
b02da0ae31 Add tuple element label information to TuplePatterns. Before we had no way
to represent them, and just dropped them on the ground. Now we parse them,
persist them in the AST, and "resolve" them from the expr grammar, but still
drop them on the ground.  This is progress towards fixing: rdar://20135489


Swift SVN r26828
2015-04-01 22:11:32 +00:00
Doug Gregor
aa0e763940 Imbue ASTContext with a lazy resolver.
Have TypeChecker's constructor register itself as the lazy resolver,
and its destructor unregister itself. This introduces the
completely-sensible restriction that there can only be one type
checker active for an ASTContext at a time, which is the case already.

Use ASTContext's lazy resolver in a single place that's been causing
trouble (rdar://problem/20363958, rdar://problem/19773096), where
deserializing a protocol conformance can cause us to pass a null lazy
resolver into the protocol conformance table, which doesn't handle it
well. This commit fixes those issues, which I'm unable to reduce down
to a sane-enough test case to commit.

This commit implies a ton of cleanup work to eliminate LazyResolver
parameters from *everywhere*, deriving them from the ASTContext in the
few places they're needed as well. It's a good direction, but that
cleanup can be evolutionary.

Swift SVN r26824
2015-04-01 21:31:47 +00:00
Joe Pamer
eee40fc53f Add basic parsing, sema and mangling support for throwing function types. Next up, metadata and serialization support, as well as more tests.
Swift SVN r26767
2015-03-31 18:55:19 +00:00
Chris Lattner
21b2e9e057 add parser and AST representation support for where/else clauses on let/var decls, some highlights:
- Enhance PBD with a whereExpr/elseStmt field to hold this.
- Start parsing the pattern of let/var decls as a potentially refutable pattern.  It becomes 
  a semantic error to use a refutable pattern without an 'else' (diagnostics not in place yet).
- Change validatePatternBindingDecl to use 'defer' instead of a goto to ensure cleanups on exit.
- Have it resolve the pattern in a PBD, rewriting it from expressions into pattern nodes when valid.
- Teach resolvePattern to handle TypedPatterns now that they can appear (wrapping) refutable patterns.
- Teach resolvePattern to handle refutable patterns in PBD's without initializers by emitting a diagnostic
  instead of by barfing, fixing regressions on validation tests my previous patch caused, and fixing
  two existing validation test crashers.

Sema, silgen, and more tests coming later.




Swift SVN r26706
2015-03-29 22:08:44 +00:00
Arnold Schwaighofer
b9f795699f Revert "add parser and AST representation support for where/else clauses on let/var decls."
It breaks the validation test suite.

This reverts commit r26692.

rdar://20339903

Swift SVN r26700
2015-03-29 13:56:32 +00:00
Chris Lattner
9c53b659ee add parser and AST representation support for where/else clauses on let/var decls.
Sema, silgen, and more tests coming later.


Swift SVN r26692
2015-03-29 06:20:24 +00:00
Doug Gregor
ccde6bb87d Allow protocol extensions to add further constraints via a trailing where clause.
Start parsing a "trailing" where clause for extension declarations, which follows the extended type name and (optional) inheritance clause. Such a where clause is only currently permitted for protocol extensions right now.

When used on a protocol extension, it allows one to create a more-constrained protocol extension, e.g.,

  extension CollectionType where Self.Generator.Element : Equatable { ... }

which appears to be working, at least in the obvious cases I've tried.

More cleanup, tests, and penance for the previous commit's "--crash" introductions still to come.

Swift SVN r26689
2015-03-29 05:42:37 +00:00
John McCall
35b7db3ae1 Parsing support for error results from SILFunctionType.
Swift SVN r26566
2015-03-26 00:01:32 +00:00
Chris Willmore
1ee6f7e67c Implement syntax changes for in-place methods.
Rename 'assignment' attribute of infix operators to 'mutating'. Add
'has_assignment' attribute, which results in an implicit declaration of
the assignment version of the same operator. Parse "func =foo"
declaration and "foo.=bar" expression. Validate some basic properties of
in-place methods.

Not yet implemented: automatic generation of wrapper for =foo() if foo()
is implemented, or vice versa; likewise for operators.

Swift SVN r26508
2015-03-25 00:22:41 +00:00
Doug Gregor
492388736c Separate the archetypes of extensions from those of their nominal types.
Start allowing extensions to redeclare type parameters, which will get
different archetypes from the original nominal type. When an extension
does not redeclare type parameters, silently clone the nominal type's
generic type parameters so we still get distinct type parameters.

When deserializing an extension, wire up its generic parameter list so
we get the right archetypes for its members. This doesn't change the
module format (that happened earlier).

When determining the substitutions for an associated type that comes
from a different declaration context from the conformance that will
own the witness, be sure to map into the conformance's
DeclContext. Otherwise, we'll end up with tangled archetypes.

Fixes rdar://problem/16519588.

Swift SVN r26483
2015-03-24 06:48:26 +00:00
Doug Gregor
8b97f911c6 Reimplement (de-)serialization of protocol conformances.
Primarily, unique normal protocol conformances and reference them via
a conformance ID. This eliminates the use of trailing records for
normal protocol conformances and (more importantly) the cases were we
would write incomplete conformances. The latter could cause problems
if we ever ended up deserializing an incomplete conformance without
also deserializing a complete record for that same conformance.

Secondarily, simplify the way we write conformances. They are now
always trailing records, and we separate out the derived conformance
kinds (specialized/inherited) from either a reference to a normal
conformance in the current module file (via a normal conformance ID)
or via a cross-reference to a conformance in another module file
(currently always a normal conformance, but this need not always be
the case). As part of this, make each conformance record
self-sustaining, so we don't have to push information down to the
reading routines (e.g., the conforming type) to actually produce a
proper conformance. This simplifies deserialization logic further.

Swift SVN r26482
2015-03-24 06:48:23 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
Doug Gregor
2fae11d62d Serialize generic requirements of extensions.
Swift SVN r26415
2015-03-22 12:35:25 +00:00
Doug Gregor
813df95fca Register protocol conformances more eagerly with the conformance lookup table during deserialization.
Swift SVN r26413
2015-03-22 12:35:23 +00:00
Doug Gregor
a2a1862202 Start using getLocalConformances() for serialization.
The lit and testsuite changes are hacks to work around the problems with the -enable-source-import model. Some day, we’ll get a “real” mock SDK with compiled overlays so these hacks can go away.

Swift SVN r26327
2015-03-19 22:10:09 +00:00
Doug Gregor
c0d783fe40 Start serializing the reference components of extension declarations.
Specifically, start serializing the generic parameter list, even
though we basically throw it away during deserialization.

Swift SVN r26318
2015-03-19 22:09:59 +00:00
Doug Gregor
e26c0352fb Use NominalTypeDecl::lookupConformance() to find conformances.
... rather than looping over all extensions and all
conformances. Should be NFC.

Swift SVN r26301
2015-03-19 15:31:41 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Michael Gottesman
3c2216b115 [+0 self] Add the deallocating parameter convention.
The deallocating parameter convention is a new convention put on a
non-trivial parameter if the caller function guarantees to the callee
that the parameter has the deallocating bit set in its object header.

This means that retains and releases do not need to be emitted on these
parameters even though they are non-trivial. This helps to solve a bug
in +0 self and makes it trivial for the optimizer to perform
optimizations based on this property.

It is not emitted yet by SILGen and will only be put on the self
argument of Deallocator functions.

Swift SVN r26179
2015-03-16 07:51:11 +00:00
Chris Lattner
8521916b86 change PatternBindingDecl to be created with a static "create" method instead
of using its ctor directly.  NFC, this is in prep for other changes coming.


Swift SVN r26174
2015-03-16 00:44:52 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
Chris Lattner
db187f2183 Enhance VarPattern to capture a bit indicating whether the pattern was a var or let.
Previously we only used this information in the parser, but Sema needs to know as well.

NFC except in -dump-ast.



Swift SVN r25914
2015-03-10 06:07:56 +00:00
Doug Gregor
bce5c20c25 Teach loadAllMembers() implementations to add the members themselves.
The contract for LazyResolver::loadAllMembers() was that the caller
would handle actually adding the members, since it was an iterable
declaration context and could centralize that (simple) logic. However,
this fails in the Clang importer in rare but amusing ways when some of
the deferred actions (e.g., finishing a protocol conformance) depend
on having the members already set. The deferred action occurs after
the member list is complete in ClangImporter's loadAllMembers(), but
before its caller actual set the member list, leaving incomplete
conformances. Fixes rdar://problem/18884272.

Swift SVN r25630
2015-02-28 01:03:41 +00:00
Doug Gregor
96a2659223 Serialize initializer stub implementations.
Fixes the cross-module initializer inheritance issues implied by
rdar://problem/19794036.

Swift SVN r25336
2015-02-17 00:38:21 +00:00
Argyrios Kyrtzidis
944e20949a [AST/IDE] Use TypeReprs to keep track of the type components in an ExtensionDecl.
This allows preserving type info and proper annotation of the extension's type components.

Swift SVN r25309
2015-02-16 08:36:16 +00:00
Jordan Rose
55174867bd [Serialization] Use references for inherited conformances from other modules.
...rather than trying to serialize them again, which could lead to attempting
to cross-reference an ExtensionDecl, which can't be done.

rdar://problem/19794141

Swift SVN r25292
2015-02-14 02:09:19 +00:00
Doug Gregor
954b4e4d83 Implement @autoclosure(escaping).
Addresses rdar://problem/19499207.

Swift SVN r25249
2015-02-12 21:09:47 +00:00
David Farler
51f8070abe Serialize local types
Local type declarations are saved in the source file during parsing,
now serialized as decls. Some of these may be defined in DeclContexts
which aren't Decls and previously weren't serialized. Create four new
record kinds:

* PatternBindingInitializer
* DefaultArgumentInitializer
* AbstractClosureExpr
* TopLevelCodeDecl

These new records are used to only preserve enough information for
remangling in the debugger, and parental context relationships.

Finally, provide a lookup API in the module to search by mangled name.
With the new remangling API, the debugging lifecycle for local types
should be complete.

The extra LOCAL_CONTEXT record will compressed back down in a
subsequent patch.

Swift SVN r24739
2015-01-27 01:49:54 +00:00
John McCall
9e26ecf2af Make ArchetypeType::NestedType its own proper type
with more explicit/semantic conversions in and out.

Using a PointerUnion with overlapping pointer types
is both error-prone and pretty close to illegible.

Swift SVN r24707
2015-01-24 13:05:38 +00:00
David Farler
cad9f99929 Revert "Serialize local types and provide a lookup API"
Changing the design of this to maintain more local context
information and changing the lookup API.

This reverts commit 4f2ff1819064dc61c20e31c7c308ae6b3e6615d0.

Swift SVN r24432
2015-01-15 00:33:10 +00:00