Commit Graph

6754 Commits

Author SHA1 Message Date
Joe Groff
6760c8dce7 SILGen: Implement NominalTypePatterns for stored properties.
If we see nominal type patterns in a switch column, grab all of the needed properties for all of the patterns when destructuring so we only need to do it once. For now, only handle stored properties. John's in the middle of reinventing the world for SIL functions and I don't want to create merge problems.

There's an issue handling the temporary allocation for address-only properties that I don't have time to address right now but will fix soon.

Swift SVN r9520
2013-10-20 05:20:08 +00:00
Joe Groff
4d8d79712c SILGenPattern: Add debug output.
Give ClauseMatrix a dump method that gives nice columnar output of the current decision matrix, and add DEBUG output to emitSwitchStmt so there's more visibility into decision tree generation.

Swift SVN r9519
2013-10-20 05:20:03 +00:00
Adrian Prantl
3fafb6c7e7 Debug info: Make the ret instruction in the function epilogue a cleanup
location rather than a regular location to avoid the linetable jumping
back to the beginning of the function.
Add a large number of testcases that check the sanity of the return
locations in various scenarios involving implicit/explicit returns,
cleanups, and multiple return locations per function.

rdar://problem/14845534

Swift SVN r9511
2013-10-19 00:20:44 +00:00
Doug Gregor
f5c6ea1c8e Use requiresObjCDispatch() rather than Decl::isObjC() for accessor callees.
Noticed by inspection.


Swift SVN r9496
2013-10-18 21:20:05 +00:00
Joe Groff
cd74f49434 Revert "SILGen: Enable lvalue-to-lvalue copy_addr initialization peephole by default."
This reverts commit r9347. The copy_addr peephole still crashes the
Demo-2012-07/uniq.swift test on the buildbot.

Swift SVN r9358
2013-10-15 18:18:29 +00:00
Joe Groff
ad379929fd SILGen: Don't apply the copy_addr peephole to initializations from computed lvalues.
Materializing the result of the getter isn't worth it, I don't think.

Swift SVN r9351
2013-10-15 17:20:48 +00:00
Joe Groff
47dd733c3f SILGen: Enable lvalue-to-lvalue copy_addr initialization peephole by default.
The Interpreter crashes this introduced in the end-to-end pipeline seem to have subsided, now that DI is prepared for it.

Swift SVN r9349
2013-10-15 16:56:15 +00:00
Joe Groff
a288f160ba SILGenPattern: Refactor clause matrix specialization to filter pattern set by each pattern.
No intended functionality change yet. For now this gives a slightly better constant factor to the O(n^2) linear scan for subsumed pattern nodes. Later on, for nominal type patterns, this will also give us an opportunity to collect the properties from all the equivalent patterns into one NominalTypePattern specialization.

Swift SVN r9297
2013-10-13 22:57:09 +00:00
Michael Gottesman
5b183cd8df Updated lib/SILGen/CMakeLists.txt in light of r9184 removing OwnershipConventions.cpp.
This fixes the build.

Swift SVN r9190
2013-10-11 02:55:16 +00:00
Adrian Prantl
9ad9548388 Debug info: Update the inout testcase and emit debug information for
unboxed [inout] arguments.

Swift SVN r9187
2013-10-11 01:00:46 +00:00
John McCall
8fbc790d39 Subsume OwnershipConventions into SILFunctionType.
Swift SVN r9186
2013-10-11 00:50:57 +00:00
Joe Groff
1bdbc97056 Drop the 'x as! T' cast syntax.
Now that we have a solid Optional-based story for dynamic casts, it's no longer needed, and can be expressed as '(x as T)!'. Future refinement of the 'as' syntax will deal with the unfortunate extra parens.

Swift SVN r9181
2013-10-10 23:47:59 +00:00
Doug Gregor
b314941328 SILGen: Generate an unconditional checked cast for (x as T)!.
This is a simple peephole optimization for cases where we're
performing a conditional checked cast and then immediately forcing it
to succeed with postfix '!'. It also happens with the new forced
downcast of 'id', e.g.,

  var w : NSView = foo.views()[0]!



Swift SVN r9180
2013-10-10 22:37:17 +00:00
Jordan Rose
5ed38c0b72 Clarify SourceFile vs. TranslationUnit interfaces for SILGen and IRGen.
Once we have multiple SourceFiles in a TranslationUnit, it no longer makes
sense to say "only SILGen decls starting from element N" without specifying
which source file you mean.

Also, clarify ownership by having performSILGeneration return a unique_ptr
instead of just a bare pointer.

Swift SVN r9112
2013-10-09 23:44:43 +00:00
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +00:00
John McCall
dcf9d15cc7 Rewrite SILFunctionTypeInfo in terms of SILFunctionType.
Swift SVN r9090
2013-10-09 20:55:46 +00:00
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +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
John Garvin
a1badb1777 Add kernel/shader data to SILFunction.
Swift SVN r9047
2013-10-09 01:11:20 +00:00
Adrian Prantl
627fec7f41 Debug info: fix scoping for boxed values that get promoted to stack
allocated values. Fixes rdar://problem/15035350

Swift SVN r9044
2013-10-09 01:01:32 +00:00
Joe Groff
1acbc5a74c SILGen: Fix a crash when 'x!' was able to emit into a buffer.
Swift SVN r9040
2013-10-09 00:36:36 +00:00
Joe Groff
d9560a9bd6 SILGen: Simplify lvalue initialization peephole when dealing with semantic stores.
Instead of trying to anticipate every combination of source and destination [unowned]/[weak] qualifiers, just back off on the copy_addr peephole and let the old path handle these cases as before.

Swift SVN r9030
2013-10-08 21:14:44 +00:00
Joe Groff
2ffd735255 SILGen: Peephole lvalue-to-lvalue initializations as copy_addrs.
If we're using emitExprInto to emit a LoadExpr, we can handle that by emitting a copy_addr from the underlying lvalue to the initialization instead of building and storing the rvalue, which plays better with the direction we're taking for value semantics optimizations.

This is currently guarded behind a flag -enable-silgen-lvalue-peepholes because it introduces a miscompile in the stdlib that crashes some tests; requires further investigation before making live.

Swift SVN r9027
2013-10-08 20:44:09 +00:00
Joe Groff
554fcc9250 SILGen: Use SILBuilder::emitDestroyAddr in place of TypeLowering::emitDestroyAddress.
The other end of r8989. Canonicalize toward destroy_addr when destroying lvalues already in memory, instead of trying to emit a more specific sequence of operations.

Swift SVN r9022
2013-10-08 03:50:51 +00:00
Joe Groff
0bda31c02b Switch over to Generator as the 'for' loop protocol.
Rewrite ForEachStmt SILGen to use the Optional intrinsics with the Generator.next method to iterate through sequences, and kill off the Enumerator path in Sema. Cut over 'EnumeratorType.Element' requirements to instead require 'GeneratorType.Element' in the stdlib.

There are a couple of bugs remaining that need follow-up work. There appears to be a bug in nested enum layout (e.g. T??) that's causing test/Interpreter/enum to break; I'll investigate and fix. There's also a lingering type-checker bug with inferred associated types that causes them to fail requirement checks <rdar://problem/15172101>, which I think Doug needs to look into.

Swift SVN r9017
2013-10-08 01:46:51 +00:00
Joe Groff
7fc2720826 SILGen: Replace uses of TypeLowering::emitCopyInto with CopyAddrInsts.
Chris and I want to move toward canonicalizing on more abstract aggregate operations (copy_addr) instead of on the component load/store/copy|destroy_value/retain|release operations, which is easier for early passes like inout deshadowing, NRVO, and move optimization to reason about. As a first step, replace the handful of places where SILGen currently used TypeLowering::emitCopyInto with simple CopyAddrInst insertions. This affects inout initializations and emitSemanticLoadInto, neither of which should disturb early passes that relied on the old behavior.

Swift SVN r8991
2013-10-07 21:17:48 +00:00
Joe Groff
fd9fd40068 Properly nest class initializer 'self' box with other argument boxes.
Emit the 'self' argument of constructors first so that its box's lifetime follows proper stack discipline relative to the other arguments.

Swift SVN r8984
2013-10-07 20:32:59 +00:00
Joe Groff
0bff1ebe7b SILGen: Emit cleanups before returning from enum case constructors.
We were leaking dealloc_stacks when the enum constructor had to create temporary allocations in order to implode address-only tuple payloads.

Swift SVN r8971
2013-10-07 18:04:43 +00:00
Chris Lattner
607114f6c6 Introduce a new "emitDestroyAddr" function, which attempts to fold destroy_addr into
preceding copy_addr instruction when totally trivial.  Adopt this in SILGen, eliminating
a couple dozen destroy_addr instructions from the stdlib and producing more canonical SIL.


Swift SVN r8968
2013-10-07 17:47:17 +00:00
Joe Groff
235f4e5017 SILGenPattern: Kill redundant helper function.
Swift SVN r8951
2013-10-07 02:18:17 +00:00
Doug Gregor
611a5cce4b Replace the library-defined postfix '!' with an expr-postfix production.
As with the monadic '?', we treat any left-bound '!' as a postfix
operator. Currently, it extracts the value of its optional
subexpression, failing at run-time if the optional is empty.


Swift SVN r8948
2013-10-06 23:09:58 +00:00
Joe Groff
aca3bd52ac SILGen: Build SILVTables while visiting classes.
When we walk a ClassDecl, generate its vtable, first pulling in decls from its ancestor classes, then overlaying overridden or new decls as we discover them.

Swift SVN r8947
2013-10-06 01:02:14 +00:00
John McCall
affefbe1e0 Remove the AllocSelfExpr from constructors and teach
alloc_ref how to call +allocWithZone: for classes that might
(i.e. probably do) use ObjC allocation.

Swift SVN r8874
2013-10-03 06:36:34 +00:00
Adrian Prantl
8808d48578 Debug info: emit captured variables in closures. rdar://problem/15035486
Swift SVN r8859
2013-10-02 22:46:03 +00:00
Joe Groff
3b0180b1b0 Allow '_' in assignments again.
Parse '_' as a DiscardAssignmentExpr. Type-check it as an lvalue, and check that it only appears in the LHS of AssignExprs. During matching pattern resolution, convert it into an AnyPattern. In SILGen, when we see '_' in the LHS of an assignment, ignore the corresponding RHS rvalue.

Swift SVN r8848
2013-10-02 18:43:20 +00:00
John McCall
6df6897756 Add an InjectIntoOptional implicit conversion expression
instead of generating ugly artificial calls to
_injectValueIntoOptional in the AST.

Swift SVN r8837
2013-10-02 05:48:30 +00:00
John McCall
97033996ba Rework optional intrinsic methods to work with RValues.
Swift SVN r8836
2013-10-02 05:48:29 +00:00
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +00:00
John McCall
a1867380d0 Distinguish the "cleanup handle" and "scope" use-cases
of CleanupsDepth.

Only with different typedefs for now, but the communicative
effect is significant.

Swift SVN r8831
2013-10-02 01:27:41 +00:00
John McCall
916b566fa6 Push and invalidate uninitialized-local cleanups.
No effect currently; just resolves a FIXME.

Swift SVN r8830
2013-10-02 01:27:39 +00:00
Joe Groff
ce2e87fa3e SILGen: Emit 'x as? T' conditional casts.
Wrap the result of a checked_cast_br into an Optional using John's injection functions.

Swift SVN r8811
2013-10-01 21:11:34 +00:00
Joe Groff
f1993cf231 Parse and type-check 'x as? T' conditional cast syntax.
Though we plan to revamp the casting syntax, our general plan is for this form of cast, which does a conditional cast and returns an Optional<T> result, to be the one that survives. Parse the status-quo syntax 'x as? T' and type-check it. While we're here, refresh some fixits for redundant casts that referred to the now defunct 'as T' coercion syntax to completely remove whatever cast was in the source code.

Swift SVN r8805
2013-10-01 17:00:54 +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
Joe Groff
9909ba275c SILGenPattern: Handle subsumption and orthogonality of superclasses in 'is' patterns.
Now that we can ask about superclasses outside of the type-checker, we can consider superclass relationships when pattern-matching 'is' patterns, producing better decision trees when a subclass checked is subsumed by a superclass check, a subclass check renders a superclass check redundant, or two classes or orthogonal and a check of one rules out the other.

Swift SVN r8769
2013-09-29 18:23:52 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Doug Gregor
1e95e4e8f5 Emit Objective-C entry points for initializers defined within class extensions.
Swift SVN r8743
2013-09-27 22:17:33 +00:00
Doug Gregor
0d33ff3f40 Teach SILGen to directly emit optional injection operations for dynamic lookup.
... rather than synthesizing expressions in the AST.


Swift SVN r8723
2013-09-27 14:12:33 +00:00
Doug Gregor
5a1a7c0f60 Fix emission of the index for a dynamic subscript.
SILGen the index of a dynamic subscript in its own context; it's
result doesn't go into the current initialization. As an added bonus, 
always evaluate the index, so that side effects occur predictable
regardless of whether the function is available.


Swift SVN r8718
2013-09-27 03:54:32 +00:00
Jordan Rose
626479fbd9 s/property/accessor/ in SILGen and TypeLowering
Several places in SILGen and TypeLowering were using "property" to mean
"accessor" (for both variables and subscripts).

Swift SVN r8702
2013-09-26 21:53:03 +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